Enable additional DHCP options to support functional parity with ONIE.

This commit is contained in:
Jeffrey Townsend
2017-07-18 16:23:22 +00:00
parent 775e7d567a
commit ab048a41d9

View File

@@ -0,0 +1,126 @@
dhcp additional options patch
Copyright (C) 2013 Curt Brune <curt@cumulusnetworks.com>
Copyright (C) 2014 david_yang <david_yang@accton.com>
Copyright (C) 2017 Jeffrey Townsend <jeffrey.townsend@bigswitch.com>
SPDX-License-Identifier: GPL-2.0
Enable the send/receive of additional DHCP options:
DHCP_LOG_SERVER
DHCP_WWW_SERVER
DHCP_DEFAULT_URL
diff -urpN a/networking/udhcp/common.c b/networking/udhcp/common.c
--- a/networking/udhcp/common.c 2017-07-18 15:11:59.626055248 +0000
+++ b/networking/udhcp/common.c 2017-07-18 15:09:47.942052391 +0000
@@ -26,7 +26,7 @@ const struct dhcp_optflag dhcp_optflags[
// { OPTION_IP | OPTION_LIST , 0x04 }, /* DHCP_TIME_SERVER */
// { OPTION_IP | OPTION_LIST , 0x05 }, /* DHCP_NAME_SERVER */
{ OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06 }, /* DHCP_DNS_SERVER */
-// { OPTION_IP | OPTION_LIST , 0x07 }, /* DHCP_LOG_SERVER */
+ { OPTION_IP | OPTION_LIST , 0x07 }, /* DHCP_LOG_SERVER */
// { OPTION_IP | OPTION_LIST , 0x08 }, /* DHCP_COOKIE_SERVER */
{ OPTION_IP | OPTION_LIST , 0x09 }, /* DHCP_LPR_SERVER */
{ OPTION_STRING_HOST | OPTION_REQ, 0x0c }, /* DHCP_HOST_NAME */
@@ -44,6 +44,7 @@ const struct dhcp_optflag dhcp_optflags[
{ OPTION_STRING_HOST , 0x28 }, /* DHCP_NIS_DOMAIN */
{ OPTION_IP | OPTION_LIST , 0x29 }, /* DHCP_NIS_SERVER */
{ OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a }, /* DHCP_NTP_SERVER */
+ { OPTION_BIN , 0x2b }, /* DHCP_VENDOR_OPTS */
{ OPTION_IP | OPTION_LIST , 0x2c }, /* DHCP_WINS_SERVER */
{ OPTION_U32 , 0x33 }, /* DHCP_LEASE_TIME */
{ OPTION_IP , 0x36 }, /* DHCP_SERVER_ID */
@@ -51,18 +52,22 @@ const struct dhcp_optflag dhcp_optflags[
//TODO: must be combined with 'sname' and 'file' handling:
{ OPTION_STRING_HOST , 0x42 }, /* DHCP_TFTP_SERVER_NAME */
{ OPTION_STRING , 0x43 }, /* DHCP_BOOT_FILE */
+ { OPTION_IP | OPTION_LIST , 0x48 }, /* DHCP_WWW_SERVER */
//TODO: not a string, but a set of LASCII strings:
// { OPTION_STRING , 0x4D }, /* DHCP_USER_CLASS */
+ { OPTION_STRING , 0x72 }, /* DHCP_DEFAULT_URL */
#if ENABLE_FEATURE_UDHCP_RFC3397
{ OPTION_DNS_STRING | OPTION_LIST , 0x77 }, /* DHCP_DOMAIN_SEARCH */
{ OPTION_SIP_SERVERS , 0x78 }, /* DHCP_SIP_SERVERS */
#endif
{ OPTION_STATIC_ROUTES | OPTION_LIST , 0x79 }, /* DHCP_STATIC_ROUTES */
+ { OPTION_BIN , 0x7d }, /* DHCP_VIVSO_OPTS */
#if ENABLE_FEATURE_UDHCP_8021Q
{ OPTION_U16 , 0x84 }, /* DHCP_VLAN_ID */
{ OPTION_U8 , 0x85 }, /* DHCP_VLAN_PRIORITY */
#endif
{ OPTION_6RD , 0xd4 }, /* DHCP_6RD */
+ { OPTION_IP , 0x96 }, /* DHCP_TFTP_SERVER_IP */
{ OPTION_STATIC_ROUTES | OPTION_LIST , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */
{ OPTION_STRING , 0xfc }, /* DHCP_WPAD */
@@ -95,7 +100,7 @@ const char dhcp_option_strings[] ALIGN1
// "timesrv" "\0" /* DHCP_TIME_SERVER */
// "namesrv" "\0" /* DHCP_NAME_SERVER */
"dns" "\0" /* DHCP_DNS_SERVER */
-// "logsrv" "\0" /* DHCP_LOG_SERVER */
+ "logsrv" "\0" /* DHCP_LOG_SERVER */
// "cookiesrv" "\0" /* DHCP_COOKIE_SERVER */
"lprsrv" "\0" /* DHCP_LPR_SERVER */
"hostname" "\0" /* DHCP_HOST_NAME */
@@ -110,13 +115,16 @@ const char dhcp_option_strings[] ALIGN1
"nisdomain" "\0" /* DHCP_NIS_DOMAIN */
"nissrv" "\0" /* DHCP_NIS_SERVER */
"ntpsrv" "\0" /* DHCP_NTP_SERVER */
+ "vendoropts" "\0" /* DHCP_VENDOR_OPTS */
"wins" "\0" /* DHCP_WINS_SERVER */
"lease" "\0" /* DHCP_LEASE_TIME */
"serverid" "\0" /* DHCP_SERVER_ID */
"message" "\0" /* DHCP_ERR_MESSAGE */
"tftp" "\0" /* DHCP_TFTP_SERVER_NAME */
"bootfile" "\0" /* DHCP_BOOT_FILE */
+ "wwwsrv" "\0" /* DHCP_WWW_SERVER */
// "userclass" "\0" /* DHCP_USER_CLASS */
+ "url" "\0" /* DHCP_DEFAULT_URL */
#if ENABLE_FEATURE_UDHCP_RFC3397
"search" "\0" /* DHCP_DOMAIN_SEARCH */
// doesn't work in udhcpd.conf since OPTION_SIP_SERVERS
@@ -124,11 +132,13 @@ const char dhcp_option_strings[] ALIGN1
"sipsrv" "\0" /* DHCP_SIP_SERVERS */
#endif
"staticroutes" "\0"/* DHCP_STATIC_ROUTES */
+ "vivso" "\0" /* DHCP_VIVSO_OPTS */
#if ENABLE_FEATURE_UDHCP_8021Q
"vlanid" "\0" /* DHCP_VLAN_ID */
"vlanpriority" "\0"/* DHCP_VLAN_PRIORITY */
#endif
"ip6rd" "\0" /* DHCP_6RD */
+ "tftpsiaddr" "\0" /* DHCP_TFTP_SERVER_IP */
"msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */
"wpad" "\0" /* DHCP_WPAD */
;
@@ -145,6 +155,7 @@ const uint8_t dhcp_option_lengths[] ALIG
[OPTION_IP] = 4,
[OPTION_IP_PAIR] = 8,
// [OPTION_BOOLEAN] = 1,
+ [OPTION_BIN] = 1, /* ignored by udhcp_str2optset */
[OPTION_STRING] = 1, /* ignored by udhcp_str2optset */
[OPTION_STRING_HOST] = 1, /* ignored by udhcp_str2optset */
#if ENABLE_FEATURE_UDHCP_RFC3397
diff -urpN a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
--- a/networking/udhcp/dhcpc.c 2017-07-18 15:11:59.626055248 +0000
+++ b/networking/udhcp/dhcpc.c 2017-07-18 15:11:11.066054194 +0000
@@ -100,6 +100,7 @@ static const uint8_t len_of_option_as_st
[OPTION_IP_PAIR ] = sizeof("255.255.255.255 ") * 2,
[OPTION_STATIC_ROUTES ] = sizeof("255.255.255.255/32 255.255.255.255 "),
[OPTION_6RD ] = sizeof("32 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 "),
+ [OPTION_BIN ] = 2,
[OPTION_STRING ] = 1,
[OPTION_STRING_HOST ] = 1,
#if ENABLE_FEATURE_UDHCP_RFC3397
@@ -240,6 +241,9 @@ static NOINLINE char *xmalloc_optname_op
dest += sprintf(dest, type == OPTION_U32 ? "%lu" : "%ld", (unsigned long) ntohl(val_u32));
break;
}
+ case OPTION_BIN:
+ *bin2hex(dest, (void*) option, len) = '\0';
+ return ret;
/* Note: options which use 'return' instead of 'break'
* (for example, OPTION_STRING) skip the code which handles
* the case of list of options.