Commit graph

7,037 commits

Author SHA1 Message Date
Seppo Takalo
bc86bf20cb net: l2: ppp: Allow using zero asyncmap locally
The L2 PPP driver was not working for any other
Async-Control-Character-Map values than 0xffffffff.

This was caused by two issues:
* modem_ppp.c was expecting CONTROL field to be always escaped.
* lcp.c was decoding async_map values wrongly. Either as 16bit,
  or raw 32bit, instead of big-endian 32 bit.

Now it should be safe to default my_options.async_map to a zero.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2026-03-13 16:33:05 +01:00
Seppo Takalo
412d48ef31 net: l2: ppp: Async-Control-Character-Map updated too early
When peer sends the Async-Control-Character-Map option on LCP
phase, Zephyr correctly responsed with Configure-Ack.
But the LCP negotiation phase have not been finnished yet,
so the remote end may not expect us to immediately
update the value.

This is seen when trying to use Zephyr's PPP stack against
PPPD from Linux, where default asyncmap option is zero.

However, if we delay the update of the asyncmap to the network phase,
it works just fine.

Fixes #105291

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2026-03-13 16:32:32 +01:00
Michael Ellerman
5d653fcfd4 net: lib: http_server: Reject over length websocket key header
If CONFIG_HTTP_SERVER_MAX_HEADER_LEN is increased from the default of
32, a compiler warning pops in the HTTP websocket code:

    zephyr/subsys/net/lib/http/http_server_http1.c:
    In function 'on_header_value':
    zephyr/subsys/net/lib/http/http_server_http1.c:898:33:
    warning: 'strncpy' output may be truncated copying between 0 and 32
    bytes from a string of length 47 [-Wstringop-truncation]
      898 |          strncpy(ctx->ws_sec_key, ctx->header_buffer,
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      899 |                  MIN(sizeof(ctx->ws_sec_key), offset));
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This comes from:

                if (ctx->websocket_sec_key_next) {
    #if defined(CONFIG_WEBSOCKET)
                         strncpy(ctx->ws_sec_key, ctx->header_buffer,
                                 MIN(sizeof(ctx->ws_sec_key), offset));
    #endif

If eg. header_buffer is 48 bytes and holds a string >= 32 bytes then
ws_sec_key can end up non-nul terminated. That can then lead to buffer
overflow in handle_http1_to_websocket_upgrade().

Add a check to make sure the header value fits in ws_sec_key, if not
reject the request with a HTTP 500. The websocket key is not expected to
be > 31 bytes.

Once the check is in place, it's safe to use memcpy() for the copy, and
then add the terminating nul manually.

Signed-off-by: Michael Ellerman <mpe@oss.tenstorrent.com>
2026-03-13 07:09:44 +01:00
Pieter De Gendt
aad056a7bc net: lib: coap: observer: Use struct net_sockaddr_storage
Replace the incomplete struct net_sockaddr with net_sockaddr_storage for
CoAP observers.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-12 14:06:27 -05:00
Pieter De Gendt
134e06c7d9 net: lib: coap: server: Use struct net_sockaddr_storage
Replace the net_sockaddr struct with a net_sockaddr_storage struct.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-12 14:06:27 -05:00
Li Long
bf31fab429 net: wifi: shell: Add check for iface type when get iface
When we start uAP by specifying the network interface "-i" like this:
    wifi ap enable … -i 1
(here: 1 is STA iface, 2 is uAP iface)

Currently, get_iface() uses interface index to choose the network
interface, but we do not check if the selected interface is correct
type.

So if the user specified interface is valid interface, we then verify
that it matches the given type. If there is no match, we return an
error and do not select a default type interface.

Signed-off-by: Li Long <li.long@nxp.com>
2026-03-12 14:06:05 -05:00
Jordan Yates
ca0815a856 net: lib: sntp: output response delay
Add a new field to the `sntp_time` struct which is an estimate of the
delay between the SNTP server sending the response and the SNTP client
(the application) receiving it. This information can then be used by
the caller to correct for the systemic bias introduced by non-zero
network latencies.

Includes internal variable naming to make it clearer which timestamps
are which.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-03-12 11:34:52 +01:00
Fin Maaß
52c254af76 net: add Kconfig option for checksum offloading
Adds a Kconfig option to detect if checksum offloading
is supported by any driver and one to activate it.

Main benefit is that `net_if_need_calc_rx_checksum()` and
`net_if_need_calc_tx_checksum()` are now inline and therefore the
compiler can optimize more, when checksum offloading is not supported.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-03-11 17:52:13 +00:00
Jordan Yates
0bf99fa4e4 net: ip: net_core: remove conn_mgr_if_used on RX
Remove the unconditional `conn_mgr_if_used` call on data reception.
Receiving data ends up being a poor metric for "interface in use" in
many situations. This is especially the case when connected to networks
with broadcast packets that are not necessarily relevant for us, such as
ARP discovery requests.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-03-11 17:50:02 +00:00
Jordan Yates
4a2374c7a1 net: lib: sntp: SNTP_UNCERTAINTY consistent time sources
When comparing time sources for `CONFIG_SNTP_UNCERTAINTY` to validate
the server responses, `dest_ts_us` and `orig_ts_us` need to be
constructed from the same time sources and have the same offsets applied
in order for math operations to be valid.

Fixes #105101

Signed-off-by: Jordan Yates <jordan@embeint.com>
2026-03-10 18:00:49 -07:00
Jani Hirsimäki
3eeff9e1ef net: ipv6: check on-link prefix before falling back to default router
When routing packets, check if the destination address matches an
on-link prefix on any interface before using the default router.
This ensures packets destined for on-link prefixes are not
incorrectly sent to the default router.

Signed-off-by: Jani Hirsimäki <jani.hirsimaki@nordicsemi.no>
2026-03-10 12:39:06 +01:00
Pieter De Gendt
e7fae7a37e net: lib: coap: client: Add multicast support
Allow sending a CoAP GET request to a multicast address and receive
multiple responses.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-10 09:32:24 +01:00
Pieter De Gendt
fe6c5e25cd net: lib: coap: client: Add const qualifier to helper functions
Make arguments that are not modified in the helper function const.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-10 09:32:24 +01:00
Tomi Fontanilles
f2615043c4 modules: mbedtls: add Kconfig option for MBEDTLS_X509_CRT_PARSE_C
Add a dedicated Kconfig option for this previously hidden and
automatically enabled Mbed TLS configuration.
Make the relevant key exchange Kconfig options depend on it.
Enable it explicitly where needed.
Fix the condition for defining MBEDTLS_X509_USE_C (based on
mbedtls_config.h).
Check for CONFIG_MBEDTLS_X509_CRT_PARSE_C instead of
MBEDTLS_X509_CRT_PARSE_C now that we have a Kconfig option for it.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2026-03-09 11:13:40 -05:00
Kapil Bhatt
6cecb912e7 net: Add WEP security support
Add WEP security support in Wi-Fi mgmt ops.
Need to enable Kconfig CONFIG_WIFI_NM_WPA_SUPPLICANT_WEP.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2026-03-06 11:36:24 +00:00
Pieter De Gendt
16aded5d1f net: lib: sockets: tls: Use struct net_sockaddr_storage for stack variables
Replace instances of struct net_sockaddr with struct net_sockaddr_storage
for stack variables.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-06 11:34:00 +00:00
Pieter De Gendt
74732cd6fc net: lib: sockets: tls: Use struct net_sockaddr_storage for caches
Storing a socket address should be done with the designated struct
net_sockaddr_storage type instead of the opaque struct net_sockaddr.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-06 11:34:00 +00:00
Pieter De Gendt
bcc4c0bb1e net: lib: sockets: tls: Validate addrlen before memcpy
Prevent writing data that is larger than the destination struct's size.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-06 11:34:00 +00:00
Pieter De Gendt
af4749d0a0 net: lib: coap_client: Store destination address in request
A CoAP client should not be limited to a single destination address for all
requests.
Store the destination address for each request or use the existing socket
directly.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-06 10:07:35 +01:00
Pieter De Gendt
a69f9e2fb9 net: lib: shell: ping: Validate identifer/sequence on response
Check if the ping reply is a response to our ping request.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-06 10:06:42 +01:00
Pieter De Gendt
50578b8aa8 net: ip: icmp: Change net_icmp_handler_t return type to enum net_verdict
Update the return type of the ICMP callback handler to enum net_verdict.
This fixes an issue where currently all ICMP handler are passed the same
pkt. Handlers could have modified the passed packet resulting in undefined
behavior.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-03-06 10:06:42 +01:00
Jukka Rissanen
6561cd064e net: http: Allow user to turn off HTTP/1 or HTTP/2 in server
If user does not need HTTP/1 or HTTP/2, then it is possible
to turn off support for them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-03-05 16:10:26 +01:00
Robert Lubos
a909dc8296 net: ipv6: mld: Return 0 if address was already joined
In case address was already joined, return 0 instead of an error code to
avoid confusion.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
f84eeb9deb net: ipv4: igmp: Return 0 if address was already joined
In case address was already joined, return 0 instead of an error code to
avoid confusion.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
c8644d6899 net: iface: Join multicast IPv6 addresses only once on iface up
Make sure autoconfigured multicast IPv6 addresses are added (and thus
referenced) only once when the interface goes up to avoid mounting refs
for a given address.

Even if address is already present and net_ipv6_mld_join() is skipped
for a given address it's not an issue as all unjoined addresses have
their reports sent on interface going up via net_ipv6_mld_rejoin().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
79e0a01ab1 net: iface: Clear is_joined flag when allocating mcast address
When allocating new multicast address, clear the is_joined flag as it
could've still be set from the previous allocation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
e62a77ddf3 net: shell: ipv4: Print also multicast address details
For each interface, print also details about registered multicast
addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
4ea96483b4 net: shell: ipv6: Print also multicast address details
For each interface, print also details about registered multicast
addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
6ec8a43045 net: iface: Don't re-register mcast addresses on iface up
We just need to resend the report, not add the address again.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
cb4a2eb534 net: ipv6: mld: Add helper function to rejoin mcast groups
Add helper function that allows to rejoin multicast groups without
registering an address. This is needed in case we just want to send
report w/o increasing the ref count of the multicast address (when
interface goes up for example).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
a9f78d65b1 net: ipv4: igmp: Add helper function to rejoin mcast groups
Add helper function that allows to rejoin multicast groups without
registering an address. This is needed in case we just want to send
report w/o increasing the ref count of the multicast address (when
interface goes up for example).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
4e2abc0118 net: ipv6: mld: Remove redundant inteface state check
Network interface state is now checked down the line in
net_try_send_data() so a separate check in the MLD code was redudant,
hence remove it to simplify the code.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
2f17aaa5c7 net: ipv6: mld: Make use of mcast address ref counting
Don't send MLD report on join if the address was already joined,
only increase the ref count by calling net_if_ipv6_maddr_add().

On leave, only send report if the address was removed from the system
(i.e. is no longer in use).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
3740a03136 net: ipv4: igmp: Make use of mcast address ref counting
Don't send IGMP report on join if the address was already joined,
only increase the ref count by calling net_if_ipv6_maddr_add().

On leave, only send report if the address was removed from the system
(i.e. is no longer in use).

For IGMPv3 specifically, if the address with non-empty include/exclude
list was already registered, return an error as registering lists from
different sources is currently not supported.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Robert Lubos
e1854efd3b net: iface: Add multicast address ref counting
Add ref counting for multicast addresses, so that if a multicast address
is registered from different subsystems, they won't interfere with each
other. That way, if one subsystem decides to remove a multicast address,
it won't affect other subsystems that may still need it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-03-04 16:43:42 +00:00
Adam Wojasinski
5b32348c1b net: ptp: Fix undefined bitwise shift in port management
Add bounds checking to PTP management interval parameters to prevent
undefined behavior from bitwise shift operations.

The port_timer_set_timeout() and port_timer_set_timeout_random()
functions perform left and right shift operations using the
log_announce_interval and log_sync_interval values as shift counts.
Without bounds validation, these int8_t parameters could be set to
extreme values (e.g., via PTP management messages) that exceed the
valid shift range, causing undefined behavior.

(C11, 6.5.7p3)
> If the value of the right operand is negative or is greater than
or equal to the width of the promoted left operand,
the behavior is undefined

(C++11, 5.8p1)
> The behavior is undefined if the right operand is negative,
or greater than or equal to the length in bits of the promoted
left operand.

Limit both log_announce_interval and log_sync_interval to the range
[-63, 63] using MIN/MAX macros when accepting values from PTP management
frames. This range is preventing shift operations outside
the 64-bit width used in the timeout calculations.

Fixes: GHSA-3v98-458v-388r

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2026-03-02 15:57:04 -08:00
Robert Lubos
5ab02c7e7a net: ip: Allow to specify default router with net_if_ipv6_router_add()
Align the net_if_ipv6_router_add() behavior with its IPv4 counterpart,
where it is possible to specify whether the router is a default one
instead of making assumptions based on the lifetime value.

The current behavior was likely inspired by the Neighbor Discovery RFC,
where the lifetime parameter of 0 received in the Router Advertisement
message indicates that the router should not be treated as a default
router, however this is an implementation detail of the Neighbor
Discovery protocol and does not need to be enforced at the router API
level, as this can be used outside of this protocol (for example when
router is added manually from the application).

Therefore, allow to specify the "is_default" parameter separately just
like in the IPv4 case.The Router Advertisement handling routine will
just specify the "is_default" value based on the received lifetime
value.

Also, clarify in the function documentation what does it mean to specify
lifetime to 0 (which means the router never expires according to current
implementation).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-02-27 21:03:52 +00:00
Henrik Brix Andersen
b439029296 net: lib: sockets: can: always verify length in zcan_sendto_ctx()
Always verify the length in zcan_sendto_ctx().

Fixes: #104652

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2026-02-27 15:31:55 +01:00
Tim Pambor
4d6de96ad4 net: ipv4: avoid casting unaligned address to net_in_addr
This change addresses an alignment problem reported by UBSAN by
using a copy of the address. This avoids the need for extensive
rework to support net_if_ipv4_maddr_lookup_raw variant.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2026-02-27 15:31:26 +01:00
Alberto Escolar Piedras
eed8d23140 net: shell: pmtu: Fix net API use
In d45cd6716b the mayority of the
Zephyr codebased was changed to use the Zephyr native net_ prefixed
types, but some were forgotten.
Without this fix/change the code still builds as we are by now setting
CONFIG_NET_NAMESPACE_COMPAT_MODE. But when this is not set, things
fail to build.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-02-27 13:56:24 +01:00
Alberto Escolar Piedras
4e04b519d1 net: sockets: tls: Fix net API use
In d45cd6716b the mayority of this code
was changed to use the Zephyr native net_/zsock_ prefixed types/functions
but some were forgotten.
Let's fix it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-02-27 13:56:24 +01:00
Alberto Escolar Piedras
6ef9e8f2d2 net: lwm2m: Use ZTESTABLE_STATIC instead of STATIC
Use the ZTESTABLE_STATIC macro to define symbols which need to be
accessible from ztests, instead of redefining STATIC which causes
trouble with some hals.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-02-27 11:50:41 +01:00
Alberto Escolar Piedras
8c06719191 net: lwm2m: Remove use of fcntl.h macros from messages
Just for consistency with the code and to avoid finding them on searches,
use the actually used macro names in the log messages.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-02-26 21:25:31 +00:00
Valerio Setti
e8cb9ba0d7 net: lib: http_server: remove legacy Mbed TLS header inclusion
This was a leftover from the previous commit that removed usage of
legacy crypto in favor of PSA API.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-02-26 08:48:27 -06:00
Julien Vermillard
0a64b9aae3 net: lwm2m: send scheduler: gate path formatting to DBG logs
The send scheduler formatted LwM2M paths with `lwm2m_path_log_buf()` even
when debug logging was not enabled for the module, causing build issues
with CONFIG_LOG off.

Signed-off-by: Julien Vermillard <julien@clunkymachines.com>
2026-02-25 13:23:07 +01:00
Robert Lubos
caa6273301 net: shell: Add FTP module
Add FTP shell module covering basic FTP client operations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-02-24 15:37:25 +01:00
Robert Lubos
991ea36f70 net: lib: ftp_client: Add FTP client library
Add FTP client library, based on the FTP client library from nRF Connect
SDK.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2026-02-24 15:37:25 +01:00
Jukka Rissanen
0747bca9e1 net: ipv4: Do packet length checks before starting fragment reassembly
Make sure to check packet length check before starting the
IPv4 fragmentation reassembly process. This way we can drop the
malformed packet without consuming resources.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-02-24 13:53:25 +01:00
Jukka Rissanen
3a40c90b98 net: dns: Check that DNS packet contains also query type and class
When receiving a DNS query, make sure that the packet contains
also query type and class fields before trying to access them.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2026-02-23 08:53:00 +01:00
Jay Beavers
f5867550af net: usbd: Set default traffic class TX count
Fixes zephyrproject-rtos/zephyr#103442
Origin: Original

Adds a separate TX traffic class for CDC-ECM and CDC-NCM in USBD Next
to prevent a deadlock during interface provisioning.

Tested with a custom nRF53-app firmware which combines CDC-ECM /
CDC-NCM (both tested) with mDNS with USB hosts MacOS, iPadOS, and
Alpine Linux.

Signed-off-by: Jay Beavers <jay@tolttechnologies.com>
2026-02-21 15:34:44 +00:00