Commit graph

6489 commits

Author SHA1 Message Date
Robert Lubos
da6b607a32 net: tcp: Do not cancel connect sem from tcp_conn_unref()
Resetting the connect semaphore from tcp_conn_unref() prevents the
ref/unref mechanism from being used freely when needed. Therefore, move
the code responsible for resetting pending connection to
tcp_conn_close() (called only when the connection is being closed on
behalf of the TCP stack, for instance due to RST being received) and to
net_tcp_put() (connection closed on behalf of the application).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-09-26 10:58:37 +01:00
Jukka Rissanen
a41f625fab net: tcp: Make sure that connection failure is propagated to app
It is possible that TCP connect() will fail if for example network
interface does not have IP address set. In this case we close
the connection during net_tcp_connect() but do not set the return
code properly. This looks in the application like the connection
succeeded even if it was not.

As the tcp_in() call in net_tcp_connect() might close the connection,
we just take extra ref count while calling tcp_in(). Otherwise we
might access already freed connection.

Before the fix:

net_tcp_connect: context: 0x80757c0, local: 0.0.0.0, remote: 192.0.2.2
net_tcp_connect: conn: 0x8087320 src: 0.0.0.0, dst: 192.0.2.2
tcp_in: [LISTEN Seq=1604170158 Ack=0]
tcp_conn_close_debug: conn: 0x8087320 closed by TCP stack (tcp_in():3626)
tcp_conn_close_debug: LISTEN->CLOSED
tcp_conn_unref: conn: 0x8087320, ref_count=1
net_tcp_connect: conn: 0x8087320, ret=0

After the fix:

net_tcp_connect: context: 0x80757c0, local: 0.0.0.0, remote: 192.0.2.2
net_tcp_connect: conn: 0x8087320 src: 0.0.0.0, dst: 192.0.2.2
tcp_conn_ref: conn: 0x8087320, ref_count: 2
tcp_in: [LISTEN Seq=1604170158 Ack=0]
tcp_conn_close_debug: conn: 0x8087320 closed by TCP stack (tcp_in():3626)
tcp_conn_close_debug: LISTEN->CLOSED
tcp_conn_unref: conn: 0x8087320, ref_count=2
net_tcp: tcp_conn_unref: conn: 0x8087320, ref_count=1
net_tcp: net_tcp_connect: conn: 0x8087320, ret=-128

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-26 10:58:37 +01:00
Ben Wolsieffer
063b146eb4 net: tcp: Fix net_tcp_endpoint_copy() with IPv4 disabled
The IPv6 branch of net_tcp_endpoint_copy() was accidentally made
conditional on CONFIG_NET_IPV4 rather than CONFIG_NET_IPV6.

Signed-off-by: Ben Wolsieffer <benwolsieffer@gmail.com>
2024-09-26 03:32:26 -04:00
Torsten Rasmussen
205691edce cmake: linker: evaluate CONFIG_LINKER_ITERABLE_SUBALIGN in CMake
Evaluate CONFIG_LINKER_ITERABLE_SUBALIGN in CMake instead of in the
linker script.

It cannot be assumed that a linker generator implementation is
pre-processed and therefore Kconfig settings cannot be used in those
but must be evaluated in CMake.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-25 16:16:35 -05:00
Jukka Rissanen
765bfbbc3c net: stats: dns: Collect DNS statistics
If DNS statistics is enabled in Kconfig, then start to collect it.
This is useful in order to see how many DNS requests/responses
received or sent, and also see the amount of dropped DNS packets.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-25 13:52:15 -05:00
Jukka Rissanen
ca0bd2cc23 net: mdns: Discard the message if query count is 0
As described in RFC 6804 ch. 2, if query count is 0, discard
the message silently.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-25 13:52:15 -05:00
Yangbo Lu
6fe7f6c55d net: lib: http_server: fix snprintk issue of size_t
The size_t type may vary from machines. Current snprintk code was
causing below build issue on arm64.

error: format '%x' expects argument of type 'unsigned int', but argument
4 has type 'size_t' {aka 'long unsigned int'} [-Werror=format=].

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2024-09-25 04:00:02 -04:00
Carlo Kirchmeier
cb304318df net: dns: Improve interface count mismatch warning
In order to reduce confusion regarding interface count
the respective warning was adjusted to better reflect
the actual state of the system.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
2024-09-24 09:20:48 -04:00
Jukka Rissanen
00bb90a42e net: if: Check chksum offloading properly for VLAN interfaces
Make sure we check the checksum offloading capabilities correctly
for VLAN interfaces. Use the real Ethernet interface when doing the
check.

Fixes #78724

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-24 10:11:33 +02:00
Jukka Rissanen
8aab3ca39d net: shell: Allow user to disable not used commands
User can set CONFIG_NET_SHELL_SHOW_DISABLED_COMMANDS=n to prevent
unused net-shell commands from showing. This can save flash as
the disabled commands will not be shown in net-shell listing.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-23 14:10:15 +01:00
Jukka Rissanen
9d9398f42d net: shell: iface: Add DHCPv6 status prints
It is useful to know the currect status of DHCPv6 client when
printing the interface information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-23 14:10:15 +01:00
Jukka Rissanen
e459191ace net: shell: dhcpv6: Add cmd to start/stop DHCPv6 client
Allow user to use the net-shell to start or stop DHCPv6 client.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-23 14:10:15 +01:00
Jukka Rissanen
bc003db998 net: shell: dhcpv4: Add cmd to start/stop DHCPv4 client
Allow user to use the net-shell to start or stop DHCPv4 client.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-23 14:10:15 +01:00
Jukka Rissanen
7e4a2c6d46 net: shell: virtual: Add attach/detach commands
Allow "net virtual" command to attach or detach virtual
interfaces. This is useful for device management.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-23 14:10:15 +01:00
Robert Lubos
c377017146 net: shell: Enable IPv4/6 and iface commands if NET_NATIVE is disabled
Some commands can be executed and some statuses can be printed even if
native IP is disabled.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-09-23 14:08:34 +01:00
Robert Lubos
8d296ba8fe net: iface: Don't require native networking to register IP address
It shouldn't be needed to enable native networking to be able to
add/delete IP addresses on network interfaces.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-09-23 14:08:34 +01:00
Robert Lubos
5d085b49a9 net: ipv4: Make native IPv4 options dependent on NET_NATIVE_IPV4
IPv4 Kconfig options which only affect native IPv4 stack should be
dependent on NET_NATIVE_IPV4, similarly as it's done for IPv6.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-09-23 14:08:34 +01:00
Matt Rodgers
f2d8766b5d net: lib: http_server: remove dynamic resource data buffer
After introduction of struct http_response_ctx, the dynamic resource
data buffer is no longer needed for transferring data between the
application callback and the server. It is therefore removed to avoid
unnecessary copying of data.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-09-23 12:00:54 +02:00
Matt Rodgers
96061428e0 tests: http_server: add tests for dynamic response context
Add tests covering new method of providing a response for dynamic
resources.

Tests cover the application sending response codes and headers,
overriding "default" headers, and sending various combinations of
headers and body data. Each case is tested for HTTP1 & HTTP2, both POST
and GET methods.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-09-23 12:00:54 +02:00
Matt Rodgers
4cc905c513 net: lib: http_server: allow application to send headers/response code
Allow the application to send headers and response codes from a dynamic
resource callback by filling out a response context structure.

This also allows simple requests to be completed in a single execution
of the callback, by setting the final_chunk flag.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
2024-09-23 12:00:54 +02:00
Stefan Petersen
f88784a7ff net: ipv6: Setting Router Solication Packet timeout
Running IPv6 on STM32H743 using eth_stm32_hal I had to extend
the timeout between the attempts to send Router Solicitation packets
from 1 second to 2 seconds. Else it looked liked the packet never
got sent (checked using tcpdump).

Signed-off-by: Stefan Petersen <spe@ciellt.se>
2024-09-23 12:00:35 +02:00
Pisit Sawangvonganan
af4527e131 style: subsys: adjust return usage in void functions
For code clarity, this commit adjusts the use of `return` statements
in functions with a void return type as follows:
- Transform `return foo();` into separate statements:
  `foo();`
  `return;`
- Remove unnecessary `return` statements when
  they don't affect control flow.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-20 11:06:55 +02:00
Pisit Sawangvonganan
44ba8a5485 net: dhcpv6: adjust switch-case in dhcpv6_enter_state
For code clarity, unified switch-case usage in `dhcpv6_enter_state` to
use `break` instead of `return`.
Typically, a `break` is used in switch-case statements unless an early
return is necessary, in which case `return` is appropriate.

In this scenario, the `break` statement is the more suitable choice.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-20 11:06:03 +02:00
Daniel DeGrasse
bc8cb0be4c net: l2: wifi: ensure certificates directory is created
Ensure that the output certificates directory is created, where
generated certificates will be placed. This fixes a build error seen
when using `make` to build samples/net/wifi for the rd_rw612_bga board,
where the output directory for generated certificates did not exist at
build time.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-09-19 18:01:53 -04:00
Florian Grandel
da0371accf net: l2: ieee802154: decouple frame decryption from upper layer fields
The L2 function `ieee802154_decipher_data_frame()` relied on upper layer
LL address fields which breaks encapsulation.

Also fixes a bug introduced in another fix that went overboard (#53734).

Fixes: #78490

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2024-09-19 18:28:26 +01:00
Florian Grandel
766fda06c2 net: l2: ieee802154: move vars to top of block
Found a few variable declarations that were not yet moved to the top of
the function/block. Doing this before actually fixing #78490 so that the
fix becomes more readable.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2024-09-19 18:28:26 +01:00
Florian Grandel
a7f235596c net: l2: ieee802154: fix typo
renamed ieeee802154 to ieee802154

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2024-09-19 18:28:26 +01:00
Florian Grandel
041d8c707c net: l2: ieee802154: fix deadlock
When an incoming PAN ID does not match or when an error occurs while
sending association requests, then locks were not properly released.

Fixes: #78495

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2024-09-19 15:13:41 +02:00
Robert Lubos
fc007eeef5 net: sockets: tls: Prevent infinite block during handshake
In case peer goes down or we disconnect from the network during the
TLS handshake, the TLS socket may block indefinitely during
connect()/accept(), waiting for data from the peer. This should be
avoided, hence use the preconfigured timeout for the TLS handshake,
same as we use for TCP-level handshake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-09-19 03:27:05 -04:00
Fengming Ye
c642b44c95 net: wifi_mgmt: add DPP reconfig support
Hostap does not support wpa_cli DPP reconfig command.
So add wifi_mgmt DPP reconfig command and api.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-09-18 09:57:27 +02:00
Fengming Ye
23d2281d6a wifi: shell: add AP DPP shell commands
Add AP DPP shell commands by expanding wifi_cmd_dpp.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-09-18 09:57:27 +02:00
Fengming Ye
4f93c84a94 hostap: add AP network security type DPP
Add DPP security type for AP DPP support.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2024-09-18 09:57:27 +02:00
Shrek Wang
0b24b960fe net: Add onlink and forwarding check to IPv6-prepare
Deadloop happens when CONFIG_NET_ROUTING and VLAN are enabled.
In function net_ipv6_prepare_for_send(), pkt->iface will be
updated with net_pkt_set_iface(pkt, iface) in 2 scenarios:
1. ip_hdr->dst is onlink
2. check_route or nbr_lookup
VLAN is virtual-iface which attaches to a physical-iface. Each
time a packet being sent to a VLAN port will invoke twice of
the net_send_data(). The 1st time, pkt->iface is set to virtual
iface and the 2nd time to physical iface.
However in above 2 scenarios, at the 2nd time of calling the
net_send_data(), the pkt-iface will be changed back to virtual
iface. The system runs into a deadloop. This can be proved by
enabling CONFIG_NET_ROUTING with the VLAN sample.
The main purpose for net_ipv6_prepare_for_send() is to set the
right ll_dst address. If the ll_dst address is already set, then
no need to go through it again. If the packet has done with the
forwarding and set the ll_dst, then no need to check_route again.
And, the pkt->iface will not be changed back to virtual iface.

Fixes: #77402

Signed-off-by: Shrek Wang <shrek.wang@nxp.com>
2024-09-17 20:11:32 -04:00
Emil Lindqvist
f5981e5d8c net: shell: increase number of arguments to net suspend command
Increased variable to the mandatory amount of commands, since the
comment of SHELL_SUBCMD_ADD states

"Number of mandatory arguments including command name"

but net suspend takes the interface number to suspend

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2024-09-17 20:10:55 -04:00
Robert Lubos
bd56fecc61 net: iface: Add missing interface mutex locks
net_if_ipv4/6_addr_rm() were missing the iface mutex lock, this commit
adds it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-09-17 17:45:34 +01:00
Simon Walz
5af3fbadfd net: lwm2m: check each block for TLV header
For composite operations, we should always check whether the TLV header
is present. Otherwise, all blocks are assigned to one resource.

Signed-off-by: Simon Walz <simon.walz@autosen.com>
2024-09-17 17:45:17 +01:00
Simon Walz
e20ef4443e net: lwm2m: check lwm2m path level while getting the block ctx
The Block1 context for composite operations is not found, as all path
levels are compared. The incoming path level should therefore always be
taken into account.

Signed-off-by: Simon Walz <simon.walz@autosen.com>
2024-09-17 17:45:17 +01:00
Jukka Rissanen
9acf53e412 net: context: Set IPv4 address properly for sendmsg()
When using sendmsg() and if CONFIG_NET_IPV4_MAPPING_TO_IPV6 is
enabled, then the addr4 variable was set too late which was causing
null pointer access.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-17 05:22:48 -04:00
Keith Packard
40ac96aa57 net: dns: Ignore GCC warnings in mdns_responder.c
GCC complains about struct sockaddr accesses due to the various
address-family-specific variants being of differing sizes. Let's not
mess with code (which looks correct), just silence the compiler.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Jukka Rissanen
cd4b854c89 net: bridge: Ignore promisc mode errors for native-sim
We do not need promiscuous mode setting in host side when testing
bridging with native-sim, so just ignore errors in this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-13 13:42:20 +02:00
Valerio Setti
6be57aaedf net: sockets_tls: add support for TLS 1.3
Enables TLS 1.3 sockets based on Mbed TLS.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-09-12 13:31:20 -04:00
Valerio Setti
33931cf8e1 mbedtls: remove unused option MBEDTLS_SSL_EXPORT_KEYS
According to Mbed TLS changelog this feature was set default ON
since 3.1.0 release, so the build symbol is no more available.
This commit removes it from Zephyr.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-09-12 13:31:20 -04:00
Fin Maaß
b32a44aa7e net: config: sntp: add periodic resync option
this adds the option to have the clock periodically resynced with
the time from the sntp server, instead of just syncing at startup.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-09-12 14:48:07 +02:00
Jukka Rissanen
1f627e3a1b net: mdns_responder: Set socket of service for statistics purposes
If the dispatcher is muxing the connection i.e., so there are two
services for the same port, then mark service socket descriptor
of the service with the socket number so that "net sockets" shell
command can show a proper value for it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-11 07:40:07 -04:00
Jukka Rissanen
caf9fd345f net: dns: Add per socket user data for the dispatcher
The socket services API has a limitation where the user data is shared
between file descriptors described in the same service.

This can cause problem in DNS dispatcher where each listened socket
needs to have their own dispatcher struct set as user data so that we
can map between dispatcher context and socket. Solve this by always
have a dispatcher table as user data, and then have the actual mapping
done via the dispatcher table when receiving data to the dispatcher socket.

Fixes #78146

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-11 07:40:07 -04:00
Jukka Rissanen
dcb71a754f net: http_server: Enable v4-to-v6 mapping by default
Fixing the regression caused by 3949873886 ("Allow service to be
created with NULL host"). If the host parameter is null when creating
the HTTP service, the IPv6 socket is created by default. This can cause
issues if both IPv4 and IPv6 are enabled, like in HTTP server sample,
and the HTTP client connection is done by IPv4.
To fix this, we need to enable IPv4-to-IPv6 mapping in order to allow
IPv6 socket to serve a IPv4 connection. Allow also user to override this
if needed.

Fixes #78112

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-10 21:51:54 -04:00
Jukka Rissanen
61c135e531 net: if: Fix rejoining IPv6 multicast group
The code was checking IPv4 address instead of IPv6.
Print also IPv6 address when rejoining the group.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-10 21:51:39 -04:00
Robert Lubos
e6f942f238 net: lwm2m: Fix enabler version reporting during bootstrap discovery
LwM2M 1.1 specification mentions that the enabler version format was
specified wrongly in LwM2M 1.0 specification, and servers only "may"
accept the old format, which no longer seems to be the case for Leshan.

The URI reference ("</>;") before the enabler version is now mandatory,
if it's missing the bootstrap discovery fails with Leshan. Another
problem are quotes around the enabler version, which seems to be
conditionally accepted only for LwM2M version 1.0. Therefore, keep the
quotes only for that version, to prevent any potential issues with other
servers.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-09-10 11:43:18 +02:00
Pisit Sawangvonganan
d207edb1cf shell: rename shell_xxx_impl wrapper functions to shell_fprintf_xxx
Since the `_impl` naming convention is intended for internal use only,
renaming these functions to the `shell_fprintf_xxx` variant is
more suitable for calls outside the module:
- `shell_info_impl` to `shell_fprintf_info`
- `shell_print_impl` to `shell_fprintf_normal`
- `shell_warn_impl` to `shell_fprintf_warn`
- `shell_error_impl` to `shell_fprintf_error`

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-09 13:55:31 -04:00
Jukka Rissanen
da97542a6e net: dhcpv6: Do not wait forever when allocating net_pkt
As the allocation is run in system workqueue context, it can
cause problems if waiting forever when allocating net_pkt.

Fixes #77935

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-09 09:28:21 +02:00