Merge branch 'feature/dhcps_config_mask' into 'master'

dhcp sever: Make option netmask configurable

Closes IDFGH-2955

See merge request espressif/esp-idf!8238
pull/5191/head
David Čermák 2020-05-04 14:22:55 +08:00
commit 2e06e9c15b
3 zmienionych plików z 40 dodań i 27 usunięć

Wyświetl plik

@ -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_
#endif // _ESP_NETIF_TYPES_H_

Wyświetl plik

@ -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;

Wyświetl plik

@ -87,6 +87,13 @@ static ip4_addr_t server_address;
static ip4_addr_t dns_server = {0};
static ip4_addr_t client_address; //added
static ip4_addr_t client_address_plus;
static ip4_addr_t s_dhcps_mask = {
#ifdef USE_CLASS_B_NET
.addr = PP_HTONL(LWIP_MAKEU32(255, 240, 0, 0))
#else
.addr = PP_HTONL(LWIP_MAKEU32(255, 255, 255, 0))
#endif
};
static list_node *plist = NULL;
static bool renew = false;
@ -136,7 +143,12 @@ void *dhcps_option_info(u8_t op_id, u32_t opt_len)
}
break;
case SUBNET_MASK:
if (opt_len == sizeof(s_dhcps_mask)) {
option_arg = &s_dhcps_mask;
}
break;
default:
break;
}
@ -185,6 +197,12 @@ void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len)
}
break;
case SUBNET_MASK:
if (opt_len == sizeof(s_dhcps_mask)) {
s_dhcps_mask = *(ip4_addr_t *)opt_info;
}
default:
break;
}
@ -296,21 +314,12 @@ static u8_t *add_offer_options(u8_t *optptr)
ipadd.addr = *((u32_t *) &server_address);
#ifdef USE_CLASS_B_NET
*optptr++ = DHCP_OPTION_SUBNET_MASK;
*optptr++ = 4; //length
*optptr++ = 255;
*optptr++ = 240;
*optptr++ = 0;
*optptr++ = 0;
#else
*optptr++ = DHCP_OPTION_SUBNET_MASK;
*optptr++ = 4;
*optptr++ = 255;
*optptr++ = 255;
*optptr++ = 255;
*optptr++ = 0;
#endif
*optptr++ = ip4_addr1(&s_dhcps_mask);
*optptr++ = ip4_addr2(&s_dhcps_mask);
*optptr++ = ip4_addr3(&s_dhcps_mask);
*optptr++ = ip4_addr4(&s_dhcps_mask);
*optptr++ = DHCP_OPTION_LEASE_TIME;
*optptr++ = 4;
@ -357,21 +366,13 @@ static u8_t *add_offer_options(u8_t *optptr)
*optptr++ = ip4_addr4(&ipadd);
}
#ifdef CLASS_B_NET
ip4_addr_t broadcast_addr = { .addr = (ipadd.addr & s_dhcps_mask.addr) | ~s_dhcps_mask.addr };
*optptr++ = DHCP_OPTION_BROADCAST_ADDRESS;
*optptr++ = 4;
*optptr++ = ip4_addr1(&ipadd);
*optptr++ = 255;
*optptr++ = 255;
*optptr++ = 255;
#else
*optptr++ = DHCP_OPTION_BROADCAST_ADDRESS;
*optptr++ = 4;
*optptr++ = ip4_addr1(&ipadd);
*optptr++ = ip4_addr2(&ipadd);
*optptr++ = ip4_addr3(&ipadd);
*optptr++ = 255;
#endif
*optptr++ = ip4_addr1(&broadcast_addr);
*optptr++ = ip4_addr2(&broadcast_addr);
*optptr++ = ip4_addr3(&broadcast_addr);
*optptr++ = ip4_addr4(&broadcast_addr);
*optptr++ = DHCP_OPTION_INTERFACE_MTU;
*optptr++ = 2;