[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] - Numeric DHCP option request facility
From:       Nigel Hathaway <Nigel.Hathaway () ubiquisys ! com>
Date:       2011-05-31 15:37:31
Message-ID: 05DE3B674BA2C74496B52B930C3B4E7DB949 () VM-DAG02 ! ubiquisys ! local
[Download RAW message or body]

Package: busybox
Version: v1.18.4
Severity: low

This patch applies on top of my previous VLAN and numeric DHCP option recog=
nition patch.

Whist this previous patch allows you to have DHCP options that are unknown =
to Busybox to be passed numerically to the udhcpc script, I found that ther=
e was no way of actually adding them to the list of requested options passe=
d to the DHCP server. This rectifies this in that you can now request DHCP =
options by number. For example:

udhcpc -O43

This adds option 43 (vendor specific information) to the set of requested o=
ptions.

["udhcpc.patch" (application/octet-stream)]

Index: busybox/networking/udhcp/dhcpc.c
===================================================================
--- busybox/networking/udhcp/dhcpc.c	(revision 14777)
+++ busybox/networking/udhcp/dhcpc.c	(working copy)
@@ -391,6 +391,7 @@
 {
 	uint8_t c;
 	int i, end, len;
+    uint8_t opt_remainder_mask[256 / 8];
 
 	udhcp_add_simple_option(packet, DHCP_MAX_SIZE, htons(IP_UDP_DHCP_SIZE));
 
@@ -398,6 +399,7 @@
 	 * from stubborn DHCP servers. Pull the data from the struct in common.c.
 	 * No bounds checking because it goes towards the head of the packet. */
 	end = udhcp_end_option(packet->options);
+    memcpy(opt_remainder_mask, client_config.opt_mask, sizeof(opt_remainder_mask));
 	len = 0;
 	for (i = 0; (c = dhcp_optflags[i].code) != 0; i++) {
 		if ((   (dhcp_optflags[i].flags & OPTION_REQ)
@@ -406,9 +408,16 @@
 		 || (client_config.opt_mask[c >> 3] & (1 << (c & 7)))
 		) {
 			packet->options[end + OPT_DATA + len] = c;
+			opt_remainder_mask[c >> 3] &= ~(1 << (c & 7));
 			len++;
 		}
 	}
+	for (c = 1; c < 254; c++) {
+		if (opt_remainder_mask[c >> 3] & (1 << (c & 7))) {
+			packet->options[end + OPT_DATA + len] = c;
+			len++;
+		}
+	}
 	if (len) {
 		packet->options[end + OPT_CODE] = DHCP_PARAM_REQ;
 		packet->options[end + OPT_LEN] = len;
@@ -1101,8 +1110,16 @@
 		client_config.no_default_options = 1;
 	while (list_O) {
 		char *optstr = llist_pop(&list_O);
-		unsigned n = udhcp_option_idx(optstr);
-		n = dhcp_optflags[n].code;
+		unsigned long n;
+		if (isdigit(*optstr)) {
+			n = strtoul(optstr, NULL, 0);
+			if (n<1 || n>254)
+				bb_error_msg_and_die("unknown option '%lu' (out of range)", n);
+		}
+		else {
+			n = udhcp_option_idx(optstr);
+			n = dhcp_optflags[n].code;
+		}
 		client_config.opt_mask[n >> 3] |= 1 << (n & 7);
 	}
 	while (list_x) {


_______________________________________________
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