Commit Graph

2943 Commits

Author SHA1 Message Date
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
raiden00pl 5b87fdfb9d Documentation: remove all migrated READMEs 2023-10-29 21:03:54 -03:00
raiden00pl b565e28da3 Kconfigs: rename {Rpmsg|rpmsg} to RPMGS 2023-10-28 13:58:56 +08:00
dongjiuzhu1 73dc8f84cc fs/dup3: impletement dup3/nx_dup3_from_tcb function
refs: https://man7.org/linux/man-pages/man2/dup.2.html

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-27 21:15:07 +08:00
Zhe Weng 9ef2a48919 net/local: Support `SO_SNDBUF` option in `getsockopt`
For datagram unix sockets, the `SO_SNDBUF` value imposes an upper limit on the size of outgoing datagrams.

Note: We don't support to change the buffer size yet, so only add support to getsockopt now.
Refs: https://man7.org/linux/man-pages/man7/unix.7.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-10-25 01:13:56 +08:00
Zhe Weng ef1ad691c3 net/icmpv6: Fix net mask logic in `icmpv6_setaddresses`
1. Both IPv6 addresses and net masks should be stored in network byte
   order
2. Fix last 2 bytes of mask applying (although it seldom triggers)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-10-24 10:31:14 -03:00
Alan Carvalho de Assis 4741ef7ca7 net: Fix RNDIS compilation error
The minimum value to CONFIG_NET_LL_GUARDSIZE work
with USB RNDIS support is 50.
2023-10-16 08:55:21 +08:00
liqinhui 3f08f32486 net: allow icmpv6 and udp to find the dev by the ifindex with s_boundto.
In order to support the dhcpv6c.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-10-11 23:34:01 +08:00
Xiang Xiao 21beb284bc net/usersock: Return -ENOSUPP directly if domain isn't equal to PF_INET/PF_INET6
regression by https://github.com/apache/nuttx/pull/9647

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-09 18:04:29 -04:00
liqinhui 8014f51cc1 net/local: Allow the local udp socketpair function to use the local_release_fifos interface.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-09-27 19:28:02 +08:00
Petteri Aimonen bedcc5fc04 Add CONFIG_NET_ICMPv6_ROUTER_LIFETIME
Allows setting the advertised route lifetime, and also to set
it to 0 for advertising only the prefix.

From RFC4861:

   A router might want to send Router Advertisements without advertising
   itself as a default router.  For instance, a router might advertise
   prefixes for stateless address autoconfiguration while not wishing to
   forward packets.  Such a router sets the Router Lifetime field in
   outgoing advertisements to zero.
2023-09-27 00:51:20 +08:00
ligd 00c0801743 local socket: fix accept used after free
==1729315==ERROR: AddressSanitizer: heap-use-after-free on address 0xf0501d60 at pc 0x032ffe43 bp 0xef4ed158 sp 0xef4ed148
READ of size 2 at 0xf0501d60 thread T0
    #0 0x32ffe42 in nxsem_wait semaphore/sem_wait.c:94
    #1 0x3548cf5 in _net_timedwait utils/net_lock.c:97
    #2 0x3548f48 in net_sem_timedwait utils/net_lock.c:236
    #3 0x3548f8c in net_sem_wait utils/net_lock.c:318
    #4 0x350124d in local_accept local/local_accept.c:246
    #5 0x3492719 in psock_accept socket/accept.c:149
    #6 0x3492bcc in accept4 socket/accept.c:280
    #7 0x662dc04 in accept net/lib_accept.c:50
    #8 0x55c81ab in kvdb_loop kvdb/server.c:415
    #9 0x55c860a in kvdbd_main kvdb/server.c:458
    #10 0x33d968b in nxtask_startup sched/task_startup.c:70
    #11 0x32ec039 in nxtask_start task/task_start.c:134
    #12 0x34109be in pre_start sim/sim_initialstate.c:52

0xf0501d60 is located 288 bytes inside of 420-byte region [0xf0501c40,0xf0501de4)
freed by thread T0 here:
    #0 0xf7aa6a3f in __interceptor_free ../../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x73aa06e in host_free sim/posix/sim_hostmemory.c:192
    #2 0x34131d6 in mm_free sim/sim_heap.c:230
    #3 0x3409388 in free umm_heap/umm_free.c:49
    #4 0x35631f3 in local_free local/local_conn.c:225
    #5 0x3563f75 in local_release local/local_release.c:129
    #6 0x34f5a32 in local_close local/local_sockif.c:785
    #7 0x3496ee8 in psock_close socket/net_close.c:102
    #8 0x36500bc in sock_file_close socket/socket.c:115
    #9 0x3635f6c in file_close vfs/fs_close.c:74
    #10 0x3632439 in nx_close_from_tcb inode/fs_files.c:670
    #11 0x36324f3 in nx_close inode/fs_files.c:697
    #12 0x3632557 in close inode/fs_files.c:735
    #13 0x55be289 in property_set_ kvdb/client.c:210
    #14 0x55c0309 in property_set_int32_ kvdb/common.c:226
    #15 0x55c03f5 in property_set_int32_oneway kvdb/common.c:236

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-24 10:42:35 +08:00
wanggang26 d827ee5ffc refine: set file mode when oflags contains O_CREAT
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-23 15:20:51 +08:00
wanggang26 e930476b4b enable O_CLOEXEC explicit
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-22 13:51:00 +08:00
SPRESENSE a35ba1e7bc net: Create fallback option for usrsock
Changed implementation to use the Kernel network stack when
usrsock daemon returns an error.

This change allows the Kernel network stack to be used instead
of UsrSock when opening a Socket at a time when a VPN configured
with TUN is enabled.
2023-09-21 01:08:11 +08:00
SPRESENSE 011d45e956 net/usrsock: Can enable TCP/UDP IP stack with Usrsock enabled
Some use cases, such as VPN, use both the device's network
stack with the Usrsock daemon and the Kernel's network stack.
Therefore, remove NET_TCP_NO_STACK/NET_UDP_NO_STACK select
from Usrsock's Kconfig.
2023-09-21 01:08:11 +08:00
zhanghongyu 55d5006462 tcp_ofosegs: prepare iob to reset io_offset
The previous iob_trimhead added dev->iob->io_offset, so if the
input frame is not merged into the ofo segment, we need to reset
dev->iob->io_offset so that the subsequent tcp_send can properly
assemble packets.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-20 14:32:16 +08:00
zhanghongyu 1389a686ba tcp: fix coverity warning for tcp_timer
use after free when the number of retransmissions reached the maximum.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-19 09:37:20 +08:00
ligd c9bc6b1ad5 rpmsg socket: add return value check.
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-09-19 09:33:30 +08:00
chao an 5026a96cfa nxstyle: cleanup UTF-8 Unicode to ASCII
Signed-off-by: chao an <anchao@xiaomi.com>
2023-09-18 11:54:17 -04:00