diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-07 01:05:47 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-07 01:05:47 +0000 |
commit | fbd2918f5c91723063ed698026217a77a0fe565b (patch) | |
tree | cddfe351592f4a876232cf4c67c23df25bf0563c /networking/udhcp/dhcpc.c | |
parent | bb5b01c7c711dd9ffc2abf23a05ccdfbf7fc0325 (diff) | |
download | busybox-w32-fbd2918f5c91723063ed698026217a77a0fe565b.tar.gz busybox-w32-fbd2918f5c91723063ed698026217a77a0fe565b.tar.bz2 busybox-w32-fbd2918f5c91723063ed698026217a77a0fe565b.zip |
udhcp: MAC_BCAST_ADDR and blank_chaddr are in fact constant, move to rodata.
a few global variables reduced to smallints
function old new delta
add_lease 75 227 +152
static.blank_chaddr - 16 +16
MAC_BCAST_ADDR - 6 +6
sockfd 4 8 +4
udhcp_run_script 1153 1155 +2
state 8 5 -3
listen_mode 4 1 -3
perform_release 152 148 -4
fd 8 4 -4
blank_chaddr 16 - -16
udhcpc_main 2518 2497 -21
.rodata 131864 131832 -32
oldest_expired_lease 61 - -61
clear_lease 127 - -127
------------------------------------------------------------------------------
(add/remove: 2/3 grow/shrink: 3/6 up/down: 180/-271) Total: -91 bytes
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index e8cdd79df..362e70169 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -17,22 +17,23 @@ | |||
17 | #include "options.h" | 17 | #include "options.h" |
18 | 18 | ||
19 | 19 | ||
20 | static int state; | ||
21 | /* Something is definitely wrong here. IPv4 addresses | 20 | /* Something is definitely wrong here. IPv4 addresses |
22 | * in variables of type long?? BTW, we use inet_ntoa() | 21 | * in variables of type long?? BTW, we use inet_ntoa() |
23 | * in the code. Manpage says that struct in_addr has a member of type long (!) | 22 | * in the code. Manpage says that struct in_addr has a member of type long (!) |
24 | * which holds IPv4 address, and the struct is passed by value (!!) | 23 | * which holds IPv4 address, and the struct is passed by value (!!) |
25 | */ | 24 | */ |
25 | static unsigned long timeout; | ||
26 | static unsigned long requested_ip; /* = 0 */ | 26 | static unsigned long requested_ip; /* = 0 */ |
27 | static uint32_t server_addr; | 27 | static uint32_t server_addr; |
28 | static unsigned long timeout; | ||
29 | static int packet_num; /* = 0 */ | 28 | static int packet_num; /* = 0 */ |
30 | static int fd = -1; | 29 | static int sockfd = -1; |
31 | 30 | ||
32 | #define LISTEN_NONE 0 | 31 | #define LISTEN_NONE 0 |
33 | #define LISTEN_KERNEL 1 | 32 | #define LISTEN_KERNEL 1 |
34 | #define LISTEN_RAW 2 | 33 | #define LISTEN_RAW 2 |
35 | static int listen_mode; | 34 | static smallint listen_mode; |
35 | |||
36 | static smallint state; | ||
36 | 37 | ||
37 | struct client_config_t client_config; | 38 | struct client_config_t client_config; |
38 | 39 | ||
@@ -42,8 +43,10 @@ static void change_mode(int new_mode) | |||
42 | { | 43 | { |
43 | DEBUG("entering %s listen mode", | 44 | DEBUG("entering %s listen mode", |
44 | new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none"); | 45 | new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none"); |
45 | if (fd >= 0) close(fd); | 46 | if (sockfd >= 0) { |
46 | fd = -1; | 47 | close(sockfd); |
48 | sockfd = -1; | ||
49 | } | ||
47 | listen_mode = new_mode; | 50 | listen_mode = new_mode; |
48 | } | 51 | } |
49 | 52 | ||
@@ -111,6 +114,7 @@ static void client_background(void) | |||
111 | * If that will be properly disabled for NOMMU, client_background() | 114 | * If that will be properly disabled for NOMMU, client_background() |
112 | * will work on NOMMU too */ | 115 | * will work on NOMMU too */ |
113 | #else | 116 | #else |
117 | // chdir(/) is problematic. Imagine that e.g. pidfile name is RELATIVE! what will unlink do then, eh? | ||
114 | bb_daemonize(DAEMON_CHDIR_ROOT); | 118 | bb_daemonize(DAEMON_CHDIR_ROOT); |
115 | logmode &= ~LOGMODE_STDIO; | 119 | logmode &= ~LOGMODE_STDIO; |
116 | #endif | 120 | #endif |
@@ -289,13 +293,13 @@ int udhcpc_main(int argc, char **argv) | |||
289 | tv.tv_sec = timeout - uptime(); | 293 | tv.tv_sec = timeout - uptime(); |
290 | tv.tv_usec = 0; | 294 | tv.tv_usec = 0; |
291 | 295 | ||
292 | if (listen_mode != LISTEN_NONE && fd < 0) { | 296 | if (listen_mode != LISTEN_NONE && sockfd < 0) { |
293 | if (listen_mode == LISTEN_KERNEL) | 297 | if (listen_mode == LISTEN_KERNEL) |
294 | fd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface); | 298 | sockfd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface); |
295 | else | 299 | else |
296 | fd = raw_socket(client_config.ifindex); | 300 | sockfd = raw_socket(client_config.ifindex); |
297 | } | 301 | } |
298 | max_fd = udhcp_sp_fd_set(&rfds, fd); | 302 | max_fd = udhcp_sp_fd_set(&rfds, sockfd); |
299 | 303 | ||
300 | if (tv.tv_sec > 0) { | 304 | if (tv.tv_sec > 0) { |
301 | DEBUG("Waiting on select..."); | 305 | DEBUG("Waiting on select..."); |
@@ -342,7 +346,8 @@ int udhcpc_main(int argc, char **argv) | |||
342 | packet_num++; | 346 | packet_num++; |
343 | } else { | 347 | } else { |
344 | /* timed out, go back to init state */ | 348 | /* timed out, go back to init state */ |
345 | if (state == RENEW_REQUESTED) udhcp_run_script(NULL, "deconfig"); | 349 | if (state == RENEW_REQUESTED) |
350 | udhcp_run_script(NULL, "deconfig"); | ||
346 | state = INIT_SELECTING; | 351 | state = INIT_SELECTING; |
347 | timeout = now; | 352 | timeout = now; |
348 | packet_num = 0; | 353 | packet_num = 0; |
@@ -393,12 +398,12 @@ int udhcpc_main(int argc, char **argv) | |||
393 | timeout = 0x7fffffff; | 398 | timeout = 0x7fffffff; |
394 | break; | 399 | break; |
395 | } | 400 | } |
396 | } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(fd, &rfds)) { | 401 | } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { |
397 | /* a packet is ready, read it */ | 402 | /* a packet is ready, read it */ |
398 | 403 | ||
399 | if (listen_mode == LISTEN_KERNEL) | 404 | if (listen_mode == LISTEN_KERNEL) |
400 | len = udhcp_get_packet(&packet, fd); | 405 | len = udhcp_get_packet(&packet, sockfd); |
401 | else len = get_raw_packet(&packet, fd); | 406 | else len = get_raw_packet(&packet, sockfd); |
402 | 407 | ||
403 | if (len == -1 && errno != EINTR) { | 408 | if (len == -1 && errno != EINTR) { |
404 | DEBUG("error on read, %s, reopening socket", strerror(errno)); | 409 | DEBUG("error on read, %s, reopening socket", strerror(errno)); |
@@ -418,7 +423,8 @@ int udhcpc_main(int argc, char **argv) | |||
418 | continue; | 423 | continue; |
419 | } | 424 | } |
420 | 425 | ||
421 | if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { | 426 | message = get_option(&packet, DHCP_MESSAGE_TYPE); |
427 | if (message == NULL) { | ||
422 | bb_error_msg("cannot get option from packet - ignoring"); | 428 | bb_error_msg("cannot get option from packet - ignoring"); |
423 | continue; | 429 | continue; |
424 | } | 430 | } |