mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-12 17:14:36 +02:00
lwip: Implement DHCP hook supporting MTU option
This commit is contained in:
@@ -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 */
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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 ----------
|
||||
|
Reference in New Issue
Block a user