Commit graph

3300 commits

Author SHA1 Message Date
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
wangchen
96fcc8bb1d net:modify check condition from IFF_UP to IFF_RUNNING in the sending process
Modify check condition from IFF_UP  to IFF_RUNNING in the sending process

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2026-01-09 21:48:18 +08:00
Jiri Vlasak
7fa4a7f3b4 net/netdev: Fix best prefix in findby
When comparing with netmask, the best prefix len is netmask.

Signed-off-by: Jiri Vlasak <jvlasak@elektroline.cz>
2026-01-08 22:45:16 +08:00
zhanghongyu
6a6bc58e07 net/udp_sendto_unbuffered.c: fix udp message cannot be sent to the network card
UDP message cannot be sent to the network card, and case a stuck issue.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-07 13:27:11 +01:00
OceanfromXiaomi
f53b986fb2 can: propagate iob_tryadd_queue() failure in can_datahandler
The can_datahandler() function calls iob_tryadd_queue() to enqueue
received CAN data. Since iob_tryadd_queue() may return a negative
value on failure, the error was previously not properly handled.

Update can_datahandler() to propagate the return value so callers
can detect and handle queueing failures correctly.

Signed-off-by: zhaohaiyang1 <zhaohaiyang1@xiaomi.com>
2026-01-07 08:31:06 +01:00
zhanghongyu
5e1410ecab net/local: replace net_lock with local_lock
remove the use of net_lock in the local module and decouple it from
other network modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-06 16:08:30 +08:00
wangchen
c2774ba1ec netdev:When running, proto stack can exchange packets with device
netdev:when network device is running status,the network protocol stack is allowed to send packet to the network device and to receive from the network device

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2026-01-06 16:04:03 +08:00
zhanghongyu
8f41613374 net: replace net_sem*wait with conn_dev_sem*wait to simplify code logic
optimize the current code format according to the previous net_xxx_wait
implementation to reduce multiple calls of similar code

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
aee7ea0d7d net/utils: conn_dev_sem_timedwait supports the input parameter sconn being NULL
thus supporting scenarios that only require break netdev_lock.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
efd8e1be2b net/ieee802154: replace net_lock with conn_lock and conn_lock_dev
decouple lock dependencies from other modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
92b3357182 net/bluetooth: replace net_lock with conn_lock and conn_lock_dev
decouple lock dependencies from other modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
11c4bb7f31 utils.h: add conn_dev_sem_timedwait interface to simplify code logic
the following code can be modified

  conn_dev_unlock(&conn->sconn, conn->dev);
  ret = net_sem_timedwait_uninterruptible(&conn->snd_sem,
    tcp_send_gettimeout(start, timeout));
  conn_dev_lock(&conn->sconn, conn->dev);
to

  ret = conn_dev_sem_timedwait(&conn->snd_sem, false,
    tcp_send_gettimeout(start, timeout), &conn->sconn, conn->dev);

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
b8850e4eb3 conn_lock: inline conn_lock/conn_dev_lock
modify functions that are simple but frequently called into inline
functions, thereby reducing CPU loading without significantly changing
the code size.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 07:48:06 -03:00
zhanghongyu
2f3b8255e0 devif_poll.c: inline the small or single caller function
reduce stack operations to lower CPU loading.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:04:16 +08:00
zhanghongyu
c481374fb8 devif_poll: only call the corresponding xxx_poll when there is data to be sent
reduce the execution consumption of irrelevant code

testing the TX rates of TCP and UDP based on the Infineon board can
increase them by 13%.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:04:16 +08:00
zhanghongyu
a0b847bf1b net/devif_callback: change flags type from uint16_t to uint32_t
increase the size of the flag to prepare for precise xxx_POLL.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:04:16 +08:00
zhanghongyu
d377f6b788 net: use netdev_lock to protect netdev_txnotify_dev
since the type of sconn lock is rmutex, there is no need to release
sconn lock before TX

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:04:16 +08:00
zhanghongyu
eb5c8f4e9c net/netlink: replace net_lock with netlink_lock
remove the use of net_lock in the netlink module and decouple it from
other network modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:00:55 +08:00
zhanghongyu
3778834527 netdev_foreach.c: add lock protection during the traversal process
when traversing g_netdevices, it is necessary to ensure that they are
not modified during the traversal.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-02 00:00:55 +08:00
zhanghongyu
f27a9bbc27 net/usrsock: replace net_lock with usrsock_lock
remove the use of net_lock in the usrsock module and decouple it from
other network modules.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-01 07:35:12 -03:00
zhanghongyu
24ee7cba86 net_lock: add net_sem_timedwait2, passing in rmutex that needs to be break
two rmutexes can be passed in, and later the wait scenarios that require
break the conn and netdev locks will be replaced.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-01 07:35:12 -03:00
zhanghongyu
8506259b79 net/socket: replace net_lock with conn_lock
dup2 and setsockopt can use the lock in conn to protect resources,
the lock in accept is originally used to protect the connection status.
however, only the send, recv, netpoll, and connect processes will
check this flag. only when the interface returns will the corresponding
conn structure be exposed to the caller, and then the above operations
can be performed. Therefore, this net_lock is not necessary.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-01 07:35:12 -03:00
zhanghongyu
ef875f335b net_sockif.c: add ip level s|getsockopt support in SOCK_CTRL
some services need to configure iptables without enable TCP/UDP/ICMP/ICMPV6

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-01 17:04:03 +08:00
zhanghongyu
7662ce6d51 net_sockif.c: add rmutex init to SOCK_CTRL
fix the issue where acquiring the lock gets stuck due to the sconn lock
not being initialized.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-01 17:04:03 +08:00
wenquan1
d6bd89ff14 Revert "net/arp: reducing unnecessary ARP requests can mitigate"
This reverts commit 696a94c8055dc59933457e8ce5c3c91dbecab980
first, when continuous ping from tester to vela, if ignore arp expire when ping response use arp_out to build L2 layer, this cause TC13 testing arp entry expire feature failed. second, the patch of support queue iob when arp_out failed can fix this bug.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2026-01-01 17:03:29 +08:00
wenquan1
5b52ab13c8 net/arp: support queue iob when arp_out failed
arp_out will replace the dev->d_iob to arp request if the iob destination
address is not exist in arp table, this mechanism cause this iob lost
result in first received ping no response or first synack retransmit.
to fix this bug, we queue the iob if arp_out failed, allocate a new
iob to send arp request, after the arp request completed, then we retry
send the queue iob packet.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2026-01-01 17:03:29 +08:00
zhanghongyu
adb161aa10 arp: the manually configured arp table should not have a timeout period
Improve the behavior of the ARP table so that the manually configured
ARP table has the highest priority, can only be manually modified to
other values, otherwise will never change again, and will not time out.
The modified behavior is consistent with that of Linux.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2026-01-01 17:03:29 +08:00
wenquan1
559c6855f3 net/ipv4: Drop ipv4 packet total length bigger than the actual transmitted data
Derived from RFC 791 s3.1 p13 Internet Header Format.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2026-01-01 16:55:52 +08:00
Bowen Wang
a4ce775a50 net/rpmsg/rpmsg_sockif: fix compile error about nxsched_getpid
need include <nuttx/sched.h>

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2025-12-31 02:36:29 +08:00
zhangkai25
711c58767a net/arp: Skip ARP request if ip address is invalid
Supports no ARP reply for invalid routing addresses in cross-segment communication

Signed-off-by: zhangkai25 <zhangkai25@xiaomi.com>
2025-12-31 02:36:09 +08:00
dongjiuzhu1
b8585b9b0c net/can: fix poll setup to properly find and use free pollfd slots
Bug Description:
The original code always used conn->pollinfo[0] (the first element) to store
new poll setup context, regardless of whether that slot was already in use.
This caused multiple poll operations on the same CAN socket to overwrite each
other's context, leading to:
- Lost poll waiters when multiple threads poll the same socket
- Memory corruption in pollfd structures
- Undefined behavior when poll_teardown tries to clean up

Root Cause:
The code directly assigned `info = conn->pollinfo` without checking if the
slot was available, effectively always using pollinfo[0]. When a second
thread called poll() on the same socket, it would overwrite the first
thread's poll context.

Solution:
1. Initialize info to NULL instead of conn->pollinfo
2. Before setting up poll, iterate through all CONFIG_NET_CAN_NPOLLWAITERS
   slots to find the first free slot (where fds == NULL)
3. Return -EBUSY if no free slots are available
4. During teardown, properly mark the slot as free by setting fds = NULL

Additional Changes:
- Added CONFIG_NET_CAN_NPOLLWAITERS Kconfig option (default 4) to make the
  maximum number of concurrent poll waiters configurable
- Changed hardcoded array size from 4 to CONFIG_NET_CAN_NPOLLWAITERS
- Fixed lock ordering in teardown to ensure fds is cleared before unlock

Impact:
- Enables multiple threads to safely poll the same CAN socket concurrently
- Prevents poll context corruption in multi-threaded applications
- Provides proper resource management with -EBUSY when all slots are full
- Makes the number of supported concurrent pollers configurable per use case

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-31 02:35:42 +08:00
dongjiuzhu1
d1bc2800e3 net/local: simplify file descriptor passing using shared filep references
This commit removes unnecessary file duplication and memory allocation when
passing file descriptors through Unix domain sockets, leveraging the new
filep reference counting framework.

Background:
With the new filep framework, file structures (filep) can be safely shared
across processes using reference counting. When passing file descriptors
through SCM_RIGHTS control messages on local sockets, the previous
implementation unnecessarily duplicated the entire file structure.

Changes:

1. In local_sendctl() (sender side):
   - Removed allocation of filep2 structure (kmm_zalloc)
   - Removed file_dup2() call that copied the file structure
   - Now directly stores the original filep with its reference count
   - Eliminates memory allocation overhead and potential failure points

2. In local_recvctl() (receiver side):
   - Changed from file_close() + kmm_free() to file_put()
   - file_put() properly decrements reference count and handles cleanup
   - Consistent with the new filep reference counting model

3. In local_freectl() (cleanup on error):
   - Changed from file_close() + kmm_free() to file_put()
   - Ensures proper reference count management during error paths

Technical Details:
The new filep framework ensures that:
- Multiple file descriptors across different processes can reference the
  same underlying filep structure safely
- Reference counting (via file_get/file_put) manages lifetime correctly
- The underlying file object is only released when all references are gone

This change is safe because file_dup() in the receiver already calls
file_get() internally to increment the reference count for the new fd,
so the filep remains valid after the sender calls file_put().

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-31 02:29:46 +08:00
zhangkai25
7a6b9e9407 net/neighbor: Skip Neighbor request if ip address is invalid at ipv6
Supports no Neighbor request for invalid routing addresses in cross-segment communication

Signed-off-by: zhangkai25 <zhangkai25@xiaomi.com>
2025-12-30 22:06:21 +08:00
wenquan1
1f5cd930a4 net/arp: support ARP entry learned on gratuitous ARP response
learn arp when received gratuitiout arp

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:10:50 +08:00
wenquan1
7e4c3f4a60 net/arp: support ARP entry learned on gratuitous ARP response
learn arp when receive gratuitous arp response

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:10:50 +08:00
wenquan1
dfaed9b855 net/icmp: Support icmp timestamp request
When received a icmp timestamp request, send a icmp timestamp reply.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:05:46 +08:00
wenquan1
d2887ef15f net/tcp: fix send RST bug when receive syn retransmit in syn-rcvd state
Fix send RST bug when receive syn retransmit in syn-rcvd state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
476e193812 net/tcp: ignore fin packet in syn-sent state
Ignore fin packet in syn-sent state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
e3c2ab8267 net/tcp: drop the packet with neither SYN or RST flag set in syn-sent state
Drop the packet with neither SYN or RST flag set in syn-sent state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
b09b5dfc9c net/tcp: ignore a RST control message in syn-send state
Ignore a RST control message in syn-send state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
12de7e6dd5 net/tcp: ignore a segment carrying an unacceptable ACK and RST in syn-send state
Ignore a segment carrying an unacceptable ACK and RST in syn-send state

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
62f8c400b6 net/tcp: send a reset if the SYN is in the window buf error
According rfc793 p71, after step1 check OTW seq, and step2 check RST flag, then check syn flag.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
c4494c714c net/tcp: support OTW SEQ number check except SYN-SEND state
According rfc793 p69, from state SYN-RECEIVED to state TIME-WAIT, if the incoming segment is not acceptable, an acknowledgment should be sent in reply (unless the RST bit is set):
<SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
758b6dd847 net/tcp: support OTW SEQ number check in SYN-RCVD state
According rfc793 p69, In SYN-RCVD state, if the incoming segment is not acceptable, an acknowledgment should be sent in reply (unless the RST bit is set):
<SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 21:04:52 +08:00
wenquan1
ee5009295c tcp_reset: Modify RST packet responses to comply with RFC 793.
According to RFC793, the flags of TCP reply packet should be as follows:
1. `RST` if flags of request packet has `ACK`
2. `RST|ACK` if flags of request packet has no `ACK`, at the same time, the sequence should be set to zero.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2025-12-30 11:44:38 +08:00