Commit graph

6,767 commits

Author SHA1 Message Date
Cla Mattia Galliard
1e4bc2855e net: connection: Unconditionally forward into packet sockets
When handling packets for inputing into packet-sockets, unconditionally
forward them, so that they may be handled by the rest of the network
stack after.

Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
2025-09-22 17:49:19 -04:00
Robert Lubos
178150590c net: tcp: Fix ACK processing when FIN packet is received
In case FIN packed also acknowledged most recently sent data, not all
ack-related TCP context variables were updated, resulting in invalid SEQ
number values sent in consecutive packets.

Fix this by refactoring the FIN handling in TCP_ESTABLISHED state.
Instead of having a separate block strictly for FIN packet processing,
let the packet be processed by common code responsible for regular
data/ack processing. This should be less error-prone for any future
modifications or not-yet-discovered issues. Only after the common
processing of data/ack is done, we check whether FIN flag was present in
the packet, and mark the connection for closing.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-09-22 09:52:13 +02:00
Robert Lubos
eda76ad21b net: tcp: Preallocate TX packet for TCP context
TCP context cannot operate w/o a TX packet for buffering transmitted
data. So far this net_pkt was allocated at runtime from the common
packet pool, but this created some not-obvious memory requirement on TCP
and could lead to TX packet starvation in case many TCP connections are
open in parallel. Therefore, allocate this packet structure statically,
as a part of the TCP context instead.

This increases the memory requirement of the TCP context by ~64 bytes,
however if that's a concern for the application, the maximum number of
TX packets can be lowered instead. In return, we get a clear separation
between the number of TCP connections opened, and the amount of packets
that can be transmitted.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-09-22 09:51:10 +02:00
Robert Lubos
b8c7984099 net: pkt: Add helper function to initialize TX packet
Add helper function to initialize externally allocated TX packet. It's
especially important to configure net_buf slab for the packet so that
net buffers are allocated from a correct pool for the packet.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-09-22 09:51:10 +02:00
Robert Lubos
aca511c91f net: tcp: Use net_buf pointer directly for out-of-order recv queue
Using net_pkt for TCP out-of-order recv queue was an overshot, as the
mechanism mostly used net_buf operations directly anyway. It can be
easily replaced with a direct net_buf pointer, so that it's not longer
needed to hog one net_pkt per TCP context anymore.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-09-22 09:51:10 +02:00
Cristian Bulacu
cdf5811791 net: dns: DNS resolver packet forwarding
This aims to implement a packet forwarding mechanism between
DNS resolver and applications that install a callback, letting
DNS resolver know that received UDP packet is also required by an
application.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-09-19 08:34:06 -04:00
Chaitanya Tata
19449e4396 wifi: treewide: Adjust defaults for dual mode usage
In case STA + AP mode is enabled, then adjust the defaults to accomodate
the second interface.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-09-19 08:27:55 -04:00
Robert Lubos
13a228381b net: tcp: Remove duplicate headers and function declarations
TCP somehow ended up with two internal headers with duplicate set of
internal function declarations. As tcp.h looks like a subset of the
tcp_internal.h header, combine the two headers into a single
tcp_internal.h and remove tcp.h. There were some differences in doxygen
API descriptions, so I've used the description that better described the
actual function purpose.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-09-18 13:50:46 -04:00
Robert Lubos
3d85e8f0ac net: tcp: Implement TCP connection backlog
Implement TCP connection backlog for TCP server. The backlog parameter
is already specified by the listen() socket API, however it was never
implemented in Zephyr. It can be useful to limit the number of incoming
connections on the server side, and thus limit the connection flood and
resource shortage.

The backlog is implemented as a atomic counter inside the TCP context.
The counter is initialized on the listen() call (and thus no connection
can be accepted before listen() is called), and then decremented
whenever new connection is initiated. When the application accepts
the incoming connection, it should call the net_tcp_conn_accepted()
API (done automatically for sockets) to inform the TCP layer that the
backlog can be incremented. The backlog value is also incremented back
if the connection is released before the connection was passed to the
application.

For tracking the parent (listening) socket, the 'accepted_conn' pointer
on the client context has been reused. Note, that the pointer used to be
cleared before the accept_cb() call before, to prevent consecutive calls
to the callback, however this was not really needed - the TCP state is
changed anyway, and the accept_cb() is only used in TCP_SYN_RECEIVED
state. The pointer is no cleared when the application accepts the
connection (or the client or the associated parent context is closed).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-09-18 13:50:46 -04:00
Marcel Wappler
9401406e6a net: lwm2m: finalize CBOR output on -ENOMEM instead of aborting
When encoding cached LwM2M 1.1 resources into SenML CBOR, the encoder
currently aborts with -ENOMEM if the number of records (minus
some CBOR delimiter elements) exceeds CONFIG_LWM2M_RW_SENML_CBOR_RECORDS.
This discards all serialized data and prevents any payload from
being sent, leaving the client stuck and caches filling up.

This patch changes the behavior: if some records were already
serialized before the buffer shortage, the CBOR output is finalized
(end marker added) and the partial payload is returned. This allows
the client to send useful data, and the upper layers can react by
reducing batch size.

Impact:
- Preserves forward progress instead of canceling the message
- Avoids cache lock-up
- No changes to the API or success path behavior

Signed-off-by: Marcel Wappler <marcel.wappler@decentlab.com>
2025-09-18 13:50:13 -04:00
Cristian Bulacu
c953517245 net: l2: openthread: Implement packet forwarding rules.
Inject packets from AIL to Thread network and vice versa taking into
account packet forwarding security safeguards and multicast forwarding.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-09-18 15:42:30 +01:00
Jukka Rissanen
221aca4bb9 net: if: Fix assert when checking lladdr existence
As the linkaddr->addr is no longer a pointer, the original
assert check is not working as it should. So use the length
of the linkaddr to verify that it is > 0.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-09-17 19:10:31 -04:00
Cristian Bulacu
2928670381 net: l2: openthread: Parse Border Router messages in correct context.
This commit adds a work item designated for Border Router message
parsing. A generic message structure has been proposed.

If CONFIG_NET_IPV4 is enabled, border router services will start only
after an IPV4 address has been assigned on the backbone interface.
If border router is initialized before DHCPV4 client has been assigned
an address, initial mDNS IPV4 packets will be dropped, because a source
address cannot be retrieved from that specific backbone interface.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-09-17 16:37:49 +02:00
Michael Zimmermann
5bba1edb6e mqtt_sn: process_ping: fix infinite loop
When next_ping == now, the code scheduled the workqueue for the current
time. On native_sim, this meant that the system workqueue thread was stuck
in an infinite loop because it kept processing the MQTT work over and over
again and the current timestamp could not advance anymore.

I didn't investigate why the yield inside the workqueue didn't help or why
native_sim can't advance time when one of the threads is stuck, but
changing the condition to >= inside mqtt_sn solves this issue.

I discovered this while running zephyr.exe through strace for up to 60
minutes. I guess that the performance overhead makes it more likely for the
workqueue handler to be run while next_ping == now, but I didn't verify
that, because it takes a long time to trigger the bug.

Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
2025-09-17 16:32:49 +02:00
Yangbo Lu
590d9d1c6f net: dsa: support PTP timestamping in netc tag driver
Supported PTP timestamping in netc tag driver.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-15 14:06:56 -04:00
Yangbo Lu
15dc8d78f2 net: pkt: support common usage of control block
Supported common usage of control block for any layer.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-15 14:06:56 -04:00
Yangbo Lu
997edb4e13 net: dsa: add PTP solution in core driver
Added PTP solution in core driver. Now only gPTP was supported.

- ethernet_api like get_capabilities and get_ptp_clock
  were supported in port driver.

- For TX timestamp, added new dsa_api port_txtstamp for device
  to handle. Device driver might put pkt in queue, and reported
  timestamp after completing transmitting on hardware.

- For RX timestamp, the timestamp could be given to pkt in tag
  driver or device driver.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-15 14:06:56 -04:00
Yangbo Lu
eabc1b38bf net: dsa: support tagger data and connecting device to tag protocol
Supported tagger data and connecting device to tag protocol, so that some
device specific work could be handled.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-15 14:06:56 -04:00
Yangbo Lu
ea6bdfe890 net: dsa: move dsa_tag_netc.h to public include directory
Moved dsa_tag_netc.h to public include directory for devices
reusing.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-15 14:06:56 -04:00
Jukka Rissanen
909710b598 net: context: Make sure TCP allocation is not leaked
If we have allocated a TCP connection, and if after that
we get an error like EADDRINUSE, then we must de-allocate
the TCP connection otherwise there is a buffer leak.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-09-13 18:13:21 -04:00
Georgios Vasilakis
53b2802fff net: websocket: Allow using PSA APIs to calculate SHA1
The websocket used mbedtls functions to calculate the
SHA1 needed. Update the code to use PSA crypto calls instead
when the configuration CONFIG_MBEDTLS_PSA_CRYPTO_CLIENT
is enabled.

This can be useful for applications which use TF-M
since it only provides PSA crypto APIs.

Also check the error code from the mbedtls_sha1
call since it can fail and it was not checked before.

Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no>
2025-09-12 18:31:04 +02:00
Yangbo Lu
5aaf69e145 net: ethernet: make inclusion relation clear for DSA and Ethernet headers
DSA is part of Ethernet and will utilize more Ethernet definitions for
more features support. So, it's proper to let DSA header include
Ethernet header with moving some DSA definiton from DSA header to
Ethernet header and adding DSA header including in c files using DSA
definition.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-12 13:19:41 +02:00
Yangbo Lu
0501be8090 net: ethernet: use void pointer for dsa switch context
In ethernet_context structure, it just needs a void pointer
for dsa switch context.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-12 13:19:41 +02:00
Philipp Finke
8a831150f0 net: sockets: socket_service: Fixed issue that prevented reconfiguration
Once running, a socket service could not be reconfigured (i.e. changing
file descriptors and/or events to be polled). This was due to an wrong
check at the end of the thread main loop of socket_service_thread that
evaluated to false as variable ret is zero if trigger_work(), which is
called previously for all returned events, returns successfully.

Signed-off-by: Philipp Finke <philipp_finke@gmx.de>
2025-09-12 08:20:18 +01:00
Cristian Bulacu
cbd599fecd net: sockets: Return mapped address from sock_get_pkt_src_addr() function
When an IPv4 packet is received on a dual-stack socket, return
the mapped v4 to v6 address as source address.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-09-11 18:09:09 +01:00
Cristian Bulacu
48897a9090 net: context: Fix issues in context_sendto() function
Fixed issue when `sendmsg()` was in use and `CONFIG_NET_IPV6`
and `CONFIG_NET_IPV4_MAPPING_TO_IPV6` were in use, as `dst_addr`
argument of `context_sendto()` was passed NULL,
but also used to determine `sa_family`.
Use msghdr, if available, to determine if v4 to v6 mapping is
present.
Also set `dst_addr` to unmapped value  when v4 to v6 mapping is
used.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-09-11 18:09:09 +01:00
Cristian Bulacu
3072c53a84 net: context: Add support to set hoplimit when v4 to v6 mapping is used
If v4 to v6 mapping is used, cmsg_level and cmsg_type should
be compared with IPv6 values even if pkt family if AF_INET.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-09-11 18:09:09 +01:00
Jukka Rissanen
80953bb8e0 net: tcp: Print TCP connection info consistently
Print TCP connection pointer value for debug prints
consistently so that it is easier to find debug prints that
are related to a certain TCP connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-09-11 09:54:27 +02:00
Jeppe Odgaard
3813b3cdda net: config: sntp: improve logging
Print return code on error and remove logging in `sntp_resync_handler`
since it calls `net_init_clock_via_sntp` which already does logging.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-09-10 16:39:34 +02:00
Cla Mattia Galliard
8e6521a14d net: socket: Specify the packet socket-type, when inputting
Specify the socket type, when inputting a packet into a packet-socket.

Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
2025-09-10 13:01:56 +02:00
Cla Mattia Galliard
b9968e9d1f net: core: Decide about l2-processing based on l2_processed-flag
Use the l2_processed-flag to decide whether a network packet needs to be
processed by an L2-handler. This could be used in the future to requeue
packets for later processing by a different traffic class queue.

Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
2025-09-10 13:01:56 +02:00
Cla Mattia Galliard
0327bb1ae0 net: pkt: Store is_loopback info in packet meta-data
Store the flag in the packet meta-data so that processing may be deferred
if necessary.

Signed-off-by: Cla Mattia Galliard <clamattia@gmail.com>
2025-09-10 13:01:56 +02:00
Muhammad Waleed Badar
df6c1831de net: wifi: Add default for max managed interfaces
This default value 2 of WIFI_NM_MAX_MANAGED_INTERFACES
ensures WiFi network manager can properly handle both
access point and station interfaces.

Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
2025-09-09 22:00:08 +02:00
Jeppe Odgaard
c6f31346d2 net: config: sntp: add resync interval range
RFC4330 section 10 states:

A client MUST NOT under any conditions use a poll interval less then 15
seconds.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-09-08 14:41:25 +02:00
Yangbo Lu
263911d79e net: net_if: use simple vlanX for vlan interface name
Used simple vlanX for vlan interface name. What interface the
vlan interface was attached to could be checked by "net iface"
or "net vlan".

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-04 11:34:15 +02:00
Yangbo Lu
0948812f70 net: vlan: drop current vlan interface naming
There were two problems about vlan interface naming currently.

1. When there were more than 1 vlan interfaces. It's not able to
   initialze name for all of them to same name VLAN-<free>.
2. When enabled vlan with tag, the name VLAN-xxx was used.
   However we may need to support multiple physical interfaces
   in the future. So, it's not able to use same name VLAN-xxx
   either for same tag on different physical interfaces.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-04 11:34:15 +02:00
Yangbo Lu
3fc03623ad net: shell: vlan: fix tag/attached info showing
There was call trace to execute "net vlan" if vlan interface
hadn't been enabled. Fixed it.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-09-04 11:34:15 +02:00
Benjamin Cabé
0132ea07fb doc: fix spelling errors tree-wide
fix some spelling errors in code comments and Kconfig helps

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-09-03 17:04:13 +02:00
Benjamin Cabé
637f1cd411 net: shell: dns: use int type for %.*s format specifier
The `%.*s` format specifier expects an int so cast the size_t parameter
to int.

Fixes an issue spotted in CI for:

    west twister -p native_sim/native/64 -s sample.net.dns_resolve.mdns

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-09-03 14:53:17 +03:00
Charles Hardin
633246a3ea net: dns: add query support for additional types CNAME, SRV, and TXT
These types are useful for IoT deployments and should be available
thru the resolver interface to get the data. The SRV is especially
useful to find services on the local network when not using a dns-sd
deployment and just something like Avanhi or Bonjour.

Signed-off-by: Charles Hardin <ckhardin@gmail.com>
2025-09-02 18:42:35 +02:00
Charles Hardin
b60ae6fb1a net: dns: only add periods between labels and not on the first label
When resolving SRV records - the label might not be compressed so
the first entry into the net buf is the start of the name and a
period could end up at the start - ie. ".example.local" so only add
a period when the buffer is not empty.

Signed-off-by: Charles Hardin <ckhardin@gmail.com>
2025-09-02 18:42:35 +02:00
Charles Hardin
ece1ed567b net: dns: adjust the enum for response type to be positive on success
The enum will auto increment, so in debug the IP and DATA records are
negative numbers which initially made this look like an error, so just
push the expected good values to be positive numbers in case of a print
or something else would imply these are ok.

Signed-off-by: Charles Hardin <ckhardin@gmail.com>
2025-09-02 18:42:35 +02:00
Jonas Spinner
da75828459 net: gptp: fix clock accuracy description
Previously, the Kconfig option `NET_GPTP_CLOCK_ACCURACY_2_5MS` had a
incorrect description "1.5ms".

Signed-off-by: Jonas Spinner <jonas.spinner@burkert.com>
2025-08-25 17:49:39 +02:00
Robert Lubos
faa507ef6c net: Fix misc Kconfig style issues in networking area
Fix misc Kconfig style issues in networking area.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-08-21 20:12:48 +02:00
Charles Hardin
0fe091bc46 net: dns: fix the bounds conditions on the failures and error returns
The loop condition is not the count of the actual tries since the
continue or breaks can occur on the loop and thus a failure count
can falsely match a loop count even when a query is outstanding.

This can be seen when a dual stack resolve is used for IPv4 and IPv6
that has two fds to be used and the interface has only gotten an
IPv6 address. The failures on the IPv4 will indicate a 1 and the break
on the tried attempt on the IPv6 will break the loop on a 1.

Signed-off-by: Charles Hardin <ckhardin@gmail.com>
2025-08-21 01:43:59 +02:00
Seppo Takalo
6cdae490e3 net: lwm2m: Suppress many LOG_ERR() that are not fatal
Suppress many LOG_ERR() messages from LwM2M registry
that are not necessary runtime errors.

Libraries and applications should be able to do following
without causing LOG_ERR to be produced:

* Checking existence of object, resource or resource instance
  using lwm2m_engine_get_res(), lwm2m_engine_get_res_inst()
  or path_to_objs(). These are only exposed in internal header.
* Delete object instance or resource instance without checking
  if it exits.

As there is no public API to check existence of some path,
application is much easier to write in a way that it directly
calls just lwm2m_get...(), lwm2m_set...(), lwm2m_delete...()
and trust the return code of -ENOENT.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2025-08-19 19:13:59 +02:00
Kapil Bhatt
f48a66121a net: zperf: Improve UDP multicast upload
UDP multicast uploads did not produce zperf-compatible server stats,
so the client waited for and tried to decode a non-existent reply,
causing “Unexpected response flags” and misleading
“LAST PACKET NOT RECEIVED!!!” output.

This change treats multicast as client-only: after sending
the negative-id FIN it does not wait for or decode server stats,
Instead transmits the FIN a few times to help receivers detect test end.
The shell prints a clear “Statistics (client only)” summary for multicast
and suppresses the error when client stats are valid.

Unicast behavior is unchanged.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2025-08-19 14:16:05 +02:00
Sean Kyer
a28925af31 net: ocpp: Fix cast warning
Fix warnings generated from casting pointers
of different sizes and string literals in ocpp

Signed-off-by: Sean Kyer <Sean.Kyer@analog.com>
2025-08-16 10:20:26 +02:00
Cristian Bulacu
4f644d8441 net: socket: Fix recvmsg() pktinfo support.
Fix an issue where IPV6_RECVPKTINFO was used instead of IPV6_PKTINFO
when insert_pktinfo was called.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-08-15 10:10:59 +03:00
Cristian Bulacu
6c826efd5a net: context: Add support for setting hop limit from ancillary data
Add support to parse over msghdr and set pkt hop limit, if needed, when
sendmsg() is used.

Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
2025-08-15 10:10:59 +03:00