Commit graph

3361 commits

Author SHA1 Message Date
zhanghongyu
51743c55b2 net/arp/arp_send.c: replace net_lock with netdev_lock
use netdev_lock to protect the arp process

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
eb2bd58640 net/nat: replace net_lock with nat_lock(mutex)
add a new API to protect access and operations on the NAT table

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
eb60667561 net/utils/net_lock.c: add api to lock conn and netdev
add new api to protect access and operation to conn and dev

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
0af74a54bb net/netdev: separate netdev_list_lock from net_lock
use netdev_list_lock to protect all network card traversal, registration,
and deregistration operations.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-29 09:42:18 +08:00
zhanghongyu
19dcd452ff net/tcp: add kconfig to support retransmission at a fixed time
the maximum retransmission interval allowed for car projects
cannot exceed 6 seconds, and allows for fixed retransmission intervals.
according to the previous algorithm, the retransmission interval
may be 0.5 * 2 ^ 4 = 8 seconds, which does not meet the requirements.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-27 21:35:00 +08:00
zhanghongyu
746d68916f net/tcp: add support for the CLOSE_WAIT state
CLOSE-WAIT - represents waiting for a connection termination request
             from the local user.
      TCP A                                                TCP B

  1.  ESTABLISHED                                          ESTABLISHED
  2.  (Close)
      FIN-WAIT-1  --> <SEQ=100><ACK=300><CTL=FIN,ACK>  --> CLOSE-WAIT
  3.  FIN-WAIT-2  <-- <SEQ=300><ACK=101><CTL=ACK>      <-- CLOSE-WAIT
  4.                                                       (Close)
      TIME-WAIT   <-- <SEQ=300><ACK=101><CTL=FIN,ACK>  <-- LAST-ACK
  5.  TIME-WAIT   --> <SEQ=101><ACK=301><CTL=ACK>      --> CLOSED
  6.  (2 MSL)
      CLOSED

in the current state, we can continue to send data until the user
calls shutdown or close, then directly enter the TCP_LAST_ACK state

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-27 21:06:23 +08:00
gaohedong
5ba6d3c4eb net/udp: Validate UDP length field against actual packet size
According to RFC768 page 2, length feild is the length  in octets  of this user datagram  including  this header  and the data.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-27 20:44:52 +08:00
gaohedong
4d525505e4 net/udp: Support zero-length UDP datagrams
According to RFC768 page2 and referring to the Linux implementation, the message with udp length of 0 is supported.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-27 20:38:47 +08:00
zhangshuai39
c44834fb92 nuttx/net: Expose the net_ipv6addr_maskcmp interface to user-mode calls
This interface needs to be called in the libc library, but the interface is implemented in the kernel, so this interface needs to be exposed

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
2025-12-25 22:13:43 +08:00
zhanghongyu
3e025b5a03 net/can: can protocol uses a separate buffer to cache can data
To avoid memory waste, can add support for using an independent iob buffer
The IP protocol often configures CONFIG_IOB_BUFSIZE to be relatively large,
such as 512, for higher throughput. However, the buffer required by CAN is
fixed at a length of 16 or 64. If the system's IOB is directly used,
a lot of memory will be wasted.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 08:56:12 -03:00
zhanghongyu
cdaf4ee653 arp_poll: skip arp_out when arp_send flow
there is no need to call arp_out again to perform layer 2 header filling
in the arp_send process, so we should directly call the driver's callback.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 08:36:47 -03:00
zhanghongyu
a0bd741387 mld: free all mld group when netdev unregister
otherwise, if the mld timers are not cancelled, an illegal address will
be accessed after timeout. to avoid this scenario, when the network card
is unregistered, all MLD timers must be attempted to be synchronously
cancelled.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 08:35:04 -03:00
zhanghongyu
c2a4899941 net/ipfrag: fix ip fragment assert when iob not enough
insufficient IOB during IP fragment is a normal scenario and should
not crash directly. The assert needs to be removed and corresponding
error handling needs to be added.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 08:34:01 -03:00
zhanghongyu
908596dde3 net/bufpool: fix typo
A previous spelling mistake has been detected. fix it

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 08:33:13 -03:00
gaohedong
07372c12ec net/icmp: fix icmp checksum bug
Use the new cheksum interface to avoid checksum errors caused by IoB discontinuity

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-25 18:09:03 +08:00
gaohedong
267df3a120 net/icmp: check the checksum field when recieve icmp message
According to RFC 792 page 4, do the icmp checksum if CONFIG_NET_ICMP_CHECKSUMS is set.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-25 18:09:03 +08:00
wangchen
c825404a2b net/icmp: Return -ENOPROTOOPT for SOL_SOCKET to avoid misleading logs
When SOL_SOCKET options (e.g., SO_BINDTODEVICE via ping -I) hit ICMP sockets, icmp_{get,set}sockopt logged “Unrecognized ICMP option: 17” before fallback. Handle SOL_SOCKET explicitly by returning -ENOPROTOOPT so psock_* routes to the socket-level handler. Removes noisy logs without changing behavior (invalid devices still return -ENODEV).

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-12-25 14:09:12 +08:00
gaohedong
23013b33ce net/ethernet: ARP can be configured on interface
ARP can be configured on interface.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-25 12:23:38 +08:00
wangchen
c5bb75441c net/tcp: modify the return value when dev is down in tcp_pollsetup
when dev is down, tcp_pollsetup returns the value 'OK' and sets the connection status to 'down' and eventset to POLLERR & POLLUP

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-12-25 10:06:49 +08:00
wangjinjing1
7b528d903c net/can: fix compile error
variable "conn" not define if CONFIG_NET_SEND_BUFSIZE > 0

Signed-off-by: wangjinjing1 <wangjinjing1@xiaomi.com>
2025-12-25 10:04:42 +08:00
zhanghongyu
31e0ec8a39 net/can: fix the typo
Otherwise, we can only manually enable NET_WRITE_BUFFERS

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 10:04:42 +08:00
zhanghongyu
1fd47357f7 net/packet: add PACKET_<ADD|DROP>_MEMBERSHIP support
Some third-party network libraries use PACKET_ADD_MEMBERSHIP to add MAC
addresses to devices, and this patch can add support for this.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 10:01:43 +08:00
wangchen
f03e4774a4 igmp_msg.c:mod check of IGMP_SCHEDMSG from assert to error log
Setting group->flags to IGMP_SCHEDMSG is a possible outcome, not unacceptable. If it occurs, an error log message will be reported

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-12-25 09:58:14 +08:00
wangchen
f10fc888fe net/tcp:resolve reconnection issues when connection failed due to rejection
After first connection refused happend,The user use the same connection failed,becasue the tcpstateflags is not TCP_ALLOCATED

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-12-25 09:56:09 +08:00
zhanghongyu
aba8cd4d86 net/net_initialize: remove the empty functions that are not needed
streamline the code structure

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 09:50:40 +08:00
gaohedong
7f9d3a055b tasking: remove no use remove excess code
Remove excess code, and add return value for function

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-24 20:09:05 +08:00
zhanghongyu
37381a9e7d net/pkt: add SOCK_DGRAM support
According to the definitions of PF_PACKET and SOCK_DGRAM,
extend the current protocol stack pkt protocol to support SOCK_DGRAM mode.

Some third-party network libraries use AF_PACKET, SOCK_DGRAM type sockets
to construct packets and send/receive data, This patch can add support
for this.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-23 09:21:18 -03:00
wangchen
0d1eb67f20 pkt: Fix DHCP transmission failure by updating d_sndlen/d_len lengths
on some device, the wifi driver uses dev->d_len as the length of the sent packet. However, due to the lack of update in d_len, the sent packet is not considered a normal packet and is not processed by the other end

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-12-22 21:27:06 +08:00
wangchen
6cf4c95517 tcp_input: Add condition to check sndseq and ackseq equality
When triggering TCP retransmission through a timer, conn->unacked_q will save more packets, which may result in sndseq being equal to ackseq. Previous implementations may cause conn->nrtx to not be cleared, leading to an increase in conn->rto errors and a longer timer time

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-12-22 21:14:53 +08:00
wangchen
eae67ef9a5 tcp: Reset wb_nack to zero when it hits TCP fast retransmit threshold
The modification is to solve the problem that the opposite end cannot receive the retransmission message, and the protocol stack no longer sends retransmission messages

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2025-12-22 21:14:53 +08:00
zhanghongyu
5c61672185 net/tcp/tcp_connect.c: move txnotify after setup_callback
otherwise, when tx is modified to direct mode, wait will not be awakened

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-20 10:58:16 +08:00
zhanghongyu
9ce35caf4e net/tcp: fix the problem of nested tx in the rxcb process
since the current txnotify is executed synchronously at the location of
the current call without switching threads, resources such as d_iob need
to be cached first.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-20 10:58:16 +08:00
zhanghongyu
9869181761 tcp.h: add TCP_CORK definition
TCP_CORK and TCP_NODELAY behave almost exactly the opposite,
so first provide simple support for TCP_CORK.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-18 15:38:17 +08:00
zhangshuai39
1914dd0820 net/socket: Check on the end of the NIC name when binding device
When using usrsock to pass the network interface name, omitting "\0" will cause the host to parse extra characters. therefore, the tail section should be inspected during device binding.

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
2025-12-17 23:01:34 -05:00
zhangshuai39
560aed72a4 net: Check listening connections when selecting ports
Added check for port number on listen queue

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
2025-12-17 01:30:11 +08:00
zhanghongyu
2b092adf48 net/can: fix possible IOB resource leak when can close
If there is data in readahead, it needs to be released; otherwise,
it will cause the leakage of IOB resources

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-15 10:19:15 +08:00
wangjinjing1
232ef950c6 net/can,udp,tcp: add sem destroy for udp/tcp sndsem;
standardize the usage of semphore

Signed-off-by: wangjinjing1 <wangjinjing1@xiaomi.com>
2025-12-15 10:19:15 +08:00
wangjinjing1
8c92be874f net/can: add write buffer to support nonblock send
The sending of can socket can support more scenarios

Signed-off-by: wangjinjing1 <wangjinjing1@xiaomi.com>
2025-12-15 10:19:15 +08:00
zhanghongyu
1c0a3a8d63 net/can: support can receive packets from all can devices
after the socket calls bind with ifindex is 0, it can receive packets
from all can devices

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-15 10:19:15 +08:00
zhanghongyu
b7b9aebab9 net/can: return -ENODEV if the device is not found when bind
correction return value

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-15 10:19:15 +08:00
zhanghongyu
150e52769b net/udp: fix build error when NET_UDP_WRITE_BUFFERS disable
fix build error.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-10 23:44:14 +08:00
zhanghongyu
8d7ce77247 net/pkt: fix build error when NET_PKT_WRITE_BUFFERS disable
fix build error.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-10 23:44:14 +08:00
zhanghongyu
e2525f61b1 net/pkt: add nonblock mode and send buffered support
Supports more flexible configuration of sending methods

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-10 23:44:14 +08:00
Zhe Weng
6fd74f817d net/pkt: Support filtering protocol in AF_PACKET
Ref: https://man7.org/linux/man-pages/man7/packet.7.html

1. For `socket(AF_PACKET, int socket_type, int protocol)`: When `protocol` is set to `htons(ETH_P_ALL)`, then all protocols are received. If `protocol` is set to zero, no packets are received.
2. For `bind`: `bind` can optionally be called with a nonzero `sll_protocol` to start receiving packets for the protocols specified.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-10 23:44:14 +08:00
gaohedong
09e12a58d3 net/pkt: add poll function for pkt socket
add poll function for pkt socket

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-10 23:44:14 +08:00
gaohedong
9e0852c6a4 net/pkt: delete the read-back mechanism in pkt stack
When app send a pkt-packet, then it will read back it and case some problem. Connection should not read back the message sent by itself.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-10 23:44:14 +08:00
gaohedong
81f42cb2cf net/ethernet: add timestamp for socket packet
add timestamp for socket packet

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-10 23:44:14 +08:00
Zhe Weng
2b34bcfcb1 netdev/ioctl: Add support for simple VLAN ioctl
Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN
Ref: https://github.com/torvalds/linux/blob/v6.12/net/8021q/vlan.c#L621

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-09 07:56:20 -03:00
Zhe Weng
242c253178 net: Add VLAN device support
Inspired by Linux's way, we also create VLAN devices for managing VLAN,
which will become interfaces like `eth0.58`.

QinQ is also supported, we can create VLAN devices above another VLAN
devices, like `eth0.100.101` (or even `eth0.1.2.3.4`, also supported on
Linux).

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-09 07:56:20 -03:00
Zhe Weng
b2db3a6430 net/netdev: Add netdev_iob_replace_l2 for netdev to avoid misuse
And fix wrong `d_len` for IOBs from `upper->txq` in TX.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-12-09 07:56:20 -03:00