Skip to content

Commit d9457b8

Browse files
committed
Merge branch 'fix/lwip_dhcp_option_len_assert' into 'master'
fix(lwip): Fix appending DHCP option with HW-ID Closes IDF-13354 See merge request espressif/esp-idf!39749
2 parents a8bf745 + a39d389 commit d9457b8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

components/lwip/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ menu "LWIP"
371371

372372
config LWIP_DHCP_OPTIONS_LEN
373373
int "DHCP total option length"
374-
default 68 if LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
375-
default 108 if !LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
376-
range 68 255
374+
default 69 if LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
375+
default 109 if !LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
376+
range 69 255
377377
depends on LWIP_IPV4
378378
help
379379
Set total length of outgoing DHCP option msg. Generally bigger value means it can carry more

components/lwip/port/hooks/lwip_default_hooks.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@
88
#include "lwip/prot/dhcp.h"
99
#include "lwip/dhcp.h"
1010
#include "lwip/prot/iana.h"
11+
#include "esp_log.h"
1112
#include <string.h>
1213

1314
#define __weak __attribute__((weak))
1415

16+
/**
17+
* Default lwip behavior is to silence LWIP_ERROR() if LWIP_DEBUG is not set.
18+
* In some case (if IDF hooks are used), we need to log the error message
19+
* instead of silently ignoring it -- using this macro
20+
*/
21+
#define LWIP_ERROR_LOG(message, expression, handler) do { if (!(expression)) { \
22+
ESP_LOGE("LWIP_ERROR", message); \
23+
handler;}} while(0)
24+
1525
#ifdef CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT
1626
struct netif *__weak
1727
lwip_hook_ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
@@ -259,8 +269,9 @@ void dhcp_append_extra_opts(struct netif *netif, uint8_t state, struct dhcp_msg
259269
state == DHCP_STATE_REQUESTING || state == DHCP_STATE_BACKING_OFF || state == DHCP_STATE_SELECTING) {
260270
size_t i;
261271
u8_t *options = msg_out->options + *options_out_len;
262-
LWIP_ERROR("dhcp_append(client_id): options_out_len + 3 + netif->hwaddr_len <= DHCP_OPTIONS_LEN",
263-
*options_out_len + 3U + netif->hwaddr_len <= DHCP_OPTIONS_LEN, return;);
272+
/* size of this option is not hwaddr_len, but hwaddr_len + 1 (IANA_HWTYPE_ETHERNET) */
273+
LWIP_ERROR_LOG("dhcp_append(client_id): options_out_len + 3 + (netif->hwaddr_len + 1) <= DHCP_OPTIONS_LEN, please increase LWIP_DHCP_OPTIONS_LEN",
274+
*options_out_len + 3U + (netif->hwaddr_len + 1) <= DHCP_OPTIONS_LEN, return;);
264275
*options_out_len = *options_out_len + netif->hwaddr_len + 3;
265276
*options++ = DHCP_OPTION_CLIENT_ID;
266277
*options++ = netif->hwaddr_len + 1; /* option size */
@@ -290,7 +301,7 @@ void dhcp_append_extra_opts(struct netif *netif, uint8_t state, struct dhcp_msg
290301
}
291302
#endif /* LWIP_NETIF_HOSTNAME */
292303
}
293-
LWIP_ERROR("dhcp_append(vci): options_out_len + 3 + vci_size <= DHCP_OPTIONS_LEN",
304+
LWIP_ERROR_LOG("dhcp_append(vci): options_out_len + 3 + vci_size <= DHCP_OPTIONS_LEN, please increase LWIP_DHCP_OPTIONS_LEN",
294305
*options_out_len + 3U + len <= DHCP_OPTIONS_LEN, return;);
295306
if (p) {
296307
u8_t *options = msg_out->options + *options_out_len;

0 commit comments

Comments
 (0)