If a ethernet driver implements get_ptp_clock
and returns a non null value, we can assume it
supports ptp.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Use %u instead of %d for validated_plpmtu and age and cast
the values to unsigned int to avoid producing incorrect printout
and possible warnings from toolchains.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
When CONFIG_MULTITHREADING=n ztest_test_skip is not able to terminate
test execution like in thread mode where thread can be aborted.
Add return after calling ztest_test_skip() in Z_TEST_SKIP_IFDEF and
Z_TEST_SKIP_IFNDEF so it could be using in configurations where
multithreading is disabled.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Add a bridge MAC address mode that builds the interface address from a
configured five-octet prefix and the bridge index. This allows users to
keep bridge MAC addresses stable across reboots while choosing the OUI or
local prefix used by their deployment.
Validate the configured prefix before parsing it, fall back to a random
address if it is invalid, and cover the new mode in the bridge tests.
Assisted-by: Cursor:GPT-5.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
A bridge interface is assigned a random locally administered MAC address
at init, regenerated on every boot. Since the bridge can own an IP
address and terminate/originate traffic, peers cache its MAC in their
ARP/neighbor tables; a new address after each reboot leaves those caches
pointing at a stale MAC until they age out.
Add a choice to select the MAC address source:
- NET_ETHERNET_BRIDGE_RANDOM_MAC (default): the existing random
per-boot behavior.
- NET_ETHERNET_BRIDGE_UNIQUE_MAC: derive a stable address from the
hardware device id (depends on HWINFO) so it stays the same across
reboots. The bridge index is mixed in so multiple bridge interfaces
get distinct addresses, and it falls back to a random address if no
device id is available.
For a fully custom address the application can still call
net_if_set_link_addr() on the bridge while it is down, as bridge
interfaces do not auto-start.
Add a net.eth_bridge.ip.unique_mac test scenario so CI builds and runs
the bridge suite under the derived-MAC path, and assert the bridge link
address is a locally administered unicast MAC.
Tested on native_sim with tests/net/bridge.
Assisted-by: Claude:Opus 4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The bridge interface can own an IP address and therefore terminate and
originate traffic of its own, acting as an Ethernet endpoint. It was
however given a link address of length sizeof(addr), i.e.
NET_LINK_ADDR_MAX_LENGTH, with type NET_LINK_UNKNOWN.
NET_LINK_ADDR_MAX_LENGTH is 8 when another L2 such as IEEE 802.15.4 or
PPP, or a custom link address length, is enabled. In that case the
bridge link address is 8 bytes. A locally destined unicast frame (for
example an ARP reply) carries a 6-byte Ethernet destination, and the
Ethernet receive path compares it against the interface link address
with net_linkaddr_cmp(), which requires equal lengths. The 8-vs-6
mismatch made the frame be dropped as "not for me", so ARP replies
never reached L3 and address resolution never completed. This also
defeats the locally-originated TX resolution added earlier, since the
resolving ARP reply is dropped.
Set the bridge link address to a proper 6-byte Ethernet MAC with type
NET_LINK_ETHERNET so the comparison succeeds. A plain Ethernet build
(NET_LINK_ADDR_MAX_LENGTH == 6) was unaffected, which is why this went
unnoticed.
Tested on native_sim with the tests/net/bridge regression tests,
including a configuration with CONFIG_NET_LINK_ADDR_CUSTOM_LENGTH=8.
Assisted-by: Claude:Opus 4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
When the bridge interface owns an IPv4 address it can originate traffic
of its own (for example a TCP server bound to the bridge). Such locally
originated IPv4 packets were flooded to the member ports with the family
reset to AF_UNSPEC, which disables the ARP step in the Ethernet L2 send
routine. The destination link address was therefore left unresolved and
defaulted to broadcast, so e.g. a TCP SYN-ACK went out to
ff:ff:ff:ff:ff:ff and RFC-compliant peers dropped it.
The member ports cannot resolve on the bridge's behalf either: an ARP
reply is addressed to the bridge link address, so a member port would
drop it as "not for me". IPv6 is unaffected as its neighbor is resolved
in net_ipv6_prepare_for_send() before the packet reaches this layer.
Resolve the destination on the bridge interface, where the ARP cache is
populated, before flooding to the member ports. On a cache miss the ARP
request is flooded and the packet held until the reply resolves it.
Forwarded (L2 bridged) frames already carry a complete header and are
left untouched.
Tested on native_sim with the tests/net/bridge regression tests.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The relocation bounds check read the target section header from
ext->sect_hdrs on every loop iteration. The check itself never
fails for valid extensions, but the per-iteration read enlarged
the relocation loop enough to shift runtime layout and trip an
execute fault in loaded extensions on arm cortex-r5 with the
power-of-two MPU, hanging the llext readonly_mpu suite. Read
the size into a local once per relocation section, which is
loop-invariant, and compare against that instead.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
A label at the end of a block is, in principle an extension.
clang warns about this even in switch defaults, so let's just
add a break in that final empty case.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
A relocation writes at r_offset within its target section, but the
general relocation path applied it without checking that the offset
falls inside the section. A crafted r_offset past the section end made
the loader write outside the section's loaded memory, corrupting
adjacent state. Reject any relocation whose offset is beyond the target
section size before it is applied. Valid modules are unaffected; only
malformed ones are refused.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
On RISC-V with userspace, an extension is mapped into a memory domain
as PMP-protected regions. PMP requires region size and start to be
aligned to the PMP granularity, but the loader sized extension regions
to the raw ELF section size, so adding the region to a domain asserted
on a misaligned size and the extension could not run in a user-mode
thread.
Round the allocated region size and alignment up to the PMP
granularity on RISC-V, the same way the Arm and ARC MPU paths already
round to their alignment. With this, an extension loaded into its own
memory domain runs as an isolated user-mode thread and calls syscalls.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
z_vrfy_rtio_sqe_cancel() forwarded a user-supplied sqe pointer directly
to z_impl_rtio_sqe_cancel(), which immediately uses CONTAINER_OF on it
and then walks the SQE chain, writing the RTIO_SQE_CANCELED flag. A
forged pointer therefore yields an arbitrary kernel write primitive.
A K_SYSCALL_MEMORY_READ check is the wrong guard: the cancel handle is
an opaque token returned by rtio_sqe_copy_in_get_handles() that points
into a kernel-resident SQE pool (RTIO_SQE_MEM is plain static, not in
rtio_partition), so user mode never has memory-region read access to it.
That check rejected every legitimate cancel from user mode.
Instead, bound the handle against the actual rtio_sqe_pool arrays: the
CONTAINER_OF'd address must fall inside one pool's storage and be element
aligned. This preserves the security guarantee while letting valid
handles through.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
z_vrfy_rtio_sqe_copy_in_get_handles() wrote the acquired (kernel) SQE
pointer into the user-supplied `handle` out-parameter without validating
it. A user thread could pass a kernel address and obtain an arbitrary
kernel write.
Validate handle with K_SYSCALL_MEMORY_WRITE before the store.
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
ZBus has been proposed elsewhere as a candidate for passing messages
between dynamic software modules, such as those loaded by LLEXT. When
multiple such modules are loaded, it is expected that one dynamic module
may want to consume messages from a different dynamic module.
Currently, this paradim is limited by the requirement that ZBus channels
must exist at compile-time in order to be placed in the correct linker
section for `zbus_chan_from_name` and `zbus_chan_from_id`, which is the
way dynamic modules need to discover channels at runtime. It therefore
follows that for these dynamic modules to work, the channel they will
use to communicate must be known statically at compile-time. This is
undesirable.
This commit adds the ability for ZBus channels to be added to and
removed from the ZBus system at runtime. This allows one dynamic module
to `malloc` a `zbus_runtime_channel` object and message storage,
register it to ZBus, and have a second dynamic module read from the
runtime channel, without the original application needing to know such a
channel will exist at compile-time.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Add a transport interface using the raw udp callback instead
of sockets. This decreases overhead and thus increases the
speed of the RTP stack
Signed-off-by: Jaro Van Landschoot <jaro.vanlandschoot@basalte.be>
As part of 93511748ee
this function was (partially) moved to be in drivers/video/video_common.c
and is used in that file, while it stopped being used from this file.
So, after this change, this static inline was left as a duplicate of that
other one, and because of being static just dead code.
Let's just remove this left over.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Just to be consistent, add [EXPERIMENTAL] to the option
name string. This helps searching the experimental options
and makes it easier to spot those in menuconfig.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The Ethernet gPTP support has been there for a long time
so remove the experimental status from it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Socket object core support has been there for a long time
so remove the experimental status from it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Both CoAP client and server support has been there for a long time
so remove the experimental status from them.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
SocketCAN support has been there for a long time
so remove the experimental status from it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
IPv4 autoconfiguration support has been there for a long time
so remove the experimental status from it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Variable size buffer support has been there for a long time and
is in production use so remove the experimental status from it.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
net_if_ipv6_calc_reachable_time() scales the base reachable time by the
RFC 4861 random factor (up to 3/2), so a large value stored through the
public net_if_ipv6_set_base_reachable_time() would overflow the uint32_t
intermediate. The Router Advertisement path already bounds the value, but
a direct API caller was unchecked.
Introduce NET_IPV6_MAX_REACHABLE_TIME (the RFC 4861 6.2.1 AdvReachableTime
limit) as the shared upper bound, clamp the setter to it, and make the RA
path reference the same constant.
Assisted-by: Claude:Opus 4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
FUSE request/response buffers were passed to the virtqueue straight from
the caller's stack. A thread stack is not guaranteed to be physically
addressable via k_mem_phys_addr(), so transfers issued from a non-main
thread could hand the device a bogus physical address and come back with
a zero-length reply (seen as FUSE_INIT returning length 0).
Bounce each FUSE transfer through a heap buffer allocated with k_malloc,
which is DMA-reachable, and tolerate a short FUSE_DESTROY reply.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Compare against the buffer size in bytes and reserve room for the local
clockIdentity that is appended afterwards, and fix the swapped NET_ERR
arguments.
Assisted-by: Claude:opus-4.8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
gptp_mi_qualify_announce() iterated announce->tlv.path_sequence up to
(steps_removed + 1) entries — with steps_removed potentially up to 254
— without validating against the actual TLV wire length. Since
path_sequence is a flexible-member array in the wire format, this could
read past the TLV data.
Compute the actual number of entries from tlv.len and reject the announce
when steps_removed + 1 exceeds that count.
Assisted-by: Claude Code:claude-opus-4.8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
gptp_handle_msg() dereferenced hdr = GPTP_HDR(pkt) and read
hdr->message_type before checking that the packet is at least
sizeof(struct gptp_hdr) bytes, allowing a short Ethernet frame to
trigger an out-of-bounds read.
Assisted-by: Claude Code:claude-opus-4.8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Make AF_PACKET SO_TIMESTAMPING reporting depend only on
net_pkt_is_rx_timestamping(). This removes the timestamp-value heuristic
and makes the RX timestamp marker the single source of truth for whether
packet timestamp control data is valid.
Update in-tree Ethernet drivers that store RX timestamps to set the marker
before handing packets to the stack, and document the migration requirement
for out-of-tree drivers. Keep test coverage for the unmarked-packet case so
unmarked timestamps are not reported to socket applications.
Signed-off-by: Philipp Steiner <philipp.steiner1987@gmail.com>
Noticed this issue when compiling for 64 bit target.
subsys/net/lib/ssh/ssh_kex_ecdh.c: In function 'gen_shared_secret':
include/zephyr/net/net_log.h:27:35: warning: format '%zu' expects \
argument of type 'size_t', but argument 3 has type 'uint32_t'
Cast to size_t to avoid the warning.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Add ssh_channel_close() to close a channel. The CHANNEL_CLOSE message
is sent and the channel freed from the transport thread. A received
CHANNEL_CLOSE for an already freed channel is now ignored instead of
tearing down the transport, so that a locally initiated close works.
Assisted-by: Claude:opus-4.8
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Allow user to register ssh transport callbacks that will
be called when those events happen.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
RFC 4443 section 2.4 says an ICMPv6 error must not be sent if the
packet that caused it was itself an ICMPv6 error (e.1) or a redirect
message (e.2). The existing check only excluded error types (type <
128), so a redirect (type 137) slipped through.
Add the redirect type and exclude it in net_icmpv6_send_error().
Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
RFC 4443 section 2.4 says an ICMPv6 error must not be sent if the
triggering packet's source doesn't identify a single node (e.6), or
if the packet was sent to a multicast destination (e.3), except for
Packet Too Big and Parameter Problem Code 2.
Add both checks to net_icmpv6_send_error().
Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
Now that controls are imported, convert them to be API wrappers instead of
using DEVICE_API_GET(). Except for video_auto_cluster_ctrl() so that it
can check if the get_volatile_ctrl() API is supported or not.
Signed-off-by: Josuah Demangeon <me@josuah.net>
Move most of the shared sources from drivers/video/ into subsys/video/.
The content left in drivers/video/ is now only used by drivers, or
drivers themselves.
Signed-off-by: Josuah Demangeon <me@josuah.net>
Move all the content of <zephyr/drivers/video.h> to a separate include
file in <zephyr/video/video.h> except driver entry points, all with a
video_drivers_... prefix.
Video control IDs are now in <zephyr/video/controls.h> and included
from both <zephyr/drivers/video.h> and <zephyr/video/video.h>.
Video format FourCCs are now in <zephyr/video/formats.h> and included
from both <zephyr/drivers/video.h> and <zephyr/video/video.h>.
As a side effect, introduce a video subsystem in MAINTAINERS.yml
Signed-off-by: Josuah Demangeon <me@josuah.net>
Change all four CONFIG_NET_PPP references (two #if guards, one
that is the symbol that actually controls whether PPP support
is compiled in.
Signed-off-by: Arya Khochare <aryakhochare@gmail.com>
The idle-hook backend closed its idle window from the idle-exit hook that
the architecture runs after the wait instruction. That only works on
architectures which wait with interrupts locked (Arm, RISC-V): the wait
returns without servicing the interrupt, so the exit hook runs before any
ISR.
Architectures that wait with interrupts enabled (x86 "sti; hlt", Xtensa
"waiti 0") let the wake-up ISR run first, and it can reschedule away from
the idle thread. The idle-exit hook is then deferred until the idle thread
is next scheduled, long after idle actually ended, so the busy time in
between is attributed to idle. Measured on qemu_xtensa, a window that was
100% idle reported a load of 1000 per mille instead of 0.
Make closing the window idempotent and also drive it from the ISR entry
hook, sys_trace_isr_enter().
The first interrupt after the CPU went idle is exactly the instant idle
ended, so closing there is accurate; a deferred idle-exit hook then finds
the window already closed and does nothing. Interrupts that did not
interrupt idle only pay one flag test.
Architectures that wait with interrupts locked are unaffected: their
idle-exit hook still closes the window before any ISR runs.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The two CPU load modules that previously lived side by side (the
scheduler-runtime-statistics metric in lib/os/cpu_load_metric and the
idle-hook measurement in lib/os/cpu_load) are merged into a single
CONFIG_CPU_LOAD module with a pluggable backend selected through the
CPU_LOAD_BACKEND choice:
- CPU_LOAD_BACKEND_RUNTIME_STATS: scheduler runtime statistics,
portable and multi-CPU capable (formerly CPU_LOAD_METRIC).
- CPU_LOAD_BACKEND_IDLE_HOOK: architecture idle hooks, low overhead
with an optional hardware counter, single CPU.
A shared feature layer above the backends provides the current-CPU
getter, the periodic report timer and the threshold callback, so both
backends gain the periodic logging and callback features. The unified
getter pair returns the load in per mille:
int cpu_load_get(bool reset); /* current CPU */
int cpu_load_get_cpu(unsigned int cpu_id, bool reset);
CONFIG_CPU_LOAD_METRIC and cpu_load_metric_get() are kept as deprecated
compatibility wrappers; the latter returns percent as before. The
<zephyr/sys/cpu_load_metric.h> header now just includes
<zephyr/sys/cpu_load.h>. The tracing backends now gate the idle
accounting on CPU_LOAD_BACKEND_IDLE_HOOK rather than CPU_LOAD, since the
idle hooks only exist for that backend.
The cpu_freq on-demand policy is migrated to cpu_load_get_cpu() and
selects CPU_LOAD together with the new CPU_LOAD_MULTICPU helper to pull
in the runtime-statistics backend.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The idle-hook based CPU load module lived under subsys/debug, required
CONFIG_TRACING, and exposed its API through <zephyr/debug/cpu_load.h>.
It does not conceptually belong to the debug subsystem, and its only
dependency on tracing was the idle notification hooks, now available
through CONFIG_SYS_IDLE_HOOKS.
Move the module to lib/os/cpu_load with its own CMakeLists and Kconfig,
relocate the public header to <zephyr/sys/cpu_load.h>, and select
SYS_IDLE_HOOKS instead of TRACING. Update all includers (the tracing
backends, samples and tests) to the new header path.
CONFIG_CPU_LOAD now builds and runs without the tracing subsystem.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The scheduler-runtime-stats based CPU load module lived in
lib/os/cpu_load and exposed cpu_load_metric_get() through
<zephyr/sys/cpu_load.h>. Its logging module name (CPU_LOAD) collided
with the idle-hook based CPU load module, and the shared directory and
header name made the two hard to tell apart.
Move the module to lib/os/cpu_load_metric, rename the source and public
header to cpu_load_metric.c and <zephyr/sys/cpu_load_metric.h>, and give
it its own log module (CPU_LOAD_METRIC) so the two no longer share a log
level symbol. Update the cpu_freq on-demand policy and its sample and
test to include the renamed header and use
CONFIG_CPU_LOAD_METRIC_LOG_LEVEL_DBG.
This frees the lib/os/cpu_load directory and the sys/cpu_load.h header
for the idle-hook based module, which moves there next.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The architecture idle paths call sys_trace_idle() and
sys_trace_idle_exit() to notify subscribers when the CPU enters and
leaves the idle state. These calls were guarded by CONFIG_TRACING,
which tied idle-time accounting to the tracing subsystem even though
no tracing backend is required to service the hooks.
Introduce a hidden Kconfig symbol, SYS_IDLE_HOOKS, that any subsystem
needing these notifications can select, and have TRACING select it.
Switch the idle-path guards in every architecture and SoC that emits
the hooks from CONFIG_TRACING to CONFIG_SYS_IDLE_HOOKS. Because
TRACING selects the new symbol, existing tracing behaviour is
unchanged; the change only lets non-tracing consumers receive the
hooks.
This is a prerequisite for building the CPU load module without the
tracing subsystem.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>