Commit graph

5585 commits

Author SHA1 Message Date
Chris Friedt 12cc7bbd8a net: sockets: use z_finalize_typed_fd() to identify as sockets
Fill-in the mode field of the fd_entry so that the
implementation can be made aware that the specific file
descriptors created are sockets.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-15 07:47:12 -04:00
Eric Ackermann 4f72df466c net: Support partial checksum offloading
The Xilinx AXI Ethernet subsystem is capable of RX/Tx checksum
offloading. While it supports computing IP and UDP/TCP checksums, it
does not support computing ICMP checksums and only computes IP checksums
for ICMP messages. Thus, this patch adds an additional configuration for
ethernet drivers that indicates for which protocols checksum offloading
is (to be) supported. This flag is then considered by the IP subsystem
in determining when flags need to be computed in software.

Signed-off-by: Eric Ackermann <eric.ackermann@cispa.de>
2024-06-14 17:10:43 -04:00
Seppo Takalo 35cc774aa5 net: lwm2m: Retry DTLS handshake before dropping to bootstrap
Allow DTLS handshake to be retried before the engine
drops into bootstrap. Otherwise any termporary failure,
for example DNS failure might drop us into bootstrap
without retrying.

Now all the retry logic should be in sm_do_network_error().
sm_do_registration() should only fall back to bootstrap
if there is configuration error.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-14 15:34:39 +02:00
Robert Lubos 0d3a021379 net: dhcpv4: Reset Renewal/Rebinding times on ACK
In case no Renewal/Rebinding times have been provided the server via
DHCP options, we should reset their values on ACK, so that the client
can recalculate the defaults. This is important, as the lease time may
change, so we should recalculate default T1/T2 timeout based on the new
lease time value.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-13 17:50:52 +02:00
Robert Lubos 4d4391bf1c net: dhcpv4: Reimplement RENEW/REBIND logic according to RFC2131
DHCP Request retransmission in RENEW and REBIND states was not
compliant with RFC2131.

The retransmission interval should not be calculated as in REQUESTING
state in such case, but rather calculated based on the remaining T2
or lease time (depending on current state).

RFC doesn't also mention any retransmission count limit for those
states. The client should retransmit the REQUEST until T2 or lease
expiry time are reached.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-13 17:50:52 +02:00
Konrad Derda cb3c087350 net: ipv6: mcast_routing: hop limit handling
While forwarding a multicast packet decrement hop limit in a common net
buffer. Also, packets with hop limit equal to 0 should not be forwarded.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-06-13 05:44:30 -04:00
Adam Wojasinski 08689e1a20 net: ptp: Network interface status check in PTP thread
Adding network interface status monitor function. Depending
on the interface operation state and change of the state
events are generated and handled by the function.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 28111ba254 net: ptp: Implement PTP thread
This commit adds implementation of the PTP thread that will
poll sockets descriptors and PTP Port's timeres for timeouts,
generate events and handle them and trigger STATE_DECISION_EVENT
handling when needed.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski db07aa2c00 net: ptp: Add handler for STATE_DECISION_EVENT
The STATE_DECISION_EVENT in PTP is a pivotal mechanism that
facilitates dynamic state management within the protocol,
allowing devices to adapt their operational states based on the BTCA's
recommendations and the health of the network.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski edfe4cd8cc net: ptp: Add event generation and event handler for PTP Port
Introduction of PTP stack's core functions responsible for
event generation and handling of these events. Events are generated
base on timeouts and/or PTP messages received via BSD sockets
assigned to a specific PTP Port. These function will be used
in PTP thread.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski f22f36dd90 net: ptp: Implement PTP Port enabling and disabling functions
The commit adds functions that enable and disable PTP Port.
This is going to be used by event handling routine.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski e14e878084 net: ptp: Add timers processing for PTP Port
Timers are used to trigger message transmission and detect
inactivity of other PTP Clocks what should result in an action
of the PTP Port.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 73eaab29a0 net: ptp: Add functions for messages transmission
This commit introduces routines for PTP message transmission.
It includes transmission of three types of messages (Announce,
Sync, Delay_Req) that should be send periodically depending
on the PTP Port's state.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski cb35cc919a net: ptp: Add management message processing
Introduction of routines processing received PTP Management messages.
The processing is split into clock-oriented and port-oriented parts.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski fe0cc7dd26 net: ptp: Implement Best TimeTransmitter Clock algorithm for PTP stack
Add handler for STATE_DECISION_EVENT it consists of following routines:
- state decision algorithm
- best timeTransmitter clock algorithm
- data sets comparison algorithm

Based on IEEE 1588-2019 section 9.3.3

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 577e58cb17 net: ptp: Implement PTP message processing for ports
This commit adds routines for handling incoming messages
needed for correct operation of the PTP stack in end to end
mode with multicast operation mode.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 5c4be2be8c net: ptp: Introduce routines for PTP Hardware Clock adjustment
Initial implementation of the clock adjustment and delay calculation.
Timestamp values used for calculations will be obtained from
proper PTP messages (Sync, Follow_Up, Delay_Req, and Delay_Resp)

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 9aabe2e477 net: ptp: Add foreign timeTransmitter records
Foreign timeTransmitters are other PTP Clocks in a domain. They announce
their parameters via announce messages. PTP Ports should record
these foreign timeTransmitters.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 0575a500ce net: ptp: Add PTP Port ID comparison function
Based on Port ID decision about message processing can be made.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 3d7dd0d6fa net: ptp: Add sockets to PTP stack
This commit introduces module responsible for sending and receiving
messages. It is based on BSD Sockets API.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 8016fa1de1 net: ptp: Extend TLV with Management TLVs
This commit adds handling of Management TLVs

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 806ba0dcd3 net: ptp: Add TLV extension to PTP
Add allocation of container used for TLVs and dummy functions for
preparing correct byte order of data. TLV stands for Type, Length,
Value, and it is extension of PTP messages that's used to transmit
extra information. This data is attached at the end of PTP message.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 8f00c5f4de net: ptp: Add byte order manipulation for PTP messages
Add functions preparing messages to network byte order before sending
and changing to host byte order after reception and before processing
by PTP stack.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski e17cf5868d net: ptp: Add PTP message allocation and management
Add dynamic memory allocation for PTP messages. Memory allocation
is done with Zephyr's memory slab. It's size can be configured
with `PTP_MSG_POLL_SIZE` Kconfig symbol.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 7e45be1bf2 net: ptp: Add definition of PTP messages types
Introduces definition of structures for all types of PTP messages
defined in the IEEE 1588-2019 standard.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski af09e4abfb net: ptp: Add Kconfig symbols and preprocessor guards for some states
Based on IEEE 1588-2019 some of PTP Port states might not be used
if the option of 17.7 is implemented. This patch prepares state
machine implementation for such scenario.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 2e7dbf1091 net: ptp: Add TIME_RECEIVER_ONLY feature
Implement possibility to configure PTP stack in TIME_RECEIVER_ONLY mode.
This restrics stack behaviour and doesn't allow for any PTP Port
of the PTP Clock become a TimeTransmitter Clock.

The change includes:
- Kconfig option
- Additional field in `struct ptp_port` structure
- New state machine function for a timeReceiver-only PTP Port.
- Extra steps in PTP Clock and PTP Port initialization.

New finite state machine is based on the figure 31
in section 9.2.5 of the IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 74a25772c5 net: ptp: Add PTP Clock and PTP Port initialization
This commit introduces PTP Clock and PTP Port structures
and API for initializing PTP Clock and PTP Ports. Configuration
options has been added as Kconfig symbols to configure parameters
of the Clock and Ports at compile time.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 70e3183c40 net: ptp: Add definitions for PTP datasets
Datasets defined in the header file are going to be used
in PTP Clock's structure and PTP Port's structure. They
gather data into structures defined in IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 424c3706d1 net: ptp: Add finite state machine implementation for PTP stack
The patch brings implementationof a state machine for full
PTP implementation. It returns new PTP Port's state based
on event that occured and previous state.

Based on the figure 30 in section 9.2.5 of the IEEE 1588-2019.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 6a40371790 net: ptp: Add derived data type header
The header's file content is based on 5.3 section of
the IEEE 1588-2019 standard describing Precise Time Protocol (PTP)
used to synchronize devices in the network.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 58a611d814 net: ptp: Initial PTP library implementation
This is an initial commit that introduces PTP library in the Zephyr.
It adds basic Kconfig symbols for enabling library, CMakeLists.txt
for compiling it, public header file, and initial PTP thread definition
and library initialization. Implementation of the functional PTP stack
will be introduced in following commits.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski ee06da545d net: socket: Add SO_TIMESTAMPING data to messages received via socket
Add returning timestamp of received packet in ancillary data buffer
in `msghdr` structure. This commit enables getting timestamp of
the received packet by calling `recvmsg()` function. The function
returns in the `msg_control` field timestamp if following criteria
are met:
- `CONFIG_NET_CONTEXT_TIMESTAMPING` is set
- `SO_TIMESTAMPING` socket option has `SOF_TIMESTAMPING_RX_HARDWARE`
  option enabled for that socket
- driver used by sockets supports packet timestamping

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski cf89e1ca29 net: socket: Add support for SO_TIMESTAMPING socket level option
This is the last commit of the set of patches that introduces
`SO_TIMESTAMPING` socket level optino in Zephyr. The patch
adds `SOF_TIMESTAMPING_RX_HARDWARE` and `SOF_TIMESTAMPING_TX_HARDWARE`
bitmasks. It can be extedned in the future to cover more timestamping
features. Currently the feature can be used with ptp_clock driver.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 7ef4f470e2 net: context: Add support for timestamping in network context
This is next commit from the set of patches that brings to the
Zephyr, SO_TIMESTAMPING socket level option. It stores timestamping
option bitmask that can be transfered to the net_pkt.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski 56338de16a net: pkt: Add flags to indicate the pkt should be timestamped
This is the first commit from the set of patches that brings to the
Zephyr, SO_TIMESTAMPING socket level option. This enables to pass to
the network driver information whether given network packet should
be timestamped or not.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Adam Wojasinski c87c36d313 net: if: Increment the packet ref count when adding to timestamp queue
Added incrementation of the packet reference count when puting
the packet on the queue used in tx timestamping thread. This fixes
an issue when user wants to access the packet data in the timestamp
callback context. Before the fix was introduced if sockets were used
packet has been unreferenced before execution reached timestamp callback
context.

Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
2024-06-13 05:40:41 -04:00
Valerio Setti 30c9f5eaa5 net: add proper PSA_WANT kconfigs for TLS sockets and RSA key exchanges
Add proper PSA_WANT kconfigs for TLS sockets and RSA key exchanges
when CONFIG_PSA_CRYPTO_CLIENT is set.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-06-13 09:22:20 +02:00
Seppo Takalo 441d970417 net: lwm2m: Bypass send_queue when sending empty Ack
In case we want to immediately send empty Ack to server,
we should bypass all send queues.

This is required when we try to send Ack from callbacks
that happen from socket-loop context. On those cases
the Ack would have not been send because the callback
might be blocking the socket-loop while processing
a request (like write callbacks).

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-12 12:50:46 -04:00
frei tycho 382670690c net: change controlling expressions in while to Boolean
Use `do { ... } while (false)` instead of `do { ... } while (0)`.

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-11 20:03:16 +03:00
Jukka Rissanen 7bb4013d8e net: tracing: Add socket tracing support
If network socket tracing is enabled, then the system will track
various socket API calls for usage.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-10 15:03:20 -05:00
Daniel Nejezchleb d6ed91795d net: tcp: Fix context leak during connect
Replaced tcp_out() with tcp_out_ext() when sending
SYN during tcp connect, so we can intercept error value,
beacuse in such case the packet would not be sent at all
and the stack would not trigger any mechanism to flush
this context so it ends up leaking. These scenarios can
arise when the underlaying interface is not properly
configured or is disconnected. The conn is marked to be
closed and is closed before exiting tcp_in().
Since we can now identify this case we can also exit
early in the net_tcp_connect() function and not wait
for any timeout.

Signed-off-by: Daniel Nejezchleb <dnejezchleb@hwg.cz>
2024-06-10 16:56:39 +03:00
Georges Oates_Larsen 7fa6b53ac3 net: shell: Add IPv4 and IPv6 connectivity events
Add descriptions for recently introduced IPv4 and IPv6
connectivity events to the net event monitor.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-06-10 00:59:34 -07:00
Georges Oates_Larsen 85c4cb9265 net: conn_mgr: Add IPv4 and IPv6 tracking
conn_mgr now fires:

- NET_EVENT_L4_IPV4_CONNECTED
- NET_EVENT_L4_IPV4_DISCONNECTED
- NET_EVENT_L4_IPV6_CONNECTED
- NET_EVENT_L4_IPV6_DISCONNECTED

These events track whether there are any ready ifaces offering
specifically IPv4 or specifically IPv6 connectivity.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-06-10 00:59:34 -07:00
Georges Oates_Larsen 32ae816d0b net: conn_mgr: Simplify blame handling
Don't track up/down blame separately.
Instead, track a single last-blame iface.

Don't track blame iface inside set_ready.
Instead, track directly inside handle_update.

These two changes will simplify the addition
of blame for IPv4- and IPv6-specific events.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-06-10 00:59:34 -07:00
Georges Oates_Larsen 875755fbb2 net: conn_mgr: Track ready count ephemerally
Instead of incrementing and decrementing global counter,
just recompute the ready-count from scratch every time
conn_mgr_mon_handle_update is called.

This will simplify the introduction of additional ready count types.

This should have no externally observable impact on the behavior of
conn_mgr.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
2024-06-10 00:59:34 -07:00
Robert Lubos 3501d6e6d4 net: shell: ipv4: Add information about ACD
Print information in IPv4 shell whether address conflict detection is
enabled or not.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos c0161c8052 net: l2: ethernet: arp: Simplify ACD case
In case of ACD Probe/Announcement, all we need is to generate ARP
packet, we don't really want any cache entries to be created or searched
for. There was a bug, that a cache entry was created for the
Announcement sent, resulting in skipped ARP packet generation and
malformed packet being sent by the ACD module.

Therefore, simplify all this, by simply returning early in case of
conflict detection packets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos cc53826cc9 net: ipv4: autoconf: Integrate with the ACD module
The autoconf module can now reuse generic address conflict detection,
which was added for all address types.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos 80339ac4ee net: dhcpv4: Add support for conflict detection
In case a conflict was detected on a DHCP-assigned address, send a
Decline message to the server and start over.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00