Commit a1796f4
authored
lwIP-v2: new patch to randomize tcp source ports (#5906)
ref: d-a-v/esp82xx-nonos-linklayer#31
origin: #5902
me-no-dev/ESPAsyncTCP#108
Following the links above is instructive.
To summarize:
* currently and from a long time lwIP tcp client connections always uses the same tcp source port number right after boot
* this port number is increased everytime a new one is needed (= new tcp client connection)
(to be noted, linux has the same increasing behavior)
* when connecting to the same server (right after boot), the triplet (esp-ip-address, source port, destination port) are the same, and may hit remote server list of sockets in time-wait-state (previous connection unproperly closed from the same esp). Consequently the new connection fails when it happens.
* this is happening only when debugging (esp reboots often, in less time than time-wait expiration), so the nasty effect is amplified especially when bugs are being chased
* efforts had been done when espressif's lwIP implementation wasn't open source, with WiFiClient::setLocalPortStart() #632 but it must be explicitely called with a different random number at every reboot. Efficient but not ideal.
This PR uses espressif firmware's r_rand() everytime a new local source port is needed. A different source port number is now showed by tcpdump right after boot. Source port range and duplication is verified everytime in lwIP's src/core/tcp.c:tcp_new_port(). It is implemented as a local patch for upstream lwIP so it is valid not only with WiFiClient but also with @me-no-dev's Async libraries (they don't use WiFiClient).
WiFiClient::setLocalPortStart() is still usable with the same effects as before.1 parent 9a2ed27 commit a1796f4
File tree
8 files changed
+18
-2
lines changed- tools/sdk
- lib
- lwip2
- include
8 files changed
+18
-2
lines changedBinary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
- .gitignore+5
- Makefile.arduino+1
- Makefile.open+26-11
- glue-esp/lwip-esp.c+3-1
- glue-lwip/arduino/lwipopts.h+6
- glue-lwip/esp-dhcpserver.c+1-1
- glue-lwip/esp-millis.c+66
- glue-lwip/esp-millis.h+9
- glue-lwip/esp-time.c+67
- glue-lwip/espconn.c+9-2
- glue-lwip/espconn_tcp.c+76-2
- glue-lwip/lwip-git.c+14-3
- glue-lwip/lwip/apps-esp/espconn.h+2
- glue-lwip/lwip/apps-esp/espconn_tcp.h+5-2
- glue-lwip/open/lwipopts.h+786-173
- glue/esp-missing.h+12
- glue/glue.h+13
- glue/gluedebug.h+10
- makefiles/Makefile.build-lwip2+7
- makefiles/Makefile.defs+1-1
- makefiles/Makefile.glue+4
- makefiles/Makefile.lwip2+3
- makefiles/patch-non-local-includes+132-7
- makefiles/patch-vendor-lwip14+39
- patches/open/sdk-mem-macros.patch+21
- patches/tcp-random-port.patch+19
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| |||
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| 46 | + | |
42 | 47 | | |
| 48 | + | |
43 | 49 | | |
44 | 50 | | |
45 | 51 | | |
| |||
94 | 100 | | |
95 | 101 | | |
96 | 102 | | |
| 103 | + | |
97 | 104 | | |
98 | 105 | | |
99 | 106 | | |
| |||
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
107 | 117 | | |
108 | 118 | | |
109 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3534 | 3534 | | |
3535 | 3535 | | |
3536 | 3536 | | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
3537 | 3543 | | |
3538 | 3544 | | |
3539 | 3545 | | |
| |||
0 commit comments