Merge branch 'fix/lwip_dhcp_option_len_assert_v5.4' into 'release/v5.4'

fix(lwip): Fix appending DHCP option with HW-ID (v5.4)

See merge request espressif/esp-idf!40232
This commit is contained in:
Jiang Jiang Jian
2025-07-11 13:42:13 +08:00
2 changed files with 17 additions and 6 deletions

View File

@@ -371,9 +371,9 @@ menu "LWIP"
config LWIP_DHCP_OPTIONS_LEN config LWIP_DHCP_OPTIONS_LEN
int "DHCP total option length" int "DHCP total option length"
default 68 if LWIP_DHCP_DISABLE_VENDOR_CLASS_ID default 69 if LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
default 108 if !LWIP_DHCP_DISABLE_VENDOR_CLASS_ID default 109 if !LWIP_DHCP_DISABLE_VENDOR_CLASS_ID
range 68 255 range 69 255
depends on LWIP_IPV4 depends on LWIP_IPV4
help help
Set total length of outgoing DHCP option msg. Generally bigger value means it can carry more Set total length of outgoing DHCP option msg. Generally bigger value means it can carry more

View File

@@ -8,10 +8,20 @@
#include "lwip/prot/dhcp.h" #include "lwip/prot/dhcp.h"
#include "lwip/dhcp.h" #include "lwip/dhcp.h"
#include "lwip/prot/iana.h" #include "lwip/prot/iana.h"
#include "esp_log.h"
#include <string.h> #include <string.h>
#define __weak __attribute__((weak)) #define __weak __attribute__((weak))
/**
* Default lwip behavior is to silence LWIP_ERROR() if LWIP_DEBUG is not set.
* In some case (if IDF hooks are used), we need to log the error message
* instead of silently ignoring it -- using this macro
*/
#define LWIP_ERROR_LOG(message, expression, handler) do { if (!(expression)) { \
ESP_LOGE("LWIP_ERROR", message); \
handler;}} while(0)
#ifdef CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT #ifdef CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT
struct netif *__weak struct netif *__weak
lwip_hook_ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest) lwip_hook_ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)
@@ -243,8 +253,9 @@ void dhcp_append_extra_opts(struct netif *netif, uint8_t state, struct dhcp_msg
state == DHCP_STATE_REQUESTING || state == DHCP_STATE_BACKING_OFF || state == DHCP_STATE_SELECTING) { state == DHCP_STATE_REQUESTING || state == DHCP_STATE_BACKING_OFF || state == DHCP_STATE_SELECTING) {
size_t i; size_t i;
u8_t *options = msg_out->options + *options_out_len; u8_t *options = msg_out->options + *options_out_len;
LWIP_ERROR("dhcp_append(client_id): options_out_len + 3 + netif->hwaddr_len <= DHCP_OPTIONS_LEN", /* size of this option is not hwaddr_len, but hwaddr_len + 1 (IANA_HWTYPE_ETHERNET) */
*options_out_len + 3U + netif->hwaddr_len <= DHCP_OPTIONS_LEN, return;); LWIP_ERROR_LOG("dhcp_append(client_id): options_out_len + 3 + (netif->hwaddr_len + 1) <= DHCP_OPTIONS_LEN, please increase LWIP_DHCP_OPTIONS_LEN",
*options_out_len + 3U + (netif->hwaddr_len + 1) <= DHCP_OPTIONS_LEN, return;);
*options_out_len = *options_out_len + netif->hwaddr_len + 3; *options_out_len = *options_out_len + netif->hwaddr_len + 3;
*options++ = DHCP_OPTION_CLIENT_ID; *options++ = DHCP_OPTION_CLIENT_ID;
*options++ = netif->hwaddr_len + 1; /* option size */ *options++ = netif->hwaddr_len + 1; /* option size */
@@ -274,7 +285,7 @@ void dhcp_append_extra_opts(struct netif *netif, uint8_t state, struct dhcp_msg
} }
#endif /* LWIP_NETIF_HOSTNAME */ #endif /* LWIP_NETIF_HOSTNAME */
} }
LWIP_ERROR("dhcp_append(vci): options_out_len + 3 + vci_size <= DHCP_OPTIONS_LEN", LWIP_ERROR_LOG("dhcp_append(vci): options_out_len + 3 + vci_size <= DHCP_OPTIONS_LEN, please increase LWIP_DHCP_OPTIONS_LEN",
*options_out_len + 3U + len <= DHCP_OPTIONS_LEN, return;); *options_out_len + 3U + len <= DHCP_OPTIONS_LEN, return;);
if (p) { if (p) {
u8_t *options = msg_out->options + *options_out_len; u8_t *options = msg_out->options + *options_out_len;