Commit graph

6489 commits

Author SHA1 Message Date
Christoph Seitz
0e4cf09b55 net: sockets: Fix AF_PACKET sll_protocol in recvfrom
Convert the protocol value in return in recvfrom to
network byte order as expected.

Signed-off-by: Christoph Seitz <christoph.seitz@infineon.com>
2025-03-10 15:02:38 +01:00
Jukka Rissanen
d955af4e62 net: dns: Join mDNS multicast group for resolving
If mDNS resolver is enabled but mDNS responder is not, then
mDNS multicast address group is not joined. This would prevent
the mDNS resolver to receive the responses. Fix this by
joining the mDNS multicast group if mDNS responder is not
enabled (because the responder will join the group itself).

Fixes #86477

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-07 20:28:03 +01:00
Mathieu Anquetin
7282ea08e9 net: dhcpv4: fix deadlock issue
There is a deadlock issue when calling stop using address conflict
detection. This is due to the fact that some net_mgmt events are fired
and trigger the dhcpv4_acd_event_handler() with lock held even if they
are of no interest for this callback.

Therefore, before acquiring the lock, make sure the event we received
is one we are expecting.

Also, do the same for dhcpv4_iface_event_handler().

Signed-off-by: Mathieu Anquetin <mathieu.anquetin@groupe-cahors.com>
2025-03-07 20:22:58 +01:00
Carlo Kirchmeier
3d1370f094 net: http: Add compression support in HTTP server
Add compression support using the accept-encoding
header to the http server static filesystem resource.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
2025-03-07 20:19:44 +01:00
bac phan
7026f113d6 net: http: Add #ifdef guard file system in HTTP server
http_server_http2.c does not guard check if file system is available
or not before using file system api. This PR will add guard for that

Signed-off-by: bac phan <phanhaibac98@gmail.com>
2025-03-07 20:18:04 +01:00
Alberto Escolar Piedras
78f800642a drivers/ethernet/eth_native_posix: Rename to eth_native_tap
Rename this driver to eth_native_tap, including renaming all its
options.
The old options remain until v4.4, but as deprecated.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-07 20:10:38 +01:00
Jukka Rissanen
0f90affcdf net: http: server: Select POSIX_C_LIB_EXT instead of FNMATCH
The CONFIG_POSIX_C_LIB_EXT will get support for fnmatch() function.
The old CONFIG_FNMATCH is deprecated.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-07 20:03:27 +01:00
Jukka Rissanen
33cf7dc78a net: http: server: The detail length of wildcard detail was wrong
The path length of the detail resource was not set properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-07 20:03:27 +01:00
Seppo Takalo
334b32d9f5 net: coap_client: Stop lifetime on piggybacked Ack
When we receive piggybacked Ack, it means that we have
received all information for this request.
There is no need to track exchange lifetime anymore.

Once we reset the internal request, it is free to be used
for the application. So if we only have few requests allocated,
it would be slow to send those as get_free_request() only
gives request structures that don't have a lifetime left.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2025-03-07 20:01:26 +01:00
Maciej Baczmanski
6636adc706 openthread: Rework L2 configuration
- Add possibility to choose implementation of OpenThread L2 and
set it to Zephyr's by default
- Remove unused `OPENTHREAD_SECURITY_INTERNAL` Kconfig
- Add missing choice names for logging and coprocessor

Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
2025-03-07 19:59:07 +01:00
Cla Mattia Galliard
7d721ce63a net: icmp: Send replies with timeout K_NO_WAIT
This ensure system stays operational in icmp flood situation.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-03-07 19:58:45 +01:00
Cla Mattia Galliard
647ca57234 net: lldp: Send replies with timeout K_NO_WAIT
This ensures system stays operation in lldp-flood situation.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-03-07 19:58:45 +01:00
Cla Mattia Galliard
353e314fbf net: arp: Send replies with timeout K_NO_WAIT
This ensures system stays operational in arp-flood situation.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-03-07 19:58:45 +01:00
Cla Mattia Galliard
19f192cfb5 net: net_context: Make use of timeout for sending
Use the newly added timeout in various send functions from within
net_context_sendto.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-03-07 19:58:45 +01:00
Cla Mattia Galliard
5b89a5c4b8 net: add try variant with timeout for various send functions
Allows to send with different timeouts to not block caller in some
situations. Stable API is kept and just calls `try`-variant with a timeout
of `K_FOREVER`.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-03-07 19:58:45 +01:00
Povilas Selevicius
37ddeb459c net: coap_client: expose has_ongoing_exchange function
The coap_client has a static/internal function, has_ongoing_exchange(),
which can be an useful addition to the public API. This would provide
a mechanism to determine when it is safe to close a socket gracefully.

Signed-off-by: Povilas Selevicius <povilas.selevicius@quadigi.com>
2025-03-07 19:52:22 +01:00
Jordan Yates
7ab8e27e26 net: lib: sntp: async query API
Add a variant of the SNTP API that does not block while waiting for a
response from the SNTP server. Instead it takes advantage of
`CONFIG_NET_SOCKETS_SERVICE` to read the response asynchronously when
the response is received.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-03-07 19:51:40 +01:00
Jordan Yates
5178835677 net: lib: sntp: extract query send logic
Extract the SNTP query send logic out of `sntp_query` so that it can be
used by functions that don't synchronously wait for the response.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-03-07 19:51:40 +01:00
Noah Olson
b2e29fe0d7 net: tcp: fix ECONNREFUSED not reported by zsock_connect
When a TCP connection is refused during zsock_connect, errno is set
to -ENOTCONN, but errno should be set to -ECONNREFUSED. This change
causes the ECONNREFUSED status to be propagated from tcp_in to
net_tcp_connect, which eventually causes errno to be set
to -ECONNREFUSED.

Signed-off-by: Noah Olson <noah@wavelynx.com>
2025-03-07 19:48:10 +01:00
Etienne de Maricourt
7bc2a1bb47 net: lwm2m: Fix data cache rollback logic compilation
The root cause of this issue is a modification of `struct ring_buf` in
3075a7d9. Even though all the fields of the struct are marked as
internal, the LwM2M code is using some of them to roll back the state of
the ring buffer on failure.

Signed-off-by: Etienne de Maricourt <edmecomemail@gmail.com>
2025-03-06 11:38:09 +00:00
Jukka Rissanen
1a5e13a79b net: if: Release the interface lock early when starting IPv4 ACD
In order to avoid any mutex deadlocks between iface->lock and
TX lock, release the interface lock before calling a function
that will acquire TX lock. See previous commit for similar issue
in RS timer handling. So here we create a separate list of ACD
addresses that are to be started when network interface comes up
without iface->lock held.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-05 16:40:29 +00:00
Jukka Rissanen
196782ed91 net: if: Release the interface lock early when rejoining mcast groups
In order to avoid any mutex deadlocks between iface->lock and
TX lock, release the interface lock before calling a function
that will acquire TX lock. See previous commit for similar issue
in RS timer handling. So here we create a separate list of multicast
addresses that are to be rejoined when network interface comes up
and then rejoin the groups without iface->lock held.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-05 16:40:29 +00:00
Jukka Rissanen
1e88c62b4e net: if: Release the interface lock early when starting IPv6 DAD
In order to avoid any mutex deadlocks between iface->lock and
TX lock, release the interface lock before calling a function
that will acquire TX lock. See previous commit for similar issue
in RS timer handling.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-05 16:40:29 +00:00
Jukka Rissanen
4926698b1c net: if: Release the interface lock early in IPv6 RS timeout handler
The net_if.c:rs_timeout() is sending a new IPv6 router solicitation
message to network by calling net_if_start_rs(). That function will
then acquire iface->lock and call net_ipv6_start_rs() which will try
to send the RS message and acquire TX send lock.
During this RS send, we might receive TCP data that could try to
send an ack to peer. This will then in turn cause also TX lock
to be acquired. Depending on timing, the lock ordering between
rx thread and system workq might mix which could lead to deadlock.
Fix this issue by releasing the iface->lock before starting the
RS sending process. The net_if_start_rs() does not really need to
keep the interface lock for a long time as it is the only one sending
the RS message.

Fixes #86499

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-03-05 16:40:29 +00:00
Joakim Andersson
d082c7dc46 net: http_client: Fix handling of poll error revents
Fix handling of poll setting socket error flag.
In this case errno is no set, so should not be the return value either.
Instead retrieve the socket error for SOCKERR and return EBADF for
SOCKNVAL.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2025-02-27 13:27:28 +00:00
Robert Lubos
565a489fa9 net: tc: Ensure TC queueing works from ISR
Queueing packets should be possible from the ISR context, recent changes
prevented that. Therefore add extra checks in
net_tc_submit_to_tx/rx_queue() to make them ISR friendly again.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-24 15:36:32 +00:00
Adib Taraben
96526796d9 ptp: clock.c: revise offset calculation
cast differences to signed int to allow
negative numbers

Signed-off-by: Adib Taraben <theadib@gmail.com>
2025-02-21 18:35:34 +00:00
Tom Hughes
9838a03ad7 net: l2: ethernet: Fix unused function warning
Building with clang warns:

subsys/net/l2/ethernet/ethernet.c:178:18: error: unused function
'ethernet_check_ipv4_bcast_addr' [-Werror,-Wunused-function]
enum net_verdict ethernet_check_ipv4_bcast_addr(struct net_pkt *pkt,
                 ^

ethernet_check_ipv4_bcast_addr is called by ethernet_ip_recv, which only
exists when CONFIG_NET_IPV4 or CONFIG_NET_IPV6 is defined.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-21 04:46:26 +01:00
Jukka Rissanen
9ba79f009b net: arp: Fix ARP protocol handler to not use Ethernet hdr directly
The ARP protocol handler cannot directly access the Ethernet header
because the caller has removed the header already when the handler
is called. So change net_arp_input() and pass source and destination
MAC address there instead of bogus pointer that was pointing to ARP
header instead of Ethernet header. This requires changes to ARP tests.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-20 21:04:44 +01:00
Maochen Wang
2b2915bd98 net: ip: Fix low Zperf UDP throughput with -a
When run the Zperf UDP throughput with '-a' (Asynchronous call),
zperf_work_q thread will generate and send the packets to tx_q thread.
When zperf_work_q and tx_q threads have same priority, if zperf_work_q
fails to take the semaphore of fifo_slot, it will not wait and directly
drop the net_pkt. Then it will allocate new net_pkt, repeat, and always
occupy the CPU, which leads to extreme low throughput.
For TX, when take the semaphore of fifo_slot, setting a wait time of
K_FOREVER to let other thread to process and free these packets.
For RX, when failed to take the semaphore of fifo_slot, yield the CPU
to let the thread of data path with same priority to run to reduce
dropping packets.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2025-02-19 18:49:13 +01:00
Robert Lubos
008a7ca202 net: if: Setup DAD timer regardless of DAD query result
In rare occasions when sending DAD NS packet fails, we should still
setup the DAD timer, unless we implement some kind of more advanced
retry mechanism. If we don't do that, the IPv6 address added to the
interface will never be usable in such cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-19 18:48:52 +01:00
Robert Lubos
a09fd8e97f net: if: Clear neighbor cache when removing IPv6 addr with active DAD
DAD creates an entry in the neighbor cache for the queried (own)
address. In case the address is removed from the interface while DAD is
still incomplete, we need to remove the corresponding cache entry (just
like in case of DAD timeout) to avoid stale entries in the cache.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-19 18:48:52 +01:00
Benjamin Cabé
cc3fd97db0 net: ipv6: use inclusive terminology in net_ipv6_pe_filter_cb_t
Minor fix to use inclusive terminology for the is_blacklist flag.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-02-19 18:48:15 +01:00
Robert Lubos
7ccf870670 net: coap_client: Stop all socket activities when cancelling requests
Calling coap_client_cancel_requests() clears the internal request
context only for active requests (i. e. not replied yet). However,
if there are any pending request context monitoring ACK duplicates,
those would still make the corresponding client socket being monitored
by poll(). In result, when application closes the socket, the polling
thread will throw POLLNVAL error for the socket.

Fix this, by resetting all request contexts unconditionally. The request
callback will only be called for the active requests.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-18 13:31:15 +01:00
Rex Chen
a296b4968b net: wifi: L2 shell cmd 11v BTM query support embedded supplicant
Remove the CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM macro in L2 shell level
to make 11v BTM query support embedded supplicant.

Signed-off-by: Rex Chen <rex.chen_1@nxp.com>
2025-02-14 19:40:09 +00:00
Robert Lubos
02c153c8b1 net: ipv6: Fix Neighbor Advertisement processing w/o TLLA option
According to RFC 4861, ch. 7.2.5:

 "If the Override flag is set, or the supplied link-layer address
  is the same as that in the cache, or no Target Link-Layer Address
  option was supplied, the received advertisement MUST update the
  Neighbor Cache entry as follows

  ...

  If the Solicited flag is set, the state of the entry MUST be
  set to REACHABLE"

This indicates that Target Link-Layer Address option does not need to be
present in the received solicited Neighbor Advertisement to confirm
reachability. Therefore remove `tllao_offset` variable check from the
if condition responsible for updating cache entry. No further changes in
the logic are required because if TLLA option is missing,
`lladdr_changed` will be set to false, so no LL address will be updated.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-14 17:10:07 +01:00
Robert Lubos
8cd213e846 net: ipv6: Send Neighbor Solicitations in PROBE state as unicast
According to RFC 4861, ch. 7.3.3:

 "Upon entering the PROBE state, a node sends a unicast Neighbor
  Solicitation message to the neighbor using the cached link-layer
  address."

Zephyr's implementation was not compliant with behavior, as instead of
sending a unicast probe for reachability confirmation, it was sending a
multicast packet instead. This commit fixes it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-14 17:10:07 +01:00
Robert Lubos
fce53922ef net: ipv6: Fix neighbor registration based on received RA message
When Router Advertisement with Source Link-Layer Address option is
received, host should register a new neighbor marked as STALE
(RFC 4861, ch. 6.3.4). This behavior was broken however, because
we always added a new neighbor in INCOMPLETE state before processing
SLLA option. In result, the entry was not updated to the STALE state,
and a redundant Neighbor Solicitation was sent.

Fix this by moving the code responsible for adding neighbor in
INCOMPLETE state after options processing, and only as a fallback
behavior if the SLLA option was not present.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-14 17:10:07 +01:00
Helge Juul
b7bbfbf1f2 net: dns: Log with debug level instead of error level when recv fails
This condition can happen if there is MDNS activity on the network that is
either not according to specifications or not supported by Zephyr.

Lowering the log level from ERR to DBG, since this does not indicate an
error in the Zephyr application.

Signed-off-by: Helge Juul <helge@fastmail.com>
2025-02-14 10:48:06 +01:00
Tomi Fontanilles
0c368e85b1 secure_storage: add a global registry header file for PSA key IDs
We need to make sure that within Zephyr different users of the PSA APIs
don't interfere with each other because of using the same numerical IDs
for persistent assets.

This takes care of the PSA key IDs when using persistent keys through
the PSA Crypto API.
See the comments in `<zephyr/psa/key_ids.h>` for more information.

This removes the recently-introduced Kconfig options that allowed changing
the base IDs subsystems were using for their persistent keys.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2025-02-13 20:22:09 +01:00
Robert Lubos
05ac5497d5 net: dhcpv6: Add support for DNS Recursive Name Server option
Implement support for DNS Recursive Name option and use obtained
information to configure DNS resolver.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-12 20:19:26 +01:00
Robert Lubos
d0e5696a0e net: dhcp: Avoid source port validation in replies
There's nothing in RFC 2131 or RFC 8415 that would mandate the DHCP
server to reply with a source port set to the IANA assigned one, and
some servers seem to send responses with some arbitrary source port set.

Therefore, make Zephyr's DHCP client implementation more permissive,
accepting packets with a source port set to a different port than the
IANA assigned server port.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-12 16:03:57 +01:00
Fengming Ye
826f445c69 wifi: shell: add ACS case in ap enable cmd
In ap enable cmd, channel set to 0 means ACS mode.
Remove hostapd AP macro for this case to make ACS mode
available for public usage.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2025-02-12 12:23:35 +01:00
Robert Lubos
558e2a5556 net: lwm2m: Fix time resource validation
When writing to a time resource, the logic was incorrect when validation
was enabled for the resource - when determining the actual underlying data
type we should compare against the data buffer length and not the
validation buffer length.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-12 09:41:35 +01:00
Jukka Rissanen
ae05221762 net: Update IP address refcount properly when address already exists
If an IP address already exists when it is tried to be added to the
network interface, then just return it but update ref count if it was
not updated. This could happen if the address was added and then removed,
but for example an active connection was still using it and keeping the
ref count > 0. In this case we must update the ref count so that the IP
address is not removed if the connection is closed.

Fixes #85380

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-12 09:41:24 +01:00
Jukka Rissanen
908cfacd85 net: mdns_responder: Add announce support
After probing, send two unsolicited mDNS response messages
for our name.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-12 09:40:15 +01:00
Jukka Rissanen
9e79184f7e net: mdns_responder: Implement probing support
The mDNS probing is described in RFC 6762 chapter 8.1.
The code will send an unsolicited mDNS query to network and
will check if there are existing hosts with the same name.
If there are, then the mDNS responder will not respond to
queries it is configured to use.

Fixes #84333

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-12 09:40:15 +01:00
Jukka Rissanen
8d601a0cc2 net: dns: Allow creating context with specific interface
Allow user to specify the network interface where the query should
be sent, but only if the user has supplied the DNS servers in sockaddr
list. If user has specified a DNS servers in a string list, then the
possible network interface is taken from the string.

The reason for this is that it is not possible to add network interface
to the sockaddr list so an extra parameter is needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-12 09:40:15 +01:00
Jukka Rissanen
82ef524777 net: dns: Allow creating context with specific svc and port
Allow user to specify socket service struct and port number so
that DNS servers specified in Kconfig etc are not used. This way
we can send a DNS query to arbitrary address without it affecting
the system configuration.

This is used in mDNS probing so that that mDNS responder can send
probe message and not change / configure system global DNS config.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-12 09:40:15 +01:00
Jukka Rissanen
af758e51a2 net: dns: Introduce resolver function that avoids using the cache
Introduce dns_resolve_name_internal() that allows resolving a name
and not use DNS cache if caching is enabled.

This is needed in mDNS probing (RFC 6762 chapter 8.1) which needs
to send a mDNS query and not get any results from cache.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-12 09:40:15 +01:00