Skip to content

Commit d4f60fe

Browse files
committed
Merge branch 'feat/lwip_2.2.0' into 'master'
feat(lwip): Support for new lwip release 2.2.0 Closes IDFGH-11237 See merge request espressif/esp-idf!30388
2 parents e035e79 + 015ab1d commit d4f60fe

File tree

11 files changed

+201
-38
lines changed

11 files changed

+201
-38
lines changed

components/esp_netif/lwip/esp_netif_lwip.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,25 +1154,13 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg)
11541154
#else
11551155
LOG_NETIF_DISABLED_AND_DO("DHCP Server", return ESP_ERR_NOT_SUPPORTED);
11561156
#endif
1157-
} else if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT) {
1158-
#if CONFIG_LWIP_IPV4
1159-
if (esp_netif->dhcpc_status != ESP_NETIF_DHCP_STARTED) {
1160-
if (p_netif != NULL) {
1161-
struct dhcp *dhcp_data = NULL;
1162-
dhcp_data = netif_dhcp_data(p_netif);
1163-
if (dhcp_data == NULL) {
1164-
dhcp_data = (struct dhcp *)malloc(sizeof(struct dhcp));
1165-
if (dhcp_data == NULL) {
1166-
return ESP_ERR_NO_MEM;
1167-
}
1168-
dhcp_set_struct(p_netif, dhcp_data);
1169-
}
1170-
}
1171-
}
1172-
#else
1157+
}
1158+
#ifndef CONFIG_LWIP_IPV4
1159+
else if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT) {
11731160
LOG_NETIF_DISABLED_AND_DO("IPv4's DHCP Client", return ESP_ERR_NOT_SUPPORTED);
1174-
#endif
11751161
}
1162+
#endif
1163+
11761164
// For netifs with (active) DHCP client: we update the default netif after getting a valid IP
11771165
if (!((esp_netif->flags & ESP_NETIF_DHCP_CLIENT) && esp_netif->dhcpc_status != ESP_NETIF_DHCP_STOPPED)) {
11781166
esp_netif_update_default_netif(esp_netif, ESP_NETIF_STARTED);

components/esp_netif/lwip/esp_netif_lwip_ppp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ static void on_ppp_notify_phase(ppp_pcb *pcb, u8_t phase, void *ctx)
175175
*
176176
* @return uint32_t Length of data successfully sent
177177
*/
178-
static uint32_t pppos_low_level_output(ppp_pcb *pcb, uint8_t *data, uint32_t len, void *netif)
178+
static uint32_t pppos_low_level_output(ppp_pcb *pcb, const void *data, uint32_t len, void *netif)
179179
{
180-
esp_err_t ret = esp_netif_transmit(netif, data, len);
180+
esp_err_t ret = esp_netif_transmit(netif, (void*)data, len);
181181
if (ret == ESP_OK) {
182182
return len;
183183
}

components/lwip/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ if(CONFIG_LWIP_ENABLE)
135135
"lwip/src/netif/ppp/vj.c")
136136
endif()
137137

138-
if(NOT ${target} STREQUAL "linux")
138+
if(CONFIG_LWIP_DHCP_DOES_ARP_CHECK)
139+
list(APPEND srcs "port/acd_dhcp_check.c")
140+
elseif(CONFIG_LWIP_DHCP_DOES_ACD_CHECK)
141+
list(APPEND srcs "lwip/src/core/ipv4/acd.c")
142+
endif()
143+
144+
if(NOT ${target} STREQUAL "linux")
139145
# Support for vfs and linker fragments only for target builds
140146
set(linker_fragments linker.lf)
141147
if(CONFIG_VFS_SUPPORT_IO)

components/lwip/Kconfig

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,29 @@ menu "LWIP"
318318
Set TCPIP task receive mail box size. Generally bigger value means higher throughput
319319
but more memory. The value should be bigger than UDP/TCP mail box size.
320320

321-
config LWIP_DHCP_DOES_ARP_CHECK
322-
bool "DHCP: Perform ARP check on any offered address"
323-
default y
321+
choice LWIP_DHCP_CHECKS_OFFERED_ADDRESS
322+
prompt "Choose how DHCP validates offered IP"
323+
default LWIP_DHCP_DOES_ARP_CHECK
324324
depends on LWIP_IPV4
325325
help
326-
Enabling this option performs a check (via ARP request) if the offered IP address
327-
is not already in use by another host on the network.
326+
Choose the preferred way of DHCP client to check if the offered address
327+
is available:
328+
* Using Address Conflict Detection (ACD) module assures that the offered IP address
329+
is properly probed and announced before binding in DHCP. This conforms to RFC5227,
330+
but takes several seconds.
331+
* Using ARP check, we only send two ARP requests to check for replies. This process
332+
lasts 1 - 2 seconds.
333+
* No conflict detection: We directly bind the offered address.
334+
335+
config LWIP_DHCP_DOES_ARP_CHECK
336+
bool "DHCP provides simple ARP check"
337+
depends on !LWIP_AUTOIP
338+
config LWIP_DHCP_DOES_ACD_CHECK
339+
bool "DHCP provides Address Conflict Detection (ACD)"
340+
config LWIP_DHCP_DOES_NOT_CHECK_OFFERED_IP
341+
bool "DHCP does not detect conflict on the offered IP"
342+
343+
endchoice
328344

329345
config LWIP_DHCP_DISABLE_CLIENT_ID
330346
bool "DHCP: Disable Use of HW address as client identification"

components/lwip/linker.lf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ entries:
112112
tcp_out:tcp_rexmit_rto_prepare (noflash_text)
113113
tcp_out:tcp_rexmit (noflash_text)
114114
tcp_out:tcp_rexmit_fast (noflash_text)
115-
tcp_out:tcp_output_control_segment (noflash_text)
115+
tcp_out:tcp_output_control_segment_netif (noflash_text)
116116
tcp_out:tcp_rst (noflash_text)
117117
tcp_out:tcp_send_empty_ack (noflash_text)
118118
sys_arch:sys_arch_protect (noflash_text)

components/lwip/lwip

Submodule lwip updated 566 files

components/lwip/port/acd_dhcp_check.c

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include "lwip/opt.h"
7+
8+
/* don't build if not configured for use in lwipopts.h */
9+
#if LWIP_IPV4 && DHCP_DOES_ARP_CHECK
10+
11+
#include "lwip/acd.h"
12+
#include "lwip/dhcp.h"
13+
#include "lwip/prot/dhcp.h"
14+
#include "lwip/timeouts.h"
15+
16+
#define ACD_DHCP_ARP_REPLY_TIMEOUT_MS 500
17+
18+
static void
19+
acd_dhcp_check_timeout_cb(void *arg);
20+
21+
static void
22+
acd_suspend(struct netif *netif)
23+
{
24+
struct dhcp *dhcp;
25+
struct acd *acd;
26+
if (netif == NULL || (dhcp = netif_dhcp_data(netif)) == NULL) {
27+
return;
28+
}
29+
acd = &dhcp->acd;
30+
acd->state = ACD_STATE_OFF;
31+
sys_untimeout(acd_dhcp_check_timeout_cb, (void *)netif);
32+
}
33+
34+
void
35+
acd_remove(struct netif *netif, struct acd *acd)
36+
{
37+
acd_suspend(netif);
38+
acd->acd_conflict_callback = NULL;
39+
}
40+
41+
void
42+
acd_netif_ip_addr_changed(struct netif *netif, const ip_addr_t *old_addr,
43+
const ip_addr_t *new_addr)
44+
{
45+
acd_suspend(netif);
46+
}
47+
48+
void
49+
acd_network_changed_link_down(struct netif *netif)
50+
{
51+
acd_suspend(netif);
52+
}
53+
54+
void
55+
acd_arp_reply(struct netif *netif, struct etharp_hdr *hdr)
56+
{
57+
struct dhcp *dhcp;
58+
ip4_addr_t sipaddr;
59+
struct eth_addr netifaddr;
60+
struct acd *acd;
61+
if (netif == NULL || (dhcp = netif_dhcp_data(netif)) == NULL) {
62+
return;
63+
}
64+
acd = &dhcp->acd;
65+
// Check that we're looking for ARP reply in ACD_PROBING state and DHCP_CHECKING state
66+
if (hdr->opcode != PP_HTONS(ARP_REPLY) || dhcp->state != DHCP_STATE_CHECKING ||
67+
acd->state != ACD_STATE_PROBING || acd->acd_conflict_callback == NULL) {
68+
return;
69+
}
70+
SMEMCPY(netifaddr.addr, netif->hwaddr, ETH_HWADDR_LEN);
71+
IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(&sipaddr, &hdr->sipaddr);
72+
LWIP_DEBUGF(ACD_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("acd_arp_reply(): CHECKING, arp reply for 0x%08"X32_F"\n",
73+
ip4_addr_get_u32(&sipaddr)));
74+
/* did another host (not our mac addr) respond with the address we were offered by the DHCP server? */
75+
if (ip4_addr_eq(&sipaddr, &dhcp->offered_ip_addr) &&
76+
!eth_addr_eq(&netifaddr, &hdr->shwaddr)) {
77+
LWIP_DEBUGF(ACD_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
78+
("acd_arp_reply(): arp reply matched with offered address, declining\n"));
79+
dhcp->acd.acd_conflict_callback(netif, ACD_DECLINE);
80+
}
81+
}
82+
83+
err_t
84+
acd_add(struct netif *netif, struct acd *acd,
85+
acd_conflict_callback_t acd_conflict_callback)
86+
{
87+
acd->acd_conflict_callback = acd_conflict_callback;
88+
return ERR_OK;
89+
}
90+
91+
static void send_probe_once(struct netif *netif)
92+
{
93+
struct dhcp *dhcp = netif_dhcp_data(netif);
94+
if (etharp_query(netif, &dhcp->offered_ip_addr, NULL) != ERR_OK) {
95+
LWIP_DEBUGF(ACD_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("acd_send_probe_once(): could not perform ARP query\n"));
96+
return;
97+
}
98+
if (dhcp->tries < 255) {
99+
dhcp->tries++;
100+
}
101+
LWIP_DEBUGF(ACD_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("acd_send_probe_once(): set request timeout %"U16_F" msecs\n", ACD_DHCP_ARP_REPLY_TIMEOUT_MS));
102+
sys_timeout(ACD_DHCP_ARP_REPLY_TIMEOUT_MS, acd_dhcp_check_timeout_cb, (void *)netif);
103+
}
104+
105+
static void
106+
acd_dhcp_check_timeout_cb(void *arg)
107+
{
108+
struct netif *netif = (struct netif *)arg;
109+
struct dhcp *dhcp;
110+
struct acd *acd;
111+
if (netif == NULL || (dhcp = netif_dhcp_data(netif)) == NULL) {
112+
return;
113+
}
114+
acd = &dhcp->acd;
115+
if (acd->state != ACD_STATE_PROBING || acd->acd_conflict_callback == NULL || dhcp->state != DHCP_STATE_CHECKING) {
116+
return;
117+
}
118+
LWIP_DEBUGF(ACD_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("acd_dhcp_check_timeout_cb(): CHECKING, ARP request timed out\n"));
119+
if (dhcp->tries <= 1) {
120+
send_probe_once(netif);
121+
} else {
122+
// No conflict detected
123+
dhcp->acd.acd_conflict_callback(netif, ACD_IP_OK);
124+
}
125+
}
126+
127+
err_t
128+
acd_start(struct netif *netif, struct acd *acd, ip4_addr_t ipaddr)
129+
{
130+
if (netif == NULL || netif_dhcp_data(netif) == NULL) {
131+
return ERR_ARG;
132+
}
133+
acd->state = ACD_STATE_PROBING;
134+
send_probe_once(netif);
135+
return ERR_OK;
136+
}
137+
138+
#endif /* LWIP_IPV4 && DHCP_DOES_ARP_CHECK */

components/lwip/port/include/lwipopts.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,23 @@ extern "C" {
308308
#define LWIP_DHCP 1
309309

310310
/**
311-
* DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address.
311+
* LWIP_DHCP_CHECKS_OFFERED_ADDRESS:
312+
* - Using Address Conflict Detection (ACD) module assures that the offered IP address
313+
* is properly probed and announced before binding in DHCP. This conforms to RFC5227,
314+
* but takes several seconds.
315+
* - Using ARP check, we only send two ARP requests to check for replies. This process
316+
* lasts 1 - 2 seconds.
317+
* - No conflict detection: We directly bind the offered address.
312318
*/
313319
#ifdef CONFIG_LWIP_DHCP_DOES_ARP_CHECK
314320
#define DHCP_DOES_ARP_CHECK 1
321+
#define LWIP_DHCP_DOES_ACD_CHECK 1
322+
#elif CONFIG_LWIP_DHCP_DOES_ACD_CHECK
323+
#define DHCP_DOES_ARP_CHECK 0
324+
#define LWIP_DHCP_DOES_ACD_CHECK 1
315325
#else
316326
#define DHCP_DOES_ARP_CHECK 0
327+
#define LWIP_DHCP_DOES_ACD_CHECK 0
317328
#endif
318329

319330
/**
@@ -381,7 +392,7 @@ extern "C" {
381392
/* Since for embedded devices it's not that hard to miss a discover packet, so lower
382393
* the discover and request retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,4,4,4)s.
383394
*/
384-
#define DHCP_REQUEST_TIMEOUT_SEQUENCE(tries) ((uint16_t)(((tries) < 5 ? 1 << (tries) : 16) * 250))
395+
#define DHCP_REQUEST_BACKOFF_SEQUENCE(state, tries) ((uint16_t)(((tries) < 5 ? 1 << (tries) : 16) * 250))
385396

386397
static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
387398
{
@@ -393,12 +404,12 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
393404
return timeout;
394405
}
395406

396-
#define DHCP_CALC_TIMEOUT_FROM_OFFERED_T0_LEASE(dhcp) \
397-
timeout_from_offered((dhcp)->offered_t0_lease, 120)
398-
#define DHCP_CALC_TIMEOUT_FROM_OFFERED_T1_RENEW(dhcp) \
399-
timeout_from_offered((dhcp)->offered_t1_renew, (dhcp)->t0_timeout>>1 /* 50% */ )
400-
#define DHCP_CALC_TIMEOUT_FROM_OFFERED_T2_REBIND(dhcp) \
401-
timeout_from_offered((dhcp)->offered_t2_rebind, ((dhcp)->t0_timeout/8)*7 /* 87.5% */ )
407+
#define DHCP_SET_TIMEOUT_FROM_OFFERED_T0_LEASE(tout, dhcp) do { \
408+
(tout) = timeout_from_offered((dhcp)->offered_t0_lease, 120); } while(0)
409+
#define DHCP_SET_TIMEOUT_FROM_OFFERED_T1_RENEW(tout, dhcp) do { \
410+
(tout) = timeout_from_offered((dhcp)->offered_t1_renew, (dhcp)->t0_timeout>>1 /* 50% */ ); } while(0)
411+
#define DHCP_SET_TIMEOUT_FROM_OFFERED_T2_REBIND(tout, dhcp) do { \
412+
(tout) = timeout_from_offered((dhcp)->offered_t2_rebind, ((dhcp)->t0_timeout/8)*7 /* 87.5% */ ); } while(0)
402413

403414
#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) \
404415
do { LWIP_UNUSED_ARG(msg); \
@@ -692,8 +703,12 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
692703
/**
693704
* LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname
694705
* field.
706+
* LWIP_DHCP_DISCOVER_ADD_HOSTNAME==1: include hostname opt in discover packets.
707+
* If the hostname is not set in the DISCOVER packet, then some servers might issue
708+
* an OFFER with hostname configured and consequently reject the REQUEST with any other hostname.
695709
*/
696710
#define LWIP_NETIF_HOSTNAME 1
711+
#define LWIP_DHCP_DISCOVER_ADD_HOSTNAME 1
697712

698713
/**
699714
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)

components/lwip/port/include/netinet/in.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@
99

1010
#include "lwip/inet.h"
1111

12-
#define IN6_IS_ADDR_MULTICAST(a) IN_MULTICAST(a)
13-
1412
#endif /* IN_H_ */

tools/ci/check_public_headers_exceptions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ components/lwip/lwip/src/include/lwip/priv/memp_std.h
2424
components/lwip/include/lwip/sockets.h
2525
components/lwip/lwip/src/include/lwip/prot/nd6.h
2626
components/lwip/lwip/src/include/netif/ppp/
27+
components/lwip/lwip/src/include/lwip/apps/tftp_server.h
28+
components/lwip/lwip/src/include/lwip/apps/tftp_client.h
2729

2830
components/spi_flash/include/spi_flash_chip_issi.h
2931
components/spi_flash/include/spi_flash_chip_mxic.h

0 commit comments

Comments
 (0)