Commit graph

6,767 commits

Author SHA1 Message Date
Georges Oates_Larsen
1c79445059 net: net_if: fix net_if_send_data for offloaded ifaces
Some offloaded ifaces have an L2, but lack support for
net_l2->send. This edge case is not handled by
net_if_send_data, resulting in a NULL dereference under
rare circumstances.

This patch expands the offloaded iface guard in
net_if_send_data to handle this edge case.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-08-06 09:19:36 +01:00
Benjamin Cabé
43b948f9a8 net: ptp: Properly handle second overflow/underflow
Fixes issues with net_ptp_time arithmetic where second
overflow/underflow would not be handled properly.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-08-06 09:17:26 +01:00
Benjamin Cabé
dff19c3ac6 net: ptp: Adjust clock using correct offset
Offset should be *subtracted* from current clock value, not added.
This was causing clock to accumulate error instead of actually
"converging".

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-08-06 09:17:26 +01:00
Fengming Ye
86b5b59928 net: wifi: shell: add DPP commands
DPP shell command handler will parse user args to params in enum
and send l2 mgmt DPP requests.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-08-05 18:40:17 -04:00
Fengming Ye
1640826fc5 net: wifi_mgmt: add hostap DPP support
Add wifi l2 mgmt dpp handlers.
Add wifi subcommand dpp to call l2 mgmt dpp handlers.

DPP l2 handlers will parse params to hostap wpa_cli format args
and send wpa_cli commands to hostap.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-08-05 18:40:17 -04:00
Ravi Dondaputi
37491cb0f7 wifi: utils: Get correct channel count
For 2.4GHz and 6GHz bands, while counting the channels in configured
range, start of the range is being counted twice. Correct this
by advancing the index by 1 while counting channels in range.

Signed-off-by: Ravi Dondaputi <ravi.dondaputi@nordicsemi.no>
2024-08-05 18:39:58 -04:00
Kapil Bhatt
cd14be6073 net: wifi: Add reset command for Wi-Fi statistics
Add "reset" as a subcommand of wifi statistics.
Also add help option in statistics command.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-08-05 16:29:21 +02:00
Kapil Bhatt
3d38b5e094 wifi_mgmt: Add new API to reset Wi-Fi statistics
Add a new offload API to reset Wi-Fi statistics from
the Wi-Fi driver.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-08-05 16:29:21 +02:00
Tom Finet
c1235bb4fb net: http: fix %d format string to %zu
Fixes logging of size_t variable to work on both 32
and 64 bit platforms.

Signed-off-by: Tom Finet <tomfinet@outlook.com>
2024-08-05 11:32:08 +02:00
Robert Lubos
5f43388308 net: coap: Parse more flag in coap_get_block2_option()
Parse the more flag in coap_get_block2_option(), so that the function
can be used not only with requests but also with replies (where the more
flag should not be ignored).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-08-02 22:12:47 -05:00
Robert Lubos
3902a990e5 net: coap: Fix underlying type for block number
The block number in block1/2 options can be encoded on up to 20 bits
according to RFC 7959, therefore the underlying type used in helper
functions to retrieve the block number should be large enough to hold
the result. Therefore, replace the container for block number with
uint32_t instead of uint8_t.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-08-02 22:12:47 -05:00
Jukka Rissanen
20a69f6dbf net: wifi: Add iterable_sections header file
This is related to change in commit dacb3dbfeb
("iterable_sections: move to specific header")

Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-08-01 12:36:00 +02:00
Seppo Takalo
e86bdf952d net: lwm2m: Always emit DISCONNECTED event
When LwM2M engine is requested to stop,
emit the disconnected event unconditionally.
There is really no reason to skip the event
on network error, or if we have never been registered.

Fixes #76422

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-08-01 12:35:53 +02:00
Matt Rodgers
47fbb8512f net: coap_client: allow application to add block2 option to requests
Allow an application to add a Block2 option to an initial request for a
resource. For any subsequent requests as part of a blockwise transfer,
drop the application-added Block2 option since the coap_client must
append a Block2 option with updated NUM and SZX fields based on the
server response.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-08-01 09:13:32 +01:00
Pisit Sawangvonganan
6211de87c0 net: mqtt: improve decoder buffer handling
Improve buffer handling logic to use local variables extensively.

This change reduces the number of pointer dereferences, which leads
to more efficient runtime and helps reduce the code size.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-31 13:08:28 +02:00
Pisit Sawangvonganan
45282a41c1 net: mqtt: improve encoder buffer handling
Improve buffer handling logic to use local variables extensively.

This change reduces the number of pointer dereferences, which leads
to more efficient runtime and helps reduce the code size.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-31 13:08:28 +02:00
Robert Lubos
349bf81e00 net: tcp: Keep track of recv window size change since last ACK
Windows TCP stack has a peculiar behavior - when running iperf, it will
fill out the RX window almost entirely, but will not set PSH flag on
packets. In result, our stack would delay the ACK and thus window
update, affecting throughputs heavily.

In order to avoid that, keep track of the most recent window size
reported to the peer, and reduce it when receiving new data. In case the
RX window, as seen from the peer perspective, drops below certain
threshold, and the real RX window is currently empty, send an ACK
immediately when updating window, so that peer can continue
with sending data.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-07-31 12:56:52 +02:00
Jukka Rissanen
03885d1cbf net: if: No need to join mcast groups if interface IPv6 is disabled
If IPv6 is not enabled for a given network interface, then there
is no need to try to join IPv6 multicast groups as it will just
cause an error print which is pointless in this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-07-31 12:40:32 +02:00
Konrad Derda
4e7bf281a1 net: ipv6: routing: decide whether to set interface's LL address
While routing between interfaces source Link-Local L2 address is set
for a packet. However, it should not be done for some of the interfaces.

This commit adds helper function to check this condition in runtime.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-31 12:40:16 +02:00
Konrad Derda
0ac5ab4a4e net: ipv6: routing: do not add route to original iface without ND
When packet is routed between interfaces new routing entry is added
to the table. This should not be done for interfaces that do not
support Neighbor Discovery protocol as they are not keep potential
neighbors in the common table.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-31 12:40:16 +02:00
Gerhard Jörges
e55278a87b net: lib: http_server: add static fs resource
adds filesystem as a resource for the http_server which serves static
(gzipped) files from a filesystem to the client.

Signed-off-by: Gerhard Jörges <joerges@metratec.com>
2024-07-31 10:08:16 +02:00
Fabian Pflug
31e91794de net: l2: ieee802154: mgmt: allow beacons without association bit
The Association permit bit shall be set to zero if the coordinator does
not accept association requests.
Not accepting association request ist not a reason to filter the
beacons from this coordinator during network scan. It is still a
network, just one you cannot associate with.

Signed-off-by: Fabian Pflug <fabian.pflug@grandcentrix.net>
2024-07-31 10:08:03 +02:00
Matt Rodgers
44d39e2028 net: coap_client: limit payload size during block transfer to block size
Limit the coap payload size passed up to the application callback to the
block size, when a block transfer is in progress and the current payload
is not the final block.

If the current payload is not part of a block transfer, or is the final
block of a transfer, then the full payload can be passed to the
application to avoid having to make another request over the network for
data that has already been received.

This avoids a problem raised in issue #76089, where a payload longer
than CONFIG_COAP_CLIENT_MESSAGE_SIZE causes the same data to be passed
to the application callback twice (once in the large packet, and once in
the next block which must have an offset that is a multiple of the block
size).

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-07-31 10:07:45 +02:00
Matt Rodgers
93f871e2d1 net: coap_client: handle truncation of received data
Use the MSG_TRUNC flag to check the total length of UDP packets
receieved by the coap_client, and hence check if the receive buffer
contains the whole message, or if it is truncated.

If the message is truncated, then use a blockwise transfer to fetch the
rest of the data.

This is related to issue #76089.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-07-31 10:07:45 +02:00
Pisit Sawangvonganan
16386d7b5f net: shell: use shell_xxx_impl in PR ... PR_WARNING macros
Due to the introduction of `shell_xxx_impl` wrapper functions in
PR #75340, we can minimize caller overhead by eliminating direct
`color` parameter passing.

This is achieved by using `shell_print_impl`, `shell_error_impl`,
`shell_info_impl` and `shell_warn_impl` instead of `shell_fprintf`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-31 10:07:29 +02:00
Pieter De Gendt
ac983f633e net: lib: http: Use Kconfig constants
Replace Kconfig values with UINT32_MAX

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-30 18:31:11 +01:00
Nick Ward
c8526bc53f net: lwm2m: shell: add observations cmd
Outputs observation configurations.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2024-07-29 14:18:10 +02:00
Nick Ward
0645609b0b net: lwm2m: observations: add attr type to str
Allows strings used to be exposed outside of file.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2024-07-29 14:18:10 +02:00
Andreas Ålgård
a5850b794c net: lib: dhcpv4_server: Add callback to allow user to set address
This functionality is useful to allow for conditional or static leases.

Signed-off-by: Andreas Ålgård <aal@ixys.no>
2024-07-28 07:30:48 +03:00
Marcin Gasiorek
313a92baf9 net: openthread: Set CIDR for NAT64
Implementation of functionality whitch configure CIDR for OT NAT64.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2024-07-28 07:29:50 +03:00
Marcin Gasiorek
ac0a9d79ab net: openthread: Add NAT64 send and receive callbacks.
Packets are routed between OT and Zephyr net stacks.
For IPv4 these packets are managed by NAT64 by default.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
2024-07-28 07:29:50 +03:00
Pisit Sawangvonganan
444e135679 net: if: streamline interface name checking logic
This commit reduces `#if / #endif` pairs by leveraging the
`IS_ENABLED` macro:
- Removed `#ifdef / #endif` around `NET_L2_DECLARE_PUBLIC` in `net_l2.h`,
  enabling compilation without affecting link time if the configuration
  is unavailable.

`set_default_name` function:
- Replaced multiple `if` statements with `else if` to use the last `else`
  without indirectly checking `name[0] == '\0'`.
- Since `snprintk` guarantees null-termination if `sizeof(name) > 0`,
  the `-1` subtraction is unnecessary, eliminating the need for
  zero initialization in `char name[CONFIG_NET_INTERFACE_NAME_LEN + 1];`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-28 07:29:01 +03:00
Vineeta S Narkhede
232c802c05 net: hostname: Add a function to set the hostname postfix as is.
Fixes: #72363

The existing function to set the postfix is converting postfix
string to hexadecimal. Adding a new function to handle a use case
where the provided postfix should be used as is without any conversion.

Signed-off-by: Vineeta S Narkhede <VineetaSNarkhede@Eaton.com>
2024-07-28 07:28:51 +03:00
Bas van Loon
85f6409043 net: if: Add net_if_ipv4_get_gw as helper function.
Most set functions have a get function as well, add the missing
function to get the set gateway IPv4 address.

Signed-off-by: Bas van Loon <basvanloon@betronic.nl>
2024-07-27 20:51:21 +03:00
Andrey Dodonov
0e699eb251 net: lib: dhcpv4: parse multiple DNS servers received from DHCP
If we receive multiple DNS servers via DHCP only the first one is used,
regardless of CONFIG_DNS_RESOLVER_MAX_SERVERS constant.
Parse DHCP option and save addresses that fit

Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
2024-07-27 20:49:57 +03:00
Pieter De Gendt
ad63ca284e kconfig: replace known integer constants with variables
Make the intent of the value clear and avoid invalid ranges with typos.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-27 20:49:15 +03:00
Pisit Sawangvonganan
b34349eed9 net: utils: improve hex digit character checking in net_bytes_from_str
Several refactors and improvements for `net_bytes_from_str` as follows:
- Replaced manual hex digit checks with `isxdigit()`.
- Changed variable `i` from unsigned int to size_t for consistency with
  the `strlen()` return type.
- Added `src_len` to store the result of `strlen(src)` to avoid
  multiple calls to `strlen` in the `for-loop`.
- Ensured casting to `unsigned char` before passing to `isxdigit()` to
  prevent undefined behavior.
- Explicitly cast the result of `strtol()` to `uint8_t` to match
  the buffer type.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-27 15:16:42 +03:00
Robert Lubos
bfe958a7f1 net: sockets: tls: Fix poll update event check
In case POLLIN is set, and no new application data has been detected,
the ztls_poll_update_ctx() should only return -EAGAIN if no other events
are available for the socket. Otherwise, the function may end up
busy-looping, in case for example POLLOUT is also monitored for the
socket.

Current check verifying that was wrong, as it caused to function to
return -EAGAIN even if some other events could've been reported for the
socket.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-07-27 15:13:17 +03:00
Maochen Wang
bf42164084 net: wifi: Fix the nm type check error
Fix the NM iface type check error, should use (1 << WIFI_TYPE_STA),
instead of WIFI_TYPE_STA. Same for WIFI_TYPE_SAP.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2024-07-27 15:09:20 +03:00
Fin Maaß
1f38d9dfef net: shell: iface: add infos from eth phy
add information about the ethernet
phy and the current link speed to the
net iface command.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-07-27 15:07:26 +03:00
Fin Maaß
2fb983a427 net: l2: ethernet: add way to access phy
add a way to access the ethernet phy
device via the ethernet device.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-07-27 15:07:26 +03:00
Pisit Sawangvonganan
1100393b79 net: lwm2m: optimize socket_loop by using local variables
Changes include:
- Introducing a local `ctx` variable to replace multiple
  `sock_ctx[i]` references.
- Using a local `revents` variable to simplify repeated
  `sock_fds[i].revents` checks.
- Consolidating conditional checks for socket events
  (ZSOCK_POLLERR, ZSOCK_POLLNVAL, and ZSOCK_POLLHUP) as they are
  individual bit definitions, allowing them to be checked simultaneously.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-07-27 10:47:58 +03:00
Gaofeng Zhang
a5781547d6 net: ipv4: Fix tx_pkts slab leak in send_ipv4_fragment
In the send_ipv4_fragment function, if net_pkt_get_data returns
fail, a tx_pkts slab leak will occur. If leak exceeds the
maximum number CONFIG_NET_PKT_TX_COUNT of tx_pkts slab, tx_ptks
will be used up, and the related modules(dhcp, ping and so on)
of net cannot alloc tx_pkt slab, and will sleep and can not
return successfully until available slab.
dhcp work or ping work cannot be executed beacause can't alloc
memory, and ping command cannot return, console also fails to
input commands, and the console hang problem occurs.

Signed-off-by: Gaofeng Zhang <gaofeng.zhang@nxp.com>
2024-07-27 10:45:14 +03:00
Konrad Derda
c2747acbff net: ipv6: routing: move checking for an own source address
When IPv6 packet is received, there is a check of the packet's source
address to verify that it is not interface's non-tentative address.

This commit moves this check to the later stages of processing as
packets that can be routed are dropped in the early stage otherwise.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-27 10:44:48 +03:00
Konrad Derda
b41b7d5da8 net: ipv6: routing: do not loop back already routed packets
If the packet was routed between interfaces by IPv6 module it should
not be looped back but has to be passed to the destination interface
instead.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-27 10:44:48 +03:00
Konrad Derda
807daf3788 net: ipv6: routing: do not use an original source address for NS
When a packet's transmission is prepared and Neighbor Solicitation is
sent its souce address is always the same as of a packet awaiting -
also for packets routed from an other interface.

Quote from the RFC:
If the source address of the packet prompting the solicitation is the
same as one of the addresses assigned to the outgoing interface, that
address SHOULD be placed in the IP Source Address of the outgoing
solicitation.  Otherwise, any one of the addresses assigned to the
interface should be used.

This commit fixes the behavior.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-27 10:44:48 +03:00
Konrad Derda
79f7b400cb net: ipv6: routing: match destination address to a given interface
Before packet is routed there is a check verifying if the destination
address is not the device's one. However, the check should be limited
to the packet's original interface. Otherwise, packet cannot be routed
if it is destined for an other interface of the device.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-07-27 10:44:48 +03:00
Seppo Takalo
6addba5698 net: lwm2m: Verify X509 hostname when URI contains valid name
Enable hostname verification in DTLS handshake when server URI contains
valid hostname.
When URI is given just as IP address, don't fill up the
ctx->desthosname or enable hostname verification.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-07-27 10:44:27 +03:00
Bjarki Arge Andreasen
280fbec58e net: lib: sockets: socketpairs: Update socketpair mem alloc
The memory allocation for socketpairs is not conformant to the new
MEM_POOL_ADD_SIZE_ mechanism for allocating heap memory.

Specifically CONFIG_NET_SOCKETPAIR_HEAP can not be selected unless
the user has specified CONFIG_HEAP_MEM_POOL_SIZE. We should be
using MEM_POOL_ADD_SIZE_ to add to the heap if the user wants to
use it for socketpair allocation.

Additionally increase the size of pre-allocated sockets to 8 from 1
to support larger devices by default, taking into consideration the
required socketpairs and buffer sizes when using
WIFI_NM_WPA_SUPPLICANT.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2024-07-27 10:43:32 +03:00
Robert Lubos
35fe353ad6 net: lib: coap_client: Replace send_mutex with more generic lock
Introduce a more generic mutex for protecting coap_client structure.

This allows to avoid a certain race condition when sending consecutive
CoAP requests. The case was, that when a CoAP receive thread notified
the application that a complete response was received, and the
application wanted to send another request from the application thread,
the consecutive call to coap_client_req() might've failed if the
application thread has higher priority than the CoAP receive thread
because of the request context cleanup is done after calling the
application callback.
Having a mutex, which is locked while processing the response, and when
attempting to send a new request allows to synchronize threads as
expected.

As this new mutex seemed redundant with the more specialized send_mutex
already present in the coap_client, the latter was removed (i. e.
transmission is also protected with the new mutex).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-07-27 10:43:15 +03:00