svn commit: trunk/busybox/networking/udhcp

vda at busybox.net vda at busybox.net
Thu Nov 23 12:57:49 UTC 2006


Author: vda
Date: 2006-11-23 04:57:49 -0800 (Thu, 23 Nov 2006)
New Revision: 16644

Log:
add "wpad" DHCP option. Spotted some optimization opportunities: -80 bytes


Modified:
   trunk/busybox/networking/udhcp/files.c
   trunk/busybox/networking/udhcp/options.c
   trunk/busybox/networking/udhcp/options.h
   trunk/busybox/networking/udhcp/script.c


Changeset:
Modified: trunk/busybox/networking/udhcp/files.c
===================================================================
--- trunk/busybox/networking/udhcp/files.c	2006-11-23 04:51:08 UTC (rev 16643)
+++ trunk/busybox/networking/udhcp/files.c	2006-11-23 12:57:49 UTC (rev 16644)
@@ -95,7 +95,8 @@
 
 
 /* add an option to the opt_list */
-static void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length)
+static void attach_option(struct option_set **opt_list,
+		const struct dhcp_option *option, char *buffer, int length)
 {
 	struct option_set *existing, *new, **curr;
 
@@ -135,7 +136,7 @@
 {
 	struct option_set **opt_list = arg;
 	char *opt, *val, *endptr;
-	struct dhcp_option *option;
+	const struct dhcp_option *option;
 	int retval = 0, length;
 	char buffer[8];
 	char *line;
@@ -144,16 +145,21 @@
 
 	/* Cheat, the only const line we'll actually get is "" */
 	line = (char *) const_line;
-	if (!(opt = strtok(line, " \t="))) return 0;
+	opt = strtok(line, " \t=");
+	if (!opt) return 0;
 
-	for (option = dhcp_options; option->code; option++)
+	option = dhcp_options;
+	while (1) {
+		if (!option->code)
+			return 0;
 		if (!strcasecmp(option->name, opt))
 			break;
+		 option++;
+	}
 
-	if (!option->code) return 0;
-
 	do {
-		if (!(val = strtok(NULL, ", \t"))) break;
+		val = strtok(NULL, ", \t");
+		if (!val) break;
 		length = option_lengths[option->flags & TYPE_MASK];
 		retval = 0;
 		opt = buffer; /* new meaning for variable opt */

Modified: trunk/busybox/networking/udhcp/options.c
===================================================================
--- trunk/busybox/networking/udhcp/options.c	2006-11-23 04:51:08 UTC (rev 16643)
+++ trunk/busybox/networking/udhcp/options.c	2006-11-23 12:57:49 UTC (rev 16644)
@@ -10,53 +10,55 @@
 
 
 /* supported options are easily added here */
-struct dhcp_option dhcp_options[] = {
-	/* name[10]	flags					code */
-	{"subnet",	OPTION_IP | OPTION_REQ,			0x01},
-	{"timezone",	OPTION_S32,				0x02},
-	{"router",	OPTION_IP | OPTION_LIST | OPTION_REQ,	0x03},
-	{"timesvr",	OPTION_IP | OPTION_LIST,		0x04},
-	{"namesvr",	OPTION_IP | OPTION_LIST,		0x05},
-	{"dns",		OPTION_IP | OPTION_LIST | OPTION_REQ,	0x06},
-	{"logsvr",	OPTION_IP | OPTION_LIST,		0x07},
-	{"cookiesvr",	OPTION_IP | OPTION_LIST,		0x08},
-	{"lprsvr",	OPTION_IP | OPTION_LIST,		0x09},
-	{"hostname",	OPTION_STRING | OPTION_REQ,		0x0c},
-	{"bootsize",	OPTION_U16,				0x0d},
-	{"domain",	OPTION_STRING | OPTION_REQ,		0x0f},
-	{"swapsvr",	OPTION_IP,				0x10},
-	{"rootpath",	OPTION_STRING,				0x11},
-	{"ipttl",	OPTION_U8,				0x17},
-	{"mtu",		OPTION_U16,				0x1a},
-	{"broadcast",	OPTION_IP | OPTION_REQ,			0x1c},
-	{"nisdomain",	OPTION_STRING | OPTION_REQ,		0x28},
-	{"nissrv",	OPTION_IP | OPTION_LIST | OPTION_REQ,	0x29},
-	{"ntpsrv",	OPTION_IP | OPTION_LIST | OPTION_REQ,	0x2a},
-	{"wins",	OPTION_IP | OPTION_LIST,		0x2c},
-	{"requestip",	OPTION_IP,				0x32},
-	{"lease",	OPTION_U32,				0x33},
-	{"dhcptype",	OPTION_U8,				0x35},
-	{"serverid",	OPTION_IP,				0x36},
-	{"message",	OPTION_STRING,				0x38},
+const struct dhcp_option dhcp_options[] = {
+	/* name[10]     flags                                   code */
+	{"subnet",      OPTION_IP | OPTION_REQ,                 0x01},
+	{"timezone",    OPTION_S32,                             0x02},
+	{"router",      OPTION_IP | OPTION_LIST | OPTION_REQ,   0x03},
+	{"timesvr",     OPTION_IP | OPTION_LIST,                0x04},
+	{"namesvr",     OPTION_IP | OPTION_LIST,                0x05},
+	{"dns",         OPTION_IP | OPTION_LIST | OPTION_REQ,   0x06},
+	{"logsvr",      OPTION_IP | OPTION_LIST,                0x07},
+	{"cookiesvr",   OPTION_IP | OPTION_LIST,                0x08},
+	{"lprsvr",      OPTION_IP | OPTION_LIST,                0x09},
+	{"hostname",    OPTION_STRING | OPTION_REQ,             0x0c},
+	{"bootsize",    OPTION_U16,                             0x0d},
+	{"domain",      OPTION_STRING | OPTION_REQ,             0x0f},
+	{"swapsvr",     OPTION_IP,                              0x10},
+	{"rootpath",    OPTION_STRING,                          0x11},
+	{"ipttl",       OPTION_U8,                              0x17},
+	{"mtu",         OPTION_U16,                             0x1a},
+	{"broadcast",   OPTION_IP | OPTION_REQ,                 0x1c},
+	{"nisdomain",   OPTION_STRING | OPTION_REQ,             0x28},
+	{"nissrv",      OPTION_IP | OPTION_LIST | OPTION_REQ,   0x29},
+	{"ntpsrv",      OPTION_IP | OPTION_LIST | OPTION_REQ,   0x2a},
+	{"wins",        OPTION_IP | OPTION_LIST,                0x2c},
+	{"requestip",   OPTION_IP,                              0x32},
+	{"lease",       OPTION_U32,                             0x33},
+	{"dhcptype",    OPTION_U8,                              0x35},
+	{"serverid",    OPTION_IP,                              0x36},
+	{"message",     OPTION_STRING,                          0x38},
 	{"vendorclass", OPTION_STRING,                          0x3C},
 	{"clientid",    OPTION_STRING,                          0x3D},
-	{"tftp",	OPTION_STRING,				0x42},
-	{"bootfile",	OPTION_STRING,				0x43},
+	{"tftp",        OPTION_STRING,                          0x42},
+	{"bootfile",    OPTION_STRING,                          0x43},
 	{"userclass",   OPTION_STRING,                          0x4D},
-	{"",		0x00,				0x00}
+	/* MSIE's "Web Proxy Autodiscovery Protocol" support */
+	{"wpad",        OPTION_STRING,                          0xfc},
+	{"",            0x00,                                   0x00}
 };
 
 /* Lengths of the different option types */
-int option_lengths[] = {
-	[OPTION_IP] =		4,
-	[OPTION_IP_PAIR] =	8,
-	[OPTION_BOOLEAN] =	1,
-	[OPTION_STRING] =	1,
-	[OPTION_U8] =		1,
-	[OPTION_U16] =		2,
-	[OPTION_S16] =		2,
-	[OPTION_U32] =		4,
-	[OPTION_S32] =		4
+const unsigned char option_lengths[] = {
+	[OPTION_IP] =      4,
+	[OPTION_IP_PAIR] = 8,
+	[OPTION_BOOLEAN] = 1,
+	[OPTION_STRING] =  1,
+	[OPTION_U8] =      1,
+	[OPTION_U16] =     2,
+	[OPTION_S16] =     2,
+	[OPTION_U32] =     4,
+	[OPTION_S32] =     4
 };
 
 
@@ -150,9 +152,9 @@
 /* add a one to four byte option to a packet */
 int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
 {
-	struct dhcp_option *dh;
+	const struct dhcp_option *dh;
 
-	for (dh=dhcp_options; dh->code; dh++) {
+	for (dh = dhcp_options; dh->code; dh++) {
 		if (dh->code == code) {
 			uint8_t option[6], len;
 

Modified: trunk/busybox/networking/udhcp/options.h
===================================================================
--- trunk/busybox/networking/udhcp/options.h	2006-11-23 04:51:08 UTC (rev 16643)
+++ trunk/busybox/networking/udhcp/options.h	2006-11-23 12:57:49 UTC (rev 16644)
@@ -26,8 +26,8 @@
 	uint8_t code;
 };
 
-extern struct dhcp_option dhcp_options[];
-extern int option_lengths[];
+extern const struct dhcp_option dhcp_options[];
+extern const unsigned char option_lengths[];
 
 uint8_t *get_option(struct dhcpMessage *packet, int code);
 int end_option(uint8_t *optionptr);

Modified: trunk/busybox/networking/udhcp/script.c
===================================================================
--- trunk/busybox/networking/udhcp/script.c	2006-11-23 04:51:08 UTC (rev 16643)
+++ trunk/busybox/networking/udhcp/script.c	2006-11-23 12:57:49 UTC (rev 16644)
@@ -54,7 +54,8 @@
 
 
 /* Fill dest with the text of option 'option'. */
-static void fill_options(char *dest, uint8_t *option, struct dhcp_option *type_p)
+static void fill_options(char *dest, uint8_t *option,
+			const struct dhcp_option *type_p)
 {
 	int type, optlen;
 	uint16_t val_u16;
@@ -152,7 +153,8 @@
 
 
 	for (i = 0; dhcp_options[i].code; i++) {
-		if (!(temp = get_option(packet, dhcp_options[i].code)))
+		temp = get_option(packet, dhcp_options[i].code);
+		if (temp)
 			continue;
 		envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2],
 			dhcp_options[i].flags & TYPE_MASK) + strlen(dhcp_options[i].name) + 2);




More information about the busybox-cvs mailing list