Commit Graph

2507 Commits

Author SHA1 Message Date
chao an 6978446b8e net/tcp: remove debug counter of connect instance
Fixed by commit:

 | net: remove pvconn reference from all devif callback
 |
 | Do not use 'pvconn' argument to get the connection pointer since
 | pvconn is normally NULL for some events like NETDEV_DOWN.
 | Instead, the connection pointer can be reliably obtained from the
 | corresponding private pointer.

Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-19 09:46:02 +08:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
chao an 85440f5db6 net/ioctl/cellular: remove redundant logic
Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-15 18:34:07 +08:00
luojun1 ec4af00538 Add Cellular link layer support
1.Add cellular link layer enum definition and register flow
2.Add ioctl flow to set cellular NICs parameters

Signed-off-by: luojun1 <luojun1@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-15 18:34:07 +08:00
chao.an 76c64b7d30 net/tcp: syscall send() should not return ETIMEDOUT
Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-15 10:17:25 +09:00
zhanghongyu 403c657f42 usrsock: combine response and events when socket setup case
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-10-14 12:29:21 +09:00
liangchaozhong c75253623d usrsock:fix blocking socket connect operation hang issue
Issue description:
usrsock will wait for state.recvsem forever because no event triggers
state.recvsem post operation when connect operation in server side is
non-blocking.

Solution:
trigger state.recvsem post operation after receive USRSOCK_EVENT_SENDTO_READY.

Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
2022-10-14 12:29:21 +09:00
zhanghongyu be06d00f85 usrsock: update state to connected when recv sento ready under connecting
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-10-14 12:29:21 +09:00
Fotis Panagiotopoulos 143d1322ea Added handling of MSG_WAITALL flag in TCP recv. 2022-10-13 18:22:05 +08:00
liangchaozhong cc426f8539 usrsock:add done flag in usrsock_iovec_do
set done to true if all data in iovec array is copied

Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
2022-10-11 00:57:49 +08:00
chao an 09bb292fa2 net/igmp: fix build warning on GCC 12.2.0
igmp/igmp_input.c: In function 'igmp_input':
igmp/igmp_input.c:201:31: warning: the comparison will always evaluate as 'false' for the address of 'grpaddr' will never be NULL [-Waddress]
  201 |             if (igmp->grpaddr == 0)
      |                               ^~
In file included from nuttx/include/nuttx/net/netstats.h:67,
                 from igmp/igmp_input.c:53:
nuttx/include/nuttx/net/igmp.h:132:12: note: 'grpaddr' declared here
  132 |   uint16_t grpaddr[2];       /* 32-bit Group address */
      |            ^~~~~~~

Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-11 00:56:13 +08:00
chao an 8e146590a9 net/local: unified formatting name function
fix build warning on GCC 12.2.0

In file included from local/local_fifo.c:25:
In function 'local_hd_name',
    inlined from 'local_open_receiver' at local/local_fifo.c:593:3:
local/local_fifo.c:128:12: warning: '%s' directive output may be truncated writing up to 107 bytes into a region of size 97 [-Wformat-truncation=]
  128 |            CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_HD_SUFFIX, inpath);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~
local/local_fifo.c: In function 'local_open_receiver':
local/local_fifo.c:128:40: note: format string is defined here
  128 |            CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_HD_SUFFIX, inpath);
      |                                        ^~
In function 'local_hd_name',
    inlined from 'local_open_receiver' at local/local_fifo.c:593:3:
local/local_fifo.c:127:3: note: 'snprintf' output between 15 and 122 bytes into a destination of size 109
  127 |   snprintf(outpath, LOCAL_FULLPATH_LEN - 1,
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  128 |            CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_HD_SUFFIX, inpath);
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-11 00:53:57 +08:00
wengzhe 6b7fe6ea8e net/ipforward: fix typo in ipv4_dev_forward
f_domain is used to determine protocol family when CONFIG_NET_IPv4 and CONFIG_NET_IPv6 are both defined, but not correctly used in ipv4_dev_forward because of typo (there's not a config named CONFIG_NET_IPv5) which may cause IPv4 packets to be forwarded as IPv6.

Signed-off-by: wengzhe <wengzhe@xiaomi.com>
2022-10-10 19:31:39 +08:00
raiden00pl d8e329231f let NET_CAN_RAW_FILTER_MAX depends on NET_CANPROTO_OPTIONS to prevent compiler errors 2022-10-05 07:56:54 +08:00
Xiang Xiao bdeaea3742 Remove the unnessary empty line after label
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-30 17:54:56 +02:00
Xiang Xiao 386547676d net: Return -ENOPROTOOPT for unsupported/unknown socket option
so usrsock implementation could support more option than built-in stack

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-28 20:47:48 +09:00
chao an aa42f29465 net/local: remove dead code
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-27 21:31:48 +08:00
chao an 98724477e7 net/procfs: fix runtime error AddressSanitizer(global-buffer-overflow)
NuttShell (NSH) NuttX-10.3.0
ap> ifconfig
=================================================================
Program received signal SIGSEGV, Segmentation fault.
==3920365==ERROR: AddressSanitizer: global-buffer-overflow on address 0x57fb4f2a at pc 0x57177067 bp 0xf1ffebb8 sp 0xf1ffeba8
READ of size 1 at 0x57fb4f2a thread T0

...................
| #10 0xf7ac4339 in __asan::__asan_report_load1 (addr=1476087594) at ../../../../../src/libsanitizer/asan/asan_rtl.cpp:117
| #11 0x57177067 in strncmp (cs=0x57fb4f2a "", ct=0x582d36e0 "stat", nb=4) at string/lib_strncmp.c:40
| #12 0x57f3b467 in netprocfs_opendir (relpath=0x57fb4f26 "net", dir=0xf1ffed80) at procfs/net_procfs.c:398
| #13 0x572b3ae1 in procfs_opendir (mountpt=0xf4602c20, relpath=0x57fb4f26 "net", dir=0xf1ffed80) at procfs/fs_procfs.c:625
| #14 0x572879ff in open_mountpoint (inode=0xf4602c20, relpath=0x57fb4f26 "net", dir=0xf1ffed80) at vfs/fs_dir.c:127
...................

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-27 09:41:55 +08:00
Xiang Xiao 40ef5bc6db libc: Move queue.h from include to include/nuttx
to avoid the conflict with libuv's queue.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-26 08:04:58 +02:00
wangbowen6 344c8be049 poll: add poll_notify() api and call it in all drivers
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-09-26 12:06:32 +08:00
chao an f43be61f69 net/tcp: remove the redundant ifdef CONFIG_NET_TCP
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-26 00:14:49 +09:00
chao an e46688c1ee net/tcp: use independent work to free the conn instance
I noticed that the conn instance will leak during stress test,
The close work queued from tcp_close_eventhandler() will be canceled
by tcp_timer() immediately:

Breakpoint 1, tcp_close_eventhandler (dev=0x565cd338 <up_irq_restore+108>, pvpriv=0x5655e6ff <getpid+12>, flags=0) at tcp/tcp_close.c:71
(gdb) bt
| #0  tcp_close_eventhandler (dev=0x565cd338 <up_irq_restore+108>, pvpriv=0x5655e6ff <getpid+12>, flags=0) at tcp/tcp_close.c:71
| #1  0x5658bf1e in devif_conn_event (dev=0x5660bd80 <g_sim_dev>, flags=512, list=0x5660d558 <g_cbprealloc+312>) at devif/devif_callback.c:508
| #2  0x5658a219 in tcp_callback (dev=0x5660bd80 <g_sim_dev>, conn=0x5660c4a0 <g_tcp_connections>, flags=512) at tcp/tcp_callback.c:167
| #3  0x56589253 in tcp_timer (dev=0x5660bd80 <g_sim_dev>, conn=0x5660c4a0 <g_tcp_connections>) at tcp/tcp_timer.c:378
| #4  0x5658dd47 in tcp_poll (dev=0x5660bd80 <g_sim_dev>, conn=0x5660c4a0 <g_tcp_connections>) at tcp/tcp_devpoll.c:95
| #5  0x5658b95f in devif_poll_tcp_connections (dev=0x5660bd80 <g_sim_dev>, callback=0x565770f2 <netdriver_txpoll>) at devif/devif_poll.c:601
| #6  0x5658b9ea in devif_poll (dev=0x5660bd80 <g_sim_dev>, callback=0x565770f2 <netdriver_txpoll>) at devif/devif_poll.c:722
| #7  0x56577230 in netdriver_txavail_work (arg=0x5660bd80 <g_sim_dev>) at sim/up_netdriver.c:308
| #8  0x5655999e in work_thread (argc=2, argv=0xf3db5dd0) at wqueue/kwork_thread.c:178
| #9  0x5655983f in nxtask_start () at task/task_start.c:129

(gdb) c
Continuing.
Breakpoint 2, tcp_update_timer (conn=0x5660c4a0 <g_tcp_connections>) at tcp/tcp_timer.c:178
(gdb) bt
| #0  tcp_update_timer (conn=0x5660c4a0 <g_tcp_connections>) at tcp/tcp_timer.c:178
| #1  0x5658952a in tcp_timer (dev=0x5660bd80 <g_sim_dev>, conn=0x5660c4a0 <g_tcp_connections>) at tcp/tcp_timer.c:708
| #2  0x5658dd47 in tcp_poll (dev=0x5660bd80 <g_sim_dev>, conn=0x5660c4a0 <g_tcp_connections>) at tcp/tcp_devpoll.c:95
| #3  0x5658b95f in devif_poll_tcp_connections (dev=0x5660bd80 <g_sim_dev>, callback=0x565770f2 <netdriver_txpoll>) at devif/devif_poll.c:601
| #4  0x5658b9ea in devif_poll (dev=0x5660bd80 <g_sim_dev>, callback=0x565770f2 <netdriver_txpoll>) at devif/devif_poll.c:722
| #5  0x56577230 in netdriver_txavail_work (arg=0x5660bd80 <g_sim_dev>) at sim/up_netdriver.c:308
| #6  0x5655999e in work_thread (argc=2, argv=0xf3db5dd0) at wqueue/kwork_thread.c:178
| #7  0x5655983f in nxtask_start () at task/task_start.c:129

Since a separate work will add 24 bytes to each conn instance,
but in order to support the feature of asynchronous close(),
I can not find a better way than adding a separate work,
for resource constraints, I recommend the developers to enable
CONFIG_NET_ALLOC_CONNS, which will reduce the ram usage.

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-22 23:33:00 +08:00
Xiang Xiao f4812e0a83 net: Implement SO_RCVBUF and SO_SNDBUF for getsockopt
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-21 09:03:20 +02:00
chao an 8b238e0b3d net/wireless: separate command catagory of bt/pktradio from wireless ioctl
1. separate command catagory of bt/pktradio from wireless ioctl
2. Remove commoand count limit to support vendor command

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-20 01:16:22 +08:00
Xiang Xiao 8a265e274d Kconfig: Remove EXPERIMENTAL for features which is been around a long time
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-19 11:39:22 -03:00
chao an f286012c0d net/procfs: disable tcp/udp proc node if no stack available
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-19 15:45:19 +08:00
Nathan Hartman d09304008e net: Fix sa_family returned by SIOCGIFHWADDR
* net/netdev/netdev_ioctl.c:
  (netdev_ifr_ioctl): The ioctl SIOCGIFHWADDR provides the hardware
   address (e.g., Ethernet MAC, etc.) of a network interface. It is
   based on Linux. (BSD-based systems don't have this ioctl.) The Linux
   implementation sets sa_family to ARPHRD_ETHER for Ethernet and IEEE
   802.11 interfaces [1]. NuttX was setting it to NET_SOCK_FAMILY for
   these interface types as well as 6LoWPAN and PKTRADIO; this was
   incorrect and also the value of NET_SOCK_FAMILY varies based on
   Kconfig settings. Correcting this to ARPHRD_ETHER for Ethernet and
   IEEE 802.11 and ARPHRD_IEEE802154 for 6LoWPAN and PKTRADIO.

References:
[1] 'man 7 netdevice' on Linux.
2022-09-16 02:59:50 +08:00
Nathan Hartman 6c4bd5c5ef net: Fix memcpy() size used by SIOCSIFHWADDR for radios
* net/netdev/netdev_ioctl.c:
  (netdev_ifr_ioctl): The ioctl SIOCSIFHWADDR sets the hardware address
   (e.g., Ethernet MAC, etc.) of a network interface. Radio devices may
   have different lengths of hardware addresses, such as
   NET_6LOWPAN_EADDRSIZE (8), NET_6LOWPAN_SADDRSIZE (2), or
   RADIO_MAX_ADDRLEN (8). Also, Kconfig CONFIG_PKTRADIO_ADDRLEN allows
   the user to set any arbitrary size. Note that while the sister ioctl
   SIOCGIFHWADDR "get hardware address" copies
   `dev->d_mac.radio.nv_addrlen` bytes, SIOCSIFHWADDR was copying
   NET_6LOWPAN_ADDRSIZE bytes unconditionally. Depending on which radio
   is used, this could be incorrect. Fixing it to use
   `dev->d_mac.radio.nv_addrlen` for SIOCSIFHWADDR as well. Also adding
   DEBUGASSERT to ensure this is within bounds of source and
   destination of the copy.
2022-09-16 02:59:40 +08:00
Xiang Xiao b400b99001 net/usrsock: Simplify the return value process of net_timedwait
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-11 10:08:04 +09:00
Xiang Xiao 77823415ed net/usrsock: Remove the unnecessary blank line
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-11 10:08:04 +09:00
Xiang Xiao 3269c1a102 net/usrsock: Remove the unnecessary label
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-11 10:08:04 +09:00
Xiang Xiao 3d0985df39 net/usrsock: Remove the unnecessary extra space
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-11 10:08:04 +09:00
liangchaozhong 5ec4296553 move usrsock_dev.c to driver folder
Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
2022-09-10 13:08:22 +08:00
Xiang Xiao ed85055edb udp: Remove the unnessary check of addr size in udp_readahead
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-09 17:21:33 +02:00
Xiang Xiao 7f26b92130 udp: Don't accumulate the receive length in psock_udp_recvfrom
since udp_recvfrom_newdata is called no more than once

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-09 17:21:33 +02:00
liangchaozhong 644c4afeed usrsock:refine usrsock's architecture
Seperate usrsock device driver with usrsock core function layer
to make it more flexiable to adopt other kind of usrsock interface driver

Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
2022-09-09 20:56:12 +09:00
chao an d10cd8d585 net/procfs: add udp profs support
add proc node /proc/net/udp to show the active udp connections from procfs

nuttx style:

server> cat /proc/net/udp
UDP sl     local_address          remote_address     flg   txsz   rxsz  (IPv4)
  1:          0.0.0.0:  5285    192.168.31.22:  7779   9      0   1041
  2:          0.0.0.0:  5286    192.168.31.22:  7779   9      0   1041
  3:          0.0.0.0:  5287    192.168.31.22:  7779   9      0   1041

linux kernel:
https://www.kernel.org/doc/Documentation/networking/proc_net_tcp.txt

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-09 19:33:46 +08:00
chao an 7190e56a14 net/procfs: add tcp profs support
add proc node /proc/net/tcp to show the active tcp connections from procfs

nuttx style:

server> cat /proc/net/tcp
TCP sl  st flg ref tmr uack nrt   rxsz local_address           remote_address
     1: 04  61   1  12    0   0   1024          0.0.0.0:4855      192.168.31.22:5001
     2: 04  61   1  12    0   0   1024          0.0.0.0:4856      192.168.31.22:5001
     3: 04  61   1   9    0   0      0                      :::4853   fe80::b27b:25ff:fe28:4011:8789
     4: 04  61   1   3    3   0      0                      :::4854   fe80::b27b:25ff:fe28:4011:8789

linux kernel:
https://www.kernel.org/doc/Documentation/networking/proc_net_tcp.txt

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-09 19:33:46 +08:00
chao an b6e76966b9 net/procfs: interface index should begin from 1
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-08 18:09:43 +09:00
chao an 66d9397320 netdev/ioctl: netlock/unlock() should in pairs
fix regression by:

commit fd53db56b6
Author: chao an <anchao@xiaomi.com>
Date:   Wed Sep 7 10:56:09 2022 +0800

    net/netdev: simplify handling of netdev ifr ioctl()

    1. call netdev_ifr_dev() only once
    2. unify the error code of ENODEV

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-08 15:50:45 +08:00
chao an fd53db56b6 net/netdev: simplify handling of netdev ifr ioctl()
1. call netdev_ifr_dev() only once
2. unify the error code of ENODEV

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-08 11:05:13 +08:00
chao an 4068b2eccc net/procfs: add entry mapping table
add entry mapping table to simplify new component registration

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-08 09:03:34 +08:00
chao an 3913ef2f2f net/inet: invalid addrlen length should return EINVAL
https://www.freebsd.org/cgi/man.cgi?connect

[EINVAL] The namelen argument is not a valid length for the address family.

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-08 09:02:30 +08:00
zhanghongyu 9bff29d7e7 udp: add IPVx_PKTINFO related support
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-09-07 10:49:47 +08:00
chao an 54dba40f87 net/netdev/ioctl: correct the argument length of ioctl MII/PHY
Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-07 03:33:41 +08:00
Xiang Xiao 9726be616a fs: Run the default action of FIONBIO/FIOCLEX/FIONCLEX in success path
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-06 23:16:15 +08:00
Xiang Xiao e0bb281e7a net: Align the prototype of sock_intf_s::si_ioctl with file_operations::ioctl
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-06 22:46:37 +08:00
chao an 0978dcf88d net/mld/route: fix build warning
In file included from route/net_del_ramroute.c:30:
route/net_del_ramroute.c: In function ‘net_match_ipv4’:
route/net_del_ramroute.c:93:9: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
   93 |   ninfo("  target=%08lx netmask=%08lx\n",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
route/net_del_ramroute.c:93:23: note: format string is defined here
   93 |   ninfo("  target=%08lx netmask=%08lx\n",
      |                   ~~~~^
      |                       |
      |                       long unsigned int
      |                   %08x

mld/mld_timer.c: In function ‘mld_gendog_work’:
mld/mld_timer.c:118:13: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  118 |   ifindex = (int)arg;
      |             ^
mld/mld_timer.c: In function ‘mld_v1dog_work’:
mld/mld_timer.c:237:13: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  237 |   ifindex = (int)arg;
      |             ^

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-06 18:24:20 +08:00
chao an 63cd44e5e1 net/usrsock: forward FIONBIO to socket level
fix usrsock nonblock connect test break:

apps/examples/usrsocktest/usrsocktest_noblock_connect.c:

...
157 TEST(no_block_connect, delayed_connect)
158 {
...
190   ret = fcntl(sd, F_SETFL, flags | O_NONBLOCK);
...
204   ret = connect(sd, (FAR const struct sockaddr *)&addr, sizeof(addr));
205   TEST_ASSERT_EQUAL(-1, ret);
206   TEST_ASSERT_EQUAL(EINPROGRESS, errno);

should goahead to socket level:

nuttx/net/netdev/netdev_ioctl.c:
...
1755 int psock_vioctl(FAR struct socket *psock, int cmd, va_list ap)
1756 {
...
1771   ret = netdev_ioctl(psock, cmd, arg);
...
1775   if (ret == -ENOTTY)
1776     {
1777       ret = netdev_file_ioctl(psock, cmd, arg);
1778     }
...

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-01 14:44:50 +08:00
Masayuki Ishikawa aaae317d0c Revert "net/usrsock: read from the closed remote should return EOF"
This reverts commit 3a653c1d5e.
2022-09-01 13:16:46 +09:00