From 2fce539d1e70e1d52ad102c96dea34e9b2d47d78 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 2 Apr 2020 19:46:45 +0200 Subject: [PATCH] esp-netif: use dhcp server netmask Use the configured esp-netif netmask to update the dhcp struct when starting the server or starting the netif itself. Use the netmask in dhcps setters and getters. --- components/esp_netif/include/esp_netif_types.h | 3 ++- components/esp_netif/lwip/esp_netif_lwip.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/components/esp_netif/include/esp_netif_types.h b/components/esp_netif/include/esp_netif_types.h index b55d1650f..0e3613932 100644 --- a/components/esp_netif/include/esp_netif_types.h +++ b/components/esp_netif/include/esp_netif_types.h @@ -73,6 +73,7 @@ typedef enum{ /** @brief Supported options for DHCP client or DHCP server */ typedef enum{ + ESP_NETIF_SUBNET_MASK = 1, /**< Network mask */ ESP_NETIF_DOMAIN_NAME_SERVER = 6, /**< Domain name server */ ESP_NETIF_ROUTER_SOLICITATION_ADDRESS = 32, /**< Solicitation router address */ ESP_NETIF_REQUESTED_IP_ADDRESS = 50, /**< Request specific IP address */ @@ -212,4 +213,4 @@ typedef esp_err_t (*esp_netif_receive_t)(esp_netif_t *esp_netif, void *buffer, s } #endif -#endif // _ESP_NETIF_TYPES_H_ \ No newline at end of file +#endif // _ESP_NETIF_TYPES_H_ diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 6282293d1..bd6a201f8 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -627,8 +627,11 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg) if (p_netif != NULL && netif_is_up(p_netif)) { esp_netif_ip_info_t *default_ip = esp_netif->ip_info; ip4_addr_t lwip_ip; + ip4_addr_t lwip_netmask; memcpy(&lwip_ip, &default_ip->ip, sizeof(struct ip4_addr)); + memcpy(&lwip_netmask, &default_ip->netmask, sizeof(struct ip4_addr)); dhcps_set_new_lease_cb(esp_netif_dhcps_cb); + dhcps_set_option_info(SUBNET_MASK, (void*)&lwip_netmask, sizeof(lwip_netmask)); dhcps_start(p_netif, lwip_ip); esp_netif->dhcps_status = ESP_NETIF_DHCP_STARTED; ESP_LOGD(TAG, "DHCP server started successfully"); @@ -986,8 +989,11 @@ static esp_err_t esp_netif_dhcps_start_api(esp_netif_api_msg_t *msg) if (p_netif != NULL && netif_is_up(p_netif)) { esp_netif_ip_info_t *default_ip = esp_netif->ip_info; ip4_addr_t lwip_ip; + ip4_addr_t lwip_netmask; memcpy(&lwip_ip, &default_ip->ip, sizeof(struct ip4_addr)); + memcpy(&lwip_netmask, &default_ip->netmask, sizeof(struct ip4_addr)); dhcps_set_new_lease_cb(esp_netif_dhcps_cb); + dhcps_set_option_info(SUBNET_MASK, (void*)&lwip_netmask, sizeof(lwip_netmask)); dhcps_start(p_netif, lwip_ip); esp_netif->dhcps_status = ESP_NETIF_DHCP_STARTED; ESP_LOGD(TAG, "DHCP server started successfully"); @@ -1547,6 +1553,7 @@ esp_err_t esp_netif_dhcps_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_m *(uint32_t *)opt_val = *(uint32_t *)opt_info; break; } + case ESP_NETIF_SUBNET_MASK: case REQUESTED_IP_ADDRESS: { memcpy(opt_val, opt_info, opt_len); break; @@ -1584,6 +1591,10 @@ esp_err_t esp_netif_dhcps_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_m } break; } + case ESP_NETIF_SUBNET_MASK: { + memcpy(opt_info, opt_val, opt_len); + break; + } case REQUESTED_IP_ADDRESS: { esp_netif_ip_info_t info; uint32_t softap_ip = 0;