This reverts commit 9401406e6a.
This patch was reverted due to regressions reported in #109814 (cached
timeseries data loss).
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Having an interface library named "mbedTLS" and the real library named
"mbedtls" (as provided by the Mbed TLS module) is misleading.
This commit replaces:
- mbedTLS -> mbedtls_iface for the CMake library. "mbedTLS" is still
available as alias to "mbedtls_iface" for backward
compatibility, but this should be removed in the future.
- mbedTLS -> Mbed TLS in comments and documentation.
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Fix uninitialized variable use reported by Valgrind. Could be a false
positive, as those arrays are filled in lwm2m_engine_get_binding() and
lwm2m_engine_get_queue_mode(), but as binding and queue buffers are
small just initialize them with 0's to satisfy Valgrind.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add optional DHCP option 114 (Captive-Portal Identity, RFC 8910) to the
Zephyr DHCPv4 server. When enabled, the server includes the option in
Offer and Acknowledgment messages when the client requests it via DHCP
option 55 (Parameter Request List), so clients can discover a captive
portal URI on isolated networks (e.g. SoftAP provisioning).
Introduce CONFIG_NET_DHCPV4_SERVER_OPTION_CAPTIVE_PORTAL to gate the
feature and CONFIG_NET_DHCPV4_SERVER_OPTION_CAPTIVE_PORTAL_URI for an
optional URI override. If the override string is empty, the server
builds http://<IPv4-on-DHCP-interface>/generate_204 from the address
stored in the server context when the server starts (ctx->server_addr).
Tested by building an application with
CONFIG_NET_DHCPV4_SERVER_OPTION_CAPTIVE_PORTAL=y and confirming DHCP
Offer/ACK include option 114 when listed in the client's parameter
request list on a SoftAP network.
Signed-off-by: Ricardo Tafas <ricardo.tafas@espressif.com>
Make sure network packet contains the network interface pointer
when IP packet is routed. Add tests that verify that interface
is always checked in routing.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The original VPN capability bit check was too strict and would
fail if the virtual interface had more capabilities configured.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The IP address parameter in the following functions
was changed to be "const struct net_in..."
net_route_ipv4_lookup()
net_route_ipv4_get_info()
net_route_ipv4_packet()
net_route_ipv6_lookup()
net_route_ipv6_get_info()
net_route_ipv6_packet()
net_ipv6_nbr_lookup()
This will make sure that the IP address cannot be changed by the
function.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Make the per-family unicast route-table options user visible and
separate them more clearly from packet forwarding.
Expose NET_IPV4_ROUTE and NET_IPV6_ROUTE as the route-table support
symbols used for static routes, shell route commands, and host-side
route selection. Rename NET_IPV4_ROUTING and NET_IPV6_ROUTING to
NET_IPV4_FORWARDING and NET_IPV6_FORWARDING so the forwarding options
describe router behavior only.
Keep the old routing symbols as deprecated compatibility aliases,
move orig_iface packet metadata behind an internal helper symbol, and
update route test configs to select the route-table options
explicitly. Also add migration-guide notes so out-of-tree users know
how the old and new symbols map.
Assisted-by: Copilot:GPT-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Allow IPv4 route entries to use 0.0.0.0/0 as an explicit default
route. The route core already supports prefix length 0, but the
IPv4-specific add path rejected the unspecified address outright.
Keep rejecting unspecified IPv4 route destinations for all non-zero
prefix lengths, and only accept 0.0.0.0 when the prefix length is 0.
Add regression coverage to verify that an explicit IPv4 default
route can be added, looked up, and returned through route info with
the configured nexthop.
Assisted-by: Copilot:GPT-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
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>
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>
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 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>
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>
When LCP receives a Configure-Request while in OPENED state
(peer-initiated renegotiation, RFC 1661 §4.2), the FSM core invokes
the LCP down callback (lcp_down). The previous implementation
called ppp_link_down(), which unconditionally set the PPP phase
to PPP_DEAD before lcp_down restored PPP_ESTABLISH. The
intermediate PPP_DEAD fired NET_EVENT_PPP_PHASE_DEAD; net_mgmt
subscribers (notably the modem cellular driver) treated it as link
loss and tore the carrier down even though LCP would have
renegotiated cleanly on its own.
ppp_change_phase() already detected the resulting NETWORK -> DEAD
transition as invalid via validate_phase_transition() but only
logged it.
Inline ppp_link_down() into lcp_down() and skip the intermediate
PPP_DEAD write: pick the final phase directly based on whether the
carrier is still up and LCP is still enabled. The end state matches
the previous implementation in every case; only the spurious DEAD
event between the two phase changes is removed.
ppp_link_down() had only this one caller and is therefore removed
from link.c along with its prototype in ppp_internal.h.
Also extend validate_phase_transition()'s rules table to cover the
transitions reachable through the new lcp_down:
- AUTH / NETWORK / RUNNING -> ESTABLISH: reachable when LCP
renegotiates and no NCP was OPENED at the time, so
ppp_network_all_down() does not transit the phase further.
- TERMINATE -> ESTABLISH: reachable when LCP renegotiates while
at least one NCP was OPENED. ppp_network_all_down() then
invokes the NCP cb.down callbacks, which through
ppp_network_down() decrement network_protos_up to zero and
write PPP_TERMINATE. The final change_phase(PPP_ESTABLISH) in
lcp_down is then observed as TERMINATE -> ESTABLISH.
- AUTH / NETWORK / RUNNING -> DEAD: reachable when carrier is
lost or LCP is disabled with no NCP OPENED. (When at least one
NCP was OPENED the path goes via TERMINATE -> DEAD which was
already valid; the rule is added defensively for the no-NCP
case where no intermediate TERMINATE write occurs.)
Empirically observed and verified on a Quectel BG770S over 3GPP
CMUX: after the initial LCP completes and IPCP starts, the modem
occasionally sends a fresh LCP Configure-Request mid-session;
without this fix the cellular driver tore the connection down on
the spurious PHASE_DEAD event.
Signed-off-by: Petr Hlineny <development@hlineny.cz>
Assisted-by: Claude Opus 4.7 <noreply@anthropic.com>
dns_resolve_reconfigure() skips NET_EVENT_DNS_SERVER_ADD when the new
server set is identical to the existing one, to avoid cancelling
in-flight queries on DHCP retransmit and IPv6 RA. The event is therefore
a per-slot delta, not a configuration-refresh signal: consumers that
wait on it as a "DNS is now configured" indicator after a network event
miss every reconfigure that re-applies the same servers.
Add NET_EVENT_DNS_SERVERS_RECONFIGURED, raised on every successful
reconfigure including the deduplicated case.
Signed-off-by: Paulo Santos <paulo.santos-ext@hexagon.com>
Use the same size for the URI buffer in the FW object implementation as
in the FW pull download helper module. That way, if the server writes
too long URI to handle in the FW pull mode, it'll get an error response
immediately instead of failing at firmware download start.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Verify the URI length provided to lwm2m_pull_context_start_transfer()
before use, otherwise in case the URI string is longer than the buffer,
only part of it was copied w/o NULL terminator, which could lead to
out-of-bound reads and other undefined behavior.
As the string length is now validated, just use strcpy() instead of
memcpy(), no need to copy the whole buffer.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Return an error when an SO_TIMESTAMPING control message is present but
too short to contain struct net_ptp_time. Keep the existing fallback
behavior for receive paths where no timestamp control message is present.
This makes malformed timestamp ancillary data explicit instead of hiding
it behind the missing-timestamp fallback path, and adds L2/IPv4 regression
coverage for both malformed and absent timestamp control messages.
Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
move qemu network interface selection, because it fits better in
cmake/emu/qemu.cmake than in cmake/modules/kernel.cmake.
It is also put at the end because for usb network cards, the usb bus
must be created before the network interface can be added. Also true
for other network cards on buses. Currently we don't have usb network
cards in zephyr, but it is better to be prepared for that.
Also use the separate netdev and device option.
The combined command line option didn't work for "usb-net" for example.
For the riscv qemu the -nic option is broken acording to the qemu issue
(https://gitlab.com/qemu-project/qemu/-/work_items/691), so we need to
use the -netdev and -device options.
Because of the change to -netdev and -device options, we need a new
Kconfig option to specify the extra arguments for the network device,
so we add NET_QEMU_DEVICE_EXTRA_ARGS option.
this can be used to customise the network device, like the mac address,
or more device specific options like setting f.e. the addresss/slot of
a pci card.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>