DHCPD: Add support for the dhcp options for netmask, router and dns. From Brennan Ashton
This commit is contained in:
parent
04bf18295f
commit
e59819bbed
@ -61,6 +61,18 @@ config NETUTILS_DHCPD_STARTIP
|
||||
hex "First IP address"
|
||||
default 0x0a000002
|
||||
|
||||
config NETUTILS_DHCPD_ROUTERIP
|
||||
hex "Router IP (0 to disable)"
|
||||
default 0x0a000001
|
||||
|
||||
config NETUTILS_DHCPD_NETMASK
|
||||
hex "Netmask (0 to disable)"
|
||||
default 0xffffff00
|
||||
|
||||
config NETUTILS_DHCPD_DNSIP
|
||||
hex "DNS (0 to disable)"
|
||||
default 0x08080808
|
||||
|
||||
config NETUTILS_DHCPD_OFFERTIME
|
||||
int "Offer time (seconds)"
|
||||
default 3600
|
||||
|
@ -86,6 +86,10 @@
|
||||
/* Code Data Description */
|
||||
/* Length */
|
||||
#define DHCP_OPTION_PAD 0 /* 1 Pad */
|
||||
#define DHCP_OPTION_SUBNET_MASK 1 /* 1 Subnet Mask */
|
||||
#define DHCP_OPTION_ROUTER 3 /* 4 Router */
|
||||
#define DHCP_OPTION_DNS_SERVER 6 /* 4N DNS */
|
||||
#define DHCP_OPTION_DNS_SERVER_L 4 /* DNS Length */
|
||||
#define DHCP_OPTION_REQ_IPADDR 50 /* 4 Requested IP Address */
|
||||
#define DHCP_OPTION_LEASE_TIME 51 /* 4 IP address lease time */
|
||||
#define DHCP_OPTION_OVERLOAD 52 /* 1 Option overload */
|
||||
@ -181,6 +185,21 @@
|
||||
# define CONFIG_NETUTILS_DHCPD_DECLINETIME (60*60) /* 1 hour */
|
||||
#endif
|
||||
|
||||
#undef HAVE_ROUTERIP
|
||||
#if defined(CONFIG_NETUTILS_DHCPD_ROUTERIP) && CONFIG_NETUTILS_DHCPD_ROUTERIP
|
||||
# define HAVE_ROUTERIP 1
|
||||
#endif
|
||||
|
||||
#undef HAVE_NETMASK
|
||||
#if defined(CONFIG_NETUTILS_DHCPD_NETMASK) && CONFIG_NETUTILS_DHCPD_NETMASK
|
||||
# define HAVE_NETMASK 1
|
||||
#endif
|
||||
|
||||
#undef HAVE_DNSIP
|
||||
#if defined(CONFIG_NETUTILS_DHCPD_DNSIP) && CONFIG_NETUTILS_DHCPD_DNSIP
|
||||
# define HAVE_DNSIP 1
|
||||
#endif
|
||||
|
||||
#undef HAVE_LEASE_TIME
|
||||
#if defined(CONFIG_NETUTILS_DHCPD_HOST) || !defined(CONFIG_DISABLE_POSIX_TIMERS)
|
||||
# define HAVE_LEASE_TIME 1
|
||||
@ -736,6 +755,31 @@ static int dhcpd_addoption32(uint8_t code, uint32_t value)
|
||||
return dhcpd_addoption(option);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dhcpd_addoption_n
|
||||
****************************************************************************/
|
||||
|
||||
#if HAVE_DNSIP
|
||||
static int dhcpd_addoption_n(uint8_t code, uint8_t *value, uint8_t len)
|
||||
{
|
||||
/* REVISIT: This form may not be supported by older compilers. It may
|
||||
* need to be replaced with malloc() and free() for portability.
|
||||
*/
|
||||
|
||||
uint8_t option[len+2];
|
||||
|
||||
/* Construct the option sequence */
|
||||
|
||||
option[DHCPD_OPTION_CODE] = code;
|
||||
option[DHCPD_OPTION_LENGTH] = len;
|
||||
memcpy(&option[DHCPD_OPTION_DATA], value, len);
|
||||
|
||||
/* Add the option sequence to the response */
|
||||
|
||||
return dhcpd_addoption(option);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dhcpd_soclet
|
||||
****************************************************************************/
|
||||
@ -953,7 +997,10 @@ static int dhcpd_sendpacket(int bbroadcast)
|
||||
static inline int dhcpd_sendoffer(in_addr_t ipaddr, uint32_t leasetime)
|
||||
{
|
||||
in_addr_t netaddr;
|
||||
|
||||
#if HAVE_DNSIP
|
||||
uint32_t dnsaddr;
|
||||
dnsaddr = htonl(CONFIG_NETUTILS_DHCPD_DNSIP);
|
||||
#endif
|
||||
/* IP address is in host order */
|
||||
|
||||
nvdbg("Sending offer: %08lx\n", (long)ipaddr);
|
||||
@ -970,6 +1017,15 @@ static inline int dhcpd_sendoffer(in_addr_t ipaddr, uint32_t leasetime)
|
||||
/* Add the leasetime to the response options */
|
||||
|
||||
dhcpd_addoption32(DHCP_OPTION_LEASE_TIME, htonl(leasetime));
|
||||
#if HAVE_NETMASK
|
||||
dhcpd_addoption32(DHCP_OPTION_SUBNET_MASK, htonl(CONFIG_NETUTILS_DHCPD_NETMASK));
|
||||
#endif
|
||||
#if HAVE_ROUTERIP
|
||||
dhcpd_addoption32(DHCP_OPTION_ROUTER, htonl(CONFIG_NETUTILS_DHCPD_ROUTERIP));
|
||||
#endif
|
||||
#if HAVE_DNSIP
|
||||
dhcpd_addoption_n(DHCP_OPTION_DNS_SERVER, (uint8_t*)&dnsaddr, DHCP_OPTION_DNS_SERVER_L);
|
||||
#endif
|
||||
|
||||
/* Send the offer response */
|
||||
|
||||
@ -1001,6 +1057,10 @@ int dhcpd_sendack(in_addr_t ipaddr)
|
||||
{
|
||||
uint32_t leasetime = CONFIG_NETUTILS_DHCPD_LEASETIME;
|
||||
in_addr_t netaddr;
|
||||
#if HAVE_DNSIP
|
||||
uint32_t dnsaddr;
|
||||
dnsaddr = htonl(CONFIG_NETUTILS_DHCPD_DNSIP);
|
||||
#endif
|
||||
|
||||
/* Initialize the ACK response */
|
||||
|
||||
@ -1019,6 +1079,15 @@ int dhcpd_sendack(in_addr_t ipaddr)
|
||||
/* Add the lease time to the response */
|
||||
|
||||
dhcpd_addoption32(DHCP_OPTION_LEASE_TIME, htonl(leasetime));
|
||||
#if HAVE_NETMASK
|
||||
dhcpd_addoption32(DHCP_OPTION_SUBNET_MASK, htonl(CONFIG_NETUTILS_DHCPD_NETMASK));
|
||||
#endif
|
||||
#if HAVE_ROUTERIP
|
||||
dhcpd_addoption32(DHCP_OPTION_ROUTER, htonl(CONFIG_NETUTILS_DHCPD_ROUTERIP));
|
||||
#endif
|
||||
#if HAVE_DNSIP
|
||||
dhcpd_addoption_n(DHCP_OPTION_DNS_SERVER, (uint8_t*)&dnsaddr, DHCP_OPTION_DNS_SERVER_L);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NETUTILS_DHCPD_IGNOREBROADCAST
|
||||
if (dhcpd_sendpacket(true) < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user