Commit graph

6489 commits

Author SHA1 Message Date
Tom Hughes
d811760779 net: lib: coap: Remove unused function
Building with clang warns:

subsys/net/lib/coap/coap_link_format.c:39:20: error: unused function
'append_be16' [-Werror,-Wunused-function]
static inline bool append_be16(struct coap_packet *cpkt, uint16_t data)

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-12 02:25:53 +01:00
Tom Hughes
1f653ae295 net: lib: http_server: Remove unused function
Building with clang warns:

subsys/net/lib/http/http_hpack.c:21:20: error: unused function
'http_hpack_key_is_dynamic' [-Werror,-Wunused-function]
static inline bool http_hpack_key_is_dynamic(uint32_t key)
                   ^

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-12 02:25:41 +01:00
Tom Hughes
d2bf3ae905 net: ipv6: Remove unused function
Building with clang warns:

subsys/net/ip/ipv6_nbr.c:137:31: error: unused function
'get_nbr_from_data' [-Werror,-Wunused-function]
static inline struct net_nbr *get_nbr_from_data(struct net_ipv6_nbr_data
                              ^                 *data)

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-12 02:23:07 +01:00
Robert Lubos
d6792494b7 net: coap_client: Fix build with cpp projects
The coap_client.h header won't build if included from c++ file:

error: expected primary-expression before ‘.’ token
  .value[0] = coap_bytes_to_block_size(CONFIG_COAP_CLIENT_BLOCK_SIZE),

Therefore move the actual function implementation to the library C file
to prevent this.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-11 15:41:37 +01:00
Qingling Wu
159332d591 net: wifi: hostap: add CA certificate used or skipped support
Added new parameter "A" in wifi connect command to support
CA certificate used or CA certificate skipped for
EAP-TTLS-MSCHAPV2 and EAP-PEAP-MSCHAPV2.

Signed-off-by: Qingling Wu <qingling.wu@nxp.com>
2025-02-11 15:38:58 +01:00
Jakub Witowski
05ab017774 net: coap: fix uninitialized usage of option struct
option struct was uninitialized in insert_option() function
during encode_options() call when the while loop wasn't
executed before.

Signed-off-by: Jakub Witowski <jakub.witowski9302@gmail.com>
2025-02-11 11:45:05 +00:00
Jakub Witowski
828f5e8b23 net: coap: fix uninitialized usage of hdr_len
The hdr_len was uninitialized when none of if-else
conditions were met in decode_delta() function.

Signed-off-by: Jakub Witowski <jakub.witowski9302@gmail.com>
2025-02-11 11:45:05 +00:00
Rene Beckmann
cc33491265 net: mqtt-sn: Wait for register & subscribe to complete
From the MQTT-SN spec:

6.5 Topic Name Registration Procedure

...
At any point in time a client may have only one
REGISTER message outstanding, i.e. it has to wait
for a REGACK message before it can register another
topic name.
...

6.9 Client’s Topic Subscribe/Un-subscribe Procedure

...
As for the REGISTER procedure, a client may have only
one SUBSCRIBE or one UNSUBCRIBE transaction open at a time.
...

Until now, the library did not comply with these requirements.
An additional "waiting" state for topics was introduced:
REGISTER, SUBSCRIBE and UNSUBSCRIBE as an extra step before
switching to REGISTERING, SUBSCRIBING and UNSUBSCRIBING. The
library now makes sure that only one topic can be REGISTERING
and only one topic can be in either SUBSCRIBING or UNSUBSCRIBING.
Additionally, requesting to UNSUBSCRIBE is now denied if the topic
is not yet SUBSCRIBED, to avoid weird race conditions.

Also, added two tests that verify this behavior.

This fixes #84644

Signed-off-by: Rene Beckmann <rene.bckmnn@gmail.com>
2025-02-11 11:44:52 +00:00
Rene Beckmann
b7c404738f net: mqtt-sn: Add comments
Add some comments to static functions and variables.

Signed-off-by: Rene Beckmann <rene.bckmnn@gmail.com>
2025-02-11 11:44:52 +00:00
Rene Beckmann
91f99fcec5 net: mqtt-sn: Rename internal 'find' functions
Add word 'by' to function names to clarify which is the thing that
is found and which is the thing that is searched for. For example,
mqtt_sn_topic_find_name was renamed to mqtt_sn_topic_find_by_name
because the function does not find the name but finds a topic by
its name.

Signed-off-by: Rene Beckmann <rene.bckmnn@gmail.com>
2025-02-11 11:44:52 +00:00
Robert Lubos
9a00bc69b7 net: http_client: Ignore message body on 101 Switching Protocols reply
When HTTP 101 Switching Protocols response is received, force the HTTP
parser to ignore any potential message body payload (which should
already belong to the new protocol).

This is usually not an issue, as Switching Protocols reply should
contain headers only, however it's been observed that some servers
specify chunked transfer-encoding header which tricks the parser
to wait for payload event though it never arrives.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-11 10:11:41 +01:00
Fengming Ye
54ef1b54d1 net: wifi: add SAE extended key security type support
Add WPA3 SAE extended key security type support in
L2 wifi mgmt and hostap.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2025-02-10 14:32:38 +01:00
Jukka Rissanen
c1201792f0 net: shell: Print interface status for iface command
Print interface status information for "net iface" command.
This is useful information when debugging connectivity issues.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-10 11:30:47 +01:00
Maochen Wang
4174c957bf net: l2: wifi: add the check if dev is NULL
Add the check if dev is NULL (when iface is NULL, dev is NULL) when
setting Wi-Fi CMD, in case Wi-Fi driver init fails and shell crashes.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2025-02-10 07:25:43 +01:00
Maochen Wang
6cbb37dd4e net: l2: wifi: setting CMD only when net_if is up
Setting Wi-Fi cmd only when the net interface is up, avoid the case
that driver deinit and net interface is down, then the L2 APIs interact
with supplicant and driver, which may lead to CPU exception.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2025-02-10 07:25:43 +01:00
Tom Hughes
67e07b7a41 net: utils: Fix unused function warning
Building with clang warns:

subsys/net/ip/utils.c:600:24: error: unused function 'pkt_calc_chksum'
[-Werror,-Wunused-function]
static inline uint16_t pkt_calc_chksum(struct net_pkt *pkt, uint16_t sum)
                       ^

pkt_calc_chksum is called by net_calc_chksum, which only exists when
CONFIG_NET_NATIVE_IP is defined.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-02-08 19:45:38 -05:00
Jukka Rissanen
c8f640a610 net: socket: service: Restart instead of bailing out when error
It might happen now after the commit 8519fa1627 ("net: socket service
resets its restart flag") that the event has disappeared before we
call the work, if that happens we must not bail out but restart
the service.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:48:14 +01:00
Jukka Rissanen
4b57f7ad2c net: mdns_responder: Not an error if dispatcher is already registered
Just ignore any EALREADY error returned when trying to register a
DNS dispatcher. This could happen if trying to init things when the
interface comes up and we have already initialized the dispatcher.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:47:12 +01:00
Jukka Rissanen
c832f3dd86 net: dns: Use DNS_EAI_SYSTEM error properly
The DNS_EAI_SYSTEM error value tells that the errno value
contains the actual system error value. So set the errno
properly when there is a system error.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:47:12 +01:00
Jukka Rissanen
7f3d140f25 net: dns: Set answer offset only when within DNS msg
Do not set answer_offset if the offset would be outside of
DNS message.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:47:12 +01:00
Jukka Rissanen
e98bf3e6d7 net: dns: Use dispatcher context in callbacks
Feed the dispatcher context to dispatcher callbacks instead of
resolver or responder context. The callback can then use the
proper context because the dispatcher context contains those
two context. This allows dispatcher callback to utilize all the
information (like interface etc) stored in dispatcher context.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:47:12 +01:00
Jukka Rissanen
3ed8151b00 net: mdns: No error if mcast address is already added to interface
Ignore any EALREADY return code as that is not really an error in
this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:47:12 +01:00
Jukka Rissanen
04242abb99 net: sockets: Remove inline from zsock_recv_dgram()
As the zsock_recv_dgram() is rather large, remove the inline
keyword from it and let compiler to decide what to do with it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:46:55 +01:00
Jukka Rissanen
3fb1e11d5b net: mdns_responder: Add more debug prints
Print the socket descriptor and interface after bounding it
successfully in order to help to figure out what sockets are
bind to one specific interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:46:55 +01:00
Jukka Rissanen
0f858b24aa net: socket: services: Restore only the socket related to work
Restore only the socket descriptor that we marked as -1 after running
the work related to that socket. Earlier we tried to restore the whole
global array of descriptors which could go wrong and is not needed
as we only support synchronous work.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-02-07 17:46:55 +01:00
Dave Lacerte
d9aab69fbf net: coap: Fix uninitialized variable warning
The variable block_len in function coap_next_block_for_option()
can be used uninitialized in case of empty packet in
coap_packet_get_payload(). Mute the compiler warning with
default value of 0.

Signed-off-by: Dave Lacerte <lacerte.dave@hydroquebec.com>
2025-02-06 17:49:42 +01:00
Chaitanya Tata
4cd6654b21 net: l2: Add a config option to allow mismatched L3/L2 address packets
The RFC1122 section 3.3.6 says we SHOULD drop the packets if L2 address
is brodcast but L3 address is unicast, but we had seen some Wi-Fi access
points in the field not conforming to that, and DHCP offer is dropped
due to this and causes Wi-Fi connectivity issues.

As the RFC saus it's SHOULD and not a MUST, add a config option to allow
such packets, disabled by default.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-02-06 17:48:37 +01:00
Seppo Takalo
ac01879330 net: lwm2m: Tickless does not depend on SOCKETPAIR
Tickless mode is refactored to use zvfs_eventfd,
but the Kconfig dependencies were not updated.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2025-02-06 14:46:55 +01:00
Dominic Moffat
8519fa1627 net: socket service resets its restart flag
The socket service restarts whenever a new socket is registered.
This is triggered via zvfs_eventfd_write(ctx.events[0].fd, 1),
but the restart flag (ctx.events[0].revents) is not properly cleared,
causing unintended repeated restarts and skipped socket processing.

Detecting socket restart is done after the socket fd has processed its
data, so the socket doesn't lose its data. Ensure the socket service
clears its restart flag (ctx.events[0].revents = 0) immediately after
detecting a restart event, preventing unnecessary restarts.

Fixes #81813

Signed-off-by: Dominic Moffat <dom@illysky.com>
2025-02-05 23:49:28 +01:00
Noah Olson
37a924be6a net: dns: Fix DNS caching bug
The current DNS caching logic is not aware of the IP address version.
If there is a cached address for a query, the caller of
dns_get_addr_info() will receive that address, even if it is not the
same version as the caller requested. For example:

- dns_get_addr_info() is called to resolve an IPv4 address
- the DNS client caches the IPv4 address that was received
- dns_get_addr_info() is called to resolve an IPv6 address
- the DNS client sees that there is a cached IPv4 address for the
  given query
- the DNS client does not check that the cached address is of the
  requested version (IPv6)
- the cached IPv4 address is returned from dns_get_addr_info()

This changes the DNS client to check IP address version when searching
cached addresses.

Signed-off-by: Noah Olson <noah@wavelynx.com>
2025-02-05 23:49:17 +01:00
Dave Lacerte
31ec42a33c net: lwm2m: Fix offset for post-write callback
The offset in post-write callback is incorrect for TLV format as
the first data block contain TLV header. This fix is replacing
reamaning for offset in opaque context struct and passing it to
post-write and validation callback.

The fix also corrects the offset in pull context as it was pointing
at the end of the block processed data and not on the block context
prior to processing.

Signed-off-by: Dave Lacerte <lacerte.dave@hydroquebec.com>
2025-02-05 23:48:38 +01:00
Robert Lubos
b7cfa54c18 net: tc: Deprecate CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO
Since a separate CONFIG_NET_TC_RX_SKIP_FOR_HIGH_PRIO was introduced for
RX TC queues, CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO became ambiguous,
rename it to CONFIG_NET_TC_TX_SKIP_FOR_HIGH_PRIO and deprecate the old
config.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-05 12:37:01 +01:00
Robert Lubos
e430dfb00f net: arp: Set family and proto type for all ARP packets
The family and proto type was not set for the IPv4 autoconf ARP packets.
Since those should be set for all ARP packets, just move the code
outside of the if block.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-02-05 12:36:25 +01:00
Cla Mattia Galliard
2153e34e14 net: ethernet: cleanup net-stats calls
There is no need to if-def away the net-stats function since there is a
shim available now.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-02-03 16:59:53 +01:00
Robert Lubos
57189b410e net: lwm2m: gateway: Prevent underflow when processing URI options
lwm2m_gw_handle_req() function logic expects that at least one URI
option was found, therefore add an extra check to return the function
early if that isn't the case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-31 19:51:17 +01:00
Jukka Rissanen
9c24578cc4 net: vlan: Allow VLAN count to be set to 0
If VLAN count is set to 0, then only priority tagged VLAN frames
that have tag value 0 can be received. Also this means that VLAN
interfaces are not created which can save memory if you do not need
to receive any other VLAN frames than those tagged with value 0.

Fixes #84023

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-31 16:12:50 +01:00
Cla Mattia Galliard
586bec760d net: ethernet: Ensure packet is not touched after consumed by l3
Ensure that all packets are no longer used by ethernet_recv after it was
consumed by the l3-handler.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-01-31 16:09:47 +01:00
Marc Lasch
dd16bc5153 net: lwm2m: Check result when sending messages
`lwm2m_send_message_async` returns critical errors which are not handled in
many cases. The function can return -ENOMEM, -EPERM or other error codes
from functions called.

Signed-off-by: Marc Lasch <marc.lasch@husqvarnagroup.com>
2025-01-31 16:09:33 +01:00
Cla Mattia Galliard
bb3ac84bce net: tc: Add a skip for rx-queues
Add a configuration option to skip the rx-queues for high priority packets
analogously to the tx-side.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-01-31 11:49:50 +01:00
Cla Mattia Galliard
ed1ebb337d net: tc: Add statistics about dropped packets
Add statistics about packets dropped in net_tc.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-01-30 20:27:33 +01:00
Cla Mattia Galliard
84f6e7a313 net: tc: Limit the max amount of packets in the traffic-class-fifo
To avoid starvation of a traffic class by another, limit the maximum amount
of packets, that can sit in a single traffic-class-fifo to a fraction of
the maximum amount of available packets. In the tx-case also reserve
packets for direct sending, in the case, where
CONFIG_NET_TC_SKIP_FOR_HIGH_PRIO is enabled.

Signed-off-by: Cla Mattia Galliard <cla-mattia.galliard@zuehlke.com>
2025-01-30 20:27:33 +01:00
Jukka Rissanen
4195130214 net: shell: events: Print more details for L4 events
Print IP address information for L4 DNS server add and remove
events.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
6edcf445ab net: shell: events: IPv4 mcast join and leave were missing
The event monitor did not handled IPv4 multicast join/leave
event information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
ef9b3d4dbf net: shell: events: IPv4 mcast addr add and del were missing
The event monitor did not handled IPv4 multicast address
addition or deletion information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
b83f86a1d2 net: shell: events: Add admin up and down events
The "admin up/down" event was not being decoded.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
e109a27c99 net: shell: events: Print event id for unknown events
To simplify debugging what event code is missing from the
events shell module, print also event id for the for unknown
events. This way it is a bit easier to figure out what the
unknown event is.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Jukka Rissanen
b2dcaa8f9e net: shell: events: Add Ethernet L2 support
Print Ethernet carrier on/off and VLAN tag enabled/disabled
status when monitoring events.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-30 18:29:45 +01:00
Robert Lubos
6677db21ce net: sockets: Make sure recvmsg() doesn't modify buffer configuration
The recvmsg() function should not modify the buffer configuration
provided in struct msghdr, such behavior is not specified in the POSIX
function description, nor is it consistent with well-known behavior of
this function in Linux.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-01-30 14:09:35 +01:00
Seppo Takalo
4d6372be93 net: lwm2m: Fix Notify response handling
As the CoAP library was refactored to handle response
messages as stated by RFC, the LwM2M message handling was
untouched.
LwM2M Notify handling is relying on response callback
to be called, but as per CoAP RFC an empty Ack is not
actually a response and the callback was not called anymore.

Fix the issue by calling the response callback when
we receive an empty ack for any confirmable response
messages.
This should not affect any handling of CoAP requests.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2025-01-30 14:08:39 +01:00
Jukka Rissanen
d243bc1fdb net: Fix inet_pton IPv4 implementation
The conversion from IPv4 string presentation to numeric value
did not check if the individual address value was between 0 and 255
inclusive.

Add also test case for this.

Fixes #84593

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-01-29 17:56:09 +01:00