Commit Graph

2485 Commits

Author SHA1 Message Date
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
chao an
5d4c774352 net/usrsock: allow usrsock *DATA_ACK with no-preload data
allow usrsock USRSOCK_MESSAGE_RESPONSE_DATA_ACK with no-preload data
so addrlen could be updated to valuelen_nontrunc of usrsock_message_datareq_ack_s

nsh> usrsocktest
...
Testing group "basic_getsockname" =>
	[TEST ASSERT FAILED!]
		In function "basic_getsockname_open":
		line 170: Assertion `(ssize_t)((ret)) == (ssize_t)((0))' failed.
			got value: -1
			should be: 0
	Group "basic_getsockname": [FAILED]

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-01 09:09:25 +09:00
chao an
3a653c1d5e net/usrsock: read from the closed remote should return EOF
fix usrsock remote_disconnect fail:

nsh> usrsocktest
...
Testing group "remote_disconnect" =>
	[TEST ASSERT FAILED!]
		In function "receive":
		line 497: Assertion `(ssize_t)((ret)) == (ssize_t)((0))' failed.
			got value: -1
			should be: 0
	Group "remote_disconnect": [FAILED]
...

Reference:

RECV(2)

NAME
       recv, recvfrom, recvmsg - receive a message from a socket
...
RETURN VALUE
...
       When a stream socket peer has performed an orderly shutdown,
       the return value will be 0 (the traditional "end-of-file" return).

       Datagram sockets in various domains (e.g., the UNIX and Internet domains)
       permit zero-length datagrams.  When such a datagram is received, the return value is 0.

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-01 08:48:26 +09:00
chao an
fe7badf2ac net/getsockname: small addrlen should be a valid value
fix usrsock getsockname fail

nsh> usrsocktest
...
Testing group "basic_getsockname" =>
	[TEST ASSERT FAILED!]
		In function "basic_getsockname_open":
		line 170: Assertion `(ssize_t)((ret)) == (ssize_t)((0))' failed.
			got value: -1
			should be: 0
	Group "basic_getsockname": [FAILED]
...

Reference:

GETSOCKNAME(2)

NAME
       getsockname - get socket name
...
DESCRIPTION
...
       The returned address is truncated if the buffer provided is too small;
       in this case, addrlen will return a value greater than was supplied to the call.

Signed-off-by: chao an <anchao@xiaomi.com>
2022-09-01 01:19:09 +08:00
chao an
6f27c29ce5 net/usrsock: Change xid from uint64_t to uint32_t
follow the below change:
  -----------------------------------------------
  commit 0334819742
  Author: Xiang Xiao <xiaoxiang@xiaomi.com>
  Date:   Mon Aug 22 05:10:47 2022 +0800

      net/usrsock: Change xid from uint64_t to uint32_t

      by generating the new xid for each transaction

      Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>

Signed-off-by: chao an <anchao@xiaomi.com>
2022-08-31 19:01:29 +02:00
chao.an
bf6cbbca5d net/tcp: fix devif callback list corruption on tcp_close()
devif_conn_event() will be called recursively in the psock_send_eventhandler(),
if the tcp event tcp_close_eventhandler() is marked as "next" in first devif_conn_event()
and released from sencond recursive call, the "next" event in the first devif_conn_event()
will become a wild pointer.

479 uint16_t devif_conn_event(FAR struct net_driver_s *dev, uint16_t flags,
480                           FAR struct devif_callback_s *list)
481 {
482   FAR struct devif_callback_s *next;
...
488   net_lock();
489   while (list && flags)
490     {
...
496       next = list->nxtconn;  <------------------  event tcp_close_eventhandler() on next
...
500       if (list->event != NULL && devif_event_trigger(flags, list->flags))
501         {
...
507           flags = list->event(dev, list->priv, flags);  <---------------- perform  psock_send_eventhandler(), event tcp_close_eventhandler() will be remove from tcp_lost_connection()
508         }
...
512       list = next;  <---------------- event tcp_close_eventhandler() has been released, wild pointer
513     }
514
515   net_unlock();
516   return flags;
517 }

The callstack as below:

Breakpoint 1, tcp_close_eventhandler (dev=0x56607d80 <g_sim_dev>, pvpriv=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_close.c:83
(gdb) bt
| #0  tcp_close_eventhandler (dev=0x56607d80 <g_sim_dev>, pvpriv=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_close.c:83
| #1  0x5658bb57 in devif_conn_event (dev=0x56607d80 <g_sim_dev>, flags=65, list=0x56609498 <g_cbprealloc+312>) at devif/devif_callback.c:507
                    ----------------> devif_conn_event() recursively
| #2  0x56589f8c in tcp_callback (dev=0x56607d80 <g_sim_dev>, conn=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_callback.c:169
| #3  0x565c55e4 in tcp_shutdown_monitor (conn=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_monitor.c:211
| #4  0x565c584b in tcp_lost_connection (conn=0x566084a0 <g_tcp_connections>, cb=0x566094b0 <g_cbprealloc+336>, flags=65) at tcp/tcp_monitor.c:391
| #5  0x565c028a in psock_send_eventhandler (dev=0x56607d80 <g_sim_dev>, pvpriv=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_send_buffered.c:544
                    ----------------> call psock_send_eventhandler() before tcp_close_eventhandler()
| #6  0x5658bb57 in devif_conn_event (dev=0x56607d80 <g_sim_dev>, flags=65, list=0x566094b0 <g_cbprealloc+336>) at devif/devif_callback.c:507
| #7  0x56589f8c in tcp_callback (dev=0x56607d80 <g_sim_dev>, conn=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_callback.c:169
| #8  0x5658e8cc in tcp_input (dev=0x56607d80 <g_sim_dev>, domain=2 '\002', iplen=20) at tcp/tcp_input.c:1059
| #9  0x5658ed77 in tcp_ipv4_input (dev=0x56607d80 <g_sim_dev>) at tcp/tcp_input.c:1355
| #10 0x5658c0a2 in ipv4_input (dev=0x56607d80 <g_sim_dev>) at devif/ipv4_input.c:358
| #11 0x56577017 in netdriver_recv_work (arg=0x56607d80 <g_sim_dev>) at sim/up_netdriver.c:182
| #12 0x5655999e in work_thread (argc=2, argv=0xf3db5dd0) at wqueue/kwork_thread.c:178
| #13 0x5655983f in nxtask_start () at task/task_start.c:129
(gdb) c
Continuing.
Breakpoint 1, tcp_close_eventhandler (dev=0x56607d80 <g_sim_dev>, pvpriv=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_close.c:83
(gdb) bt
| #0  tcp_close_eventhandler (dev=0x56607d80 <g_sim_dev>, pvpriv=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_close.c:83
      ----------------------> "next" corrupted, invaild call tcp_close_eventhandler()
| #1  0x5658bb57 in devif_conn_event (dev=0x56607d80 <g_sim_dev>, flags=65, list=0x56609498 <g_cbprealloc+312>) at devif/devif_callback.c:507
| #2  0x56589f8c in tcp_callback (dev=0x56607d80 <g_sim_dev>, conn=0x566084a0 <g_tcp_connections>, flags=65) at tcp/tcp_callback.c:169
| #3  0x5658e8cc in tcp_input (dev=0x56607d80 <g_sim_dev>, domain=2 '\002', iplen=20) at tcp/tcp_input.c:1059
| #4  0x5658ed77 in tcp_ipv4_input (dev=0x56607d80 <g_sim_dev>) at tcp/tcp_input.c:1355
| #5  0x5658c0a2 in ipv4_input (dev=0x56607d80 <g_sim_dev>) at devif/ipv4_input.c:358
| #6  0x56577017 in netdriver_recv_work (arg=0x56607d80 <g_sim_dev>) at sim/up_netdriver.c:182
| #7  0x5655999e in work_thread (argc=2, argv=0xf3db5dd0) at wqueue/kwork_thread.c:178
| #8  0x5655983f in nxtask_start () at task/task_start.c:129
(gdb) c
Continuing.
[    2.680000] up_assert: Assertion failed at file:devif/devif_callback.c line: 85 task: lpwork

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-30 19:41:18 +08:00
chao.an
162fcd10ca net: cleanup pvconn reference to avoid confuse
More reference:
https://github.com/apache/incubator-nuttx/pull/5252
https://github.com/apache/incubator-nuttx/pull/5434

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-26 20:58:11 +08:00
chao.an
ea621599fd 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-08-26 20:58:11 +08:00
chao.an
77a99acc98 net/icmpv6: fix build break "duplicate macro parameter"
Error: net/icmpv6/icmpv6.h:442:33: error: duplicate macro parameter "d"
 #  define icmpv6_setaddresses(d,d,p,p) (0)

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-26 10:00:22 +02:00
zhanghongyu
cc421e43e4 icmpv6: add NTOHL when parse ICMPV6 option MTU
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-26 10:00:22 +02:00
luojun1
00cf3e559d update IPv6 NIC parameters unconditionally when ICMPv6 RA is received
Signed-off-by: luojun1 <luojun1@xiaomi.com>
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-26 10:00:22 +02:00
luojun1
7c2986bb34 finetune the RA parsing procedure
Signed-off-by: luojun1 <luojun1@xiaomi.com>
Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-26 10:00:22 +02:00
Fotis Panagiotopoulos
9bc47ecdce Added lock in ifr ioctl calls. 2022-08-25 14:02:20 +02:00
chao.an
9cb17841d8 net/sockopt: move BINDTODEVICE to socket level
rename the UDP_BINDTODEVICE to SO_BINDTODEVICE to follow the linux
style to be compatible with non-UDP protocol binding requirements

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-08-25 17:56:52 +08:00
Huang Qi
e4e3208180 Replace all strncpy with strlcpy for safety
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-08-25 13:38:36 +08:00
chengkai
841d8f5b37 net:add btsnoop and snoop
Signed-off-by: chengkai <chengkai@xiaomi.com>
2022-08-24 21:42:30 +08:00
Xiang Xiao
0334819742 net/usrsock: Change xid from uint64_t to uint32_t
by generating the new xid for each transaction

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-23 12:16:33 -03:00
Xiang Xiao
697e2a333b net/usrsock: Remove dev field from usrsockdev_s
since this field isn't really used at all

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-22 17:49:51 +03:00
zhanghongyu
e03c2c321a tcp: reset conn->nrtx when ack received
Otherwise, when a long test triggers multiple timeout retransmissions,
the late timeout retransmissions are always delayed between 24 and 48 seconds

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-08-17 21:35:09 +03:00
Xiang Xiao
ba9486de4a iob: Remove iob_user_e enum and related code
since it is impossible to track producer and consumer
correctly if TCP/IP stack pass IOB directly to netdev

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-15 08:41:20 +03:00
Xiang Xiao
838690fc9f net/local: Remove the sync preamble from datagram
since pipe is a reliable transport, the sync just waste the space and time

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-08-10 09:50:25 +03:00
Jiuzhu Dong
fe17f747a7 fs/directory: move private directory information to filesystem
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-08-09 23:30:01 +08:00
Jiuzhu Dong
90db4daca9 fs/directory: update readdir interface for all filesystem
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2022-08-09 23:30:01 +08:00