mirror of
https://github.com/espressif/esp-lwip.git
synced 2026-08-25 11:20:02 +00:00
dhcp: Fix client identifier to be added to relevant packets
Also added a configuration macro to disable client id option in DHCP packets Closes https://github.com/espressif/esp-lwip/issues/30
This commit is contained in:
committed by
David Čermák
parent
5a567d52f7
commit
2195f7416f
+44
-12
@@ -221,6 +221,9 @@ static u16_t dhcp_option_long(u16_t options_out_len, u8_t *options, u32_t value)
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
static u16_t dhcp_option_hostname(u16_t options_out_len, u8_t *options, struct netif *netif);
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
#if ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
static u16_t dhcp_option_client_id(struct netif *netif, struct dhcp_msg *msg_out, u16_t options_out_len);
|
||||
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
/* always add the DHCP options trailer to end and pad */
|
||||
static void dhcp_option_trailer(u16_t options_out_len, u8_t *options, struct pbuf *p_out);
|
||||
|
||||
@@ -403,13 +406,9 @@ dhcp_select(struct netif *netif)
|
||||
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_REQUESTED_IP, 4);
|
||||
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
|
||||
|
||||
#if ESP_DHCP
|
||||
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_CLIENT_ID, DHCP_OPTION_CLIENT_ID_MAC_LEN);
|
||||
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, DHCP_OPTION_CLIENT_ID_MAC);
|
||||
for (i = 0; i < netif->hwaddr_len; i++) {
|
||||
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, netif->hwaddr[i]);
|
||||
}
|
||||
#endif/* ESP_DHCP */
|
||||
#if ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
options_out_len = dhcp_option_client_id(netif, msg_out, options_out_len);
|
||||
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
|
||||
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_SERVER_ID, 4);
|
||||
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr))));
|
||||
@@ -1036,6 +1035,10 @@ dhcp_decline(struct netif *netif)
|
||||
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_REQUESTED_IP, 4);
|
||||
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
|
||||
|
||||
#if ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
options_out_len = dhcp_option_client_id(netif, msg_out, options_out_len);
|
||||
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_BACKING_OFF, msg_out, DHCP_DECLINE, &options_out_len);
|
||||
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
|
||||
|
||||
@@ -1094,11 +1097,9 @@ dhcp_discover(struct netif *netif)
|
||||
options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif);
|
||||
#endif /* LWIP NETIF HOSTNAME */
|
||||
|
||||
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_CLIENT_ID, DHCP_OPTION_CLIENT_ID_MAC_LEN);
|
||||
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, DHCP_OPTION_CLIENT_ID_MAC);
|
||||
for (i = 0; i < netif->hwaddr_len; i++) {
|
||||
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, netif->hwaddr[i]);
|
||||
}
|
||||
#if !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
options_out_len = dhcp_option_client_id(netif, msg_out, options_out_len);
|
||||
#endif /* !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
#endif/* ESP_DHCP */
|
||||
|
||||
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
|
||||
@@ -1340,6 +1341,10 @@ dhcp_renew(struct netif *netif)
|
||||
options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif);
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
#if ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
options_out_len = dhcp_option_client_id(netif, msg_out, options_out_len);
|
||||
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_RENEWING, msg_out, DHCP_REQUEST, &options_out_len);
|
||||
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
|
||||
|
||||
@@ -1395,6 +1400,10 @@ dhcp_rebind(struct netif *netif)
|
||||
options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif);
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
#if ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
options_out_len = dhcp_option_client_id(netif, msg_out, options_out_len);
|
||||
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REBINDING, msg_out, DHCP_DISCOVER, &options_out_len);
|
||||
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
|
||||
|
||||
@@ -1452,6 +1461,10 @@ dhcp_reboot(struct netif *netif)
|
||||
options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif);
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
#if ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
options_out_len = dhcp_option_client_id(netif, msg_out, options_out_len);
|
||||
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REBOOTING, msg_out, DHCP_REQUEST, &options_out_len);
|
||||
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
|
||||
|
||||
@@ -1519,6 +1532,10 @@ dhcp_release_and_stop(struct netif *netif)
|
||||
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_SERVER_ID, 4);
|
||||
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&server_ip_addr))));
|
||||
|
||||
#if ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
options_out_len = dhcp_option_client_id(netif, msg_out, options_out_len);
|
||||
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
|
||||
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, dhcp->state, msg_out, DHCP_RELEASE, &options_out_len);
|
||||
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
|
||||
|
||||
@@ -1665,6 +1682,21 @@ dhcp_option_hostname(u16_t options_out_len, u8_t *options, struct netif *netif)
|
||||
}
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
#if ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID
|
||||
static u16_t
|
||||
dhcp_option_client_id(struct netif *netif, struct dhcp_msg *msg_out, u16_t options_out_len)
|
||||
{
|
||||
size_t i;
|
||||
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_CLIENT_ID, DHCP_OPTION_CLIENT_ID_MAC_LEN);
|
||||
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, DHCP_OPTION_CLIENT_ID_MAC);
|
||||
for (i = 0; i < netif->hwaddr_len; i++) {
|
||||
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, netif->hwaddr[i]);
|
||||
}
|
||||
return options_out_len;
|
||||
}
|
||||
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_CLIENT_ID */
|
||||
|
||||
|
||||
/**
|
||||
* Extract the DHCP message and the DHCP options.
|
||||
*
|
||||
|
||||
@@ -104,6 +104,7 @@
|
||||
#define TCP_OOSEQ_DEBUG LWIP_DBG_ON
|
||||
#define ESP_DHCP_DEBUG 1
|
||||
#define ESP_THREAD_PROTECTION 0
|
||||
#define ESP_DHCP_DISABLE_CLIENT_ID 0
|
||||
|
||||
#ifdef IP_NAPT
|
||||
#define IP_NAPT_MAX 16
|
||||
|
||||
Reference in New Issue
Block a user