diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-26 15:01:13 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-05-26 15:03:05 +0200 |
commit | bcb1fc3e6ca6fe902610f507eaf9b0b58a5c583a (patch) | |
tree | 7d591d16007a2a162e13b1f601fc33c9115299e8 /networking/udhcp/dhcpc.c | |
parent | 818d9e02f2de87aef3ba72c2b3bcec6eed4ef974 (diff) | |
download | busybox-w32-bcb1fc3e6ca6fe902610f507eaf9b0b58a5c583a.tar.gz busybox-w32-bcb1fc3e6ca6fe902610f507eaf9b0b58a5c583a.tar.bz2 busybox-w32-bcb1fc3e6ca6fe902610f507eaf9b0b58a5c583a.zip |
udhcp: rename client_config to client_data, server_config to server_data
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 214 |
1 files changed, 107 insertions, 107 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 7b1b23706..cb85fa9e3 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -49,7 +49,7 @@ struct tpacket_auxdata { | |||
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | 51 | ||
52 | /* "struct client_config_t client_config" is in bb_common_bufsiz1 */ | 52 | /* "struct client_data_t client_data" is in bb_common_bufsiz1 */ |
53 | 53 | ||
54 | 54 | ||
55 | #if ENABLE_LONG_OPTS | 55 | #if ENABLE_LONG_OPTS |
@@ -477,7 +477,7 @@ static char **fill_envp(struct dhcp_packet *packet) | |||
477 | } | 477 | } |
478 | curr = envp = xzalloc(sizeof(envp[0]) * envc); | 478 | curr = envp = xzalloc(sizeof(envp[0]) * envc); |
479 | 479 | ||
480 | *curr = xasprintf("interface=%s", client_config.interface); | 480 | *curr = xasprintf("interface=%s", client_data.interface); |
481 | putenv(*curr++); | 481 | putenv(*curr++); |
482 | 482 | ||
483 | if (!packet) | 483 | if (!packet) |
@@ -577,8 +577,8 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name) | |||
577 | envp = fill_envp(packet); | 577 | envp = fill_envp(packet); |
578 | 578 | ||
579 | /* call script */ | 579 | /* call script */ |
580 | log1("executing %s %s", client_config.script, name); | 580 | log1("executing %s %s", client_data.script, name); |
581 | argv[0] = (char*) client_config.script; | 581 | argv[0] = (char*) client_data.script; |
582 | argv[1] = (char*) name; | 582 | argv[1] = (char*) name; |
583 | argv[2] = NULL; | 583 | argv[2] = NULL; |
584 | spawn_and_wait(argv); | 584 | spawn_and_wait(argv); |
@@ -608,15 +608,15 @@ static void init_packet(struct dhcp_packet *packet, char type) | |||
608 | 608 | ||
609 | packet->xid = random_xid(); | 609 | packet->xid = random_xid(); |
610 | 610 | ||
611 | client_config.last_secs = monotonic_sec(); | 611 | client_data.last_secs = monotonic_sec(); |
612 | if (client_config.first_secs == 0) | 612 | if (client_data.first_secs == 0) |
613 | client_config.first_secs = client_config.last_secs; | 613 | client_data.first_secs = client_data.last_secs; |
614 | secs = client_config.last_secs - client_config.first_secs; | 614 | secs = client_data.last_secs - client_data.first_secs; |
615 | packet->secs = htons(secs); | 615 | packet->secs = htons(secs); |
616 | 616 | ||
617 | memcpy(packet->chaddr, client_config.client_mac, 6); | 617 | memcpy(packet->chaddr, client_data.client_mac, 6); |
618 | if (client_config.clientid) | 618 | if (client_data.clientid) |
619 | udhcp_add_binary_option(packet, client_config.clientid); | 619 | udhcp_add_binary_option(packet, client_data.clientid); |
620 | } | 620 | } |
621 | 621 | ||
622 | static void add_client_options(struct dhcp_packet *packet) | 622 | static void add_client_options(struct dhcp_packet *packet) |
@@ -631,7 +631,7 @@ static void add_client_options(struct dhcp_packet *packet) | |||
631 | end = udhcp_end_option(packet->options); | 631 | end = udhcp_end_option(packet->options); |
632 | len = 0; | 632 | len = 0; |
633 | for (i = 1; i < DHCP_END; i++) { | 633 | for (i = 1; i < DHCP_END; i++) { |
634 | if (client_config.opt_mask[i >> 3] & (1 << (i & 7))) { | 634 | if (client_data.opt_mask[i >> 3] & (1 << (i & 7))) { |
635 | packet->options[end + OPT_DATA + len] = i; | 635 | packet->options[end + OPT_DATA + len] = i; |
636 | len++; | 636 | len++; |
637 | } | 637 | } |
@@ -642,12 +642,12 @@ static void add_client_options(struct dhcp_packet *packet) | |||
642 | packet->options[end + OPT_DATA + len] = DHCP_END; | 642 | packet->options[end + OPT_DATA + len] = DHCP_END; |
643 | } | 643 | } |
644 | 644 | ||
645 | if (client_config.vendorclass) | 645 | if (client_data.vendorclass) |
646 | udhcp_add_binary_option(packet, client_config.vendorclass); | 646 | udhcp_add_binary_option(packet, client_data.vendorclass); |
647 | if (client_config.hostname) | 647 | if (client_data.hostname) |
648 | udhcp_add_binary_option(packet, client_config.hostname); | 648 | udhcp_add_binary_option(packet, client_data.hostname); |
649 | if (client_config.fqdn) | 649 | if (client_data.fqdn) |
650 | udhcp_add_binary_option(packet, client_config.fqdn); | 650 | udhcp_add_binary_option(packet, client_data.fqdn); |
651 | 651 | ||
652 | /* Request broadcast replies if we have no IP addr */ | 652 | /* Request broadcast replies if we have no IP addr */ |
653 | if ((option_mask32 & OPT_B) && packet->ciaddr == 0) | 653 | if ((option_mask32 & OPT_B) && packet->ciaddr == 0) |
@@ -655,15 +655,15 @@ static void add_client_options(struct dhcp_packet *packet) | |||
655 | 655 | ||
656 | /* Add -x options if any */ | 656 | /* Add -x options if any */ |
657 | { | 657 | { |
658 | struct option_set *curr = client_config.options; | 658 | struct option_set *curr = client_data.options; |
659 | while (curr) { | 659 | while (curr) { |
660 | udhcp_add_binary_option(packet, curr->data); | 660 | udhcp_add_binary_option(packet, curr->data); |
661 | curr = curr->next; | 661 | curr = curr->next; |
662 | } | 662 | } |
663 | // if (client_config.sname) | 663 | // if (client_data.sname) |
664 | // strncpy((char*)packet->sname, client_config.sname, sizeof(packet->sname) - 1); | 664 | // strncpy((char*)packet->sname, client_data.sname, sizeof(packet->sname) - 1); |
665 | // if (client_config.boot_file) | 665 | // if (client_data.boot_file) |
666 | // strncpy((char*)packet->file, client_config.boot_file, sizeof(packet->file) - 1); | 666 | // strncpy((char*)packet->file, client_data.boot_file, sizeof(packet->file) - 1); |
667 | } | 667 | } |
668 | 668 | ||
669 | // This will be needed if we remove -V VENDOR_STR in favor of | 669 | // This will be needed if we remove -V VENDOR_STR in favor of |
@@ -691,12 +691,12 @@ static void add_client_options(struct dhcp_packet *packet) | |||
691 | * client reverts to using the IP broadcast address. | 691 | * client reverts to using the IP broadcast address. |
692 | */ | 692 | */ |
693 | 693 | ||
694 | static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet, uint32_t src_nip) | 694 | static int raw_bcast_from_client_data_ifindex(struct dhcp_packet *packet, uint32_t src_nip) |
695 | { | 695 | { |
696 | return udhcp_send_raw_packet(packet, | 696 | return udhcp_send_raw_packet(packet, |
697 | /*src*/ src_nip, CLIENT_PORT, | 697 | /*src*/ src_nip, CLIENT_PORT, |
698 | /*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, | 698 | /*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, |
699 | client_config.ifindex); | 699 | client_data.ifindex); |
700 | } | 700 | } |
701 | 701 | ||
702 | static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server) | 702 | static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server) |
@@ -705,7 +705,7 @@ static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t | |||
705 | return udhcp_send_kernel_packet(packet, | 705 | return udhcp_send_kernel_packet(packet, |
706 | ciaddr, CLIENT_PORT, | 706 | ciaddr, CLIENT_PORT, |
707 | server, SERVER_PORT); | 707 | server, SERVER_PORT); |
708 | return raw_bcast_from_client_config_ifindex(packet, ciaddr); | 708 | return raw_bcast_from_client_data_ifindex(packet, ciaddr); |
709 | } | 709 | } |
710 | 710 | ||
711 | /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ | 711 | /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ |
@@ -731,7 +731,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) | |||
731 | add_client_options(&packet); | 731 | add_client_options(&packet); |
732 | 732 | ||
733 | bb_info_msg("sending %s", "discover"); | 733 | bb_info_msg("sending %s", "discover"); |
734 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); | 734 | return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); |
735 | } | 735 | } |
736 | 736 | ||
737 | /* Broadcast a DHCP request message */ | 737 | /* Broadcast a DHCP request message */ |
@@ -775,7 +775,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste | |||
775 | 775 | ||
776 | temp_addr.s_addr = requested; | 776 | temp_addr.s_addr = requested; |
777 | bb_info_msg("sending select for %s", inet_ntoa(temp_addr)); | 777 | bb_info_msg("sending select for %s", inet_ntoa(temp_addr)); |
778 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); | 778 | return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); |
779 | } | 779 | } |
780 | 780 | ||
781 | /* Unicast or broadcast a DHCP renew message */ | 781 | /* Unicast or broadcast a DHCP renew message */ |
@@ -845,7 +845,7 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req | |||
845 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); | 845 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); |
846 | 846 | ||
847 | bb_info_msg("sending %s", "decline"); | 847 | bb_info_msg("sending %s", "decline"); |
848 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); | 848 | return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); |
849 | } | 849 | } |
850 | #endif | 850 | #endif |
851 | 851 | ||
@@ -984,12 +984,12 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
984 | 984 | ||
985 | /*** Main ***/ | 985 | /*** Main ***/ |
986 | 986 | ||
987 | /* Values for client_config.listen_mode */ | 987 | /* Values for client_data.listen_mode */ |
988 | #define LISTEN_NONE 0 | 988 | #define LISTEN_NONE 0 |
989 | #define LISTEN_KERNEL 1 | 989 | #define LISTEN_KERNEL 1 |
990 | #define LISTEN_RAW 2 | 990 | #define LISTEN_RAW 2 |
991 | 991 | ||
992 | /* Values for client_config.state */ | 992 | /* Values for client_data.state */ |
993 | /* initial state: (re)start DHCP negotiation */ | 993 | /* initial state: (re)start DHCP negotiation */ |
994 | #define INIT_SELECTING 0 | 994 | #define INIT_SELECTING 0 |
995 | /* discover was sent, DHCPOFFER reply received */ | 995 | /* discover was sent, DHCPOFFER reply received */ |
@@ -1100,35 +1100,35 @@ static void change_listen_mode(int new_mode) | |||
1100 | : "none" | 1100 | : "none" |
1101 | ); | 1101 | ); |
1102 | 1102 | ||
1103 | client_config.listen_mode = new_mode; | 1103 | client_data.listen_mode = new_mode; |
1104 | if (client_config.sockfd >= 0) { | 1104 | if (client_data.sockfd >= 0) { |
1105 | close(client_config.sockfd); | 1105 | close(client_data.sockfd); |
1106 | client_config.sockfd = -1; | 1106 | client_data.sockfd = -1; |
1107 | } | 1107 | } |
1108 | if (new_mode == LISTEN_KERNEL) | 1108 | if (new_mode == LISTEN_KERNEL) |
1109 | client_config.sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface); | 1109 | client_data.sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_data.interface); |
1110 | else if (new_mode != LISTEN_NONE) | 1110 | else if (new_mode != LISTEN_NONE) |
1111 | client_config.sockfd = udhcp_raw_socket(client_config.ifindex); | 1111 | client_data.sockfd = udhcp_raw_socket(client_data.ifindex); |
1112 | /* else LISTEN_NONE: client_config.sockfd stays closed */ | 1112 | /* else LISTEN_NONE: client_data.sockfd stays closed */ |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | /* Called only on SIGUSR1 */ | 1115 | /* Called only on SIGUSR1 */ |
1116 | static void perform_renew(void) | 1116 | static void perform_renew(void) |
1117 | { | 1117 | { |
1118 | bb_info_msg("performing DHCP renew"); | 1118 | bb_info_msg("performing DHCP renew"); |
1119 | switch (client_config.state) { | 1119 | switch (client_data.state) { |
1120 | case BOUND: | 1120 | case BOUND: |
1121 | change_listen_mode(LISTEN_KERNEL); | 1121 | change_listen_mode(LISTEN_KERNEL); |
1122 | case RENEWING: | 1122 | case RENEWING: |
1123 | case REBINDING: | 1123 | case REBINDING: |
1124 | client_config.state = RENEW_REQUESTED; | 1124 | client_data.state = RENEW_REQUESTED; |
1125 | break; | 1125 | break; |
1126 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ | 1126 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ |
1127 | udhcp_run_script(NULL, "deconfig"); | 1127 | udhcp_run_script(NULL, "deconfig"); |
1128 | case REQUESTING: | 1128 | case REQUESTING: |
1129 | case RELEASED: | 1129 | case RELEASED: |
1130 | change_listen_mode(LISTEN_RAW); | 1130 | change_listen_mode(LISTEN_RAW); |
1131 | client_config.state = INIT_SELECTING; | 1131 | client_data.state = INIT_SELECTING; |
1132 | break; | 1132 | break; |
1133 | case INIT_SELECTING: | 1133 | case INIT_SELECTING: |
1134 | break; | 1134 | break; |
@@ -1141,10 +1141,10 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) | |||
1141 | struct in_addr temp_addr; | 1141 | struct in_addr temp_addr; |
1142 | 1142 | ||
1143 | /* send release packet */ | 1143 | /* send release packet */ |
1144 | if (client_config.state == BOUND | 1144 | if (client_data.state == BOUND |
1145 | || client_config.state == RENEWING | 1145 | || client_data.state == RENEWING |
1146 | || client_config.state == REBINDING | 1146 | || client_data.state == REBINDING |
1147 | || client_config.state == RENEW_REQUESTED | 1147 | || client_data.state == RENEW_REQUESTED |
1148 | ) { | 1148 | ) { |
1149 | temp_addr.s_addr = server_addr; | 1149 | temp_addr.s_addr = server_addr; |
1150 | strcpy(buffer, inet_ntoa(temp_addr)); | 1150 | strcpy(buffer, inet_ntoa(temp_addr)); |
@@ -1163,7 +1163,7 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) | |||
1163 | udhcp_run_script(NULL, "deconfig"); | 1163 | udhcp_run_script(NULL, "deconfig"); |
1164 | 1164 | ||
1165 | change_listen_mode(LISTEN_NONE); | 1165 | change_listen_mode(LISTEN_NONE); |
1166 | client_config.state = RELEASED; | 1166 | client_data.state = RELEASED; |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | static uint8_t* alloc_dhcp_option(int code, const char *str, int extra) | 1169 | static uint8_t* alloc_dhcp_option(int code, const char *str, int extra) |
@@ -1183,7 +1183,7 @@ static void client_background(void) | |||
1183 | bb_daemonize(0); | 1183 | bb_daemonize(0); |
1184 | logmode &= ~LOGMODE_STDIO; | 1184 | logmode &= ~LOGMODE_STDIO; |
1185 | /* rewrite pidfile, as our pid is different now */ | 1185 | /* rewrite pidfile, as our pid is different now */ |
1186 | write_pidfile(client_config.pidfile); | 1186 | write_pidfile(client_data.pidfile); |
1187 | } | 1187 | } |
1188 | #endif | 1188 | #endif |
1189 | 1189 | ||
@@ -1266,9 +1266,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1266 | /* Default options */ | 1266 | /* Default options */ |
1267 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) | 1267 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) |
1268 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) | 1268 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) |
1269 | client_config.interface = "eth0"; | 1269 | client_data.interface = "eth0"; |
1270 | client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; | 1270 | client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; |
1271 | client_config.sockfd = -1; | 1271 | client_data.sockfd = -1; |
1272 | str_V = "udhcp "BB_VER; | 1272 | str_V = "udhcp "BB_VER; |
1273 | 1273 | ||
1274 | /* Parse command line */ | 1274 | /* Parse command line */ |
@@ -1282,9 +1282,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1282 | "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */ | 1282 | "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */ |
1283 | , udhcpc_longopts | 1283 | , udhcpc_longopts |
1284 | , &str_V, &str_h, &str_h, &str_F | 1284 | , &str_V, &str_h, &str_h, &str_F |
1285 | , &client_config.interface, &client_config.pidfile /* i,p */ | 1285 | , &client_data.interface, &client_data.pidfile /* i,p */ |
1286 | , &str_r /* r */ | 1286 | , &str_r /* r */ |
1287 | , &client_config.script /* s */ | 1287 | , &client_data.script /* s */ |
1288 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ | 1288 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ |
1289 | , &list_O | 1289 | , &list_O |
1290 | , &list_x | 1290 | , &list_x |
@@ -1295,11 +1295,11 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1295 | if (opt & (OPT_h|OPT_H)) { | 1295 | if (opt & (OPT_h|OPT_H)) { |
1296 | //msg added 2011-11 | 1296 | //msg added 2011-11 |
1297 | bb_error_msg("option -h NAME is deprecated, use -x hostname:NAME"); | 1297 | bb_error_msg("option -h NAME is deprecated, use -x hostname:NAME"); |
1298 | client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0); | 1298 | client_data.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0); |
1299 | } | 1299 | } |
1300 | if (opt & OPT_F) { | 1300 | if (opt & OPT_F) { |
1301 | /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */ | 1301 | /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */ |
1302 | client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3); | 1302 | client_data.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3); |
1303 | /* Flag bits: 0000NEOS | 1303 | /* Flag bits: 0000NEOS |
1304 | * S: 1 = Client requests server to update A RR in DNS as well as PTR | 1304 | * S: 1 = Client requests server to update A RR in DNS as well as PTR |
1305 | * O: 1 = Server indicates to client that DNS has been updated regardless | 1305 | * O: 1 = Server indicates to client that DNS has been updated regardless |
@@ -1308,9 +1308,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1308 | * N: 1 = Client requests server to not update DNS (S must be 0 then) | 1308 | * N: 1 = Client requests server to not update DNS (S must be 0 then) |
1309 | * Two [0] bytes which follow are deprecated and must be 0. | 1309 | * Two [0] bytes which follow are deprecated and must be 0. |
1310 | */ | 1310 | */ |
1311 | client_config.fqdn[OPT_DATA + 0] = 0x1; | 1311 | client_data.fqdn[OPT_DATA + 0] = 0x1; |
1312 | /*client_config.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */ | 1312 | /*client_data.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */ |
1313 | /*client_config.fqdn[OPT_DATA + 2] = 0; */ | 1313 | /*client_data.fqdn[OPT_DATA + 2] = 0; */ |
1314 | } | 1314 | } |
1315 | if (opt & OPT_r) | 1315 | if (opt & OPT_r) |
1316 | requested_ip = inet_addr(str_r); | 1316 | requested_ip = inet_addr(str_r); |
@@ -1328,49 +1328,49 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1328 | n = udhcp_option_idx(optstr, dhcp_option_strings); | 1328 | n = udhcp_option_idx(optstr, dhcp_option_strings); |
1329 | n = dhcp_optflags[n].code; | 1329 | n = dhcp_optflags[n].code; |
1330 | } | 1330 | } |
1331 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 1331 | client_data.opt_mask[n >> 3] |= 1 << (n & 7); |
1332 | } | 1332 | } |
1333 | if (!(opt & OPT_o)) { | 1333 | if (!(opt & OPT_o)) { |
1334 | unsigned i, n; | 1334 | unsigned i, n; |
1335 | for (i = 0; (n = dhcp_optflags[i].code) != 0; i++) { | 1335 | for (i = 0; (n = dhcp_optflags[i].code) != 0; i++) { |
1336 | if (dhcp_optflags[i].flags & OPTION_REQ) { | 1336 | if (dhcp_optflags[i].flags & OPTION_REQ) { |
1337 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 1337 | client_data.opt_mask[n >> 3] |= 1 << (n & 7); |
1338 | } | 1338 | } |
1339 | } | 1339 | } |
1340 | } | 1340 | } |
1341 | while (list_x) { | 1341 | while (list_x) { |
1342 | char *optstr = xstrdup(llist_pop(&list_x)); | 1342 | char *optstr = xstrdup(llist_pop(&list_x)); |
1343 | udhcp_str2optset(optstr, &client_config.options, | 1343 | udhcp_str2optset(optstr, &client_data.options, |
1344 | dhcp_optflags, dhcp_option_strings, | 1344 | dhcp_optflags, dhcp_option_strings, |
1345 | /*dhcpv6:*/ 0 | 1345 | /*dhcpv6:*/ 0 |
1346 | ); | 1346 | ); |
1347 | free(optstr); | 1347 | free(optstr); |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | if (udhcp_read_interface(client_config.interface, | 1350 | if (udhcp_read_interface(client_data.interface, |
1351 | &client_config.ifindex, | 1351 | &client_data.ifindex, |
1352 | NULL, | 1352 | NULL, |
1353 | client_config.client_mac) | 1353 | client_data.client_mac) |
1354 | ) { | 1354 | ) { |
1355 | return 1; | 1355 | return 1; |
1356 | } | 1356 | } |
1357 | 1357 | ||
1358 | clientid_mac_ptr = NULL; | 1358 | clientid_mac_ptr = NULL; |
1359 | if (!(opt & OPT_C) && !udhcp_find_option(client_config.options, DHCP_CLIENT_ID)) { | 1359 | if (!(opt & OPT_C) && !udhcp_find_option(client_data.options, DHCP_CLIENT_ID)) { |
1360 | /* not suppressed and not set, set the default client ID */ | 1360 | /* not suppressed and not set, set the default client ID */ |
1361 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7); | 1361 | client_data.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7); |
1362 | client_config.clientid[OPT_DATA] = 1; /* type: ethernet */ | 1362 | client_data.clientid[OPT_DATA] = 1; /* type: ethernet */ |
1363 | clientid_mac_ptr = client_config.clientid + OPT_DATA+1; | 1363 | clientid_mac_ptr = client_data.clientid + OPT_DATA+1; |
1364 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); | 1364 | memcpy(clientid_mac_ptr, client_data.client_mac, 6); |
1365 | } | 1365 | } |
1366 | if (str_V[0] != '\0') { | 1366 | if (str_V[0] != '\0') { |
1367 | // can drop -V, str_V, client_config.vendorclass, | 1367 | // can drop -V, str_V, client_data.vendorclass, |
1368 | // but need to add "vendor" to the list of recognized | 1368 | // but need to add "vendor" to the list of recognized |
1369 | // string opts for this to work; | 1369 | // string opts for this to work; |
1370 | // and need to tweak add_client_options() too... | 1370 | // and need to tweak add_client_options() too... |
1371 | // ...so the question is, should we? | 1371 | // ...so the question is, should we? |
1372 | //bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR"); | 1372 | //bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR"); |
1373 | client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0); | 1373 | client_data.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0); |
1374 | } | 1374 | } |
1375 | 1375 | ||
1376 | #if !BB_MMU | 1376 | #if !BB_MMU |
@@ -1388,7 +1388,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1388 | /* Make sure fd 0,1,2 are open */ | 1388 | /* Make sure fd 0,1,2 are open */ |
1389 | bb_sanitize_stdio(); | 1389 | bb_sanitize_stdio(); |
1390 | /* Create pidfile */ | 1390 | /* Create pidfile */ |
1391 | write_pidfile(client_config.pidfile); | 1391 | write_pidfile(client_data.pidfile); |
1392 | /* Goes to stdout (unless NOMMU) and possibly syslog */ | 1392 | /* Goes to stdout (unless NOMMU) and possibly syslog */ |
1393 | bb_info_msg("started, v"BB_VER); | 1393 | bb_info_msg("started, v"BB_VER); |
1394 | /* Set up the signal pipe */ | 1394 | /* Set up the signal pipe */ |
@@ -1396,7 +1396,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1396 | /* We want random_xid to be random... */ | 1396 | /* We want random_xid to be random... */ |
1397 | srand(monotonic_us()); | 1397 | srand(monotonic_us()); |
1398 | 1398 | ||
1399 | client_config.state = INIT_SELECTING; | 1399 | client_data.state = INIT_SELECTING; |
1400 | udhcp_run_script(NULL, "deconfig"); | 1400 | udhcp_run_script(NULL, "deconfig"); |
1401 | change_listen_mode(LISTEN_RAW); | 1401 | change_listen_mode(LISTEN_RAW); |
1402 | packet_num = 0; | 1402 | packet_num = 0; |
@@ -1414,16 +1414,16 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1414 | /* silence "uninitialized!" warning */ | 1414 | /* silence "uninitialized!" warning */ |
1415 | unsigned timestamp_before_wait = timestamp_before_wait; | 1415 | unsigned timestamp_before_wait = timestamp_before_wait; |
1416 | 1416 | ||
1417 | //bb_error_msg("sockfd:%d, listen_mode:%d", client_config.sockfd, client_config.listen_mode); | 1417 | //bb_error_msg("sockfd:%d, listen_mode:%d", client_data.sockfd, client_data.listen_mode); |
1418 | 1418 | ||
1419 | /* Was opening raw or udp socket here | 1419 | /* Was opening raw or udp socket here |
1420 | * if (client_config.listen_mode != LISTEN_NONE && client_config.sockfd < 0), | 1420 | * if (client_data.listen_mode != LISTEN_NONE && client_data.sockfd < 0), |
1421 | * but on fast network renew responses return faster | 1421 | * but on fast network renew responses return faster |
1422 | * than we open sockets. Thus this code is moved | 1422 | * than we open sockets. Thus this code is moved |
1423 | * to change_listen_mode(). Thus we open listen socket | 1423 | * to change_listen_mode(). Thus we open listen socket |
1424 | * BEFORE we send renew request (see "case BOUND:"). */ | 1424 | * BEFORE we send renew request (see "case BOUND:"). */ |
1425 | 1425 | ||
1426 | udhcp_sp_fd_set(pfds, client_config.sockfd); | 1426 | udhcp_sp_fd_set(pfds, client_data.sockfd); |
1427 | 1427 | ||
1428 | tv = timeout - already_waited_sec; | 1428 | tv = timeout - already_waited_sec; |
1429 | retval = 0; | 1429 | retval = 0; |
@@ -1452,20 +1452,20 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1452 | * or if the status of the bridge changed). | 1452 | * or if the status of the bridge changed). |
1453 | * Refresh ifindex and client_mac: | 1453 | * Refresh ifindex and client_mac: |
1454 | */ | 1454 | */ |
1455 | if (udhcp_read_interface(client_config.interface, | 1455 | if (udhcp_read_interface(client_data.interface, |
1456 | &client_config.ifindex, | 1456 | &client_data.ifindex, |
1457 | NULL, | 1457 | NULL, |
1458 | client_config.client_mac) | 1458 | client_data.client_mac) |
1459 | ) { | 1459 | ) { |
1460 | goto ret0; /* iface is gone? */ | 1460 | goto ret0; /* iface is gone? */ |
1461 | } | 1461 | } |
1462 | if (clientid_mac_ptr) | 1462 | if (clientid_mac_ptr) |
1463 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); | 1463 | memcpy(clientid_mac_ptr, client_data.client_mac, 6); |
1464 | 1464 | ||
1465 | /* We will restart the wait in any case */ | 1465 | /* We will restart the wait in any case */ |
1466 | already_waited_sec = 0; | 1466 | already_waited_sec = 0; |
1467 | 1467 | ||
1468 | switch (client_config.state) { | 1468 | switch (client_data.state) { |
1469 | case INIT_SELECTING: | 1469 | case INIT_SELECTING: |
1470 | if (!discover_retries || packet_num < discover_retries) { | 1470 | if (!discover_retries || packet_num < discover_retries) { |
1471 | if (packet_num == 0) | 1471 | if (packet_num == 0) |
@@ -1514,12 +1514,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1514 | * were seen in the wild. Treat them similarly | 1514 | * were seen in the wild. Treat them similarly |
1515 | * to "no response to discover" case */ | 1515 | * to "no response to discover" case */ |
1516 | change_listen_mode(LISTEN_RAW); | 1516 | change_listen_mode(LISTEN_RAW); |
1517 | client_config.state = INIT_SELECTING; | 1517 | client_data.state = INIT_SELECTING; |
1518 | goto leasefail; | 1518 | goto leasefail; |
1519 | case BOUND: | 1519 | case BOUND: |
1520 | /* 1/2 lease passed, enter renewing state */ | 1520 | /* 1/2 lease passed, enter renewing state */ |
1521 | client_config.state = RENEWING; | 1521 | client_data.state = RENEWING; |
1522 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1522 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1523 | change_listen_mode(LISTEN_KERNEL); | 1523 | change_listen_mode(LISTEN_KERNEL); |
1524 | log1("entering renew state"); | 1524 | log1("entering renew state"); |
1525 | /* fall right through */ | 1525 | /* fall right through */ |
@@ -1555,7 +1555,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1555 | } | 1555 | } |
1556 | /* Timed out or error, enter rebinding state */ | 1556 | /* Timed out or error, enter rebinding state */ |
1557 | log1("entering rebinding state"); | 1557 | log1("entering rebinding state"); |
1558 | client_config.state = REBINDING; | 1558 | client_data.state = REBINDING; |
1559 | /* fall right through */ | 1559 | /* fall right through */ |
1560 | case REBINDING: | 1560 | case REBINDING: |
1561 | /* Switch to bcast receive */ | 1561 | /* Switch to bcast receive */ |
@@ -1571,8 +1571,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1571 | /* Timed out, enter init state */ | 1571 | /* Timed out, enter init state */ |
1572 | bb_info_msg("lease lost, entering init state"); | 1572 | bb_info_msg("lease lost, entering init state"); |
1573 | udhcp_run_script(NULL, "deconfig"); | 1573 | udhcp_run_script(NULL, "deconfig"); |
1574 | client_config.state = INIT_SELECTING; | 1574 | client_data.state = INIT_SELECTING; |
1575 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1575 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1576 | /*timeout = 0; - already is */ | 1576 | /*timeout = 0; - already is */ |
1577 | packet_num = 0; | 1577 | packet_num = 0; |
1578 | continue; | 1578 | continue; |
@@ -1588,10 +1588,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1588 | /* Is it a signal? */ | 1588 | /* Is it a signal? */ |
1589 | switch (udhcp_sp_read()) { | 1589 | switch (udhcp_sp_read()) { |
1590 | case SIGUSR1: | 1590 | case SIGUSR1: |
1591 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1591 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1592 | already_waited_sec = 0; | 1592 | already_waited_sec = 0; |
1593 | perform_renew(); | 1593 | perform_renew(); |
1594 | if (client_config.state == RENEW_REQUESTED) { | 1594 | if (client_data.state == RENEW_REQUESTED) { |
1595 | /* We might be either on the same network | 1595 | /* We might be either on the same network |
1596 | * (in which case renew might work), | 1596 | * (in which case renew might work), |
1597 | * or we might be on a completely different one | 1597 | * or we might be on a completely different one |
@@ -1626,15 +1626,15 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1626 | int len; | 1626 | int len; |
1627 | 1627 | ||
1628 | /* A packet is ready, read it */ | 1628 | /* A packet is ready, read it */ |
1629 | if (client_config.listen_mode == LISTEN_KERNEL) | 1629 | if (client_data.listen_mode == LISTEN_KERNEL) |
1630 | len = udhcp_recv_kernel_packet(&packet, client_config.sockfd); | 1630 | len = udhcp_recv_kernel_packet(&packet, client_data.sockfd); |
1631 | else | 1631 | else |
1632 | len = udhcp_recv_raw_packet(&packet, client_config.sockfd); | 1632 | len = udhcp_recv_raw_packet(&packet, client_data.sockfd); |
1633 | if (len == -1) { | 1633 | if (len == -1) { |
1634 | /* Error is severe, reopen socket */ | 1634 | /* Error is severe, reopen socket */ |
1635 | bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); | 1635 | bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); |
1636 | sleep(discover_timeout); /* 3 seconds by default */ | 1636 | sleep(discover_timeout); /* 3 seconds by default */ |
1637 | change_listen_mode(client_config.listen_mode); /* just close and reopen */ | 1637 | change_listen_mode(client_data.listen_mode); /* just close and reopen */ |
1638 | } | 1638 | } |
1639 | /* If this packet will turn out to be unrelated/bogus, | 1639 | /* If this packet will turn out to be unrelated/bogus, |
1640 | * we will go back and wait for next one. | 1640 | * we will go back and wait for next one. |
@@ -1652,7 +1652,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1652 | 1652 | ||
1653 | /* Ignore packets that aren't for us */ | 1653 | /* Ignore packets that aren't for us */ |
1654 | if (packet.hlen != 6 | 1654 | if (packet.hlen != 6 |
1655 | || memcmp(packet.chaddr, client_config.client_mac, 6) != 0 | 1655 | || memcmp(packet.chaddr, client_data.client_mac, 6) != 0 |
1656 | ) { | 1656 | ) { |
1657 | //FIXME: need to also check that last 10 bytes are zero | 1657 | //FIXME: need to also check that last 10 bytes are zero |
1658 | log1("chaddr does not match, ignoring packet"); // log2? | 1658 | log1("chaddr does not match, ignoring packet"); // log2? |
@@ -1665,7 +1665,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1665 | continue; | 1665 | continue; |
1666 | } | 1666 | } |
1667 | 1667 | ||
1668 | switch (client_config.state) { | 1668 | switch (client_data.state) { |
1669 | case INIT_SELECTING: | 1669 | case INIT_SELECTING: |
1670 | /* Must be a DHCPOFFER */ | 1670 | /* Must be a DHCPOFFER */ |
1671 | if (*message == DHCPOFFER) { | 1671 | if (*message == DHCPOFFER) { |
@@ -1707,7 +1707,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1707 | requested_ip = packet.yiaddr; | 1707 | requested_ip = packet.yiaddr; |
1708 | 1708 | ||
1709 | /* enter requesting state */ | 1709 | /* enter requesting state */ |
1710 | client_config.state = REQUESTING; | 1710 | client_data.state = REQUESTING; |
1711 | timeout = 0; | 1711 | timeout = 0; |
1712 | packet_num = 0; | 1712 | packet_num = 0; |
1713 | already_waited_sec = 0; | 1713 | already_waited_sec = 0; |
@@ -1754,19 +1754,19 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1754 | if (!arpping(packet.yiaddr, | 1754 | if (!arpping(packet.yiaddr, |
1755 | NULL, | 1755 | NULL, |
1756 | (uint32_t) 0, | 1756 | (uint32_t) 0, |
1757 | client_config.client_mac, | 1757 | client_data.client_mac, |
1758 | client_config.interface, | 1758 | client_data.interface, |
1759 | arpping_ms) | 1759 | arpping_ms) |
1760 | ) { | 1760 | ) { |
1761 | bb_info_msg("offered address is in use " | 1761 | bb_info_msg("offered address is in use " |
1762 | "(got ARP reply), declining"); | 1762 | "(got ARP reply), declining"); |
1763 | send_decline(/*xid,*/ server_addr, packet.yiaddr); | 1763 | send_decline(/*xid,*/ server_addr, packet.yiaddr); |
1764 | 1764 | ||
1765 | if (client_config.state != REQUESTING) | 1765 | if (client_data.state != REQUESTING) |
1766 | udhcp_run_script(NULL, "deconfig"); | 1766 | udhcp_run_script(NULL, "deconfig"); |
1767 | change_listen_mode(LISTEN_RAW); | 1767 | change_listen_mode(LISTEN_RAW); |
1768 | client_config.state = INIT_SELECTING; | 1768 | client_data.state = INIT_SELECTING; |
1769 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1769 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1770 | requested_ip = 0; | 1770 | requested_ip = 0; |
1771 | timeout = tryagain_timeout; | 1771 | timeout = tryagain_timeout; |
1772 | packet_num = 0; | 1772 | packet_num = 0; |
@@ -1782,7 +1782,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1782 | requested_ip = packet.yiaddr; | 1782 | requested_ip = packet.yiaddr; |
1783 | 1783 | ||
1784 | start = monotonic_sec(); | 1784 | start = monotonic_sec(); |
1785 | udhcp_run_script(&packet, client_config.state == REQUESTING ? "bound" : "renew"); | 1785 | udhcp_run_script(&packet, client_data.state == REQUESTING ? "bound" : "renew"); |
1786 | already_waited_sec = (unsigned)monotonic_sec() - start; | 1786 | already_waited_sec = (unsigned)monotonic_sec() - start; |
1787 | timeout = lease_seconds / 2; | 1787 | timeout = lease_seconds / 2; |
1788 | if ((unsigned)timeout < already_waited_sec) { | 1788 | if ((unsigned)timeout < already_waited_sec) { |
@@ -1790,7 +1790,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1790 | timeout = already_waited_sec = 0; | 1790 | timeout = already_waited_sec = 0; |
1791 | } | 1791 | } |
1792 | 1792 | ||
1793 | client_config.state = BOUND; | 1793 | client_data.state = BOUND; |
1794 | change_listen_mode(LISTEN_NONE); | 1794 | change_listen_mode(LISTEN_NONE); |
1795 | if (opt & OPT_q) { /* quit after lease */ | 1795 | if (opt & OPT_q) { /* quit after lease */ |
1796 | goto ret0; | 1796 | goto ret0; |
@@ -1832,12 +1832,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1832 | /* return to init state */ | 1832 | /* return to init state */ |
1833 | bb_info_msg("received %s", "DHCP NAK"); | 1833 | bb_info_msg("received %s", "DHCP NAK"); |
1834 | udhcp_run_script(&packet, "nak"); | 1834 | udhcp_run_script(&packet, "nak"); |
1835 | if (client_config.state != REQUESTING) | 1835 | if (client_data.state != REQUESTING) |
1836 | udhcp_run_script(NULL, "deconfig"); | 1836 | udhcp_run_script(NULL, "deconfig"); |
1837 | change_listen_mode(LISTEN_RAW); | 1837 | change_listen_mode(LISTEN_RAW); |
1838 | sleep(3); /* avoid excessive network traffic */ | 1838 | sleep(3); /* avoid excessive network traffic */ |
1839 | client_config.state = INIT_SELECTING; | 1839 | client_data.state = INIT_SELECTING; |
1840 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1840 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1841 | requested_ip = 0; | 1841 | requested_ip = 0; |
1842 | timeout = 0; | 1842 | timeout = 0; |
1843 | packet_num = 0; | 1843 | packet_num = 0; |
@@ -1855,7 +1855,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1855 | perform_release(server_addr, requested_ip); | 1855 | perform_release(server_addr, requested_ip); |
1856 | retval = 0; | 1856 | retval = 0; |
1857 | ret: | 1857 | ret: |
1858 | /*if (client_config.pidfile) - remove_pidfile has its own check */ | 1858 | /*if (client_data.pidfile) - remove_pidfile has its own check */ |
1859 | remove_pidfile(client_config.pidfile); | 1859 | remove_pidfile(client_data.pidfile); |
1860 | return retval; | 1860 | return retval; |
1861 | } | 1861 | } |