Commit Graph

2962 Commits

Author SHA1 Message Date
zhanghongyu
3956a52c58 net/tcp: return true only when send window updates
return true even when window has not changed will cause delayed ack cannot take effect.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-03-13 22:24:04 +08:00
Xiang Xiao
615c4bc6e9 net/local: Fix the wrong direction of threshold setting
reader should set POLLIN threshold, writer should set POLLOUT threshold.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-03-10 11:44:33 -03:00
Xiang Xiao
b0e3a35c39 net/local: Skip poll_notify in local_event_pollsetup if no event happen
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-03-10 11:44:33 -03:00
Xiang Xiao
155768bae3 net/local: Fix minor issues found in code reading
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-03-10 11:44:33 -03:00
Xiang Xiao
1ba065db87 drivers/pipe: Change to the block mode by file_ioctl(FIONBIO)
it's simpler and safer than file_fcntl(F_SETFL)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-03-07 10:09:35 -03:00
Yanfeng Liu
3bd35487f0 docs/comments: add simple document and fix typo
This patch adds simple document for the shared memory file system.
with typos fix in a other places.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-03-03 01:55:07 +08:00
Xiang Xiao
61d9394366 net/local: Add local_freectl to avoid the code duplicaton
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-02-29 16:28:01 -03:00
Xiang Xiao
c7a513b182 net/local: Remove the check of SOCK_STREAM before local_stream_connect
since psock_local_connect is called only when the socket is SOCK_STREAM

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-02-29 16:28:01 -03:00
Xiang Xiao
039a3eccf4 net/local: Initialize lc_crefs to 1
and remove local_addref call after local_alloc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-02-29 16:28:01 -03:00
Xiang Xiao
86039057f8 net/local: Remove the unused lc_psock from local_conn_s
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-02-29 16:28:01 -03:00
ligd
7ccdd29f3e local: correct shutdown state when use UDP mode
Signed-off-by: ligd <liguiding1@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2024-02-29 16:28:01 -03:00
Zhe Weng
5eb08a4b33 net: Fix minor coding problems
Fix minor problems when reading codes:
- icmpv6_autoconfig: Call net_unlock before return
- pkt_sendmsg: Return error for types other than SOCK_RAW

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-02-23 10:34:23 -03:00
Zhe Weng
9a23ebdbc0 net/pkt: Support binding to devices other than ETH
We're using the `sll_ifindex` inside `struct sockaddr_ll` to bind
device, so we don't need to translate it into mac address, we can just
match the index, which also let us bind to different type of devices
other than Ethernet.

Ref: Linux also uses `ifindex` to find related device and note it down without mac addresses.
https://man7.org/linux/man-pages/man7/packet.7.html
https://github.com/torvalds/linux/blob/v6.7/net/packet/af_packet.c#L3328
https://github.com/torvalds/linux/blob/v6.7/net/packet/af_packet.c#L3264-L3265

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-02-22 21:21:48 -08:00
Bowen Wang
fcfd5e8ebf rpmsg/Kconfig: add rpmsg_local_name to replace rptun_local_name
Because rpmsg service depends on RPMSG, make rpmsg socket use the
RPMSG_LOCAL_NAME

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-02-18 04:09:34 -08:00
Bowen Wang
169f47beec rpmsg: make all the rpmsg services deponds on RPMSG
After decoupled the rpmsg and rptun, all the rpmsg service should
depends on the RPMSG.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-02-18 04:09:34 -08:00
Zhe Weng
5a10367312 net/nat: Fix ICMP Error MSG Processing
1. Don't assert on IGMP inside ICMP, just ignore it.
2. Check we have full IP header inside ICMP payload before accessing it.
3. `inner_l4hdrbak` need to be `L4_MAXHDRLEN`, not `L4_MAXHDRLEN/2`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-02-05 19:36:59 +08:00
Xiang Xiao
3594e3e541 net/rpmsgsock: Rename rpmsg_socket_getconnname to rpmsg_socket_getpeername
to align with the naming convention of getpeername.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-02-04 22:06:45 +08:00
Zhe Weng
8562dd5796 net/udp: Fix source address selection under IPv6
https://github.com/apache/nuttx/pull/11384 has changed the source
address selection of UDP from raddr to laddr, but not all UDP
connections have laddr set, then we need to fallback to get source from
raddr.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-02-02 09:07:38 -08:00
wangchen
204f4a18a0 Support to ARP Address Conflict Detection
Support to ARP Address Conflict Detection

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-01-25 11:25:03 -03:00
Zhe Weng
3b74cfecc2 net/route: Support longest prefix match for routing
Support longest prefix match routing described as "Longest Match" in
RFC 1812, Section 5.2.4.3, Page 75.

Introduced `prefixlen` to indicate the prefix length of currently
founded route, and only looks up for longer prefix in all later steps.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-01-09 05:58:10 -08:00
Zhe Weng
54f3452293 net/route: Fix null pointer access when ramroute is full
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-01-09 05:58:10 -08:00
Zhe Weng
688f0e9117 net: Only call arp_send for PF_INET and icmpv6_neighbor for PF_INET6
If we only enable one of `CONFIG_NET_ARP_SEND` and
`CONFIG_NET_ICMPv6_NEIGHBOR`, both IPv4 and IPv6 traffic will send
ARP or NDP, which causes problem.

Example:
`CONFIG_NET_ARP_SEND=n`
`CONFIG_NET_ICMPv6_NEIGHBOR=y`

Wrong:
IPv4 traffic (`PF_INET`) goes into `icmpv6_neighbor`, which
definitely causes problem.

Correct:
IPv4 traffic doesn't call anything, IPv6 traffic calls `icmpv6_neighbor`

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-01-09 05:56:28 -08:00
Zhe Weng
1adfc1ae79 net/can: Release IOB when failed to queue in datahandler
If we just clear the IOB when failed to queue, we'll leak it.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-01-06 04:20:36 -08:00
Bowen Wang
e2cf0cad39 rpmsg_sockif: recv/recvmsg return 0 when peer close
Follow the posix standard:
If no messages are available to be received and the peer has
performed an orderly shutdown, recv() shall return 0.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-01-04 20:07:43 -08:00
Bowen Wang
7a9aa9539c local_sendmsg: fix peer->lc_cfps[] array out-of-range write
When peer->lc_cfpcount == LOCAL_NCONTROLFDS,
Line 122: peer->lc_cfps[peer->lc_cfpcount++] = filep2; access
out-of-range

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-01-04 20:07:06 -08:00
zhanghongyu
e1a1f7b5f4 net/udp: set ipv6 remote addr before udpip_hdrsize
In this case, remote addr is all zero, and the length of the
ip header is not recognized as ipv6_is_ipv4, This will cause
problems in subsequent data filling.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-12-27 12:24:59 +01:00
yinshengkai
9852428953 fs: procfs add poll support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-12-26 19:23:13 -08:00
zhanghongyu
d50b1778f7 net/local: make the call return of each process consistent with linux
move the accept logic into connect flow.

In order to successfully establish a blocking connection between
the client and server on the same thread.

nonblock is not affected, and the block connect is now the same
as the nonblock flow, other apis are not affected.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-12-25 16:53:46 -08:00
Zhe Weng
5aeb15469a netdev/ipv6: Move xxx_ipv6multicast from arch to common code
The `xxx_ipv6multicast` function in each driver is not adapted to
multiple IPv6 addresses yet, and they're redundant, so try to take them
into common code.

Change:
1. Add MAC `g_ipv6_ethallnodes` and `g_ipv6_ethallrouters` in
   `icmpv6_devinit` and call them in `netdev_register`
2. Add multicast MAC for Neighbor Solicitation when adding any IPv6
   address, and remove them when IPv6 address is removed
3. Select `NET_MCASTGROUP` when `NET_ICMPv6` because now we need
   `d_addmac` when we have ICMPv6

Note:
We want modules outside net stack to call functions like
`netdev_ipv6_add` and never touch the related MAC address, so these MAC
functions are added as internal functions to `net/netdev/netdev.h`

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-12-16 05:26:16 -08:00
Petteri Aimonen
06e5b661ed tcp: Recover from iob shortage with TCP_WRITE_BUFFERS
When CONFIG_NET_TCP_WRITE_BUFFERS is enabled, iobs are used for
both queuing data from application, and for assembling packets
for sending. If there is a system-wide shortage of iobs, it could
happen that there is not enough free space to form any packets
to send. The buffers allocated for TCP data also can't be released
until the packet is sent.

Normally this should be avoided by setting suitable values for
CONFIG_IOB_NBUFFERS and CONFIG_IOB_THROTTLE. The default values
are ok for light usage, but can run out when using multiple
simultaneous TCP streams.

Before this commit, iob shortage would cause TCP connections to
get stuck and eventually timeout. With this change, TCP stack
sends smaller packets, eventually freeing some buffers from the
write queue.
2023-12-15 20:12:13 -08:00
liqinhui
98e3615b60 net/netdev: Modify the logic for setting the IFF_RUNNING status of interfaces.
Refer to the logic of the `netif_carrier_on` on linux.
https://github.com/torvalds/linux/blob/master/net/sched/sch_generic.c#L575

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-12-15 18:24:23 -08:00
Petteri Aimonen
c3a234fe99 ipv6: Fix source address with many addresses in same network
Previously ipv6 multi-address support decided packet source
address based on its destination. This doesn't work if NuttX
device has multiple addresses within same subnet.

Instead when a packet is a response to existing connection,
the source address should be based on the destination address
used in the received packet.
2023-12-13 06:13:25 -08:00
Zhe Weng
22b6076f26 net/udp: Add check when sending too big packet without IP frag
Commit 8a63d29c removed `devif_iob_send` from `udp_sendto_buffered`
workflow, `devif_iob_send` drops too big packet. Now we still need a
place to check the packet length, otherwise a packet larger than MTU
may be sent to the net driver.

In case of similar problem happens somewhere else, this commit also
adds a check in `netdev_upperhalf`, and count these cases into
`NETDEV_TXERRORS`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-12-12 06:42:33 -08:00
Xiang Xiao
ca5a9c711a Remove @ and % tag from all comments
and format the multiple line comments

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-12-11 17:00:10 -03:00
liqinhui
a69c8a6183 net/icmpv6:Optimize the process of obtaining the IPv6 address through RA.
- When receiving Router Advertisement Message, if Managed Address
  Configuration flag is set, we should ignore the Autonomous
  Address-configuration flag, and obtain the IPv6 address via the
  stateful process.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-12-05 23:40:37 -08:00
Xiang Xiao
eddd90de78 poll: pollsetup should notify only one fd passd by caller
since it's redundant to iterate the whole fds array in setup

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-11-21 09:07:17 +01:00
Petteri Aimonen
cb161940c2 udp: Add support for SO_TIMESTAMP
Adds support for timestamping received UDP packets, either in
hardware or in kernel. Builds on the existing support of SO_TIMESTAMP
for SocketCAN.

Implementation uses CLOCK_REALTIME for timestamping to match the
behavior of Linux. This could be made configurable in future if needed.
2023-11-18 03:10:29 -08:00
zhanghongyu
8a479cc2ca igmp: call IFF_SET_IPv4 when igmp_send
If the flag is not set, The flag is affected by the previously sent and
received packets, L2 header may be filled with ipv6

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-11-16 07:29:48 -08:00
Zhe Weng
4c99ad1ba9 net/utils: Switch argument order of net_ipv6_pref2mask
When implementing IPv6-related logic, we found the `net_ipv6_pref2mask`
and `net_ipv6addr_copy` are using different argument order:
```
net_ipv6addr_copy(ifaddr->addr, addr);
net_ipv6_pref2mask(preflen, ifaddr->mask);
```
Change the order to:
```
net_ipv6addr_copy(ifaddr->addr, addr);
net_ipv6_pref2mask(ifaddr->mask, preflen);
```

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng
3e4d847f42 net/netdev: Support managing multiple IPv6 addresses by ioctl
1. Supporting `SIOCSIFADDR` and `SIOCDIFADDR` with Linux in6_ifreq struct to manage ipv6 addresses.
   Ref: https://man7.org/linux/man-pages/man7/netdevice.7.html
2. Supporting alias like 'eth0:0' for multiple IPv6 addresses, to keep previous ioctl `SIOCGLIFADDR`, `SIOCSLIFADDR`, `SIOCGLIFNETMASK` and `SIOCSLIFNETMASK` working.
   Ref: https://man7.org/linux/man-pages/man8/ifconfig.8.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng
7f421a46ca net/procfs: Support printing multiple IPv6 address per netdev
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng
2b9633e652 net: Support multiple IPv6 address per netdev
Note that user-space related code, like procfs and lifreq related ioctl commands, are not touched in this commit.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng
96233e0c42 net/netdev: Support multiple IPv6 addresses per device
Compatible with previous usage, because may network drivers are using old member name to print logs, and there's no significant need to change them now.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng
c7845f5b25 netlink: Explicitly set ip address for netlink notify
Prepare for multiple IPv6 addresses per net device, then we can notify
add/remove of a single address later.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-07 19:30:36 +08:00
Zhe Weng
d1c73b6ed6 net/tcp: Support initial sequence number described in RFC 6528
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-06 09:04:09 +08:00
Zhe Weng
5096a2c9fd net/tcp: Take out get random process as common function
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-06 09:04:09 +08:00
zhanghongyu
43ecf36d78 udp: modify ipv4 multicast to allow different conn to join simultaneously
add ref count for ipv4 multicast and leave the multicast group when close
behavior alignment with linux.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-11-04 17:56:06 +08:00
zhanghongyu
3a9c193bf7 ioctl: add SIOCGIWNAME support
some tools use this command to distinguish which device returned via getifaddrs() are wireless network device.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-11-04 17:52:47 +08:00
daniellizewski
c08ccbef02 Usrsock fallback with ENETDOWN 2023-11-03 22:49:27 +08:00
Zhe Weng
c95fd46be3 net: Simplify getting value for different domain
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-11-03 22:23:50 +08:00