aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Dill <Russ.Dill@asu.edu>2002-12-11 21:12:45 +0000
committerRuss Dill <Russ.Dill@asu.edu>2002-12-11 21:12:45 +0000
commit1eb7a17b12a6ee3df8849d00d4ebd2c227ccf1f8 (patch)
treed7b4fa1a385e1943afdd111d4c708a64cdd5520f
parentd7e1a6c6ebfeecc1e7ff3982235b6edb84d9a017 (diff)
downloadbusybox-w32-1eb7a17b12a6ee3df8849d00d4ebd2c227ccf1f8.tar.gz
busybox-w32-1eb7a17b12a6ee3df8849d00d4ebd2c227ccf1f8.tar.bz2
busybox-w32-1eb7a17b12a6ee3df8849d00d4ebd2c227ccf1f8.zip
resync with udhcp cvs
-rw-r--r--networking/udhcp/Config.in9
-rw-r--r--networking/udhcp/README.udhcpc1
-rw-r--r--networking/udhcp/dhcpc.c4
-rw-r--r--networking/udhcp/dumpleases.c2
-rw-r--r--networking/udhcp/files.c2
-rw-r--r--networking/udhcp/options.c7
-rw-r--r--networking/udhcp/options.h3
-rw-r--r--networking/udhcp/script.c99
-rw-r--r--networking/udhcp/version.h2
9 files changed, 46 insertions, 83 deletions
diff --git a/networking/udhcp/Config.in b/networking/udhcp/Config.in
index 674470a39..5baaa6a49 100644
--- a/networking/udhcp/Config.in
+++ b/networking/udhcp/Config.in
@@ -38,14 +38,5 @@ config CONFIG_FEATURE_UDHCP_DEBUG
38 help 38 help
39 Please submit a patch to add help text for this item. 39 Please submit a patch to add help text for this item.
40 40
41config CONFIG_FEATURE_UDHCPC_IP
42 bool " Compile udhcpc with ip support"
43 default n
44 depends on CONFIG_UDHCPC
45 help
46 Say yes if you are using the ip command instead of route and ifconfig
47 in your scripts to bring up the interface.
48 This is needed as ip wants the subnet as a bitprefix not an ip value.
49
50endmenu 41endmenu
51 42
diff --git a/networking/udhcp/README.udhcpc b/networking/udhcp/README.udhcpc
index d94908650..8aee9814b 100644
--- a/networking/udhcp/README.udhcpc
+++ b/networking/udhcp/README.udhcpc
@@ -69,6 +69,7 @@ The paramaters for enviromental variables are as follows:
69 $1 - What action the script should perform 69 $1 - What action the script should perform
70 interface - The interface this was obtained on 70 interface - The interface this was obtained on
71 ip - The obtained IP 71 ip - The obtained IP
72 mask - The number of bits in the netmask (ie: 24)
72 siaddr - The bootp next server option 73 siaddr - The bootp next server option
73 sname - The bootp server name option 74 sname - The bootp server name option
74 boot_file - The bootp boot file option 75 boot_file - The bootp boot file option
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index c55ebbb09..740daaffb 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -248,7 +248,7 @@ int main(int argc, char *argv[])
248 switch (c) { 248 switch (c) {
249 case 'c': 249 case 'c':
250 len = strlen(optarg) > 255 ? 255 : strlen(optarg); 250 len = strlen(optarg) > 255 ? 255 : strlen(optarg);
251 free(client_config.clientid); 251 if (client_config.clientid) free(client_config.clientid);
252 client_config.clientid = xmalloc(len + 2); 252 client_config.clientid = xmalloc(len + 2);
253 client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; 253 client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID;
254 client_config.clientid[OPT_LEN] = len; 254 client_config.clientid[OPT_LEN] = len;
@@ -264,7 +264,7 @@ int main(int argc, char *argv[])
264 case 'h': 264 case 'h':
265 case 'H': 265 case 'H':
266 len = strlen(optarg) > 255 ? 255 : strlen(optarg); 266 len = strlen(optarg) > 255 ? 255 : strlen(optarg);
267 free(client_config.hostname); 267 if (client_config.hostname) free(client_config.hostname);
268 client_config.hostname = xmalloc(len + 2); 268 client_config.hostname = xmalloc(len + 2);
269 client_config.hostname[OPT_CODE] = DHCP_HOST_NAME; 269 client_config.hostname[OPT_CODE] = DHCP_HOST_NAME;
270 client_config.hostname[OPT_LEN] = len; 270 client_config.hostname[OPT_LEN] = len;
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index 32ee24b94..2b19d9768 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -28,7 +28,7 @@ struct lease_t {
28 u_int32_t expires; 28 u_int32_t expires;
29}; 29};
30 30
31#ifdef COMBINED_BINARY 31#ifdef BB_VER
32int dumpleases_main(int argc, char *argv[]) 32int dumpleases_main(int argc, char *argv[])
33#else 33#else
34int main(int argc, char *argv[]) 34int main(int argc, char *argv[])
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index cf72de1a8..842e0f2db 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -38,7 +38,7 @@ static int read_str(char *line, void *arg)
38{ 38{
39 char **dest = arg; 39 char **dest = arg;
40 40
41 free(*dest); 41 if (*dest) free(*dest);
42 *dest = strdup(line); 42 *dest = strdup(line);
43 43
44 return 1; 44 return 1;
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 3f3a38963..58144728e 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -13,16 +13,11 @@
13#include "options.h" 13#include "options.h"
14#include "leases.h" 14#include "leases.h"
15 15
16#include "config.h"
17 16
18/* supported options are easily added here */ 17/* supported options are easily added here */
19struct dhcp_option options[] = { 18struct dhcp_option options[] = {
20 /* name[10] flags code */ 19 /* name[10] flags code */
21#ifdef CONFIG_FEATURE_UDHCPC_IP 20 {"subnet", OPTION_IP | OPTION_REQ, 0x01},
22 {"subnet", OPTION_IP | OPTION_REQ | OPTION_PREFIX, 0x01},
23#else
24 {"subnet", OPTION_IP | OPTION_REQ, 0x01},
25#endif
26 {"timezone", OPTION_S32, 0x02}, 21 {"timezone", OPTION_S32, 0x02},
27 {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03}, 22 {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03},
28 {"timesvr", OPTION_IP | OPTION_LIST, 0x04}, 23 {"timesvr", OPTION_IP | OPTION_LIST, 0x04},
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index dccaa2af9..1fded2ef4 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -4,8 +4,6 @@
4 4
5#include "packet.h" 5#include "packet.h"
6 6
7#include "config.h"
8
9#define TYPE_MASK 0x0F 7#define TYPE_MASK 0x0F
10 8
11enum { 9enum {
@@ -22,7 +20,6 @@ enum {
22 20
23#define OPTION_REQ 0x10 /* have the client request this option */ 21#define OPTION_REQ 0x10 /* have the client request this option */
24#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */ 22#define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */
25#define OPTION_PREFIX 0x40 /* ip wants a prefix instead of a ip for subnet */
26 23
27struct dhcp_option { 24struct dhcp_option {
28 char name[10]; 25 char name[10];
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 1c6f1bd33..2eb4459dd 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -37,8 +37,6 @@
37#include "options.h" 37#include "options.h"
38#include "debug.h" 38#include "debug.h"
39 39
40#include "config.h"
41
42/* get a rough idea of how long an option will be (rounding up...) */ 40/* get a rough idea of how long an option will be (rounding up...) */
43static int max_option_length[] = { 41static int max_option_length[] = {
44 [OPTION_IP] = sizeof("255.255.255.255 "), 42 [OPTION_IP] = sizeof("255.255.255.255 "),
@@ -60,41 +58,22 @@ static int upper_length(int length, struct dhcp_option *option)
60} 58}
61 59
62 60
63static int sprintip(char *dest, char *pre, unsigned char *ip) { 61static int sprintip(char *dest, char *pre, unsigned char *ip)
64 return sprintf(dest, "%s%d.%d.%d.%d ", pre, ip[0], ip[1], ip[2], ip[3]);
65}
66
67#ifdef CONFIG_FEATURE_UDHCPC_IP
68/* convert a netmask (255.255.255.0) into the length (24) */
69static int inet_ntom (const char *src, short *dst)
70{ 62{
71 in_addr_t mask, num; 63 return sprintf(dest, "%s%d.%d.%d.%d", pre, ip[0], ip[1], ip[2], ip[3]);
72 64}
73 mask = ntohl(*(unsigned int *)src);
74
75 for (num = mask; num & 1; num >>= 1);
76
77 if (num != 0 && mask != 0)
78 {
79 for (num = ~mask; num & 1; num >>= 1);
80 if (num)
81 return 0;
82 }
83
84 for (num = 0; mask; mask <<= 1)
85 num++;
86 65
87 *dst = num;
88 66
89 return 1; 67/* really simple implementation, just count the bits */
68static int mton(struct in_addr *mask)
69{
70 int i;
71 /* note: mask will always be in network byte order, so
72 * there are no endian issues */
73 for (i = 31; i >= 0 && !((mask->s_addr >> i) & 1); i--);
74 return i + 1;
90} 75}
91 76
92static int sprintprefix(char *dest, char *pre, unsigned char *ip) {
93 short sdest = 0;
94 inet_ntom(ip, &sdest);
95 return sprintf(dest, "%s%hd ", pre, sdest);
96}
97#endif
98 77
99/* Fill dest with the text of option 'option'. */ 78/* Fill dest with the text of option 'option'. */
100static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p) 79static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p)
@@ -117,41 +96,30 @@ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *
117 *(dest++) = '/'; 96 *(dest++) = '/';
118 option += 4; 97 option += 4;
119 optlen = 4; 98 optlen = 4;
120#ifndef CONFIG_FEATURE_UDHCPC_IP
121 case OPTION_IP: /* Works regardless of host byte order. */ 99 case OPTION_IP: /* Works regardless of host byte order. */
122#endif
123 dest += sprintip(dest, "", option); 100 dest += sprintip(dest, "", option);
124 break; 101 break;
125#ifdef CONFIG_FEATURE_UDHCPC_IP
126 case OPTION_IP: /* Works regardless of host byte order. */
127 if (type_p->flags & OPTION_PREFIX) {
128 dest += sprintprefix(dest, "", option);
129 } else {
130 dest += sprintip(dest, "", option);
131 }
132 break;
133#endif
134 case OPTION_BOOLEAN: 102 case OPTION_BOOLEAN:
135 dest += sprintf(dest, *option ? "yes " : "no "); 103 dest += sprintf(dest, *option ? "yes" : "no");
136 break; 104 break;
137 case OPTION_U8: 105 case OPTION_U8:
138 dest += sprintf(dest, "%u ", *option); 106 dest += sprintf(dest, "%u", *option);
139 break; 107 break;
140 case OPTION_U16: 108 case OPTION_U16:
141 memcpy(&val_u16, option, 2); 109 memcpy(&val_u16, option, 2);
142 dest += sprintf(dest, "%u ", ntohs(val_u16)); 110 dest += sprintf(dest, "%u", ntohs(val_u16));
143 break; 111 break;
144 case OPTION_S16: 112 case OPTION_S16:
145 memcpy(&val_s16, option, 2); 113 memcpy(&val_s16, option, 2);
146 dest += sprintf(dest, "%d ", ntohs(val_s16)); 114 dest += sprintf(dest, "%d", ntohs(val_s16));
147 break; 115 break;
148 case OPTION_U32: 116 case OPTION_U32:
149 memcpy(&val_u32, option, 4); 117 memcpy(&val_u32, option, 4);
150 dest += sprintf(dest, "%lu ", (unsigned long) ntohl(val_u32)); 118 dest += sprintf(dest, "%lu", (unsigned long) ntohl(val_u32));
151 break; 119 break;
152 case OPTION_S32: 120 case OPTION_S32:
153 memcpy(&val_s32, option, 4); 121 memcpy(&val_s32, option, 4);
154 dest += sprintf(dest, "%ld ", (long) ntohl(val_s32)); 122 dest += sprintf(dest, "%ld", (long) ntohl(val_s32));
155 break; 123 break;
156 case OPTION_STRING: 124 case OPTION_STRING:
157 memcpy(dest, option, len); 125 memcpy(dest, option, len);
@@ -161,6 +129,7 @@ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *
161 option += optlen; 129 option += optlen;
162 len -= optlen; 130 len -= optlen;
163 if (len <= 0) break; 131 if (len <= 0) break;
132 dest += sprintf(dest, " ");
164 } 133 }
165} 134}
166 135
@@ -186,6 +155,7 @@ static char **fill_envp(struct dhcpMessage *packet)
186 int i, j; 155 int i, j;
187 char **envp; 156 char **envp;
188 unsigned char *temp; 157 unsigned char *temp;
158 struct in_addr subnet;
189 char over = 0; 159 char over = 0;
190 160
191 if (packet == NULL) 161 if (packet == NULL)
@@ -202,23 +172,32 @@ static char **fill_envp(struct dhcpMessage *packet)
202 } 172 }
203 173
204 envp = xmalloc((num_options + 5) * sizeof(char *)); 174 envp = xmalloc((num_options + 5) * sizeof(char *));
205 envp[0] = xmalloc(sizeof("interface=") + strlen(client_config.interface)); 175 j = 0;
176 envp[j++] = xmalloc(sizeof("interface=") + strlen(client_config.interface));
206 sprintf(envp[0], "interface=%s", client_config.interface); 177 sprintf(envp[0], "interface=%s", client_config.interface);
207 envp[1] = find_env("PATH", "PATH=/bin:/usr/bin:/sbin:/usr/sbin"); 178 envp[j++] = find_env("PATH", "PATH=/bin:/usr/bin:/sbin:/usr/sbin");
208 envp[2] = find_env("HOME", "HOME=/"); 179 envp[j++] = find_env("HOME", "HOME=/");
209 180
210 if (packet == NULL) { 181 if (packet == NULL) {
211 envp[3] = NULL; 182 envp[j++] = NULL;
212 return envp; 183 return envp;
213 } 184 }
214 185
215 envp[3] = xmalloc(sizeof("ip=255.255.255.255")); 186 envp[j] = xmalloc(sizeof("ip=255.255.255.255"));
216 sprintip(envp[3], "ip=", (unsigned char *) &packet->yiaddr); 187 sprintip(envp[j++], "ip=", (unsigned char *) &packet->yiaddr);
217 for (i = 0, j = 4; options[i].code; i++) { 188
218 if ((temp = get_option(packet, options[i].code))) { 189
219 envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2], &options[i]) + strlen(options[i].name) + 2); 190 for (i = 0; options[i].code; i++) {
220 fill_options(envp[j], temp, &options[i]); 191 if (!(temp = get_option(packet, options[i].code)))
221 j++; 192 continue;
193 envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2], &options[i]) + strlen(options[i].name) + 2);
194 fill_options(envp[j++], temp, &options[i]);
195
196 /* Fill in a subnet bits option for things like /24 */
197 if (options[i].code == DHCP_SUBNET) {
198 envp[j] = xmalloc(sizeof("mask=32"));
199 memcpy(&subnet, temp, 4);
200 sprintf(envp[j++], "mask=%d", mton(&subnet));
222 } 201 }
223 } 202 }
224 if (packet->siaddr) { 203 if (packet->siaddr) {
diff --git a/networking/udhcp/version.h b/networking/udhcp/version.h
index 07b1db163..3862539f5 100644
--- a/networking/udhcp/version.h
+++ b/networking/udhcp/version.h
@@ -1,6 +1,6 @@
1#ifndef _UDHCP_VERSION_H 1#ifndef _UDHCP_VERSION_H
2#define _UDHCP_VERSION_H 2#define _UDHCP_VERSION_H
3 3
4#define VERSION "0.9.8" 4#define VERSION "0.9.9-pre"
5 5
6#endif 6#endif