Commit graph

6489 commits

Author SHA1 Message Date
Vijayakannan Ayyathurai
32253c6159 net: ip: resolve NET_IPV4_FRAGMENT build warning
warning: format '%d' expects argument of type 'int', but argument 3 has
type 'size_t' {aka 'long unsigned int'} [-Wformat=]

Change the printf modifier to %zd for size_t variable will resolve the
warning.

Signed-off-by: Vijayakannan Ayyathurai <vijayakannan.ayyathurai@intel.com>
2025-05-01 18:17:46 +02:00
Pieter De Gendt
857abda15e net: lib: coap: coap_server: Change error print to debug
The POLLHUP is expected with, for example DTLS UDP sockets.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-05-01 08:53:32 -04:00
Pieter De Gendt
470b582e04 net: lib: coap: Add CoAP secure support
Add optional TLS secure tag lists for CoAP services to enable DTLS
sockets.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-05-01 08:53:32 -04:00
Robert Lubos
29a2b5c8c6 net: sockets: packet: Fix default binding order
Default binding should take place before we actually make use of the
local address when registering packet socket "connection".
Also, instead of hard coding the protocol for default binding to
ETH_P_ALL, use the protocol that the socket was created with.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-04-30 16:26:16 +02:00
Robert Lubos
c8798d017f net: sockets: packet: Make it possible to receive packets when unbound
In order to be able to receive packets on unbound packet sockets (which
should collect packet from all interfaces in such case), it's needed to
register receive callback at the socket layer as soon as the socket is
created.

In additional to that, the default binding for packet sockets need to be
revisited. Packet socket should not be bound to the default interface,
as this way the socket would only be receiving packets from that
particular interface. Instead, leave the interface unspecified in such
case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-04-30 16:26:16 +02:00
Robert Lubos
cd0b195b00 net: connection: Make it possible to update local address
Allow to update the local address on a registered connection when
rebinding.

This is needed for packet sockets, as by default packet socket
will be bound to "any" interface (interface index 0), and interface
index is part of the local address registered for packet socket.
In order to be able to explicitly bind to a specific interface later, it
needs to be possible to update the local address registered for the
connection, as we need to update the interface index, which is used
by net_conn_packet_input() for packet filtering.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-04-30 16:26:16 +02:00
Shrek Wang
adaec1c7ed net: tcp: start keepalive timer at the right time
keep_alive_timer_restart() only works in ESTABLISHED state. In
tcp_in() SYN_SENT and SYN_RECEIVED state, it won't work by calling
this function. So remove the call in that 2 states while adding it
in the bottom after changing the conn->state to ESTABLISHED.

Signed-off-by: Shrek Wang <inet_eman@outlook.com>
2025-04-30 07:52:14 +02:00
Jordan Yates
7087eb49ef net: zperf: increase default max packet size
Slightly increase the default maximum size for zperf uploads to support
1kB of data payload together with the 40 bytes UDP client header.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-29 20:08:32 -04:00
Jordan Yates
d6cb7f4eea net: zperf: custom data upload support
Add support for uploading custom data, instead of a static packet of
'z'. This can be used for more accurate profiling of uplink throughput
for a given application. For example, reading data from flash, or
application level encryption.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-29 20:08:32 -04:00
Jordan Yates
bbaf4a7947 net: zperf: specify Unix time offset
The timestamp in the UDP header is expected to be a Unix timestamp, not
an application uptime. Add the option to specify the Unix time at
function entry so that the reported timestamps are accurate.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-29 20:08:32 -04:00
Jordan Yates
2f091ad800 net: zperf: fix minimum UDP packet size
The minimum packet size is the combination of the datagram and client
headers, not just the datagram header.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-29 20:08:32 -04:00
Adrian Friedli
89f8f5bb07 net: lib: coap: fix division by zero
Prevent the modulo operation causing a division by zero error by falling
back to the minimal ACK timeout value if the random factor is 1.0. Also
fall back to the same value if the random factor is erroneously smaller
than 1.0. Additionally make the upper bound of the random range
reachable.

Signed-off-by: Adrian Friedli <adrian.friedli@husqvarnagroup.com>
2025-04-29 19:04:16 +02:00
Jukka Rissanen
702776bd1f net: mgmt: Remove the _ from symbols
The _ is a reserved character in front of the symbols so remove
it from network management event macros. The remaining string
without the _ will identify the network API anyway so having
underscore there is not needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-04-29 13:01:01 +02:00
Fin Maaß
3a195a08da drivers: net: ethernet: change ETHERNET_LINK_*BASE_T
change ETHERNET_LINK_*BASE_T to ETHERNET_LINK_*BASE.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-04-28 09:22:09 +01:00
Jukka Rissanen
aef83fce14 net: if: Allow selecting deprecated IPv6 address as src addr
This adjust the IPv6 source address selection so that it is possible
to select deprecated IPv6 address if no better preferred address is found.

From RFC 6724 chapter 5:

   Rule 3: Avoid deprecated addresses.
   If one of the two source addresses is "preferred" and one of them is
   "deprecated" (in the RFC 4862 sense), then prefer the one that is
   "preferred".

   Rule 8: Use longest matching prefix.
   If CommonPrefixLen(SA, D) > CommonPrefixLen(SB, D), then prefer SA.
   Similarly, if CommonPrefixLen(SB, D) > CommonPrefixLen(SA, D), then
   prefer SB.

So the fix allows deprecated address to be selected if it is a better
match than the preferred one. The reasoning here is that an address with
a longer matching prefix is generally considered topologically closer to
the destination. Using such a source address can lead to more efficient
routing, as it's more likely that the source and destination are within
the same network segment or a closely related one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-04-25 19:00:59 +02:00
Emil Lindqvist
500c67fa18 wifi: fix -Wignored-qualifiers warning
Including wifi.h with -Wignored-qualifiers warning enabled gives
a warning. Fix this warning

Signed-off-by: Emil Lindqvist <emil@lindq.gr>
2025-04-25 18:58:25 +02:00
Ibe Van de Veire
c6d98acbbf net: lib: sockets: Increase socketpair mem pool size
Increased the heap mempool size for the socketpairs. This way there will
be enough memory available to allocate 2 * struct spair.

Signed-off-by: Ibe Van de Veire <ibe.vandeveire@basalte.be>
2025-04-25 15:57:25 +02:00
Jukka Rissanen
feb0265e43 net: if: Stop IPv6 router solicitation if interface goes down
Make sure RS process is stopped if network interface goes down
as there is no point doing it any more.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-04-25 14:06:00 +02:00
Jukka Rissanen
c73f9d834a net: if: Make sure IPv6 RS timer is not added twice to list
It might happen that if the network interface is going up/down
fast enough, the RS timer could get inserted to the active RS
timer list twice. This would then cause a forever loop in
rs_timeout() when traversing the active list.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-04-25 14:06:00 +02:00
Fin Maaß
051d257b3c net: config: sntp: don't use fallback, when Kconfig is not set
don't use fallback address, when Kconfig server address
is not set.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-04-25 14:05:35 +02:00
Fin Maaß
5819e1722b net: config: sntp: add assert, when address is not set.
when the sntp address is not set and geting it via
dhcp is not activated do a build assert.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-04-25 14:05:35 +02:00
Fin Maaß
71aa1b1bec net: config: sntp: add option for failure try interval
add option for a different resync interval, that is
applied when the sntp request fails.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-04-25 14:05:35 +02:00
Jukka Rissanen
3e09a40de5 net: zperf: Add -w option to delay upload jobs
Use -w option to delay the startup of the upload job.
Then when ready, do "zperf jobs start" to launch all upload
sessions at the same time.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-04-25 10:22:33 +01:00
Jukka Rissanen
563f05eb8b net: zperf: Add concurrency when doing upload tests
If user has enabled CONFIG_ZPERF_SESSION_PER_THREAD, then if
user gives -a (async) option to upload command, then multiple
uploads can be run simultaneously. Each upload will be run
in a dedicated work queue. The work queue thread priority can
be set by -t option.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-04-25 10:22:33 +01:00
Jordan Yates
1c2fc02cf2 net: ip: net_if: consistent interface id logging
Update logging to consistently refer to interfaces by their ID, instead
of a mix of IDs and pointers.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-24 22:58:51 +02:00
Jordan Yates
3772c719e0 net: l2: ethernet: ethernet_ll_prepare_on_ipv4 handling
Shift the error handling for `ethernet_ll_prepare_on_ipv4` out into
`ethernet_send`, since that is the function that needs to handle the
various result types of the ARP process.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-24 22:58:51 +02:00
Jordan Yates
029f542bb4 net: l2: ethernet: arp: unref pkt if queue add fails
Make it clearer that the `net_buf_ref` is for `k_queue_unique_append`,
and reverse the reference if the queue add fails.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-24 22:58:51 +02:00
Jordan Yates
d283130b68 net: l2: ethernet: arp: explicit error codes
Update `net_arp_prepare` to return a return code instead of a pointer,
so that the various results of the function can be differentiated.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-24 22:58:51 +02:00
Jordan Yates
4e0386a445 net: ip: net_if: warning message on send failure
Print a warning if sending a packet on the L2 interface fails. Currently
this is completely silent unless `NET_DBG` is enabled and the `context`
parameter is provided.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-24 22:58:51 +02:00
Seppo Takalo
78ee0f0c23 net: lwm2m: Do not enforce canonical CBOR decoding
Our decoder can handle decoding of non-deterministic CBOR just fine.
There is no need to block valid CBOR if the server does not produce
length-first deterministic CBOR.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2025-04-24 22:58:24 +02:00
Jukka Rissanen
0e5df7a67b net: vlan: Avoid printf modifier issue with size_t variable
Change the printf modifier to %zd for size_t variable printout
to avoid compiler warning.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-04-24 20:27:58 +02:00
Fengming Ye
23494b7b68 net: sockets: kconfig: change hostap default socket pair add heap size
Reduce default socket pair add heap size in hostap case.
Reduce 1 socket pair in wpa_supplicant case.
Reduce 2 socket pairs in wpa_supplicant and hostapd coex case.

Signed-off-by: Fengming Ye <frank.ye@nxp.com>
2025-04-24 10:38:03 +02:00
Yangbo Lu
f0b1cb578f net: dsa: introduce new DSA framework
The new DSA framework purpose and changes are as below.

- Aligned to Linux DSA framework which has been already mature framework
  for many years, For now in zephyr, the DSA components were splited
  as: switch, port, master(not need driver file for now), slave, and tag.
  Seperated drivers were used for maintaining and developing new
  features.

- The unified dts bindings (aligned to linux) were supported. The port
  driver would parse DTS to decide the port type (master port, slave
  port, or cpu port) to set up the switch. All the ports registered as
  standard ethernet devices. (dsa port and dsa switch tree was not
  supported.)

- How to add DSA device driver based on the framework? All the device
  driver needing to do is providing dsa_spi implementation and private
  data, and calling below initialization.

    DSA_INIT_INSTANCE(n, _dapi, data)

- For switch tag case, recv/xmit helpers in dsa_api could be used for
  taging/untagging. No modified ethernet drivers.
  For no-tag type case, ethernet driver of master port should support
  packet injection/extraction for slave ports leaving NULL recv/xmit.

The dsa_nxp_imx_netc.c driver will be the first example of the new DSA
framework.

The future work for DSA will be supporting bridge for ports. We may align
Linux to give users two options to use DSA device:

- Standalone mode: the switch ports work as regular ethernet ports.

- Bridge mode: switch mode with virtual bridge device which could be
  assigned IP address.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-04-24 01:26:46 +02:00
Yangbo Lu
b22db75cec include: ethernet: rename dsa master/slave to conduit/user
Renamed dsa master/slave to conduit/user for capabilities.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-04-24 01:26:46 +02:00
Yangbo Lu
018a718e12 net: dsa: make current DSA core driver obsolete
Current DSA TX/RX way was hard-coded in ethernet devices driver
with ETH_DSA_SUPPORT and NET_DSA.
This patch is to make such way obsolete, as we actually will support
a better DSA framework to handle this in NET/DSA core driver.
To make legacy devices not affected, below options are used instead.

- ETH_DSA_SUPPORT_DEPRECATED
- NET_DSA_DEPRECATED

Once the legacy devices are converted to new DSA framework, this code
could be removed.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-04-24 01:26:46 +02:00
Arkadiusz Balys
66e78e05d3 openthread: Separate OpenThread Kconfigs from L2 layer
Moved OpenThread-related Kconfigs from L2 layer to
modules/openthread. All of those configs were not strictly related
to the L2 layer, so they fits better to OpenThread module.
This operation allows using OpenThread Kconfigs even if L2 layer is
disabled.

Enabling NET_L2_OPENTHREAD also configures those configs by
selecting the OPENTHREAD kconfig, so there is no change regarding
backwards compatibility. The only change is that the Kconfigs
related to Thread were moved to the modules space, so their
location in the menuconfig also changed.

Once it is done, a choice for setting different L2 implementations
seems to be redundant.

Signed-off-by: Arkadiusz Balys <arkadiusz.balys@nordicsemi.no>
2025-04-23 17:54:58 +02:00
Jordan Yates
00c68722d9 net: lib: zperf: TCP uploader: populate total_len
Populate the `total_len` field of the output results.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-23 11:48:42 +02:00
Jordan Yates
6ce51997e7 net: lib: zperf: conditional UDP/TCP compilation
Only compile in the UDP/TCP variants of the zperf functions if the
underlying support is present.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-23 11:48:42 +02:00
Jordan Yates
82d767585d net: lib: zperf: optional server support
Make the zperf server support optional, if only upload throughput
testing is required. This reduces the resources required to operate.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-23 11:48:42 +02:00
Jordan Yates
05d577993f net: lib: zperf: update descriptions
`NET_ZPERF` enables the core zperf utility library, not a shell module.
Add more specifics about what the utility can communicate with.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-23 11:48:42 +02:00
Robert Lubos
379e71def3 net: connection: Cleanup packet input processing
Part of the socket matching criteria for AF_PACKET family took place
inside conn_raw_socket() function, and some of it was redundant with
what already was checked in net_conn_packet_input(). Moreover, if the
packet cloning for packet socket failed for whatever reason, the packet
was reported as NET_DROP, which was confusing.
Finally, conn_raw_socket() updated network stats, which didn't really
work as net stats are only collected for UDP/TCP protocols and not for
L2 level protocols.

Therefore, cleanup the processing by:
  * Moving all socket matching criteria into net_conn_packet_input()
    for clarity,
  * Drop unneeded net stats functions,
  * Clarify NET_DROP strategy for packet socket input.
    net_conn_packet_input() should only be responsible for delivering
    packets to respective packet sockets, it should not decide whether
    to drop the packet or not - it's L2/L3 processing code
    responsibility. Therefore, assume this function forwards packet for
    further processing by default, and only allow small optimization to
    return NET_OK if the packet socket was really the only endpoint in
    the system.
  * And finally, since now conn_raw_socket() responsibility was to clone
    the packet for the respective socket, and was almost identical to a
    corresponding function for raw IP sockets, unify the two functions.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-04-23 11:48:33 +02:00
Robert Lubos
32f3ce396f net: connection: Split net_conn_input()
The current implementation of net_conn_input() can accept different
packet types, with completely different processing code, resulting in a
function which is pretty bloated, sliced with conditionally enabled code
and hard to understand and therefore maintain.

This commit splits that function into smaller ones, specialized for
different packet types (and entry levels). The following functions have
been extracted from the original one:
  - net_conn_packet_input() for early packet processing (covering
    AF_PACKET family sockets)
  - net_conn_raw_ip_input() for raw IP packets processing (covering
    AF_INET(6)/SOCK_RAW sockets)
  - net_conn_can_input() for CAN packets processing (covering AF_CAN
    family sockets)

The net_conn_input() function stripped from above cases now only takes
care of packets that have been processed by respective L4 and are
intended for regular TCP/UDP sockets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-04-23 11:48:33 +02:00
Robert Lubos
edba291799 net: core: Pass the actual LL proto for DGRAM packet sockets
After L2 processing, the LL protocol type is already known and should be
set accordingly on the packet. Therefore it can be passed to the
net_packet_socket_input() function to allow proper socket filtering
based on protocol.

Additionally, as LL protocol type is 16 bit value, fix the proto
parameter type in net_packet_socket_input().

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-04-23 11:48:33 +02:00
Jordan Yates
4582c64816 net: lib: zperf: warning on bad response flags
Output a warning if the server response does not have the expected
header flag set.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-22 09:59:57 +02:00
Jordan Yates
5c8b7cdd89 net: lib: zperf: fix internal UDP header definition
Fix the zperf UDP datagram header definition, as iperf introduced a
backwards incompatible format change in version 2.0.10 (August 2017).
```
struct UDP_datagram {
// used to reference the 4 byte ID number we place in UDP datagrams
// Support 64 bit seqno on machines that support them
    uint32_t id;
    uint32_t tv_sec;
    uint32_t tv_usec;
    uint32_t id2;
};
```

Update the header to the new format, with a Kconfig option to fall back
to the previous header definition.

The response decoding was testd with a nRF7002 client and
`iperf-2.2.1-win64.exe` server, with the output statistics struct now
containing the same information as reported on the PC server.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-22 09:59:57 +02:00
Robert Lubos
6c0aef4da0 net: sockets: packet: Ensure correct interface is used
Make sure that when sendto is being used without the socket being bound
before, a correct interface is used for transmission. As
zpacket_sendto_ctx() calls net_context_recv() to register receive
callback before sending, a default binding was used by the context
layer, which would bind the socket to the default interface. This could
lead to unexpected results, i.e. packet being sent on a default
interface, even though a different one was specified.

Make also sure that there is no ambiguity in the interface selection -
the application should be explicitly clear what interface it wants to
use when it comes to packet sockets. It's better to return an error if
no valid interface was specified.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-04-17 17:23:23 +02:00
Robert Lubos
332843be33 net: sockets: packet: Allow proto 0 for RAW sockets
According to AF_PACKET man pages protocol number 0 is allowed, however
in such case the socket is only capable of transmitting packets then:

  "If protocol is set to zero, no packets are received."

Therefore, allow to create sockets with such protocol, and at the
connection.c level filter out such sockets from data reception.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-04-17 17:23:23 +02:00
Chaitanya Tata
eb1a13eda7 samples: net: wifi: Add two variants of certs
RSA3K based certs are not supported on all platforms, so, keep both
variants, rsa2k (the older certs but with longer expiry 9999 days) and
rsa3k (latest ones) and we can have more variants in this folders.

Also, add a cmake variable to override the path with default as rsa3k.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-04-17 17:22:58 +02:00
Chaitanya Tata
9b68218e9a net: l2: wifi: Make build time certs as optional
Certificates usage depends on STA/AP mode, but we don't have that
information at a build time, so, make all certs as optional and if a
file isn't found then generate an empty header so that corresponding C
code will be built.

Any missing mandatory certificates will be validated before connection
and connection is failed.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-04-17 17:22:58 +02:00
Chaitanya Tata
c2f4e67c8a net: lib: tls_credentials_shell: Fix crash during delete
Deletion of credential should use the pointer from the reference slot
not the temporary buffer, this causes a crash (unknown error).

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-04-17 17:22:58 +02:00