check_notifications() returned a next event time in the past when a due
observation could not be served, either because its previous notification
was still unacknowledged or because no free message was available, so the
socket loop called zsock_poll() with a zero timeout until the situation
cleared. With a cooperative engine thread that starves the net RX thread,
so the acknowledgment which would end the loop never arrives, and the
spin lasts until CoAP retransmission gives up.
Reschedule an observation with an active notification from the current
time rather than from its stale timestamp, and retry NOTIFY_DELAY_MS
later when no message is free, so the engine always blocks in between.
The next event time is taken after an observation has been handled and
the remaining observations are always scanned: after a notification was
created a further due one keeps its zero timeout, while with no free
message it waits NOTIFY_DELAY_MS like the one that failed.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
generate_notify_message() returned -ENOMEM both when no message was free
and when the encoded payload did not fit, and check_notifications()
treated both as a temporary shortage to retry right away, so an
observation whose value never fits was rebuilt on every pass and the
observations after it were never reached.
Report an empty message pool as -EAGAIN, at debug level since the engine
handles it, so that a payload which does not fit is rescheduled like any
other build error.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
virtiofs_readdir() passed expected_len=-1 to
virtiofs_validate_response(), so the host-controlled out_header.len was
used to compute the return value without a bounds check. A value smaller
than the header underflowed, and a value larger than the dirent and name
buffers was reported as read.
virtiofs_write() validated the reply header but returned the
device-supplied write_out.size without checking it against the request.
A value larger than the requested size makes fs_write() report more
bytes than the caller supplied, and the int accumulator in
virtio_zfs_write() can overflow on 32-bit targets.
Reject both cases with -EIO.
Tested on qemu_x86_64/atom: invalid READDIR lengths and oversized WRITE
replies are rejected with -EIO.
Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
The engine matched incoming packets only against its own pendings and
replies, so every other Confirmable request went to the request handler,
retransmissions included. When a resource callback holds the single engine
thread past the server's ACK timeout, the retransmitted copies queue up in
the socket and are processed again once the callback returns, running
post-write and execute callbacks once per copy. Only Block1 continuation
blocks were recognised as already handled.
Keep a small per-context cache of handled requests for EXCHANGE_LIFETIME as
RFC 7252 section 4.5 requires. The socket of a context is connected, so the
message ID alone identifies a request and the cache needs no peer address.
A request found in the cache is answered with the stored response instead
of being processed again. The entry holds a CoAP header, a token and a
Block1 option, which covers every response the engine builds without a
payload. A response with a payload is not stored. A Read or Fetch with such
a response is not recorded at all, since its duplicate is processed again,
as it has no side effects, and an entry would only evict others; a
duplicate of any other method, which only a gateway callback can answer
with a payload, is dropped rather than run twice. When the application
acknowledged the request separately, a duplicate gets the same empty ACK
while the separate response is tracked by its own pending; if that separate
response cannot be sent, a duplicate gets the response piggybacked instead.
The cache is cleared together with the pendings and replies when the
context is closed, and when its socket is started, as a new socket is a new
endpoint to which requests handled on the old one cannot be retransmitted.
The cache size and lifetime are configurable; a size of 0 disables the
feature. The default of eight entries covers a server that sends several
requests at once; the observed case was seven concurrent Writes of which
five were retransmitted.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
net_context_connect() rejects a multicast peer for TCP, and for IPv4
also a broadcast peer, with -EADDRNOTAVAIL. The check read the address
from context->remote before the new peer address was copied into it, so
it tested the previous peer, which is unset on a fresh socket.
As a result, connect() of a TCP socket to ff02::1, 224.0.0.1 or
255.255.255.255 was accepted. The stack sent SYNs to the multicast or
broadcast address and connect() failed with ETIMEDOUT after the
retransmissions.
Run the check on the address passed to connect().
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
handle_stream_frame() used the stream without holding a reference. The
only reference of a new stream went to the accept queue, so the stream
could be accepted and closed, or released with its connection, before
the data of the frame that opened it was delivered. A stream found by
quic_find_stream() could be released the same way. The data was then
written to a stream that was released, or to the stream that took its
slot.
quic_find_stream() now returns the stream with a reference, taken only
while the stream is in use, and a new stream is referenced before it is
queued for accept. The reference is dropped once the frame is handled.
A reader woken by the delivered data runs before the QUIC service
thread finishes the frame, so a stream closed right after its last read
is now released, together with its connection context, when the frame
is handled. Test 470 waits for the closed contexts instead of expecting
them at once. Test 491 checks that the lookup skips a stream that is
being released, then marks its streams as in use for the other lookups.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Packets sent over an interface using the dummy L2 skip the IP send
checks in net_if_try_send_data(), so a datagram larger than the
loopback MTU is delivered whole and the fragmentation and reassembly
code never runs. That is the right behavior for normal loopback use,
but it means a loopback benchmark or test of fragmented traffic does
not measure what it claims to: the zperf loopback selftest's
udp4_frag and udp6_frag transfers never fragment.
Add CONFIG_NET_LOOPBACK_FRAGMENT, off by default. When it is set, the
dummy L2 bypass runs the fragmentation step of the IP send checks, so
oversized datagrams are fragmented on send and reassembled on receive.
Raw IP sockets still skip it, as they do on other interfaces.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
The check that fragments a packet larger than the MTU was inline in
net_ipv6_prepare_for_send(), together with the neighbor cache lookup.
Move it into net_ipv6_prepare_for_send_fragment() in ipv6_fragment.c,
the counterpart of net_ipv4_prepare_for_send_fragment(), so that it can
be run without the neighbor discovery part.
net_ipv6_prepare_for_send() calls the new function first and returns its
verdict unless it is NET_OK, so the behavior does not change.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
When an HCI ACL packet carries more than one L2CAP PDU, the bytes after
a PDU may be fewer than an L2CAP header. bt_br_acl_recv() still read
the length field from them, which can reach past the end of the
received data before the remainder is rejected as a short packet.
Check that a whole header is present before reading it.
Tested with a new tests/bluetooth/host_br_acl_recv case on native_sim,
which covers dropping such a remainder; the read itself is not
observable there.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
A malformed L2CAP length in received ACL data is a fault on the remote
side, and bt_br_acl_recv() recovers by dropping the rest of the packet,
so these are warnings rather than local errors.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
A receiver may keep the buffer of an L2CAP PDU after bt_l2cap_recv()
returns, as an RFCOMM recv() callback returning -EINPROGRESS does.
bt_br_acl_recv() then restored and pulled that same buffer to reach the
next PDU, so the kept buffer had len 0 when the application read it, or
showed the following PDU when the HCI ACL packet carried several.
Hand the last PDU over in the ACL buffer itself and each earlier one in
a view that references the ACL buffer, from a pool of
CONFIG_BT_BR_ACL_RX_VIEW_COUNT views. Views rather than clones because
a clone from the ACL RX pool would be reported to the Controller as
another completed packet. When no view is left, a PDU shares the ACL
buffer's cursor as before rather than being dropped, since the peer has
spent flow control credits on it.
Tested with tests/bluetooth/host_br_acl_recv on native_sim, with and
without CONFIG_BT_HCI_ACL_FLOW_CONTROL.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
zsock_getpeername_ctx() builds the IPv6 address field by field and
leaves out sin6_scope_id. Copy it from the remote address of the
context.
Fixes#123510
Signed-off-by: Kirill Shypachov <kshypachov@outlook.com>
The remote address of an accepted connection is copied from conn->dst,
which is built from the received packet and carries no zone. accept()
and getpeername() return a link-local peer with sin6_scope_id 0.
Set the zone of a link-local peer to the index of the interface of the
connection, after the IPv4-mapped address handling. conn->dst is left
as is, as received packets are matched against it.
Signed-off-by: Kirill Shypachov <kshypachov@outlook.com>
net_context_connect() binds an unbound context to :: and source
address selection picks the interface from the peer address alone.
fe80::/64 is on every interface, so connect() to fe80::2%2 sends the
TCP SYN through whichever interface selection returns, while
getpeername() reports zone 2. An explicit bind() to :: before
connect() has the same problem, as the interface was chosen at bind
time. A connected UDP socket sends to a multicast peer through the
context interface too, so its zone was not used either.
When the peer has a zone, set the context interface to the one it
names after the default bind. A socket bound to an interface with
SO_BINDTODEVICE, or to a local address, keeps that interface, and a
zone naming another one fails with -EINVAL. This is stricter than
Linux, which rejects only a bound device or link-local address and
lets a socket bound to a global address of another interface use the
zone. Here IPv6 input accepts a unicast packet only on the interface
that has the destination address, so a reply on the interface of the
zone would be dropped and connect() would time out. A zone that names
no interface fails with -ENODEV. Both are checked before the context
is changed, so a failed connect() leaves the socket as it was.
Signed-off-by: Kirill Shypachov <kshypachov@outlook.com>
net_context_connect() copies the address, port and family of the peer
into context->remote, but not sin6_scope_id. The zone given to connect()
for a link-local peer is lost: getpeername() cannot return it, and the
send path, which picks the interface from it, never sees one for a
connected socket.
Keep sin6_scope_id for a link-local unicast peer and for an
interface-local or link-local multicast peer (ffx1::/16, ffx2::/16).
For other addresses the zone has no meaning and is set to 0, as Linux
reports it.
Signed-off-by: Kirill Shypachov <kshypachov@outlook.com>
The echo_server sample on qemu_cortex_a53 overflows the network
management event stack at boot. Increasing that stack alone exposes
an RX thread stack overflow during TCP echo traffic.
Set ARM64 defaults to 1536 bytes for network management events and
3072 bytes for RX threads. Preserve the existing Wi-Fi supplicant
and coverage defaults for management events.
Enable stack sentinel for the ARM64 echo_server scenario.
Verified 1000 TCP echoes with 1-1400 byte payloads and stack sentinel
enabled on qemu_cortex_a53 using Zephyr SDK 1.0.1.
Assisted-by: Codex:GPT-6
Signed-off-by: Sheng Xuan Min <tenoneshiyi@gmail.com>
An empty DATA frame consumes no flow control credit, yet the server
answered it with WINDOW_UPDATE frames carrying a zero increment, on the
stream and on the connection. A zero increment is a PROTOCOL_ERROR for
the receiver (RFC 9113, Section 6.9), so a strict client fails the
stream or the whole connection over it.
Skip the frame when there is nothing to grant.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The static table stores the empty values of RFC 7541, Appendix A, as
NULL, and the indexed field representation refused such entries as
malformed. An indexed reference to any static entry is valid HPACK
(RFC 7541, Section 6.1), so decode it with an empty value.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The integer decoder only refused a sixth continuation byte. A fifth byte
with a group above 15, or a sum running past UINT32_MAX, wrapped the
value silently, so a crafted length prefix decoded as a small number.
Check each group and the addition against the 32-bit limit and fail the
entry with -EBADMSG instead.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Encoding a header field from a name and a value takes filling in the
four string fields of the header buffer before the encoder is called.
Add a helper that does that, for the server now and for any other user
of HPACK.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
A PADDED frame of zero length has no room for its Pad Length field, and
a frame shorter than five bytes has none for the priority field its
PRIORITY flag announces. The parsers took the field length off the frame
length regardless, which wrapped around, and the server then waited for
a payload of several gigabytes. Treat both as malformed frames, which
end the connection.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
A Huffman-coded string that does not fit the decoding buffer failed the
decode with -ENOBUFS, although the entry's length on the wire is known
and the block could be read past it. The caller had no way to drop just
that field, so a single large header cost the whole connection.
Consume the entry and report the field as oversized in the header
buffer. The server rejects such a field as before.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The decoder consumed a dynamic table size update without telling the
caller what it had decoded, so the server went on to process the entry
as a header field, with whatever name and value the previous field had
left in the buffer. The size requested was dropped as well, although
the caller is the one that knows what table size it advertised.
Report the kind of entry and the requested size in the header buffer.
The server skips size update entries; what it accepts does not change,
as the default table size of 4096 applies until a peer has received the
server SETTINGS (RFC 9113, Section 6.5.3).
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
An empty value is valid for a header field and HPACK encodes it as a
zero-length string, but the encoder rejected it with -EINVAL, so such
a field could not be sent. Only a NULL value with a non-zero length is
invalid.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
A PADDED frame whose payload is nothing but the Pad Length field and
the padding is valid: RFC 9113, Section 6.1 only forbids padding that
is longer than the rest of the payload. The server treated the two the
same and failed the connection on such a frame, e.g. a DATA frame that
carries only padding and END_STREAM.
Assisted-by: Claude:claude-fable-5.1
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
ICMP echo mappings kept the client's identifier on the external side.
Two clients pinging the same server with the same identifier got
identical reply tuples, and the replies for both went to whichever
mapping came first in the table. A request also matched an existing
mapping on the addresses alone and overwrote its stored identifier, so
a second identifier from the same client took over the replies of the
first.
Treat the echo identifier like a port, as RFC 5508 section 3.1
describes for NAPT: a request matches a mapping only with the same
identifier, a new mapping gets its external identifier from the same
allocator as TCP and UDP ports (kept when free, endpoint independent
per RFC 5508 REQ-1 a), and SNAT and DNAT rewrite the identifier and
update the ICMP checksum. Identifiers have no reserved range or parity,
so any free value can be used.
Check the contiguous length before reading the identifier of a new
echo request, as the match functions already do, since it is now also
written.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
A new mapping always used the client's own source port as the external
port. Two clients using the same source port towards the same server
then got identical reply tuples, and the replies for both went to
whichever mapping came first in the table. RFC 4787 REQ-3 (UDP) and
RFC 5382 REQ-7 (TCP) forbid this "port overloading".
Choose the external port when a TCP or UDP mapping is created. A client
address and port that already has a mapping keeps its external port for
every destination, which keeps the mapping endpoint independent (RFC
4787 REQ-1, RFC 5382 REQ-1). Otherwise the client's port is kept when
no other mapping on the external address uses it, and on a collision
the next free port of the same range (1-1023 or 1024-65535) and parity
is used (RFC 4787 REQ-3 a and REQ-4).
The SNAT and DNAT paths already rewrite the ports from the tuples, so
only the allocation changes. ICMP echo identifiers are not translated
and are left as they were.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
These functions are used in many places, and inlining them
instead of compiling them caused unnecessary memory overhead.
For CONFIG_ASSERT=y the FLASH difference is 644 bytes
when building the BT_SHELL for nrf52840dk/nrf52840
For CONFIG_ASSERT=n the FLASH difference is 144 bytes
when building the BT_SHELL nrf52840dk/nrf52840
The macro, BT_DEV_LOCK_ASSERT, was kept as is, as implementing
that as a function only increased the FLASH.
RAM is unaffected by this change.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
A scanner that sets BT_LE_SCAN_OPT_EXT_FILTER_POLICY receives directed
advertisements whose target is a resolvable private address that the
Controller could not resolve, reported as BT_ADDR_LE_UNRESOLVED. To act
on one, the application has to check whether the address was generated
from an IRK it holds, such as its own IRK after a peer lost the bond or
an old IRK after bt_id_reset_irk(). The Host and the Controller already
share this check as bt_rpa_irk_matches() in the private common/rpa.h.
Declare it in addr.h as bt_addr_matches_irk(), next to
bt_addr_le_rpa_resolve(), taking the address first like the other
bt_addr_ functions, and update the Host, Controller and test callers.
BT_IRK_SIZE moves from bluetooth.h to addr.h for the prototype;
bluetooth.h includes addr.h, so its users still see it. The bt_addr API
version goes to 1.1.0. The direct_addr documentation of struct
bt_le_scan_recv_info points to the new function.
It now returns false for an address that is not an RPA, without running
AES. The Host callers already check for an RPA, so they behave as
before. The Controller's resolving list lookup keeps its address type
check and leaves the RPA bit check to the function. The Controller's
PAST receiver with CONFIG_BT_CTLR_SW_DEFERRED_PRIVACY does not check: it
passes any random AdvA to the deferred resolution, static and
non-resolvable ones included. Such an address used to match on a 24-bit
hash collision and no longer does.
Fixes#120887
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
rpa.c is built only when CONFIG_BT_SMP, CONFIG_BT_PRIVACY or
CONFIG_BT_CTLR_PRIVACY selects CONFIG_BT_RPA, and bt_rpa_irk_matches()
had its own guard on the same three options. An observer could only get
the function by enabling privacy, although it can hold the IRKs of peers
that use resolvable private addresses, for example provisioned out of
band, and recognise their advertising without using an RPA itself.
The helpers only need AES, from CONFIG_BT_HOST_CRYPTO or
CONFIG_BT_CTLR_CRYPTO, which CONFIG_BT_RPA already depends on. Enable
CONFIG_BT_RPA by default and drop the guard in rpa.c, so that the
helpers are built whenever AES is available. The linker drops them
when nothing calls them; with CONFIG_LOG=y the bt_rpa log source adds
24 bytes of flash.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
PE data-role initialization programs both TCPC roles using a
zero-initialized power role, which corresponds to sink. On source
attachment, this overwrites the source role set by the Type-C state
machine. PE startup later updates only its local power role, leaving
the TCPC's GoodCRC header configured as sink.
Set the initial power and data roles and notify the DPM in the Type-C
attached states. Initialize the PE role context without reprogramming
the TCPC or duplicating role notifications.
Signed-off-by: Nicholas Cadieux <ncadieux@qti.qualcomm.com>
struct bt_att_tx_meta_data puts its uint8_t opcode between an int and
a uint16_t, and struct bt_smp has passkey_round alone between passkey
and two pointers. The resulting holes cost RAM in every ATT TX buffer
and every SMP context.
Move attr_count and opcode after the pointers in the ATT TX metadata,
next to chan_opt: 24 to 20 bytes where an enum takes one byte, as with
the Zephyr SDK's GCC on Cortex-M, where short enums are the default.
With int-sized enums, as on native_sim and 64-bit targets, the size
does not change.
Move passkey and passkey_round below the OOB data pointers in the SMP
context, so that passkey_round joins local_dist and remote_dist: 368 to
360 bytes on bbc_microbit. smp_init() still clears the same members,
everything from method up to the L2CAP channel.
The bbc_microbit peripheral_hr and central_hr builds have three ATT TX
buffers and one SMP context, 20 bytes less in total.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
An LE-only build stores only a struct closure, two pointers, in the
user data of the buffers it sends, but CONFIG_BT_CONN_TX_USER_DATA_SIZE
reserves 16 bytes per buffer on 32-bit and 32 bytes on 64-bit targets.
The larger sizes are for Classic, whose per-buffer state is bigger:
struct l2cap_br_closure (11 bytes on 32-bit, 19 bytes on 64-bit),
struct avctp_buf_user_data (12 and 16 bytes) and struct
bt_avrcp_tg_vd_rsp_tx (16 and 24 bytes).
Keep 16 and 32 bytes when Classic is enabled, and otherwise default to
the size of struct closure: 8 bytes on 32-bit and 16 bytes on 64-bit
targets. ISO stores nothing there; conn_iso_send() only checks that the
user data is as large as the option. Pools that applications size with
the option shrink in the same way.
The ATT and ACL TX pools shrink by 8 bytes per buffer, 40 bytes in the
bbc_microbit peripheral_hr and central_hr builds.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
struct bt_dev stores the whole 64-octet Read Local Supported Commands
response, but the host only checks nine bits of it. Keep those as bits
of an atomic bitmap instead, which grows with the list of commands the
host checks. They are set from the response with the existing
BT_CMD_TEST()-style macros and cleared in bt_disable() as before.
Threads other than the one that sets and clears them read them, for
example when an API call checks for LE Set Host Channel Classification,
hence the atomic accesses.
struct bt_dev shrinks by 64 bytes in the bbc_microbit peripheral_hr and
central_hr minimal builds (280 to 216 and 256 to 192 bytes) and by 56
bytes in the extended observer and mesh_demo builds (224 to 168 and 328
to 272 bytes).
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Replace the open-coded test of K_USER in a thread's user_options with
k_thread_is_user_thread(). No functional change.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The random delay before the initial discover was drawn on every start,
even when it ends up unused. Draw it only on the first start from INIT,
where it is applied.
The delay is at most CONFIG_NET_DHCPV4_INITIAL_DELAY_MAX (10) seconds,
so take 8 bits of randomness instead of 32, both here and for the retry
delay after a failed send.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Fin Maaß <info@finmaass.de>
Compute the length of the path together with the query and fragment
that follow it, bound it against the buffer before copying, and return
-ENOBUFS when it does not fit, so the command fails instead of sending
the request to "/".
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Opening a file is a common way to check whether an optional file exists,
in which case -ENOENT is an expected result, but fs_open() logged it as
an error. Only log the other errors, as fs_stat() already does for
-ENOENT.
Tested with the fat_fs_api and fs_api tests on native_sim.
Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
The MCC reads the object metadata of the included OTS instance with
BT_OTS_METADATA_REQ_ALL, which makes the OTS client read the Object
First-Created and Object Last-Modified characteristics. The MCC
discovery never stored their handles, so those reads were sent to
handle 0. Store the First-Created and Last-Modified handles in the
existing bt_ots_client fields. Also store the Object Changed handle.
The OTS client does not use it, it is kept so that the BTP tester can
report it to PTS, which expects the handle of every supported OTS
characteristic to be returned during discovery.
Signed-off-by: Alex Ciascai <alexandru.ciascai@nordicsemi.no>
net_pkt_alloc_buffer_with_reserve() and net_pkt_alloc_buffer_raw() log
every allocation failure unconditionally. Under sustained buffer
pressure (e.g. a saturated TCP send/receive path) this turns into a
log flood that adds its own overhead on top of the exhaustion it is
reporting. Use NET_ERR_RATELIMIT instead, consistent with how other
hot-path error logging in this subsystem already handles
high-frequency, low-value-per-occurrence failures.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Henry Zhang <henryzhang62@gmail.com>
A stream recv() with MSG_WAITALL on a non-blocking call (MSG_DONTWAIT
or O_NONBLOCK) that found less data queued than requested looped
without sleeping until the rest arrived. The same happened on a
blocking call whose SO_RCVTIMEO deadline passed between reads. The
loop only returned -EAGAIN when no data had been received at all.
Before commit 1fa2ea1c82 ("net: sockets: tcp: split recv_stream into
immediate and timed"), an empty queue with some data received returned
that data.
When nothing is queued and no time is left to wait, return the data
received so far.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
A blocking stream recv() with MSG_WAITALL and SO_RCVTIMEO that timed
out after receiving part of the requested data returned -1 with EAGAIN.
The data had already been copied to the user buffer and removed from
the receive queue, so it was lost.
commit d47e803976 ("net: sockets: Implement MSG_WAITALL recv flag")
returned the data received so far in this case, as Linux does. Since
commit 20a51b49a0 ("net: sockets: Release the socket lock if needed")
the wait returns the timeout before that check is reached.
Return the data received so far when the wait fails and some data was
already received. A pending socket error is then reported by the next
recv(), as is already done when the error is seen before waiting.
The MSG_WAITALL with SO_RCVTIMEO test asked for exactly the amount of
data it sent, so the timeout was never hit. Ask for one byte more.
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
k_mutex_unlock() reports an unlock by a thread that does not hold the
mutex with -EPERM (or -EINVAL when nobody holds it), and
bt_dev_unlock() asserts on that. With CONFIG_NO_RUNTIME_CHECKS the
kernel skips both checks: the unlock goes through, corrupts the lock
count and owner of the host lock and returns 0, so the misuse goes
unnoticed.
Assert with BT_DEV_LOCK_ASSERT() before the unlock. This catches the
misuse in every build with CONFIG_ASSERT and names the offending thread
instead of only the error code. The macro moves above the lock helpers
so that bt_dev_unlock() can use it.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
When an iteration of sntp_simple_helper() receives the response to an
earlier query, sntp_query() returns -ERANGE and the helper keeps calling
sntp_recv_response() for the response to the current query. If that
times out, the loop is meant to go on to the next query. The check
compares the result with ETIMEDOUT instead of -ETIMEDOUT, so the timeout
ends the loop and sntp_simple() and sntp_simple_addr() return -ETIMEDOUT
long before the caller's timeout expires.
This happens whenever the first reply arrives after the first
iteration's 100 ms receive timeout and the second reply does not arrive
within the second iteration's 200 ms. On an ESP32-S3 Wi-Fi station, a
10 s sntp_simple_addr() query to time.google.com returned -ETIMEDOUT
in under a second.
Compare with -ETIMEDOUT, as the check at the top of the loop does. The
wrong sign came in with commit 72534b83e4 ("net: lib: sntp_simple:
Handle responses from previous iterations").
Tested on the same ESP32-S3: with the fix, 9 of 10 boots synchronized
and none returned before the timeout.
Fixes#123543
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: ganesh sharma <ganeshsharma24894@gmail.com>
That iface->if_dev is NULL should never happen,
therefore move the iface->if_dev assert to init,
so it is only checked once and not inlined with
the inline functions everytime.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
A router must set the Router (R) flag in its Neighbor Advertisements
(RFC 4861 4.4/7.2.4). The IPv6 ND code built both solicited and
unsolicited NAs without it, so when CONFIG_NET_IPV6_FORWARDING is
enabled the device sent NAs with R=0. Hosts then treat the node as no
longer a router and delete routes learned from it (RFC 4861 7.2.5).
Add a na_router_flag() helper returning NET_ICMPV6_NA_FLAG_ROUTER when
CONFIG_NET_IPV6_FORWARDING is enabled, and use it in both the solicited
(handle_ns_input) and unsolicited (send_unsolicited_na) NA senders.
Signed-off-by: Nouman Bashir <nouman.bashir@nxp.com>
IAR may incorrectly handle direct assignment of a const
bt_sdp_discover_params structure, resulting in corrupted function
and data pointers after the copy.
Use memcpy() to perform a byte-wise copy and avoid the issue.
Signed-off-by: Make Shi <make.shi@nxp.com>
The bulk OUT completion callback runs in the USB device stack thread,
which serves every class and endpoint of the device. The callback
waited for network packets: up to 100 ms for the temporary source
packet, taken from the TX slab, and without a time limit for each
received datagram.
When the network stack is short of packets, the whole USB device then
stops. The OUT endpoint is not re-armed, the host reports "NETDEV
WATCHDOG: transmit queue 0 timed out", and other classes such as CDC
ACM stall. Before commit d4a50db799, cdc_ncm_send() also waited
without a time limit for an IN completion that only this thread
delivers, so the device stayed stuck until a reset.
Allocate both packets from the RX slab without waiting. If no packet
is available, drop the rest of the NTB and re-arm the OUT transfer, as
an Ethernet driver drops frames when its receive ring is full. Remove
the now unused NET_PKT_ALLOC_TIMEOUT.
Signed-off-by: George Jerzy Dziewierz Rey <george_zephyr@rey.wiki>
skip_fqdn() rejected a label length octet equal to DNS_LABEL_MAX_SIZE
(63), although RFC 1035 ch. 3.1 allows labels of 63 octets or less.
dns_unpack_answer() therefore returned -EINVAL for any answer whose
owner name contains an uncompressed 63 octet label, and
dns_validate_msg() stopped processing the rest of the reply.
Accept lengths up to and including DNS_LABEL_MAX_SIZE, as
dns_unpack_name() and dns_msg_pack_qname() already do. Values 0x40 to
0xbf are still rejected. The bounds check at the top of the loop still
covers the label, so the change does not allow reads past the buffer.
Fixes#123433
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jitheswar Sai Chathan <jitheswaredu@gmail.com>
An extended advertising report without AD data, and a periodic
advertising report with zero-length AD data, call memcpy() with a NULL
source and a length of 0. That is undefined behavior, and UBSAN reports
it.
Copy only when there is data.
Seen on nrf52_bsim with CONFIG_UBSAN=y: tests/bsim/bluetooth/ll/bis hits
the first; the second needs that test to send zero-length periodic
advertising data. Not tested on hardware.
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Arkadiusz Grzelka <arkadiusz.grzelka@arivemb.com>