Commit Graph

3344 Commits

Author SHA1 Message Date
Shunchao Hu eb4df019af net/ipforward: Forbid non-forwardable multicast scopes.
Build Documentation / build-html (push) Has been cancelled
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>
2026-04-18 19:54:59 -03:00
zhanghongyu 34fbaa15ee net/route: fix return value of net_writeroute_ipv6
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>
2026-04-13 08:46:57 -03:00
zhanghongyu c6c7cf6bba net/netlink: fix memory leak in netlink_get_neighbor
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>
2026-04-13 08:46:57 -03:00
zhanghongyu 244ddfcc2c net/netfilter: fix match name for UDP in ipt_filter
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>
2026-04-13 08:46:57 -03:00
zhanghongyu 39639282d1 net/mld: remove duplicate net_unlock in mld_gendog_work
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>
2026-04-13 08:46:57 -03:00
zhanghongyu 6cba2674fa net/icmpv6: fix wrong logical operator in recvmsg validation
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>
2026-04-13 08:46:57 -03:00
zhanghongyu 0c7f8204fd net/icmp: use break instead of return in icmp_findconn
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>
2026-04-13 08:46:57 -03:00
zhanghongyu a0b8969636 net/bluetooth: fix null pointer dereference in bluetooth_sendmsg
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>
2026-04-13 08:46:57 -03:00
zhanghongyu faa4d7ff8d net/udp: fix conn_unlock not called outside conditional block
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>
2026-04-09 03:04:15 +08:00
Piyush Patle 0dccc8ba21 include/debug.h: Move to include/nuttx/debug.h
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>
2026-04-07 07:50:06 -03:00
Shunchao Hu 1e6c751db7 net/nat: Unlock on outbound NAT entry creation failure.
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>
2026-04-05 11:22:41 -04:00
zhanghongyu 27214321be net/can,udp: fix conn unlock position in callback
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>
2026-04-02 20:55:27 +08:00
shichunma ef67e94613 net/nat: fix missed nat_unlock
If call nat_enable twice, there will be a miss "nat_unlock".

Signed-off-by: Jerry Ma <shichunma@bestechnic.com>
2026-03-24 13:49:12 +08:00
shichunma db572d860b net/nat: g_nat_lock can be used recursively
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>
2026-03-24 13:49:12 +08:00
Huang Qi e09048cc88 style: Fix "is is" typo across the codebase.
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>
2026-03-24 09:39:26 +08:00
Huang Qi e3eeaefd6d style: Fix "the the" typo across the codebase.
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>
2026-03-23 11:07:49 +01:00
shichunma 121e3ac9fc netdev/netdev_ioctl: log in hex mode for ioctl cmd
It's a more friendly when output cmd in hex mode, since it's defined like: 0x7xx

Signed-off-by: Jerry Ma <shichunma@bestechnic.com>
2026-03-03 15:58:03 -03:00
SPRESENSE 72b67832ea Makefile: Remove make depend files by make distclean
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>
2026-02-16 16:27:57 +01:00
zhangyuan29 c99fa1994f net/utils: add union name for tasking compiler compatibility
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>
2026-02-12 10:49:44 -03:00
shichunma 3fb776e45c net/netdev: a valid netdev for ipv4 should have ipv4 addr configured
It's not a valid netdev if without ipv4 address.

Signed-off-by: Jerry Ma <shichunma@bestechnic.com>
2026-02-02 13:57:56 +08:00
zhaohaiyang1 f653ffd723 forward: Add IFF_NOSRC_FORWARD and IFF_NODST_FORWARD flags.
* IFF_NOSRC_FORWARD: Controls whether device prohibits forwarding packets inputs
* IFF_NODST_FORWARD: Controls whether device prohibits forwarding packets outputs

This allows users to selectively enable/disable forwarding on specific
devices, improving network flexibility and security.
Signed-off-by: zhaohaiyang1 <zhaohaiyang1@xiaomi.com>
2026-01-31 02:37:58 +08:00
yintao 741324d73c net/rpmsg: add err handle when rpmsg_socket_unbind called
After waiting, it is necessary to check if the connection
has been disconnected

Signed-off-by: yintao <yintao@xiaomi.com>
2026-01-29 09:15:33 -03:00
yintao 3fa55fb72e net/rpmsg: support POLLHUP when unbind
rpmsg_socket_ns_unbind should notify pollhup when reconnect
Otherwise, uv_poll can't UV_DISCONNECT
eg:
if (revent & POLL_ERROR || revent & POLL_DISCONNECT)
           xxxx();

Signed-off-by: yintao <yintao@xiaomi.com>
2026-01-29 09:15:33 -03:00
zhanghongyu d5d6b65213 Revert "net: limit TCP and UDP send/recv buffer usage with throttled IOB"
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>
2026-01-23 14:40:06 -03:00
Bartosz Wawrzynek 585d954d0b boards/sim: Fix watchdog callback
drivers: Fix types and sx127x driver rx
net/pkt: Fix type

Small fixes.

Signed-off-by: Bartosz <bartol2205@gmail.com>
2026-01-23 09:46:02 +08:00
zhanghongyu fa652f9c24 net: limit TCP and UDP send/recv buffer usage with throttled IOB
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>
2026-01-21 20:06:47 +08:00
zhanghongyu 646010d0a0 net/bluetooth: fix rmutex deadlock
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>
2026-01-21 19:24:02 +08:00
daichuan a82ee60da8 usrsock: Check RECVFROM_AVAIL before setting POLLIN in pollsetup
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>
2026-01-20 22:37:10 +08:00
daichuan 7a4a6ce4ce usrsock: Avoid frequent POLLIN when remote close during accept.
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>
2026-01-20 22:37:10 +08:00
daichuan d19ee93c60 net: Support no-lto option for the network build.
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>
2026-01-20 10:12:45 +08:00
daichuan 32ffc69bdd net/icmp: Fix devif_loopback dead loop when unrecognized ICMP packet received
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>
2026-01-20 06:56:27 +08:00
zhangshuai39 49ffd94d84 net/pkt: Fix coverity issue
The value ret is overwritten after being assigned a value.

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
2026-01-19 15:33:03 -05:00
daichuan b01f8b04e9 netdev: delete macro CONFIG_NETDEV_CHECKSUM with nuttx
not need CONFIG_NETDEV_CHECKSUM with nuttx

Signed-off-by: daichuan <daichuan@xiaomi.com>
2026-01-19 23:22:46 +08:00
daichuan 99bf7c3c5f net: skip TCP/UDP pseudo-header checksum with hardware offload
When supporting hardware checksum offloading, the network protocol stack
does not perform TCP/UDP pseudo-header checksum calculation.

Skip TCP/UDP pseudo header checksum calculation in network protocol stack

Signed-off-by: daichuan <daichuan@xiaomi.com>
2026-01-19 23:22:46 +08:00
daichuan 42da4e322a net/netdev: fix compile error and add cmake/makefile
Fix compilation errors and add build files

Signed-off-by: daichuan <daichuan@xiaomi.com>
2026-01-19 23:22:46 +08:00
daichuan d2dde8a29a net/netdev: modify for hardware checksum offload
Implementation of main hardware verification and uninstallation functions

Signed-off-by: daichuan <daichuan@xiaomi.com>
2026-01-19 23:22:46 +08:00
wangjinjing1 18820ef07d net/can: allow errmask to be set to CAN_ERR_FLAG;
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>
2026-01-19 15:13:14 +08:00
guoshichao 3d45550da9 can_sendmsg_buffered: fix can_sendmsg param type mismatch error
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>
2026-01-16 21:11:39 +08:00
guoshichao 57637e5927 net: make the sendmsg param type consistent with posix specification
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>
2026-01-16 21:11:39 +08:00
daichuan cf8dacde9c netinet/in.h: Rename imr_interface to imr_address in struct ip_mreqn.
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>
2026-01-16 09:42:12 +08:00
zhanghongyu 4ce3dac146 net: move the tool interface functions to the public directory
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>
2026-01-16 09:42:01 +08:00
zhanghongyu da43a2e53b tcp_timer.c: send TCP_RST when keepalive timeout
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>
2026-01-16 09:39:45 +08:00
daichuan df7a58dab8 net/neighbor: fix compilation with CONFIG_NET_ICMPv6_NO_STACK
When CONFIG_NET_ICMPv6_NO_STACK is enabled, icmpv6_solicit should not be called.

Signed-off-by: daichuan <daichuan@xiaomi.com>
2026-01-16 09:38:27 +08:00
zhanghongyu da35465d43 tcp_input.c: standardize the processing of urgent data
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>
2026-01-15 16:26:19 -03:00
zhanghongyu 0dc0b94380 net/ipv4: check whether the length of the ipv4 option is correct
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>
2026-01-15 16:14:19 -03:00
zhanghongyu 6296aeecdb net/route/ramroute: replace prealloc with netpool
reuse the netpool module to optimize the code implementation.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-15 23:15:03 +08:00
zhanghongyu 5ce2955e62 net/netdev: correct the ioctl command validation logic
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>
2026-01-15 19:59:40 +08:00
zhanghongyu 0fdd6b5bf6 ipfrag: use netdev_iob_replace_l2 to replace d_iob
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>
2026-01-15 01:55:19 +08:00
zhanghongyu a7f084bfd4 icmpv6_autoconfig.c: fix crash when ipv6 address modified during autoconfig
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>
2026-01-13 13:55:17 -08:00
shichunma 52e67d167a net/route: need clear old cached route info when do reset cache
When do net_flushcache_ip4/6, it may have old info at that time.

Signed-off-by: Jerry Ma <masc2008@gmail.com>
2026-01-11 23:23:34 +08:00