match_path_uri() compares a resource path against the URI carried in a
Uri-Query option. That URI points straight into the received packet
buffer and is not NUL terminated, but the inner path character loop
advanced k for every path character without ever checking it against
len. A query such as "?href=/foob", aimed at an application that
registers a "foobar" resource, therefore walked past the end of the
option value, and past the end of the packet buffer when the option is
the last thing in the packet.
The over-read cannot change the result: returning true requires either
k == len or k + 1 == len, both in bounds, so bytes beyond the option
only ever steer the loop towards the next candidate path. The impact is
the undefined behaviour and the fault it may cause, not a matching
error or an information leak back to the requester.
Add a "k >= len" guard at the top of the inner loop. The check has to
stay inside the loop: hoisting it into a "plen > len - i" test in front
of the loop would also reject a trailing wildcard, so that "/ab*" would
stop matching a path such as "abcdefgh".
Extend test_match_path_uri with a URI built without a NUL terminator,
so that the over-read is trapped when the suite is run under a
sanitizer, and with a URI whose length is shorter than its buffer to
cover the guard on a path that does match.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Renames functions to have raw in the names, this helps when
debugging with both raw and raw dummy transports enabled, as
without the change the debugger will show the names as the same
Signed-off-by: Jamie McCrae <spam@helper3000.net>
Add receive support for Protocol-Field-Compression and
Address-and-Control-Field-Compression.
ppp_l2.c accepts a 1-octet Protocol field: PPP protocol numbers have
bit 0 of the high octet clear, so an odd first byte is unambiguously a
compressed single octet; pull 1 vs 2 bytes accordingly.
modem_ppp.c: in the HDLC HDR_FF state a non-0xFF byte means the frame
omits the FF 03 header (ACFC); start the frame and treat the byte as
the first Protocol octet instead of dropping it. The first octet may
arrive HDLC-escaped (e.g. the 0x00 high octet of the IP protocol
0x0021, sent as 7D 20), so an escape in HDR_FF moves to the new
HDR_FF_UNESCAPE state which unescapes the octet before starting the
frame; an octet that unescapes to 0xFF is an escaped Address field and
falls back to normal FF 03 header processing.
The compressed forms are accepted unconditionally, independent of LCP
negotiation. RFC 1661 only requires accepting the compressed form once
the option has been negotiated, and forbids transmitting it otherwise;
transmit therefore always stays uncompressed. Unconditional accept is
needed for peers that compress unilaterally: a usbmon capture of the
Neoway N717 shows it sending PFC-compressed IP data frames
(FF 03 21 45 ...) even after pppd rejected the option, so negotiation
completes over full-form LCP/IPCP and the data frames are then
dropped. Linux pppd likewise accepts compressed frames regardless of
negotiation.
Signed-off-by: Aleksandr Senin <al@meshium.net>
Change net_context.local from a struct net_sockaddr_ptr, which only
held pointers into the interface's address storage, to an inline
address that owns a copy of the bound local address, like
net_context.remote.
The field is stored in a union that exposes both a struct net_sockaddr,
used for all accesses, and a struct net_sockaddr_storage alias. In
Zephyr the two types are identical in size and layout, so the union
costs nothing and simply makes the storage-typed view available without
forcing casts on every accessor.
The old multicast pointer aliased a net_if_mcast_addr slot that is
recycled when an interface goes down and back up. After such a cycle the
stored pointer silently repointed the bound group (e.g. ff02::fb ->
ff02::1), which broke the mDNS responder's ability to recover after
interface loss.
The AF_PACKET link-layer address is now copied inline as well. Since the
inline copy no longer auto-tracks the interface, net_context_recv()
re-reads the link address live from the interface (its length can change
at runtime, e.g. 802.15.4 switching between short and extended
addressing).
Assisted-by: Cursor:Claude Opus 4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Introduce a NET_CONTEXT_LOCAL_ADDR_SET flag and a matching
net_context_is_local_addr_set() helper to track whether a local address
has been bound to a network context, instead of relying on the local
address pointer in net_context.local being non-NULL.
The flag is set in net_context_bind() for each supported address family
(IPv6, IPv4, AF_PACKET and CAN) and is checked in bind_default(), the
port-reuse scan in check_used_port(), net_context_connect(),
recv_dgram(), net_tcp_accept(), zsock_getsockname() and the net shell,
replacing the previous pointer-is-non-NULL tests.
Assisted-by: Cursor:Claude Opus 4.8
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
net_pkt_cursor_operate() re-derived the overwrite/append state of the
operation and the fragment limits several times for every processed
fragment, through pkt_cursor_advance() and pkt_cursor_update() which
each recompute them. Since packet payloads are split into many small
fragments (CONFIG_NET_BUF_DATA_SIZE is 128 bytes by default), this
bookkeeping runs a dozen times for a single MTU-sized read or write
and is pure overhead on every user-to-packet copy in the stack.
Hoist the loop-invariant overwrite/append state out of the loop,
compute the fragment limit once per fragment, and update the cursor
inline using the already computed values instead of re-deriving them
in pkt_cursor_update().
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The network shell has no mandatory support for IPv4 IGMP.
Remove the hard dependency on IPv4 IGMP when CONFIG_NET_SHELL is enabled.
Applications that use IPv4 multicast group join/leave from the
network shell must now enable CONFIG_NET_IPV4_IGMP explicitly.
Signed-off-by: Rui Sousa <rui.sousa@nxp.com>
Handle the case where put_string() is called with an empty buffer.
This prevents malformed CoAP packets from being generated.
Signed-off-by: Diogo Sousa <sousadiogo7@gmail.com>
When replying with RST to an incoming segment without ACK, the ACK
field must be set to SEG.SEQ + SEG.LEN per RFC 9293. SEG.LEN includes
both SYN and FIN because they occupy sequence space.
net_tcp_reply_rst() already incremented ACK for SYN, but not for FIN.
For a FIN-only segment, this produced ACK=SEG.SEQ instead of the
required ACK=SEG.SEQ+1, making the RST non-compliant and potentially
ignored by strict TCP peers.
Add the missing FIN increment so RST ACK calculation matches the RFC.
Signed-off-by: Swamidas Nampalli <Swami.Das@silabs.com>
The IPC backend receive callback logged msg->channel_name with a plain
%s on the recv_cb error path. That frame originates from a peer domain
and, precisely because recv_cb rejected it, channel_name[] is not
guaranteed to be NUL-terminated.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Move the declaration of arch_page_phys_get() from the internal
kernel_arch_interface.h to the public arch_interface.h, under the
existing arch-mmu group, so that drivers and subsystems can query the
physical address of an already-mapped virtual page without depending
on private kernel headers.
The declaration stays unconditional, as it was in the internal header:
callers such as munmap() in subsys/portability/posix/options/mmap.c
reference the function even when CONFIG_MMU is disabled (guarded only
by a runtime IS_ENABLED() check), so hiding the declaration behind
CONFIG_MMU breaks the build on MMU-less platforms.
Clean up the existing users that resorted to including the internal
header or to extern declarations:
- subsys/portability/posix/options/mmap.c
- subsys/portability/posix/options/shm.c
- subsys/portability/cmsis_rtos_v1/cmsis_thread.c
Fixes#113314
Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
ipv4_route_packet() passes a NULL iface to net_if_ipv4_addr_onlink(),
which per its documented contract must then search all interfaces for
the best matching subnet (as the IPv6 variant does). The IPv4
implementation instead returned false whenever the iface was NULL and
otherwise only ever inspected the single interface passed in, so the
on-link routing branch was effectively dead: destinations reachable
on-link but without a routing-table entry were dropped. This shows up
when NAT is enabled and the packet is routed across interfaces.
net_route_ipv4_get_info() relies on the same NULL "search all
interfaces" behavior to short-circuit on-link destinations so they are
delivered directly instead of via the default gateway, and was broken
for the same reason.
Align net_if_ipv4_addr_onlink() with the IPv6 implementation and its
documentation: iterate over all interfaces when no specific interface is
requested, restrict to a single interface only when one is provided, and
tolerate a NULL iface pointer (net_route_ipv4_get_info() calls it that
way).
Assisted-by: Claude:opus-4.8
Signed-off-by: Yasas Kahawala <yasasravinda@hotmail.com>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Avoid memmove() when net_pkt_pull() removes data from the start of a
fragment. Advance the data pointer instead, making the operation O(1).
Document that pull and compaction do not preserve packet storage
layout.
Assisted-by: Claude:fable-5
Assisted-by: Codex:sol-5.6
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
A net_buf fragment is a storage detail and must not become an implicit
MAC frame boundary. When 6LoWPAN fragmentation is not required,
ieee802154_send() currently sends one frame per net_buf.
Linearize the complete packet chain into the existing MTU-sized frame
buffer and transmit it once. Validate the total frame length before
transmission, and update the 6LoWPAN test to model an unfragmented
packet as one wire frame.
Assisted-by: Codex:sol-5.6
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The modem chat module typically wants to send a command and a delimiter
per request. As the pipe API now supports sending multiple buffers in a
single call, use that API.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Add an optional extension function for pipe backends to support sending
multiple data buffers in a single call. The primary use case for this
change is the modem chat module, which typically is sending both a
command buffer and a delimiter buffer. Merging both of these into a
single API call improves the usage efficiency of the comms medium, as
transaction setup costs are not zero.
Signed-off-by: Jordan Yates <jordan@embeint.com>
The "send" command of the CAN shell allows to send also CAN FD frames,
which can contain up to 64 bytes of data.
Increase the shell argc count to be able to send a fully complete CAN FD
frame with all the payload.
The exact count of argc is determined by the following command, which
uses extended ID, enables CAN FD and bit rate switch, and specify the
maximum payload size :
can send can0 -e -f -b 12345678 00 01 02 03 04 05 06 07 08 09 10 11 12 13
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
When registering a resolver socket, the dispatcher may reject it with
-EALREADY because it already has a registration for the same local
port. The resolver treats this as benign and skips it, but if two
distinct resolver sockets end up sharing a local port (for example when
a bound ephemeral port is not resolved and both look like port 0), the
later socket is never dispatched and replies from that server are
silently dropped.
Emit a debug message in that path so such a misconfiguration is
diagnosable instead of failing silently.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Store the OS assigned port in the DNS context so that multiple
dispatcher registrations do not treat all sockets as port 0.
Assisted-by: GPT-5.5
Signed-off-by: Jordan Yates <jordan@embeint.com>
The resolver sockets are created with zsock_socket() and are never
connect()ed, so the kernel does not filter datagrams by source. Replies
are matched to a pending query only by the 16-bit DNS id and the query
hash. With server fallback now keeping several server sockets open and
extending the time a query slot stays active, any open server socket
could be used to inject a forged reply that merely matches that id and
hash, widening the off-path spoofing window.
Track which configured server delivered each reply and drop it unless
that server was actually queried for the matching slot, using the new
per-query "sent" bitset. Late replies from a server we did query (for
example after a timeout fallback) are still accepted; multicast mDNS and
LLMNR responders, which legitimately answer from multiple hosts, are
exempt. dispatcher_cb now also bounds the computed server index before
indexing the server array.
dns_validate_msg() / dns_read() gain a recv_server_idx argument; passing
-1 disables the check, which the dns_packet unit tests use as they call
dns_validate_msg() directly without a server socket.
Add dns_resolve regression tests for both server-selection modes. In
sequential mode a reply on a not-yet-queried server is injected; in
query-all mode one server is removed from the eligible set and a reply
is injected on it. Both assert the reply is dropped while a reply from a
queried server still completes the query. Both tests fail without this
change and pass with it.
Tested with twister on native_sim: tests/net/lib/dns_resolve (all
scenarios) and tests/net/lib/dns_packet (303/303 cases pass).
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Treat .local names as mDNS queries and single-label names as LLMNR
queries when deciding how to send resolver requests.
This keeps multicast lookups to a single send even when
CONFIG_DNS_RESOLVER_QUERY_ALL_AVAILABLE_SERVERS is enabled, while
preserving normal unicast DNS parallel sends across configured DNS
servers.
Update the LLMNR Kconfig help to describe the actual behavior and add
tests covering mDNS single-send, LLMNR single-send, and normal DNS
parallel sends with LLMNR enabled.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Track per-query DNS server state so unicast lookups can advance to the
next configured server when one times out or returns a failure.
Keep query-all behavior unchanged by still accepting the first
successful response when CONFIG_DNS_RESOLVER_QUERY_ALL_AVAILABLE_SERVERS
is enabled.
Scale the per-query server tracking with DNS_RESOLVER_MAX_POLL and make
the default additional buffer count follow DNS_RESOLVER_MAX_SERVERS so
the resolver has enough buffers for concurrent server connections.
This improves getaddrinfo() robustness when one configured DNS server is
down, unresponsive, or replies without usable answers.
Assisted-by: Copilot:gpt-5.4
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The relative card address is a 16-bit value. If bit 15 is set,
`relative_addr << 16U` promotes to a signed int before the shift,
which overflows and would be trapped by the undefined behavior sanitizer.
Signed-off-by: Egill Sigurdur <egill@egill.xyz>
With timeouts that do not divide evenly by the tick, because of flooring
when converting to ticks, there is a left over time in which the sendto
function would k_poll with a 0 timeout, which would return
immediately, and result in k_poll being called right again.
Effectively busy wait looping until the left time is indeed 0.
Let's avoid this busy waiting by rounding up/ceiling the numberof ms to
wait.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
With timeouts that do not divide evenly by the tick, because of flooring
when converting to ticks, there is a left over time in which the send/recv
functions would zsock_poll with a 0 timeout, which would return
immediately, and result in zsock_poll being called right again.
Effectively busy wait looping until the timeout is indeed 0.
Let's avoid this busy waiting by rounding up/ceiling the numberof ms to
wait.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Building on the build-time interface policy, add a runtime API so the
application can turn the mDNS responder on or off for a specific network
interface after boot:
int mdns_responder_enable_iface(struct net_if *iface);
int mdns_responder_disable_iface(struct net_if *iface);
The functions are gated by the new
CONFIG_MDNS_RESPONDER_RUNTIME_IFACE_CONTROL option; when it is not set,
inline stubs return -ENOTSUP. A per-interface runtime override takes
precedence over the build-time policy, so an interface excluded by the
policy can still be enabled once its hardware is ready, and an interface
the policy would enable can be turned off.
The same mdns_iface_is_enabled() predicate now consults the runtime
state first and falls back to the policy. Changing the state rebuilds
the listeners: the responder tears down its listener sockets and leaves
the mDNS multicast groups, then re-runs the existing setup path which
recreates sockets and rejoins the groups only on the interfaces that are
still enabled. This reuses init_listener() (and pre_init_listener() when
probing is enabled) rather than duplicating the per-interface setup, and
is serialized with a mutex. Rebuilds are deferred until the initial
listener setup has run.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
By default the mDNS responder attaches to every network interface in
the system. On multi-interface devices this is not always desirable:
some interfaces have hardware that is not ready when the responder
initializes (leading to boot-time socket allocation failures), and
secondary interfaces often have no need for local service discovery
and should not spend a socket and multicast membership on it.
Add a build-time interface policy so the application can restrict
where the responder operates:
CONFIG_MDNS_RESPONDER_IFACE_POLICY = ALL (default) | ALLOWLIST |
DENYLIST
CONFIG_MDNS_RESPONDER_IFACE_LIST = comma separated interface names
Interface names are matched instead of interface indexes because the
indexes can change with configuration. The non-default policies select
NET_INTERFACE_NAME so name lookup is always available.
A single mdns_iface_is_enabled() predicate consults the policy and is
checked at every point that binds the responder to an interface:
listener socket creation, the IGMP/MLD multicast joins, the probe
pre-init contexts, and the interface/address management event handlers.
Disabled interfaces therefore never get a socket, never join the mDNS
groups, and never schedule probing or recovery rejoins. The default
ALL policy keeps the previous behavior.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Instead of manually defining a variable for the compatible's name, use
the one that gets autogenerated upon build.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Instead of manually defining a variable for the compatible's name, use
the one that gets autogenerated upon build.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Starting from commit 7710704 ("net: core: Initialize ARP during network
initialization once only"), the net_arp_init() is called once during
net_post_init. This means we don't need to set the init flag any more.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
(cte_types & A) || (cte_types & B) is equivalent to
cte_types & (A | B). Collapse the BT_HCI_LE_AOD_CTE_RSP_1US / _2US test
into a single masked check. No change in behavior.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
(keys->flags & A) || (keys->flags & B) is equivalent to
keys->flags & (A | B). Collapse the BT_KEYS_OOB / BT_KEYS_SC test into a
single masked check.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Replace hardcoded 0x8000 base address values with
the CONFIG_LOG_FRONTEND_STMESP_TURBO_LOG_BASE
configuration parameter. This parameter was previously
defined but never used. Using it makes
the code more configurable and allows the base address
to be adjusted via kconfig without
modifying source code.
Signed-off-by: Alejandro Lara Raigada <Alejandro.Lararaigada@analog.com>
Without optimizations the compiler does not follow how addr may be used,
only that it passed to zsoc_accept. And warns that it may be used
unitialized. Let's initialize it to zero to silence this warning.
If optimizations are used, the compiler should anyhow drop the
initialization.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Add CONFIG_TASK_WDT_HW_FALLBACK_PAUSE_HALTED_BY_DBG Kconfig option to
control whether the hardware fallback watchdog is paused when the system
is halted by the debugger. The option is enabled by default to preserve
the previous behavior.
Previously, WDT_OPT_PAUSE_HALTED_BY_DBG was unconditionally passed to
wdt_setup(), which could cause issues on hardware watchdogs that do not
support this option. The flag is now conditionally compiled in, guarded
by the new Kconfig symbol.
Signed-off-by: Łukasz Stępnicki <lukasz.stepnicki@nordicsemi.no>
Apply the default pinctrl state during PM_DEVICE_ACTION_RESUME to restore
normal SHI operation.
Apply the sleep pinctrl state during PM_DEVICE_ACTION_SUSPEND to disable
the SHI interface pins and prevent leakage.
This lets board/shim code control the pin state purely via
pm_device_runtime_get()/put().
Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
build_client_hello() only verified that the output buffer was at least
256 bytes before starting to serialize the ClientHello. The fixed
prologue fits in that budget, but the variable-length extensions
(key_share, ALPN, quic_transport_parameters and the pre_shared_key
block) as well as the fixed extensions that follow a large SNI can still
run past the end of the buffer, corrupting adjacent memory.
Add a bounds check in front of every remaining extension write so the
function returns -ENOBUFS instead of overflowing when the caller's
buffer is too small. The checks mirror the existing SNI guard: compute
the number of bytes about to be written and compare against buf_size.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
TLS handshake failures in the CRYPTO frame path surfaced as a generic
FRAME_ENCODING_ERROR (or no CONNECTION_CLOSE at all), giving a standard
QUIC peer no useful reason for the failure.
Map the errno returned by the handshake/certificate processing to the
matching TLS alert in a 0x0100 + alert CONNECTION_CLOSE (RFC 9001
Section 4.8): bad_certificate, decrypt_error, no_application_protocol,
handshake_failure, internal_error and decode_error. -EPROTO (CRYPTO
overlap / prohibited KeyUpdate) stays a transport PROTOCOL_VIOLATION and
-ENOMEM stays CRYPTO_BUFFER_EXCEEDED.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>