Commit Graph

419 Commits

Author SHA1 Message Date
YAMAMOTO Takashi
09869e5d41 net/tcp/tcp.h: Remove unused extern g_netdevices 2021-03-30 12:27:50 -05:00
YAMAMOTO Takashi
1c29a2e8e8 net/tcp/tcp_send_buffered.c: Fix non-blocking I/O
My recent changes to buffered tcp send broke this. [1]

One of my local apps using non-blocking tcp is working
again with this fix.

[1]
```
commit 837e1a72a4
Author: YAMAMOTO Takashi <yamamoto@midokura.com>
Date:   Mon Mar 15 16:19:42 2021 +0900

    tcp_send_buffered.c: improve tcp write buffering
```
2021-03-30 01:12:55 -05:00
YAMAMOTO Takashi
271e748ba5 tcp_send_buffered.c: Add a bit more info to an ninfo() 2021-03-30 01:12:55 -05:00
YAMAMOTO Takashi
a2840b6354 tcp_send_buffered.c: Add an assertion 2021-03-30 01:12:55 -05:00
YAMAMOTO Takashi
ef9adcf399 tcp_send_buffered.c: Remove dead code 2021-03-30 01:12:55 -05:00
YAMAMOTO Takashi
837e1a72a4 tcp_send_buffered.c: improve tcp write buffering
* Send data chunk-by-chunk
  Note: A stream socket doesn't have atomicity requirement.

* Increase the chance to use full-sized segments

Benchmark numbers in my environment:

* Over ESP32 wifi
* The peer is NetBSD, which has traditional delayed ack TCP
* iperf uses 16384 bytes buffer

---

without this patch,
CONFIG_IOB_NBUFFERS=36
CONFIG_IOB_BUFSIZE=196

does not work.
see https://github.com/apache/incubator-nuttx/pull/2772#discussion_r592820639

---

without this patch,
CONFIG_IOB_NBUFFERS=128
CONFIG_IOB_BUFSIZE=196
```
nsh> iperf -c 192.168.8.1
       IP: 192.168.8.103

 mode=tcp-client sip=192.168.8.103:5001,dip=192.168.8.1:5001, interval=3, time=30

        Interval Bandwidth

   0-   3 sec,  4.11 Mbits/sec
   3-   6 sec,  4.63 Mbits/sec
   6-   9 sec,  4.89 Mbits/sec
   9-  12 sec,  4.63 Mbits/sec
  12-  15 sec,  4.85 Mbits/sec
  15-  18 sec,  4.85 Mbits/sec
  18-  21 sec,  5.02 Mbits/sec
  21-  24 sec,  3.67 Mbits/sec
  24-  27 sec,  4.94 Mbits/sec
  27-  30 sec,  4.81 Mbits/sec
   0-  30 sec,  4.64 Mbits/sec
nsh>
```

---

with this patch,
CONFIG_IOB_NBUFFERS=36
CONFIG_IOB_BUFSIZE=196
```
nsh> iperf -c 192.168.8.1
       IP: 192.168.8.103

 mode=tcp-client sip=192.168.8.103:5001,dip=192.168.8.1:5001, interval=3, time=30

        Interval Bandwidth

   0-   3 sec,  5.33 Mbits/sec
   3-   6 sec,  5.59 Mbits/sec
   6-   9 sec,  5.55 Mbits/sec
   9-  12 sec,  5.59 Mbits/sec
  12-  15 sec,  5.59 Mbits/sec
  15-  18 sec,  5.72 Mbits/sec
  18-  21 sec,  5.68 Mbits/sec
  21-  24 sec,  5.29 Mbits/sec
  24-  27 sec,  4.67 Mbits/sec
  27-  30 sec,  4.50 Mbits/sec
   0-  30 sec,  5.35 Mbits/sec
nsh>
```

---

with this patch,
CONFIG_IOB_NBUFFERS=128
CONFIG_IOB_BUFSIZE=196
```
nsh> iperf -c 192.168.8.1
       IP: 192.168.8.103

 mode=tcp-client sip=192.168.8.103:5001,dip=192.168.8.1:5001, interval=3, time=30

        Interval Bandwidth

   0-   3 sec,  5.51 Mbits/sec
   3-   6 sec,  4.67 Mbits/sec
   6-   9 sec,  4.54 Mbits/sec
   9-  12 sec,  5.42 Mbits/sec
  12-  15 sec,  5.37 Mbits/sec
  15-  18 sec,  5.11 Mbits/sec
  18-  21 sec,  5.07 Mbits/sec
  21-  24 sec,  5.29 Mbits/sec
  24-  27 sec,  5.77 Mbits/sec
  27-  30 sec,  4.63 Mbits/sec
   0-  30 sec,  5.14 Mbits/sec
nsh>
```
2021-03-22 01:12:59 -07:00
chao.an
e03218ab71 net/tcp: reset the connection ref count before tcp_free()
reset the connection refcount if SYN retry count has elapsed

Assertion:

up_assert: Assertion failed at file:tcp/tcp_conn.c line: 764 task: netdev_wq

N/A

Signed-off-by: chao.an <anchao@xiaomi.com>
2021-03-22 10:55:30 +09:00
chao.an
a5613e6008 net/tcp: correct the port byte order
1. unify the byte order to network
2. Do not re-select the port if the local port has been bind()

Signed-off-by: chao.an <anchao@xiaomi.com>
2021-03-20 09:13:18 -07:00
YAMAMOTO Takashi
45098769e7 tcp_sendfile.c: Remove an unused copy of CONFIG_NET_TCP_SPLIT_SIZE 2021-03-15 04:52:58 -07:00
Masayuki Ishikawa
e65d5d8c73 Revert "net: tcp: Add DEBUGASSERT() in psock_tcp_send()"
Summary:
- Based on the discussion (PR#2772), let me revert the commit

Impact:
- None

Testing:
- N/A

This reverts commit ec8bf5c8c1.

Suggested-by: YAMAMOTO Takashi <yamamoto@midokura.com>
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-03-12 16:23:01 +08:00
Gustavo Henrique Nihei
330eff36d7 sourcefiles: Fix relative path in file header 2021-03-09 23:18:28 +08:00
Jiuzhu Dong
4d5a964f29 net: unify socket into file descriptor
Change-Id: I9bcd21564e6c97d3edbb38aed1748c114160ea36
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-03-03 19:01:41 -08:00
Alin Jerpelea
37d5c1b0d9 net: Author Gregory Nutt: update licenses to Apache
Gregory Nutt has submitted the SGA and we can migrate the licenses
 to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-20 00:38:18 -08:00
Alin Jerpelea
7dc7ef45f1 net: nxstyle fixes
Nxstyle fixes to pass CI.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-20 00:38:18 -08:00
Masayuki Ishikawa
ec8bf5c8c1 net: tcp: Add DEBUGASSERT() in psock_tcp_send()
Summary:
- This commit adds DEBUGASSERT() to check the IOB size

Impact:
- None

Testing:
- Tested with sabre-6quad:netnsh with QEMU

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-01-29 00:05:01 -08:00
Abdelatif Guettouche
7e3d4a5f29 net: Remove duplicate forward references.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-01-16 07:39:04 -08:00
Abdelatif Guettouche
8e4397968c net/ & esp32/wlan: Fix some typos and nxstyle issues.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-01-14 07:57:27 -06:00
chao.an
ae5b727580 net/tcp/handshake: send the SYN immediately.
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-12-18 14:16:11 +09:00
chao.an
5e9e50991c net/tcp: send the ack on nonblock mode
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-12-18 14:16:11 +09:00
Juha Niskanen
de1ad1fdb3 net: fix typos, incorrect comments, nxstyle
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2020-12-13 09:06:28 -06:00
chao.an
8d0118569c [Performance]net/tcp: send the ACK in time after obtain ahead buffer from iobs
Request the TCP ACK to estimate the receive window after handle
any data already buffered in a read-ahead buffer.

Change-Id: Id998a1125dd2991d73ba4bef081ddcb7adea4f0d
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-12-10 12:23:47 +09:00
chao.an
881dd9d62d net/tcp: add a member to record the current receiving window
Change-Id: Ic4c46d643a905fdd3a828e563eab4814da70dbe5
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-12-10 12:23:47 +09:00
chao.an
794a6ec23d net/tcp: rename the winszie to snd_wnd to make the semantics more accurate
Change-Id: I8fdc7cf78a7f2cd53a30ef1de702b1a697c43238
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-12-10 12:23:47 +09:00
Gregory Nutt
45699e2701 net/tcp/tcp_input.c: Correct bad check of urgent data length
Urgent data preceded "normal" data in the TCP payload.  If the urgent data is larger than the size of the TCP payload, this indicates that the entire payload is urgent data and that urgent data continues in the next packet.

This case was handled correctly for the case where urgent data was present but was not being handled correctly in the case where the urgent data was NOT present.
2020-12-09 07:25:14 -08:00
YAMAMOTO Takashi
cee4261c0d net/tcp/tcp_sendfile.c: Fix syslog formats 2020-12-05 08:13:32 -06:00
chao.an
c2b0006dcd net/tcp: implement the fast retransmit
RFC2001: TCP Slow Start, Congestion Avoidance, Fast Retransmit,
         and Fast Recovery Algorithms

...

3.  Fast Retransmit
  Modifications to the congestion avoidance algorithm were proposed in
  1990 [3].  Before describing the change, realize that TCP may
  generate an immediate acknowledgment (a duplicate ACK) when an out-
  of-order segment is received (Section 4.2.2.21 of [1], with a note
  that one reason for doing so was for the experimental fast-
  retransmit algorithm).  This duplicate ACK should not be delayed.
  The purpose of this duplicate ACK is to let the other end know that a
  segment was received out of order, and to tell it what sequence
  number is expected.

  Since TCP does not know whether a duplicate ACK is caused by a lost
  segment or just a reordering of segments, it waits for a small number
  of duplicate ACKs to be received.  It is assumed that if there is
  just a reordering of the segments, there will be only one or two
  duplicate ACKs before the reordered segment is processed, which will
  then generate a new ACK.  If three or more duplicate ACKs are
  received in a row, it is a strong indication that a segment has been
  lost.  TCP then performs a retransmission of what appears to be the
  missing segment, without waiting for a retransmission timer to
  expire.

Change-Id: Ie2cbcecab507c3d831f74390a6a85e0c5c8e0652
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-12-01 11:36:10 -06:00
chao.an
234d3df19f net/tcp: correct the available iobs count if throttle is enabled
The number of available iobs is already sub in iob_navail(true) on line 114

net/tcp/tcp_recvwindow.c:
...
 73 uint16_t tcp_get_recvwindow(FAR struct net_driver_s *dev)
...
114   niob_avail    = iob_navail(true);

Change-Id: I230927904d8db08ed8d95d7fa18c5c5fce08aa5e
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-11-28 23:24:44 -06:00
chao.an
4305718691 net/tcp: fix nxstyle warnings
Change-Id: Id885fefc80caa12806c73778e632c8b0c5888be0
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-11-28 00:03:47 -06:00
chao.an
bf21056001 net/tcp: fallback to unthrottle pool to avoid deadlock
Add a fallback mechanism to ensure that there are still available
iobs for an free connection, Guarantees all connections will have
a minimum threshold iob to keep the connection not be hanged.

Change-Id: I59bed98d135ccd1f16264b9ccacdd1b0d91261de
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-11-28 00:03:47 -06:00
YAMAMOTO Takashi
cc9b3a3ec5 net/tcp/tcp_appsend.c: Fix syslog formats
Note: tx_unacked is either uint16_t or uint32_t depending on the config.
2020-11-27 05:18:57 -06:00
YAMAMOTO Takashi
cbdbb369c0 net/tcp/tcp_input.c: Fix syslog formats
Note: tx_unacked is either uint16_t or uint32_t depending on the config.
2020-11-27 05:18:57 -06:00
YAMAMOTO Takashi
af6719965f net/tcp/tcp_appsend.c: Fix syslog formats 2020-11-25 05:11:26 -08:00
YAMAMOTO Takashi
390f766b36 net/tcp/tcp_appsend.c: Appease nxstyle 2020-11-25 05:11:26 -08:00
YAMAMOTO Takashi
40d4c03a8c net/tcp/tcp_input.c: Fix syslog formats 2020-11-25 05:11:26 -08:00
YAMAMOTO Takashi
17654f592e net/tcp/tcp_send_buffered.c: Fix syslog formats 2020-11-25 05:11:26 -08:00
YAMAMOTO Takashi
634713cec4 net/tcp/tcp_sendfile.c: Fix syslog formats 2020-11-24 22:31:33 -08:00
YAMAMOTO Takashi
ee1c914277 net/tcp/tcp_input.c: Fix syslog formats 2020-11-23 05:00:10 -08:00
YAMAMOTO Takashi
28fda4e5bb net/tcp/tcp_send_unbuffered.c: Fix syslog formats 2020-11-23 05:00:10 -08:00
YAMAMOTO Takashi
8cb6790cef net/tcp/tcp_send_unbuffered.c: Fix a syslog format 2020-11-20 22:22:53 -08:00
YAMAMOTO Takashi
8a23f98233 net/tcp/tcp_wrbuffer_dump.c: Fix a syslog format 2020-11-20 22:22:53 -08:00
YAMAMOTO Takashi
ba1b6876b4 net/tcp/tcp_send_buffered.c: Fix a syslog format error 2020-11-20 22:22:53 -08:00
GAEHWILER Reto
cbd4e90781 net/tcp: Rectified keepalive fix
Simplification of previous fix. Also fixes the case when new data should
be sent while a keepalive is not yet acked.
2020-11-18 17:40:42 -03:00
chao.an
95be9eaf4b net/callback: remove the assert check of conn instance
remove the connection assertion since the instance will be invalid
if the network device has been taken down.

net/netdev/netdev_ioctl.c:

1847 void netdev_ifdown(FAR struct net_driver_s *dev)
1848 {
...
1871       /* Notify clients that the network has been taken down */
1872
1873       devif_dev_event(dev, NULL, NETDEV_DOWN);
...
1883 }

Change-Id: I492b97b5ebe035ea67bbdd7ed635cb13d085e89c
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-11-10 19:40:41 -08:00
chao.an
a22f5bb8b0 net/tcp: fix nxstyle warning
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-10-28 11:41:16 -07:00
chao.an
d78bf36740 net/tcp: fix tcp socket close timeout if loss wireless connection
In the current net stack implementation, there is no mechanism
for notifying the loss of the wireless connection, if the network
is disconnected then application sends data packets through tcp,
the tcp_timer will keep retrying fetch the ack for awhile, the
connection status will not be able to be switched timely.

Change-Id: I84d1121527edafc6ee6ad56ba164838694e7e11c
Signed-off-by: chao.an <anchao@xiaomi.com>
2020-10-28 11:41:16 -07:00
GAEHWILER Reto
83745652c4 TCP-stack fix for stalled tcp sockets due to broken keepalive
Fixes an issue where tcp sockets with activated keepalives stalled and
were not properly closed. Poll would not indicate a POLLHUP and therefore
locks down the application.

* tcp_conn_s.tcp_conn_s & tcp_conn_s.keepintvl changed to uint32_t
  According RFC1122 keepidle MUST have a default of 2 hours.
2020-10-27 11:21:56 -07:00
Nathan Hartman
80ce7800a9 Sources and Docs: Fix typos and nxstyle issues
Documentation/contributing/coding_style.rst:

    * Fix repeated words: ("this this").
    * Remove trailing spaces.

boards/z80/z80/z80sim/README.txt:

    * Fix repeated words: ("this this") and rewrap lines.

graphics/Kconfig,
libs/libc/math/Kconfig:

    * Fix repeated words: ("this this").

arch/arm/src/armv7-a/arm_assert.c,
arch/arm/src/armv7-r/arm_assert.c,
arch/arm/src/imxrt/imxrt_enet.c,
arch/arm/src/kinetis/kinetis_enet.c,
arch/arm/src/kinetis/kinetis_flexcan.c,
arch/arm/src/s32k1xx/s32k1xx_enet.c,
arch/arm/src/s32k1xx/s32k1xx_flexcan.c,
arch/arm/src/stm32/stm32_pwm.c,
arch/arm/src/stm32h7/stm32_pwm.c,
arch/arm/src/stm32l4/stm32l4_pwm.c,
arch/renesas/src/rx65n/rx65n_usbdev.c,
binfmt/libnxflat/libnxflat_bind.c,
drivers/pipes/pipe_common.c,
net/igmp/igmp_input.c,
net/tcp/tcp_conn.c,
sched/sched/sched_roundrobin.c:

    * Fix typo in comment ("this this").

arch/arm/src/cxd56xx/cxd56_usbdev.c,
arch/arm/src/lc823450/lc823450_usbdev.c:

    * Fix typo in comment and rewrap lines.

arch/arm/src/imxrt/imxrt_usbdev.c,
arch/arm/src/stm32/stm32_dac.c,
arch/arm/src/stm32f0l0g0/stm32_pwm.c,
arch/arm/src/stm32f7/stm32_pwm.c,
arch/arm/src/tiva/lm/lm4f_gpio.h,
fs/nxffs/nxffs_write.c,
include/nuttx/analog/pga11x.h,
include/nuttx/usb/usbdev.h,
net/mld/mld_join.c:

    * Fix typo in comment ("this this").
    * Fix nxstyle issues.
2020-10-02 04:54:52 +02:00
YAMAMOTO Takashi
4f7745ae1c net/tcp/tcp_timer.c: Remove redundant assignments
Found by clang-check:

tcp/tcp_timer.c:185:15: warning: Value stored to 'result' is never read
              result = tcp_callback(dev, conn, TCP_TIMEDOUT);
              ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tcp/tcp_timer.c:264:23: warning: Value stored to 'result' is never read
                      result = tcp_callback(dev, listener, TCP_TIMEDOUT);
                      ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tcp/tcp_timer.c:300:19: warning: Value stored to 'result' is never read
                  result = tcp_callback(dev, conn, TCP_TIMEDOUT);
                  ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.
2020-08-03 22:52:31 -05:00
Masayuki Ishikawa
c7500c5c9d net: tcp: Fix port info in warning message in tcp_input.c
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2020-05-19 13:36:45 +08:00
Gregory Nutt
57bc329aac Run nxstyle all .c and .h files modified by PR. 2020-05-17 14:01:00 -03:00