summaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-11-22 00:58:49 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-11-22 00:58:49 +0000
commit223bc97f61f2fd5efbccede0837a374c1669e864 (patch)
tree0105a1f02dbc344ede7cca99565b6c556e7cab96 /networking/udhcp/dhcpc.c
parentc881c733bb05286f7147d0ca49ad238b86f6d848 (diff)
downloadbusybox-w32-223bc97f61f2fd5efbccede0837a374c1669e864.tar.gz
busybox-w32-223bc97f61f2fd5efbccede0837a374c1669e864.tar.bz2
busybox-w32-223bc97f61f2fd5efbccede0837a374c1669e864.zip
udhcpc: an option to perform ARP check (Jonas Danielsson <jonas.danielsson@axis.com>)
configurable, ~+300 bytes when on.
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c65
1 files changed, 53 insertions, 12 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index c6f9fe42d..b3b89459e 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -145,6 +145,13 @@ int udhcpc_main(int argc, char **argv)
145{ 145{
146 uint8_t *temp, *message; 146 uint8_t *temp, *message;
147 char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_A, *str_t; 147 char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_A, *str_t;
148 int tryagain_timeout = 60;
149 int discover_timeout = 3;
150 int discover_retries = 3;
151#if ENABLE_FEATURE_UDHCPC_ARPING
152 int decline_wait = 10;
153 char *str_W;
154#endif
148 uint32_t xid = 0; 155 uint32_t xid = 0;
149 uint32_t lease = 0; /* can be given as 32-bit quantity */ 156 uint32_t lease = 0; /* can be given as 32-bit quantity */
150 unsigned t1 = 0, t2 = 0; /* what a wonderful names */ 157 unsigned t1 = 0, t2 = 0; /* what a wonderful names */
@@ -180,6 +187,10 @@ int udhcpc_main(int argc, char **argv)
180 OPT_v = 1 << 17, 187 OPT_v = 1 << 17,
181 OPT_S = 1 << 18, 188 OPT_S = 1 << 18,
182 OPT_A = 1 << 19, 189 OPT_A = 1 << 19,
190#if ENABLE_FEATURE_UDHCPC_ARPING
191 OPT_a = 1 << 20,
192 OPT_W = 1 << 21,
193#endif
183 }; 194 };
184#if ENABLE_GETOPT_LONG 195#if ENABLE_GETOPT_LONG
185 static const char udhcpc_longopts[] ALIGN1 = 196 static const char udhcpc_longopts[] ALIGN1 =
@@ -203,14 +214,15 @@ int udhcpc_main(int argc, char **argv)
203 "retries\0" Required_argument "t" 214 "retries\0" Required_argument "t"
204 "tryagain\0" Required_argument "A" 215 "tryagain\0" Required_argument "A"
205 "syslog\0" No_argument "S" 216 "syslog\0" No_argument "S"
217#if ENABLE_FEATURE_UDHCPC_ARPING
218 "arping\0" No_argument "a"
219 "wait\0" Required_argument "W"
220#endif
206 ; 221 ;
207#endif 222#endif
208 /* Default options. */ 223 /* Default options. */
209 client_config.interface = "eth0"; 224 client_config.interface = "eth0";
210 client_config.script = DEFAULT_SCRIPT; 225 client_config.script = DEFAULT_SCRIPT;
211 client_config.retries = 3;
212 client_config.timeout = 3;
213 client_config.tryagain = 60;
214 226
215 /* Parse command line */ 227 /* Parse command line */
216 opt_complementary = "c--C:C--c" // mutually exclusive 228 opt_complementary = "c--C:C--c" // mutually exclusive
@@ -218,10 +230,12 @@ int udhcpc_main(int argc, char **argv)
218#if ENABLE_GETOPT_LONG 230#if ENABLE_GETOPT_LONG
219 applet_long_options = udhcpc_longopts; 231 applet_long_options = udhcpc_longopts;
220#endif 232#endif
221 opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:", 233 opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSA:"
222 &str_c, &str_V, &str_h, &str_h, &str_F, 234 USE_FEATURE_UDHCPC_ARPING("aW:")
235 , &str_c, &str_V, &str_h, &str_h, &str_F,
223 &client_config.interface, &client_config.pidfile, &str_r, 236 &client_config.interface, &client_config.pidfile, &str_r,
224 &client_config.script, &str_T, &str_t, &str_A 237 &client_config.script, &str_T, &str_t, &str_A
238 USE_FEATURE_UDHCPC_ARPING(, &str_W)
225 ); 239 );
226 240
227 if (opt & OPT_c) 241 if (opt & OPT_c)
@@ -259,11 +273,11 @@ int udhcpc_main(int argc, char **argv)
259 requested_ip = inet_addr(str_r); 273 requested_ip = inet_addr(str_r);
260 // if (opt & OPT_s) client_config.script = ... 274 // if (opt & OPT_s) client_config.script = ...
261 if (opt & OPT_T) 275 if (opt & OPT_T)
262 client_config.timeout = xatoi_u(str_T); 276 discover_timeout = xatoi_u(str_T);
263 if (opt & OPT_t) 277 if (opt & OPT_t)
264 client_config.retries = xatoi_u(str_t); 278 discover_retries = xatoi_u(str_t);
265 if (opt & OPT_A) 279 if (opt & OPT_A)
266 client_config.tryagain = xatoi_u(str_A); 280 tryagain_timeout = xatoi_u(str_A);
267 if (opt & OPT_v) { 281 if (opt & OPT_v) {
268 puts("version "BB_VER); 282 puts("version "BB_VER);
269 return 0; 283 return 0;
@@ -274,6 +288,11 @@ int udhcpc_main(int argc, char **argv)
274 logmode |= LOGMODE_SYSLOG; 288 logmode |= LOGMODE_SYSLOG;
275 } 289 }
276 290
291#if ENABLE_FEATURE_UDHCPC_ARPING
292 if (opt & OPT_W)
293 decline_wait = xatou_range(str_W, 10, INT_MAX);
294#endif
295
277 if (read_interface(client_config.interface, &client_config.ifindex, 296 if (read_interface(client_config.interface, &client_config.ifindex,
278 NULL, client_config.arp)) 297 NULL, client_config.arp))
279 return 1; 298 return 1;
@@ -339,14 +358,14 @@ int udhcpc_main(int argc, char **argv)
339 /* timeout dropped to zero */ 358 /* timeout dropped to zero */
340 switch (state) { 359 switch (state) {
341 case INIT_SELECTING: 360 case INIT_SELECTING:
342 if (packet_num < client_config.retries) { 361 if (packet_num < discover_retries) {
343 if (packet_num == 0) 362 if (packet_num == 0)
344 xid = random_xid(); 363 xid = random_xid();
345 364
346 /* send discover packet */ 365 /* send discover packet */
347 send_discover(xid, requested_ip); /* broadcast */ 366 send_discover(xid, requested_ip); /* broadcast */
348 367
349 timeout = now + client_config.timeout; 368 timeout = now + discover_timeout;
350 packet_num++; 369 packet_num++;
351 } else { 370 } else {
352 udhcp_run_script(NULL, "leasefail"); 371 udhcp_run_script(NULL, "leasefail");
@@ -360,12 +379,12 @@ int udhcpc_main(int argc, char **argv)
360 } 379 }
361 /* wait to try again */ 380 /* wait to try again */
362 packet_num = 0; 381 packet_num = 0;
363 timeout = now + client_config.tryagain; 382 timeout = now + tryagain_timeout;
364 } 383 }
365 break; 384 break;
366 case RENEW_REQUESTED: 385 case RENEW_REQUESTED:
367 case REQUESTING: 386 case REQUESTING:
368 if (packet_num < client_config.retries) { 387 if (packet_num < discover_retries) {
369 /* send request packet */ 388 /* send request packet */
370 if (state == RENEW_REQUESTED) 389 if (state == RENEW_REQUESTED)
371 send_renew(xid, server_addr, requested_ip); /* unicast */ 390 send_renew(xid, server_addr, requested_ip); /* unicast */
@@ -491,6 +510,28 @@ int udhcpc_main(int argc, char **argv)
491 lease = ntohl(lease); 510 lease = ntohl(lease);
492 } 511 }
493 512
513#if ENABLE_FEATURE_UDHCPC_ARPING
514 if (opt & OPT_a) {
515 if (!arpping(packet.yiaddr,
516 (uint32_t) 0,
517 client_config.arp,
518 client_config.interface)
519 ) {
520 bb_info_msg("offered address is in use,"
521 " declining");
522 send_decline(xid, server_addr);
523
524 if (state != REQUESTING)
525 udhcp_run_script(NULL, "deconfig");
526 state = INIT_SELECTING;
527 requested_ip = 0;
528 packet_num = 0;
529 change_mode(LISTEN_RAW);
530 timeout = now + decline_wait;
531 break;
532 }
533 }
534#endif
494 /* enter bound state */ 535 /* enter bound state */
495 t1 = lease / 2; 536 t1 = lease / 2;
496 537