[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] - DHCP option support for VLAN and other applications
From: "Nigel Hathaway" <Nigel.Hathaway () ubiquisys ! com>
Date: 2011-03-31 14:53:54
Message-ID: 094A73044298734FB7D58CAAA319E1D603775E17 () UBIQ-SERV1 ! ubiquisys ! local
[Download RAW message or body]
Package: busybox
Version: v1.18.4
Severity: low
This patch adds support for VLAN DHCP options 132 and 133, and this
works with both the udhcp client and the server (and is conditionally
compiled by enabling FEATURE_UDHCP_8021Q which is enabled by default).
The udhcp client also forwards all (formerly) unrecognised DHCP options
arriving from the server onto the dhcpc client script in the form of
environment variables. For example, an environment variable of the
following form:
opt8=01020304
(as produced from a back-to-back test with udhcpd using the example
config file)
This is explained as:
optN=XXXX..XX, where N is the decimal option number and XXXX..XX is a
string of hex digit pairs representing the bytes passed in the option
["dhcp_otps.patch" (application/octet-stream)]
diff -Naur busybox-1.18.4-orig/examples/udhcp/udhcpd.conf busybox-1.18.4/examples/udhcp/udhcpd.conf
--- busybox-1.18.4-orig/examples/udhcp/udhcpd.conf 2011-03-13 01:45:06.000000000 +0000
+++ busybox-1.18.4/examples/udhcp/udhcpd.conf 2011-03-31 15:16:12.195097140 +0100
@@ -90,6 +90,8 @@
#opt wpad STRING
#opt serverid IP # default: server's IP
#opt message STRING # error message (udhcpd sends it on success too)
+#opt vlanid NUM # 802.1P VLAN ID
+#opt vlanpriority NUM # 802.1Q VLAN priority
# Options specifying server(s)
#opt dns IP_LIST
#opt wins IP_LIST
@@ -97,8 +99,15 @@
#opt ntpsrv IP_LIST
#opt lprsrv IP_LIST
#opt swapsrv IP
+# Options specifying routes
+#opt routes IP_PAIR_LIST
# Obsolete options, no longer supported
#opt logsrv IP_LIST # 704/UDP log server (not syslog!)
#opt namesrv IP_LIST # IEN 116 name server, obsolete (August 1979!!!)
#opt cookiesrv IP_LIST # RFC 865 "quote of the day" server, rarely (never?) used
#opt timesrv IP_LIST # RFC 868 time server, rarely (never?) used
+# TODO: in development
+#opt userclass STRING # RFC 3004. set of LASCII strings. "I am a printer" etc
+#opt sipserv STRING LIST # RFC 3361. flag byte, then: 0: domain names, 1: IP addrs
+#opt staticroutes STATIC_ROUTES
+#opt msstaticroutes STATIC_ROUTES
diff -Naur busybox-1.18.4-orig/networking/udhcp/common.c busybox-1.18.4/networking/udhcp/common.c
--- busybox-1.18.4-orig/networking/udhcp/common.c 2011-03-13 01:45:06.000000000 +0000
+++ busybox-1.18.4/networking/udhcp/common.c 2011-03-31 11:39:31.942945900 +0100
@@ -55,6 +55,10 @@
{ OPTION_SIP_SERVERS , 0x78 }, /* DHCP_SIP_SERVERS */
#endif
{ OPTION_STATIC_ROUTES , 0x79 }, /* DHCP_STATIC_ROUTES */
+#if ENABLE_FEATURE_UDHCP_8021Q
+ { OPTION_U16 , 0x84 }, /* DHCP_VLAN_ID */
+ { OPTION_U8 , 0x85 }, /* DHCP_VLAN_PRIORITY */
+#endif
{ OPTION_STATIC_ROUTES , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */
{ OPTION_STRING , 0xfc }, /* DHCP_WPAD */
@@ -118,6 +122,10 @@
// doesn't work in udhcpd.conf since OPTION_STATIC_ROUTES
// is not handled yet by "string->option" conversion code:
"staticroutes" "\0"/* DHCP_STATIC_ROUTES */
+#if ENABLE_FEATURE_UDHCP_8021Q
+ "vlanid" "\0" /* DHCP_VLAN_ID */
+ "vlanpriority" "\0"/* DHCP_VLAN_PRIORITY */
+#endif
"msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */
"wpad" "\0" /* DHCP_WPAD */
;
diff -Naur busybox-1.18.4-orig/networking/udhcp/common.h busybox-1.18.4/networking/udhcp/common.h
--- busybox-1.18.4-orig/networking/udhcp/common.h 2011-03-13 01:45:06.000000000 +0000
+++ busybox-1.18.4/networking/udhcp/common.h 2011-03-31 11:16:08.551658405 +0100
@@ -145,6 +145,8 @@
//#define DHCP_DOMAIN_SEARCH 0x77 /* RFC 3397. set of ASCIZ string, DNS-style compressed */
//#define DHCP_SIP_SERVERS 0x78 /* RFC 3361. flag byte, then: 0: domain names, 1: IP addrs */
//#define DHCP_STATIC_ROUTES 0x79 /* RFC 3442. (mask,ip,router) tuples */
+#define DHCP_VLAN_ID 0x84 /* 802.1P VLAN ID */
+#define DHCP_VLAN_PRIORITY 0x85 /* 802.1Q VLAN priority */
//#define DHCP_MS_STATIC_ROUTES 0xf9 /* Microsoft's pre-RFC 3442 code for 0x79? */
//#define DHCP_WPAD 0xfc /* MSIE's Web Proxy Autodiscovery Protocol */
#define DHCP_END 0xff
diff -Naur busybox-1.18.4-orig/networking/udhcp/Config.src busybox-1.18.4/networking/udhcp/Config.src
--- busybox-1.18.4-orig/networking/udhcp/Config.src 2011-03-13 01:45:40.000000000 +0000
+++ busybox-1.18.4/networking/udhcp/Config.src 2011-03-31 11:25:35.240398880 +0100
@@ -99,6 +99,14 @@
search lists via option 119, specified in RFC 3397,
and SIP servers option 120, specified in RFC 3361.
+config FEATURE_UDHCP_8021Q
+ bool "Support for 802.1Q VLAN parameters"
+ default y
+ depends on UDHCPD || UDHCPC
+ help
+ If selected, both client and server will support passing of VLAN
+ ID and priority via options 132 and 133 as per 802.1Q.
+
config UDHCPC_DEFAULT_SCRIPT
string "Absolute path to config script"
default "/usr/share/udhcpc/default.script"
diff -Naur busybox-1.18.4-orig/networking/udhcp/dhcpc.c busybox-1.18.4/networking/udhcp/dhcpc.c
--- busybox-1.18.4-orig/networking/udhcp/dhcpc.c 2011-03-13 01:45:40.000000000 +0000
+++ busybox-1.18.4/networking/udhcp/dhcpc.c 2011-03-31 14:21:28.018021054 +0100
@@ -238,6 +238,8 @@
const char *opt_name;
uint8_t *temp;
uint8_t overload = 0;
+ uint32_t found_opts[256/(sizeof(uint32_t)*8)]; /* bitmap */
+ memset(found_opts, 0, sizeof(found_opts));
/* We need 6 elements for:
* "interface=IFACE"
@@ -250,16 +252,18 @@
envc = 6;
/* +1 element for each option, +2 for subnet option: */
if (packet) {
- for (i = 0; dhcp_optflags[i].code; i++) {
- if (udhcp_get_option(packet, dhcp_optflags[i].code)) {
- if (dhcp_optflags[i].code == DHCP_SUBNET)
+ for (i = 0x01; i<0xff; i++) {
+ temp = udhcp_get_option(packet, i);
+ if (temp) {
+ if (i == DHCP_OPTION_OVERLOAD)
+ overload = *temp;
+ else if (i == DHCP_SUBNET)
envc++; /* for mton */
envc++;
+ if (i != DHCP_MESSAGE_TYPE)
+ found_opts[i/(sizeof(uint32_t)*8)] |= 1U<<(i%(sizeof(uint32_t)*8));
}
}
- temp = udhcp_get_option(packet, DHCP_OPTION_OVERLOAD);
- if (temp)
- overload = *temp;
}
curr = envp = xzalloc(sizeof(char *) * envc);
@@ -276,12 +280,16 @@
opt_name = dhcp_option_strings;
i = 0;
while (*opt_name) {
- temp = udhcp_get_option(packet, dhcp_optflags[i].code);
- if (!temp)
+ uint8_t code = dhcp_optflags[i].code;
+ uint32_t *found_ptr = &found_opts[code/(sizeof(uint32_t)*8)];
+ uint32_t found_mask = 1U<<(code%(sizeof(uint32_t)*8));
+ if (!(*found_ptr & found_mask))
goto next;
+ *found_ptr &= ~found_mask; /* leave only unknown options */
+ temp = udhcp_get_option(packet, code);
*curr = xmalloc_optname_optval(temp, &dhcp_optflags[i], opt_name);
putenv(*curr++);
- if (dhcp_optflags[i].code == DHCP_SUBNET) {
+ if (code == DHCP_SUBNET) {
/* Subnet option: make things like "$ip/$mask" possible */
uint32_t subnet;
move_from_unaligned32(subnet, temp);
@@ -307,6 +315,29 @@
*curr = xasprintf("sname=%."DHCP_PKT_SNAME_LEN_STR"s", packet->sname);
putenv(*curr++);
}
+ /* Handle unknown options */
+ for (i=0; i<256; i++) {
+ uint32_t bitmap = found_opts[i/(sizeof(uint32_t)*8)];
+ if (i%(sizeof(uint32_t)*8) == 0 && !bitmap) {
+ i += (sizeof(uint32_t)*8)-1;
+ continue;
+ }
+ if (bitmap & 1U<<(i%(sizeof(uint32_t)*8))) {
+ uint8_t len;
+ char optbuf[4];
+ temp = udhcp_get_option(packet, i);
+ len = *(temp-1);
+ sprintf(optbuf, "%d", i);
+ *curr = xmalloc(3+strlen(optbuf)+1+len*2+1);
+ sprintf(*curr, "opt%s=", optbuf);
+ while (len) {
+ sprintf(*curr + strlen(*curr), "%02X", (unsigned)*temp);
+ temp++;
+ len--;
+ }
+ putenv(*curr++);
+ }
+ }
return envp;
}
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic