Commit Graph

682 Commits

Author SHA1 Message Date
Petro Karashchenko
d499ac9d58 nuttx: fix multiple 'FAR', 'CODE' and style issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-25 19:22:15 +08:00
daichuan
fe01d7c462 modify for offload checksum and add macro with tcp/icmp/icmpv6/igmp checksum
Signed-off-by: daichuan <daichuan@xiaomi.com>
2024-08-24 20:41:40 +08:00
meijian
c0eef6c137 net/tcp_timer: fix tcp_timer idle loop and retransmission bug
1. Tcp will idle loop by tcp_timer when have no packet to send. This will cause low-power devices to be frequently woken up.
2. We should add tcp_timer when timer has been canceled and have packet to send.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-08-24 18:07:03 +08:00
liqinhui
a60185cc40 net:Fix the warnings.
tcp/tcp_send_buffered.c: In function 'psock_send_eventhandler':
tcp/tcp_send_buffered.c:1025:17: warning: format '%u' expects argument of type 'unsigned int', but argument 9 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=]
 1025 |           ninfo("SEND: wrb=%p seq=%" PRIu32 " pktlen=%u sent=%u sndlen=%zu "
      |                 ^~~~~~~~~~~~~~~~~~~~
......
 1030 |                 conn->snd_wnd, seq, remaining_snd_wnd);
      |                 ~~~~~~~~~~~~~
      |                     |
      |                     uint32_t {aka long unsigned int}

wireless/ieee80211/bcm43xxx/bcmf_netdev.c: In function 'bcmf_addmac':
wireless/ieee80211/bcm43xxx/bcmf_netdev.c:879:26: warning: unused variable 'priv' [-Wunused-variable]
  879 |   FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private;
      |                          ^~~~

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-08-21 23:30:49 +08:00
liqinhui
bf78bf1db4 net/tcp: reset the dupack counter.
After setting the retransmission flag, we need to set the dupack counter to 0.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-08-21 02:12:55 +08:00
zhanghongyu
3c4897310b tcp_input: if tcp->req > recvreq, send ack only when state is TCP_ESTABLISHED
The Bluetooth network on N62 does not retransmit packet, so no packet
retransmition if we drop one, 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-08-20 08:31:55 +02:00
wangchen
5fedb1e6de tcp_timer.c:solve Problem of parameter calculation exceeding the boundary
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-08-20 13:51:39 +08:00
Kian Karas
46a8c665d7 net/tcp: fix missing error code propagation
If devif_send() failed its returned error code was not propagated
to user space. Instead, a send length of zero was returned (in
violation of POSIX).
2024-06-22 19:26:14 -03:00
zhanghongyu
9472426f69 net/inet: Rename ttl to s_ttl in sconn.
uniform naming convention

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-06-05 23:22:15 +08:00
liqinhui
05b101134a net:Support jumbo frame prealloc the iob for the ICMP/UDP/TCP.
For the ICMP, UDP and TCP, pre-alloc an iob for a jumbo frame.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2024-06-02 09:31:37 -03:00
meijian
0bad215cf8 net/tcp: fix tcp will not close when tcp retransmission reaches TCP_MAXRTX
In "psock_send_eventhandler",when retransmit count bigger TCP_MAXRTX nuttx will set release wrb. But before this it will also set "conn->tx_unacked = 0" if we only retransmit one packet(conn->tx_unacked == sent),and In func "tcp_timer" only "conn->tx_unacked > 0" will close the tcp conn. So app will never close if nuttx retransmit over max timers.

Signed-off-by: meijian <meijian@xiaomi.com>
2024-05-22 17:46:04 -03:00
zhanghongyu
45568229ef tcp: decouple TCP_NODELAY and NET_TCP_KEEPALIVE
TCP_NODELAY is an independent configuration and does not depend on TCP_KEEPALIVE

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-04-29 17:45:14 +08:00
Zhe Weng
e543a8086e net: Optimize TCP/UDP port selection
Optimize TCP/UDP port selection, and fix possibly dead loop.

Finish discussion in https://github.com/apache/nuttx/pull/12116#discussion_r1560851977

Note:
Linux also uses EADDRINUSE for failing in finding a portno, according to https://man7.org/linux/man-pages/man2/bind.2.html

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-12 15:46:29 +08:00
Zhe Weng
f2ff5cee03 net/nat: Make some IPv4 NAT functions as common
To prepare for future IPv6 NAT functions.
- Rename common ipv4_nat_xxx to nat_xxx
- Move some common definitions into header

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-04-11 22:23:29 +08:00
meijian
93beeeeab0 [tcp/udp] fix port generation not in range
(port % max + min)may overflow uint16

Signed-off-by: meijian <meijian@xiaomi.com>
2024-04-09 23:35:55 +08:00
wangchen
b446a002db net:add customizable default max & min port
add customizable default max & min port

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-04-09 23:35:55 +08:00
Xiang Xiao
2fd73bd82f net: Fix max conn always one less than configured value
return NULL only when the total number is larger than configured value

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-04-07 10:42:56 -03:00
zhanghongyu
3956a52c58 net/tcp: return true only when send window updates
return true even when window has not changed will cause delayed ack cannot take effect.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-03-13 22:24:04 +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
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
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
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
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
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
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
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
Zhe Weng
33c3abb706 net/tcp: Stop monitor in tcp_free
We may just free some TCP connections before monitor stopped, e.g.
sacrificie a TCP conn in `tcp_alloc` will just call `tcp_free` and reuse
the connection.  But we noticed that the TCP monitor is not released in
`tcp_free` because it is mounted on `conn->connevents` instead of
`conn->sconn.list` while `tcp_free` only release the latter.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-09-14 22:55:10 +08:00
zhanghongyu
2c39cfefef psock_tcp_cansend: return EWOULDBLOCK when send buffer is full
with nonblocking sockets, POLLOUT is returned when the application
calls poll even if the send buffer is full

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-14 14:50:45 +03:00
Zhe Weng
7c422381ca net/tcp: Set SO_ERROR for poll error in setup
Normally, `SO_ERROR` for disconn events will be set by `tcp_poll_eventhandler`, but when the socket is closed before poll, we should also set the `SO_ERROR`.

On Linux, `tcp_poll` returns `EPOLLERR` event when `sk->sk_err` has value but doesn't let `poll` fail (doesn't set `errno`). https://github.com/torvalds/linux/blob/v6.5/net/ipv4/tcp.c#L594-L596
Note: `sk->sk_err` can be get by socket option `SO_ERROR` on Linux, so `POLLERR` will always be together with `SO_ERROR`.

Common libs like curl may try to read `SO_ERROR` on `POLLERR`.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-09-14 14:32:56 +08:00
xuxin19
7a9d3c03e4 cmake:complete missing changes during reforming for net
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-13 21:51:20 +08:00
zhanghongyu
3f927b63b7 tcp_input: update tx_unack before reorder_ofosegs
After the sack is enabled and the ofosegs has gap, tcp cannot update the
tx_unacked, so the peer received packets are retransmitted after the
timer timeout.
So update tx_unacked first.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-09-01 12:30:06 +03:00
chao an
7d1763a57c net/assert: remove all unnecessary check for psock/conn
Since inet/socket layer already contains sanity checks, so remove unnecessary lower half checks

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 20:36:49 +08:00
chao an
664927c86e mm/alloc: remove all unnecessary cast for alloc
Fix the minor style issue and remove unnecessary cast

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 14:34:20 +08:00
zhanghongyu
32b1af3008 tcp_send_buffered: change Not connected message level from error to warning
Non-blocking sockets are almost never in the connected state when app try to
get result of connect success through poll, to avoid confusion because of
this error print, so downgrade the print level to warning.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-25 20:38:59 +03:00
Ville Juven
9cd8ea32d1 net/xx/wrbuffer: Do not use SEM_INITIALIZER for buffers
Using the macro places the buffers into .data section which means they
will consume the full buffer size of flash / read only memory as well.

Place the buffers into .bss to avoid this case.
2023-08-25 00:02:07 +08:00
Zhe Weng
d44e19d115 mm/iob: Add support for increasing length in iob_update_pktlen
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-22 16:34:21 +09:00
liqinhui
0100e8338e net: Fix unreadable error when doing poll operation on tcp socket.
When do poll operation and the tcp connection state is TCP_ALLOCATED, eventset(POLLERR|POLLHUP) is return, causing the libuv poll_multiple_handles to fail.

Verification: Use the libuv test case ` uv_run_tests poll_multiple_handles`.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-08-21 17:38:00 +08:00
wangyingdong
2ce31c442f net/tcp:Added tcp zero window probe timer support
https://www.rfc-editor.org/rfc/rfc1122#page-92

Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-08-20 19:47:11 -03:00
Zhe Weng
d3bca3c2cf net: Add FIOC_FILEPATH ioctl support for ICMP(v6)/RPMsg/Usrsock sockets
Example of /proc/PID/group/fd in this case:

FD  OFLAGS  TYPE POS       PATH
3   3       9    0         icmp:[dev eth0, id 1, flg 1]
4   3       9    0         icmp6:[dev eth0, id 2, flg 1]
5   3       9    0         rpmsg:[ap:[test:0]<->remote] # server side
5   3       9    0         rpmsg:[remote<->ap:[test:0]] # client side

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-15 15:00:59 +08:00
liqinhui
8631e0c6b5 net/tcp: Fix the sack byte aligment error.
The error log is as follows:
  tcp/tcp_send_buffered.c:376:57: runtime error: member access within misaligned
  address 0x10075942 for type 'struct tcp_sack_s', which requires 4 byte alignment

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2023-08-14 20:46:09 +08:00
Zhe Weng
d98bfc3e49 net/icmpv6: Fix icmpv6_neighbor for link-local address
The netdev of link-local address cannot be auto decided, and the link-local address should always be reguarded as address on local network.

The problem we met:
When using `icmpv6_autoconfig` with multiple netdev, the `icmpv6_neighbor` may take out wrong netdev with ip address already set, then it may send solicitation with wrong address (`dev->d_ipv6draddr`) on wrong device, and regard the link-local address as conflict (because `dev->d_ipv6draddr` exists on this network).

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-11 02:00:39 +08:00
Zhe Weng
817a43de4d net: Add FIOC_FILEPATH ioctl support for tcp/udp/local sockets
Example of /proc/PID/group/fd, which prints the file path:

FD  OFLAGS  TYPE POS       PATH
0   3       1    0         /dev/console
1   3       1    0         /dev/console
2   3       1    0         /dev/console
3   3       9    0         udp:[0.0.0.0:10197<->114.118.7.163:123, tx 0/16384, rx 0/16384, flg 1]
4   1027    9    0         tcp:[0.0.0.0:23<->0.0.0.0:0, tx 0/16384, rx 0/16384 + ofo 0, st 01, flg 31]
5   67      9    0         local:[md:ap]

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-08-07 08:08:37 -07:00
wangchen
b10d6be17a net:Add check for address binding
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-03 03:16:31 -07:00
wangchen
bdf82d2087 net/tcp: Return -EINVAL if bind is called more than once
Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-08-02 22:48:07 -07:00
Zhe Weng
075eb6a6d2 net/udp: Change conn->readahead to I/O buffer chain
When using IOB queue to store readahead data, we use one IOB for each
UDP packet. Then if the packets are very small, like 10Bytes per packet,
we'll use ~1600 IOBs just for 16KB recv buffer size, which is wasteful
and dangerous. So change conn->readahead to a single IOB chain like TCP.

Benefits:
- Using memory and IOBs more efficiently (small packets are common in
  UDP)

Side effects:
- UDP recv buffer size may count the overhead
- A little bit drop in performance (<1%, more seek & copy)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-18 10:51:45 +08:00
Zhe Weng
4b7604cf81 net: Rename tcp_dataconcat to net_iob_concat
Allow other protocols like UDP to use concat logic.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-18 10:51:45 +08:00
wangyingdong
57bf3e1fea net: Add msg_peek support for udp and tcp
Signed-off-by: wangyingdong <wangyingdong@xiaomi.com>
2023-07-13 19:40:04 +08:00