summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko2006-11-23 12:57:49 +0000
committerDenis Vlasenko2006-11-23 12:57:49 +0000
commitc90c3f30a899b5f0aae58e54839109aa9b3eaee6 (patch)
tree190c1a90f38aa4ddbfdddf52ea89978d42536606 /networking
parent48237b0c88343154d58854020c3a9c8b07c61b10 (diff)
downloadbusybox-c90c3f30a899b5f0aae58e54839109aa9b3eaee6.zip
busybox-c90c3f30a899b5f0aae58e54839109aa9b3eaee6.tar.gz
add "wpad" DHCP option. Spotted some optimization opportunities: -80 bytes
Diffstat (limited to 'networking')
-rw-r--r--networking/udhcp/files.c20
-rw-r--r--networking/udhcp/options.c88
-rw-r--r--networking/udhcp/options.h4
-rw-r--r--networking/udhcp/script.c6
4 files changed, 64 insertions, 54 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 2c2c542..829d7e9 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -95,7 +95,8 @@ struct option_set *find_option(struct option_set *opt_list, char code)
/* 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 @@ static int read_opt(const char *const_line, void *arg)
{
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 @@ static int read_opt(const char *const_line, void *arg)
/* 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;
-
- if (!option->code) return 0;
+ option++;
+ }
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 */
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 9fcbc84..4a46da5 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -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 @@ int add_option_string(uint8_t *optionptr, uint8_t *string)
/* 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;
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index 1b179f1..588504e 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -26,8 +26,8 @@ struct dhcp_option {
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);
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 6e0ca88..d44c80b 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -54,7 +54,8 @@ static int mton(struct in_addr *mask)
/* 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 @@ static char **fill_envp(struct dhcpMessage *packet)
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);