summaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-23 12:57:49 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-23 12:57:49 +0000
commitc90c3f30a899b5f0aae58e54839109aa9b3eaee6 (patch)
tree190c1a90f38aa4ddbfdddf52ea89978d42536606 /networking/udhcp
parent48237b0c88343154d58854020c3a9c8b07c61b10 (diff)
downloadbusybox-w32-c90c3f30a899b5f0aae58e54839109aa9b3eaee6.tar.gz
busybox-w32-c90c3f30a899b5f0aae58e54839109aa9b3eaee6.tar.bz2
busybox-w32-c90c3f30a899b5f0aae58e54839109aa9b3eaee6.zip
add "wpad" DHCP option. Spotted some optimization opportunities: -80 bytes
Diffstat (limited to 'networking/udhcp')
-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 2c2c5422c..829d7e960 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)
95 95
96 96
97/* add an option to the opt_list */ 97/* add an option to the opt_list */
98static void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length) 98static void attach_option(struct option_set **opt_list,
99 const struct dhcp_option *option, char *buffer, int length)
99{ 100{
100 struct option_set *existing, *new, **curr; 101 struct option_set *existing, *new, **curr;
101 102
@@ -135,7 +136,7 @@ static int read_opt(const char *const_line, void *arg)
135{ 136{
136 struct option_set **opt_list = arg; 137 struct option_set **opt_list = arg;
137 char *opt, *val, *endptr; 138 char *opt, *val, *endptr;
138 struct dhcp_option *option; 139 const struct dhcp_option *option;
139 int retval = 0, length; 140 int retval = 0, length;
140 char buffer[8]; 141 char buffer[8];
141 char *line; 142 char *line;
@@ -144,16 +145,21 @@ static int read_opt(const char *const_line, void *arg)
144 145
145 /* Cheat, the only const line we'll actually get is "" */ 146 /* Cheat, the only const line we'll actually get is "" */
146 line = (char *) const_line; 147 line = (char *) const_line;
147 if (!(opt = strtok(line, " \t="))) return 0; 148 opt = strtok(line, " \t=");
149 if (!opt) return 0;
148 150
149 for (option = dhcp_options; option->code; option++) 151 option = dhcp_options;
152 while (1) {
153 if (!option->code)
154 return 0;
150 if (!strcasecmp(option->name, opt)) 155 if (!strcasecmp(option->name, opt))
151 break; 156 break;
152 157 option++;
153 if (!option->code) return 0; 158 }
154 159
155 do { 160 do {
156 if (!(val = strtok(NULL, ", \t"))) break; 161 val = strtok(NULL, ", \t");
162 if (!val) break;
157 length = option_lengths[option->flags & TYPE_MASK]; 163 length = option_lengths[option->flags & TYPE_MASK];
158 retval = 0; 164 retval = 0;
159 opt = buffer; /* new meaning for variable opt */ 165 opt = buffer; /* new meaning for variable opt */
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 9fcbc8474..4a46da579 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -10,53 +10,55 @@
10 10
11 11
12/* supported options are easily added here */ 12/* supported options are easily added here */
13struct dhcp_option dhcp_options[] = { 13const struct dhcp_option dhcp_options[] = {
14 /* name[10] flags code */ 14 /* name[10] flags code */
15 {"subnet", OPTION_IP | OPTION_REQ, 0x01}, 15 {"subnet", OPTION_IP | OPTION_REQ, 0x01},
16 {"timezone", OPTION_S32, 0x02}, 16 {"timezone", OPTION_S32, 0x02},
17 {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03}, 17 {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03},
18 {"timesvr", OPTION_IP | OPTION_LIST, 0x04}, 18 {"timesvr", OPTION_IP | OPTION_LIST, 0x04},
19 {"namesvr", OPTION_IP | OPTION_LIST, 0x05}, 19 {"namesvr", OPTION_IP | OPTION_LIST, 0x05},
20 {"dns", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06}, 20 {"dns", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06},
21 {"logsvr", OPTION_IP | OPTION_LIST, 0x07}, 21 {"logsvr", OPTION_IP | OPTION_LIST, 0x07},
22 {"cookiesvr", OPTION_IP | OPTION_LIST, 0x08}, 22 {"cookiesvr", OPTION_IP | OPTION_LIST, 0x08},
23 {"lprsvr", OPTION_IP | OPTION_LIST, 0x09}, 23 {"lprsvr", OPTION_IP | OPTION_LIST, 0x09},
24 {"hostname", OPTION_STRING | OPTION_REQ, 0x0c}, 24 {"hostname", OPTION_STRING | OPTION_REQ, 0x0c},
25 {"bootsize", OPTION_U16, 0x0d}, 25 {"bootsize", OPTION_U16, 0x0d},
26 {"domain", OPTION_STRING | OPTION_REQ, 0x0f}, 26 {"domain", OPTION_STRING | OPTION_REQ, 0x0f},
27 {"swapsvr", OPTION_IP, 0x10}, 27 {"swapsvr", OPTION_IP, 0x10},
28 {"rootpath", OPTION_STRING, 0x11}, 28 {"rootpath", OPTION_STRING, 0x11},
29 {"ipttl", OPTION_U8, 0x17}, 29 {"ipttl", OPTION_U8, 0x17},
30 {"mtu", OPTION_U16, 0x1a}, 30 {"mtu", OPTION_U16, 0x1a},
31 {"broadcast", OPTION_IP | OPTION_REQ, 0x1c}, 31 {"broadcast", OPTION_IP | OPTION_REQ, 0x1c},
32 {"nisdomain", OPTION_STRING | OPTION_REQ, 0x28}, 32 {"nisdomain", OPTION_STRING | OPTION_REQ, 0x28},
33 {"nissrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x29}, 33 {"nissrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x29},
34 {"ntpsrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a}, 34 {"ntpsrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a},
35 {"wins", OPTION_IP | OPTION_LIST, 0x2c}, 35 {"wins", OPTION_IP | OPTION_LIST, 0x2c},
36 {"requestip", OPTION_IP, 0x32}, 36 {"requestip", OPTION_IP, 0x32},
37 {"lease", OPTION_U32, 0x33}, 37 {"lease", OPTION_U32, 0x33},
38 {"dhcptype", OPTION_U8, 0x35}, 38 {"dhcptype", OPTION_U8, 0x35},
39 {"serverid", OPTION_IP, 0x36}, 39 {"serverid", OPTION_IP, 0x36},
40 {"message", OPTION_STRING, 0x38}, 40 {"message", OPTION_STRING, 0x38},
41 {"vendorclass", OPTION_STRING, 0x3C}, 41 {"vendorclass", OPTION_STRING, 0x3C},
42 {"clientid", OPTION_STRING, 0x3D}, 42 {"clientid", OPTION_STRING, 0x3D},
43 {"tftp", OPTION_STRING, 0x42}, 43 {"tftp", OPTION_STRING, 0x42},
44 {"bootfile", OPTION_STRING, 0x43}, 44 {"bootfile", OPTION_STRING, 0x43},
45 {"userclass", OPTION_STRING, 0x4D}, 45 {"userclass", OPTION_STRING, 0x4D},
46 {"", 0x00, 0x00} 46 /* MSIE's "Web Proxy Autodiscovery Protocol" support */
47 {"wpad", OPTION_STRING, 0xfc},
48 {"", 0x00, 0x00}
47}; 49};
48 50
49/* Lengths of the different option types */ 51/* Lengths of the different option types */
50int option_lengths[] = { 52const unsigned char option_lengths[] = {
51 [OPTION_IP] = 4, 53 [OPTION_IP] = 4,
52 [OPTION_IP_PAIR] = 8, 54 [OPTION_IP_PAIR] = 8,
53 [OPTION_BOOLEAN] = 1, 55 [OPTION_BOOLEAN] = 1,
54 [OPTION_STRING] = 1, 56 [OPTION_STRING] = 1,
55 [OPTION_U8] = 1, 57 [OPTION_U8] = 1,
56 [OPTION_U16] = 2, 58 [OPTION_U16] = 2,
57 [OPTION_S16] = 2, 59 [OPTION_S16] = 2,
58 [OPTION_U32] = 4, 60 [OPTION_U32] = 4,
59 [OPTION_S32] = 4 61 [OPTION_S32] = 4
60}; 62};
61 63
62 64
@@ -150,9 +152,9 @@ int add_option_string(uint8_t *optionptr, uint8_t *string)
150/* add a one to four byte option to a packet */ 152/* add a one to four byte option to a packet */
151int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) 153int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
152{ 154{
153 struct dhcp_option *dh; 155 const struct dhcp_option *dh;
154 156
155 for (dh=dhcp_options; dh->code; dh++) { 157 for (dh = dhcp_options; dh->code; dh++) {
156 if (dh->code == code) { 158 if (dh->code == code) {
157 uint8_t option[6], len; 159 uint8_t option[6], len;
158 160
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index 1b179f173..588504e5d 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -26,8 +26,8 @@ struct dhcp_option {
26 uint8_t code; 26 uint8_t code;
27}; 27};
28 28
29extern struct dhcp_option dhcp_options[]; 29extern const struct dhcp_option dhcp_options[];
30extern int option_lengths[]; 30extern const unsigned char option_lengths[];
31 31
32uint8_t *get_option(struct dhcpMessage *packet, int code); 32uint8_t *get_option(struct dhcpMessage *packet, int code);
33int end_option(uint8_t *optionptr); 33int end_option(uint8_t *optionptr);
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 6e0ca885f..d44c80b9f 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -54,7 +54,8 @@ static int mton(struct in_addr *mask)
54 54
55 55
56/* Fill dest with the text of option 'option'. */ 56/* Fill dest with the text of option 'option'. */
57static void fill_options(char *dest, uint8_t *option, struct dhcp_option *type_p) 57static void fill_options(char *dest, uint8_t *option,
58 const struct dhcp_option *type_p)
58{ 59{
59 int type, optlen; 60 int type, optlen;
60 uint16_t val_u16; 61 uint16_t val_u16;
@@ -152,7 +153,8 @@ static char **fill_envp(struct dhcpMessage *packet)
152 153
153 154
154 for (i = 0; dhcp_options[i].code; i++) { 155 for (i = 0; dhcp_options[i].code; i++) {
155 if (!(temp = get_option(packet, dhcp_options[i].code))) 156 temp = get_option(packet, dhcp_options[i].code);
157 if (temp)
156 continue; 158 continue;
157 envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2], 159 envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2],
158 dhcp_options[i].flags & TYPE_MASK) + strlen(dhcp_options[i].name) + 2); 160 dhcp_options[i].flags & TYPE_MASK) + strlen(dhcp_options[i].name) + 2);