Commit graph

6647 commits

Author SHA1 Message Date
Chaitanya Tata
2f991f2bff net: lib: zperf: Add support for skipping UDP upload server report
Add support for skipping UDP upload server report, useful in test TX
only with loopback (packets are dropped, so, no report).

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-06-02 17:37:55 +02:00
Shrek Wang
6e7756a542 net: tcp: Change SYN FIN to use send_data_timer
The send_queue was used as SYN/FIN packet retransmission. Before
the SYN/FIN being ACKed and dequeue-ed, the following packets in
the send_queue cannot be sent out. That's why Zephyr had to send
a FIN+ACK instead of a duplicated ACK-only in FINWAIT1, CLOSING.
In fact, we can take SYN/FIN as kind of data and use the same
send_data_timer for retransmission, like other OSes do. This way,
the send_queue is simply used for local traffics.
Benefits (in theory):
1. The code is easier,
2. TxPkt performance is better after skipping enq/deq send_queue,
3. The struct tcp{} node is a few bytes smaller, saving memory.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-06-02 13:30:19 +02:00
Pieter De Gendt
d5931bae93 net: lib: coap: Return an error on removing a non-existing observer
If we're parsing a CoAP request with an observe option of '1', but there is
no matching observer, return an error instead of returning a zero.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-05-30 10:28:02 +02:00
Robert Lubos
38e00d1969 net: tcp: Fix user_data provided to accept callback
TCP implementation provided the parent net_context pointer to the
accept callback instead of the user_data pointer registered with
net_tcp_accept(). This worked fine with the socket integration, as
sockets explicitly registered parent context as user_data, however it
shouldn't be hardcoded like this at the TCP level.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-29 12:05:58 +02:00
Shrek Wang
744380a278 net: tcp: Use correct seqnum for tcp_out and tcp_out_ext
Based on TCP Spec., the outgoing TCP packets shoud use SND.NXT as
the seqnum. In Zephyr, the conn->seq works as the SND.UNA and the
conn->seq + conn->unacked_len works as the SND.NXT. Currently, it
uses SND.UNA in tcp_out() as the seqnum, which might get dropped
as old packets and could not deliver the message to the peer.
A few exceptions use SND.NXT - 1 as the seqnum are: keepalive,
zero-window-probe, FIN/SYN retransmissions. And, for closing a
connection, Zephyr won't send out FIN until all the data has been
ACKed, so the conn->unacked_len is 0 and it is ok to use conn->seq
as the SND.NXT.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-05-29 08:42:20 +02:00
Robert Lubos
c26f39450d net: context: Verify if CONFIG_NET_SOCKETS_PACKET_DGRAM is enabled
Verify if CONFIG_NET_SOCKETS_PACKET_DGRAM is enabled when creating a
datagram packet socket. Otherwise, it's possible to create
non-functional AF_PACKET/SOCK_DGRAM socket w/o an error.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-05-28 15:33:24 +02:00
Jukka Rissanen
e44ed8dbb8 net: ipv6: Make sure we do not access link address past array length
It is possible to manually set link address length past 6 at runtime
and trying to generate IPv6 IID address that way. This should fail
as we could read two bytes past the address buffer. There is no issues
in the copying as the target buffer has plenty of space.

Coverity-CID: 516232

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-05-28 10:05:21 +02:00
Chen Tao
b513e08271 net: wifi: fix the bug by non-wifi network call
Added network type check to fix the system crash caused by non-wifi
network card calling wifi api interface

Company:BSH Crop
Signed-off-by: Chen Tao <ct05342@163.com>
2025-05-27 11:51:23 +02:00
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