Enhance "net route check" so it does more than print the selected
egress interface for WireGuard VPN routes. When the resolved route
uses a WireGuard interface, also report whether the destination is
covered by the peer's AllowedIP list and whether the peer currently
has usable session state for transmission.
This makes the command much more useful when debugging VPN routing,
as it now explains why traffic selected for a WireGuard interface may
still not be sendable.
Also handle on-link routes without a nexthop explicitly in the route
output instead of assuming a nexthop address is always present.
Assisted-by: Copilot:GPT-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
WireGuard already validates inbound inner packets against the peer's
AllowedIP list, but outgoing inner packets were accepted without
checking whether the destination belonged to that peer.
Add a shared AllowedIP match helper and use it for both directions.
Ingress still validates the decrypted packet source address, and
egress now validates the inner destination address before starting a
handshake or encrypting the packet.
Keep empty keepalive packets exempt from the check so normal session
maintenance traffic still works.
Assisted-by: Copilot:GPT-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
When IPv6 routing is disabled, net_if_ipv6_get_best_match()
applies a VPN-specific filter to avoid selecting the virtual
interface for unrelated destinations. That filter assumed a /64
prefix for every VPN address.
Replace the hard-coded /64 with the configured IPv6 prefix of the
candidate source address. If no matching prefix is configured, only
then assume /64 prefix length.
This keeps the no-routing VPN heuristic intact without rejecting
valid non-/64 setups or relying on an implicit subnet size.
Assisted-by: Copilot:GPT-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Treat VPN virtual interfaces as non-ND links in the IPv6 route
transmit path.
Routed IPv6 traffic on WireGuard-style interfaces could fail even
with a valid route, because the route code still required an IPv6
neighbor-cache entry for the configured nexthop. That assumption is
wrong for VPN interfaces that do not use normal L2 neighbor
discovery.
Assisted-by: Copilot:GPT-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Show IPv4 route add and delete information when those network
management events are triggered.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make locally originated IPv6 traffic consult route state
before falling back to the default interface.
Local source/interface selection could previously choose the default
interface before checking explicit host or prefix routes. That let
configured gateway paths win over more specific routes on another
interface, which breaks VPN and similar multi-interface setups.
Add route-aware helpers in net_if.c and use them in IPv6
source/interface selection paths. The IPv6 path checks
neighbor state before route and default-router fallback so local
selection stays aligned with actual egress routing.
Assisted-by: Copilot:GPT-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Teach local IPv4 source/interface selection to consult the IPv4
route table before falling back to the default interface.
Locally originated traffic such as shell ping selected its outgoing
interface via net_if_ipv4_select_src_iface(). When no source address
matched the destination subnet, the code fell back to the default
interface immediately. This bypassed explicit IPv4 routes on other
interfaces, so traffic could be sent through default interface even
when a host route existed on another interface.
Add a helper that resolves the route-selected interface first and use
it in both net_if_ipv4_select_src_iface_addr() and
net_if_ipv4_select_src_addr(). This keeps source address selection
aligned with the actual routed egress interface.
Assisted-by: Copilot:GPT-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
If routing is disabled, then do extra check with VPN connection
so that the system will work like before.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
If a network interface does not have IP address configuration
in it, then it cannot be used for IP routing so skip those
interfaces when viewing the routing information.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
When optimized for speed it was possible that compiler for ARM Cortex-M
used double word read for code that was reading two words from an array.
However, it was possible that this array was not word-aligned and
double word access was resulting in a bus fault. Refactored the function
to ensure that only word access is used (word access on Cortex-M4 and
later supports unaligned access).
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
In prov_msg_recv(), the protocol timer was reset unconditionally at
the top of the function, before the FCS check and before the
ADV_LINK_INVALID check. When the link has been marked invalid (e.g.
after a provisioning failure), any incoming PB-ADV packet with a
passing FCS would still reset the timer, preventing
protocol_timeout() from firing and closing the link via
prov_link_close().
Move k_work_reschedule() to after the ADV_LINK_INVALID check so the
timer is only reset for valid PDUs on an active, non-failed link.
Move the FCS check before the timer reset for the same reason.
Once ADV_LINK_INVALID is set the protocol timer is no longer
extended by incoming packets, and the link is closed by
protocol_timeout() as intended, after which the unprovisioned
device beacon and PB-ADV link acceptance are restored.
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
osDelayUntil() previously called k_sleep(K_TICKS(ticks - ticks_elapsed))
which caused a wrap-around when ticks was in the past, resulting in a
K_FOREVER sleep.
This patch changes the implementation to account for ticks being
in the past according to:
https://github.com/ARM-software/CMSIS_5/issues/277#issuecomment-390646527
Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
ext2_fetch_direntry() trusted the on-disk de_rec_len and de_name_len,
and the lookup and readdir paths advanced traversal by an unvalidated
de_rec_len. A crafted ext2 image could trigger an out-of-bounds read
past the directory block buffer or a zero-progress loop in any path
that walks a directory.
Validate rec_len and name_len in the parser, and reject entries whose
header does not fit in the remaining block or whose rec_len would
cross the block boundary in each caller.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
Implement Native Simulator host filesystem mounting under Zephyr. This file
system allows to access host files and directories inside Zephyr running
under Native Simulator.
There is new Native Simulator executable parameter supported '-volume',
which can be used to mount any host directory in Zephyr (following Docker
volume mount syntax):
-volume=/host/dir:/dir
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
Optimises the erase check when using swap-using-offset to only erase
the first sector if the first sector has data, rather than if any of
the image has data
Signed-off-by: Jamie McCrae <spam@helper3000.net>
Adds a new Kconfig option, CONFIG_IMG_CUSTOM_SECTOR_SIZE, which can
be used to force setting what the sector size is that MCUboot is
using when configured in swap using offset mode, this allows for
using different page sizes in the application vs MCUboot (in order
to increase efficiency of MCUboot and reducing the swap status size)
Signed-off-by: Jamie McCrae <spam@helper3000.net>
This commit introduces a new option that enables querying all available
DNS servers simultaneously.
When enabled, DNS queries will be sent to all available DNS servers
concurrently rather than just the first server. The first valid response
received will be used and returned to the application.
Signed-off-by: Cristian Bulacu <cristian.bulacu@nxp.com>
When a ARP reply is received, the destination MAC address
in net_pkt was set from the destination address in the
ethernet header, but the pending packet does not have a
ethernet header yet. This caused the destination MAC to
be set to the first bytes of the IP header.
Set the destination MAC address from the updated ARP
entry.
Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Enable request header capture in the HTTP/3 test target and add
regression coverage for captured headers on QUIC request streams.
Add one test for a GET request and one for a POST request so the
suite verifies both immediate delivery and the deferred first DATA
callback path used by body-carrying HTTP/3 requests.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Feed decoded QPACK request headers into the existing header capture
path so HTTP/3 exposes captured headers the same way as HTTP/1 and HTTP/2.
Keep the capture state per HTTP/3 stream and restore it with the
rest of the stream state. This avoids concurrent request streams
overwriting each other's captured headers and keeps header-only and
body-carrying requests working correctly.
Dynamic HTTP/3 handlers now receive captured headers on the first
application callback, including requests that do not deliver the
body until a later DATA frame.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
mbedtls_ssl_get_peer_cid() always writes MBEDTLS_SSL_CID_OUT_LEN_MAX
bytes into the destination buffer regardless of the actual CID length.
tls_opt_dtls_peer_connection_id_value_get() passed the caller-supplied
optval directly without checking it was large enough, allowing an OOB
write of up to 31 bytes past the buffer end.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
Since commit 37717b229f ("sys: util: rename Z_MIN Z_MAX Z_CLAMP to min
max and clamp"), <zephyr/sys/util.h> unconditionally defines function-
like macros named `min`, `max`, and `clamp` in the global namespace (in
C mode). util.h gets pulled in transitively by very broad headers,
including the POSIX layer's <pthread.h>, so any third-party C code that
uses these names as ordinary identifiers (e.g. XNNPACK's static `clamp`
helper and its public `clamp` struct field) fails to build as soon as
<pthread.h> is included.
Following the approach used by Linux, move the lowercase `min`, `max`,
`min3`, `max3`, and `clamp` macros (and their helpers) into a new
<zephyr/sys/minmax.h> header that has to be included explicitly by
source files that want them. util.h keeps the uppercase MIN/MAX/CLAMP,
so most code is unaffected; only the (much smaller) set of files that
actually use the lowercase variants needs to pick up the new include.
Fixes#107853.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
There is a linking failure if using clang and no optimizations
subsys/net/lib/http/http_server_core.c:1060:
(.text.handle_listen_pollin+0x159):
undefined reference to `accept_h3_connection'
subsys/net/lib/http/http_server_core.c:1101:
(.text.handle_listen_pollin+0x425):
undefined reference to `h3_open_uni_streams'
When CONFIG_NO_OPTIMIZATIONS=y was set.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
flash_area_label just returns the
fa_label from the struct flash_area, this
should be inlined for optimisation.
This way we no longer have to jump to
that function.
also fixes the use of
``#if CONFIG_FLASH_MAP_LABELS``
instead of
``#if defined(CONFIG_***)``;
make it visible in the docs;
implement ithe function when
CONFIG_FLASH_MAP_LABELS is not set.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
flash_area_get_device just returns the
fa_dev from the struct flash_area, this
should be inlined for optimisation.
This way we no longer have to jump to
that function.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
the return value of uart_irq_update() is not relevant,
therefore change it to void.
Also as most uart drivers don't need irq_update, make
it optional to implement this function in the driver.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
The member port of ethernet_context and the related APIs
net_eth_get_ptp_port/net_eth_set_ptp_port were actually
gPTP specific. The purpose was to store gPTP port number.
Let's rename port to gptp_port and define it under
CONFIG_NET_GPTP instead of CONFIG_NET_L2_PTP. And use
uint16_t for gPTP port number per IEEE 1588 standard.
This is very clear.
Dropped the APIs from ethernet, and would define public
gptp_get_port_number and gptp_set_port_number in gptp
stack instead.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
There was some misunderstanding of current GPTP_PORT_END definition.
GPTP_PORT_END was not the last gPTP port, but (GPTP_PORT_END - 1) was.
There were some wrong checking. For example,
for (port = GPTP_PORT_START; port <= GPTP_PORT_END; port++)
This patch is to make GPTP_PORT_END as the last gPTP port number to
avoid misunderstanding, and also to fix related checking.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Even for non-gPTP interface, current code was always getting
1 as gPTP port number, which is GPTP_PORT_START.
int port = net_eth_get_ptp_port(iface) + 1;
This patch is to fix this by directly setting gPTP port number
into ethernet_context.
Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
The when the reception stopped callback was called, we should
call bt_cap_handover_broadcast_reception_stopped and not
cap_handover_broadcast_audio_stopped, as we need to stop the
broadcast as a result of it, and not just delete it.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The multicast group join flag clearing on iface down, and then rejoining
on iface up was added so that MLD reports are sent on the interface when
it goes back up. This should not be the case though for interfaces with
disabled MLD.
Currently this was only partially handled, and with a wrong flag
(NET_IF_IPV6_NO_ND), i.e. the join flag was cleared on the iface down,
but it was not reenabled on iface up, if NET_IF_IPV6_NO_ND was set
(which is the case for OpenThread).
Therefore clean up the flag usage, use NET_IF_IPV6_NO_MLD to decide
whether to clear/rejoin the mcast group join flag, and use
NET_IF_IPV6_NO_ND specifically to decide whether to add multicast
addresses needed for Neighbor Discovery to the interface on iface up.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add a new Kconfig option WIFI_STA_AUTO_DHCPV4 to allow applications
to control whether DHCPv4 client should be automatically started by
the Wi-Fi driver or supplicant after STA connection is established.
This addresses the use case where applications need to switch between
static IP addressing and DHCP, or prefer to manually control when
the DHCP client starts.
When CONFIG_WIFI_STA_AUTO_DHCPV4=n, the application layer becomes
responsible for either manually starting the DHCPv4 client or
configuring a static IPv4 address after Wi-Fi connection is established.
The option defaults to 'y' to maintain backward compatibility with
existing behavior.
Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
Unify the helper text with other network shell commands so that
we can save some flash memory.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
ffa_create_top() was opening files with FS_O_CREATE | FS_O_WRITE
only, which caused host applications like 'cat' to fail with
Permission denied when trying to read the file through FUSE. This
is because FAT filesystem explicitly checks the READ flag before
allowing read access.
Fix by replacing FS_O_WRITE with FS_O_RDWR so the file is opened
with both read and write access.
Signed-off-by: Surya Prakash T <suryat@aerlync.com>
If CMUX is going to be shut down while in power-saving mode,
we need to wake-up before doing the state transitioning.
If we directly transition from STATE_POWERSAVE to
STATE_DISCONNECTING, the UART is not woken up and the
disconnect commands are not send.
Use is_connection() helper on both disconnect and connect APIs
to clean up the state check.
Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
Fix expressions where increment or decrement operators are combined
with other side effects in the same full expression, violating
MISRA-C Rule 13.3.
Separate the increment and decrement operations into standalone
statements to ensure each full expression contains at most one
side effect.
Assisted-by: GitHub Copilot
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add missing error checks for any function calls in the
affected files, as that is required by the Zephyr coding guidelines.
The call to bt_ots_client_register in mcc.c was moved to
avoid calling it mulitple times, causing it to fail if
bt_mcc_discover_mcs was called more than once.
Assisted-by: Copilot:claude-sonnet-4.6
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add a LOG_DBG for all aborts so that it is easier
to determine the exact reason for an aborted CAP
procedure.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Minor change to valid_unicast_to_broadcast_metadata to break
the loop earlier if the unique_metadata_cnt is already too
large.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
bt_avdtp_parse_capability_codec() returns immediately after parsing the
Media Codec service category, skipping any subsequent service categories
in the capability list. This causes the Delay Reporting service category
(0x08) to be missed when it appears after the Media Codec in a Set
Configuration command.
Fix by replacing 'return 0' with 'break' so the while loop continues
to parse remaining service categories. Also update the final return to
check whether a codec was actually found.
Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
Update the documentation for the uncast_x_complete callbacks
so that applications can better determine what `err` might be
and act according to the error.
It also makes the disconnect callback more unique, as well
as treating control point write rejects different from
invalid state changes.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The characteristic name and definitions in the TBS spec for
the values are "optional opcodes" instead of "support features".
Additionally, the field is 16-bit, instead of the current 8-bit
in the register parameters.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Use the PRIu64 macro from inttypes.h to format the stream ID,
which is of type uint64_t. This change resolves the -Wformat
warning on 64-bit platforms:
format '%llu' expects argument of type 'long long unsigned int',
but argument 6 has type 'uint64_t' {aka 'long unsigned int'}
Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>