Commit graph

3128 commits

Author SHA1 Message Date
Zhe Weng
3e62be8361 net: Enable dynamic allocation of tcp/udp/ipfwd buffer by default
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-07 22:00:21 +08:00
Zhe Weng
50b3ab7671 net/bufpool: Call init automatically on alloc
Note: Initialize function of protocols (tcp, udp, pkt, etc.) are kept empty.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-07 22:00:21 +08:00
Zhe Weng
f702f1705f net/bufpool: Use SEM_INITIALIZER to init sem
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-07 22:00:21 +08:00
Zhe Weng
3b26c6df51 net/udp: Let cansend return EWOULDBLOCK when send buffer is full
Notes:
1. This commit do the same thing as TCP did: https://github.com/apache/nuttx/pull/10627
2. UDP uses `iob_navail(false)` but TCP uses `iob_navail(true)`, this is because of a problem related to TCP recv window (https://github.com/apache/nuttx/pull/4142), so we don't need to change UDP now.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2025-01-02 23:13:39 +08:00
zhanghongyu
f344a422e8 tcp_input: remove tcp_callback(ABORT) when accept conn recv TCP_RESET
when accept conn receives TCP_RESET, only accept conn itself should handle
the event, and there is no need to notify the listening conn. otherwise,
the server's poll will return with POLLERR and POLLHUP. this may cause
some applications to execute incorrect logic in the future.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-12-31 09:43:35 +08:00
zhanghongyu
05f7b7ac97 include/netinet/arp.h: change the type of arp_dev from uint8_t to char
the same variable type in linux is char, in order to avoid modifying
the third-party library code when porting the third-party library code.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-12-26 23:29:23 +08:00
Zhe Weng
84d261e3be net: Optimize ipfwd and wrbuffer by buffer pool
To allow dynamic allocation of these structs, performance keeps the same
as the previous implementation.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-23 16:57:19 -03:00
Zhe Weng
1fe07d0838 net: Add buffer pool to replace connection allocation
Our net socket connection allocations are powerful but redundant
because they're implemented once in each protocol.  This is not good for
further optimizing and extending to other allocations, so maybe we can
add a common implementation for the usage.

Impact:
1. We add a `struct net_bufpool_s` as pool descriptor, which may use a
   little bit more memory than previous implementation (~28Bytes).
2. We share same functions between pools, so code size may shrink under
   some scenarios.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-23 16:57:19 -03:00
liqinhui
88a300d2e6 net: Remove the DEBUGASSERT of the same event of the same fd in tcp_pollsetup.
In libuv, if the real_timeout in the uv__io_poll is less than 0, the poll logic will be entered directly by the uv__run_timers, which will trigger the ASSERT.
It seems that the situation of first epoll and then poll for the same fd is used in libuv.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-12-23 19:41:13 +08:00
wangchen
8ea31668ca tcp_recvfrom.c:malloc a new iob to handle psock_send_eventhandler when tcp_recvhandler calls tcp_newdata to clear dev->d_iob
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-12-22 19:26:04 +08:00
Zhe Weng
035fdb4951 net: Refresh config dependency of NET_READAHEAD
ICMP(v6) uses IOB queue as readahead, but TCP/UDP don't now.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-20 20:01:19 +08:00
chao an
4793407b67 net/icmp: fix typo timout -> timeout
Signed-off-by: chao an <anchao@lixiang.com>
2024-12-17 20:48:07 +08:00
meijian
d1786507b6 net/tcp_timer: fix tcp RTO abnormally large after retransmission occurs
when tcp retransmission only double conn->timer in Karn(tcp_timer.c L602), after retransmission in Jacobson
M is is now rtt test will become a negative value.
```
  signed char m;
  m = conn->rto - conn->timer; // M is now rtt test

  /* This is taken directly from VJs original code in his paper */

  m = m - (conn->sa >> 3);
  conn->sa += m;              //conn->sa is a negative value
  if (m < 0)
	{
	  m = -m;
	}

  m = m - (conn->sv >> 2);
  conn->sv += m;
  conn->rto = (conn->sa >> 3) + conn->sv; //rto
```
For example,we lost one ack packet, we will set conn->timer = 6 by backoff,conn->rto still 3.
After retransmission we will Do RTT estimation, then will get
```
conn->sa = 253
conn->rto = 46
```
Then if any packets lost it will wait for a long time before triggering a retransmission.

Test method.
We can reproduce this issue by adding drop ACK packets in tcp_input, and debug conn->rto after Jacobson.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-12-10 22:00:55 +08:00
Zhe Weng
752245aca4 net: Move NET_TCP/UDP_HAVE_STACK to netconfig.h
Now the HAVE_PFINET(6)_SOCKETS depends on NET_TCP/UDP_HAVE_STACK, which
is previously defined in net/ folder and cannot be included.
Considering many places use this check, maybe moving them to netconfig.h
could be better.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-11-21 23:07:30 +08:00
meijian
6944a16306 tcp/tls: fix tcp tls bugs
assert: tcp conn and didn't recv ack, tcp_free will assert in L909
and no need to tcp free because tcp close will free by lpwork.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-11-21 00:23:01 +08:00
meijian
3b50bf1782 net/tcp_conn: fix thread_cancel() caused recv/connect/send event used after free
Problem Description:
Problem occurrence when Thread1 creat connect/recv socket and Thread2 cancel Thread1.
1. Thread2 cancel when Thread1 connect event, will cause DEBUGASSERT in devif_callback_free.Because cb in g_cbfreelist.
2. Thread2 cancel when Thread1 recvfrom sem-wait, when the FIN packet input and will trigger tcp_recvhandler and will crash.Becuase some thread stack data was freed.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-11-21 00:23:01 +08:00
wangchen
540036ab60 udp:add tls cleanup protection to protect udp_callback info in psock_udp_recvfrom
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-11-20 13:42:58 +08:00
wangchen
b0d8fd9d75 udp:add tls cleanup protection to protect waitsem in udp_txdrain
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-11-20 13:42:58 +08:00
chenchuang
0c2ee8b492 fix: remove duplicated statistics of upd.drop
The valule of g_netstats.udp.drop has been increased in net_dataevent() function,
while it is increased in udp_datahandler().
2024-11-18 12:37:57 +08:00
wangjunfeng3
bfdfbc10ab net:Compatible with cellular network cards of lladdr generation
In the context of cellular networks, lladdr should use the interface identifiers from PDN.

Signed-off-by: wangjunfeng3 <wangjunfeng3@xiaomi.com>
2024-11-12 15:17:24 +08:00
zhanghongyu
af6db95fea tcp: fix tcp can not retransmit timely when ACK with TCP_NEWDATA
The current receive data needs to be handled by following
tcp_recvhandler or tcp_data_event. Notify driver to send the
message and marked as rexmit

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-11-10 00:39:48 +08:00
Peter van der Perk
faee89b966 net: fix inet #14634 regression
Define wasn't imported by netconfig.h move definitions
2024-11-05 18:36:02 +08:00
Peter van der Perk
c371afc7f4 net: inet.h match inet_sockif.c definition
Fixes psock_socket: ERROR: socket address family unsupported: 2
When using the minimal CONFIG_NET configuration typically used for
SocketCAN

Update net/inet/inet.h

Co-authored-by: Xiang Xiao <xiaoxiang781216@gmail.com>

Update net/inet/inet.h

Co-authored-by: Xiang Xiao <xiaoxiang781216@gmail.com>
2024-11-05 01:58:45 +08:00
Kian Karas
832a76542f net/netlink: improve comments 2024-11-04 18:18:28 +08:00
Kian Karas
105dd04ee5 net/netlink: fix netlink poll return value on success
Make sure the return value is zero on success - as described in the
documentation of the function.

It doesn't look like the "error" affected any code.
2024-11-04 18:18:28 +08:00
wangchen
90e2395d6c netlink:add tls cleanup protection to protect waitsem in netlink_get_response
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-11-03 02:55:43 +08:00
wangchen
807c3a16e3 tcp:set NET_TCP_NPOLLWAITERS default value to 2 & add warning of different events having same event bit
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-11-03 02:55:02 +08:00
ouyangxiangzhen
17c51c0667 userspace: Exclude nuttx/arch.h
This patch fixed userspace headers conflict. Architecture-related definition and API should not be exposed to users.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-11-01 16:59:37 +08:00
yintao
265978d16a net/rpmsg: Don't set POLLHUP if rpmsg channel has not been established
Signed-off-by: yintao <yintao@xiaomi.com>
2024-10-31 15:35:03 +08:00
zhanghongyu
d5d9c501fa tcp_input: if tcp->req > recvreq, send ack only when state is TCP_ESTABLISHED
we will drop packet when tcp_close_eventhandler
is register and invoke by tcp_input. then we will always early return and
never stop, the peer will only close the connection if we send reset packet.

precondition:
close -> register tcp_close_eventhandler;

tcp_input -> tcp_callback(TCP_NEWDATA) -> devif_conn_event -> tcp_close_eventhandler
-> flags &= ~TCP_NEWDATA -> NOT entry tcp_data_event -> conn->recvreq NOT increase

old flow:
tcp_input -> tcp->seqno greater than conn->rcvseq -> tcp_send(TCP_ACK)

with this patch:
tcp_input -> tcp->seqno greater than conn->rcvseq -> !TCP_ESTABLISHED
-> case TCP_FIN_WAIT_1 -> dev->d_len greater than 0 -> tcp_reset

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-10-31 15:31:01 +08:00
zhanghongyu
583ff3b962 net/usrsock: usrsock supports offload netlink
supports the usrsock client to subscribe netlink events,
so that it can detect events such as link connection changes.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-10-28 19:42:05 +08:00
Xiang Xiao
32784b0898 libc: Refine the arc4random_buf implementation
fill the buffer with getrandom instead random pool
and move the implementation to from crypto to libc

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-26 18:04:21 -03:00
zhanghongyu
824dfacd08 net/local: fix used after free
now the lc_path of the client will not be the same as that of the server.
therefore, accept->peer = NULL will not be set when the client release
the conn, then when release accept conn, set
client->peer(accept->peer->peer) = NULL will cause used after free

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-10-22 23:34:43 +08:00
wangchen
addfe127a9 socketpair.c:Replace kmm with fs heap
due to https://github.com/apache/nuttx/pull/13722/commits, In the socketpair.c,fs_heap interface replaces kmm interface

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-10-16 20:56:39 +08:00
Jukka Laitinen
ef827e88a7 net: Copy out also can cmsg data into the end of packet
This has been broken at some point. Just fix it by copying the can frame and
the cmsg data into IOB, and fix devif_poll to copy out the full data.

The can drivers expect to find the timeout timestamp in the end of the frame.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-10-16 15:39:11 +08:00
Jukka Laitinen
313b2cd1ed net/netdev/netdev_default.c: Exclude socket can from default devices
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2024-10-16 15:39:11 +08:00
wangxiaoxin
2a99490ed6 add a flag of lin internal sleep/wakeup state
Signed-off-by: wangxiaoxin <wangxiaoxin@xiaomi.com>
2024-10-16 14:33:59 +08:00
daichuan
a75ca4acf3 modify for set conn status with connected when receive event USRSOCK_EVENT_SENDTO_READY 2024-10-16 07:55:10 +08:00
hujun5
a567148888 sched: add up_this_task and up_change_task macro stub
reason:
We can utilize percpu storage to hold information about the
current running task. If we intend to implement this feature, we would
need to define two macros that help us manage this percpu information
effectively.

up_this_task: This macro is designed to read the contents of the percpu
              register to retrieve information about the current
              running task.This allows us to quickly access
              task-specific data without having to disable interrupts,
              access global variables and obtain the current cpu index.

up_update_task: This macro is responsible for updating the contents of
                the percpu register.It is typically called during
                initialization or when a context switch occurs to ensure
                that the percpu register reflects the information of the
                newly running task.

Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
   -machine virt,virtualization=on,gic-version=3 \
   -net none -chardev stdio,id=con,mux=on -serial chardev:con \
   -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-10-15 15:25:55 +08:00
liqinhui
4c85805be0 net/tcp: Reset the conn when receiving a ACK in the SYN_SENT state.
According to RFC793, Section 3.4, Page 33. In the SYN_SENT state, if receive a ACK without the SYN, we should reset the connection and retransmit the SYN.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-10-15 01:11:22 +08:00
yintao
d2fc3f21de net/rpmsg: use hash to handle rp_name
expand the user's rpname size
hash when exceed RPMSG_SOCKET_NAME_LEN due to the limitation of eptname

Signed-off-by: yintao <yintao@xiaomi.com>
2024-10-13 11:33:04 +08:00
Xiang Xiao
cb2a6a3480 net/rpmsg: Minor cleanups
1.Simplify the message process in rpmsg_socket_send_single
2.Add more lock protection in rpmsg socket
3.Fix the style issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-13 11:33:04 +08:00
Xiang Xiao
3a32531a05 net/rpmsg: Remove all the special handle of "backlog == -1"
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-13 11:33:04 +08:00
Xiang Xiao
034215ab9c net/rpmsg: sendsize should be protected by sendlock not recvlock
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-13 11:33:04 +08:00
yintao
5b372a4706 rpmsg_sockif: add rpmsg_socket_ept_release for free conn
Signed-off-by: yintao <yintao@xiaomi.com>
2024-10-13 11:33:04 +08:00
Xiang Xiao
8ea51b3efc net/can: Save simple options to socket_conn_s
like other protocols(e.g. ip, tcp, udp)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-13 11:24:31 +08:00
wangchen
be17bf2f86 net:when work_cancel_sync is excuted,it releases net_lock
the modification is to solve the deadlock caused by work cancel not releasing netlock

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-10-13 02:05:26 +08:00
wangchen
b791e27a8d igmp_group.c:add work_cancel_sync in igmp_grpfree
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-10-13 02:05:26 +08:00
wangchen
78b64cc220 igmp_leave:add check of dev status in igmp_leavegroup
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-10-13 02:05:26 +08:00
wangchen
7dcbd235fc netdev:In netdev_default,If there is only one loopback network devices, it returns NULL
Referring to Linux,if there is only a loopback network device and the destination address does not belong to the loopback address, then the loopback network devices is not selected

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-10-13 02:02:54 +08:00