Commit graph

5477 commits

Author SHA1 Message Date
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
Robert Lubos 50c523636b net: ipv6: Clear joined flag on all mcast address when operational down
When the network inteface goes operational DOWN (for example cable
unplugged), clear "joined" flag on all registered multicast addresses,
so that MLD report is sent for them when the interface goes back up.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-14 18:20:56 -04:00
Robert Lubos 3e046626c1 net: ipv6: Rejoin all solicited node mcast addresses
When bringing interface down, all IPv6 multicast addresses are removed
from the interface. However, when the interface was brought back up,
rejoin_ipv6_mcast_groups() would look only for solicited node mcast
addresses already present on the interface. In result, after going back
up, the interface was missing solicited-node mcast addresses for those
unicast addresses, that were already present on the interface when
bringing up.

As net_ipv6_mld_join() does similar checks to skip MLD when not needed,
we can just skip the lookup when rejoining, and use already defined
join_mcast_nodes().

Additionally, check for IPV6 and NO_ND flags on the interface before
attempting to add the address back, those multicast addresses are not
needed if ND is disabled on the interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-14 18:20:56 -04:00
Robert Lubos d48da4cfd1 net: ipv6: Fix missing DAD for link-local address
In case a network interface is brought down and back up, DAD was not
performed for link-local unicast address.

This happens because the logic in the network interface code assumed
that DAD for link-local address is triggered when the address is added,
and it's explicitly omited when looping over IPv6 address. This wasn't
the case however when interface was brought back up, as the address was
already present on the interface, hence DAD skipped.

In Linux, the link-local address is removed from the interface when the
interface is brought down. Such approach solves the issue described,
hence implement it in a similar way in Zephyr.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-14 18:20:56 -04:00
Jukka Rissanen 1d7970be04 net: context: Do not check our own ports
There is no need to check our own context when going through
the used ports in the system. This prevents error when binding
in some corner cases.

Fixes #72035

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-14 18:19:54 -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
Tomi Fontanilles 2d61db9a60 mbedtls: introduce PSA-specific Kconfig file
It is meant specifically for configuration of the PSA crypto library.

The underlying PSA configuration items are guarded by the condition
that a PSA crypto provider must be present, which is the case when
either TF-M is in use or MbedTLS's PSA core is built as part of
the application image.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2024-05-10 18:24:38 -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
Konrad Derda 9074c07ae7 net: ipv6: mld: use proper MLDv2 modes
According to the RFC, MODE_IS_INCLUDE/MODE_IS_EXCLUDE codes should be
used while sendling Multicast Listener Reports in response to a query.
When performing a transition between states (e.g., when joining or
leaving a multicast group) CHANGE_TO_INCLUDE_MODE/CHANGE_TO_EXCLUDE_MODE
have to be used.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-05-10 11:44:50 +02:00
Konrad Derda 7f5a481ec7 net: ipv6: mld: remove addition of unspecified source in MLDv2 report
From RFC:
* "source list" is an unordered list of zero or more unicast
addresses from which multicast reception is desired or not desired [...]

It means that there is no need to add any special address to specify
"block all" and "allow all" states explicitly. This commit removes the
unnecessary addition.

Signed-off-by: Konrad Derda <konrad.derda@nordicsemi.no>
2024-05-10 11:44:50 +02:00
Valerio Setti d068982005 net: tcp: use PSA for SHA256 when BUILD_WITH_TFM
When BUILD_WITH_TFM is enabled we can dispatch hash computation
to TFM. This allows to remove the built-in support of SHA256 from
the non-secure side (if it's not used for any other purpose, of course).

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-05-09 10:27:30 +02:00
Valerio Setti b25f322b73 net: tcp: use CS random generators to generate ISN
Use only cryptographically secure random number generators for ISN.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-05-09 10:27:30 +02: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
Robert Lubos 6551e6f5ba net: arp: Add support for gratuitous ARP transmission
Add support for gratuitous ARP transmission by Zephyr network stack.
This allows to prematurely fill the peer ARP table, so there's no need
to send an explicit request when peer needs to send an actual packet.

The gratuitous ARP is send when the network interface is brought up
(joins the network) or a new IP address is added. The gratuitous ARP
request is also sent periodically, with a configurable interval time.
The gratuitous ARP should also be sent whenever MAC address of the
interface is changed, but as Zephyr only allows to do this when
interface is down, this is already covered by the first case (interface
brought up).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2024-05-08 16:09:31 -04:00
Jukka Rissanen f9ac565f12 net: shell: Pretty print websocket output
Fixing the websocket command output to align the fields and
printing interface index instead of a pointer value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 85e9b0b274 net: websocket: Add socket statistics collection
Add socket obj_core support to websocket so that the socket
information can be viewed by "net sockets" command.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 3c9513e9cc net: http_server: Add websocket support
After upgrading the HTTP connection to websocket, call the
application registered callback to transfer the ownership of
the socket to the application.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen dedd30e140 net: websocket: Do not print error in closing
If the other end closes the connection, it is not exactly an
error so downgrade the print to debug level.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 13118cf3c0 net: websocket: Create websocket_register() for http_server use
The http_server needs a way to bind a websocket socket to the
upgraded http connection socket. So websocket_register() is used
for that.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 97caab6396 net: websocket: Do not use menuconfig
Use normal "config" in order to avoid this error from compliance
check script:

    Found pointless 'menuconfig' symbols without children.
    Use regular 'config' symbols instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 535d4b40a8 net: lib: http_server: Upgrade from HTTP/1.1 to websocket
Allow connection to be upgraded from HTTP/1.1 to websocket.
This commit does nothing yet with the upgraded connection.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Jukka Rissanen 37956465e1 net: lib: http_server: Check HTTP/1.1 Upgrade field
Check what kind of upgrading we are doing and return error
if we receive upgrade that we do not support.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-08 15:02:16 -05:00
Maciej Baczmanski 479e957b79 kconfig: openthread: Fix PSA Key Ref config for RCP architecture
`OPENTHREAD_PLATFORM_KEY_REF` should not be selected for RCP
architecture, as keys are handled on host's side and passed to
device over Spinel, and therefore they cannot be exported
on platform from reference with PSA Crypto API.

Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
2024-05-08 09:25:15 -04:00
Philippe Schumacher 67db6f69f3 net: lwm2m: efficent cbor record data structure
The record data structure is better aligned. Each record saves
24 bytes.

Signed-off-by: Philippe Schumacher <philippe.schumacher@husqvarnagroup.com>
2024-05-08 12:00:57 +02:00
Pieter De Gendt db8bb9ef56 cmake: linker: Use kconfig for iterable section subalign
Replace the hard-coded 4 with the Kconfig symbol
CONFIG_LINKER_ITERABLE_SECTION_SUBALIGN .

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-05-07 18:01:37 -04:00
Seppo Takalo e2ab41b625 net: lwm2m: Fix pull-context on queue mode
Two issues fixed:
When pull-context is created, it does not have to wake up the RD
client context. Ignore the EPERM warning.

When new pull-context creates a new socket, sometimes socket-loop
gets to recvfrom() before we have set O_NONBLOCK on the socket.
So use ZSOCK_MSG_DONTWAIT on zsock_recvfrom() so it does not
block the socket loop.

Fixes #71450

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
2024-05-07 15:10:09 -05:00
Marcin Kajor b571e45d80 net: if: Extend the usage of rejoining the multicast groups
It may happen that the interface is up but not yet running
when we issue the rejoin_ipv6_mcast_groups(). This can be
fixed by calling this function again right after the iface
is set to 'running' state in the notify_iface_up handler.

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
2024-05-07 15:07:14 -05:00
Fin Maaß afff8a16dc net: config: correct dependency of NET_CONFIG*
Corrects the dependencies of NET_CONFIG*

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-05-06 22:51:19 +01:00
Jukka Rissanen 8d077ca66d net: if: Print warning if there are no network interfaces
When calling net_if_get_default(), print a warning if no
network interfaces are found. This helps debugging mysterious
crashes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen 17f852f3cf net: if: ipv6: Do not crash if there are no network interfaces
When trying to get IPv6 prefix, if there are no network interfaces
then the net_if_get_default() will return NULL but we should not
crash at that point but return gracefully.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen 2711e12039 net: ipv6: Tailor PE values for Zephyr
Making default preferred time much closer to default valid time
so that the served addresses are much shorter time in deprecated
state where they cannot be utilized. This is important in Zephyr
as there are limited number of IPv6 addresses that can be allocated
to the network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen 39ab0bb002 net: sockets: Fix getsockname() for TCP
The local address used for established TCP socket needs to be
dig out from TCP internals and not from context->local.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen c6c021b1f8 net: context: Add helpers for figuring out local endpoint address
We usually cannot use context->local for established TCP connections
because the local address is not updated for TCP if we are bound to
any address. So create helper that try to figure out the end point
addresses.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen d47e0dd93e net: Add IPv6 source address selection support
Add support for IPv6 Source Address Selection defined in RFC 5014.
This commit does not add any address selection support to getaddrinfo()
as described in the RFC. The AI_EXTFLAGS symbol and also the ai_eflags
to hints is added but they are not used by the code.
The public/temporary address selection is only done internally by
the net_if_ipv6_select_src_addr_hint() according to flags set by
setsockopt().

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen bd496541d7 net: shell: Print ref count information for IPv4 and IPv6 addresses
When printing IPv4 and IPv6 address information in "net ipv4" and
"net ipv6" commands, print also reference count of the IP address.
This is useful for debugging purposes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen f96087e257 net: Add ref counting to net_if_addr struct
Add reference counting to network interface address (for both
IPv4 and IPv6) so that the address is not removed if there are
sockets using it. If the interface address is removed while there
are sockets using it, the connectivity will fail for the said
socket.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen c69357a8b4 net: if: Remove IPv6 address when it expires
No need to keep the expired addresses around, just remove it.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00
Jukka Rissanen a7e332dc18 net: ipv6: Add Privacy Extension events to net_mgmt
Add events to be generated when privacy extension is enabled
or disabled, or when allow/deny filter is added or deleted.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-05-06 22:50:18 +01:00