Skip to content

Commit a9a39bb

Browse files
committed
Merge branch 'bugfix/gateway_wrong_after_dhcp_renewal' into 'master'
fix(dhcp): Fixed incorrect address (mask/gateway) when dhcp renewal See merge request sdk/ESP8266_NONOS_SDK!291
2 parents ecb17ee + 6a8f1e3 commit a9a39bb

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ phy:
1717
gitlab:
1818
driver : 5a2a54b4
1919
json : f55d5fee
20-
lwip : f6bc9a8c
20+
lwip : c7b8f692
2121
mbedtls : 82b93fe5
2222
smartconfig : ea1d4a13(v2.5.5)

lib/liblwip.a

68 Bytes
Binary file not shown.

third_party/lwip/core/dhcp.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,23 +1073,34 @@ dhcp_bind(struct netif *netif)
10731073
/* copy offered network mask */
10741074
ip_addr_copy(sn_mask, dhcp->offered_sn_mask);
10751075
} else {
1076-
/* subnet mask not given, choose a safe subnet mask given the network class */
1077-
u8_t first_octet = ip4_addr1(&dhcp->offered_ip_addr);
1078-
if (first_octet <= 127) {
1079-
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xff000000));
1080-
} else if (first_octet >= 192) {
1081-
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xffffff00));
1082-
} else {
1083-
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xffff0000));
1084-
}
1076+
/* subnet mask not given */
1077+
if (!ip_addr_isany(&netif->netmask)) {
1078+
/* if there is a previous subnet mask, use it */
1079+
ip_addr_copy(sn_mask, netif->netmask);
1080+
} else {
1081+
/* choose a safe subnet mask given the network class */
1082+
u8_t first_octet = ip4_addr1(&dhcp->offered_ip_addr);
1083+
if (first_octet <= 127) {
1084+
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xff000000));
1085+
} else if (first_octet >= 192) {
1086+
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xffffff00));
1087+
} else {
1088+
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xffff0000));
1089+
}
1090+
}
10851091
}
10861092

1087-
ip_addr_copy(gw_addr, dhcp->offered_gw_addr);
10881093
/* gateway address not given? */
1089-
if (ip_addr_isany(&gw_addr)) {
1094+
if (!ip_addr_isany(&dhcp->offered_gw_addr)) {
1095+
/* Use the offered address */
1096+
ip_addr_copy(gw_addr, dhcp->offered_gw_addr);
1097+
} else if (!ip_addr_isany(&netif->gw)) {
1098+
/* Use the address previously received */
1099+
ip_addr_copy(gw_addr, netif->gw);
1100+
} else {
10901101
/* copy network address */
10911102
ip_addr_get_network(&gw_addr, &dhcp->offered_ip_addr, &sn_mask);
1092-
/* use first host address on network as gateway */
1103+
/* assume gateway is xxx.xxx.xxx.1 */
10931104
ip4_addr_set_u32(&gw_addr, ip4_addr_get_u32(&gw_addr) | PP_HTONL(0x00000001));
10941105
}
10951106

0 commit comments

Comments
 (0)