mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
dhcpserver: make subnet mask configurable
Closes https://github.com/espressif/esp-idf/issues/4988
This commit is contained in:
parent
ad60568151
commit
fa57bdbdbe
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user