Commit graph

2451 commits

Author SHA1 Message Date
Robert Lubos
5cea38021e net: lib: zperf: Fix socket leak during socket setup
During socket setup, if one of the setsockopt() calls failed, the
function would return an error w/o closing the socket. That's wrong, as
in case of errors the function should clean up any resources it
allocated, the socket file descriptor is lost otherwise and resources
are leaked.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 11:38:11 -04:00
Robert Lubos
1aca4205b8 net: lib: dns: Fix error code returned when socket creation failed
We should return the errno value in such case, as ret will always be -1
on failure, which might misleading, as it does not give any hint on what
failed.

Also bump the log level of the error message, so the failure is visible
w/o needing to enable debug logs. Such a failure is fatal for the DNS
subsystem, so error level is justified here.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 08:44:29 -04:00
Robert Lubos
e018281d3b net: lib: dns: Fix DNS dispatcher double net buf unref
The `dns_data` buffer, allocated by the DNS dispatcher was dereferenced
twice - once in registered DNS handler, second time in the dispatcher
itself.

Since the buffer was allocated by the dispatcher, and it's not really
guaranteed that the buffer will be freed in the registered handler (this
depends on the processing outcome, the function may return early w/o
freeing the net buf in case of errors), it makes most sense for the
dispatcher to keep ownership of the buffer. Hence, the registered
handlers will no longer release the buffer provided in any case, and the
dispatcher will free it on exit.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-21 08:44:15 -04:00
Henrik Maier
abeae8fd08 net: lib: http_server: Fix dynamic HTTP post zero 0 length reply
Fix issue in http server that a http post
was unable to send a 0 length reply.

Signed-off-by: Henrik Maier <hwmaier@gmail.com>
2024-06-20 08:58:03 +02:00
Chris Friedt
72bd951ac4 net: ptp: do not use a reserved id in global scope
Generally, we should avoid using reserved names in global
contexts.

subsys/net/lib/ptp/clock.c:58:25: \
  error: 'clock' redeclared as different kind of symbol
   58 | static struct ptp_clock clock = { 0 };

/opt/toolchains/zephyr-sdk-0.16.8/arm-zephyr-eabi/picolibc/ \
  include/time.h💯12: \
  note: previous declaration of 'clock' with type 'clock_t(void)' \
  {aka 'long unsigned int(void)'}
  100 | clock_t    clock (void);

subsys/net/lib/ptp/clock.c:58:25: \
  error: 'clock' defined but not used [-Werror=unused-variable]
   58 | static struct ptp_clock clock = { 0 };

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-18 19:54:53 -04:00
Yong Cong Sin
3c0aae8415 net: lwm2m: replace deprecated lwm2m_engine_get_resource
`lwm2m_engine_get_resource()` has been mark for deprecation for
more than 2 releases, but we are still using it in tree now,
because the `__deprecated` marker was probably forgotten in the
initial deprecation commit.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:32:56 -04:00
Yong Cong Sin
94e12d595e net: lwm2m: remove deprecated functions & definition
These functions have been deprecated for more than 2 releases,
remove them:

- lwm2m_engine_update_observer_min_period
- lwm2m_engine_update_observer_max_period
- lwm2m_engine_create_obj_inst
- lwm2m_engine_delete_obj_inst
- lwm2m_engine_set_opaque
- lwm2m_engine_set_string
- lwm2m_engine_set_u8
- lwm2m_engine_set_u16
- lwm2m_engine_set_u32
- lwm2m_engine_set_u64
- lwm2m_engine_set_s8
- lwm2m_engine_set_s16
- lwm2m_engine_set_s32
- lwm2m_engine_set_s64
- lwm2m_engine_set_bool
- lwm2m_engine_set_float
- lwm2m_engine_set_objlnk
- lwm2m_engine_set_time
- lwm2m_engine_get_opaque
- lwm2m_engine_get_string
- lwm2m_engine_get_u8
- lwm2m_engine_get_u16
- lwm2m_engine_get_u32
- lwm2m_engine_get_u64
- lwm2m_engine_get_s8
- lwm2m_engine_get_s16
- lwm2m_engine_get_s32
- lwm2m_engine_get_s64
- lwm2m_engine_get_bool
- lwm2m_engine_get_float
- lwm2m_engine_get_objlnk
- lwm2m_engine_get_time
- lwm2m_engine_register_read_callback
- lwm2m_engine_register_pre_write_callback
- lwm2m_engine_register_validate_callback
- lwm2m_engine_register_post_write_callback
- lwm2m_engine_register_exec_callback
- lwm2m_engine_register_create_callback
- lwm2m_engine_register_delete_callback
- lwm2m_engine_set_res_buf
- lwm2m_engine_set_res_data
- lwm2m_engine_set_res_data_len
- lwm2m_engine_get_res_buf
- lwm2m_engine_get_res_data
- lwm2m_engine_create_res_inst
- lwm2m_engine_delete_res_inst
- lwm2m_engine_path_is_observed
- lwm2m_engine_send
- lwm2m_send
- lwm2m_engine_enable_cache

And additionally, the following definition:
- LWM2M_RD_CLIENT_EVENT_REG_UPDATE_FAILURE

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:32:56 -04:00
Yong Cong Sin
606f90efa9 net: dns: remove deprecated function
`dns_sd_extract_service_proto_domain()` has been deprecated for
more than 2 releases, remove it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:32:56 -04:00
Rex Chen
dcf42917c5 net: lib: dhcpv4: Add check for input parameter of echo_reply_handler
For station and internal AP coexist case, station connected to
external AP, ping from station to external AP cause cpu hang.

Internal AP dhcpv4 server register handler echo_reply_handler
on icmp handler by net_icmp_init_ctx for dhcp server snoop
feature. Ping also register handler handle_ipv4_echo_reply on
icmp handler for ping cmd. If no external station connect to
internal AP, input parameter ‘user_data’ of function
echo_reply_handler is NULL. When we trigger ping process,
icmp_call_handlers fetch all handlers from icmp handler
if receive any ICMP packet, so echo_reply_handler be called,
but input parameter is NULL, cause CPU hang.
Add input parameters check to fix this issue.

Signed-off-by: Rex Chen <rex.chen_1@nxp.com>
2024-06-18 11:07:09 +02:00
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
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
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
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
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
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
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
Robert Lubos
7352aaa841 net: config: Add support for IPv4 ACD
In case IPv4 conflict detection is enabled, monitor network events to
determine whether IPv4 address is ready to use or not, so that the
library returns only after the network setup is fully complete.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Robert Lubos
a89dd1a6f6 net: shell: Add ACD events to the event monitor
Include new ACD events in the shell event monitor.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-06-10 00:59:28 -07:00
Seppo Takalo
d3081e2f30 net: lwm2m: On write, use server selected block size
When we receive CoAP packets, it is in input buffer
that is size of NET_IPV6_MTU.
So in reality, we can handle bigger Block-Wise writes
than CONFIG_LWM2M_COAP_BLOCK_SIZE.

So if parsing of CoAP packet has passed, continue
with the same block-size instead of going to default.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-05 14:43:14 +01:00
Chris Friedt
0fa97326c7 posix: create kconfig options for pse51, pse52, pse53
Create Kconfig "shortcuts" for PSE51, PSE52, and PSE53.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
487a8756c3 posix: eventfd: fix dependency cycle between net and posix
Until recently, the posix api was purely a consumer of the
network subsystem. However, a dependency cycle was added as
a stop-gap solution for challenges with the native platform.

Specifically,

1. eventfd symbols conflict with those of the host
2. eventfd was excluded from native libc builds via cmake

If any part of the posix were then to select the network
subsystem (which is a legitimate use case, given that networking
is a part of the posix api), we would get a build error due to
the Kconfig dependency cycle.

As usual, with dependency cycles, the cycle can be broken
via a third, mutual dependency.

What is the third mutual dependency? Naturally, it is ZVFS
which was planned some time ago. ZVFS will be where we
collect file-descriptor and FILE-pointer APIs so that we can
ensure consistency for Zephyr users.

This change deprecates EVENTFD_MAX in favour of
ZVFS_EVENTFD_MAX.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
bc4374b5fe posix: deprecate POSIX_MAX_FDS and add POSIX_DEVICE_IO
The POSIX_MAX_FDS option does not correspond to any standard
POSIX option. It was used to define the size of the file
descriptor table, which is by no means exclusively used by
POSIX (also net, fs, ...).

POSIX_MAX_FDS is being deprecated in order to ensure that
Zephyr's POSIX Kconfig variables correspond to those defined in
the specification, as of IEEE 1003.1-2017. Namely,
POSIX_OPEN_MAX. CONFIG_POSIX_MAX_OPEN_FILES is being deprecated
for the same reason.

To mitigate any possible layering violations, that option is
not user selectable. It tracks the newly added
CONFIG_ZVFS_OPEN_MAX option, which is native to Zephyr.

With this deprecation, we introduce the following Kconfig
options that map directly to standard POSIX Option Groups by
simply removing "CONFIG_":

* CONFIG_POSIX_DEVICE_IO

Similarly, with this deprecation, we introduce the following
Kconfig options that map directly to standard POSIX Options by
simply removing "CONFIG":

* CONFIG_POSIX_OPEN_MAX

In order to maintain parity with the current feature set, we
introduce the following Kconfig options.

* CONFIG_POSIX_DEVICE_IO_ALIAS_CLOSE
* CONFIG_POSIX_DEVICE_IO_ALIAS_OPEN
* CONFIG_POSIX_DEVICE_IO_ALIAS_READ
* CONFIG_POSIX_DEVICE_IO_ALIAS_WRITE

Gate open(), close(), read(), and write() via the
CONFIG_POSIX_DEVICE_IO Kconfig option and move
implementations into device_io.c, to be conformant with the
spec.

Lastly, stage function names for upcoming ZVFS work, to be
completed as part of the LTSv3 Roadmap (e.g. zvfs_open(), ..).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
4a5c4e5f73 posix: timers: deprecate CONFIG_POSIX_CLOCK and TIMER
The POSIX_CLOCK option does not correspond to any standard
option. It was used to active features of several distinct
POSIX Options and Option Groups, which complicated API and
application configuration as a result.

POSIX_CLOCK is being deprecated in order to ensure that Zephyr's
POSIX Kconfig variables correspond to those defined in the
specification, as of IEEE 1003.1-2017.

Additionally, CONFIG_TIMER is being deprecated because it does
not match the corresponding POSIX Option (_POSIX_TIMERS).

With this deprecation, we introduce the following Kconfig
options that map directly to standard POSIX Option Groups by
simply removing "CONFIG_":

* CONFIG_POSIX_TIMERS

Similarly, we introduce the following Kconfig options that
map directly to standard POSIX Options by simply removing
"CONFIG":

* CONFIG_POSIX_CLOCK_SELECTION
* CONFIG_POSIX_CPUTIME
* CONFIG_POSIX_DELAYTIMER_MAX
* CONFIG_POSIX_MONOTONIC_CLOCK
* CONFIG_POSIX_TIMEOUTS
* CONFIG_POSIX_TIMER_MAX

In order to maintain parity with the current feature set, we
introduce the following Kconfig options that map directly to
standard POSIX Option Groups by simply removing "CONFIG_":

* CONFIG_POSIX_MULTI_PROCESS - sleep()

Similarly, in order to maintain parity with the current feature
set, we introduce the following additional Kconfig options that
map directly to standard POSIX Options by simply removing
"CONFIG":

* CONFIG_XSI_SINGLE_PROCESS - gettimeofday()

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Jukka Rissanen
a124dd2596 net: http_server: Send chunked response correctly
The chunked response was not sent properly. There were extra
"\r\n" before the chunk lenght and the length of the string
to be sent was calculated incorrectly.

Fixes #72887

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-03 15:39:09 +02:00
Seppo Takalo
9e615429d5 net: lwm2m: Block-Wise response NUM field fix
When calculating the offset for blockwise writes,
we should not advance the block_ctx->current field
past the block boundary.
It causes CoAP layer to reply with the next NUM field
instead of the current one being processed.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-06-03 15:37:21 +02:00
Jukka Rissanen
b95821f809 net: dns: llmnr_responder: Print query type properly
Instead of printing either A or AAAA resource query type,
print the correct query type value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-03 09:49:01 +02:00
Jukka Rissanen
b305be037c net: Start socket service thread by net core init
Do not depend on init level but start the socket service
already in net core init because DNS init code depends on
socket service API to be ready to serve. And we call DNS
init at the net core init.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-03 09:49:01 +02:00
Jukka Rissanen
1eb4a709e8 net: dns: Allow using resolver and responder at the same time
Allow mDNS resolver and responder to to be used at the same
time so that both can use the port 5353. This requires
a DNS traffic dispatcher which affects also the normal DNS
resolver.

Fixes #72553

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-03 09:49:01 +02:00
Jukka Rissanen
63e6a83510 net: dns: Add helper for figuring out the query type
Add helper function that returns the name of the query type
so that we can print it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-03 09:49:01 +02:00
Jukka Rissanen
434e290649 net: dns: Add ANY query resource type
Don't give an error for ANY type record.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-06-03 09:49:01 +02:00
Tomi Fontanilles
c1342b3aa9 modules: mbedtls: remove the default enabling of features
In an effort to shave off code size, remove out-of-the-box
enabling of crypto features (except SHA-256).

Configurations are adjusted to enable what they need.

Bonuses:

- When enabled, AES now defaults to using a smaller version
(`CONFIG_MBEDTLS_AES_ROM_TABLES` isn't default enabled anymore,
and if enabled, `CONFIG_MBEDTLS_AES_FEWER_TABLES` defaults to y).

- Conditions around Mbed TLS Kconfig options have been improved
to reflect the reality of the dependencies.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-05-31 16:33:06 -05:00
Jukka Rissanen
08dc8f93fe net: http_server: Add wildcard support to resource strings
Allow user to specify resource string using wildcard characters
so that multiple URL paths can be served with just one handler.

Fixes #73367

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-31 09:57:22 -05:00
Kapil Bhatt
8a52b64875 net: shell: Add random MAC address generation
Add option for setting a random MAC address to
the net iface set_mac command. With random option
a random MAC address can be assigned to an interface.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
2024-05-30 11:55:27 +01:00
Jukka Rissanen
99693bee5f net: socket: Change the protocol field for AF_PACKET sockets
In order to be compatible with Linux AF_PACKET socket calls, the
protocol field needs to be in network byte order.
So for example, if user wants to receive all packets, then the
protocol field needs to be set as "htons(ETH_P_ALL)".
See Linux manual page at
https://www.man7.org/linux/man-pages/man7/packet.7.html
for details.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-29 10:48:34 -07:00
Seppo Takalo
b76683e4cb net: lwm2m: Allow setting RD context without starting
When tests control the LwM2M client entirely through
shell, we should be able to set the RD client context
from the application without causing RD client to
start registration.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-29 10:47:57 -07:00
Tomi Fontanilles
3efdbe6c0c modules: mbedtls: rename CONFIG_MBEDTLS_MAC_*_ENABLED and rm duplicates
Remove the `_MAC` part because those Kconfig options enable only hash
algorithms, nothing MAC-related, and the `_ENABLED` part to align the
naming to the Mbed TLS defines (plus we don't need such a part).

As a bonus, enabling SHA-256 does not automatically enable SHA-224
anymore.

See the migration guide entries for more details on the practical
changes.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-05-29 08:39:26 +02:00
Yong Cong Sin
bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00
Seppo Takalo
4049e17c62 net: lwm2m: Fix null dereference when post-write cb is set
When opaque resources have post-write callback set, but
the write is not a Block-Wise write, there is no block_ctx
and the code causes null pointer dereference when calculating
the offset of the data.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-28 18:54:31 +02:00
Jukka Rissanen
3f96a87d1c net: dns: Fix resolver debug print
Make sure that we are not trying to print NULL pointer string.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-28 17:49:59 +02:00
Jukka Rissanen
74f9a1c482 net: sockets_service: Add build check for using zephyr libc
Add checks to make sure that we are not trying to use the socket
service library with eventfd if CONFIG_POSIX_API is not set and if
using native_sim based board. The reason is that we should always
use zephyr libc based eventfd implementation instead of host libc one.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-28 17:49:59 +02:00
Jukka Rissanen
aa458a279a Revert "net: sockets: Check eventfd errors better"
This reverts commit b56297bf16
because it is causing problems when using native_sim and not
having CONFIG_POSIX_API set.

The proper fix is to set CONFIG_POSIX_API when using eventfd
and native_sim so that picolibc is used instead of host libc.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-28 17:49:59 +02:00
Jukka Rissanen
2a16f4d2bc net: dns: responder: No need to double the socket count
The socket allocation count was incorrectly calculated as
we have only one socket per listened port.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-27 05:01:28 -07:00
Jukka Rissanen
ecda6b190f net: dns: The DNS_EAI_ALLDONE is not an error
If DNS_EAI_ALLDONE is returned, it indicates that the request
was done and should not be considered an error.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-27 05:01:28 -07:00
Marcin Niestroj
c6fd2a1ddf net: dns: don't request address in recvfrom()
Source address is not used anywhere, so don't request it with recvfrom()
API.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-05-24 07:48:17 -04:00
Robert Lubos
1e3f14476b net: tls_credentials: Add missing base64.h header inclusion
base64_encode() was used w/o including the base64.h header. This commit
fixes it.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-23 07:47:41 -04:00
Jordan Yates
0f56974c9d net: lib: dhcpv4: goto INIT on IF down, not RENEWING
When the interface goes down, the safest thing to do is to return to
the INIT state, as there is no guarantee that any state is preserved
upon the interface coming back up again.

This is particularly the case with WiFi.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-22 21:34:44 -04:00
Benjamin Lindqvist
ed025b2f04 net: lib: coap_client: observe-related fixes
An earlier pull request implementing observe support was merged too
hastily. It had a few issues:

1. The predicate for whether a request should be marked not ongoing was
wrong (it checked ret != 0 instead of ret < 0)
2. Without observes in mind, MID-based deduplication is not a required
feature. Deduplication was handled implicitly - the exchange would get
dropped after the first response anyway, so duplicate responses would
not get matched to anything. But with observes, there are several
responses in an exchange. This commit adds this.
3. Using coap_request_is_observe(&internal_req->request) in the response
handler requires the whole request to stay in scope for the lifetime of
the observation, which I observed was not always the case. Adding an
is_observe bool to the internal struct improved stability significantly.

With these fixes, GETs with observe option works very well.

Signed-off-by: Benjamin Lindqvist <benjamin@eub.se>
2024-05-21 16:42:38 -04:00
Jukka Rissanen
b56297bf16 net: sockets: Check eventfd errors better
With native_sim, this error is seen a lot when socket
service API is used.

  <dbg> net_sock: get_sock_vtable: (net_socket_service):
    Invalid access on sock 3 by thread 0x807a8e0 (net_socket_service)

If we just ignore the error, then we might get into forever
loop which is not good. So if this happens, mark the eventfd
fd as not pollable to basically ignore the eventfd support in
this case.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen
3f1bd6b29e net: sockets: Add extra debug print for invalid socket access
Print also thread name when printing socket access error.
This helps debugging what thread caused it.
Lowering the Error to Debug as we could be missing vtable
for example for eventfd descriptors, this is easily seen when using
socket service API.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen
d5cd41a0fe net: llmnr_responder: Convert LLMNR responder to use socket service API
Instead of using net_context API directly, the LLMNR responder is
changed to use the socket service API. This allows DNS access
for offloaded sockets and can lower overall memory consumption.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen
94433b9ce2 net: mdns_responder: Convert mDNS responder to use socket service API
Instead of using net_context API directly, the mDNS responder is
changed to use the socket service API. This allows DNS access
for offloaded sockets and can lower overall memory consumption.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Jukka Rissanen
9a40066b4f net: dns: Convert resolver to use socket service API
Instead of using net_context API directly, the DNS resolver is
changed to use the socket service API. This allows DNS access
for offloaded sockets and can lower overall memory consumption.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-20 14:25:44 +03:00
Pete Skeggs
f04f8b2422 net: lib: coap_client: Improve cancel function
Improve coap_client_cancel_requests(). Ensure it can be
called from a callback. Report error to waiting callbacks.
Clear active flag.

This is useful when the network becomes unavailable
or prior to disconnecting in order to save power.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2024-05-17 10:34:12 +02:00
Ayush Singh
56882e2d91 net: zperf: Fix upload ping timeout error
Fixes remote address for ping before upload. This caused the ping in zperf
upload to timeout as shown in the following output:

```
uart:~$ zperf udp upload 2001:db8::2 5001 10 50 1M
Remote port is 5001
Connecting to 2001:db8::2
Duration:       10.00 s
Packet size:    50 bytes
Rate:           1000 kbps
Starting...
ping 2001:db8::2 timeout
Rate:           1.00 Mbps
Packet duration 390 us
```

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/68674

Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2024-05-15 17:07:58 +02:00
Seppo Takalo
37f6803833 net: lwm2m: Allow Block-Wise write without callbacks
Allow Block-Wise writes to resources that have enough buffer for
the whole content. Calculate the offset before calling the
content specific write handlers when callback is not set.

Previously only resources with post-write callback were able to
assemble the content.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-15 14:58:15 +02:00
Seppo Takalo
a9e91af375 test: lwm2m: Add tests for Block-Wise transfers
Block-Wise GET, PUT and SEND

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-15 14:58:15 +02:00
Seppo Takalo
01b57b4999 net: lwm2m: Add offset to post-write callback
When Block-Wise transfer restarts, the post-write callback should
receive some indication that the block is actually a beginning of new,
instead of part of previous transfer.

Fixes #71351

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-15 14:58:15 +02:00
Jukka Rissanen
6d129b2a2d net: http_server: Add support for specifying Content-Type
Allow user to specify the Content-Type header field for the
HTTP response.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 20:22:58 -04:00
Jukka Rissanen
3d1b8c6116 net: shell: Add command to show HTTP server information
The new command is "net http" which shows all services and
related resources defined in the system.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 15:51:20 +02:00
Jordan Yates
23ca74b756 convert: use k_uptime_seconds
Replace usage of `k_uptime_get() / MSEC_PER_SEC` and
`k_uptime_get() / 1000` with dedicated function.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-05-14 09:32:01 +02:00
Jukka Rissanen
70ab0e65a5 net: websocket: Add a way to unregister a websocket connection
Doing a normal close for a websocket does not close the underlying
real socket. If we do not have fd for the real socket, then it is
not possible to fully close a websocket connection. As we are allocating
a websocket using websocket_register() in HTTP server use case,
create a websocket_unregister() that will close both the real
socket and the websocket socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 09:31:37 +02:00
Jukka Rissanen
4d9d0ee64c net: websocket: Ignore error during close if we are disconnected
No need to return an error during a close if we are already
disconnected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 09:31:37 +02:00
Fin Maaß
9bd0170aad net: http: client: mark as unstable
As the http client API is currently used by two applications
(websocket and hawkbit), it should be marked as unstable, according
to the docs:
https://docs.zephyrproject.org/latest/develop/api/api_lifecycle.html

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-05-13 16:02:55 -04:00
Adam Matus
684a28656e net: zperf: Add periodic reporting for upload
Add option for zperf tcp upload that will enable periodic result reporting.
This is useful for monitoring performance swings during a longer session.

Signed-off-by: Adam Matus <adam.matus@nxp.com>
2024-05-10 14:45:48 -05:00
Adam Matus
a6ededcc9f net: zperf: Move TCP nodelay socket option
TCP nodelay option is part of zperf upload params, but was not being
set in common zperf_prepare_upload_sock function. Move it there
to align with how other options are set.

Signed-off-by: Adam Matus <adam.matus@nxp.com>
2024-05-10 14:45:48 -05:00
Robert Lubos
0ba6a20896 net: sockets: Move TLS sockets out of experimental
TLS socket have now been in Zephyr for a few years already and are
widely adopted across the codebase. Given above, they should no longer
be considered an experimental feature.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-10 14:42:03 -05:00
Valerio Setti
e6281c9d21 tls_credentials: remove TinyCrypt implementation of digest_raw
Moving toward the adoption of PSA crypto APIs, TinyCrypt is going
to be deprecated so we can remove it in favor of newer APIs.

Moreover tls_credentials is mostly meant to store data in the
protected storage meaning that there is a TFM implementation
providing this service. The same TFM can of course be used to
compute sha256 hashing thus saving memory footprint on the NS
side by removing TC.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-05-08 22:14:19 -07:00
Valerio Setti
34c4b54473 net: tls_credentials: use PSA to compute SHA256 when BUILD_WITH_TFM
When using the TLS_CREDENTIALS_BACKEND_PROTECTED_STORAGE there is
BUILD_WITH_TFM enabled which means that we can take advantage of
TFM (thorugh PSA interface) to compute the SHA256 hash.

This removes the need for the built-in implementation of
mbedtls_sha256() on the non-secure image (unless it's used somewhere
else, of course) and therefore it helps in reducing the memory
footprint.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-05-08 22:14:19 -07:00