Commit graph

6647 commits

Author SHA1 Message Date
Robert Lubos
151295f98e net: sockets: Move socket vtable definition
Offloaded socket implementations need to create the socket operations
vtable, therefore need access to struct socket_op_vtable. So far this
has been defined in a private header, so implementations needed to add
the header location to the include path in CMake.

Therefore, move struct socket_op_vtable definition to the internal part
of the public socket header, so it's no longer needed to include a
private header. This is also more consistent with the rest of the public
header content, as for example macros needed to register a socket
implementation are already there.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-11 16:32:49 -05:00
Andrey Dodonov
1c0608dc02 net: http: service: check for uncompressed file correctly
Correct not resetting compression extension,
when checking for an uncompressed file,
in case if compression is enabled, but no compressed file found.

Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
2025-07-10 16:01:47 -05:00
Robert Lubos
4872527605 net: coap_client: Don't send RST on unrecognized ACK response
According to CoAP RFC (7252, ch. 4.2), Reset cannot be sent in a
response for an ACK reply, rejected ACKs should be silently ignored
instead. Therefore, in case an unrecognized response is received, verify
the response type before sending Reset.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-10 16:01:03 -05:00
Simon Piriou
932005abf2 net: l2: ieee802154: mgmt: fix net_pkt leaks
The ieee802154_radio_send() function does not decrease reference counter
of the net_pkt, it's instead done one layer above in ieee802154_send().
This commit updates the mgmt functions using ieee802154_radio_send() to
always free the used net_pkt afterward.

Signed-off-by: Simon Piriou <spiriou31@gmail.com>
2025-07-10 10:13:35 -05:00
Simon Piriou
732a3a5c66 net: l2: ieee802154: shell: fix scan argc validation
Bump the argc check from 3 to 4 as the shell scan command has 3 required
parameters, the last being the scan duration:
- argv[0]
- passive|active
- channels
- per-channel duration in ms

Signed-off-by: Simon Piriou <spiriou31@gmail.com>
2025-07-09 00:26:29 -05:00
Jukka Rissanen
69fddf8f0b net: dns: Check interfaces to be NULL before use
Make sure interfaces variable is not NULL before using it.

Coverity-CID: 529857

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-07-08 13:41:11 -05:00
Robert Lubos
8f983ccda5 net: lib: http_client: Fix end of message detection
HTTP 1.1 server has two ways of indicating the message body length -
either by providing the Content Length header, or by closing the
connection when the entire body has been transmitted.

The second method didn't work with Zephyr's HTTP client implementation,
as EOF on a socket was treated as an error condition. Therefore, if no
Content Length was provided by the server, such transfers would always
end up with ECONNRESET error.

In order to fix this, we need to notify the parser about the EOF on a
socket when connection is closed. It is the parser role to determine
whether the EOF was expected in current state (by marking end of message
flag) or not (by setting an error).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-07 10:04:17 -05:00
Tim Pambor
6226bb1264 net: sockets_service: Fix function signature
Update the socket_service_thread function signature to match the expected
k_thread_entry_t type:
typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3);

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-07-04 14:21:23 -10:00
Gaetan Perrot
80df24e3b2 net: lib: coap: fix potential null pointer
In coap_well_known_core_get(), move the null check for 'resource' before
applying pointer arithmetic ('resource + 1') to avoid undefined behavior
when 'resource == NULL'.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2025-07-04 15:48:40 -05:00
Robert Lubos
aa4a8789d5 net: sockets: socket_dispatcher: Fix close function type
Socket dispatcher (and offloaded implementations in tests) register
fd as ZVFS_MODE_IFSOCK therefore they should register a  close2(
function instead of close().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
a4fdd2c266 net: sockets: socketpair: Fix close function type
socketpair fd regsiters ZVFS_MODE_IFSOCK therefore it should register a
close2() function instead of close().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
82945a7f52 net: l2: ieee802154: Prevent NULL pointer access
In case address mode in a packet is none, the address pointer within mhr
struct will not be set. Therefore, the pointer should not be used before
address mode is verified inside ieee802154_check_dst_addr().

This was reported by UBSAN:

  subsys/net/l2/ieee802154ieee802154.c:296:41: runtime error: member
  access within null pointer of type 'struct ieee802154_address_field'

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
31b79a93af net: pkt: Add explicit casts to uint32_t when bitshifting uint8_t val
Cast uint8_t variable to uint32_t explicitly to avoid implicit cast to
int, and thus potentially undefined behavior, reported by UBSAN:

  net_pkt.c:1946:17: runtime error: left shift of 239 by 24 places
  cannot be represented in type 'int'

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
7949789ce8 net: ip: utils: Avoid casting to in(6)_addr struct in net_addr_ntop()
In order to avoid alignment issues when casting void pointers to
in(6)_addr structures, create a properly aligned copy of the ip(v6)
address on stack.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
bd96b5dd83 net: lib: websocket: Avoid bitshift overflow warning
In order to prevent an overflow warning from UBSAN when bitshifting,
cast to uint64_t first before shifting, and then back to uint32_t.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
62a5260e01 net: Fix alignment error with net_ipaddr_copy()
As struct sockaddr have now alignment of 4 bytes, net_ipaddr_copy()
gives the following error if used for sockaddr:

  error: alignment 1 of ‘struct <anonymous>’ is less than 4
  [-Werror=packed-not-aligned]

Just use memcpy() instead, net_ipaddr_copy() was intended to use with IP
addresses, not socket related structs.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
8124032cbb net: ipv4: Avoid casting unaligned address to struct in_addr
Rework the IPv4-related code to avoid casting. Use raw variants of
IPv4-related functions whenever possible (especially on the critical
data path).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
f549bfcfeb net: ipv4: Add raw variants of various IPv4 functions
To address the misaligned access issues reported by UBSAN, introduce raw
variant of certain IPv4 functions used in the critical data path of the
network stack, operating on plain uint8_t buffers in stead of IPv4
address struct.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
0f6dcb37d7 net: ipv6: Avoid casting unaligned address to struct in6_addr
Rework the rest of the IPv6-related code to avoid casting. Use raw
variants of IPv6-related functions whenever possible (especially on the
critical data path). For the routing case, use a copy of the address to
avoid massive rework of the routing module.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
edf5319ca6 net: ipv6: nbr: Avoid casting unaligned address to struct in6_addr
IPv6 Neighbor Discovery interfaces modules like neighbor or routing
tables - converting them to raw variants seems futile. Therefore, for
IPv6 ND case, copy the raw IP address from the packet into the in6_addr
structure, and then pass it to respective functions. Performance
overhead should not be a big problem in such case as those actions are
only performed if a respective ND packet is received.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
f5455e66e3 net: ipv6: 6lo: Avoid casting unaligned address to struct in6_addr
Refactor local functions to work with byte buffers instead of struct
in6_addr and use switch to use raw variants of functions operating on
IPv6 addresses.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Robert Lubos
74ccd5fdaa net: ipv6: Add raw variants of various IPv6 functions
To address the misaligned access issues reported by UBSAN, introduce raw
variant of certain IPv6 functions used in the critical data path of the
network stack, operating on plain uint8_t buffers in stead of IPv6
address struct.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Shrek Wang
6a27fd2255 net: tcp: Add TCP ACK validation
According to RFC 793, ch 3.9 Event Processing,
after the connection is sync-ed with seqnum of both sides then,
        1. drop any received segment if the ACK bit is off.
        2. validate the acknum like this:
        SND.UNA =< SEG.ACK =< SND.NXT

The ACK validation is done before entering the state-machine, so
remove the flags <ACK> check in the state-machine processing.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-07-04 13:08:57 -05:00
Tim Pambor
e6f179d180 tests: net: dns-sd: Fix undefined behavior reported by UBSAN
htons() takes uint16_t as argument. Add the 'u' suffix to the
TTL constants to ensure the correct unsigned type is used and to avoid
undefined behavior if these functions are implemented as macros using
bit shifts.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-07-02 03:55:06 -10:00
Robert Lubos
d720971ae2 net: coap: Verify block number before processing
Verify if the block number isn't negative before processing it, to
prevent potentially undefined behavior. This was reported by the
undefined behavior sanitizer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-02 03:53:40 -10:00
Florian La Roche
25e1b88880 net: dns: is_server_name_found(): fix return code check
In is_server_name_found() fix the return code checking
of net_addr_ntop().

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
2025-07-01 19:03:29 -05:00
Toon Stegen
d1872d7272 net: mdns: make net_buf size configurable
for longer DNS-SD text records and instance names we need a bigger
buffer

Signed-off-by: Toon Stegen <toon@toostsolutions.be>
2025-07-01 10:16:20 -05:00
Alberto Escolar Piedras
a1d916edd0 net: dhcpv6: Avoid directly accessing address of unaligned struct
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-01 10:15:55 -05:00
Alberto Escolar Piedras
1deb2e3c68 net: http_server: Avoid directly accessing address of unaligned struct
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-01 10:15:55 -05:00
Alberto Escolar Piedras
82658ea6b2 net: igmp: Avoid directly accessing address of unaligned struct
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-01 10:15:55 -05:00
Alberto Escolar Piedras
236ccd379f net: ieee802154: Do not access addr of unaligned struct
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-01 10:15:55 -05:00
Alberto Escolar Piedras
93fa3b7831 net: tcp: Avoid directly accessing address of unaligned struct
Use UNALIGNED_MEMBER_ADDR when getting the address of possibly
unaligned structures members instead of attempting to directly
get the address as an offset.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-01 10:15:55 -05:00
Daniel Schultz
2c767cbfc0 net: lib: zperf: Fix 'kbps' in output
zperf should only return 'Kbps'. There are still two left-overs
from converting shell prints to 'Kbps'.

Align all prints to make it easier for scripting and parsing
content from console output.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
2025-06-30 15:19:39 -05:00
Juha Ylinen
ed79675199 net: http_client: Fix handling of POLLHUP
POLLHUP event may be returned even if there is still data to read
and POLLIN is set. To ensure all data is consumed, check for
POLLHUP after handling POLLIN.

https://man7.org/linux/man-pages/man2/poll.2.html

Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
2025-06-30 15:17:11 -05:00
Hui Bai
12babf9e39 net: l2: wifi: Fix roaming fail issue
The NET_EVENT_WIFI_SIGNAL_CHANGE was not added to net mgmt event queue
so that no scan was triggered, which caused roaming fail. The event
NET_EVENT_WIFI_SIGNAL_CHANGE was dropped because it was not enabled in
WIFI_SHELL_MGMT_EVENTS. After adding NET_EVENT_WIFI_SIGNAL_CHANGE, the
roaming works as expected.
Same issue found on event NET_EVENT_WIFI_NEIGHBOR_REP_COMP for 11k
roaming. Add this event to WIFI_SHELL_MGMT_EVENTS, too.

Signed-off-by: Hui Bai <hui.bai@nxp.com>
2025-06-27 18:27:45 -05:00
Benjamin Cabé
222a601b21 net: lib: ptp: fix memory slab alignment issues
Commit 3c47f91be4 introduced alignment
validation in K_MEM_SLAB_DEFINE macros.
A couple PTP message slabs wer using alignment 8, while the size of
the elements wasn't a multiple of 8, causing a static assertion
failure.

Fix by changing the alignment from 8 to 4 bytes.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-27 17:00:37 -05:00
Benjamin Cabé
1a01318efa net: lib: dns: dns_cache: check arguments in dns_cache_remove
Like other API in DNS cache, `dns_cache_remove` should check arguements
return -EINVAL if any of them is NULL.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-27 10:05:40 -05:00
Tomasz Bursztyka
175da6bdb0 init: Make entry init-function less and introduce service objects
Since the addition of deinit operation in device, init and deinit have
been within each device, rendering their init entry's init function
useless.

In order to save ROM space, let's remove the init function from
init entry altogether, and introduce a new object called "service"
which owns an init function to go along with SYS_INIT/SYS_INIT_NAMED.

Signed-off-by: Tomasz Bursztyka <tobu@bang-olufsen.dk>
2025-06-27 14:13:58 +02:00
Jukka Rissanen
96818f45a9 hostap: Replace wifi event mechanism by k_fifo
Earlier we had socketpair to pass wifi event information from
wpa_supplicant side to zephyr adaption layer. This is now replaced
by k_fifo to save some RAM.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-27 10:56:49 +02:00
Robert Lubos
3e704256e3 net: ppp: stats: Fix net_mgmt request handler format
This has been missed in net_mgmt rework in commit
5a9a39caf3.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-06-27 09:43:13 +02:00
Robert Lubos
8aa842c2c4 net: lwm2m: Prevent busy looping when active notify is set
In case a new notification is triggered while the previous one is still
active (i.e. not acknowledged), the LwM2M engine will start busy
looping, as the new notification is still valid (and supposed to be sent
after the previous one is done), but it's not sent in the current
iteration. The busy looping might prevent the system from receiving the
acknowledgment for the previous one, resulting in unresponsive system.

Fix this, by delaying the new notification timestamp a bit in such case,
so that the new notification will be scheduled for later instead of
trying to send it again right away.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-06-26 11:00:42 -05:00
Robert Lubos
a9c30d73f8 net: lwm2m: Implement gt/lt/st attributes handling
While it was possible to specify Greater Than / Less Than / Step
observe attributes for a resource, they were not taken into
consideration when evaluating notification criteria. This commit adds
support for checking if the resource value meets the value criteria
specified by gt/lt/st attributes.

Note that gt/lt attributes are thresholds - notification should only
sent if the resource value crosses them.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-06-26 11:00:42 -05:00
Robert Lubos
1bfd2ab4fd net: lwm2m: Update value of resources in notification registry
Update the value stored in the notification registry whenever
notification is sent (for those resources that have gt/lt/st attributes
assigned).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-06-26 11:00:42 -05:00
Robert Lubos
1ee6943cb5 net: lwm2m: Implement notified value registry for gt/lt/st attributes
Greater than, Less than and Step attributes require to track the last
notified value of a resource/resource instance in order to be able to
apply the specific thershold/step rules that the attributes define.

Therefore, implement a simple registry of the last notified values. When
one of the gt/lt/st attributes is configured on a resource/resource
instance, a registry entry is allocated for respective resource.
Whenever a notification is sent (either as a reply to Observe message,
or proactively) the registry is updated for the notified resources.

The stored resource values have been unified as "double" variables, to
avoid implementation complexity of having to support different
integer/floating point resource types.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-06-26 11:00:42 -05:00
Robert Lubos
46aaf287da net: lwm2m: Do not apply gt/lt/st attributes to incompatible resources
gt/lt/st attributes can only be applied to numerical resources according
to LwM2M specification (and common sense), hence verify that when
attributes are assigned.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-06-26 11:00:42 -05:00
Jukka Rissanen
f1a9ff97cb net: shell: dns: Print info about DHCP added servers
Print information which DNS servers were added by DHCP when
listing DNS servers in "net dns" command. This helps debugging
DNS server issues.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-26 14:08:19 +02:00
Jukka Rissanen
25084203c2 net: dhcp: Remove only added DNS servers when stopping
Make sure that we remove only the added DNS servers when
the DHCP is stopped.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-26 14:08:19 +02:00
Jukka Rissanen
cdc6c324d7 net: dns: Save info about source when configuring DNS servers
Remember which DNS server was added by a source like DHCPv4 or v6
message. This will allow system to remove DNS servers that were added by
that source. Then when stopping for example DHCP, we can remove those
specific DNS servers and not leaving DNS servers hanging in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-26 14:08:19 +02:00
Ravi Dondaputi
d289bed4af net: lib: wifi_credentials: Add support for Enterprise security
Add support for configuring enterprise mode security.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2025-06-25 15:31:29 -10:00
Pieter De Gendt
0b8c00b5dd net: lib: dhcpv4: Support INIT-REBOOT
Add the init-reboot state for DHCPv4 to request an already assigned IP
address.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-06-25 14:09:46 +02:00