Commit graph

6489 commits

Author SHA1 Message Date
Jukka Rissanen
b0b20229b0 net: sockets: Add support for IP_LOCAL_PORT_RANGE socket option.
Add support for IP_LOCAL_PORT_RANGE socket option. The option
supports both IPv4 and IPv6 sockets although the type is IPPROTO_IP.

The option can be used to enforce the ephemeral port number selection
to be in certain range.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-22 17:42:08 +01:00
Chen Xingyu
50f23500b8 net: Fix warning of size_t formatting with %.*s
This addresses the following warning building with `CONFIG_64BIT=y`:

    error: field precision specifier '.*' expects argument of type 'int',
    but argument X has type 'size_t' {aka 'long unsigned int'}

Signed-off-by: Chen Xingyu <hi@xingrz.me>
2024-11-22 08:25:31 -05:00
Jukka Rissanen
39889c0023 net: if: Do not report error if we are already in promisc mode
If we are already in promiscuous mode, then do not report error
in that case.

Fixes #81605

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-21 20:11:01 +01:00
Seppo Takalo
2066cf6a3d net: lib: coap_client: Release non-confirmable requests
Non-confirmable CoAP requests need lifetime tracking as well
so we can free the structure after a timeout.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-21 14:47:38 +01:00
Seppo Takalo
6c169668e9 net: lib: coap_client: Fix timeout for separate response
When waiting for response after receiving the empty Ack, client
actually used way too timeout.
CoAP timeout only holds the timeout value in ms. t0 is the starting time.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-21 14:47:38 +01:00
Chaitanya Tata
0f1f01f9f4 net: l2: wifi: Fix the minimum value
802.11 doesn't have specific constraints, it just says that listen
interval should be >=0 and it a 2 byte field.

3 as a typical DTIM value from nRF chipsets, so, remove the hardware
specific line and just set a failure.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-11-20 15:57:06 -05:00
Andi Gerl
9c2421444b net: lwm2m: add set_socketoptions cb to pull context LwM2M context
The pull context LwM2M client's set_socketoptions callback is currently
unused and can't be set by a user. Add a public API to set the
pull context's client's set_socketoptions callback.

Signed-off-by: Andi Gerl <andi.gerl@exacttechnology.com>
2024-11-20 08:23:44 -05:00
Jukka Rissanen
bffa312ea6 net: context: Fix the connect check for IPv4
Make sure that we cannot connect to IPv4 multicast or broadcast
destination address for a TCP socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 19:29:58 -05:00
Jukka Rissanen
d3bac7047d net: socket: Add support for IP_MULTICAST_IF option
Allow user to set the network interface for multicast sockets
of type SOCK_DGRAM.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 19:29:58 -05:00
Jukka Rissanen
056a3d3242 net: if: Add helper to return the first IPv4 address for iface
This is helper is only needed in socket multicast interface selection
where we need to get one address from the interface so that it will
tell (when getsockopt() is used), the interface IPv4 address where
multicast packets will be sent. This is private function which is not
needed in public headers so place the prototype to net_private.h file.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 19:29:58 -05:00
Jukka Rissanen
0bd6f3b3f0 net: if: Fix source interface select for IPv4 address
Do the selection same way as in IPv6 so that if user supplies
unspecified destination address, the default interface is selected
the same way.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 19:29:58 -05:00
Jukka Rissanen
7bf9f599b1 drivers: net: loopback: Allow tests to control address swapping
Some of the network tests require that source and destination
addresses are not swapped so allow test to control the address
swapping from the test.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 19:29:58 -05:00
Jukka Rissanen
96d4f84a52 net: socket: Add support for IPV6_MULTICAST_IF option
Allow user to set the network interface for multicast sockets
of type SOCK_DGRAM.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 19:29:58 -05:00
Jukka Rissanen
247941f79d net: ipv6_fragment: Data in one frag must be multiple of 8
After we take the true MTU into account, we need to send proper
number of bytes (multiple of 8) in one IPv6 fragment.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
19f9ce5622 net: ipv6_fragment: Add PMTU support
If PMTU is enabled, then use the MTU value from it instead of always
using network interface MTU.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
b6618e8a53 net: ipv4_fragment: Add PMTU support
If PMTU is enabled, then use the MTU value from it instead of always
using network interface MTU.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
9fb09da21a net: Add support for IPV6_MTU IPv6 socket option
Add IPV6_MTU IPv6 socket option and implement getsockopt() and
setsockopt() calls for the option.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
a818839186 net: Add support for IP_MTU IPv4 socket option
Add IP_MTU IPv4 socket option and implement getsockopt()
call for the option. The IP_MTU option does not support
setsockopt() call.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
fad10f7370 net: shell: events: Set the command mask correctly
Set the commands to monitor correctly. Before this change some
events were missed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
f0172e7fce net: shell: events: Print PMTU event values
Print the changed PMTU value and IP address in the event monitor.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
02ccb0e523 net: pmtu: Send net_mgmt event for changed path MTU
Send a network management event for a changed path MTU value.
Both IPv4 and IPv6 have their own events as we cannot mix these
because how the network event numbering space is implemented.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
55e582635f tests: net: pmtu: Add IPv4 specific PMTU TCP tests
Allow tests to check whether a IPv4 TCP connection MTU is changed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
9dba02f8f4 net: ipv4: Add PMTU support
Catch "Destination Unreachable" ICMPv4 messages and update PMTU for
a given destination IPv4 address.
Use that PMTU when sending data to the destination.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
d178eb2908 net: stats: ipv4: pmtu: Add Path MTU Discovery statistics
Add information about PMTU related packets received/sent/dropped
for IPv4.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
ab0ddc0bbe net: shell: Add pmtu command to the net-shell
Show information whether PMTU is enabled or not.
Show pmtu destination cache content with "net pmtu"
command. The "net pmtu flush" can be used to clear the
cache.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
281c4ac742 tests: net: pmtu: Add IPv6 specific PMTU TCP tests
Allow tests to check whether a IPv6 TCP connection MTU is changed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
e7e3afcd01 net: ipv6: Add PMTU support
Catch "Packet Too Big" ICMPv6 messages and update PMTU for
a given destination IPv6 address.
Use that PMTU when sending data to the destination.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
84b135e226 net: ipv6: Print verdict information
Print more cases when the packet is dropped, and also print
the upper layer verdict for the packet.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
026f88481d net: stats: ipv6: pmtu: Add Path MTU Discovery statistics
Add information about PMTU related packets received/sent/dropped
for IPv6.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
3da2629715 net: ip: pmtu: Add generic IP PMTU Discovery support
This adds generic code that can be used by both IPv4 and IPv6
Path MTU Discovery mechanism. The actual PMTU support for each
protocol family is in subsequent commits.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-18 07:26:07 -05:00
Jukka Rissanen
185269d86e net: shell: ipv6: Print information about SLAAC addresses
Print information in "net ipv6" command how the SLAAC addresses
are generated. There is the default legacy EUI-64 method (RFC 4862) or
the stable method described in RFC 7217.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-16 15:55:49 -05:00
Jukka Rissanen
94177a200e net: ipv6: Add support for stable IID addresses
This implements support for RFC 7217 which describes a method
to have stable IPv6 Interface Identifiers to be used with IPv6
Stateless Address Autoconfiguration (SLAAC). The stable IIDs are used
to provide enhanced privacy so that an IPv6 address configured using
this method is stable within each subnet, but the corresponding
Interface Identifier changes when the host moves from one network
to another. This method is meant to be an alternative to generating
Interface Identifiers based on hardware (MAC) addresses,
such that the benefits of stable addresses can be achieved without
sacrificing the security and privacy of users.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-16 15:55:49 -05:00
Adrian Gielniewski
9fd9e231df net: openthread: Add platform message management
* Add CONFIG_OPENTHREAD_PLATFORM_MESSAGE_MANAGEMENT to allow enabling
message management by the platform.
* Add implementation of `otPlatMessagePoolInit`, `otPlatMessagePoolNew`
and `otPlatMessagePoolFree`.

Signed-off-by: Adrian Gielniewski <adrian.gielniewski@nordicsemi.no>
2024-11-16 15:21:20 -05:00
Matt Rodgers
2eda6df48a net: lib: http_server: add option to use ALPN
Web browsers don't support HTTP Upgrade mechanism to upgrade to HTTP2.
Instead, HTTP2 is supported only over TLS, and ALPN is used to negotiate
the protocol to be used.

This commit adds the supported HTTP protocols to the ALPN list, so that
web browsers can use HTTP2 with the server.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-11-16 15:19:36 -05:00
Kenneth Witham
aa9c9228d4 net: mqtt-sn: Add Gateway Advertisement and Discovery process support
Fixes: #78010
This commit implements the "Gateway Advertisement and Discovery" process
defined in section 6.1 of the MQTT-SN specification.
This includes breaking changes to the transport interface and the default
included UDP interface implementation as support for UDP multicast
messages is added as implemented by the Paho MQTT-SN Gateway.

Signed-off-by: Kenneth Witham <kennywitham4@gmail.com>
2024-11-16 15:08:27 -05:00
Fin Maaß
8646a6c289 net: ethernet: arp: extend error log
If a gateway is not set for a interface,
also log the destination address.

Also print the interface index instead of the
interface pointer.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-11-16 14:56:57 -05:00
Jukka Rissanen
f95ab280fb net: shell: dns: Print DNS server with network interface
If network interface is specified in the DNS server, then send
the queries to the server via the network interface. Print this
information in the server list.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-16 13:51:27 -05:00
Jukka Rissanen
6c95daf0ae net: dns: Bind DNS server to a network interface
Allow user to specify a network interface in the DNS server
list. User can append "%" and network interface name to the
DNS server to use this. If the network interface is mentioned
in the server list, then the DNS queries are sent via this network
interface.
For example setting the interfaces like this:
   192.0.2.2%eth1
   [2001:db8::2]:5353%ppp0

would cause the DNS queries to sent to 192.0.2.1 via eth1 in the first
example, and to 2001:db8::2 via ppp0 in the second example.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-16 13:51:27 -05:00
Jukka Rissanen
5f3e6212af net: utils: Port parsing failure in net_ipaddr_parse()
If trying to parse a string like 192.0.2.2:80/foobar and
setting the length to 12 which means to parse the IP address
and port, the parsing failed because it used one extra character
from the string. This issue was not present if the input string
was terminated after the port number.

Add a test case to catch this problem.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-16 13:51:27 -05:00
Seppo Takalo
b3f3bce23e net: lib: coap_client: Add API to cancel specific request
Add a new API to cancel just one, or mathing requests,
instead of cancelling all ongoing requests.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Seppo Takalo
f0c6efe798 net: lib: coap_client: Stop polling on unneeded sockets
poll() only for sockets that have traffic ongoing or have some lifetime
left.
On socket failures during a poll(), stop listening for the socket.
Application can recover by reconnecting the socket.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Seppo Takalo
f72d634826 net: lib: coap_client: All error cases should be reported to callback
When the client fails when parsing the response and we stop proceeding,
we should report that to the application.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Seppo Takalo
c0eb260c2c net: lib: coap_client: Drop duplicate MID only after responding with Ack
Even if we receive duplicate confirmable message, we should still
respond with the Ack. Just don't deliver the second callback.

This is achieved by moving the MID deduplication to after Ack handling.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Seppo Takalo
48434a3c1b net: lib: coap_client: Return -errno from send_request()
Return the -errno when zsock_sendto() or zsock_recvfrom() fails, so
rest of the code can deal with return values, instead of separately
comparing errno and return value.


Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Seppo Takalo
a1368a7ff7 net: lib: coap_client: Drop duplicate responses
When response is already handled, don't forward anymore responses
to the client application.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Seppo Takalo
934c74f26e net: lib: coap_client: Don't match zero length tokens
If our internal structure is cleared, don't match tokens.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Seppo Takalo
7b0cce4418 net: lib: coap_client: Parse incoming MID only once
Incomming Message-ID is already parsed, use it as a parameter to
get_request_with_mid().

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Seppo Takalo
41ee35ae8b net: lib: coap_client: Don't clear internal structures on response
When response is received and handled, don't just clear the structure
but instead mark it as ongoing=false.
So if we later on receive a duplicate response for it, we can still
respond with Ack or Rst.

This is achieved by using release_internal_request() when we don't
expect any response for it and reset_internal_request() when we really
fill up a new request.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-11-16 13:33:28 -05:00
Jukka Rissanen
04d8b7c595 net: sockets: Cleanup socket properly if POSIX API is enabled
The sock_obj_core_dealloc() was not called if close() is called
instead of zsock_close(). This happens if POSIX API is enabled.

Fix this by calling zvfs_close() from zsock_close() and then
pass the socket number to zsock_close_ctx() so that the cleanup
can be done properly.

Reported-by: Andreas Ålgård <aal@ixys.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-08 15:56:39 -06:00
Jukka Rissanen
fe56ce5a1c net: ipv6: fragmentation: Drop the packet if fragmentation fails
If we could not fragment the IPv6 packet, then drop it and do
not try to send it. Let the upper layer re-send the packet if
needed. It is causing more trouble if we try to send the packet
and not honor the MTU setting.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-11-08 11:37:49 -06:00