RFC 3171 reserves 224.0.0.0/24 for link-local IPv4 multicast
scope, so packets in this range must not be forwarded by routers,
regardless of the TTL value.
IPv6 also defines multicast scopes that must not be forwarded beyond
the local topology. In particular, interface-local and link-local
multicast destinations must not be routed across interfaces.
Add IPv4/IPv6 scope checks so non-forwardable multicast packets are
rejected before entering the multicast forwarding path.
Signed-off-by: Shunchao Hu <ankohuu@gmail.com>
Return ntotal (total bytes written) instead of ret (result of last
write call). This matches the expected semantics and is consistent
with net_writeroute_ipv4().
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Add kmm_free(alloc) before returning NULL when neigh is NULL in
netlink_get_neighbor(). Without this, the allocated memory is
leaked on the error path.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
In both convert_ipv4entry() and convert_ipv6entry(), the IPPROTO_UDP
case was incorrectly comparing against XT_MATCH_NAME_TCP instead of
XT_MATCH_NAME_UDP. This caused UDP filter rules to never match.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Remove a redundant net_unlock() call in the early return path of
mld_gendog_work(). The network lock is already released at the
common exit path, causing a double-unlock.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Change && to || in the fromlen validation of icmpv6_recvmsg().
The original condition (fromlen == NULL && *fromlen < sizeof(...))
would never be true when fromlen is NULL due to short-circuit
evaluation. The correct logic is: reject if fromlen is NULL or
the buffer is too small.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Replace return with break inside the loop in icmp_findconn() to
ensure any post-loop cleanup logic is properly executed before
returning.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Move the NULL check for radio pointer before the DEBUGASSERT that
dereferences it. Previously DEBUGASSERT(radio->r_dev.d_lltype == ...)
was executed before verifying radio != NULL, which would crash when
the device is not found.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Move conn_unlock() call outside the if block in psock_udp_sendto()
to ensure the connection lock is always released before returning,
preventing a potential deadlock when the condition is not met.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.
A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.
Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
Release nat_lock before returning -ENOENT from the IPv4 and IPv6
outbound NAT paths when NAT entry creation fails.
Signed-off-by: Shunchao Hu <ankohuu@gmail.com>
Move conn_unlock() after the data event handling in can_callback()
and udp_callback(). Previously, the connection lock was released
immediately after devif_conn_event(), leaving the subsequent
can_data_event()/net_dataevent() and read-ahead buffer operations
unprotected. This could lead to a race condition where another
context modifies the connection state while data is being stored.
Hold the lock until the entire callback processing is complete to
ensure thread safety.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
case: when rndis receive a packet and this packet is going to be forwarded.
1. first lock happen when ipv4_dev_forward call ipv4_nat_outbound;
2. next lock is: ipv4_nat_outbound_entry_find --> nat_port_select --> tcp_selectport
--> nat_port_inuse
Signed-off-by: Jerry Ma <shichunma@bestechnic.com>
Correct duplicate "is is" word found in 181 files throughout the
codebase.
In most cases "is is" was changed to "is", but in contexts like
"MCU is is sleep mode" it was corrected to "MCU in sleep mode".
Also fixes a "the the" typo in net/inet/inet_sockif.c.
This is a pure style/documentation fix that improves code readability.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Fix 269 occurrences of duplicate "the" word typo found in 209 files
across source code, header files, and configuration.
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Intermediate files of make depend like .ddc and .dds may remain
when make is interrupted. Remove them using make distclean.
Signed-off-by: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com>
Some compilers like Tasking do not support anonymous unions/structs.
Add explicit names to the anonymous union and struct members in
snoop_packet_header_s and update all references accordingly.
Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
This reverts commit fa652f9c24.
When testing iperf on boards such as ESP32-C6, ESP32-C3, and ESP32,
blocking issues are encountered, so the patch is reverted.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
The main content of this submission is to limit both the TX/RX buffers
of TCP/UDP to throttled IOBs, avoiding impacts on the sending and
receiving of control-type messages.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
the lock in the "bluetooth_conn" was not initialized, which resulted in
a blocking situation when attempting to hold the lock for the first
time.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
In usrsock_pollsetup, only set POLLIN if USRSOCK_EVENT_RECVFROM_AVAIL is set when remote is closed, avoiding invalid POLLIN events.
Signed-off-by: daichuan <daichuan@xiaomi.com>
Clear USRSOCK_EVENT_RECVFROM_AVAIL flag when remote closes connection during accept to prevent repeated POLLIN events and EPIPE loop.
Signed-off-by: daichuan <daichuan@xiaomi.com>
Add CONFIG_NET_NO_LTO to allow compiling the network stack with -fno-lto.
This is useful for avoiding LTO-related issues in the network layer.
Signed-off-by: daichuan <daichuan@xiaomi.com>
When an unrecognized ICMP (type=3, code=2) packet is received, the ICMP flow does not set dev->d_len to 0, causing a devif_loopback dead loop.
Therefore, in ICMP input processing, when an ICMP_DEST_UNREACHABLE message is received, if it is not ICMP_FRAG_NEEDED code, jump to typeerr for error handling.
Signed-off-by: daichuan <daichuan@xiaomi.com>
For the LIN protocol, the error frame ID can be 0. This change is to ensure that all LIN error frames can pass the filter.
Signed-off-by: wangjinjing1 <wangjinjing1@xiaomi.com>
Update the can_sendmsg() signature from "struct msghdr *msg" to
"const struct msghdr *msg" to match the updated sendmsg() prototype
and resolve compilation errors due to parameter type inconsistency.
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
To ensure consistency, in all places where the "sendmsg" function is used
either directly or indirectly, the type of the "struct msghdr *msg" parameter
needs to be modified to "const struct msghdr *msg".
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
Rename imr_interface to imr_address in struct ip_mreqn to match the Linux definition.
This ensures compatibility with standard socket APIs and existing Linux applications.
Signed-off-by: daichuan <daichuan@xiaomi.com>
expose the query interface of the network card to the network card
driver so that the network card driver can support more features.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
The RFC requires sending an TCP_RST packet in this scenario, so to better
comply with the standard definition, the sending of TCP_RST is added.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
urgent data needs to be treated as normal data when
CONFIG_NET_TCPURGDATA disable. some test sets will verify this
behavior, correct the processing logic.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This patch adds validation for IPv4 option lengths during packet processing
to prevent malformed packets from causing undefined behavior. The new
ipv4_check_opt() function verifies that option lengths are within valid
bounds before processing them.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This patch fixes the validation order in netdev ioctl handlers for
Bluetooth, IEEE 802.15.4, and packet radio devices. The command type
should be validated before checking the argument pointer to return
the correct error code (-ENOTTY vs -EINVAL).
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
d_len needs to include NET_LL_HDRLEN(dev) to avoid errors in
the verification of message length in ipv4_in/ipv6_in.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
During the autoconfig process, if the user modifies the link local
address while waiting for the Router Advertisement message, a crash will
occur when sending the ICMPv6 Neighbor Advertisement message because
netdev_ipv6_lladdr returns NULL.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>