Commit graph

6489 commits

Author SHA1 Message Date
Damian Krolik
391290e67d net: shell: udp: allow sending packet when bound
"udp bind" and "udp send" commands use the same net context
variable and they fail early if the context is already used.

This prevents from using "udp send" after "udp bind", which
makes the commands hard to use for testing bidirectional
communication. Make "udp send" reuse the already bound
context if possible, and resort to allocating temporary one
otherwise.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2025-05-27 11:51:11 +02:00
Shrek Wang
b5a31dcb49 net: tcp: Move the CLOSED state to the front
In enum tcp_state {}, the CLOSED state was put at the last one.
When we do Sequence & Ack validation, we will need to skip the
CLOSED, LISTEN, SYNSENT states. It is easier for coding if we
put the CLOSED to the front, e.g. if state > SYNSENT. And, in
other OSes, the state sequence is normally defined like this.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-05-27 06:51:46 +02:00
Robert Lubos
3572c9f825 net: http: client: Allow to abort download from response callback
Update the response callback function signature to allow the callback to
return an error code, which in turn will cause the HTTP client to abort
the download.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-23 17:20:24 +02:00
Robert Lubos
73e248f6cf net: zperf: Make UDP upload report retransmission count configurable
Add a Kconfig option to configure the maximum retransmission count of
the UDP upload report.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-23 17:20:10 +02:00
Robert Lubos
02530beeda net: zperf: Fix invalid zsock_recv() error check
The return value can only be -1, errno value should be verified instead
for the actual error code.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-23 17:20:10 +02:00
Maochen Wang
804e6a22ce net: l2: wifi:fix the parameter count error when start SAP
During previous commit of adding interface arg, wrongly change the
parameter count of 'wifi ap enable' to a small one. Change the value
to 47 can fix this issue and match the need of adding interface arg.

Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
2025-05-22 17:03:39 +02:00
Robert Lubos
2bb9aef4b1 net: sockets: tls: Add new option to register certificate verify cb
Add new TLS socket option, TLS_CERT_VERIFY_CALLBACK, which allows to
register an application callback to verify certificates obtained during
the TLS handshake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-22 13:44:43 +02:00
Robert Lubos
887e8e0e7e net: sockets: tls: Add new option to retrieve cert verification result
Add new TLS socket option, TLS_CERT_VERIFY_RESULT, to obtain the
certificate verification result from the most recent handshake on the
socket. The option works if TLS_PEER_VERIFY_OPTIONAL was set on the
socket, in which case the handshake may succeed even if certificate
verification fails.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-22 13:44:43 +02:00
Jordan Yates
b212fb91bd net: ip: net_pkt: conditional net_if_get_by_iface
Don't reference `net_if_get_by_iface` if `CONFIG_NET_RAW_MODE=y`, since
`net_if.c` is not compiled in that case, leading to linker errors.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-05-22 04:53:08 +02:00
Alberto Escolar Piedras
44699baff5 subsys/net/lib/shell: Fix code compliance issues
Fix issues detected by checkpatch

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-05-21 12:35:28 +02:00
Chaitanya Tata
3611d5eeaf net: l2: wifi: Add interface arg for all commands
In order to support working with multiple VIFs (e.g., STA + AP) add
interface as an option for all commands.

The interface can belong to same chipset or different (hypothetical).

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-05-21 12:34:22 +02:00
Jukka Rissanen
4f1095206f net: if: Add debug prints for IPv6 prefix selection
Useful to see what prefix is being selected for a given
IPv6 address if debugging is enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-05-21 09:30:22 +02:00
Jukka Rissanen
75860479cd tests: net: ipv6: Fix deprecated address selection
Make sure the IPv6 address selection works as specified.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-05-21 09:30:22 +02:00
Jukka Rissanen
da13b5184c net: if: Prefer always preferred IPv6 address
Always prefer preferred IPv6 address over deprecated one
regardless of prefix length. This works now same way as in
Linux.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-05-21 09:30:22 +02:00
Shrek Wang
20489a1f18 net: tcp: Fix TCP reset issue
According to RFC793 chapter3.5 with the 'Reset Processing' part,
"In the SYN-SENT state (a RST received in response to an initial
SYN), the RST is acceptable if the ACK field acknowledges the SYN."
So, in the net_tcp_reply_rst() we should use 'ack++' if no ACK
flag but have SYN flag.
And, all the RST packet should use net_tcp_reply_rst() instead of
tcp_out().

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-05-21 08:01:55 +02:00
Robert Lubos
011f2bc458 net: conn_mgr: Fix disconnect with CONN_MGR_IF_NO_AUTO_DOWN unset
Connection manager enforces non-blocking disconnect() behavior, yet in
case CONN_MGR_IF_NO_AUTO_DOWN flag is not set, it'd put the interface
down right after, disrupting the disconnect process.

As putting the interface down can be handled in the corresponding event
handler as well, when the interface is actually disconnected, remove the
conn_mgr_conn_if_auto_admin_down() call from conn_mgr_if_disconnect().
To make this work with persistence flag, introduce a new internal flag
indicating that the interface is in active disconnect.

Finally, since it isn't really necessary that disconnect() API call is
non-blocking, remove that requirement.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-19 16:37:07 +02:00
Damian Krolik
82b802f9ab net: lib: zperf: fix compilation with UDP/TCP only
Fix regression introduced by #88747 that breaks linking
with zperf server enabled but TCP or UDP disabled.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2025-05-19 11:24:58 +02:00
Anas Nashif
2aacbcaab5 style: add missing curly braces in if/while/for statements.
Add missing curly braces in if/while/for statements.

This is a style guideline we have that was not enforced in CI. All
issues fixed here were detected by sonarqube SCA.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-17 14:10:33 +02:00
Shrek Wang
6ee55e4211 net: tcp: Remove NULL-pkt support for tcp_in()
The NULL-pkt parameter for tcp_in() was designed for generating
a SYN packet to start the 1st TCP handshake. It is only used
in net_tcp_connect() and tp_input().
To simplify the tcp_in() code logic and make it better under-
standable, a tcp_start_handshake() is added for net_tcp_connect()
and tp_input() to use. Thus, the tcp_in() only handles the in-
coming TCP packets.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-05-15 16:17:18 +02:00
Chris Friedt
393446108e samples: net: lwm2m: depend on xsi single process for gettimeofday()
https://github.com/zephyrproject-rtos/zephyr/actions/runs/\
15014534061/job/42189411225

We were seeing a linker error of the form

```
picolibc/x86_64-zephyr-elf/lib/32/libc.a(libc_time_time.c.o): \
  in function `time':
time.c:(.text.time+0x11): undefined reference to `gettimeofday'
```

Update the dependency from CONFIG_POSIX_TIMERS to
CONFIG_XSI_SINGLE_PROCESS for gettimeofday().

Note: this is really only a workaround. The proper solution would
be to have libc functions not depend on POSIX functions.

Specifically, here

https://github.com/zephyrproject-rtos/picolibc/blob/\
51a8b32857e75345c37652a80b5cda98b28d69e5/newlib/libc/time/\
time.c#L54

and here

https://github.com/zephyrproject-rtos/zephyr/blob/\
3a4e12899c2ae5962a64055f4739f774fb7262e5/lib/libc/common/\
source/time/time.c#L17

Also mentioned in #89068

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-15 09:04:08 +02:00
Jordan Yates
0f1d7d3b59 net: dns: dispatcher: fix OOB array access
Validate that the file descriptor is not a negative number before
writing to the `dispatch_table` `ctx` field. Setting file descriptors
to `-1` is the standard "not in use" value, and in fact the entire array
of `fds` is set to this value in `dns_resolve_init_locked`. This
resolves memory corruption of whichever variable is unfortunate to exist
just before `dispatch_table` in memory.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-05-14 14:11:11 +02:00
Robert Lubos
e1d77710b7 net: mqtt-sn: Correct the allowed Keep Alive value range
Keep Alive timeout is represented by 2-byte unsigned integer, however
the corresponding Kconfig option was limited to UINT8_MAX only.
Also, similarly to regular MQTT, allow to disable the Keep Alive
functionality by specifying the Keep Alive value to 0.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-14 14:10:34 +02:00
Markus Lassila
93c3975fe6 net: l2: ppp: Terminate connection with dormant
When PPP net_if is changed to dormant, the PPP connection
is terminated asynchronously. This is used so that the driver
can terminate the PPP connection gracefully.

Note: net_if_down() is not used as it would require synchronous
operation which would block the system workqueue thus causing
deadlock.

Signed-off-by: Markus Lassila <markus.lassila@nordicsemi.no>
2025-05-14 14:10:21 +02:00
Tomi Fontanilles
35f7eda545 modules: mbedtls: make key exchange Kconfigs depend on, not select
Turn the MBEDTLS_RSA_FULL selects into depends on.
This is how the other MBEDTLS_KEY_EXCHANGE_* Kconfig options are defined.

This is done to avoid circular dependencies.

At the same time update uses of the affected MBEDTLS_KEY_EXCHANGE_*
Kconfig options to enable/disable the dependencies which used to be
automatically handled.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2025-05-13 22:22:43 -04:00
Robert Lubos
be46c94e3e net: l2: openthread: Fix error logs on adding already present address
Error checking of otIp6AddUnicastAddress() and
otIp6SubscribeMulticastAddress() was added recently, however it wasn't
taken into account that those APIs return an error on attempt to
register an IPv6 address that is already present on the OT interface.
Therefore, add more specific error checks, to return silently in case
address was already present.

As those two APIs are not very consistent, and otIp6AddUnicastAddress()
returns OT_ERROR_INVALID_ARGS in such cases, add an extra check if the
address is already present before attempting to register the address.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-13 16:23:37 +02:00
Seppo Takalo
252f8fefe0 net: lwm2m: Fix blockwise Ack NUM calculation
After the PR #85000 the calculation of NUM field of
Block 1 option on CoAP Ack packet started to advance
to next packet block.

We should not update the ctx->current field because it is
used for calculating the NUM field in response packet.
It should point to beginning of the payload,
so the response is correct.

Leshan server don't seem to care about this, but Coiote does.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2025-05-12 16:47:58 +02:00
Yangbo Lu
1ee51232de net: ptp: fix infinite loop in pkt frag
There was wrong implementation in pkt frag removing and inserting.
This was causing infinite loop in either net_buf_frag_last or
net_pkt_get_len. This happened only when the pkt frag removing
and inserting was executed too fast after sending pkt before
ethernet_send calling net_pkt_get_len.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-05-12 14:54:06 +02:00
Fin Maaß
ff5e031c20 net: conn_mgr: set to unstable
Set connection manager to unstable. It is now used
by multiple parts in zephyr and numerous samples.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-10 13:02:21 +02:00
Fin Maaß
bad506eb7a net: config: init: sntp: use connection manager
Add option to use the connection manager to
schedule a (re-) sync on connection and diabeling the
work, when there is no connection.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-10 13:02:21 +02:00
Fin Maaß
265eb71eef logging: backend: net: use connection mgr
Use connection manager to deactivate and activate
net log backend.
This removes the warnings about dropped packages
completly.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-10 13:02:21 +02:00
Fin Maaß
e7047059b1 logging: backend: net: avoid early enabling
Avoid early enabling of the syslog backend in
the the dhcpv4 options parser.

When CONFIG_NET_IPV4_ACD is enabled, the assigned ip address has
not been checked, when the other dhcpv4 options are parsed, this would
lead to the syslog backend being enabled before the src ip address
is valid, so we get lots of warnings about dropd packets, this fixes
it at least on start. We will still get the warnings, when the iface
goes down and then up later.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-10 13:02:21 +02:00
Robert Lubos
53f01fa37c net: ip: mld: Ensure MLD APIs work with offloaded interfaces
MLD APIs are commonly used across the codebase to configure IPv6
multicast addresses on network interfaces. Sending MLD reports however
works only for native interfaces as it uses low-level APIs. Therefore,
in order to make the APIs at least semi-functional for offloaded
interfaces as well (i.e. allow to configure multicast address on
the interface), return early in case interface is offloaded.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-09 18:00:14 +02:00
Robert Lubos
e0a1e910ac net: ip: igmp: Ensure IGMP APIs work with offloaded interfaces
IGMP APIs are commonly used across the codebase to configure IPv4
multicast addresses on network interfaces. Sending IGMP reports however
works only for native interfaces as it uses low-level APIs. Therefore,
in order to make the APIs at least semi-functional for offloaded
interfaces as well (i.e. allow to configure multicast address on
the interface), return early in case interface is offloaded.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-09 18:00:14 +02:00
Robert Lubos
4d01228193 net: mqtt_sn: Use zsock_inet_ntop instead of inet_ntop
Use zsock_inet_ntop() instead of inet_ntop() to avoid dependency to the
POSIX subsystem in the library.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-09 18:00:14 +02:00
Robert Lubos
d745689fe7 net: mqtt_sn: Verify result of transport initialization
The result of the transport init() function should be propagated to the
application, otherwise the initialization could fail silently.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-09 18:00:14 +02:00
Robert Lubos
a04e9fd0de net: mqtt_sn: Make sure multicast functionalities are enabled
UDP transport for the MQTT SN libraries depends on IGMP/MLD APIs
unconditionally (via respective setsockopt calls) and without them being
enabled transport initialization would fail. Therefore, ensure
respective multicast libraries are always enabled if MQTT SN UDP
transport is used.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-09 18:00:14 +02:00
Shrek Wang
e59fb26db8 net: tcp: Remove the 'goto next_state' in tcp_in()
Each incoming TCP packet has been completely handled in current
state. No need to do further process by 'goto next_state'.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-05-09 18:00:00 +02:00
Vytautas Virvičius
9a409d6b00 net: l2: ppp: Explicitly negotiate ACCM
Many cellular modems attempt to negotiate an ACCM value of 0x00000000.
While the PPP driver rejects this by default, it does not propose an
alternative. As a result, some modems default to using 0x00000000 after
LCP negotiation. Because the PPP driver expects all control characters
to be escaped, this causes issues during decoding. This change
negotiates an ACCM value of 0xffffffff to ensure compatibility with such
modems.

Signed-off-by: Vytautas Virvičius <vytautas@virvicius.dev>
2025-05-09 08:23:16 +02:00
Robert Lubos
45a1cf7fcc net: dhcpv4: client: Do not generate new xid for Request message
According to RFC 2131, DHCP clients should use the same xid as
received in the Offer message when sending DHCP Requests. Therefore,
when generating DHCP Request message, the xid value should not be
incremented.

One vague topic is whether the xid value should be updated when
sending Requests from Renewing or Rebinding states, however RFC makes no
exception for those states, and other implementations (dhclient, lwip)
seem to reuse the same xid in such cases, so comply with this behavior.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-08 15:55:55 +02:00
Robert Lubos
9d54465559 net: dhcpv4: client: Handle Pad option
Pad option (option code 0) can be present in between other options for
alignment. The option has a fixed 1-byte length (i. e. no length field),
therefore it did not fall under the common processing code for
unrecognized options (which include the length field at the second
byte). Therefore, not processing this option explicitly could disturb
other options processing, as the parser would wrongly interpret the next
option code as the length field. This commit adds Pad option handling to
fix the issue.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-08 15:55:55 +02:00
Robert Lubos
f4408c088c net: dhcpv4: client: Prevent asserting on malformed message
In case the received DHCP message is malformed and contains invalid
message type, the code responsible for matching message type with a
string would assert. This shouldn't be the case that external conditions
(like receiving malformed packet) trigger asserts in the system.
Therefore modify that code, to return "invalid" string in such case
instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-08 15:55:55 +02:00
Robert Lubos
493be790ac net: http: client: Fix the body callback processing
Response "data_len" field needs to be set with the size of the
received data before calling the parser as it's used inside the on_body
callback, this commit fixes it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-08 14:01:07 +02:00
Yangbo Lu
07e1de381a net: ptp: adjust only frequency for continuous synchronization
Current clock synchronization was always stepping clock. This was
causing large offset, and discontiguous ptp hardware clock time.
For TSN hardware, discontiguous ptp hardware clock time was not
able to be used for other TSN protocols.

This patch is to convert to frequency adjustment with a basic
PI control algorithm.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-05-08 12:25:30 +02:00
Yangbo Lu
e9efff6e33 net: ptp: calculate link delay with right timestamps
At the starting of ptp syncrhonization, there may be not Sync frame
TX/RX timestamps in first time link delay calculation.
So, need a check for that in case of wrong link delay calculated.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-05-08 12:25:30 +02:00
Shrek Wang
f2ef654155 net: tcp: Replace the FIN only case with FIN+ACK
According to TCP Spec. RFC793, ACK flag should be always set
after sequences of both sides are sync-ed except for RST seg-
ment. It is not necessary to send FIN only packet in the
test case, using FIN | ACK instead.
Similarly, change the tcp_out(conn, FIN | ACK) in CLOSE_WAIT.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-05-06 10:50:39 +02:00
Arkadiusz Balys
596844a2cb openthread: Move OpenThread implementation from net to modules
Move OpenThread-related code from
zephyr/subsys/net/l2/openthread/openthread.c to
zephyr/modules/openthread/platform/openthread.c.

The primary goal of this refactor is to enable the use
of OpenThread as an independent module, without the necessity
of Zephyr's networking layer.

This change is particularly beneficial for simple applications
that have their own implementation of the IEEE802.15.4 driver
and do not require a networking layer. These applications can
now disable Zephyr's L2 and IEEE802.15.4 shim layers and
directly use the OpenThread module, saving valuable kilobytes
of memory.

In this approach if the CONFIG_NET_L2_OPENTHREAD
Kconfig option is set, Zephyr's L2 and IEEE802.15.4 layers
will be used, and everything will function as before.
The main difference is the Zephyr's L2 layer now uses
the OpenThread module, no longer implementing it.

While most of the functions in include/net/openthread.h
have been deprecated, they are still available for use to
maintain backwards compatibility.

Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
2025-05-05 14:25:13 +02:00
Fin Maaß
211c0e3819 net: config: init: remove second init of syslog
Doing another init of the log_backend_net in
the net config init could lead to the
server, set during runtime, being overwritten
by the Kconfig default.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-05 12:21:00 +02:00
Robert Lubos
d60831810b net: websocket: Make use of any leftover data after HTTP processing
In case HTTP client read out more data from a socket that it processed
it will indicate there is leftover data in the receive buffer available.
Make use of it at the websocket level, so that no data is lost. As we
reuse the same receive buffer in this case, it's only needed to update
the count variable to indicate how many bytes are available.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-05 10:57:43 +02:00
Robert Lubos
4a85e47061 net: http: client: Notify application about unprocessed data
The HTTP client would read data from a socket up to the size of the
receiving buffer, however it may not process them all. This is usually
only the case if protocol switching takes place, where the data read may
belong to another protocol. Therefore we need a way to notify the caller
about any potential data that is already present in the buffer and needs
to be processed.

Introduce an new data_len member in struct http_request to provide the
information about the data already available in the receive buffer. If,
after HTTP response processing, the value is non-zero, the data will be
available in the beginning of the user provided receive buffer.

To make this possible however, we need to track how many bytes were
actually processed by the http_parser, therefore the code will no longer
ignore the http_parser_execute() return value. To simplify processing,
it's also been changed how the receive buffer is used. Instead of using
it in a ring-buffer-like way, the offset variable will track how many
bytes are available in the buffer, and in the rare occasions when not
all data from the buffer was processed by the HTTP parser, we'll
memmomve the remaining data to the beginning of the buffer.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-05 10:57:43 +02:00
Yangbo Lu
f8b450d6a5 net: gptp: adjust only frequency for continuous synchronization
Current clock synchronization was always stepping clock. This was
causing large offset, and discontiguous ptp hardware clock time.
For TSN hardware, discontiguous ptp hardware clock time was not
able to be used for other TSN protocols.

This patch is to convert to frequency adjustment with a basic
PI control algorithm.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-05-02 09:17:12 +02:00