Commit graph

7,037 commits

Author SHA1 Message Date
Simon Piriou
f186218e42 net: l2: ieee802154: add support for MLME coordinator address
There are two ways in the current implementation to join a network,
either with an association request or a via MLME-SET(macShortAddress) to
rejoin a previously associated network.

The coordinator address needs to be valid in the rejoin case. It can be
lost, for example if the device power cycles. This commit fixes that gap
with new MLME GET/SET for:
- macCoordShortAddress
- macCoordExtendedAddress

Signed-off-by: Simon Piriou <spiriou31@gmail.com>
2025-12-01 12:24:05 -05:00
Simon Piriou
b87b17502f net: l2: ieee802154: skip filter removal for unassociated values
Trying to remove filter with NOT_ASSOCIATED parameter results in noisy
warning logs in most of the radio drivers. It's safe to ignore it as
this is an invalid operation.

Signed-off-by: Simon Piriou <spiriou31@gmail.com>
2025-12-01 12:23:56 -05:00
Valerio Setti
1969f493e3 net: lib: midi2: remove unnecessary cipher selection in mbedtls-shim driver
Cipher support is already implied by default so there is no need to
select it explicitly.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-12-01 08:26:29 +01:00
Aurelien Jarno
78a3890acb net: mqtt_sn: udp: enforce maximum address size at build time
Introduce BUILD_ASSERT checks in the UDP transport implementation to
ensure the configured maximum address size is large enough for the
enabled IP families.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2025-11-28 22:10:40 +00:00
Aurelien Jarno
05b9ffb390 net: mqtt_sn: document address size and add support for IPv6
Add guidelines in Kconfig explaining the minimum required
MQTT_SN_LIB_MAX_ADDR_SIZE for UDP transport and IPv4 and or IPv6. Also
explain when this value might need to be changed.

Use these values to provide a sane default for IPv4 and IPv6.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2025-11-28 22:10:40 +00:00
Robert Lubos
f908d0b5f2 net: shell: Verify array index during dynamic iface completion
Verify that the interface index, converted to array index,
 does not exceed the preallocated string array for dynamic index
completion.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-27 21:56:37 +01:00
Robert Lubos
852a1e8104 net: sockets: getnameinfo: Cast to sockaddr_in6 instead of sockaddr_in
As explained in the comment in the code, both structs have the same
offsets for it's fields, but sockaddr_in is smaller, hence it can
confuse static analyzer, giving warnings about potential out-of-bound
access. Therefore, cast to sockaddr_in6 instead to avoid the warning.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-27 21:55:12 +01:00
Robert Lubos
a00fefc5a9 net: sockets: tls: Specify a separate Kconfig option for TLS timeout
It's been periodically reported that the default connect timeout shared
with regular TCP sockets (3 seconds) is not enough for the TLS handshake
to complete. Therefore, it'd make sense to increase the default value
for TLS sockets specifically. However currently the option is used by
both TCP and TLS connections, which makes this impractical.

Therefore, introduce a separate CONFIG_NET_SOCKETS_TLS_CONNECT_TIMEOUT
Kconfig option for TLS sockets specifically, and set the default to 10
seconds. For samples/tests that modified the old option for TLS-specific
purpose, update the new option value as well.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-27 14:45:32 +01:00
Robert Lubos
996a0f445c net: sockets: tls: Fix timeout error code for blocking accept()
In case a handshake timed out on a blocking accept() call, the TLS
socket would return EAGAIN error which is ambiguous and not intuitive.
Report ETIMEDOUT instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-27 14:45:32 +01:00
Aurelien Jarno
5f5db5bf3c net: mqtt_sn: udp: use correct get/setsockopt parameters for IPv6
On IPv6, IPPROTO_IPV6 needs to be replaced by IPPROTO_IP and
IP_MULTICAST_TTL by IPV6_MULTICAST_HOPS.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2025-11-27 11:35:03 +01:00
Aurelien Jarno
5e3bf02e50 net: mqtt_sn: udp: ignore EALREADY when adding multicast addresses
On IPv6, the host is subscribed to a few multicast addresses by default.
Reusing such an address for MQTT-SN leads to an EALREADY error. Ignore
this error instead of returning. Do the same for IPv4 for consistency,
and because it could happen if the multicast address has already been
added manually from another part of the code, although this is really a
corner case.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2025-11-27 11:35:03 +01:00
Aurelien Jarno
e3013fe5c2 net: mqtt_sn: udp: reserve enough space to hold an IPv6 address
The current allocated buffer for storing the IP address is not always
large enough to hold an IPv6 address.  Instead of using a hard-coded
value, use NET_INET6_ADDRSTRLEN, which covers all cases, including
possible mapped IPv4 addresses.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2025-11-27 11:35:03 +01:00
Aurelien Jarno
05dd10c3f1 net: mqtt_sn: udp: fix return value in case of error
errno returns a positive value, while the API specifies that a negative
value is returned in case of error. Therefore replaces "return errno" by
"return -errno".

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2025-11-27 11:35:03 +01:00
Simon Piriou
25f667a6a0 net: l2: ieee802154: don't use net_context->local for AF_PACKET sockets
There is an issue with AF_PACKET sockets bound to ieee802154 l2 iface.
The socket keeps track of the iface link_addr with a sockaddr_ll_ptr
structure, with sll_addr pointing to the iface link_addr address, and
sll_halen being a copy of the iface link_addr length.

The iface link address for ieee802154 can change during association
between extended address (8 bytes) and short address (2 bytes). The
iface link_addr s correctly updated, but the sll_halen of already bound
sockets is not, as it's a out of sync local copy.

This commit fixes #99711 by replacing all the sll_halen usage for
AF_PACKET socket with the iface link_addr length directly on recv and
send paths.

Signed-off-by: Simon Piriou <spiriou31@gmail.com>
2025-11-27 11:34:54 +01:00
Andrew Kontra
c47de21db3 net: Using const char * in net_hostname_set()
When calling net_hostname_set() from C++, you will hit compile
errors if you attempt to use a const char *. Since the internals
of net_hostname_set() just uses memcpy(), we should pass in the
new hostname as a const char * to better support C++.

Tested using samples/cpp/hello_world, with an added call to
net_hostname_set().

Signed-off-by: Andrew Kontra <andrew@legatoxp.com>
2025-11-26 11:06:34 +00:00
Robert Lubos
0f9131e351 net: tcp: Fix out-of-bound warnings in debugging code
A few debug logs in TCP code relied on a fact that IP address offset is
the same in struct sockaddr_in and sockaddr_in6. However, the logs
casted the address to struct sockaddr_in, which is smaller than
sockaddr_in6, causing theoretical out-of-bounds access warnings in IPv6
case. Fix this by casting to struct sockaddr_in6 instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-25 19:25:05 +00:00
Saravanan Sekar
d837c9531e net: lib: ocpp: cleanup outdated code from initial design
Cleanup outdated code from initial design.

Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
2025-11-25 16:07:44 +00:00
Jukka Rissanen
2d7d56964c net: shell: filter: Convert to use Zephyr APIs
The filter shell used POSIX symbols so replaced them by
Zephyr APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-25 16:06:56 +00:00
Jukka Rissanen
e458197499 net: ptp: Convert to use Zephyr network APIs
Couple of POSIX API leftovers replaced by Zephyr network APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-25 16:06:56 +00:00
Robert Lubos
741ce37f28 net: config: sntp: Asynchronous resynchronization
Make SNTP resynchronization asynchronous, so that it doesn't block the
system work queue while waiting for response.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-25 13:07:13 +01:00
Robert Lubos
550e0b866c net: config: sntp: Add helper symbols for resync timeouts
For more concise code.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-25 13:07:13 +01:00
Robert Lubos
a1e4047e38 net: config: sntp: Add helper function to set clocks
Move the code responsible for setting clocks into a helper function,
as it'll be reused with asynchronous resynchronization.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-25 13:07:13 +01:00
Nik Schewtschuk
d36c0bec85 net: l2: ppp: Add support for LCP MRU negotiation
Previously, the LCP MRU option sent by the peer was ignored.
This could result in the interface MTU remaining at the default (1500),
even if the peer requested a smaller MRU, potentially leading to packet
loss. This commit adds parsing for the peer's MRU option and updates the
network interface MTU accordingly.

Signed-off-by: Nik Schewtschuk <nik@schew.dev>
2025-11-24 17:36:18 +01:00
Robert Lubos
8b91d3abc3 net: websocket: Fix truncated string warning on copying
WS_MAGIC is a constant string and when calculating lengths for copying
we always exclude the NULL terminator. In result, using strncpy() for
copying can generate a warning about truncated string, as WS_MAGIC will
always be truncated from the NULL terminator. Therefore replace
strncpy() with memcpy() as it seems more appropriate for this case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-24 17:30:22 +01:00
Cristian Bulacu
b9542abf86 net: l2: openthread: border_router: Enhance modules deinit
This commit deinitializes platform modules when external network
interface is brought down. It also delets the multicast routes that are
added for OpenThread interface.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-11-21 11:42:46 -05:00
Alberto Escolar Piedras
1329a097c1 net: ocpp: Correct way of getting strdup prototype
Zephyr subsystems' headers should not duplicate C library prototypes
(in this case strdup(), which is either ISO C23 or a POSIX extension to
the C library <string.h>).

Instead they should request those prototypes from the C library.
By now Zephyr only requires ISO C17, but many C libraries will have
strdup() and expose it also when the POSIX extensions prototypes are
requested, so let's request these prototype from the C library by
setting the feature test macro _POSIX_C_SOURCE to version 2008.09
which includes it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-11-21 11:42:33 -05:00
Robert Lubos
7bd45cd39b net: dns: Fix potential buffer overflow when unpacking labels
As the loop unpacking the DNS name from records checks the current
label length on each iteration, it's also needed to update the remaining
buffer length on each iteration, otherwise the buffer length checks
doesn't work as expected.

Additionally, the remaining buffer checks while technically worked, they
were conceptually wrong and unintuitive. The buf->data pointer doesn't
move, so comparing against this pointer when adding new labels doesn't
make sense. It's more intuitive to simply compare the label size vs
the remaining buffer space.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-21 11:40:44 -05:00
Robert Lubos
6be292c35e net: tcp: Wake pending threads if non-blocking connect fails
If a thread was sleeping in poll(), monitoring POLLIN only, it should
still be notified if an asynchronous connection, triggered by
non-blocking connect(), failed. Currently that's not the case.
In result the application would never know whether the connection
was successful or not and would be stuck with a disconnected socket
that would not report anything with poll().

This was not an issue if POLLOUT was monitored as well, because POLLOUT
sets up a connect semaphore that was reset in case of errors. POLLIN
however only monitors the recv fifo, which was not waken up in such
case.

Fix this by canceling any pending waits on recv fifo and recv
condition variable.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-21 09:47:50 -05:00
Jukka Rissanen
61d57c35ff net: Disable namespace compatibility support for tests
Do not enable network compatibility mode flag for network tests
so that we will get better coverage of the wrong network APIs
used.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-21 12:01:31 +01:00
Alberto Escolar Piedras
8ecbda3283 net: lwm2m: Remove use of fcntl.h
Use the underlaying zsock_ prefixed fcntl macros instead of the
POSIX_API fcntl renames.
After d45cd6716b and this, we do not
anymore use fcntl directly but use the underlaying Zephyr APIs.
So, let's also remove this include.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-11-21 12:01:31 +01:00
Jukka Rissanen
8046a24104 net: Fix network API calls that were not namespaced
Some of the networking calls were not namespaced so fix it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-21 12:01:31 +01:00
Peter Büchler
8d01323b2f net: lib: ptp: fix BTCA grandmaster selection and related state transition
The BMCA comparator ptp_btca_ds_cmp() did not follow the IEEE1588
ranking order: priority fields handled only the “greater” case, causing
valid winners to fall through to the clockIdentity tie-breaker and
resulting in incorrect grandmaster selection. This also caused the
state transition from TIME_TRANSMITTER to GRAND_MASTER to be missed.

Fixes: #99562
Fixes: #99566

Signed-off-by: Peter Büchler <peter.buechler@gmail.com>
2025-11-21 11:59:49 +01:00
Robert Lubos
da5c9c8630 net: sockets: tls: Prefix overlooked CID-related symbols
Some CID-related symbols were prefixed but not updated in sockets_tls.c
as that configuration was not built by the tests/net/all test suite,
hence easy to miss.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-11-20 17:15:15 +00:00
Kfir Bracha
c53f050e02 net: http_server: Support reason phrase for chunked encoded response
Add HTTP reason phrases in chunked transfer-encoded responses

Signed-off-by: Kfir Bracha <kfirous@gmail.com>
2025-11-20 17:15:05 +00:00
Alberto Escolar Piedras
764e21032f net: l2: wifi_shell: remove unnecessary include
Since we are using sys_getopt now we do not need to pull unistd.h
for anything amore.
Let's remove it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-11-20 17:14:57 +00:00
Alberto Escolar Piedras
c3cd5d1c86 subsys/net wifi/wifi_shell: Fix use of sys_getopt global status
sys_getopt has now its global status variables prefixed with sys_getopt_
Let's fix the use here. Note this worked as Zephyr's POSIX_C_LIB_EXT
keeps a replica of these variables without the prefix.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-11-20 17:14:57 +00:00
Jukka Rissanen
77bdec412f net: openthread: Remove invalid assert
There is no openthread_instance so the assert will always fail so
remove it to prevent compilation issue.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-20 16:00:46 +00:00
Alberto Escolar Piedras
9fee526365 net: Fix EVENTFD kconfig selection
Since 820cd34dbb these net components
use ZVFS_EVENTFD directly instead of thru EVENTFD.
So, let's select ZVFS_EVENTFD directly instead of indirectly
thru EVENTFD.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-11-19 15:53:19 -05:00
Jukka Rissanen
22f9ef0a33 sys: getopt: Rename getopt to sys_getopt to avoid conflicts with Posix
Summary:

As Zephyr getopt is not really compatible with Posix getopt, rename
Zephyr getopt to sys_getopt.

Background:

Zephyr getopt module was introduced in #31356 to be used by the shell.
Zephyr's getopt is not the standard one. It has multiple APIs which make
it more suited for a system like Zephyr where different components may
want to use it for different purposes. Including APIs to init it,
get and set its internal state etc.
Several Zephyr modules (shell, net, wifi, ztest) use this getopt with
these special APIs. The getopt module is bundled in the POSIX
compatibility API subsystem (CONFIG_POSIX_C_LIB_EXT).

Problem description:

As it is not the standard getopt(), no C library can possibly provide
a Zephyr compatible version (even if such C library were to provide a
standard getopt()). As it is bundled in Zephyr's POSIX API in
CONFIG_POSIX_C_LIB_EXT), multiple components that depend on it are
selecting CONFIG_POSIX_C_LIB_EXT. Zephyr core components should not
depend on the POSIX API in this way.

Changes done in this commit:

Rename the getopt*() APIs to sys_getopt*() and move them into a module
under lib/utils with its own Kconfig option to enable it.
Zephyr's users are changed to use this new component.
The POSIX subsystem can continue providing getopt() by calling the new
sys_getopt() and in that way retain backwards compatibility for external
users.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-18 10:46:29 -05:00
Jukka Rissanen
55457ee4b8 net: zperf: Change old code to pass compliance checker
Compliance checker complains

   TYPO_SPELLING: 'in in' may be misspelled - perhaps 'is in'?

for code like this

   static struct net_sockaddr_in in_addr_my = {

so change the variable to ipv4_addr_my. Similar change is
done for IPv6 variables for consistency.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-17 14:01:32 -05:00
Jukka Rissanen
6c18fd348c net: sockets: Remove Posix header file includes
Do not include Posix header files inside network stack as we should
not depend on Posix symbols in net stack.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-17 14:01:32 -05:00
Jukka Rissanen
d45cd6716b net: Convert network codebase to use renamed network APIs
Rename network symbols in network stack to use the renamed network APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-17 14:01:32 -05:00
Jukka Rissanen
a63dbfb6cc net: Namespace network symbols to avoid conflicts with Posix/libc
Rename network symbols i.e., add net_, NET_ or ZSOCK_ prefixes
to those network symbols that can be found in Posix or libc.
This way we can avoid circular dependency issues.

Add also a compatibility header file that allows user to continue
use various network APIs without adding either net_, NET_ or ZSOCK_
prefixes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-17 14:01:32 -05:00
Josuah Demangeon
9bd94fab14 style: subsys: apply coding style on CMakeLists.txt files
Apply the CMake style guidelines to CMakeList.txt files in subsys/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-11-17 13:48:03 -05:00
Joel Schaller
f22899e80c net: http_server: No Error ENETDOWN
Set Log Level to Info when the HTTP socket reports ENETDOWN,
instead of logging an error each time the network is down.

Signed-off-by: Joel Schaller <joel.schaller16@gmail.com>
2025-11-17 09:15:54 -05:00
Cristian Bulacu
0a3de5b07d net: l2: openthread: Add NAT64 code for border router app
This commit enables NAT64 functionality for border router application.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-11-17 09:15:16 -05:00
Fengming Ye
478fad83e9 net: zperf: udp upload clock compensate
When clock accuracy is 1KHz or lower, udp_upload rate has
much lower accuracy. eg. 20M rate has 60M actual throughput.
It's because any packet_duration less than 1000us will be
treated as 1 tick. In this case rate cannot control throughput.

Add clock compensate when time clock is lower than 1KHz to fix it.
In every 10 ticks or longer delta time, calculate packets sent
actual number and expected number, and then compensate ticks.
And add compensate ticks to delay ticks count.

If we cannot compensate a minus ticks as delay cannot be negative,
add it to next compensate period.
If compensate sum ticks is lower than -1000, it means current rate
is higher than low level capability. So no need to compensate
in remaining traffic.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2025-11-15 11:33:09 +01:00
Yangbo Lu
58edd1b4db net: select NET_PKT_TIMESTAMP_THREAD for NET_L2_PTP
NET_L2_PTP requires NET_PKT_TIMESTAMP_THREAD. So, use
select instead.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-11-15 11:32:42 +01:00
Yangbo Lu
c1d213a86d net: net_if: remove redundant NET_PKT_TIMESTAMP_STACK_SIZE definition
Kconfig makes sure the NET_PKT_TIMESTAMP_STACK_SIZE with default value
1024 when NET_PKT_TIMESTAMP_THREAD is enabled.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-11-15 11:32:42 +01:00
Jani Hirsimäki
9800ff5c47 net: possibility to set custom link layer address length
This commit adds a new Kconfig option NET_LINK_ADDR_CUSTOM_LENGTH
that allows to set custom link layer address length if your link layer
technology is not supported directly. If this option is set to a value
greater than 0, that value is used as link layer address length.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2025-11-14 10:30:35 +02:00