Captured request headers are only delivered in the first dynamic
resource callback, which was not documented explicitly enough, causing
confusion for users. Document this contract on the Kconfig option,
the API, and the HTTP server guide.
Assisted-by: Cursor:Claude Opus 4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Keep rx_timestamp_valid tied to timestamps captured by the transport. A
PHC sample taken after packet reception can populate the fallback host
time, but it must not be treated as an RX hardware timestamp.
Check PHC reads before using their output during synchronization and clock
steps. Skip the adjustment when a read fails instead of consuming
uninitialized time data.
Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Corrects argument order in two logs that happen
if NULL check succeeds on result of
llext_section_name. Fixes issues introduced by
PR #109875.
Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
On multi-interface devices, ping could try to read RSSI on non-IEEE
802.15.4 links when CONFIG_IEEE802154 is enabled.
Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
The Linux ping command supports the quiet parameter `-q` that suppresses
the printing of the ping response to the shell.
This is helpful for Zephyr applications where the underlying UART is shared
with the logging module.
Extensive logging prevents that `net ping` can send its message to the UART
for more than 100ms. The net stack becomes unresponsive for upcoming pings.
The behavior looks like an issue with the network stack, which is not the
case. Logging is battling against the `shell_print()` of the `net ping`
command.
So, the quiet parameter allows having extensive logging active while ping
commands are ongoing.
Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
On ping command termination, three additional lines are printed
with packet statistics and round-trip times as known from Linux `ping`.
> --- ping statistics ---
> 3 packets transmitted, 3 received, 0% packet loss
> rtt min/avg/max = 87/91/93 ms
Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
There are two calculation and string formats for FPU and non-FPU
controllers. These macros will be useful later for outputting
ping time statistics.
Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
The print function of the `net ping` shell command can be joined
together for IPv4 and IPv6. This will reduce code duplication slightly.
Pre-works to be able to add ping statistics without code duplication.
Signed-off-by: Stefan Schwendeler <Stefan.Schwendeler@husqvarnagroup.com>
nvs_read() returns the full stored entry length, which can exceed the
read buffer. Three name-read sites then wrote name[rc] = '\0' using that
length, writing the NUL past the fixed stack buffer at an attacker-
influenced offset (shared-flash threat model).
Skip entries whose nvs_read length is >= the buffer size before the NUL
store.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Now that the ZVFS eventfd table can be sized from the sum of all
CONFIG_ZVFS_EVENTFD_ADD_SIZE_* requirements, let the networking
subsystems that allocate eventfds declare how many they need, so the
default count no longer has to be bumped manually by the application.
Each subsystem reserves an eventfd for its poll loop wake-up:
the HTTP server, the CoAP server, the socket service dispatcher, PTP,
and the LwM2M engine (only in tickless mode) request one each, while
the SSH server and client scale with their configured instance counts.
Assisted-by: Cursor:Claude Opus 4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
If the user call getaddrinfo() while K_HEAP_MEM_POOL_SIZE == 0 and
CONFIG_NET_IP=y, he get a link time failure:
.../ld.bfd: ...: in function `zsock_getaddrinfo':
...(.text.zsock_getaddrinfo+0xe): undefined reference to `k_calloc'
In fact, k_calloc() is required if CONFIG_NET_IP or CONFIG_DNS_RESOLVER is
set (because of the definition of ANY_RESOLVER) but K_HEAP_MEM_POOL_SIZE is
guaranteed to be != 0 only if CONFIG_DNS_RESOLVER is set.
So, forward the dependency in Kconfig to fix the issue.
Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Hop limit should only be decremented if a route is found and if the
packet is actually forwarded.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
handle_ra_6co() did not enforce the RFC 6775 maximum context length of
128. A larger value made context_len/8 exceed the prefix size and
underflowed the memset length, smashing the 6lo context table from an
unauthenticated link-local Router Advertisement.
Reject context_len > 128 before computing the memset length.
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The Record Route and Timestamp handlers computed skip = ptr - ptr_offset
with ptr taken from the IP option. A pointer below ptr_offset underflowed
skip (uint8_t) to ~252 and over-read the option data into the reply,
leaking stack to a remote attacker.
Reject ptr < ptr_offset before the subtraction in both handlers.
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
get_ihpc_inlined_size() indexed da_inline_size_table (13 entries) with a
4-bit destination index (M|DAC|DAM, 0-15). Reserved combinations 13-15
read past the table, yielding a bogus inline size used downstream. Reject
an index beyond the table.
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
ptp_msg_post_recv() indexed msg_size[] with the 4-bit message type taken
straight off the wire (0-15), but the table only has entries up to
PTP_MSG_MANAGEMENT (0xD). Types 0xE/0xF produced an out-of-bounds read
whose bogus length then drove a copy.
Reject type >= ARRAY_SIZE(msg_size) before indexing.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
TCP is obligatory for HTTP1/HTTP2 to work, therefore ensure it's enabled
if one of those is used, although make the select for native stack only,
to ensure the library can still work with offloaded interfaces.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
most ethernet drivers already don't report
capabilities, that are not compiled in, so we also
don't need to compile the descriptions in the shell in.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
When the LPN terminates a friendship by sending Friend Clear, the
Confirm was never received due to two issues:
1. The Friend's immediate Confirm was enqueued into the Friend
Queue and then purged by friend_clear(). Fixed by calling
friend_clear() before sending.
2. The Confirm advertisement completed before the LPN finished
its own retransmissions and started scanning. Fixed by delaying
the Confirm send based on network transmit parameters.
Additionally, bypass the LPN transport filter during the CLEAR
state so the Confirm is not dropped on arrival.
The clear procedure and Confirm contexts share a union since they
are mutually exclusive for the same Friend slot.
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
http_server_run() polls the listening and client sockets with an
infinite timeout and treats a return value of 0 as "should never
happen". It can happen: zsock_poll() returns 0 even with an infinite
timeout when k_poll() wakes for a registered event but every fd reports
no revents on the subsequent POLL_UPDATE pass (a spurious wakeup).
In that case the loop breaks and http_server_run() returns 0 without
taking the closing: path, so close_all_sockets() is skipped. All
sockets are leaked and, worse, the per-client inactivity timers
(k_work_delayable) stay armed in the kernel timeout list. The server
thread then re-initializes the context and http_server_init() memset()s
the client array out from under those still-armed timeouts, corrupting
the kernel timeout list and leading to a delayed fault.
Re-poll instead of breaking. With an infinite timeout, polling again is
always correct and leaves the sockets and their timers intact.
Signed-off-by: Andreas Petter <Andreas.Petter@mcnetic.de>
The "dfd receivers-get" shell command prints the firmware distribution
progress under the JSON "progress" key, but first divides
bt_mesh_dfu_cli_progress() by two.
bt_mesh_dfu_cli_progress() is documented to return "the progress of the
current transfer in percent", i.e. a 0-100 value. The division mirrors
the on-wire encoding of the Transfer Progress field in the Firmware
Distribution Receivers List message, which is expressed in 2% increments
(0-50, see handle_receivers_get() in dfd_srv.c). That encoding is correct
for the over-the-air field, but applying it to a human-facing diagnostic
command is misleading: the command reports half of the actual percentage
(e.g. 25 while the transfer is at 50%).
It is also inconsistent with the Firmware Update Client shell command:
cmd_dfu_tx_progress() in shell/dfu.c prints bt_mesh_dfu_cli_progress()
directly as "DFU progress: %u %%", i.e. a 0-100 percentage.
Drop the division so the dfd shell reports the 0-100 percentage that the
API returns, aligning it with the dfu cli command. The on-wire encoding
in dfd_srv.c is intentionally left unchanged.
Signed-off-by: Francesco Vatteroni <francescov.90@gmail.com>
When CONFIG_HTTP_SERVER_VERSION_3 is not defined, h3_alpn_list could be
used without being defined. Add the missing #define block to fix the
error.
Signed-off-by: Jim Broadus <jbroadus@gmail.com>
net_if_ipv6_select_src_addr_hint() is compiled for any CONFIG_NET_IPV6
build, but it calls net_if_ipv6_prefix_get(), which is only built under
CONFIG_NET_NATIVE_IPV6. On an offloaded IPv6 interface this leaves an
undefined reference at link time.
On-link prefix bookkeeping is only maintained by the native IPv6 stack,
so guard the lookup with CONFIG_NET_NATIVE_IPV6 and fall back to a
full-length (128-bit) prefix match for offloaded interfaces.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:Auto
When the net shell is enabled on an offloaded-only stack
(CONFIG_NET_OFFLOAD=y, CONFIG_NET_NATIVE=n), several command files
reference native-only symbols, which breaks both compilation and
linking:
- iface: print_supported_ethernet_capabilities() was defined under
NET_L2_ETHERNET && NET_NATIVE but called under NET_L2_ETHERNET
alone. The helper only needs the static inline
net_eth_get_hw_capabilities(), so drop NET_NATIVE from the guard.
- conn: net_conn_foreach() and its callback come from connection.c,
which is native-only. Guard the connection-handler listing with
NET_NATIVE; the offloaded context listing via net_context_foreach()
is retained.
- stats: net_stats_reset() lives in net_stats.c (native-only), so
guard the reset path and print a hint instead. Include <stdlib.h>
for strtol(), and print the 64-bit byte counters with PRIu64 and a
uint64_t cast. In offloaded builds GET_STAT() is stubbed to a plain
int 0, which otherwise mismatches the 64-bit format.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:Auto
The ICMP echo API (net_icmp_send_echo_request() and friends) was
designed to support offloading: offloaded drivers can register a ping
handler via net_icmp_register_offload_ping(). However, icmp.c was only
compiled for the native stack, so the API and the net shell "ping"
command were unavailable on offloaded-only devices
(CONFIG_NET_OFFLOAD=y, CONFIG_NET_NATIVE=n).
Build icmp.c whenever CONFIG_NET_IP is enabled, and gate only the
native echo-request senders (which rely on the native IP output path)
with CONFIG_NET_NATIVE_IPV4/IPV6. The dispatch layer keeps routing to
the offload ping handler, so devices that implement ping offloading can
use the command, while non-offloaded paths fall back to -ENOTSUP.
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:Auto
- Adds the CRC-32/MPEG-2 variant
(ISO/IEC 13818-1 Annex A, ITU-T H.222.0)
to both the software CRC subsystem and the CRC device API.
- Adds crc32_mpeg2() and crc32_mpeg2_update().
Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
The user data struct contains "struct net_sockaddr" which
should not be used when instantiating a variable.
Change the code to use "struct net_sockaddr_storage" which
will hold enough space to store both IPv4 and IPv6 socket
addresses.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
net_tcp_get_mtu() initialised its work structure with
"data.remote = *dst", which copies the full generic struct
net_sockaddr (NET_SOCKADDR_MAX_SIZE bytes). Callers pass a pointer to a
family-specific struct net_sockaddr_in or net_sockaddr_in6, both of
which are smaller than the generic struct, so copying the whole struct
read past the end of the caller's object. AddressSanitizer reports this
as a stack-buffer-overflow when running tests/net/pmtu
(test_pmtu_05_ipv4_tcp / test_pmtu_05_ipv6_tcp).
Tested with tests/net/pmtu on native_sim with CONFIG_ASAN=y.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Instead of logging based on the bap stats interval, the USB
part will not just use a flat rate limit of 30 seconds.
Since the bap_stats_interval and USB rates are used for 2 very different
things, and since USB will likely be trigger way more often, it did
not make a lot of sense to use the same value for both.
30 seconds was chosen as it still provides information to
the user on a reasonable interval, without filling up the
shell console too fast.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add command to loop through known receive states and print
their content. This also adds the request BIS sync value for
comparison to the currently synced value.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Change the order of the pa_interval and bis_sync arguments for
the add_src command. The reason is that the user will generally
care more about setting the right bis_sync value (e.g. to 0x01)
rather than the PA interval which may be set to "unknown" in
any case. With this change the user can set the bis_sync without
the pa_interval and just defer to the "unknown" PA interval value.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Commit bf31fab429 ("net: wifi: shell: Add check for iface type when
get iface") made get_iface() reject a user supplied "-i" interface when
its NM role did not match the requested STA/SoftAP type.
That check is wrong for single-VIF parts. There the same netdev serves
STA and SoftAP, switching role at runtime, so the NM role only tells us
what the interface is doing now, not what it is allowed to do. Matching
against it rejects a valid "wifi ap enable -i <sta>" before the role
switch can even happen.
Drop the role match and keep only the check that the interface is a
managed Wi-Fi interface. Whether a STA->SoftAP switch is possible is up
to the driver/supplicant, which already rejects unsupported requests.
Default (no "-i") selection still picks the right netdev through
net_if_get_wifi_sta()/sap().
Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
Assisted-by: Cursor:Auto
DataFragment fragments are 1-indexed. A frag_counter of 0 underflows
(frag_counter - 1) in the decoder, producing a wild frame index and
flash offset. Reject it at the transport layer.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Re-implementation of the fix originally proposed as PR #109426 on
top of the z_try_abort_timeout() infrastructure.
When a dynamically allocated k_timer's reference count drops to
zero its storage is about to be freed. If the timer's expiration
handler is in flight on another CPU at this moment, it will
dereference the freed memory.
Introduce k_timer_cleanup(): cancels the timeout and waits for any
in-flight handler to complete. Unlike k_timer_stop() it does not
run the user stop_fn nor wake pending threads -- the caller is
about to drop the storage and there is no further consumer. The
retry-on-EAGAIN loop around z_try_abort_timeout() guarantees that
when this returns 0 the handler has fully run; no in-band sentinel
is involved.
unref_check() in kernel/userspace/userspace.c calls
k_timer_cleanup() for K_OBJ_TIMER, guarded by K_OBJ_FLAG_INITIALIZED
(z_waitq_head() on an uninitialized dnode would otherwise read
garbage).
Add sys_port_trace_k_timer_cleanup_{enter,exit} hooks across the
tracing backends (default no-op).
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Set z_spinlock_abort_sentinel in swap_data before force-aborting a
thread that holds a lock after an expected panic/assert, so that
z_assert_can_swap() can exempt the forced-abort swap path.
Signed-off-by: Jinming Zhao <jinmzhao@qti.qualcomm.com>