6393 Commits

Author SHA1 Message Date
2c6482bafb lwip timer:optimization dhcp fine timer 2022-10-24 16:23:29 +08:00
9bad641bc7 Lwip:add TCP Fin2 timeout configuration 2022-10-18 15:40:05 +08:00
316cfc17ce tcp/close: Fix clean socket closure when lignering
If so_linger option enabled, we should preferably close the socket cleanly. Only
after timeout, we give up and close it with RTS.
2022-09-15 12:36:31 +02:00
8b599aa152 tcp_in: Fix incomplete closure if linger active
If SO_LINGER enabled and lingering close is in progress, we have to
complete the closure to release the blocked api_msg: close(). Otherwise,
it might be blocked forever, as the linked pcb is removed.
2022-09-15 12:36:31 +02:00
0866f57860 ci: Introduce lwip test apps
In some cases it's necessary to test more complex scenarios than single
thread unit tests. The initial socket test uses two threads to verify
basic TCP client-server communicaton.

Ref IDF-4797
2022-09-15 12:35:52 +02:00
ec115c720b ci: Publish branch 2.1.3-esp if CI passes
Ref IDF-4797
2022-08-16 10:48:49 +02:00
e9704b8a8b test/napt: Add unit test for IP forward with PBUF_REF
Picked from espressif/esp-lwip@76303df2
Ref IDF-4797
2022-08-16 10:47:51 +02:00
4a05f3979d napt: Fix PBUF_REF type to clone the pbuf before forwarding
Picked from espressif/esp-idf@39068263
Ref IDF-4800
2022-08-16 10:47:51 +02:00
8a5a30dd5d PPP: Add test exhibiting empty packet null-deref
Also updates lcp.c to compile with PPP_AUTH_SUPPORT=0 in clang

Picked from espressif/esp-lwip@202a07da
Patch posted https://savannah.nongnu.org/patch/?10179
Ref IDF-4797
2022-08-16 10:47:51 +02:00
b5934a2c33 PPP: Fix null-deref when processing wrong packet
This happens during quick reconnect of LTE ppp session.
When processing an input packet containing only zero's,
the pppos state machine assumes these are control fields,
so doesn't allocate any pbuf for data. So if the `PPP_FLAG` comes
(start of another valid packet) in this state and the `FCS` is valid
(which is valid as long as only zero characters are being received)
we de-reference `pppos->in_tail` in pppos.c:544.

Picked from espressif/esp-lwip@537c69d5
Patch posted https://savannah.nongnu.org/patch/?10179
Ref IDF-4847
2022-08-16 10:47:51 +02:00
95048339bf dns: Add API to clear dns cache
Picked from espressif/esp-lwip@ee59f77d
Ref IDF-4839
2022-08-16 10:47:51 +02:00
5446609ae9 timeout: Add function for deinit system timers
Picked from espressif/esp-lwip@2749568f
Ref IDF-4847
2022-08-16 10:47:51 +02:00
e8c46a566b sntp: Fix client receive KOD packet that make pool MEMP_SYS_TIMEOUT not be freed
Reported as https://savannah.nongnu.org/bugs/?58817
picked from espressif/esp-lwip@1c1642fe
Ref IDF-4847
2022-08-16 10:47:51 +02:00
9247429ee4 dns: Fix server_idx increasing to DNS_MAX_SERVERS and trigger the LWIP_ASSERT
ESP specific patch

Picked from espressif/esp-lwip@5a567d52
Ref IDF-4839
2022-08-16 10:47:51 +02:00
223101f1ed tcp_in: Flag the pcb as closing if TCP_EVENT_CLOSED refused
If the packet contained FIN flag, we post a TCP_EVENT_CLOSE with null pbuf,
which could get lost if the underlying platform implementation of sys_mbox_(try)post()
returns ERR_MEM (i.e. won't fit into the recv mailbox).
Loosing this event causes trouble since the FIN initiator gets ACK'ed and
assumes the connection has closed, but the TCP state machine is stuck in its active state.
Fixed by flagging the pcb as closing if the ERR_MEM returned.

Picked from espressif/esp-lwip@d050c331
Patch posted https://savannah.nongnu.org/patch/?10013
Ref IDF-4847
2022-08-16 10:47:51 +02:00
1343f47b0f dhcp: Add dhcp state debug info
Picked from espressif/esp-lwip@9c62fd4e
Ref IDF-4817
2022-08-16 10:47:51 +02:00
84e0273282 slip: Fix SLIP RX linked list append.
Append to the linked list of pbuf objects was broken so that the second
(and subsequent) packets received in a SLIP transaction would be
appended to themselves and consequently lost.
This resulted in these packets being dropped and the system suffering
extreme memory leakage.

Picked from espressif/esp-lwip@01d0ecff
Ref IDF-4847
2022-08-16 10:47:51 +02:00
9d6459ec2d tcp_in: Fix for potential segment overflow
The TCP MSS is 1436, assuming that the received packet length is 1436,
the disordered queue will change in order because of the arrival of this packet.
Make sure that the total length of this package and the shuffled package does not exceed the window

picked from espressif/esp-lwip@7285b846
Ref IDF-4852
2022-08-16 10:47:51 +02:00
a46014d2b9 nd6: Queue IPv6 packets while ND6 inprogress
...and return ERR_MEM on ND6 queue full.
Issue:
When ESP32/S2 UDPv6 TX, the pkts are queued into neighbor cache queue
when MAC address is being resolved, and as a result of LwIP component's "malloc"
use C lib not the LwIP memory pool, which cause the restriction of max
nd6 queue num can't limit the memory use.

picked from espressif/esp-lwip@80d6d19a
Ref IDF-4849
2022-08-16 10:47:51 +02:00
00585644b9 arp: Return ERR_MEM on ARP queue full
Root Cause:
When the ARP cache table is filled, when a new packet comes in, the ARP cache table will be emptied.
Solution:
If the ARP cache table is full, ERR_MEM is returned.

picked from espressif/esp-lwip@602d25c5
Ref IDF-4849
2022-08-16 10:47:51 +02:00
70d46d23cd ip_frag: Drop IPv6 packets larger than MTU
Drop larger packets if ipv6-fragmentation is disabled

Picked from: espressif/esp-lwip@5b2072eb
Ref IDF-4846
2022-08-16 10:47:51 +02:00
c35e4d32f9 ppp: Fix potential array overflow
`vallen` is verified to be less than `len`, therefore, it can never
be the case that `vallen >= len + sizeof(rhostname)`.

This PR fixes the check so the `rhostname` array does not overflow.

Reported-by: Github Security Lab <securitylab@github.com>
Signed-off-by: Alvaro Muñoz <pwntester@github.com>
Ref IDF-4847
2022-08-16 10:47:51 +02:00
66666948f9 sockets: Fix free-select-locked after udp close
ESP_LWIP supports closing socket while waiting. This fixes potential
races.
Orig: fix bug for after udp close select_waiting assert (dd3b3017)

Ref IDF-4794
2022-08-16 10:47:51 +02:00
83edc19882 ip_frag: Drop IPv4 packets larger than MTU
Drop larger packets if ipv4-fragmentation is disabled

Ref IDF-4846
2022-08-16 10:47:51 +02:00
8cf7089c58 api_msg: Fixes for sock close from another thread
Ref IDF-4794
2022-08-16 10:47:51 +02:00
882716f729 sockets: Fix potential race when socket is closed already
Ref IDF-4794
2022-08-16 10:47:51 +02:00
d058bbbe25 sockets: Fix select-waiter when socket closed abruptly
ESP_LWIP supports closing socket while waiting. This fixes potential
races.

Ref IDF-4794
2022-08-16 10:47:51 +02:00
c0fa16fb23 ipv6: Support IPv4/IPv6 mapped PCBs
This change also drops UDP IPv4 packet received on IPv6-only socket.

Ref IDF-4845
2022-08-16 10:47:51 +02:00
9752eb5f98 autoip: Make max-conflics and rate-limit configurable
These constants are defined in RFC-3927 (10 conflicts before rate
limiting and 60 seconds between attempts) and are not intended to be
configurable. We cannot pass BCT without adjusting these params, though.

Ref IDF-4843
2022-08-16 10:47:51 +02:00
771421c863 dns: Support for fallback DNS server
This adds support for list of DNS servers, that could contain manually
configured server that won't be rewritten.
Also if some of the servers in the list is NULL, the algorithm continues
searching with other configured servers up to DNS_MAX_SERVERS.

Ref IDF-4839
2022-08-16 10:47:51 +02:00
7d3b07fdfb igmp/mld6: Add on-demand timers config
IGMP and MLD6 timers activated only when joining groups or receiving
QUERY packets. This reduces the power consumption in applications that
do not use IGMP and MLD6.

Signed-off-by: Sachin Parekh <sachin.parekh@espressif.com>
Co-Authored-By: Axel Lin <axel.lin@gmail.com> (espressif/esp-lwip@b1eec77b)
Ref IDF-4837
2022-08-16 10:47:29 +02:00
f978e87f3c dhcp: Add hook for appending extra client's request options
Co-Authored-By: Liu Han <liuhan@espressif.com> (espressif/esp-lwip@ae7edc2a)
Ref IDF-4817
2022-03-29 16:21:41 +02:00
632ac61f95 dhcp/test: Add dhcp option tests for platform hooks
Testing various cominations of extra dhcp options:
* MTU
* client-id
* VSI/VCI

Ref IDF-4817
2022-03-29 16:20:07 +02:00
0633e7d14b dhcp: Continuously try to rebind in t2 (if failed in t1)
The root cause of this issue is big UDP traffic consuming the buffer
so the DHCP doesn't have the bandwitdh to access the Tx buffer.
More info espressif/esp-lwip!217

Ref IDF-4817
2022-03-25 18:53:06 +01:00
729d724cae dhcp: Set hostname for DISCOVER packets
If the hostname is not set in the DISCOVER packet, then some servers might
issue an OFFER with hostname configured and consequently reject the REQUEST
with any other hostname.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Ref IDF-4817
2022-03-24 18:56:24 +01:00
73a92e31c0 dhcp: Enable custom config for timeouts, thresholds, delays
Also updates timeout type from u16 to u32

Co-Authored-By: David Cermak <cermak@espressif.com>
Co-Authored-By: ronghulin <ronghulin@espressif.com> (espressif/esp-lwip@32b1aaf2)
Ref IDF-4817
2022-03-24 18:56:19 +01:00
14bba8e365 dhcp: Add post_init hook to allow skip discovery
This enables embedded devices restart the DHCP state machine easily
after reset and continue directly with DHCP_BIND of previously bound
address.

Co-Authored-By: MartinValik <martin.valik@mail.com> (espressif/esp-lwip@3b88e84f)
Ref IDF-4817
2022-03-24 10:20:54 +01:00
319d4d3c91 napt: Add basic support for NAT by martin-ger
* Cosmetic updates on NAPT functionality implemented by martin-ger
- moved NAPT specific code from ip4.c to ip4_napt.c
- formatting updates to keep the changes easier to review
- updated per C-90 style used for lwip upstream (fixed warning,
renaming, lwip types)
- esp_random() -> LWIP_RAND()
- drop the connection with routing err if failed to add new napt record
- prepared for lwip unit testing

* Add ip4 routing tests
- lwip native ip-forward tests
- napt feature test udp, tcp
- napt feature, test add/release of nat records
Testing configurations: lwip unit tests are executed in the following
three configurations:
- default
- IP_FORWARD=1
- IP_FORWARD=1 & IP_NAPT=1
Note that debugging option ESP_TEST_DEBUG was introduced to enable running only
IP-FORWARD/IP-NAPT tests with verbose output

* Fix checksum of UDP
- According to the UDP protocol, the checksum is optional.
so if the checksum is 0, this meaning the checksum is turn off, and no need to
correct checksum.

* Fix disbale IPv6 and enable NAPT will build error

Co-Authored-By: David Cermak <cermak@espressif.com> (4b4d6b28, 754b8d5d)
Co-Authored-By: leo chung <gewalalb@gmail.com> (bb63eed1)
Co-Authored-By: yuanjm <yuanjianmin@espressif.com> (74cf7f9f)
Ref IDF-4800
2022-03-24 10:20:47 +01:00
bc50722223 ipv6: Add error check on joining incorrect multicast address
Ref IDF-4799
Picked from espressif/esp-lwip@d8327f98
2022-03-20 11:31:13 +01:00
72105e5338 tcp: Make retransmission timeout (RTO) configurable
Ref IDF-4798
Picked from espressif/esp-lwip@64b640ec
2022-03-20 11:16:38 +01:00
0a9dad958e api_msg: Support sock close from another thread
Add support for closing the socket from another thread
while is blocked on connection.

Ref IDF-4794
2022-03-20 10:08:19 +01:00
5f246f5f78 ci: Add unit test suite to validate tcp state transitions
Ref IDF-4797
2022-03-20 10:08:19 +01:00
4a2fb7801a ci: Add github/lab build/run unit tests on linux
Co-Authored-By: Erik Ekman <erik@kryo.se> (lwip-tcpip/lwip@853258ff)
Co-Authored-By: xueyunfei <xueyunfei@espressif.com> (espressif/esp-lwip@74e2fa32)
Ref IDF-4797
2022-03-20 10:08:19 +01:00
08f1b41db7 ci: Update esp-lwip's version to 2.1.3-esp
Ref IDF-4797
2022-03-20 10:08:19 +01:00
dd27077ab7 Fix compile error with GCC 8 in makefsdata
lwip/lwip/src/apps/http/makefsdata/makefsdata.c:929:56: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
   snprintf(qualifiedName, sizeof(qualifiedName), "%s/%s", curSubdir, filename);

/home/dziegel/lwip/lwip/src/apps/http/makefsdata/makefsdata.c:929:3: note: ‘snprintf’ output 2 or more bytes (assuming 257) into a destination of size 256
   snprintf(qualifiedName, sizeof(qualifiedName), "%s/%s", curSubdir, filename);

Reduce subdir string length by 3 bytes to make the warning go away. The whole file path including directory AND filename is limited to MAX_PATH_LEN - so it is reasonable to reserve 3 bytes less for directory - the filename won't fit anyway in the remaining 3 bytes.

Ref IDF-4797
Picked from lwip-tcpip/lwip@30b2d073
2022-03-19 19:17:47 +01:00
6ca936f6b5 Prepare 2.1.3 release 2021-11-10 19:25:03 +01:00
e7b74570d9 Remove unnecessary files in release tarball
This patch adds a few entries in .gitattributes to specify files that
should never end up in a distribution tarball.

Signed-off-by: Hu Keping <hukeping@huawei.com>
2021-11-10 19:18:11 +01:00
018c64ab94 PPP: assert if ppp_set_* functions are called when session is not dead
ppp_set_* functions that set the PPP session parameters must only be
called when the session is in a dead state (i.e. disconnected),
otherwise not fatal but surprising results may happen.
2021-10-13 21:30:13 +02:00
7e92fb3d7f PPP: remove LWIP_ASSERT_CORE_LOCKED on ppp_set_auth function
We do not have equivalents in PPPAPI for ppp_set_* functions because
calling them only makes sense while session is disconnected, furthermore
they are only setting structure members of the session configuration.
2021-10-13 21:29:29 +02:00
051fbea5e6 Fix bug #54805: IP address can not be obtained over dhcp if PBUF_POOL_BUFSIZE is too small
Patch by Christoph Chang
2021-10-03 12:33:58 +02:00