Skip to content

Commit ef2c714

Browse files
committed
feat(lwip): update lwip component according to IDF
commit ID: 79a5b0b5
1 parent da3362e commit ef2c714

File tree

23 files changed

+613
-435
lines changed

23 files changed

+613
-435
lines changed

components/lwip/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(srcs
4747
"lwip/src/core/ipv4/icmp.c"
4848
"lwip/src/core/ipv4/igmp.c"
4949
"lwip/src/core/ipv4/ip4.c"
50+
"lwip/src/core/ipv4/ip4_napt.c"
5051
"lwip/src/core/ipv4/ip4_addr.c"
5152
"lwip/src/core/ipv4/ip4_frag.c"
5253
"lwip/src/core/ipv6/dhcp6.c"
@@ -92,10 +93,6 @@ set(srcs
9293
"port/${target}/netif/dhcp_state.c"
9394
"port/${target}/netif/wlanif.c")
9495

95-
if(CONFIG_IDF_TARGET_ESP32)
96-
list(APPEND srcs
97-
"port/${target}/netif/nettestif.c")
98-
endif()
9996

10097
if(CONFIG_LWIP_PPP_SUPPORT)
10198
list(APPEND srcs

components/lwip/Kconfig

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ menu "LWIP"
7171
will be redirected to lwip_select(), therefore, select can be used
7272
for sockets only.
7373

74+
config LWIP_SO_LINGER
75+
bool "Enable SO_LINGER processing"
76+
default n
77+
help
78+
Enabling this option allows SO_LINGER processing.
79+
l_onoff = 1,l_linger can set the timeout.
80+
81+
If l_linger=0, When a connection is closed, TCP will terminate the connection.
82+
This means that TCP will discard any data packets stored in the socket send buffer
83+
and send an RST to the peer.
84+
85+
If l_linger!=0,Then closesocket() calls to block the process until
86+
the remaining data packets has been sent or timed out.
87+
7488
config LWIP_SO_REUSE
7589
bool "Enable SO_REUSEADDR option"
7690
default y
@@ -105,18 +119,45 @@ menu "LWIP"
105119
Enabling this option allows checking for the destination address
106120
of a received IPv4 Packet.
107121

108-
config LWIP_IP_FRAG
109-
bool "Enable fragment outgoing IP packets"
110-
default n
122+
config LWIP_IP4_FRAG
123+
bool "Enable fragment outgoing IP4 packets"
124+
default y
125+
help
126+
Enabling this option allows fragmenting outgoing IP4 packets if their size
127+
exceeds MTU.
128+
129+
config LWIP_IP6_FRAG
130+
bool "Enable fragment outgoing IP6 packets"
131+
default y
111132
help
112-
Enabling this option allows fragmenting outgoing IP packets if their size
133+
Enabling this option allows fragmenting outgoing IP6 packets if their size
113134
exceeds MTU.
114135

115-
config LWIP_IP_REASSEMBLY
116-
bool "Enable reassembly incoming fragmented IP packets"
136+
config LWIP_IP4_REASSEMBLY
137+
bool "Enable reassembly incoming fragmented IP4 packets"
138+
default n
139+
help
140+
Enabling this option allows reassemblying incoming fragmented IP4 packets.
141+
142+
config LWIP_IP6_REASSEMBLY
143+
bool "Enable reassembly incoming fragmented IP6 packets"
117144
default n
118145
help
119-
Enabling this option allows reassemblying incoming fragmented IP packets.
146+
Enabling this option allows reassemblying incoming fragmented IP6 packets.
147+
148+
config LWIP_IP_FORWARD
149+
bool "Enable IP forwarding"
150+
default n
151+
help
152+
Enabling this option allows packets forwarding across multiple interfaces.
153+
154+
config LWIP_IPV4_NAPT
155+
bool "Enable NAT (new/experimental)"
156+
depends on LWIP_IP_FORWARD
157+
select LWIP_L2_TO_L3_COPY
158+
default n
159+
help
160+
Enabling this option allows Network Address and Port Translation.
120161

121162
config LWIP_STATS
122163
bool "Enable LWIP statistics"
@@ -254,6 +295,14 @@ menu "LWIP"
254295
If rate limiting self-assignment requests, wait this long between
255296
each request.
256297

298+
config LWIP_IPV6_AUTOCONFIG
299+
bool "Enable IPV6 stateless address autoconfiguration"
300+
default n
301+
help
302+
Enabling this option allows the devices to IPV6 stateless address autoconfiguration.
303+
304+
See RFC 4862.
305+
257306
menuconfig LWIP_NETIF_LOOPBACK
258307
bool "Support per-interface loopback"
259308
default y
@@ -344,7 +393,8 @@ menu "LWIP"
344393
config LWIP_TCP_SND_BUF_DEFAULT
345394
int "Default send buffer size"
346395
default 5744 # 4 * default MSS
347-
range 2440 65535
396+
range 2440 65535 if !LWIP_WND_SCALE
397+
range 2440 1024000 if LWIP_WND_SCALE
348398
help
349399
Set default send buffer size for new TCP sockets.
350400

@@ -360,7 +410,8 @@ menu "LWIP"
360410
config LWIP_TCP_WND_DEFAULT
361411
int "Default receive window size"
362412
default 5744 # 4 * default MSS
363-
range 2440 65535
413+
range 2440 65535 if !LWIP_WND_SCALE
414+
range 2440 1024000 if LWIP_WND_SCALE
364415
help
365416
Set default TCP receive window size for new TCP sockets.
366417

@@ -400,6 +451,12 @@ menu "LWIP"
400451
Disable this option to save some RAM during TCP sessions, at the expense
401452
of increased retransmissions if segments arrive out of order.
402453

454+
config LWIP_TCP_SACK_OUT
455+
bool "Support sending selective acknowledgements"
456+
default n
457+
help
458+
TCP will support sending selective acknowledgements (SACKs).
459+
403460
config LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES
404461
bool "Keep TCP connections when IP changed"
405462
default n
@@ -449,6 +506,13 @@ menu "LWIP"
449506
help
450507
Enable this feature to support TCP window scaling.
451508

509+
config LWIP_TCP_RTO_TIME
510+
int "Default TCP rto time"
511+
default 3000
512+
help
513+
Set default TCP rto time for a reasonable initial rto.
514+
In bad network environment, recommend set value of rto time to 1500.
515+
452516
endmenu # TCP
453517

454518
menu "UDP"
@@ -526,6 +590,17 @@ menu "LWIP"
526590

527591
PPP over serial support is experimental and unsupported.
528592

593+
config LWIP_PPP_ENABLE_IPV6
594+
bool "Enable IPV6 support for PPP connections (IPV6CP)"
595+
depends on LWIP_PPP_SUPPORT && LWIP_IPV6
596+
default y
597+
help
598+
Enable IPV6 support in PPP for the local link between the DTE (processor) and DCE (modem).
599+
There are some modems which do not support the IPV6 addressing in the local link.
600+
If they are requested for IPV6CP negotiation, they may time out.
601+
This would in turn fail the configuration for the whole link.
602+
If your modem is not responding correctly to PPP Phase Network, try to disable IPV6 support.
603+
529604
config LWIP_PPP_NOTIFY_PHASE_SUPPORT
530605
bool "Enable Notify Phase Callback"
531606
depends on LWIP_PPP_SUPPORT
@@ -621,4 +696,11 @@ menu "LWIP"
621696

622697
endmenu # SNTP
623698

699+
config LWIP_ESP_LWIP_ASSERT
700+
bool "Enable LWIP ASSERT checks"
701+
default y
702+
help
703+
Enable this option allows lwip to check assert.
704+
It is recommended to keep it open, do not close it.
705+
624706
endmenu

components/lwip/apps/dhcpserver/dhcpserver.c

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,19 @@ typedef struct _list_node {
8181

8282
static const u32_t magic_cookie = 0x63538263;
8383

84-
static struct udp_pcb *pcb_dhcps = NULL;
84+
static struct netif *dhcps_netif = NULL;
8585
static ip4_addr_t broadcast_dhcps;
8686
static ip4_addr_t server_address;
8787
static ip4_addr_t dns_server = {0};
8888
static ip4_addr_t client_address; //added
8989
static ip4_addr_t client_address_plus;
90+
static ip4_addr_t s_dhcps_mask = {
91+
#ifdef USE_CLASS_B_NET
92+
.addr = PP_HTONL(LWIP_MAKEU32(255, 240, 0, 0))
93+
#else
94+
.addr = PP_HTONL(LWIP_MAKEU32(255, 255, 255, 0))
95+
#endif
96+
};
9097

9198
static list_node *plist = NULL;
9299
static bool renew = false;
@@ -136,7 +143,12 @@ void *dhcps_option_info(u8_t op_id, u32_t opt_len)
136143
}
137144

138145
break;
146+
case SUBNET_MASK:
147+
if (opt_len == sizeof(s_dhcps_mask)) {
148+
option_arg = &s_dhcps_mask;
149+
}
139150

151+
break;
140152
default:
141153
break;
142154
}
@@ -185,6 +197,12 @@ void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len)
185197
}
186198
break;
187199

200+
case SUBNET_MASK:
201+
if (opt_len == sizeof(s_dhcps_mask)) {
202+
s_dhcps_mask = *(ip4_addr_t *)opt_info;
203+
}
204+
205+
188206
default:
189207
break;
190208
}
@@ -253,11 +271,13 @@ void node_remove_from_list(list_node **phead, list_node *pdelete)
253271
*phead = NULL;
254272
} else {
255273
if (plist == pdelete) {
256-
*phead = plist->pnext;
274+
// Note: Ignoring the "use after free" warnings, as it could only happen
275+
// if the linked list contains loops
276+
*phead = plist->pnext; // NOLINT(clang-analyzer-unix.Malloc)
257277
pdelete->pnext = NULL;
258278
} else {
259279
while (plist != NULL) {
260-
if (plist->pnext == pdelete) {
280+
if (plist->pnext == pdelete) { // NOLINT(clang-analyzer-unix.Malloc)
261281
plist->pnext = pdelete->pnext;
262282
pdelete->pnext = NULL;
263283
}
@@ -294,21 +314,12 @@ static u8_t *add_offer_options(u8_t *optptr)
294314

295315
ipadd.addr = *((u32_t *) &server_address);
296316

297-
#ifdef USE_CLASS_B_NET
298-
*optptr++ = DHCP_OPTION_SUBNET_MASK;
299-
*optptr++ = 4; //length
300-
*optptr++ = 255;
301-
*optptr++ = 240;
302-
*optptr++ = 0;
303-
*optptr++ = 0;
304-
#else
305317
*optptr++ = DHCP_OPTION_SUBNET_MASK;
306318
*optptr++ = 4;
307-
*optptr++ = 255;
308-
*optptr++ = 255;
309-
*optptr++ = 255;
310-
*optptr++ = 0;
311-
#endif
319+
*optptr++ = ip4_addr1(&s_dhcps_mask);
320+
*optptr++ = ip4_addr2(&s_dhcps_mask);
321+
*optptr++ = ip4_addr3(&s_dhcps_mask);
322+
*optptr++ = ip4_addr4(&s_dhcps_mask);
312323

313324
*optptr++ = DHCP_OPTION_LEASE_TIME;
314325
*optptr++ = 4;
@@ -355,21 +366,13 @@ static u8_t *add_offer_options(u8_t *optptr)
355366
*optptr++ = ip4_addr4(&ipadd);
356367
}
357368

358-
#ifdef CLASS_B_NET
369+
ip4_addr_t broadcast_addr = { .addr = (ipadd.addr & s_dhcps_mask.addr) | ~s_dhcps_mask.addr };
359370
*optptr++ = DHCP_OPTION_BROADCAST_ADDRESS;
360371
*optptr++ = 4;
361-
*optptr++ = ip4_addr1(&ipadd);
362-
*optptr++ = 255;
363-
*optptr++ = 255;
364-
*optptr++ = 255;
365-
#else
366-
*optptr++ = DHCP_OPTION_BROADCAST_ADDRESS;
367-
*optptr++ = 4;
368-
*optptr++ = ip4_addr1(&ipadd);
369-
*optptr++ = ip4_addr2(&ipadd);
370-
*optptr++ = ip4_addr3(&ipadd);
371-
*optptr++ = 255;
372-
#endif
372+
*optptr++ = ip4_addr1(&broadcast_addr);
373+
*optptr++ = ip4_addr2(&broadcast_addr);
374+
*optptr++ = ip4_addr3(&broadcast_addr);
375+
*optptr++ = ip4_addr4(&broadcast_addr);
373376

374377
*optptr++ = DHCP_OPTION_INTERFACE_MTU;
375378
*optptr++ = 2;
@@ -525,6 +528,7 @@ static void send_offer(struct dhcps_msg *m, u16_t len)
525528

526529
ip_addr_t ip_temp = IPADDR4_INIT(0x0);
527530
ip4_addr_set(ip_2_ip4(&ip_temp), &broadcast_dhcps);
531+
struct udp_pcb *pcb_dhcps = dhcps_netif->dhcps_pcb;
528532
#if DHCPS_DEBUG
529533
SendOffer_err_t = udp_sendto(pcb_dhcps, p, &ip_temp, DHCPS_CLIENT_PORT);
530534
DHCPS_LOG("dhcps: send_offer>>udp_sendto result %x\n", SendOffer_err_t);
@@ -602,6 +606,7 @@ static void send_nak(struct dhcps_msg *m, u16_t len)
602606

603607
ip_addr_t ip_temp = IPADDR4_INIT(0x0);
604608
ip4_addr_set(ip_2_ip4(&ip_temp), &broadcast_dhcps);
609+
struct udp_pcb *pcb_dhcps = dhcps_netif->dhcps_pcb;
605610
#if DHCPS_DEBUG
606611
SendNak_err_t = udp_sendto(pcb_dhcps, p, &ip_temp, DHCPS_CLIENT_PORT);
607612
DHCPS_LOG("dhcps: send_nak>>udp_sendto result %x\n", SendNak_err_t);
@@ -678,6 +683,7 @@ static void send_ack(struct dhcps_msg *m, u16_t len)
678683

679684
ip_addr_t ip_temp = IPADDR4_INIT(0x0);
680685
ip4_addr_set(ip_2_ip4(&ip_temp), &broadcast_dhcps);
686+
struct udp_pcb *pcb_dhcps = dhcps_netif->dhcps_pcb;
681687
SendAck_err_t = udp_sendto(pcb_dhcps, p, &ip_temp, DHCPS_CLIENT_PORT);
682688
#if DHCPS_DEBUG
683689
DHCPS_LOG("dhcps: send_ack>>udp_sendto result %x\n", SendAck_err_t);
@@ -1135,19 +1141,20 @@ void dhcps_set_new_lease_cb(dhcps_cb_t cb)
11351141
*******************************************************************************/
11361142
void dhcps_start(struct netif *netif, ip4_addr_t ip)
11371143
{
1138-
struct netif *apnetif = netif;
1144+
dhcps_netif = netif;
11391145

1140-
if (apnetif->dhcps_pcb != NULL) {
1141-
udp_remove(apnetif->dhcps_pcb);
1146+
if (dhcps_netif->dhcps_pcb != NULL) {
1147+
udp_remove(dhcps_netif->dhcps_pcb);
11421148
}
11431149

1144-
pcb_dhcps = udp_new();
1150+
dhcps_netif->dhcps_pcb = udp_new();
1151+
struct udp_pcb *pcb_dhcps = dhcps_netif->dhcps_pcb;
11451152

11461153
if (pcb_dhcps == NULL || ip4_addr_isany_val(ip)) {
11471154
printf("dhcps_start(): could not obtain pcb\n");
11481155
}
11491156

1150-
apnetif->dhcps_pcb = pcb_dhcps;
1157+
dhcps_netif->dhcps_pcb = pcb_dhcps;
11511158

11521159
IP4_ADDR(&broadcast_dhcps, 255, 255, 255, 255);
11531160

@@ -1212,6 +1219,7 @@ static void kill_oldest_dhcps_pool(void)
12121219
list_node *minpre = NULL, *minp = NULL;
12131220
struct dhcps_pool *pdhcps_pool = NULL, *pmin_pool = NULL;
12141221
pre = plist;
1222+
assert(pre != NULL && pre->pnext != NULL); // Expect the list to have at least 2 nodes
12151223
p = pre->pnext;
12161224
minpre = pre;
12171225
minp = p;
@@ -1326,5 +1334,5 @@ dhcps_dns_getserver(void)
13261334
{
13271335
return dns_server;
13281336
}
1329-
#endif
1337+
#endif // ESP_DHCP
13301338

components/lwip/apps/ping/ping_sock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ static int esp_ping_receive(esp_ping_t *ep)
103103
int len = 0;
104104
struct sockaddr_storage from;
105105
int fromlen = sizeof(from);
106+
uint16_t data_head = (uint16_t)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr));
106107

107108
while ((len = recvfrom(ep->sock, buf, sizeof(buf), 0, (struct sockaddr *)&from, (socklen_t *)&fromlen)) > 0) {
108-
if (len >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
109-
ep->recv_len = (uint32_t)len;
109+
if (len >= data_head) {
110110
if (from.ss_family == AF_INET) {
111111
// IPv4
112112
struct sockaddr_in *from4 = (struct sockaddr_in *)&from;
@@ -128,6 +128,7 @@ static int esp_ping_receive(esp_ping_t *ep)
128128
if ((iecho->id == ep->packet_hdr->id) && (iecho->seqno == ep->packet_hdr->seqno)) {
129129
ep->received++;
130130
ep->ttl = iphdr->_ttl;
131+
ep->recv_len = lwip_ntohs(IPH_LEN(iphdr)) - data_head; // The data portion of ICMP
131132
return len;
132133
}
133134
}

0 commit comments

Comments
 (0)