diff --git a/components/lwip/port/esp32/hooks/lwip_default_hooks.c b/components/lwip/port/esp32/hooks/lwip_default_hooks.c index db34443334..69f3e87e0c 100644 --- a/components/lwip/port/esp32/hooks/lwip_default_hooks.c +++ b/components/lwip/port/esp32/hooks/lwip_default_hooks.c @@ -5,6 +5,8 @@ */ #include "lwip_default_hooks.h" +#include "lwip/prot/dhcp.h" +#include "lwip/dhcp.h" #define __weak __attribute__((weak)) @@ -100,3 +102,27 @@ ip4_route_src_hook(const ip4_addr_t *src,const ip4_addr_t *dest) } #endif #endif /* LWIP_HOOK_IP4_ROUTE_SRC */ + +void dhcp_parse_extra_opts(struct dhcp *dhcp, uint8_t state, uint8_t option, uint8_t len, struct pbuf* p, uint16_t offset) +{ + if ((option == DHCP_OPTION_MTU) && + (state == DHCP_STATE_REBOOTING || state == DHCP_STATE_REBINDING || + state == DHCP_STATE_RENEWING || state == DHCP_STATE_REQUESTING)) { + u32_t mtu = 0; + struct netif *netif; + LWIP_ERROR("dhcp_parse_extra_opts(): MTU option's len != 2", len == 2, return;); + LWIP_ERROR("dhcp_parse_extra_opts(): extracting MTU option failed", + pbuf_copy_partial(p, &mtu, 2, offset) == 2, return;); + mtu = lwip_htons((u16_t)mtu); + NETIF_FOREACH(netif) { + /* find the netif related to this dhcp */ + if (dhcp == netif_dhcp_data(netif)) { + if (mtu < netif->mtu) { + netif->mtu = mtu; + LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_parse_extra_opts(): Negotiated netif MTU is %d\n", netif->mtu)); + } + return; + } + } + } /* DHCP_OPTION_MTU */ +} diff --git a/components/lwip/port/esp32/include/lwip_default_hooks.h b/components/lwip/port/esp32/include/lwip_default_hooks.h index 1577b60e6b..464228b1e7 100644 --- a/components/lwip/port/esp32/include/lwip_default_hooks.h +++ b/components/lwip/port/esp32/include/lwip_default_hooks.h @@ -57,6 +57,9 @@ int lwip_hook_ip6_input(struct pbuf *p, struct netif *inp); struct netif * ip4_route_src_hook(const ip4_addr_t *src,const ip4_addr_t *dest); +struct dhcp; +void dhcp_parse_extra_opts(struct dhcp *dhcp, uint8_t state, uint8_t option, uint8_t len, struct pbuf* p, uint16_t offset); + #ifdef __cplusplus } #endif diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index cc80ca3291..68d948d5a5 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -358,6 +358,11 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) #define DHCP_CALC_TIMEOUT_FROM_OFFERED_T2_REBIND(dhcp) \ timeout_from_offered((dhcp)->offered_t2_rebind, ((dhcp)->t0_timeout/8)*7 /* 87.5% */ ) +#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) \ + do { LWIP_UNUSED_ARG(msg); \ + dhcp_parse_extra_opts(dhcp, state, option, len, pbuf, offset); \ + } while(0) + /* ------------------------------------ ---------- AUTOIP options ----------