diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-17 11:54:52 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-17 11:54:52 +0200 |
commit | ac906fa85e61b4e34161709de777616f858bc945 (patch) | |
tree | 7b247714814fd9dcf3fd3dccf954521b29eef5a2 /networking/udhcp/dhcpc.c | |
parent | ed8982bfc0e9895fe707a5f6152cf184e06f2052 (diff) | |
download | busybox-w32-ac906fa85e61b4e34161709de777616f858bc945.tar.gz busybox-w32-ac906fa85e61b4e34161709de777616f858bc945.tar.bz2 busybox-w32-ac906fa85e61b4e34161709de777616f858bc945.zip |
udhcp: change UDHCP_DEBUG into int, make verbosity selectable with -v
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 44ff197b9..eed9d9a01 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -20,9 +20,9 @@ | |||
20 | 20 | ||
21 | static int sockfd = -1; | 21 | static int sockfd = -1; |
22 | 22 | ||
23 | #define LISTEN_NONE 0 | 23 | #define LISTEN_NONE 0 |
24 | #define LISTEN_KERNEL 1 | 24 | #define LISTEN_KERNEL 1 |
25 | #define LISTEN_RAW 2 | 25 | #define LISTEN_RAW 2 |
26 | static smallint listen_mode; | 26 | static smallint listen_mode; |
27 | 27 | ||
28 | #define INIT_SELECTING 0 | 28 | #define INIT_SELECTING 0 |
@@ -41,7 +41,7 @@ static smallint state; | |||
41 | /* just a little helper */ | 41 | /* just a little helper */ |
42 | static void change_listen_mode(int new_mode) | 42 | static void change_listen_mode(int new_mode) |
43 | { | 43 | { |
44 | DEBUG("entering %s listen mode", | 44 | log1("entering %s listen mode", |
45 | new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none"); | 45 | new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none"); |
46 | 46 | ||
47 | listen_mode = new_mode; | 47 | listen_mode = new_mode; |
@@ -195,18 +195,17 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
195 | OPT_s = 1 << 12, | 195 | OPT_s = 1 << 12, |
196 | OPT_T = 1 << 13, | 196 | OPT_T = 1 << 13, |
197 | OPT_t = 1 << 14, | 197 | OPT_t = 1 << 14, |
198 | OPT_v = 1 << 15, | 198 | OPT_S = 1 << 15, |
199 | OPT_S = 1 << 16, | 199 | OPT_A = 1 << 16, |
200 | OPT_A = 1 << 17, | 200 | OPT_O = 1 << 17, |
201 | OPT_O = 1 << 18, | 201 | OPT_o = 1 << 18, |
202 | OPT_o = 1 << 19, | 202 | OPT_f = 1 << 19, |
203 | OPT_f = 1 << 20, | ||
204 | /* The rest has variable bit positions, need to be clever */ | 203 | /* The rest has variable bit positions, need to be clever */ |
205 | OPTBIT_f = 20, | 204 | OPTBIT_f = 19, |
206 | USE_FOR_MMU( OPTBIT_b,) | 205 | USE_FOR_MMU( OPTBIT_b,) |
207 | IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) | 206 | IF_FEATURE_UDHCPC_ARPING(OPTBIT_a,) |
208 | IF_FEATURE_UDHCP_PORT( OPTBIT_P,) | 207 | IF_FEATURE_UDHCP_PORT( OPTBIT_P,) |
209 | USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) | 208 | USE_FOR_MMU( OPT_b = 1 << OPTBIT_b,) |
210 | IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) | 209 | IF_FEATURE_UDHCPC_ARPING(OPT_a = 1 << OPTBIT_a,) |
211 | IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) | 210 | IF_FEATURE_UDHCP_PORT( OPT_P = 1 << OPTBIT_P,) |
212 | }; | 211 | }; |
@@ -219,18 +218,26 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
219 | 218 | ||
220 | /* Parse command line */ | 219 | /* Parse command line */ |
221 | /* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */ | 220 | /* Cc: mutually exclusive; O: list; -T,-t,-A take numeric param */ |
222 | opt_complementary = "c--C:C--c:O::T+:t+:A+"; | 221 | opt_complementary = "c--C:C--c:O::T+:t+:A+" |
222 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 | ||
223 | ":vv" | ||
224 | #endif | ||
225 | ; | ||
223 | IF_GETOPT_LONG(applet_long_options = udhcpc_longopts;) | 226 | IF_GETOPT_LONG(applet_long_options = udhcpc_longopts;) |
224 | opt = getopt32(argv, "c:CV:H:h:F:i:np:qRr:s:T:t:vSA:O:of" | 227 | opt = getopt32(argv, "c:CV:H:h:F:i:np:qRr:s:T:t:SA:O:of" |
225 | USE_FOR_MMU("b") | 228 | USE_FOR_MMU("b") |
226 | IF_FEATURE_UDHCPC_ARPING("a") | 229 | IF_FEATURE_UDHCPC_ARPING("a") |
227 | IF_FEATURE_UDHCP_PORT("P:") | 230 | IF_FEATURE_UDHCP_PORT("P:") |
231 | "v" | ||
228 | , &str_c, &str_V, &str_h, &str_h, &str_F | 232 | , &str_c, &str_V, &str_h, &str_h, &str_F |
229 | , &client_config.interface, &client_config.pidfile, &str_r /* i,p */ | 233 | , &client_config.interface, &client_config.pidfile, &str_r /* i,p */ |
230 | , &client_config.script /* s */ | 234 | , &client_config.script /* s */ |
231 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ | 235 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ |
232 | , &list_O | 236 | , &list_O |
233 | IF_FEATURE_UDHCP_PORT(, &str_P) | 237 | IF_FEATURE_UDHCP_PORT(, &str_P) |
238 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 | ||
239 | , &dhcp_verbose | ||
240 | #endif | ||
234 | ); | 241 | ); |
235 | if (opt & OPT_c) | 242 | if (opt & OPT_c) |
236 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0); | 243 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, str_c, 0); |
@@ -252,10 +259,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
252 | } | 259 | } |
253 | if (opt & OPT_r) | 260 | if (opt & OPT_r) |
254 | requested_ip = inet_addr(str_r); | 261 | requested_ip = inet_addr(str_r); |
255 | if (opt & OPT_v) { | ||
256 | puts("version "BB_VER); | ||
257 | return 0; | ||
258 | } | ||
259 | #if ENABLE_FEATURE_UDHCP_PORT | 262 | #if ENABLE_FEATURE_UDHCP_PORT |
260 | if (opt & OPT_P) { | 263 | if (opt & OPT_P) { |
261 | CLIENT_PORT = xatou16(str_P); | 264 | CLIENT_PORT = xatou16(str_P); |
@@ -348,7 +351,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
348 | retval = 0; /* If we already timed out, fall through, else... */ | 351 | retval = 0; /* If we already timed out, fall through, else... */ |
349 | if (tv.tv_sec > 0) { | 352 | if (tv.tv_sec > 0) { |
350 | timestamp_before_wait = (unsigned)monotonic_sec(); | 353 | timestamp_before_wait = (unsigned)monotonic_sec(); |
351 | DEBUG("Waiting on select..."); | 354 | log1("Waiting on select..."); |
352 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); | 355 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); |
353 | if (retval < 0) { | 356 | if (retval < 0) { |
354 | /* EINTR? A signal was caught, don't panic */ | 357 | /* EINTR? A signal was caught, don't panic */ |
@@ -428,7 +431,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
428 | case BOUND: | 431 | case BOUND: |
429 | /* Half of the lease passed, time to enter renewing state */ | 432 | /* Half of the lease passed, time to enter renewing state */ |
430 | change_listen_mode(LISTEN_KERNEL); | 433 | change_listen_mode(LISTEN_KERNEL); |
431 | DEBUG("Entering renew state"); | 434 | log1("Entering renew state"); |
432 | state = RENEWING; | 435 | state = RENEWING; |
433 | /* fall right through */ | 436 | /* fall right through */ |
434 | case RENEWING: | 437 | case RENEWING: |
@@ -439,7 +442,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
439 | continue; | 442 | continue; |
440 | } | 443 | } |
441 | /* Timed out, enter rebinding state */ | 444 | /* Timed out, enter rebinding state */ |
442 | DEBUG("Entering rebinding state"); | 445 | log1("Entering rebinding state"); |
443 | state = REBINDING; | 446 | state = REBINDING; |
444 | /* fall right through */ | 447 | /* fall right through */ |
445 | case REBINDING: | 448 | case REBINDING: |
@@ -477,7 +480,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
477 | else | 480 | else |
478 | len = udhcp_recv_raw_packet(&packet, sockfd); | 481 | len = udhcp_recv_raw_packet(&packet, sockfd); |
479 | if (len == -1) { /* error is severe, reopen socket */ | 482 | if (len == -1) { /* error is severe, reopen socket */ |
480 | DEBUG("error on read, %s, reopening socket", strerror(errno)); | 483 | bb_info_msg("Read error: %s, reopening socket", strerror(errno)); |
481 | sleep(discover_timeout); /* 3 seconds by default */ | 484 | sleep(discover_timeout); /* 3 seconds by default */ |
482 | change_listen_mode(listen_mode); /* just close and reopen */ | 485 | change_listen_mode(listen_mode); /* just close and reopen */ |
483 | } | 486 | } |
@@ -489,20 +492,21 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
489 | continue; | 492 | continue; |
490 | 493 | ||
491 | if (packet.xid != xid) { | 494 | if (packet.xid != xid) { |
492 | DEBUG("Ignoring xid %x (our xid is %x)", | 495 | log1("xid %x (our is %x), ignoring packet", |
493 | (unsigned)packet.xid, (unsigned)xid); | 496 | (unsigned)packet.xid, (unsigned)xid); |
494 | continue; | 497 | continue; |
495 | } | 498 | } |
496 | 499 | ||
497 | /* Ignore packets that aren't for us */ | 500 | /* Ignore packets that aren't for us */ |
498 | if (memcmp(packet.chaddr, client_config.client_mac, 6)) { | 501 | if (memcmp(packet.chaddr, client_config.client_mac, 6)) { |
499 | DEBUG("Packet does not have our chaddr - ignoring"); | 502 | //FIXME: need to also check that last 10 bytes are zero |
503 | log1("chaddr does not match, ignoring packet"); // log2? | ||
500 | continue; | 504 | continue; |
501 | } | 505 | } |
502 | 506 | ||
503 | message = get_option(&packet, DHCP_MESSAGE_TYPE); | 507 | message = get_option(&packet, DHCP_MESSAGE_TYPE); |
504 | if (message == NULL) { | 508 | if (message == NULL) { |
505 | bb_error_msg("cannot get message type from packet - ignoring"); | 509 | bb_error_msg("no message type option, ignoring packet"); |
506 | continue; | 510 | continue; |
507 | } | 511 | } |
508 | 512 | ||
@@ -563,7 +567,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
563 | client_config.client_mac, | 567 | client_config.client_mac, |
564 | client_config.interface) | 568 | client_config.interface) |
565 | ) { | 569 | ) { |
566 | bb_info_msg("offered address is in use " | 570 | bb_info_msg("Offered address is in use " |
567 | "(got ARP reply), declining"); | 571 | "(got ARP reply), declining"); |
568 | send_decline(xid, server_addr, packet.yiaddr); | 572 | send_decline(xid, server_addr, packet.yiaddr); |
569 | 573 | ||