Commit Graph

2723 Commits

Author SHA1 Message Date
liangchaozhong
7e80879f88 usrsock: Output the log if usrsock_request return error
Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
2023-01-28 16:27:21 +09:00
liangchaozhong
cc940e8f69 net_lock:fix deadlock issue when running iperf tx test on usrsock
Issue Description:
deadlock happens when runnging iperf TCP tx on usrsock with the
following commands:
device command: iperf2 -c <PC IP address> -u -i 1 -p 1122  -t 10
PC command: iperf -s -u -i 1 -p 1122

iperf's thread holds net_lock before call usrsock_setup_request_callback
and waits for conn->resp.sem by calling
nxsem_wait_uninterruptible(&conn->resp.sem), while conn->resp.sem
can only be signaled in usrsock_response, who is waiting for net_lock in
tptun's thread.

Solution:
call net_lockedwait_uninterruptible to make sure net_lock can be
released when conn->resp.sem is not available.

Here's the backtrace:
up_block_task
nuttx/arch/arm/src/common/arm_blocktask.c:151
nxsem_wait
nuttx/sched/semaphore/sem_wait.c:185 (discriminator 2)
nxsem_wait_uninterruptible
nuttx/sched/semaphore/sem_wait.c:223 (discriminator 1)
usrsock_setup_request_callback
nuttx/net/usrsock/usrsock_conn.c:228
usrsock_setup_data_request_callback
nuttx/net/usrsock/usrsock_conn.c:257
usrsock_getsockopt
nuttx/net/usrsock/usrsock_getsockopt.c:202
psock_getsockopt
nuttx/net/socket/getsockopt.c:448
getsockopt
nuttx/net/socket/getsockopt.c:515
getsock_tcp_windowsize
external/iperf2/iperf2/src/tcp_window_size.c:165
reporter_reportsettings
external/iperf2/iperf2/src/ReportDefault.c:384
reporter_print
external/iperf2/iperf2/src/Reporter.c:1402
reporter_process_report
external/iperf2/iperf2/src/Reporter.c:860
reporter_process_report
external/iperf2/iperf2/src/Reporter.c:828
reporter_spawn
external/iperf2/iperf2/src/Reporter.c:720
thread_run_wrapper
external/iperf2/iperf2/compat/Thread.c:270
pthread_startup
nuttx/libs/libc/pthread/pthread_create.c:59 (discriminator 2)
pthread_start
nuttx/sched/pthread/pthread_create.c:182 (discriminator 4)

up_block_task
nuttx/arch/arm/src/common/arm_blocktask.c:151
nxsem_wait
nuttx/sched/semaphore/sem_wait.c:185 (discriminator 2)
sem_wait
nuttx/sched/semaphore/sem_wait.c:271
nxmutex_lock
nuttx/include/nuttx/mutex.h:165
nxrmutex_lock
nuttx/include/nuttx/mutex.h:369
usrsock_handle_req_response
nuttx/net/usrsock/usrsock_devif.c:466
usrsockdev_write
nuttx/drivers/usrsock/usrsock_dev.c:304
file_write
nuttx/fs/vfs/fs_write.c:90
usrsock_rpmsg_default_handler
apps/netutils/usrsock_rpmsg/usrsock_rpmsg_client.c:137
rpmsg_virtio_rx_callback
nuttx/openamp/open-amp/lib/rpmsg/rpmsg_virtio.c:371
virtqueue_notification
nuttx/openamp/open-amp/lib/virtio/virtqueue.c:706
rproc_virtio_notified
nuttx/openamp/open-amp/lib/remoteproc/remoteproc_virtio.c:337 (discriminator 2)
remoteproc_get_notification
nuttx/openamp/open-amp/lib/remoteproc/remoteproc.c:999
rptun_worker
nuttx/drivers/rptun/rptun.c:333
rptun_thread
nuttx/drivers/rptun/rptun.c:364 (discriminator 1)
nxtask_start
nuttx/sched/task/task_start.c:144

Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
2023-01-28 16:27:21 +09:00
zhanghongyu
99c2d2009a udp: remove DEBUGASSERT for ip6_is_ipv4addr
fix build break if enable CONFIG_NET_IPv6 only

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-28 09:04:29 +02:00
zhanghongyu
c1521b2ef2 tcp: add TCP_ACKDATA flag to close event callback
The close package cannot be sent in time without TCP_ACKDATA

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-28 09:02:42 +02:00
zhanghongyu
3725fe28fb tcp: fix trans data error when fast retrans
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-28 09:02:14 +02:00
liangchaozhong
fbe641a916 socket:return -EAGAIN if timeout happends in psock_tcp_send
psock_tcp_send will enter busyloop state when no IOB keeps at unavailable state
when the socket is blocking socket and this will cause WDT.
According to socket's manpage, -1 should be returned while errno set to EAGAIN
if send/recv timeout was set.

Here's the description:
SO_RCVTIMEO and SO_SNDTIMEO
Specify the receiving or sending timeouts until reporting an error. The argument is a struct timeval. If an input or output function blocks for this period of time, and data has been sent or received, the return value of that function will be the amount of data transferred; if no data has been transferred and the timeout has been reached then -1 is returned with errno set to EAGAIN or EWOULDBLOCK, or EINPROGRESS (for connect(2)) just as if the socket was specified to be nonblocking. If the timeout is set to zero (the default) then the operation will never timeout. Timeouts only have effect for system calls that perform socket I/O (e.g., read(2), recvmsg(2), send(2), sendmsg(2)); timeouts have no effect for select(2), poll(2), epoll_wait(2), and so on.

Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
2023-01-28 08:06:57 +02:00
David
22feaeeebb Bugfixed the SocketCAN send via setting the dev->d_len to dev->d_sndlen. The dev->d_len wouldn't be assigned otherwise. 2023-01-27 23:08:05 +08:00
Masayuki Ishikawa
dc454765fb Revert "add holder for mutex"
This reverts commit fc176addeb.
2023-01-19 06:04:48 +09:00
lilei19
fc176addeb add holder for mutex
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-01-18 17:40:58 +08:00
chao an
64dd7e6376 net/tcp: add Selective-ACK support
Reference:
https://datatracker.ietf.org/doc/html/rfc2018

Iperf2 client/server test on esp32c3:

Drop(1/50):
CONFIG_NET_TCP_DEBUG_DROP_SEND=y
CONFIG_NET_TCP_DEBUG_DROP_SEND_PROBABILITY=50  // Drop probability: 1/50
CONFIG_NET_TCP_DEBUG_DROP_RECV=y
CONFIG_NET_TCP_DEBUG_DROP_RECV_PROBABILITY=50  // Drop probability: 1/50

Drop(1/50) + OFO/SACK:
CONFIG_NET_TCP_DEBUG_DROP_SEND=y
CONFIG_NET_TCP_DEBUG_DROP_SEND_PROBABILITY=50  // Drop probability: 1/50
CONFIG_NET_TCP_DEBUG_DROP_RECV=y
CONFIG_NET_TCP_DEBUG_DROP_RECV_PROBABILITY=50  // Drop probability: 1/50

CONFIG_NET_TCP_OUT_OF_ORDER=y
CONFIG_NET_TCP_SELECTIVE_ACK=y

---------------------------------------------------------
|  TCP Config            | Server | Client |            |
|-------------------------------------------------------|
|  Original              |   12   |     9  |  Mbits/sec |
|  Drop(1/50)            |  0.6   |   0.3  |  Mbits/sec |
|  Drop(1/50) + OFO/SACK |    8   |     8  |  Mbits/sec |
---------------------------------------------------------

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 16:24:09 +08:00
chao an
c581cc5f9b net/tcp: parse tcp options in common function
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 16:24:09 +08:00
chao an
d175f50f01 net/tcp: add out-of-order segment support
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 16:24:09 +08:00
chao an
0e7d397553 net/tcp: new api tcp_dataconcat() to concatenate/pack iob chain
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 16:24:09 +08:00
Zhe Weng
1cf3147626 net/netdev: Avoid hardcoded guardsize when using d_iob
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-18 14:41:07 +08:00
chao an
2afa1b3b64 net/udp: correct linger timeout
UDP linger timeout will be wrongly converted to UINT_MAX by _SO_TIMEOUT() when it is set to 0,

net/socket/socket.h:
|
| #  define _SO_TIMEOUT(t) ((t) ? (t) * MSEC_PER_DSEC : UINT_MAX)

net/udp/udp_close.c:
|
| if (_SO_GETOPT(conn->sconn.s_options, SO_LINGER))
|   {
|     timeout = _SO_TIMEOUT(conn->sconn.s_linger);
|   }

this change will correct this behavior, if the linger is set to 0, the timeout value should be 0

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 02:47:12 +08:00
chao an
1f75d02bb5 net/tcp: correct behavior of SO_LINGER
1. Remove tcp_txdrain() from close() to avoid indefinitely block
2. Send TCP_RST immediately if linger timeout

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 02:47:12 +08:00
chao an
fa6ba05097 net/tcp: move drop send source code to correct place
Merge conflicts lead to code being placed in thre wrong place
The debug code should placed in tcp_send() not tcp_synack()

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 02:12:43 +08:00
chao an
9ae7119a39 net/devif: bypass send length check if ip fragment enabled
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 02:12:02 +08:00
chao an
715785245c net/tcp: fix potential busy loop in tcp_send_buffered.c
if the wrbuffer does not have enough space to send the rest of
the data, then the send function will loop infinitely in nonblock
mode, add send timeout check to avoid this issue.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-18 02:11:33 +08:00
ligd
1b333bfad5 rpmsg_socket: destroy_ept only at close
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 02:11:16 +08:00
ligd
a7dea8ddf6 rpmsg_socket: shouldn't call create_device again after create_ept
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 02:11:16 +08:00
ligd
d6cad21a17 rpmsg_socket: rpmsg_send_nocpy() should lock with rpmsg_destroy_ept
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 02:11:16 +08:00
ligd
c0735f06f6 rpmsg_socket: release tx buffer when send_oncopy failed
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 02:11:16 +08:00
luojun1234
ff3733b5b5 Support fragmentation and reassembly
Signed-off-by: luojun1 <luojun1@xiaomi.com>
2023-01-17 14:01:37 +08:00
crafcat7
2ec117b3ca fs/fs_fsync:Fix the expected error of socket,fifo and pipe returning error in fsync case 2023-01-17 01:56:40 +08:00
Xiang Xiao
a851ad84c3 net: consistent the net sem wait naming conversion
to prepare the new mutex wait function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-15 12:31:30 -03:00
chao an
22348c890b net/tcp: debug feature to drop the tx/rx packet
Add 2 configurations
1. Config to drop recived packet
CONFIG_NET_TCP_DEBUG_DROP_RECV=y
CONFIG_NET_TCP_DEBUG_DROP_RECV_PROBABILITY=50 /* Default drop probability is 1/50 */

2. Config to drop sent packet
CONFIG_NET_TCP_DEBUG_DROP_SEND=y
CONFIG_NET_TCP_DEBUG_DROP_SEND_PROBABILITY=50 /* Default drop probability is 1/50 */

Iperf2 client/server test on esp32c3:

---------------------------------------------------------
|  TCP Config            | Server | Client |            |
|-------------------------------------------------------|
|  Original              |   12   |     9  |  Mbits/sec |
|  Drop(1/50)            |  0.6   |   0.3  |  Mbits/sec |
|  Drop(1/50) + OFO/SACK |    8   |     8  |  Mbits/sec |
---------------------------------------------------------

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-14 14:05:26 +08:00
Xiang Xiao
695f42f8d2 net: Move accept to libc after https://github.com/apache/nuttx/pull/8083
since accept can simply forward to kernel accept4 function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-13 11:23:42 +02:00
chao an
8a63d29c6e net/devif_poll: optimize device buffer alloc in txpoll
Allocate the device buffer only if the protocol really need to send data.
not all protocols require the driver to prepare additional iob before
sending, especially UDP, each iob reserves l2/l3 header in advance
after prepare write buffer, net device could reuse this entry to send directly

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-13 16:41:10 +08:00
chao an
0cbbbb9215 net/devif: reuse devif_send() for can/pkt/icmp stack
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-13 16:41:10 +08:00
田昕
40c9e627d6 net/local:set POLLIN/POLLOUT threshold for local fifo
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
2023-01-13 12:27:54 +08:00
chao an
1a513588bf net/mld: update help manual for mld router
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-12 15:06:22 +08:00
Zhe Weng
6222ad5764 Revert "net: downgrade iob priority of input/udp/icmp to avoid blocking devif"
This reverts commit d87620abc9.
2023-01-12 01:56:18 +08:00
zhanghongyu
48c9d10336 net_socket: add accept4 function
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-01-11 23:28:08 +08:00
chao an
47d628d22e net/mld: fix build break of mld router
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-11 22:58:21 +08:00
梁超众
aca1a065a8 move usrsock to kernel space
Signed-off-by: 梁超众 <liangchaozhong@xiaomi.com>
2023-01-11 15:14:03 +08:00
chengkai
f864e5f657 wireless/bluetooth: add interrupt_context hander for netsnoop
Signed-off-by: chengkai <chengkai@xiaomi.com>
2023-01-10 18:08:22 +08:00
chao an
35c1e53b1a net/netdev: clear device buffer handle by default
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-06 16:33:13 +08:00
chao an
ffd81e63be net/tcp: reprepare response buffer from unthrottle pool
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-06 16:33:13 +08:00
chao an
3af47d1913 net/tcp: remove unnecessary clear for device buffer
which has been cleared in tcp_datahandler()

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-06 16:33:13 +08:00
Zhe Weng
d87620abc9 net: downgrade iob priority of input/udp/icmp to avoid blocking devif
When trying to use iperf2, we found it comsumes all the IOB when sending UDP packets, then devif_poll has no IOB to send the packet out, so speed drops to 0 and never recovers.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-01-05 22:25:19 +08:00
dongjiuzhu1
31134719e7 net/local: rename NET_LOCAL_VFS_PATH to follow linux
And skip same prefix for unix path

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-01-04 20:50:38 +08:00
chao an
1510dbee68 net/tcp: Do not trigger retransmission if the new data has not been consumed.
Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-03 16:28:30 +08:00
zhanghongyu
43cc4bd7bf net_local: fix error when work with epoll
epoll_wait collects revent by checking fds->revent,
but local_socket will copy fds to the other two private pollfd shandow struct,
then the pipe_poll will not be able to update fds->revent directly,
so need local_socket save fds and implement a private poll_notify function
to passing revent to original fds->revent.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-12-31 02:23:50 +08:00
Zhe Weng
34ade7a0b6 net/devif: fix devif_poll loop logic
Previously, the devif_poll works in this flow:
devif_poll_xx -> bstop = callback -> continue if !bstop -> poll another

Now we split the polling and callback, so it should work like:
devif_poll_connections -> return true if callback need to be called
   -> bstop = callback -> loop if !bstop -> poll again

Conditions:
poll_connections == 0, d_len == 0, break, return 0
poll_connections == 1, d_len == 0, break, return 1 (other stop case,
                                                    don't callback)
poll_connections == 1, d_len > 0, callback == 1, break, return 1
poll_connections == 1, d_len > 0, callback == 0, loop

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-30 21:25:59 +08:00
Zhe Weng
cbe4cb2056 net: Add set/getsockopt options compatible with iptables.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-28 22:40:53 +08:00
zhanghongyu
5d3f47c37b net: Separate IP_PKTINFO from NET_IGMP
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-12-28 00:05:57 +08:00
Zhe Weng
7f9cf184e5 net/devif_loopback: Add robustness to avoid infinite loop
When ipv4_input/ipv6_input called by devif_loopback writes wrong data into buffer (another bug we're fixing), the else block does nothing but only record the 'dropped' statistic, then infinite loop happens.

Refers to previous lo device with dropping logic:
https://github.com/apache/nuttx/blob/releases/11.0/drivers/net/loopback.c#L178-L180

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-24 16:20:17 +08:00
Zhe Weng
cb958e5d69 net/nat: Clear entries when NAT will be disabled
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-24 12:05:20 +08:00
Zhe Weng
902a6dcad2 net/nat: Support isolation between multiple WAN devices by saving external ip
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-24 12:05:20 +08:00
Zhe Weng
0ceee72239 net/nat: modify chksum_adjust and MANIP_IPADDR macro for better readability
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-24 12:05:20 +08:00
Zhe Weng
7bd2195fde net/nat: Fix misused d_draddr in select_port
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-23 19:40:19 +08:00
Zhe Weng
a9da1fff28 net/nat: Add auto reclaim logic for NAT entries.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-22 20:20:12 +08:00
Zhe Weng
879c337e30 net/nat: Use hashtable to optimize performance
Performance tested on simulator:

Before optimization:      -25% bandwidth @2k entries, -64% @10k entries
hashtable size=  2(1bit): -24% bandwidth @2k entries, -65% @10k entries
hashtable size=  4(2bits):-15% bandwidth @2k entries, -51% @10k entries
hashtable size= 32(5bits): -3% bandwidth @2k entries, -14% @10k entries
hashtable size=256(8bits): -1% bandwidth @2k entries,  -3% @10k entries

Note: Tested on worst performance, the earliest entry will be the worst.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-22 20:20:12 +08:00
Xiang Xiao
fd0d6a9bf5 compiler.h: Add _ between format|printf|syslog|scanf|strftime and like
align with other macro naming style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-21 01:05:19 +02:00
Xiang Xiao
4d2794250f net/local: Support the abstract path
https://man7.org/linux/man-pages/man7/unix.7.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-18 20:12:30 +02:00
Xiang Xiao
6b36ba0b6e net/local: Remove LOCAL_TYPE_UNTYPED
let's represent the unbound local socket as LOCAL_TYPE_UNNAMED

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-18 20:12:30 +02:00
Xiang Xiao
aea8f8175a net/local: Return -EINVAL if the address length passed to local_bind is too small
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-18 20:12:30 +02:00
chao an
6f15b32e34 net/tcp: rename NET_TCP_RECV_CONTIG to NET_TCP_RECV_PACK
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-19 01:32:05 +08:00
chao an
794adc5814 net/tcp: contig received data to reducing iob consumption
Fragmentation of network data will intensify iob consumption, if
the device receives a message storm of fragmented packets, the iob
cache will not be effectively used, this is not allowed on iot devices
since the resources of such devices are limited. Of course, this
also takes some disadvantages: data needs to be copied.
This option will brings some balance on resource-constrained devices,
enable this config to reduce the consumption of iob, the received iob
buffers will be merged into the contiguous iob chain.

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-18 21:15:47 +08:00
Xiang Xiao
d5689e070b net/arp: Remove nuttx/net/arp.h
1.move ARPHRD_ETHER to netinet/arp.h
1.move arp_entry_s to net/arp/arp.h
2.move arp_input to nuttx/net/netdev.h

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-16 22:10:59 +02:00
chao an
01eb4d586b mm/iob: iob members are initialized after allocate
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-16 09:51:53 +08:00
chao an
3a50911810 net/udp: correct udp send timeout
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-16 09:51:15 +08:00
chao an
5492e961bc net/devif: replace redundant code to iob_clone_partial()
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-14 21:37:20 +08:00
wangjunfeng0
b2b014df0b Remove redundant length checking
Signed-off-by: wangjunfeng0 <wangjunfeng3@xiaomi.com>
2022-12-14 21:20:14 +08:00
zhanghongyu
c74cb1aaa5 net/arp: change arptable struct from arp_entry_s to arpreq
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-12-14 21:17:08 +08:00
zhanghongyu
1a81a936df arp: add device check for arp interface
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-12-14 21:17:08 +08:00
Zhe Weng
2f3e237380 net/ipfwd: limit number of ipforward struct to be less than number of IOB
If ipforward consumes all the IOB, devif_poll will not poll any more. Without polling, ipforward will not release any IOB, then all the network stack may fail with no IOB available.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-09 11:20:16 +08:00
tangyusong1
f454dfccb2 Adjust ioctl function of cellular
Add SIOCGCELLNETDEV
Give a uint8_t[136] for cellular to save data

Signed-off-by: tangyusong1 <tangyusong1@xiaomi.com>
2022-12-09 11:19:55 +08:00
tangyusong1
1c7a9d282c Add mtu set and interface name set in ioctl
Follow LinuxOS:linux-5.10.152\include\uapi\linux\sockios.h
Add SIOCSIFMTU and SIOCSIFNAME

Signed-off-by: tangyusong1 <tangyusong1@xiaomi.com>
2022-12-08 13:58:26 +01:00
chao an
11de08de27 net/devif_send: replace all block send to nonblock mode
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-08 09:53:15 +01:00
chao an
6950b67b46 net/can: device buffer must be clear after enqueue to readahead
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-08 03:16:42 +08:00
chao an
fc1b71b9a6 net/can: add support of iob input
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-08 03:16:42 +08:00
chao an
d295b4e1f1 net/devif: Use the device ll header length to calculate send limit
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-08 03:16:42 +08:00
chao an
960b4bb2a7 net/devif: initialize d_len to 0 before polling connections
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-08 03:16:42 +08:00
chao an
c738da048c net/ipforward: update IP buffer offset
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-07 00:01:52 +08:00
Zhe Weng
6e9053265c net/ipfwd: fix ipv4_dev_forward after IOB offload.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-06 17:03:47 +08:00
Zhe Weng
2a780e0467 net/ipfwd: fix devif_forward after IOB offload.
Problem:
- `iob_copyout` to `d_buf` doesn't set `io_len` of the IOB, so `devif_poll` failed to copy the data into `buf` by `iob_copyout`

Modification:
- Just Move the IOB in `devif_forward`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-06 17:03:47 +08:00
chao an
e002edf87c net/devif: reprepare iob buffer before polling connections
Loopback device will consume the d_iob packet in upper layer protocol,
in order to avoid null pointer access, reprepare iob buffer before polling connections

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-05 17:32:07 +08:00
chao an
8fc1e524ab net/ip: return success if the packet was forwarded.
The incoming packet should not be input to ip layer if the packet has been forwarded

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-04 15:59:43 -03:00
Xiang Xiao
43bda3282f net/arp: Move arp_ipin and arp_out to private header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-04 20:39:21 +08:00
Xiang Xiao
c6e9edcbb6 net: Rename arp_arpin to arp_input
align with other similar function(e.g. ipv4_input and ipv6_input)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-04 20:39:21 +08:00
chao an
62004a28a6 net/d_buf: remove d_buf reference from l3/l4
l3/l4 stack will decouple the reference of d_buf gradually, Only legacy
devices still retain d_buf support, new net devices will use d_iob

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-04 20:37:14 +08:00
chao an
dc6f10f33b net/nerighbor: No need to update pktlen before l2 output
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-04 20:37:14 +08:00
chao an
82d67b201a net/offload: add offload support for pkt/arp
1. add offload support for pkt/arp
2. Reset the d_buf to NULL if d_iob has released

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-04 01:34:30 +08:00
chao an
34d2cde8a8 net/l2/l3/l4: add support of iob offload
1. Add new config CONFIG_NET_LL_GUARDSIZE to isolation of l2 stack,
   which will benefit l3(IP) layer for multi-MAC(l2) implementation,
   especially in some NICs such as celluler net driver.

new configuration options: CONFIG_NET_LL_GUARDSIZE

CONFIG_NET_LL_GUARDSIZE will reserved l2 buffer header size of
network buffer to isolate the L2/L3 (MAC/IP) data on network layer,
which will be beneficial to L3 network layer protocol transparent
transmission and forwarding

------------------------------------------------------------
Layout of frist iob entry:

        iob_data (aligned by CONFIG_IOB_ALIGNMENT)
            |
            |                  io_offset(CONFIG_NET_LL_GUARDSIZE)
            |                                |
            -------------------------------------------------
      iob   |            Reserved            |    io_len    |
            -------------------------------------------------

-------------------------------------------------------------
Layout of different NICs implementation:

        iob_data (aligned by CONFIG_IOB_ALIGNMENT)
            |
            |                 io_offset(CONFIG_NET_LL_GUARDSIZE)
            |                                |
            -------------------------------------------------
 Ethernet   |       Reserved    | ETH_HDRLEN |    io_len    |
            ---------------------------------|---------------
 8021Q      |   Reserved  | ETH_8021Q_HDRLEN |    io_len    |
            ---------------------------------|---------------
 ipforward  |            Reserved            |    io_len    |
            -------------------------------------------------

--------------------------------------------------------------------

2. Support iob offload to l2 driver to avoid unnecessary memory copy

Support send/receive iob vectors directly between the NICs and l3/l4
stack to avoid unnecessary memory copies, especially on hardware that
supports Scatter/gather, which can greatly improve performance.

new interface to support iob offload:

  ------------------------------------------
  |    IOB version     |     original      |
  |----------------------------------------|
  |  devif_iob_poll()  |   devif_poll()    |
  |       ...          |       ...         |
  ------------------------------------------

--------------------------------------------------------------------

1> NIC hardware support Scatter/gather transfer

TX:

                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll("NIC"_txpoll)                callback() // "NIC"_txpoll
                                                  |
                            dev->d_iob:           |
                                                ---------------         ---------------
                             io_data       iob1 |  |          |    iob3 |  |          |
                                    \           ---------------         ---------------
                                  ---------------  |       --------------- |
                             iob0 |  |          |  |  iob2 |  |          | |
                                  ---------------  |       --------------- |
                                     \             |          /           /
                                        \          |       /           /
                                   ----------------------------------------------
                    NICs io vector |    |    |    |    |    |    |    |    |    |
                                   ----------------------------------------------

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
          pkt/ipv[4/6]_input()/...
                    |
                    |
     NICs io vector receive(iov_base to each iobs)

--------------------------------------------------------------------

2> CONFIG_IOB_BUFSIZE is greater than MTU:

TX:

"(CONFIG_IOB_BUFSIZE) > (MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE + CONFIG_NET_LL_GUARDSIZE)"

                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll("NIC"_txpoll)                callback() // "NIC"_txpoll
                                                  |
                                             "NIC"_send()
                          (dev->d_iob->io_data[CONFIG_NET_LL_GUARDSIZE - NET_LL_HDRLEN(dev)])

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
          pkt/ipv[4/6]_input()/...
                    |
                    |
     NICs io vector receive(iov_base to io_data)

--------------------------------------------------------------------

3> Compatible with all old flat buffer NICs

TX:
                tcp_poll()/udp_poll()/pkt_poll()/...(l3|l4)
                           /              \
                          /                \
devif_poll_[l3|l4]_connections()     devif_iob_send() (nocopy:udp/icmp/...)
           /                                   \      (copy:tcp)
          /                                     \
  devif_iob_poll(devif_poll_callback())  devif_poll_callback() /* new interface, gather iobs to flat buffer */
       /                                           \
      /                                             \
 devif_poll("NIC"_txpoll)                     "NIC"_send()(dev->d_buf)

RX:

  [tcp|udp|icmp|...]ipv[4|6]_data_handler()(iob_concat/append to readahead)
                    |
                    |
      [tcp|udp|icmp|...]_ipv[4|6]_in()/...
                    |
                    |
               netdev_input()  /* new interface, Scatter/gather flat/iob buffer */
                    |
                    |
          pkt/ipv[4|6]_input()/...
                    |
                    |
    NICs io vector receive(Orignal flat buffer)

3. Iperf passthrough on NuttX simulator:

  -------------------------------------------------
  |  Protocol      | Server | Client |            |
  |-----------------------------------------------|
  |  TCP           |  813   |   834  |  Mbits/sec |
  |  TCP(Offload)  | 1720   |  1100  |  Mbits/sec |
  |  UDP           |   22   |   757  |  Mbits/sec |
  |  UDP(Offload)  |   25   |  1250  |  Mbits/sec |
  -------------------------------------------------

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-03 11:47:04 +08:00
Zhe Weng
025430a964 net/icmpv6: Fix icmpv6_reply function
Fix icmpv6_reply logic broken by commit 48311cc61f and 391b501639.

- 48311cc61f "Fix unaligned memory access when creating ICMP Port Unreachable messages"
  - It removed `htonl` function outside `data`, then the byte order may be wrong, so add `htons` back.
- 391b501639 "net: extract l3 header build code into new functions"
  - It mis-removed the `memmove`, and the icmpv6 has no payload copied after this commit.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-02 15:26:45 +08:00
Zhe Weng
69cbcfd19f net/ipfwd: Support ICMPv6 error reply when forwarding IPv6
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-02 15:26:45 +08:00
Zhe Weng
f416fd86bb net/ipfwd: Support ICMP error reply when forwarding IPv4
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-02 15:26:45 +08:00
Zhe Weng
da6ab79d65 net/ipv4_input: Set IPv4 flag at the same place as ipv6_input
Set IPv4 flag before processing ipforward, otherwise the ICMP packet responded by ipforward may sometimes be regarded as IPv6.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-02 15:26:45 +08:00
Zhe Weng
9aefd6717c net/nat: Add support for ICMP Error Message
Support DEST_UNREACHABLE, TIME_EXCEEDED and PARAMETER_PROBLEM ICMP types in NAT.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-01 22:45:22 +08:00
Zhe Weng
23dfdeacab net/nat: Split out ipv4_nat_in/outbound_internal
Split out ipv4_nat_in/outbound_internal which returns entry instead of error code, for later ICMP error types, does not change any current logic.

Reason: Outer packet doesn't have information of port, so we need to find entry by inner packet, and apply the entry to outer packet.

| Outer Packet: SRC = Peer IP<No Port>, DST = External IP<No Port> |
| Inner Packet: SRC = External IP:Port, DST = Peer IP:Port         |

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-01 22:45:22 +08:00
Zhe Weng
8b211128f1 net/nat: Support param to manipulate src or dest
This commit is for later ICMP error types processing, and does not change any current logic.

Reason for supporting both side of modification is that an inbound ICMP Error MSG may carry original packet like this:

|          IP HDR: SRC = Peer IP,       DST = External IP |
|        ICMP HDR: ERROR MSG                              |
| <Origin> IP HDR: SRC = External IP,   DST = Peer IP     |
| <Origin> L4 HDR: SRC = External Port, DST = Peer Port   |

So we need to support inbound translation (External -> Local) on SRC or DST of each header.

And so do the outbound direction.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-01 22:45:22 +08:00
Zhe Weng
3aac6a1a3b net/devif: fix devif loopback
devif_loopback needs to be applied on l2 data, and was broken by commit below, now fix it.

| commit 8850dee746
| Author: chao an <anchao@xiaomi.com>
| Date:   Sun Nov 27 03:31:07 2022 +0800
|
|     net/devif: move preprocess of txpoll into common code
|
|     Signed-off-by: chao an <anchao@xiaomi.com>

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2022-12-01 19:48:23 +08:00
chao an
a0bce18192 net/ipv4: fix shadows declaration
devif/ipv4_input.c: In function ‘ipv4_in’:
devif/ipv4_input.c:305:15: warning: declaration of ‘ret’ shadows a previous local [-Wshadow]
  305 |           int ret = ipv4_forward(dev, ipv4);
      |               ^~~
devif/ipv4_input.c:151:7: note: shadowed declaration is here
  151 |   int ret = OK;
      |       ^~~

Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-01 09:38:33 +08:00
chao an
4281acdb83 net/chksum: move all chksum api declarations to common header
The following APIs need to be overriden by the arch after enabling
CONFIG_NET_ARCH_CHKSUM, move these functions to the common header
file to avoid prototype conflicts

uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len);
uint16_t net_chksum(FAR uint16_t *data, uint16_t len);
uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev, uint8_t proto);
uint16_t ipv6_upperlayer_chksum(FAR struct net_driver_s *dev,
                                uint8_t proto, unsigned int iplen);
uint16_t ipv4_chksum(FAR struct ipv4_hdr_s *ipv4);

Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-30 15:08:14 +08:00
chao an
0de9e387a7 net/loopback: reuse devif_loopback() logic for device lo(loopback)
TX poll callback in device lo(loopback) can be replaced by devif_loopback()
from devif_poll() hook, remove duplicate code to reuse this logic

Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-30 10:07:14 +08:00
chao an
823252261f net/devif: remove link layer length from loopback
Add link layer length in loopback is unnecessary after below change checkin:

 | commit 6fa60627eb
 | Author: chao an <anchao@xiaomi.com>
 | Date:   Sun Nov 27 02:13:21 2022 +0800
 |
 |     net/devif/ip: build l2 header on the IP layer
 |
 |     Signed-off-by: chao an <anchao@xiaomi.com>

Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-30 10:07:14 +08:00
liyi
391b501639 net: extract l3 header build code into new functions
Signed-off-by: liyi <liyi25@xiaomi.com>
2022-11-29 18:36:15 +08:00
chao an
d54a20b393 net/tcp/udp: remove all domain assertion
fix build break if enable CONFIG_NET_IPv6 only

In file included from tcp/tcp_sendfile.c:38:
tcp/tcp_sendfile.c: In function ‘sendfile_eventhandler’:
tcp/tcp_sendfile.c:173:27: error: ‘struct tcp_conn_s’ has no member named ‘domain’
  173 |           DEBUGASSERT(conn->domain == PF_INET6);
      |                           ^~

Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-29 17:28:36 +08:00