diff options
author | Ron Yorston <rmy@pobox.com> | 2019-05-27 11:56:52 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-05-27 11:56:52 +0100 |
commit | a61949401890cbb33a9d6c4571b51c53460ad438 (patch) | |
tree | 64dedaddb89896d5b1670a421af123670ca2120b /networking | |
parent | 03a7b173605a890e1db5177ecd5b8dd591081c41 (diff) | |
parent | bcb1fc3e6ca6fe902610f507eaf9b0b58a5c583a (diff) | |
download | busybox-w32-a61949401890cbb33a9d6c4571b51c53460ad438.tar.gz busybox-w32-a61949401890cbb33a9d6c4571b51c53460ad438.tar.bz2 busybox-w32-a61949401890cbb33a9d6c4571b51c53460ad438.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'networking')
29 files changed, 509 insertions, 416 deletions
diff --git a/networking/dnsd.c b/networking/dnsd.c index 37a80309d..f2c6bddc6 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -133,7 +133,7 @@ static struct dns_entry *parse_conf_file(const char *fileconf) | |||
133 | } | 133 | } |
134 | 134 | ||
135 | if (OPT_verbose) | 135 | if (OPT_verbose) |
136 | bb_error_msg("name:%s, ip:%s", token[0], token[1]); | 136 | bb_info_msg("name:%s, ip:%s", token[0], token[1]); |
137 | 137 | ||
138 | /* sizeof(*m) includes 1 byte for m->name[0] */ | 138 | /* sizeof(*m) includes 1 byte for m->name[0] */ |
139 | m = xzalloc(sizeof(*m) + strlen(token[0]) + 1); | 139 | m = xzalloc(sizeof(*m) + strlen(token[0]) + 1); |
@@ -438,7 +438,7 @@ static int process_packet(struct dns_entry *conf_data, | |||
438 | answstr = table_lookup(conf_data, type, query_string); | 438 | answstr = table_lookup(conf_data, type, query_string); |
439 | #if DEBUG | 439 | #if DEBUG |
440 | /* Shows lengths instead of dots, unusable for !DEBUG */ | 440 | /* Shows lengths instead of dots, unusable for !DEBUG */ |
441 | bb_error_msg("'%s'->'%s'", query_string, answstr); | 441 | bb_info_msg("'%s'->'%s'", query_string, answstr); |
442 | #endif | 442 | #endif |
443 | outr_rlen = 4; | 443 | outr_rlen = 4; |
444 | if (answstr && type == htons(REQ_PTR)) { | 444 | if (answstr && type == htons(REQ_PTR)) { |
@@ -474,7 +474,7 @@ static int process_packet(struct dns_entry *conf_data, | |||
474 | * RCODE = 0 "success" | 474 | * RCODE = 0 "success" |
475 | */ | 475 | */ |
476 | if (OPT_verbose) | 476 | if (OPT_verbose) |
477 | bb_error_msg("returning positive reply"); | 477 | bb_info_msg("returning positive reply"); |
478 | outr_flags = htons(0x8000 | 0x0400 | 0); | 478 | outr_flags = htons(0x8000 | 0x0400 | 0); |
479 | /* we have one answer */ | 479 | /* we have one answer */ |
480 | head->nansw = htons(1); | 480 | head->nansw = htons(1); |
@@ -539,7 +539,7 @@ int dnsd_main(int argc UNUSED_PARAM, char **argv) | |||
539 | 539 | ||
540 | { | 540 | { |
541 | char *p = xmalloc_sockaddr2dotted(&lsa->u.sa); | 541 | char *p = xmalloc_sockaddr2dotted(&lsa->u.sa); |
542 | bb_error_msg("accepting UDP packets on %s", p); | 542 | bb_info_msg("accepting UDP packets on %s", p); |
543 | free(p); | 543 | free(p); |
544 | } | 544 | } |
545 | 545 | ||
@@ -557,7 +557,7 @@ int dnsd_main(int argc UNUSED_PARAM, char **argv) | |||
557 | continue; | 557 | continue; |
558 | } | 558 | } |
559 | if (OPT_verbose) | 559 | if (OPT_verbose) |
560 | bb_error_msg("got UDP packet"); | 560 | bb_info_msg("got UDP packet"); |
561 | buf[r] = '\0'; /* paranoia */ | 561 | buf[r] = '\0'; /* paranoia */ |
562 | r = process_packet(conf_data, conf_ttl, buf); | 562 | r = process_packet(conf_data, conf_ttl, buf); |
563 | if (r <= 0) | 563 | if (r <= 0) |
diff --git a/networking/ifplugd.c b/networking/ifplugd.c index 026ff1cc8..1426709cb 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c | |||
@@ -326,7 +326,7 @@ static int run_script(const char *action) | |||
326 | char *argv[5]; | 326 | char *argv[5]; |
327 | int r; | 327 | int r; |
328 | 328 | ||
329 | bb_error_msg("executing '%s %s %s'", G.script_name, G.iface, action); | 329 | bb_info_msg("executing '%s %s %s'", G.script_name, G.iface, action); |
330 | 330 | ||
331 | argv[0] = (char*) G.script_name; | 331 | argv[0] = (char*) G.script_name; |
332 | argv[1] = (char*) G.iface; | 332 | argv[1] = (char*) G.iface; |
@@ -345,7 +345,7 @@ static int run_script(const char *action) | |||
345 | bb_unsetenv_and_free(env_PREVIOUS); | 345 | bb_unsetenv_and_free(env_PREVIOUS); |
346 | bb_unsetenv_and_free(env_CURRENT); | 346 | bb_unsetenv_and_free(env_CURRENT); |
347 | 347 | ||
348 | bb_error_msg("exit code: %d", r & 0xff); | 348 | bb_info_msg("exit code: %d", r & 0xff); |
349 | return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r; | 349 | return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r; |
350 | } | 350 | } |
351 | 351 | ||
@@ -365,7 +365,7 @@ static void up_iface(void) | |||
365 | if (!(ifrequest.ifr_flags & IFF_UP)) { | 365 | if (!(ifrequest.ifr_flags & IFF_UP)) { |
366 | ifrequest.ifr_flags |= IFF_UP; | 366 | ifrequest.ifr_flags |= IFF_UP; |
367 | /* Let user know we mess up with interface */ | 367 | /* Let user know we mess up with interface */ |
368 | bb_error_msg("upping interface"); | 368 | bb_info_msg("upping interface"); |
369 | if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "setting interface flags") < 0) { | 369 | if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "setting interface flags") < 0) { |
370 | if (errno != ENODEV && errno != EADDRNOTAVAIL) | 370 | if (errno != ENODEV && errno != EADDRNOTAVAIL) |
371 | xfunc_die(); | 371 | xfunc_die(); |
@@ -414,7 +414,7 @@ static void maybe_up_new_iface(void) | |||
414 | (uint8_t)(ifrequest.ifr_hwaddr.sa_data[5])); | 414 | (uint8_t)(ifrequest.ifr_hwaddr.sa_data[5])); |
415 | } | 415 | } |
416 | 416 | ||
417 | bb_error_msg("using interface %s%s with driver<%s> (version: %s)", | 417 | bb_info_msg("using interface %s%s with driver<%s> (version: %s)", |
418 | G.iface, buf, driver_info.driver, driver_info.version); | 418 | G.iface, buf, driver_info.driver, driver_info.version); |
419 | } | 419 | } |
420 | #endif | 420 | #endif |
@@ -447,7 +447,7 @@ static smallint detect_link(void) | |||
447 | logmode = sv_logmode; | 447 | logmode = sv_logmode; |
448 | if (status != IFSTATUS_ERR) { | 448 | if (status != IFSTATUS_ERR) { |
449 | G.api_method_num = i; | 449 | G.api_method_num = i; |
450 | bb_error_msg("using %s detection mode", method_table[i].name); | 450 | bb_info_msg("using %s detection mode", method_table[i].name); |
451 | break; | 451 | break; |
452 | } | 452 | } |
453 | } | 453 | } |
@@ -632,7 +632,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
632 | /* | (1 << SIGCHLD) - run_script does not use it anymore */ | 632 | /* | (1 << SIGCHLD) - run_script does not use it anymore */ |
633 | , record_signo); | 633 | , record_signo); |
634 | 634 | ||
635 | bb_error_msg("started: %s", bb_banner); | 635 | bb_info_msg("started: %s", bb_banner); |
636 | 636 | ||
637 | if (opts & FLAG_MONITOR) { | 637 | if (opts & FLAG_MONITOR) { |
638 | struct ifreq ifrequest; | 638 | struct ifreq ifrequest; |
@@ -649,7 +649,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
649 | iface_status_str = strstatus(iface_status); | 649 | iface_status_str = strstatus(iface_status); |
650 | 650 | ||
651 | if (opts & FLAG_MONITOR) { | 651 | if (opts & FLAG_MONITOR) { |
652 | bb_error_msg("interface %s", | 652 | bb_info_msg("interface %s", |
653 | G.iface_exists ? "exists" | 653 | G.iface_exists ? "exists" |
654 | : "doesn't exist, waiting"); | 654 | : "doesn't exist, waiting"); |
655 | } | 655 | } |
@@ -657,7 +657,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
657 | * by potentially lying that it really exists */ | 657 | * by potentially lying that it really exists */ |
658 | 658 | ||
659 | if (G.iface_exists) { | 659 | if (G.iface_exists) { |
660 | bb_error_msg("link is %s", iface_status_str); | 660 | bb_info_msg("link is %s", iface_status_str); |
661 | } | 661 | } |
662 | 662 | ||
663 | if ((!(opts & FLAG_NO_STARTUP) | 663 | if ((!(opts & FLAG_NO_STARTUP) |
@@ -712,7 +712,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
712 | if (G.iface_exists < 0) /* error */ | 712 | if (G.iface_exists < 0) /* error */ |
713 | goto exiting; | 713 | goto exiting; |
714 | if (iface_exists_old != G.iface_exists) { | 714 | if (iface_exists_old != G.iface_exists) { |
715 | bb_error_msg("interface %sappeared", | 715 | bb_info_msg("interface %sappeared", |
716 | G.iface_exists ? "" : "dis"); | 716 | G.iface_exists ? "" : "dis"); |
717 | if (G.iface_exists) | 717 | if (G.iface_exists) |
718 | maybe_up_new_iface(); | 718 | maybe_up_new_iface(); |
@@ -730,7 +730,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
730 | iface_status_str = strstatus(iface_status); | 730 | iface_status_str = strstatus(iface_status); |
731 | 731 | ||
732 | if (iface_status_old != iface_status) { | 732 | if (iface_status_old != iface_status) { |
733 | bb_error_msg("link is %s", iface_status_str); | 733 | bb_info_msg("link is %s", iface_status_str); |
734 | 734 | ||
735 | if (delay_time) { | 735 | if (delay_time) { |
736 | /* link restored its old status before | 736 | /* link restored its old status before |
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 8a6efc976..5327b0979 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -1177,8 +1177,15 @@ static int doit(char *str) | |||
1177 | 1177 | ||
1178 | static int execute_all(struct interface_defn_t *ifd, const char *opt) | 1178 | static int execute_all(struct interface_defn_t *ifd, const char *opt) |
1179 | { | 1179 | { |
1180 | /* 'opt' is always short, the longest value is "post-down". | ||
1181 | * Can use on-stack buffer instead of xasprintf'ed one. | ||
1182 | */ | ||
1183 | char buf[sizeof("run-parts /etc/network/if-%s.d") | ||
1184 | + sizeof("post-down") | ||
1185 | /*paranoia:*/ + 8 | ||
1186 | ]; | ||
1180 | int i; | 1187 | int i; |
1181 | char *buf; | 1188 | |
1182 | for (i = 0; i < ifd->n_options; i++) { | 1189 | for (i = 0; i < ifd->n_options; i++) { |
1183 | if (strcmp(ifd->option[i].name, opt) == 0) { | 1190 | if (strcmp(ifd->option[i].name, opt) == 0) { |
1184 | if (!doit(ifd->option[i].value)) { | 1191 | if (!doit(ifd->option[i].value)) { |
@@ -1192,8 +1199,7 @@ static int execute_all(struct interface_defn_t *ifd, const char *opt) | |||
1192 | * complains, and this message _is_ annoyingly visible. | 1199 | * complains, and this message _is_ annoyingly visible. |
1193 | * Don't "fix" this (unless newer Debian does). | 1200 | * Don't "fix" this (unless newer Debian does). |
1194 | */ | 1201 | */ |
1195 | buf = xasprintf("run-parts /etc/network/if-%s.d", opt); | 1202 | sprintf(buf, "run-parts /etc/network/if-%s.d", opt); |
1196 | /* heh, we don't bother free'ing it */ | ||
1197 | return doit(buf); | 1203 | return doit(buf); |
1198 | } | 1204 | } |
1199 | 1205 | ||
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 8364f6a3e..7b7e0154b 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c | |||
@@ -23,6 +23,7 @@ | |||
23 | 23 | ||
24 | struct filter_t { | 24 | struct filter_t { |
25 | char *label; | 25 | char *label; |
26 | /* Flush cmd buf. If !NULL, print_addrinfo() constructs flush commands in it */ | ||
26 | char *flushb; | 27 | char *flushb; |
27 | struct rtnl_handle *rth; | 28 | struct rtnl_handle *rth; |
28 | int scope, scopemask; | 29 | int scope, scopemask; |
@@ -34,6 +35,8 @@ struct filter_t { | |||
34 | smallint showqueue; | 35 | smallint showqueue; |
35 | smallint oneline; | 36 | smallint oneline; |
36 | smallint up; | 37 | smallint up; |
38 | /* Misnomer. Does not mean "flushed something" */ | ||
39 | /* More like "flush commands were constructed by print_addrinfo()" */ | ||
37 | smallint flushed; | 40 | smallint flushed; |
38 | inet_prefix pfx; | 41 | inet_prefix pfx; |
39 | } FIX_ALIASING; | 42 | } FIX_ALIASING; |
@@ -201,7 +204,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) | |||
201 | 204 | ||
202 | static int flush_update(void) | 205 | static int flush_update(void) |
203 | { | 206 | { |
204 | if (rtnl_send(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { | 207 | if (rtnl_send_check(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { |
205 | bb_perror_msg("can't send flush request"); | 208 | bb_perror_msg("can't send flush request"); |
206 | return -1; | 209 | return -1; |
207 | } | 210 | } |
@@ -510,7 +513,6 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) | |||
510 | xrtnl_dump_filter(&rth, store_nlmsg, &ainfo); | 513 | xrtnl_dump_filter(&rth, store_nlmsg, &ainfo); |
511 | } | 514 | } |
512 | 515 | ||
513 | |||
514 | if (G_filter.family && G_filter.family != AF_PACKET) { | 516 | if (G_filter.family && G_filter.family != AF_PACKET) { |
515 | struct nlmsg_list **lp; | 517 | struct nlmsg_list **lp; |
516 | lp = &linfo; | 518 | lp = &linfo; |
@@ -571,8 +573,8 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) | |||
571 | 573 | ||
572 | for (l = linfo; l; l = l->next) { | 574 | for (l = linfo; l; l = l->next) { |
573 | if ((oneline && G_filter.family != AF_PACKET) | 575 | if ((oneline && G_filter.family != AF_PACKET) |
574 | || (print_linkinfo(&l->h) == 0) | ||
575 | /* ^^^^^^^^^ "ip -oneline a" does not print link info */ | 576 | /* ^^^^^^^^^ "ip -oneline a" does not print link info */ |
577 | || (print_linkinfo(&l->h) == 0) | ||
576 | ) { | 578 | ) { |
577 | struct ifinfomsg *ifi = NLMSG_DATA(&l->h); | 579 | struct ifinfomsg *ifi = NLMSG_DATA(&l->h); |
578 | if (G_filter.family != AF_PACKET) | 580 | if (G_filter.family != AF_PACKET) |
diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c index f572414e9..984dd4bdd 100644 --- a/networking/libiproute/ipneigh.c +++ b/networking/libiproute/ipneigh.c | |||
@@ -32,7 +32,10 @@ struct filter_t { | |||
32 | int state; | 32 | int state; |
33 | int unused_only; | 33 | int unused_only; |
34 | inet_prefix pfx; | 34 | inet_prefix pfx; |
35 | /* Misnomer. Does not mean "flushed N something" */ | ||
36 | /* More like "no_of_flush_commands_constructed_by_print_neigh()" */ | ||
35 | int flushed; | 37 | int flushed; |
38 | /* Flush cmd buf. If !NULL, print_neigh() constructs flush commands in it */ | ||
36 | char *flushb; | 39 | char *flushb; |
37 | int flushp; | 40 | int flushp; |
38 | int flushe; | 41 | int flushe; |
@@ -45,7 +48,7 @@ typedef struct filter_t filter_t; | |||
45 | 48 | ||
46 | static int flush_update(void) | 49 | static int flush_update(void) |
47 | { | 50 | { |
48 | if (rtnl_send(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { | 51 | if (rtnl_send_check(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { |
49 | bb_perror_msg("can't send flush request"); | 52 | bb_perror_msg("can't send flush request"); |
50 | return -1; | 53 | return -1; |
51 | } | 54 | } |
@@ -299,9 +302,7 @@ static int FAST_FUNC ipneigh_list_or_flush(char **argv, int flush) | |||
299 | G_filter.rth = &rth; | 302 | G_filter.rth = &rth; |
300 | 303 | ||
301 | while (round < MAX_ROUNDS) { | 304 | while (round < MAX_ROUNDS) { |
302 | if (xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETNEIGH) < 0) { | 305 | xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETNEIGH); |
303 | bb_perror_msg_and_die("can't send dump request"); | ||
304 | } | ||
305 | G_filter.flushed = 0; | 306 | G_filter.flushed = 0; |
306 | if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { | 307 | if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { |
307 | bb_perror_msg_and_die("flush terminated"); | 308 | bb_perror_msg_and_die("flush terminated"); |
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 2a8610ea6..b11078ed5 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c | |||
@@ -26,7 +26,10 @@ | |||
26 | 26 | ||
27 | struct filter_t { | 27 | struct filter_t { |
28 | int tb; | 28 | int tb; |
29 | /* Misnomer. Does not mean "flushed something" */ | ||
30 | /* More like "flush commands were constructed by print_route()" */ | ||
29 | smallint flushed; | 31 | smallint flushed; |
32 | /* Flush cmd buf. If !NULL, print_route() constructs flush commands in it */ | ||
30 | char *flushb; | 33 | char *flushb; |
31 | int flushp; | 34 | int flushp; |
32 | int flushe; | 35 | int flushe; |
@@ -53,7 +56,7 @@ typedef struct filter_t filter_t; | |||
53 | 56 | ||
54 | static int flush_update(void) | 57 | static int flush_update(void) |
55 | { | 58 | { |
56 | if (rtnl_send(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { | 59 | if (rtnl_send_check(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { |
57 | bb_perror_msg("can't send flush request"); | 60 | bb_perror_msg("can't send flush request"); |
58 | return -1; | 61 | return -1; |
59 | } | 62 | } |
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index 40955fcae..b0d4166ac 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c | |||
@@ -34,7 +34,7 @@ void FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) | |||
34 | rth->seq = time(NULL); | 34 | rth->seq = time(NULL); |
35 | } | 35 | } |
36 | 36 | ||
37 | int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) | 37 | void FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) |
38 | { | 38 | { |
39 | struct { | 39 | struct { |
40 | struct nlmsghdr nlh; | 40 | struct nlmsghdr nlh; |
@@ -48,18 +48,45 @@ int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int ty | |||
48 | req.nlh.nlmsg_seq = rth->dump = ++rth->seq; | 48 | req.nlh.nlmsg_seq = rth->dump = ++rth->seq; |
49 | req.g.rtgen_family = family; | 49 | req.g.rtgen_family = family; |
50 | 50 | ||
51 | return rtnl_send(rth, (void*)&req, sizeof(req)); | 51 | rtnl_send(rth, (void*)&req, sizeof(req)); |
52 | } | 52 | } |
53 | 53 | ||
54 | //TODO: pass rth->fd instead of full rth? | 54 | /* A version which checks for e.g. EPERM errors. |
55 | int FAST_FUNC rtnl_send(struct rtnl_handle *rth, char *buf, int len) | 55 | * Try: setuidgid 1:1 ip addr flush dev eth0 |
56 | */ | ||
57 | int FAST_FUNC rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len) | ||
56 | { | 58 | { |
57 | struct sockaddr_nl nladdr; | 59 | struct nlmsghdr *h; |
60 | int status; | ||
61 | char resp[1024]; | ||
58 | 62 | ||
59 | memset(&nladdr, 0, sizeof(nladdr)); | 63 | status = write(rth->fd, buf, len); |
60 | nladdr.nl_family = AF_NETLINK; | 64 | if (status < 0) |
65 | return status; | ||
66 | |||
67 | /* Check for immediate errors */ | ||
68 | status = recv(rth->fd, resp, sizeof(resp), MSG_DONTWAIT|MSG_PEEK); | ||
69 | if (status < 0) { | ||
70 | if (errno == EAGAIN) /* if no error, this happens */ | ||
71 | return 0; | ||
72 | return -1; | ||
73 | } | ||
61 | 74 | ||
62 | return xsendto(rth->fd, buf, len, (struct sockaddr*)&nladdr, sizeof(nladdr)); | 75 | for (h = (struct nlmsghdr *)resp; |
76 | NLMSG_OK(h, status); | ||
77 | h = NLMSG_NEXT(h, status) | ||
78 | ) { | ||
79 | if (h->nlmsg_type == NLMSG_ERROR) { | ||
80 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); | ||
81 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) | ||
82 | bb_error_msg("ERROR truncated"); | ||
83 | else | ||
84 | errno = -err->error; | ||
85 | return -1; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | return 0; | ||
63 | } | 90 | } |
64 | 91 | ||
65 | int FAST_FUNC rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) | 92 | int FAST_FUNC rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) |
diff --git a/networking/libiproute/libnetlink.h b/networking/libiproute/libnetlink.h index 51bee2d67..1b082e019 100644 --- a/networking/libiproute/libnetlink.h +++ b/networking/libiproute/libnetlink.h | |||
@@ -20,7 +20,7 @@ struct rtnl_handle { | |||
20 | 20 | ||
21 | extern void xrtnl_open(struct rtnl_handle *rth) FAST_FUNC; | 21 | extern void xrtnl_open(struct rtnl_handle *rth) FAST_FUNC; |
22 | #define rtnl_close(rth) (close((rth)->fd)) | 22 | #define rtnl_close(rth) (close((rth)->fd)) |
23 | extern int xrtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) FAST_FUNC; | 23 | extern void xrtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) FAST_FUNC; |
24 | extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) FAST_FUNC; | 24 | extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) FAST_FUNC; |
25 | extern int xrtnl_dump_filter(struct rtnl_handle *rth, | 25 | extern int xrtnl_dump_filter(struct rtnl_handle *rth, |
26 | int (*filter)(const struct sockaddr_nl*, struct nlmsghdr *n, void*) FAST_FUNC, | 26 | int (*filter)(const struct sockaddr_nl*, struct nlmsghdr *n, void*) FAST_FUNC, |
@@ -34,8 +34,23 @@ extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, | |||
34 | int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), | 34 | int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), |
35 | void *jarg) FAST_FUNC; | 35 | void *jarg) FAST_FUNC; |
36 | 36 | ||
37 | extern int rtnl_send(struct rtnl_handle *rth, char *buf, int) FAST_FUNC; | 37 | int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len) FAST_FUNC; |
38 | //TODO: pass rth->fd instead of full rth? | ||
39 | static ALWAYS_INLINE void rtnl_send(struct rtnl_handle *rth, const void *buf, int len) | ||
40 | { | ||
41 | // Used to be: | ||
42 | //struct sockaddr_nl nladdr; | ||
43 | //memset(&nladdr, 0, sizeof(nladdr)); | ||
44 | //nladdr.nl_family = AF_NETLINK; | ||
45 | //return xsendto(rth->fd, buf, len, (struct sockaddr*)&nladdr, sizeof(nladdr)); | ||
38 | 46 | ||
47 | // iproute2-4.2.0 simplified the above to: | ||
48 | //return send(rth->fd, buf, len, 0); | ||
49 | |||
50 | // We are using even shorter: | ||
51 | xwrite(rth->fd, buf, len); | ||
52 | // and convert to void, inline. | ||
53 | } | ||
39 | 54 | ||
40 | extern int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data) FAST_FUNC; | 55 | extern int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data) FAST_FUNC; |
41 | extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen) FAST_FUNC; | 56 | extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen) FAST_FUNC; |
diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c index 7d46221ac..611e0a2c9 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c | |||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | /* Please conditionalize exotic protocols on CONFIG_something */ | 16 | /* Please conditionalize exotic protocols on CONFIG_something */ |
17 | 17 | ||
18 | static const uint16_t llproto_ids[] = { | 18 | static const uint16_t llproto_ids[] ALIGN2 = { |
19 | #define __PF(f,n) ETH_P_##f, | 19 | #define __PF(f,n) ETH_P_##f, |
20 | __PF(LOOP,loop) | 20 | __PF(LOOP,loop) |
21 | __PF(PUP,pup) | 21 | __PF(PUP,pup) |
diff --git a/networking/ntpd.c b/networking/ntpd.c index 027cfe783..cd6da2b38 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -1130,7 +1130,7 @@ step_time(double offset) | |||
1130 | } | 1130 | } |
1131 | tval = tvn.tv_sec; | 1131 | tval = tvn.tv_sec; |
1132 | strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval); | 1132 | strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval); |
1133 | bb_error_msg("setting time to %s.%06u (offset %+fs)", buf, (unsigned)tvn.tv_usec, offset); | 1133 | bb_info_msg("setting time to %s.%06u (offset %+fs)", buf, (unsigned)tvn.tv_usec, offset); |
1134 | //maybe? G.FREQHOLD_cnt = 0; | 1134 | //maybe? G.FREQHOLD_cnt = 0; |
1135 | 1135 | ||
1136 | /* Correct various fields which contain time-relative values: */ | 1136 | /* Correct various fields which contain time-relative values: */ |
@@ -2132,7 +2132,7 @@ recv_and_process_peer_pkt(peer_t *p) | |||
2132 | 2132 | ||
2133 | p->reachable_bits |= 1; | 2133 | p->reachable_bits |= 1; |
2134 | if ((MAX_VERBOSE && G.verbose) || (option_mask32 & OPT_w)) { | 2134 | if ((MAX_VERBOSE && G.verbose) || (option_mask32 & OPT_w)) { |
2135 | bb_error_msg("reply from %s: offset:%+f delay:%f status:0x%02x strat:%d refid:0x%08x rootdelay:%f reach:0x%02x", | 2135 | bb_info_msg("reply from %s: offset:%+f delay:%f status:0x%02x strat:%d refid:0x%08x rootdelay:%f reach:0x%02x", |
2136 | p->p_dotted, | 2136 | p->p_dotted, |
2137 | offset, | 2137 | offset, |
2138 | p->p_raw_delay, | 2138 | p->p_raw_delay, |
diff --git a/networking/tc.c b/networking/tc.c index 3e9808328..2e1078d31 100644 --- a/networking/tc.c +++ b/networking/tc.c | |||
@@ -124,7 +124,8 @@ static char* print_tc_classid(uint32_t cid) | |||
124 | } | 124 | } |
125 | 125 | ||
126 | /* Get a qdisc handle. Return 0 on success, !0 otherwise. */ | 126 | /* Get a qdisc handle. Return 0 on success, !0 otherwise. */ |
127 | static int get_qdisc_handle(uint32_t *h, const char *str) { | 127 | static int get_qdisc_handle(uint32_t *h, const char *str) |
128 | { | ||
128 | uint32_t maj; | 129 | uint32_t maj; |
129 | char *p; | 130 | char *p; |
130 | 131 | ||
@@ -143,7 +144,8 @@ static int get_qdisc_handle(uint32_t *h, const char *str) { | |||
143 | } | 144 | } |
144 | 145 | ||
145 | /* Get class ID. Return 0 on success, !0 otherwise. */ | 146 | /* Get class ID. Return 0 on success, !0 otherwise. */ |
146 | static int get_tc_classid(uint32_t *h, const char *str) { | 147 | static int get_tc_classid(uint32_t *h, const char *str) |
148 | { | ||
147 | uint32_t maj, min; | 149 | uint32_t maj, min; |
148 | char *p; | 150 | char *p; |
149 | 151 | ||
diff --git a/networking/tftp.c b/networking/tftp.c index d20d4ca4b..5ebd22105 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -245,7 +245,7 @@ static int tftp_blksize_check(const char *blksize_str, int maxsize) | |||
245 | return -1; | 245 | return -1; |
246 | } | 246 | } |
247 | # if ENABLE_TFTP_DEBUG | 247 | # if ENABLE_TFTP_DEBUG |
248 | bb_error_msg("using blksize %u", blksize); | 248 | bb_info_msg("using blksize %u", blksize); |
249 | # endif | 249 | # endif |
250 | return blksize; | 250 | return blksize; |
251 | } | 251 | } |
diff --git a/networking/tls.c b/networking/tls.c index d2385efe8..d1a0204ed 100644 --- a/networking/tls.c +++ b/networking/tls.c | |||
@@ -1393,12 +1393,12 @@ static void find_key_in_der_cert(tls_state_t *tls, uint8_t *der, int len) | |||
1393 | /* enter subjectPublicKeyInfo */ | 1393 | /* enter subjectPublicKeyInfo */ |
1394 | der = enter_der_item(der, &end); | 1394 | der = enter_der_item(der, &end); |
1395 | { /* check subjectPublicKeyInfo.algorithm */ | 1395 | { /* check subjectPublicKeyInfo.algorithm */ |
1396 | static const uint8_t OID_RSA_KEY_ALG[] = { | 1396 | static const uint8_t OID_RSA_KEY_ALG[] ALIGN1 = { |
1397 | 0x30,0x0d, // SEQ 13 bytes | 1397 | 0x30,0x0d, // SEQ 13 bytes |
1398 | 0x06,0x09, 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01, //OID_RSA_KEY_ALG 42.134.72.134.247.13.1.1.1 | 1398 | 0x06,0x09, 0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01, //OID_RSA_KEY_ALG 42.134.72.134.247.13.1.1.1 |
1399 | //0x05,0x00, // NULL | 1399 | //0x05,0x00, // NULL |
1400 | }; | 1400 | }; |
1401 | static const uint8_t OID_ECDSA_KEY_ALG[] = { | 1401 | static const uint8_t OID_ECDSA_KEY_ALG[] ALIGN1 = { |
1402 | 0x30,0x13, // SEQ 0x13 bytes | 1402 | 0x30,0x13, // SEQ 0x13 bytes |
1403 | 0x06,0x07, 0x2a,0x86,0x48,0xce,0x3d,0x02,0x01, //OID_ECDSA_KEY_ALG 42.134.72.206.61.2.1 | 1403 | 0x06,0x07, 0x2a,0x86,0x48,0xce,0x3d,0x02,0x01, //OID_ECDSA_KEY_ALG 42.134.72.206.61.2.1 |
1404 | //allow any curve code for now... | 1404 | //allow any curve code for now... |
@@ -2089,7 +2089,7 @@ static void send_client_key_exchange(tls_state_t *tls) | |||
2089 | } | 2089 | } |
2090 | } | 2090 | } |
2091 | 2091 | ||
2092 | static const uint8_t rec_CHANGE_CIPHER_SPEC[] = { | 2092 | static const uint8_t rec_CHANGE_CIPHER_SPEC[] ALIGN1 = { |
2093 | RECORD_TYPE_CHANGE_CIPHER_SPEC, TLS_MAJ, TLS_MIN, 00, 01, | 2093 | RECORD_TYPE_CHANGE_CIPHER_SPEC, TLS_MAJ, TLS_MIN, 00, 01, |
2094 | 01 | 2094 | 01 |
2095 | }; | 2095 | }; |
diff --git a/networking/tls_aes.c b/networking/tls_aes.c index cf6b5fe3d..5400ad9b5 100644 --- a/networking/tls_aes.c +++ b/networking/tls_aes.c | |||
@@ -130,7 +130,7 @@ static int KeyExpansion(uint32_t *RoundKey, const void *key, unsigned key_len) | |||
130 | // The round constant word array, Rcon[i], contains the values given by | 130 | // The round constant word array, Rcon[i], contains the values given by |
131 | // x to th e power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8). | 131 | // x to th e power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8). |
132 | // Note that i starts at 2, not 0. | 132 | // Note that i starts at 2, not 0. |
133 | static const uint8_t Rcon[] = { | 133 | static const uint8_t Rcon[] ALIGN1 = { |
134 | 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 | 134 | 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 |
135 | //..... 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,... | 135 | //..... 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,... |
136 | // but aes256 only uses values up to 0x36 | 136 | // but aes256 only uses values up to 0x36 |
diff --git a/networking/tls_pstm_montgomery_reduce.c b/networking/tls_pstm_montgomery_reduce.c index d46e2aa2b..20f9c26d5 100644 --- a/networking/tls_pstm_montgomery_reduce.c +++ b/networking/tls_pstm_montgomery_reduce.c | |||
@@ -73,7 +73,7 @@ asm( \ | |||
73 | "movl %%edx,%1 \n\t" \ | 73 | "movl %%edx,%1 \n\t" \ |
74 | :"=g"(_c[LO]), "=r"(cy) \ | 74 | :"=g"(_c[LO]), "=r"(cy) \ |
75 | :"0"(_c[LO]), "1"(cy), "g"(mu), "g"(*tmpm++) \ | 75 | :"0"(_c[LO]), "1"(cy), "g"(mu), "g"(*tmpm++) \ |
76 | : "%eax", "%edx", "%cc") | 76 | : "%eax", "%edx", "cc") |
77 | 77 | ||
78 | #define PROPCARRY \ | 78 | #define PROPCARRY \ |
79 | asm( \ | 79 | asm( \ |
@@ -82,7 +82,7 @@ asm( \ | |||
82 | "movzbl %%al,%1 \n\t" \ | 82 | "movzbl %%al,%1 \n\t" \ |
83 | :"=g"(_c[LO]), "=r"(cy) \ | 83 | :"=g"(_c[LO]), "=r"(cy) \ |
84 | :"0"(_c[LO]), "1"(cy) \ | 84 | :"0"(_c[LO]), "1"(cy) \ |
85 | : "%eax", "%cc") | 85 | : "%eax", "cc") |
86 | 86 | ||
87 | /******************************************************************************/ | 87 | /******************************************************************************/ |
88 | #elif defined(PSTM_X86_64) | 88 | #elif defined(PSTM_X86_64) |
@@ -235,7 +235,7 @@ asm( \ | |||
235 | " STR r0,%1 \n\t" \ | 235 | " STR r0,%1 \n\t" \ |
236 | :"=r"(cy),"=m"(_c[0])\ | 236 | :"=r"(cy),"=m"(_c[0])\ |
237 | :"0"(cy),"r"(mu),"r"(*tmpm++),"m"(_c[0])\ | 237 | :"0"(cy),"r"(mu),"r"(*tmpm++),"m"(_c[0])\ |
238 | :"r0","%cc"); | 238 | :"r0","cc"); |
239 | #define PROPCARRY \ | 239 | #define PROPCARRY \ |
240 | asm( \ | 240 | asm( \ |
241 | " LDR r0,%1 \n\t" \ | 241 | " LDR r0,%1 \n\t" \ |
@@ -246,7 +246,7 @@ asm( \ | |||
246 | " MOVCC %0,#0 \n\t" \ | 246 | " MOVCC %0,#0 \n\t" \ |
247 | :"=r"(cy),"=m"(_c[0])\ | 247 | :"=r"(cy),"=m"(_c[0])\ |
248 | :"0"(cy),"m"(_c[0])\ | 248 | :"0"(cy),"m"(_c[0])\ |
249 | :"r0","%cc"); | 249 | :"r0","cc"); |
250 | #else /* Non-Thumb2 code */ | 250 | #else /* Non-Thumb2 code */ |
251 | //#pragma message ("Using 32 bit ARM Assembly Optimizations") | 251 | //#pragma message ("Using 32 bit ARM Assembly Optimizations") |
252 | #define INNERMUL \ | 252 | #define INNERMUL \ |
@@ -259,7 +259,7 @@ asm( \ | |||
259 | " STR r0,%1 \n\t" \ | 259 | " STR r0,%1 \n\t" \ |
260 | :"=r"(cy),"=m"(_c[0])\ | 260 | :"=r"(cy),"=m"(_c[0])\ |
261 | :"0"(cy),"r"(mu),"r"(*tmpm++),"m"(_c[0])\ | 261 | :"0"(cy),"r"(mu),"r"(*tmpm++),"m"(_c[0])\ |
262 | :"r0","%cc"); | 262 | :"r0","cc"); |
263 | #define PROPCARRY \ | 263 | #define PROPCARRY \ |
264 | asm( \ | 264 | asm( \ |
265 | " LDR r0,%1 \n\t" \ | 265 | " LDR r0,%1 \n\t" \ |
@@ -269,7 +269,7 @@ asm( \ | |||
269 | " MOVCC %0,#0 \n\t" \ | 269 | " MOVCC %0,#0 \n\t" \ |
270 | :"=r"(cy),"=m"(_c[0])\ | 270 | :"=r"(cy),"=m"(_c[0])\ |
271 | :"0"(cy),"m"(_c[0])\ | 271 | :"0"(cy),"m"(_c[0])\ |
272 | :"r0","%cc"); | 272 | :"r0","cc"); |
273 | #endif /* __thumb2__ */ | 273 | #endif /* __thumb2__ */ |
274 | 274 | ||
275 | 275 | ||
diff --git a/networking/tls_pstm_mul_comba.c b/networking/tls_pstm_mul_comba.c index ac4fcc3ef..af50358e5 100644 --- a/networking/tls_pstm_mul_comba.c +++ b/networking/tls_pstm_mul_comba.c | |||
@@ -85,7 +85,7 @@ asm( \ | |||
85 | "addl %%eax,%0 \n\t" \ | 85 | "addl %%eax,%0 \n\t" \ |
86 | "adcl %%edx,%1 \n\t" \ | 86 | "adcl %%edx,%1 \n\t" \ |
87 | "adcl $0,%2 \n\t" \ | 87 | "adcl $0,%2 \n\t" \ |
88 | :"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i), "m"(j) :"%eax","%edx","%cc"); | 88 | :"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i), "m"(j) :"%eax","%edx","cc"); |
89 | //bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build | 89 | //bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build |
90 | 90 | ||
91 | /******************************************************************************/ | 91 | /******************************************************************************/ |
@@ -155,7 +155,7 @@ asm( \ | |||
155 | " ADDS %0,%0,r0 \n\t" \ | 155 | " ADDS %0,%0,r0 \n\t" \ |
156 | " ADCS %1,%1,r1 \n\t" \ | 156 | " ADCS %1,%1,r1 \n\t" \ |
157 | " ADC %2,%2,#0 \n\t" \ | 157 | " ADC %2,%2,#0 \n\t" \ |
158 | :"=r"(c0), "=r"(c1), "=r"(c2) : "0"(c0), "1"(c1), "2"(c2), "r"(i), "r"(j) : "r0", "r1", "%cc"); | 158 | :"=r"(c0), "=r"(c1), "=r"(c2) : "0"(c0), "1"(c1), "2"(c2), "r"(i), "r"(j) : "r0", "r1", "cc"); |
159 | 159 | ||
160 | /******************************************************************************/ | 160 | /******************************************************************************/ |
161 | #elif defined(PSTM_MIPS) | 161 | #elif defined(PSTM_MIPS) |
diff --git a/networking/tls_pstm_sqr_comba.c b/networking/tls_pstm_sqr_comba.c index 8604132d6..a4d421b89 100644 --- a/networking/tls_pstm_sqr_comba.c +++ b/networking/tls_pstm_sqr_comba.c | |||
@@ -78,7 +78,7 @@ asm( \ | |||
78 | "addl %%eax,%0 \n\t" \ | 78 | "addl %%eax,%0 \n\t" \ |
79 | "adcl %%edx,%1 \n\t" \ | 79 | "adcl %%edx,%1 \n\t" \ |
80 | "adcl $0,%2 \n\t" \ | 80 | "adcl $0,%2 \n\t" \ |
81 | :"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i) :"%eax","%edx","%cc"); | 81 | :"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i) :"%eax","%edx","cc"); |
82 | //bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build | 82 | //bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build |
83 | 83 | ||
84 | #define SQRADD2(i, j) \ | 84 | #define SQRADD2(i, j) \ |
@@ -91,7 +91,7 @@ asm( \ | |||
91 | "addl %%eax,%0 \n\t" \ | 91 | "addl %%eax,%0 \n\t" \ |
92 | "adcl %%edx,%1 \n\t" \ | 92 | "adcl %%edx,%1 \n\t" \ |
93 | "adcl $0,%2 \n\t" \ | 93 | "adcl $0,%2 \n\t" \ |
94 | :"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i), "m"(j) :"%eax","%edx","%cc"); | 94 | :"=rm"(c0), "=rm"(c1), "=rm"(c2): "0"(c0), "1"(c1), "2"(c2), "m"(i), "m"(j) :"%eax","%edx","cc"); |
95 | //bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build | 95 | //bbox: ^^^ replaced "=r" with "=rm": %ebx is not available on shared build |
96 | 96 | ||
97 | #define SQRADDSC(i, j) \ | 97 | #define SQRADDSC(i, j) \ |
@@ -101,7 +101,7 @@ asm( \ | |||
101 | "movl %%eax,%0 \n\t" \ | 101 | "movl %%eax,%0 \n\t" \ |
102 | "movl %%edx,%1 \n\t" \ | 102 | "movl %%edx,%1 \n\t" \ |
103 | "xorl %2,%2 \n\t" \ | 103 | "xorl %2,%2 \n\t" \ |
104 | :"=r"(sc0), "=r"(sc1), "=r"(sc2): "0"(sc0), "1"(sc1), "2"(sc2), "g"(i), "g"(j) :"%eax","%edx","%cc"); | 104 | :"=r"(sc0), "=r"(sc1), "=r"(sc2): "0"(sc0), "1"(sc1), "2"(sc2), "g"(i), "g"(j) :"%eax","%edx","cc"); |
105 | 105 | ||
106 | #define SQRADDAC(i, j) \ | 106 | #define SQRADDAC(i, j) \ |
107 | asm( \ | 107 | asm( \ |
@@ -110,7 +110,7 @@ asm( \ | |||
110 | "addl %%eax,%0 \n\t" \ | 110 | "addl %%eax,%0 \n\t" \ |
111 | "adcl %%edx,%1 \n\t" \ | 111 | "adcl %%edx,%1 \n\t" \ |
112 | "adcl $0,%2 \n\t" \ | 112 | "adcl $0,%2 \n\t" \ |
113 | :"=r"(sc0), "=r"(sc1), "=r"(sc2): "0"(sc0), "1"(sc1), "2"(sc2), "g"(i), "g"(j) :"%eax","%edx","%cc"); | 113 | :"=r"(sc0), "=r"(sc1), "=r"(sc2): "0"(sc0), "1"(sc1), "2"(sc2), "g"(i), "g"(j) :"%eax","%edx","cc"); |
114 | 114 | ||
115 | #define SQRADDDB \ | 115 | #define SQRADDDB \ |
116 | asm( \ | 116 | asm( \ |
@@ -120,7 +120,7 @@ asm( \ | |||
120 | "addl %6,%0 \n\t" \ | 120 | "addl %6,%0 \n\t" \ |
121 | "adcl %7,%1 \n\t" \ | 121 | "adcl %7,%1 \n\t" \ |
122 | "adcl %8,%2 \n\t" \ | 122 | "adcl %8,%2 \n\t" \ |
123 | :"=r"(c0), "=r"(c1), "=r"(c2) : "0"(c0), "1"(c1), "2"(c2), "r"(sc0), "r"(sc1), "r"(sc2) : "%cc"); | 123 | :"=r"(c0), "=r"(c1), "=r"(c2) : "0"(c0), "1"(c1), "2"(c2), "r"(sc0), "r"(sc1), "r"(sc2) : "cc"); |
124 | 124 | ||
125 | /******************************************************************************/ | 125 | /******************************************************************************/ |
126 | #elif defined(PSTM_X86_64) | 126 | #elif defined(PSTM_X86_64) |
@@ -223,7 +223,7 @@ asm( \ | |||
223 | " ADDS %0,%0,r0 \n\t" \ | 223 | " ADDS %0,%0,r0 \n\t" \ |
224 | " ADCS %1,%1,r1 \n\t" \ | 224 | " ADCS %1,%1,r1 \n\t" \ |
225 | " ADC %2,%2,#0 \n\t" \ | 225 | " ADC %2,%2,#0 \n\t" \ |
226 | :"=r"(c0), "=r"(c1), "=r"(c2) : "0"(c0), "1"(c1), "2"(c2), "r"(i) : "r0", "r1", "%cc"); | 226 | :"=r"(c0), "=r"(c1), "=r"(c2) : "0"(c0), "1"(c1), "2"(c2), "r"(i) : "r0", "r1", "cc"); |
227 | 227 | ||
228 | /* for squaring some of the terms are doubled... */ | 228 | /* for squaring some of the terms are doubled... */ |
229 | #define SQRADD2(i, j) \ | 229 | #define SQRADD2(i, j) \ |
@@ -235,13 +235,13 @@ asm( \ | |||
235 | " ADDS %0,%0,r0 \n\t" \ | 235 | " ADDS %0,%0,r0 \n\t" \ |
236 | " ADCS %1,%1,r1 \n\t" \ | 236 | " ADCS %1,%1,r1 \n\t" \ |
237 | " ADC %2,%2,#0 \n\t" \ | 237 | " ADC %2,%2,#0 \n\t" \ |
238 | :"=r"(c0), "=r"(c1), "=r"(c2) : "0"(c0), "1"(c1), "2"(c2), "r"(i), "r"(j) : "r0", "r1", "%cc"); | 238 | :"=r"(c0), "=r"(c1), "=r"(c2) : "0"(c0), "1"(c1), "2"(c2), "r"(i), "r"(j) : "r0", "r1", "cc"); |
239 | 239 | ||
240 | #define SQRADDSC(i, j) \ | 240 | #define SQRADDSC(i, j) \ |
241 | asm( \ | 241 | asm( \ |
242 | " UMULL %0,%1,%6,%7 \n\t" \ | 242 | " UMULL %0,%1,%6,%7 \n\t" \ |
243 | " SUB %2,%2,%2 \n\t" \ | 243 | " SUB %2,%2,%2 \n\t" \ |
244 | :"=r"(sc0), "=r"(sc1), "=r"(sc2) : "0"(sc0), "1"(sc1), "2"(sc2), "r"(i), "r"(j) : "%cc"); | 244 | :"=r"(sc0), "=r"(sc1), "=r"(sc2) : "0"(sc0), "1"(sc1), "2"(sc2), "r"(i), "r"(j) : "cc"); |
245 | 245 | ||
246 | #define SQRADDAC(i, j) \ | 246 | #define SQRADDAC(i, j) \ |
247 | asm( \ | 247 | asm( \ |
@@ -249,7 +249,7 @@ asm( \ | |||
249 | " ADDS %0,%0,r0 \n\t" \ | 249 | " ADDS %0,%0,r0 \n\t" \ |
250 | " ADCS %1,%1,r1 \n\t" \ | 250 | " ADCS %1,%1,r1 \n\t" \ |
251 | " ADC %2,%2,#0 \n\t" \ | 251 | " ADC %2,%2,#0 \n\t" \ |
252 | :"=r"(sc0), "=r"(sc1), "=r"(sc2) : "0"(sc0), "1"(sc1), "2"(sc2), "r"(i), "r"(j) : "r0", "r1", "%cc"); | 252 | :"=r"(sc0), "=r"(sc1), "=r"(sc2) : "0"(sc0), "1"(sc1), "2"(sc2), "r"(i), "r"(j) : "r0", "r1", "cc"); |
253 | 253 | ||
254 | #define SQRADDDB \ | 254 | #define SQRADDDB \ |
255 | asm( \ | 255 | asm( \ |
@@ -259,7 +259,7 @@ asm( \ | |||
259 | " ADDS %0,%0,%3 \n\t" \ | 259 | " ADDS %0,%0,%3 \n\t" \ |
260 | " ADCS %1,%1,%4 \n\t" \ | 260 | " ADCS %1,%1,%4 \n\t" \ |
261 | " ADC %2,%2,%5 \n\t" \ | 261 | " ADC %2,%2,%5 \n\t" \ |
262 | :"=r"(c0), "=r"(c1), "=r"(c2) : "r"(sc0), "r"(sc1), "r"(sc2), "0"(c0), "1"(c1), "2"(c2) : "%cc"); | 262 | :"=r"(c0), "=r"(c1), "=r"(c2) : "r"(sc0), "r"(sc1), "r"(sc2), "0"(c0), "1"(c1), "2"(c2) : "cc"); |
263 | 263 | ||
264 | /******************************************************************************/ | 264 | /******************************************************************************/ |
265 | #elif defined(PSTM_MIPS) | 265 | #elif defined(PSTM_MIPS) |
@@ -330,7 +330,7 @@ asm( \ | |||
330 | " mflo %0 \n\t" \ | 330 | " mflo %0 \n\t" \ |
331 | " mfhi %1 \n\t" \ | 331 | " mfhi %1 \n\t" \ |
332 | " xor %2,%2,%2 \n\t" \ | 332 | " xor %2,%2,%2 \n\t" \ |
333 | :"=r"(sc0), "=r"(sc1), "=r"(sc2):"0"(sc0), "1"(sc1), "2"(sc2), "r"(i),"r"(j) : "%cc"); | 333 | :"=r"(sc0), "=r"(sc1), "=r"(sc2):"0"(sc0), "1"(sc1), "2"(sc2), "r"(i),"r"(j) : "cc"); |
334 | 334 | ||
335 | #define SQRADDAC(i, j) \ | 335 | #define SQRADDAC(i, j) \ |
336 | asm( \ | 336 | asm( \ |
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 59cf723ee..62ad248ce 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -191,7 +191,7 @@ static void log_option(const char *pfx, const uint8_t *opt) | |||
191 | if (dhcp_verbose >= 2) { | 191 | if (dhcp_verbose >= 2) { |
192 | char buf[256 * 2 + 2]; | 192 | char buf[256 * 2 + 2]; |
193 | *bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0'; | 193 | *bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0'; |
194 | bb_error_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf); | 194 | bb_info_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf); |
195 | } | 195 | } |
196 | } | 196 | } |
197 | #else | 197 | #else |
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 9d1f71aae..bba3d6037 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -40,7 +40,7 @@ struct dhcp_packet { | |||
40 | uint32_t yiaddr; /* 'your' (client) IP address */ | 40 | uint32_t yiaddr; /* 'your' (client) IP address */ |
41 | /* IP address of next server to use in bootstrap, returned in DHCPOFFER, DHCPACK by server */ | 41 | /* IP address of next server to use in bootstrap, returned in DHCPOFFER, DHCPACK by server */ |
42 | uint32_t siaddr_nip; | 42 | uint32_t siaddr_nip; |
43 | uint32_t gateway_nip; /* relay agent IP address */ | 43 | uint32_t gateway_nip; /* aka 'giaddr': relay agent IP address */ |
44 | uint8_t chaddr[16]; /* link-layer client hardware address (MAC) */ | 44 | uint8_t chaddr[16]; /* link-layer client hardware address (MAC) */ |
45 | uint8_t sname[64]; /* server host name (ASCIZ) */ | 45 | uint8_t sname[64]; /* server host name (ASCIZ) */ |
46 | uint8_t file[128]; /* boot file name (ASCIZ) */ | 46 | uint8_t file[128]; /* boot file name (ASCIZ) */ |
@@ -222,10 +222,9 @@ uint8_t *dname_enc(const uint8_t *cstr, int clen, const char *src, int *retlen) | |||
222 | #endif | 222 | #endif |
223 | struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code) FAST_FUNC; | 223 | struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code) FAST_FUNC; |
224 | 224 | ||
225 | |||
226 | // RFC 2131 Table 5: Fields and options used by DHCP clients | 225 | // RFC 2131 Table 5: Fields and options used by DHCP clients |
227 | // | 226 | // |
228 | // Fields 'hops', 'yiaddr', 'siaddr', 'giaddr' are always zero | 227 | // Fields 'hops', 'yiaddr', 'siaddr', 'giaddr' are always zero, 'chaddr' is always client's MAC |
229 | // | 228 | // |
230 | // Field DHCPDISCOVER DHCPINFORM DHCPREQUEST DHCPDECLINE DHCPRELEASE | 229 | // Field DHCPDISCOVER DHCPINFORM DHCPREQUEST DHCPDECLINE DHCPRELEASE |
231 | // ----- ------------ ------------ ----------- ----------- ----------- | 230 | // ----- ------------ ------------ ----------- ----------- ----------- |
@@ -234,56 +233,49 @@ struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code) | |||
234 | // 'secs' 0 or seconds since 0 or seconds since 0 or seconds since 0 0 | 233 | // 'secs' 0 or seconds since 0 or seconds since 0 or seconds since 0 0 |
235 | // DHCP process started DHCP process started DHCP process started | 234 | // DHCP process started DHCP process started DHCP process started |
236 | // 'flags' Set 'BROADCAST' Set 'BROADCAST' Set 'BROADCAST' 0 0 | 235 | // 'flags' Set 'BROADCAST' Set 'BROADCAST' Set 'BROADCAST' 0 0 |
237 | // flag if client flag if client flag if client | 236 | // flag if client needs flag if client needs flag if client needs |
238 | // requires broadcast requires broadcast requires broadcast | 237 | // broadcast reply broadcast reply broadcast reply |
239 | // reply reply reply | ||
240 | // 'ciaddr' 0 client's IP 0 or client's IP 0 client's IP | 238 | // 'ciaddr' 0 client's IP 0 or client's IP 0 client's IP |
241 | // (BOUND/RENEW/REBIND) | 239 | // (BOUND/RENEW/REBIND) |
242 | // 'chaddr' client's MAC client's MAC client's MAC client's MAC client's MAC | ||
243 | // 'sname' options or sname options or sname options or sname (unused) (unused) | 240 | // 'sname' options or sname options or sname options or sname (unused) (unused) |
244 | // 'file' options or file options or file options or file (unused) (unused) | 241 | // 'file' options or file options or file options or file (unused) (unused) |
245 | // 'options' options options options message type opt message type opt | 242 | // 'options' options options options message type opt message type opt |
246 | // | 243 | // |
247 | // Option DHCPDISCOVER DHCPINFORM DHCPREQUEST DHCPDECLINE DHCPRELEASE | 244 | // Option DHCPDISCOVER DHCPINFORM DHCPREQUEST DHCPDECLINE DHCPRELEASE |
248 | // ------ ------------ ---------- ----------- ----------- ----------- | 245 | // ------ ------------ ---------- ----------- ----------- ----------- |
249 | // Requested IP address MAY MUST NOT MUST (in MUST MUST NOT | 246 | // Requested IP address MAY MUST NOT MUST (in SELECTING MUST MUST NOT |
250 | // SELECTING or | 247 | // or INIT-REBOOT) |
251 | // INIT-REBOOT) | 248 | // MUST NOT (in BOUND |
252 | // MUST NOT (in | 249 | // or RENEWING) |
253 | // BOUND or | 250 | // IP address lease time MAY MUST NOT MAY MUST NOT MUST NOT |
254 | // RENEWING) | 251 | // Use 'file'/'sname' fields MAY MAY MAY MAY MAY |
255 | // IP address lease time MAY MUST NOT MAY MUST NOT MUST NOT | 252 | // Client identifier MAY MAY MAY MAY MAY |
256 | // Use 'file'/'sname' fields MAY MAY MAY MAY MAY | 253 | // Vendor class identifier MAY MAY MAY MUST NOT MUST NOT |
257 | // Client identifier MAY MAY MAY MAY MAY | 254 | // Server identifier MUST NOT MUST NOT MUST (after SELECTING) MUST MUST |
258 | // Vendor class identifier MAY MAY MAY MUST NOT MUST NOT | ||
259 | // Server identifier MUST NOT MUST NOT MUST (after MUST MUST | ||
260 | // SELECTING) | ||
261 | // MUST NOT (after | 255 | // MUST NOT (after |
262 | // INIT-REBOOT, | 256 | // INIT-REBOOT, BOUND, |
263 | // BOUND, RENEWING | 257 | // RENEWING or REBINDING) |
264 | // or REBINDING) | 258 | // Parameter request list MAY MAY MAY MUST NOT MUST NOT |
265 | // Parameter request list MAY MAY MAY MUST NOT MUST NOT | 259 | // Maximum message size MAY MAY MAY MUST NOT MUST NOT |
266 | // Maximum message size MAY MAY MAY MUST NOT MUST NOT | 260 | // Message SHOULD NOT SHOULD NOT SHOULD NOT SHOULD SHOULD |
267 | // Message SHOULD NOT SHOULD NOT SHOULD NOT SHOULD SHOULD | 261 | // Site-specific MAY MAY MAY MUST NOT MUST NOT |
268 | // Site-specific MAY MAY MAY MUST NOT MUST NOT | 262 | // All others MAY MAY MAY MUST NOT MUST NOT |
269 | // All others MAY MAY MAY MUST NOT MUST NOT | ||
270 | |||
271 | 263 | ||
272 | /*** Logging ***/ | 264 | /*** Logging ***/ |
273 | 265 | ||
274 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 | 266 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 |
275 | # define IF_UDHCP_VERBOSE(...) __VA_ARGS__ | 267 | # define IF_UDHCP_VERBOSE(...) __VA_ARGS__ |
276 | extern unsigned dhcp_verbose; | 268 | extern unsigned dhcp_verbose; |
277 | # define log1(...) do { if (dhcp_verbose >= 1) bb_error_msg(__VA_ARGS__); } while (0) | 269 | # define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0) |
278 | # if CONFIG_UDHCP_DEBUG >= 2 | 270 | # if CONFIG_UDHCP_DEBUG >= 2 |
279 | void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; | 271 | void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; |
280 | # define log2(...) do { if (dhcp_verbose >= 2) bb_error_msg(__VA_ARGS__); } while (0) | 272 | # define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0) |
281 | # else | 273 | # else |
282 | # define udhcp_dump_packet(...) ((void)0) | 274 | # define udhcp_dump_packet(...) ((void)0) |
283 | # define log2(...) ((void)0) | 275 | # define log2(...) ((void)0) |
284 | # endif | 276 | # endif |
285 | # if CONFIG_UDHCP_DEBUG >= 3 | 277 | # if CONFIG_UDHCP_DEBUG >= 3 |
286 | # define log3(...) do { if (dhcp_verbose >= 3) bb_error_msg(__VA_ARGS__); } while (0) | 278 | # define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0) |
287 | # else | 279 | # else |
288 | # define log3(...) ((void)0) | 280 | # define log3(...) ((void)0) |
289 | # endif | 281 | # endif |
diff --git a/networking/udhcp/d6_common.h b/networking/udhcp/d6_common.h index 2178cb9d6..dee2558e2 100644 --- a/networking/udhcp/d6_common.h +++ b/networking/udhcp/d6_common.h | |||
@@ -141,7 +141,7 @@ struct client6_data_t { | |||
141 | unsigned env_idx; | 141 | unsigned env_idx; |
142 | /* link-local IPv6 address */ | 142 | /* link-local IPv6 address */ |
143 | struct in6_addr ll_ip6; | 143 | struct in6_addr ll_ip6; |
144 | }; | 144 | } FIX_ALIASING; |
145 | 145 | ||
146 | #define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)])) | 146 | #define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)])) |
147 | 147 | ||
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 3562988fd..15e9f3924 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -63,7 +63,7 @@ | |||
63 | #include <netpacket/packet.h> | 63 | #include <netpacket/packet.h> |
64 | #include <linux/filter.h> | 64 | #include <linux/filter.h> |
65 | 65 | ||
66 | /* "struct client_config_t client_config" is in bb_common_bufsiz1 */ | 66 | /* "struct client_data_t client_data" is in bb_common_bufsiz1 */ |
67 | 67 | ||
68 | static const struct dhcp_optflag d6_optflags[] = { | 68 | static const struct dhcp_optflag d6_optflags[] = { |
69 | #if ENABLE_FEATURE_UDHCPC6_RFC3646 | 69 | #if ENABLE_FEATURE_UDHCPC6_RFC3646 |
@@ -427,7 +427,7 @@ static char **fill_envp(const uint8_t *option, const uint8_t *option_end) | |||
427 | client6_data.env_ptr = NULL; | 427 | client6_data.env_ptr = NULL; |
428 | client6_data.env_idx = 0; | 428 | client6_data.env_idx = 0; |
429 | 429 | ||
430 | *new_env() = xasprintf("interface=%s", client_config.interface); | 430 | *new_env() = xasprintf("interface=%s", client_data.interface); |
431 | 431 | ||
432 | if (option) | 432 | if (option) |
433 | option_to_env(option, option_end); | 433 | option_to_env(option, option_end); |
@@ -449,8 +449,8 @@ static void d6_run_script(const uint8_t *option, const uint8_t *option_end, | |||
449 | envp = fill_envp(option, option_end); | 449 | envp = fill_envp(option, option_end); |
450 | 450 | ||
451 | /* call script */ | 451 | /* call script */ |
452 | log1("executing %s %s", client_config.script, name); | 452 | log1("executing %s %s", client_data.script, name); |
453 | argv[0] = (char*) client_config.script; | 453 | argv[0] = (char*) client_data.script; |
454 | argv[1] = (char*) name; | 454 | argv[1] = (char*) name; |
455 | argv[2] = NULL; | 455 | argv[2] = NULL; |
456 | spawn_and_wait(argv); | 456 | spawn_and_wait(argv); |
@@ -486,7 +486,7 @@ static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid | |||
486 | packet->d6_xid32 = xid; | 486 | packet->d6_xid32 = xid; |
487 | packet->d6_msg_type = type; | 487 | packet->d6_msg_type = type; |
488 | 488 | ||
489 | clientid = (void*)client_config.clientid; | 489 | clientid = (void*)client_data.clientid; |
490 | return mempcpy(packet->d6_options, clientid, clientid->len + 2+2); | 490 | return mempcpy(packet->d6_options, clientid, clientid->len + 2+2); |
491 | } | 491 | } |
492 | 492 | ||
@@ -499,7 +499,7 @@ static uint8_t *add_d6_client_options(uint8_t *ptr) | |||
499 | 499 | ||
500 | ptr += 4; | 500 | ptr += 4; |
501 | for (option = 1; option < 256; option++) { | 501 | for (option = 1; option < 256; option++) { |
502 | if (client_config.opt_mask[option >> 3] & (1 << (option & 7))) { | 502 | if (client_data.opt_mask[option >> 3] & (1 << (option & 7))) { |
503 | ptr[0] = (option >> 8); | 503 | ptr[0] = (option >> 8); |
504 | ptr[1] = option; | 504 | ptr[1] = option; |
505 | ptr += 2; | 505 | ptr += 2; |
@@ -518,7 +518,7 @@ static uint8_t *add_d6_client_options(uint8_t *ptr) | |||
518 | ptr = mempcpy(ptr, &opt_fqdn_req, sizeof(opt_fqdn_req)); | 518 | ptr = mempcpy(ptr, &opt_fqdn_req, sizeof(opt_fqdn_req)); |
519 | #endif | 519 | #endif |
520 | /* Add -x options if any */ | 520 | /* Add -x options if any */ |
521 | curr = client_config.options; | 521 | curr = client_data.options; |
522 | while (curr) { | 522 | while (curr) { |
523 | len = (curr->data[D6_OPT_LEN] << 8) | curr->data[D6_OPT_LEN + 1]; | 523 | len = (curr->data[D6_OPT_LEN] << 8) | curr->data[D6_OPT_LEN + 1]; |
524 | ptr = mempcpy(ptr, curr->data, D6_OPT_DATA + len); | 524 | ptr = mempcpy(ptr, curr->data, D6_OPT_DATA + len); |
@@ -528,7 +528,7 @@ static uint8_t *add_d6_client_options(uint8_t *ptr) | |||
528 | return ptr; | 528 | return ptr; |
529 | } | 529 | } |
530 | 530 | ||
531 | static int d6_mcast_from_client_config_ifindex(struct d6_packet *packet, uint8_t *end) | 531 | static int d6_mcast_from_client_data_ifindex(struct d6_packet *packet, uint8_t *end) |
532 | { | 532 | { |
533 | /* FF02::1:2 is "All_DHCP_Relay_Agents_and_Servers" address */ | 533 | /* FF02::1:2 is "All_DHCP_Relay_Agents_and_Servers" address */ |
534 | static const uint8_t FF02__1_2[16] = { | 534 | static const uint8_t FF02__1_2[16] = { |
@@ -540,7 +540,7 @@ static int d6_mcast_from_client_config_ifindex(struct d6_packet *packet, uint8_t | |||
540 | packet, (end - (uint8_t*) packet), | 540 | packet, (end - (uint8_t*) packet), |
541 | /*src*/ &client6_data.ll_ip6, CLIENT_PORT6, | 541 | /*src*/ &client6_data.ll_ip6, CLIENT_PORT6, |
542 | /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_BCAST_ADDR, | 542 | /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_BCAST_ADDR, |
543 | client_config.ifindex | 543 | client_data.ifindex |
544 | ); | 544 | ); |
545 | } | 545 | } |
546 | 546 | ||
@@ -670,8 +670,8 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct in6_addr *requested_ip | |||
670 | */ | 670 | */ |
671 | opt_ptr = add_d6_client_options(opt_ptr); | 671 | opt_ptr = add_d6_client_options(opt_ptr); |
672 | 672 | ||
673 | bb_error_msg("sending %s", "discover"); | 673 | bb_info_msg("sending %s", "discover"); |
674 | return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); | 674 | return d6_mcast_from_client_data_ifindex(&packet, opt_ptr); |
675 | } | 675 | } |
676 | 676 | ||
677 | /* Multicast a DHCPv6 request message | 677 | /* Multicast a DHCPv6 request message |
@@ -727,8 +727,8 @@ static NOINLINE int send_d6_select(uint32_t xid) | |||
727 | */ | 727 | */ |
728 | opt_ptr = add_d6_client_options(opt_ptr); | 728 | opt_ptr = add_d6_client_options(opt_ptr); |
729 | 729 | ||
730 | bb_error_msg("sending %s", "select"); | 730 | bb_info_msg("sending %s", "select"); |
731 | return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); | 731 | return d6_mcast_from_client_data_ifindex(&packet, opt_ptr); |
732 | } | 732 | } |
733 | 733 | ||
734 | /* Unicast or broadcast a DHCP renew message | 734 | /* Unicast or broadcast a DHCP renew message |
@@ -800,15 +800,15 @@ static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, st | |||
800 | */ | 800 | */ |
801 | opt_ptr = add_d6_client_options(opt_ptr); | 801 | opt_ptr = add_d6_client_options(opt_ptr); |
802 | 802 | ||
803 | bb_error_msg("sending %s", "renew"); | 803 | bb_info_msg("sending %s", "renew"); |
804 | if (server_ipv6) | 804 | if (server_ipv6) |
805 | return d6_send_kernel_packet( | 805 | return d6_send_kernel_packet( |
806 | &packet, (opt_ptr - (uint8_t*) &packet), | 806 | &packet, (opt_ptr - (uint8_t*) &packet), |
807 | our_cur_ipv6, CLIENT_PORT6, | 807 | our_cur_ipv6, CLIENT_PORT6, |
808 | server_ipv6, SERVER_PORT6, | 808 | server_ipv6, SERVER_PORT6, |
809 | client_config.ifindex | 809 | client_data.ifindex |
810 | ); | 810 | ); |
811 | return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); | 811 | return d6_mcast_from_client_data_ifindex(&packet, opt_ptr); |
812 | } | 812 | } |
813 | 813 | ||
814 | /* Unicast a DHCP release message */ | 814 | /* Unicast a DHCP release message */ |
@@ -830,12 +830,12 @@ int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) | |||
830 | if (client6_data.ia_pd) | 830 | if (client6_data.ia_pd) |
831 | opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, client6_data.ia_pd->len + 2+2); | 831 | opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, client6_data.ia_pd->len + 2+2); |
832 | 832 | ||
833 | bb_error_msg("sending %s", "release"); | 833 | bb_info_msg("sending %s", "release"); |
834 | return d6_send_kernel_packet( | 834 | return d6_send_kernel_packet( |
835 | &packet, (opt_ptr - (uint8_t*) &packet), | 835 | &packet, (opt_ptr - (uint8_t*) &packet), |
836 | our_cur_ipv6, CLIENT_PORT6, | 836 | our_cur_ipv6, CLIENT_PORT6, |
837 | server_ipv6, SERVER_PORT6, | 837 | server_ipv6, SERVER_PORT6, |
838 | client_config.ifindex | 838 | client_data.ifindex |
839 | ); | 839 | ); |
840 | } | 840 | } |
841 | 841 | ||
@@ -903,13 +903,12 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6, struct d6_pac | |||
903 | 903 | ||
904 | /*** Main ***/ | 904 | /*** Main ***/ |
905 | 905 | ||
906 | static int sockfd = -1; | 906 | /* Values for client_data.listen_mode */ |
907 | |||
908 | #define LISTEN_NONE 0 | 907 | #define LISTEN_NONE 0 |
909 | #define LISTEN_KERNEL 1 | 908 | #define LISTEN_KERNEL 1 |
910 | #define LISTEN_RAW 2 | 909 | #define LISTEN_RAW 2 |
911 | static smallint listen_mode; | ||
912 | 910 | ||
911 | /* Values for client_data.state */ | ||
913 | /* initial state: (re)start DHCP negotiation */ | 912 | /* initial state: (re)start DHCP negotiation */ |
914 | #define INIT_SELECTING 0 | 913 | #define INIT_SELECTING 0 |
915 | /* discover was sent, DHCPOFFER reply received */ | 914 | /* discover was sent, DHCPOFFER reply received */ |
@@ -924,7 +923,6 @@ static smallint listen_mode; | |||
924 | #define RENEW_REQUESTED 5 | 923 | #define RENEW_REQUESTED 5 |
925 | /* release, possibly manually requested (SIGUSR2) */ | 924 | /* release, possibly manually requested (SIGUSR2) */ |
926 | #define RELEASED 6 | 925 | #define RELEASED 6 |
927 | static smallint state; | ||
928 | 926 | ||
929 | static int d6_raw_socket(int ifindex) | 927 | static int d6_raw_socket(int ifindex) |
930 | { | 928 | { |
@@ -1018,35 +1016,35 @@ static void change_listen_mode(int new_mode) | |||
1018 | : "none" | 1016 | : "none" |
1019 | ); | 1017 | ); |
1020 | 1018 | ||
1021 | listen_mode = new_mode; | 1019 | client_data.listen_mode = new_mode; |
1022 | if (sockfd >= 0) { | 1020 | if (client_data.sockfd >= 0) { |
1023 | close(sockfd); | 1021 | close(client_data.sockfd); |
1024 | sockfd = -1; | 1022 | client_data.sockfd = -1; |
1025 | } | 1023 | } |
1026 | if (new_mode == LISTEN_KERNEL) | 1024 | if (new_mode == LISTEN_KERNEL) |
1027 | sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT6, client_config.interface); | 1025 | client_data.sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT6, client_data.interface); |
1028 | else if (new_mode != LISTEN_NONE) | 1026 | else if (new_mode != LISTEN_NONE) |
1029 | sockfd = d6_raw_socket(client_config.ifindex); | 1027 | client_data.sockfd = d6_raw_socket(client_data.ifindex); |
1030 | /* else LISTEN_NONE: sockfd stays closed */ | 1028 | /* else LISTEN_NONE: client_data.sockfd stays closed */ |
1031 | } | 1029 | } |
1032 | 1030 | ||
1033 | /* Called only on SIGUSR1 */ | 1031 | /* Called only on SIGUSR1 */ |
1034 | static void perform_renew(void) | 1032 | static void perform_renew(void) |
1035 | { | 1033 | { |
1036 | bb_error_msg("performing DHCP renew"); | 1034 | bb_info_msg("performing DHCP renew"); |
1037 | switch (state) { | 1035 | switch (client_data.state) { |
1038 | case BOUND: | 1036 | case BOUND: |
1039 | change_listen_mode(LISTEN_KERNEL); | 1037 | change_listen_mode(LISTEN_KERNEL); |
1040 | case RENEWING: | 1038 | case RENEWING: |
1041 | case REBINDING: | 1039 | case REBINDING: |
1042 | state = RENEW_REQUESTED; | 1040 | client_data.state = RENEW_REQUESTED; |
1043 | break; | 1041 | break; |
1044 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ | 1042 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ |
1045 | d6_run_script_no_option("deconfig"); | 1043 | d6_run_script_no_option("deconfig"); |
1046 | case REQUESTING: | 1044 | case REQUESTING: |
1047 | case RELEASED: | 1045 | case RELEASED: |
1048 | change_listen_mode(LISTEN_RAW); | 1046 | change_listen_mode(LISTEN_RAW); |
1049 | state = INIT_SELECTING; | 1047 | client_data.state = INIT_SELECTING; |
1050 | break; | 1048 | break; |
1051 | case INIT_SELECTING: | 1049 | case INIT_SELECTING: |
1052 | break; | 1050 | break; |
@@ -1056,15 +1054,15 @@ static void perform_renew(void) | |||
1056 | static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) | 1054 | static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) |
1057 | { | 1055 | { |
1058 | /* send release packet */ | 1056 | /* send release packet */ |
1059 | if (state == BOUND | 1057 | if (client_data.state == BOUND |
1060 | || state == RENEWING | 1058 | || client_data.state == RENEWING |
1061 | || state == REBINDING | 1059 | || client_data.state == REBINDING |
1062 | || state == RENEW_REQUESTED | 1060 | || client_data.state == RENEW_REQUESTED |
1063 | ) { | 1061 | ) { |
1064 | bb_error_msg("unicasting a release"); | 1062 | bb_info_msg("unicasting a release"); |
1065 | send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */ | 1063 | send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */ |
1066 | } | 1064 | } |
1067 | bb_error_msg("entering released state"); | 1065 | bb_info_msg("entering released state"); |
1068 | /* | 1066 | /* |
1069 | * We can be here on: SIGUSR2, | 1067 | * We can be here on: SIGUSR2, |
1070 | * or on exit (SIGTERM) and -R "release on quit" is specified. | 1068 | * or on exit (SIGTERM) and -R "release on quit" is specified. |
@@ -1073,7 +1071,7 @@ static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *ou | |||
1073 | */ | 1071 | */ |
1074 | d6_run_script_no_option("deconfig"); | 1072 | d6_run_script_no_option("deconfig"); |
1075 | change_listen_mode(LISTEN_NONE); | 1073 | change_listen_mode(LISTEN_NONE); |
1076 | state = RELEASED; | 1074 | client_data.state = RELEASED; |
1077 | } | 1075 | } |
1078 | 1076 | ||
1079 | ///static uint8_t* alloc_dhcp_option(int code, const char *str, int extra) | 1077 | ///static uint8_t* alloc_dhcp_option(int code, const char *str, int extra) |
@@ -1093,7 +1091,7 @@ static void client_background(void) | |||
1093 | bb_daemonize(0); | 1091 | bb_daemonize(0); |
1094 | logmode &= ~LOGMODE_STDIO; | 1092 | logmode &= ~LOGMODE_STDIO; |
1095 | /* rewrite pidfile, as our pid is different now */ | 1093 | /* rewrite pidfile, as our pid is different now */ |
1096 | write_pidfile(client_config.pidfile); | 1094 | write_pidfile(client_data.pidfile); |
1097 | } | 1095 | } |
1098 | #endif | 1096 | #endif |
1099 | 1097 | ||
@@ -1172,8 +1170,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1172 | /* Default options */ | 1170 | /* Default options */ |
1173 | IF_FEATURE_UDHCP_PORT(SERVER_PORT6 = 547;) | 1171 | IF_FEATURE_UDHCP_PORT(SERVER_PORT6 = 547;) |
1174 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT6 = 546;) | 1172 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT6 = 546;) |
1175 | client_config.interface = "eth0"; | 1173 | client_data.interface = "eth0"; |
1176 | client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; | 1174 | client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; |
1175 | client_data.sockfd = -1; | ||
1177 | 1176 | ||
1178 | /* Parse command line */ | 1177 | /* Parse command line */ |
1179 | opt = getopt32long(argv, "^" | 1178 | opt = getopt32long(argv, "^" |
@@ -1185,8 +1184,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1185 | "v" | 1184 | "v" |
1186 | "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */ | 1185 | "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */ |
1187 | , udhcpc6_longopts | 1186 | , udhcpc6_longopts |
1188 | , &client_config.interface, &client_config.pidfile, &str_r /* i,p */ | 1187 | , &client_data.interface, &client_data.pidfile, &str_r /* i,p */ |
1189 | , &client_config.script /* s */ | 1188 | , &client_data.script /* s */ |
1190 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ | 1189 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ |
1191 | , &list_O | 1190 | , &list_O |
1192 | , &list_x | 1191 | , &list_x |
@@ -1217,29 +1216,29 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1217 | n = udhcp_option_idx(optstr, d6_option_strings); | 1216 | n = udhcp_option_idx(optstr, d6_option_strings); |
1218 | n = d6_optflags[n].code; | 1217 | n = d6_optflags[n].code; |
1219 | } | 1218 | } |
1220 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 1219 | client_data.opt_mask[n >> 3] |= 1 << (n & 7); |
1221 | } | 1220 | } |
1222 | if (!(opt & OPT_o)) { | 1221 | if (!(opt & OPT_o)) { |
1223 | unsigned i, n; | 1222 | unsigned i, n; |
1224 | for (i = 0; (n = d6_optflags[i].code) != 0; i++) { | 1223 | for (i = 0; (n = d6_optflags[i].code) != 0; i++) { |
1225 | if (d6_optflags[i].flags & OPTION_REQ) { | 1224 | if (d6_optflags[i].flags & OPTION_REQ) { |
1226 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 1225 | client_data.opt_mask[n >> 3] |= 1 << (n & 7); |
1227 | } | 1226 | } |
1228 | } | 1227 | } |
1229 | } | 1228 | } |
1230 | while (list_x) { | 1229 | while (list_x) { |
1231 | char *optstr = xstrdup(llist_pop(&list_x)); | 1230 | char *optstr = xstrdup(llist_pop(&list_x)); |
1232 | udhcp_str2optset(optstr, &client_config.options, | 1231 | udhcp_str2optset(optstr, &client_data.options, |
1233 | d6_optflags, d6_option_strings, | 1232 | d6_optflags, d6_option_strings, |
1234 | /*dhcpv6:*/ 1 | 1233 | /*dhcpv6:*/ 1 |
1235 | ); | 1234 | ); |
1236 | free(optstr); | 1235 | free(optstr); |
1237 | } | 1236 | } |
1238 | 1237 | ||
1239 | if (d6_read_interface(client_config.interface, | 1238 | if (d6_read_interface(client_data.interface, |
1240 | &client_config.ifindex, | 1239 | &client_data.ifindex, |
1241 | &client6_data.ll_ip6, | 1240 | &client6_data.ll_ip6, |
1242 | client_config.client_mac) | 1241 | client_data.client_mac) |
1243 | ) { | 1242 | ) { |
1244 | return 1; | 1243 | return 1; |
1245 | } | 1244 | } |
@@ -1253,8 +1252,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1253 | clientid->data[1] = 3; /* DUID-LL */ | 1252 | clientid->data[1] = 3; /* DUID-LL */ |
1254 | clientid->data[3] = 1; /* ethernet */ | 1253 | clientid->data[3] = 1; /* ethernet */ |
1255 | clientid_mac_ptr = clientid->data + 2+2; | 1254 | clientid_mac_ptr = clientid->data + 2+2; |
1256 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); | 1255 | memcpy(clientid_mac_ptr, client_data.client_mac, 6); |
1257 | client_config.clientid = (void*)clientid; | 1256 | client_data.clientid = (void*)clientid; |
1258 | } | 1257 | } |
1259 | 1258 | ||
1260 | #if !BB_MMU | 1259 | #if !BB_MMU |
@@ -1272,13 +1271,13 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1272 | /* Make sure fd 0,1,2 are open */ | 1271 | /* Make sure fd 0,1,2 are open */ |
1273 | bb_sanitize_stdio(); | 1272 | bb_sanitize_stdio(); |
1274 | /* Create pidfile */ | 1273 | /* Create pidfile */ |
1275 | write_pidfile(client_config.pidfile); | 1274 | write_pidfile(client_data.pidfile); |
1276 | /* Goes to stdout (unless NOMMU) and possibly syslog */ | 1275 | /* Goes to stdout (unless NOMMU) and possibly syslog */ |
1277 | bb_error_msg("started, v"BB_VER); | 1276 | bb_info_msg("started, v"BB_VER); |
1278 | /* Set up the signal pipe */ | 1277 | /* Set up the signal pipe */ |
1279 | udhcp_sp_setup(); | 1278 | udhcp_sp_setup(); |
1280 | 1279 | ||
1281 | state = INIT_SELECTING; | 1280 | client_data.state = INIT_SELECTING; |
1282 | d6_run_script_no_option("deconfig"); | 1281 | d6_run_script_no_option("deconfig"); |
1283 | change_listen_mode(LISTEN_RAW); | 1282 | change_listen_mode(LISTEN_RAW); |
1284 | packet_num = 0; | 1283 | packet_num = 0; |
@@ -1297,16 +1296,16 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1297 | /* silence "uninitialized!" warning */ | 1296 | /* silence "uninitialized!" warning */ |
1298 | unsigned timestamp_before_wait = timestamp_before_wait; | 1297 | unsigned timestamp_before_wait = timestamp_before_wait; |
1299 | 1298 | ||
1300 | //bb_error_msg("sockfd:%d, listen_mode:%d", sockfd, listen_mode); | 1299 | //bb_error_msg("sockfd:%d, listen_mode:%d", client_data.sockfd, client_data.listen_mode); |
1301 | 1300 | ||
1302 | /* Was opening raw or udp socket here | 1301 | /* Was opening raw or udp socket here |
1303 | * if (listen_mode != LISTEN_NONE && sockfd < 0), | 1302 | * if (client_data.listen_mode != LISTEN_NONE && client_data.sockfd < 0), |
1304 | * but on fast network renew responses return faster | 1303 | * but on fast network renew responses return faster |
1305 | * than we open sockets. Thus this code is moved | 1304 | * than we open sockets. Thus this code is moved |
1306 | * to change_listen_mode(). Thus we open listen socket | 1305 | * to change_listen_mode(). Thus we open listen socket |
1307 | * BEFORE we send renew request (see "case BOUND:"). */ | 1306 | * BEFORE we send renew request (see "case BOUND:"). */ |
1308 | 1307 | ||
1309 | udhcp_sp_fd_set(pfds, sockfd); | 1308 | udhcp_sp_fd_set(pfds, client_data.sockfd); |
1310 | 1309 | ||
1311 | tv = timeout - already_waited_sec; | 1310 | tv = timeout - already_waited_sec; |
1312 | retval = 0; | 1311 | retval = 0; |
@@ -1335,20 +1334,20 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1335 | * or if the status of the bridge changed). | 1334 | * or if the status of the bridge changed). |
1336 | * Refresh ifindex and client_mac: | 1335 | * Refresh ifindex and client_mac: |
1337 | */ | 1336 | */ |
1338 | if (d6_read_interface(client_config.interface, | 1337 | if (d6_read_interface(client_data.interface, |
1339 | &client_config.ifindex, | 1338 | &client_data.ifindex, |
1340 | &client6_data.ll_ip6, | 1339 | &client6_data.ll_ip6, |
1341 | client_config.client_mac) | 1340 | client_data.client_mac) |
1342 | ) { | 1341 | ) { |
1343 | goto ret0; /* iface is gone? */ | 1342 | goto ret0; /* iface is gone? */ |
1344 | } | 1343 | } |
1345 | 1344 | ||
1346 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); | 1345 | memcpy(clientid_mac_ptr, client_data.client_mac, 6); |
1347 | 1346 | ||
1348 | /* We will restart the wait in any case */ | 1347 | /* We will restart the wait in any case */ |
1349 | already_waited_sec = 0; | 1348 | already_waited_sec = 0; |
1350 | 1349 | ||
1351 | switch (state) { | 1350 | switch (client_data.state) { |
1352 | case INIT_SELECTING: | 1351 | case INIT_SELECTING: |
1353 | if (!discover_retries || packet_num < discover_retries) { | 1352 | if (!discover_retries || packet_num < discover_retries) { |
1354 | if (packet_num == 0) | 1353 | if (packet_num == 0) |
@@ -1363,7 +1362,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1363 | d6_run_script_no_option("leasefail"); | 1362 | d6_run_script_no_option("leasefail"); |
1364 | #if BB_MMU /* -b is not supported on NOMMU */ | 1363 | #if BB_MMU /* -b is not supported on NOMMU */ |
1365 | if (opt & OPT_b) { /* background if no lease */ | 1364 | if (opt & OPT_b) { /* background if no lease */ |
1366 | bb_error_msg("no lease, forking to background"); | 1365 | bb_info_msg("no lease, forking to background"); |
1367 | client_background(); | 1366 | client_background(); |
1368 | /* do not background again! */ | 1367 | /* do not background again! */ |
1369 | opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); | 1368 | opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); |
@@ -1376,7 +1375,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1376 | } else | 1375 | } else |
1377 | #endif | 1376 | #endif |
1378 | if (opt & OPT_n) { /* abort if no lease */ | 1377 | if (opt & OPT_n) { /* abort if no lease */ |
1379 | bb_error_msg("no lease, failing"); | 1378 | bb_info_msg("no lease, failing"); |
1380 | retval = 1; | 1379 | retval = 1; |
1381 | goto ret; | 1380 | goto ret; |
1382 | } | 1381 | } |
@@ -1397,12 +1396,12 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1397 | * were seen in the wild. Treat them similarly | 1396 | * were seen in the wild. Treat them similarly |
1398 | * to "no response to discover" case */ | 1397 | * to "no response to discover" case */ |
1399 | change_listen_mode(LISTEN_RAW); | 1398 | change_listen_mode(LISTEN_RAW); |
1400 | state = INIT_SELECTING; | 1399 | client_data.state = INIT_SELECTING; |
1401 | goto leasefail; | 1400 | goto leasefail; |
1402 | case BOUND: | 1401 | case BOUND: |
1403 | /* 1/2 lease passed, enter renewing state */ | 1402 | /* 1/2 lease passed, enter renewing state */ |
1404 | state = RENEWING; | 1403 | client_data.state = RENEWING; |
1405 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1404 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1406 | change_listen_mode(LISTEN_KERNEL); | 1405 | change_listen_mode(LISTEN_KERNEL); |
1407 | log1("entering renew state"); | 1406 | log1("entering renew state"); |
1408 | /* fall right through */ | 1407 | /* fall right through */ |
@@ -1425,7 +1424,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1425 | } | 1424 | } |
1426 | /* Timed out, enter rebinding state */ | 1425 | /* Timed out, enter rebinding state */ |
1427 | log1("entering rebinding state"); | 1426 | log1("entering rebinding state"); |
1428 | state = REBINDING; | 1427 | client_data.state = REBINDING; |
1429 | /* fall right through */ | 1428 | /* fall right through */ |
1430 | case REBINDING: | 1429 | case REBINDING: |
1431 | /* Switch to bcast receive */ | 1430 | /* Switch to bcast receive */ |
@@ -1439,10 +1438,10 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1439 | continue; | 1438 | continue; |
1440 | } | 1439 | } |
1441 | /* Timed out, enter init state */ | 1440 | /* Timed out, enter init state */ |
1442 | bb_error_msg("lease lost, entering init state"); | 1441 | bb_info_msg("lease lost, entering init state"); |
1443 | d6_run_script_no_option("deconfig"); | 1442 | d6_run_script_no_option("deconfig"); |
1444 | state = INIT_SELECTING; | 1443 | client_data.state = INIT_SELECTING; |
1445 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1444 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1446 | /*timeout = 0; - already is */ | 1445 | /*timeout = 0; - already is */ |
1447 | packet_num = 0; | 1446 | packet_num = 0; |
1448 | continue; | 1447 | continue; |
@@ -1458,10 +1457,10 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1458 | /* Is it a signal? */ | 1457 | /* Is it a signal? */ |
1459 | switch (udhcp_sp_read()) { | 1458 | switch (udhcp_sp_read()) { |
1460 | case SIGUSR1: | 1459 | case SIGUSR1: |
1461 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1460 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1462 | already_waited_sec = 0; | 1461 | already_waited_sec = 0; |
1463 | perform_renew(); | 1462 | perform_renew(); |
1464 | if (state == RENEW_REQUESTED) { | 1463 | if (client_data.state == RENEW_REQUESTED) { |
1465 | /* We might be either on the same network | 1464 | /* We might be either on the same network |
1466 | * (in which case renew might work), | 1465 | * (in which case renew might work), |
1467 | * or we might be on a completely different one | 1466 | * or we might be on a completely different one |
@@ -1484,7 +1483,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1484 | timeout = INT_MAX; | 1483 | timeout = INT_MAX; |
1485 | continue; | 1484 | continue; |
1486 | case SIGTERM: | 1485 | case SIGTERM: |
1487 | bb_error_msg("received %s", "SIGTERM"); | 1486 | bb_info_msg("received %s", "SIGTERM"); |
1488 | goto ret0; | 1487 | goto ret0; |
1489 | } | 1488 | } |
1490 | 1489 | ||
@@ -1496,15 +1495,15 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1496 | int len; | 1495 | int len; |
1497 | 1496 | ||
1498 | /* A packet is ready, read it */ | 1497 | /* A packet is ready, read it */ |
1499 | if (listen_mode == LISTEN_KERNEL) | 1498 | if (client_data.listen_mode == LISTEN_KERNEL) |
1500 | len = d6_recv_kernel_packet(&srv6_buf, &packet, sockfd); | 1499 | len = d6_recv_kernel_packet(&srv6_buf, &packet, client_data.sockfd); |
1501 | else | 1500 | else |
1502 | len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd); | 1501 | len = d6_recv_raw_packet(&srv6_buf, &packet, client_data.sockfd); |
1503 | if (len == -1) { | 1502 | if (len == -1) { |
1504 | /* Error is severe, reopen socket */ | 1503 | /* Error is severe, reopen socket */ |
1505 | bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); | 1504 | bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); |
1506 | sleep(discover_timeout); /* 3 seconds by default */ | 1505 | sleep(discover_timeout); /* 3 seconds by default */ |
1507 | change_listen_mode(listen_mode); /* just close and reopen */ | 1506 | change_listen_mode(client_data.listen_mode); /* just close and reopen */ |
1508 | } | 1507 | } |
1509 | /* If this packet will turn out to be unrelated/bogus, | 1508 | /* If this packet will turn out to be unrelated/bogus, |
1510 | * we will go back and wait for next one. | 1509 | * we will go back and wait for next one. |
@@ -1521,7 +1520,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1521 | continue; | 1520 | continue; |
1522 | } | 1521 | } |
1523 | 1522 | ||
1524 | switch (state) { | 1523 | switch (client_data.state) { |
1525 | case INIT_SELECTING: | 1524 | case INIT_SELECTING: |
1526 | if (packet.d6_msg_type == D6_MSG_ADVERTISE) | 1525 | if (packet.d6_msg_type == D6_MSG_ADVERTISE) |
1527 | goto type_is_ok; | 1526 | goto type_is_ok; |
@@ -1544,15 +1543,15 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1544 | option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE); | 1543 | option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE); |
1545 | if (option && (option->data[0] | option->data[1]) != 0) { | 1544 | if (option && (option->data[0] | option->data[1]) != 0) { |
1546 | /* return to init state */ | 1545 | /* return to init state */ |
1547 | bb_error_msg("received DHCP NAK (%u)", option->data[4]); | 1546 | bb_info_msg("received DHCP NAK (%u)", option->data[4]); |
1548 | d6_run_script(packet.d6_options, | 1547 | d6_run_script(packet.d6_options, |
1549 | packet_end, "nak"); | 1548 | packet_end, "nak"); |
1550 | if (state != REQUESTING) | 1549 | if (client_data.state != REQUESTING) |
1551 | d6_run_script_no_option("deconfig"); | 1550 | d6_run_script_no_option("deconfig"); |
1552 | change_listen_mode(LISTEN_RAW); | 1551 | change_listen_mode(LISTEN_RAW); |
1553 | sleep(3); /* avoid excessive network traffic */ | 1552 | sleep(3); /* avoid excessive network traffic */ |
1554 | state = INIT_SELECTING; | 1553 | client_data.state = INIT_SELECTING; |
1555 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1554 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1556 | requested_ipv6 = NULL; | 1555 | requested_ipv6 = NULL; |
1557 | timeout = 0; | 1556 | timeout = 0; |
1558 | packet_num = 0; | 1557 | packet_num = 0; |
@@ -1561,7 +1560,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1561 | } | 1560 | } |
1562 | option = d6_copy_option(packet.d6_options, packet_end, D6_OPT_SERVERID); | 1561 | option = d6_copy_option(packet.d6_options, packet_end, D6_OPT_SERVERID); |
1563 | if (!option) { | 1562 | if (!option) { |
1564 | bb_error_msg("no server ID, ignoring packet"); | 1563 | bb_info_msg("no server ID, ignoring packet"); |
1565 | continue; | 1564 | continue; |
1566 | /* still selecting - this server looks bad */ | 1565 | /* still selecting - this server looks bad */ |
1567 | } | 1566 | } |
@@ -1572,7 +1571,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1572 | client6_data.server_id = option; | 1571 | client6_data.server_id = option; |
1573 | if (packet.d6_msg_type == D6_MSG_ADVERTISE) { | 1572 | if (packet.d6_msg_type == D6_MSG_ADVERTISE) { |
1574 | /* enter requesting state */ | 1573 | /* enter requesting state */ |
1575 | state = REQUESTING; | 1574 | client_data.state = REQUESTING; |
1576 | timeout = 0; | 1575 | timeout = 0; |
1577 | packet_num = 0; | 1576 | packet_num = 0; |
1578 | already_waited_sec = 0; | 1577 | already_waited_sec = 0; |
@@ -1670,11 +1669,11 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1670 | free(client6_data.ia_na); | 1669 | free(client6_data.ia_na); |
1671 | client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA); | 1670 | client6_data.ia_na = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_NA); |
1672 | if (!client6_data.ia_na) { | 1671 | if (!client6_data.ia_na) { |
1673 | bb_error_msg("no %s option, ignoring packet", "IA_NA"); | 1672 | bb_info_msg("no %s option, ignoring packet", "IA_NA"); |
1674 | continue; | 1673 | continue; |
1675 | } | 1674 | } |
1676 | if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) { | 1675 | if (client6_data.ia_na->len < (4 + 4 + 4) + (2 + 2 + 16 + 4 + 4)) { |
1677 | bb_error_msg("%s option is too short:%d bytes", | 1676 | bb_info_msg("%s option is too short:%d bytes", |
1678 | "IA_NA", client6_data.ia_na->len); | 1677 | "IA_NA", client6_data.ia_na->len); |
1679 | continue; | 1678 | continue; |
1680 | } | 1679 | } |
@@ -1683,11 +1682,11 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1683 | D6_OPT_IAADDR | 1682 | D6_OPT_IAADDR |
1684 | ); | 1683 | ); |
1685 | if (!iaaddr) { | 1684 | if (!iaaddr) { |
1686 | bb_error_msg("no %s option, ignoring packet", "IAADDR"); | 1685 | bb_info_msg("no %s option, ignoring packet", "IAADDR"); |
1687 | continue; | 1686 | continue; |
1688 | } | 1687 | } |
1689 | if (iaaddr->len < (16 + 4 + 4)) { | 1688 | if (iaaddr->len < (16 + 4 + 4)) { |
1690 | bb_error_msg("%s option is too short:%d bytes", | 1689 | bb_info_msg("%s option is too short:%d bytes", |
1691 | "IAADDR", iaaddr->len); | 1690 | "IAADDR", iaaddr->len); |
1692 | continue; | 1691 | continue; |
1693 | } | 1692 | } |
@@ -1698,7 +1697,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1698 | move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4); | 1697 | move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4); |
1699 | lease_seconds = ntohl(lease_seconds); | 1698 | lease_seconds = ntohl(lease_seconds); |
1700 | /// TODO: check for 0 lease time? | 1699 | /// TODO: check for 0 lease time? |
1701 | bb_error_msg("%s obtained, lease time %u", | 1700 | bb_info_msg("%s obtained, lease time %u", |
1702 | "IPv6", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); | 1701 | "IPv6", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); |
1703 | address_timeout = lease_seconds; | 1702 | address_timeout = lease_seconds; |
1704 | } | 1703 | } |
@@ -1708,11 +1707,11 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1708 | free(client6_data.ia_pd); | 1707 | free(client6_data.ia_pd); |
1709 | client6_data.ia_pd = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_PD); | 1708 | client6_data.ia_pd = d6_copy_option(packet.d6_options, packet_end, D6_OPT_IA_PD); |
1710 | if (!client6_data.ia_pd) { | 1709 | if (!client6_data.ia_pd) { |
1711 | bb_error_msg("no %s option, ignoring packet", "IA_PD"); | 1710 | bb_info_msg("no %s option, ignoring packet", "IA_PD"); |
1712 | continue; | 1711 | continue; |
1713 | } | 1712 | } |
1714 | if (client6_data.ia_pd->len < (4 + 4 + 4) + (2 + 2 + 4 + 4 + 1 + 16)) { | 1713 | if (client6_data.ia_pd->len < (4 + 4 + 4) + (2 + 2 + 4 + 4 + 1 + 16)) { |
1715 | bb_error_msg("%s option is too short:%d bytes", | 1714 | bb_info_msg("%s option is too short:%d bytes", |
1716 | "IA_PD", client6_data.ia_pd->len); | 1715 | "IA_PD", client6_data.ia_pd->len); |
1717 | continue; | 1716 | continue; |
1718 | } | 1717 | } |
@@ -1721,17 +1720,17 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1721 | D6_OPT_IAPREFIX | 1720 | D6_OPT_IAPREFIX |
1722 | ); | 1721 | ); |
1723 | if (!iaprefix) { | 1722 | if (!iaprefix) { |
1724 | bb_error_msg("no %s option, ignoring packet", "IAPREFIX"); | 1723 | bb_info_msg("no %s option, ignoring packet", "IAPREFIX"); |
1725 | continue; | 1724 | continue; |
1726 | } | 1725 | } |
1727 | if (iaprefix->len < (4 + 4 + 1 + 16)) { | 1726 | if (iaprefix->len < (4 + 4 + 1 + 16)) { |
1728 | bb_error_msg("%s option is too short:%d bytes", | 1727 | bb_info_msg("%s option is too short:%d bytes", |
1729 | "IAPREFIX", iaprefix->len); | 1728 | "IAPREFIX", iaprefix->len); |
1730 | continue; | 1729 | continue; |
1731 | } | 1730 | } |
1732 | move_from_unaligned32(lease_seconds, iaprefix->data + 4); | 1731 | move_from_unaligned32(lease_seconds, iaprefix->data + 4); |
1733 | lease_seconds = ntohl(lease_seconds); | 1732 | lease_seconds = ntohl(lease_seconds); |
1734 | bb_error_msg("%s obtained, lease time %u", | 1733 | bb_info_msg("%s obtained, lease time %u", |
1735 | "prefix", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); | 1734 | "prefix", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); |
1736 | prefix_timeout = lease_seconds; | 1735 | prefix_timeout = lease_seconds; |
1737 | } | 1736 | } |
@@ -1747,9 +1746,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1747 | timeout = 61; | 1746 | timeout = 61; |
1748 | /* enter bound state */ | 1747 | /* enter bound state */ |
1749 | d6_run_script(packet.d6_options, packet_end, | 1748 | d6_run_script(packet.d6_options, packet_end, |
1750 | (state == REQUESTING ? "bound" : "renew")); | 1749 | (client_data.state == REQUESTING ? "bound" : "renew")); |
1751 | 1750 | ||
1752 | state = BOUND; | 1751 | client_data.state = BOUND; |
1753 | change_listen_mode(LISTEN_NONE); | 1752 | change_listen_mode(LISTEN_NONE); |
1754 | if (opt & OPT_q) { /* quit after lease */ | 1753 | if (opt & OPT_q) { /* quit after lease */ |
1755 | goto ret0; | 1754 | goto ret0; |
@@ -1778,7 +1777,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1778 | perform_d6_release(&srv6_buf, requested_ipv6); | 1777 | perform_d6_release(&srv6_buf, requested_ipv6); |
1779 | retval = 0; | 1778 | retval = 0; |
1780 | ret: | 1779 | ret: |
1781 | /*if (client_config.pidfile) - remove_pidfile has its own check */ | 1780 | /*if (client_data.pidfile) - remove_pidfile has its own check */ |
1782 | remove_pidfile(client_config.pidfile); | 1781 | remove_pidfile(client_data.pidfile); |
1783 | return retval; | 1782 | return retval; |
1784 | } | 1783 | } |
diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c index 493943d72..01d1c930b 100644 --- a/networking/udhcp/d6_packet.c +++ b/networking/udhcp/d6_packet.c | |||
@@ -17,7 +17,7 @@ void FAST_FUNC d6_dump_packet(struct d6_packet *packet) | |||
17 | if (dhcp_verbose < 2) | 17 | if (dhcp_verbose < 2) |
18 | return; | 18 | return; |
19 | 19 | ||
20 | bb_error_msg( | 20 | bb_info_msg( |
21 | " xid %x" | 21 | " xid %x" |
22 | , packet->d6_xid32 | 22 | , packet->d6_xid32 |
23 | ); | 23 | ); |
@@ -40,7 +40,7 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6 | |||
40 | } | 40 | } |
41 | 41 | ||
42 | if (bytes < offsetof(struct d6_packet, d6_options)) { | 42 | if (bytes < offsetof(struct d6_packet, d6_options)) { |
43 | bb_error_msg("packet with bad magic, ignoring"); | 43 | bb_info_msg("packet with bad magic, ignoring"); |
44 | return -2; | 44 | return -2; |
45 | } | 45 | } |
46 | log1("received %s", "a packet"); | 46 | log1("received %s", "a packet"); |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index e2fb18aba..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 */ |
@@ -730,8 +730,8 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) | |||
730 | */ | 730 | */ |
731 | add_client_options(&packet); | 731 | add_client_options(&packet); |
732 | 732 | ||
733 | bb_error_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 */ |
@@ -774,8 +774,8 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste | |||
774 | add_client_options(&packet); | 774 | add_client_options(&packet); |
775 | 775 | ||
776 | temp_addr.s_addr = requested; | 776 | temp_addr.s_addr = requested; |
777 | bb_error_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 */ |
@@ -815,7 +815,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) | |||
815 | add_client_options(&packet); | 815 | add_client_options(&packet); |
816 | 816 | ||
817 | temp_addr.s_addr = server; | 817 | temp_addr.s_addr = server; |
818 | bb_error_msg("sending renew to %s", inet_ntoa(temp_addr)); | 818 | bb_info_msg("sending renew to %s", inet_ntoa(temp_addr)); |
819 | return bcast_or_ucast(&packet, ciaddr, server); | 819 | return bcast_or_ucast(&packet, ciaddr, server); |
820 | } | 820 | } |
821 | 821 | ||
@@ -844,8 +844,8 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req | |||
844 | 844 | ||
845 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); | 845 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); |
846 | 846 | ||
847 | bb_error_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 | ||
@@ -866,7 +866,7 @@ int send_release(uint32_t server, uint32_t ciaddr) | |||
866 | 866 | ||
867 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); | 867 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); |
868 | 868 | ||
869 | bb_error_msg("sending %s", "release"); | 869 | bb_info_msg("sending %s", "release"); |
870 | /* Note: normally we unicast here since "server" is not zero. | 870 | /* Note: normally we unicast here since "server" is not zero. |
871 | * However, there _are_ people who run "address-less" DHCP servers, | 871 | * However, there _are_ people who run "address-less" DHCP servers, |
872 | * and reportedly ISC dhcp client and Windows allow that. | 872 | * and reportedly ISC dhcp client and Windows allow that. |
@@ -969,7 +969,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
969 | skip_udp_sum_check: | 969 | skip_udp_sum_check: |
970 | 970 | ||
971 | if (packet.data.cookie != htonl(DHCP_MAGIC)) { | 971 | if (packet.data.cookie != htonl(DHCP_MAGIC)) { |
972 | bb_error_msg("packet with bad magic, ignoring"); | 972 | bb_info_msg("packet with bad magic, ignoring"); |
973 | return -2; | 973 | return -2; |
974 | } | 974 | } |
975 | 975 | ||
@@ -984,13 +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 | static int sockfd = -1; | 987 | /* Values for client_data.listen_mode */ |
988 | |||
989 | #define LISTEN_NONE 0 | 988 | #define LISTEN_NONE 0 |
990 | #define LISTEN_KERNEL 1 | 989 | #define LISTEN_KERNEL 1 |
991 | #define LISTEN_RAW 2 | 990 | #define LISTEN_RAW 2 |
992 | static smallint listen_mode; | ||
993 | 991 | ||
992 | /* Values for client_data.state */ | ||
994 | /* initial state: (re)start DHCP negotiation */ | 993 | /* initial state: (re)start DHCP negotiation */ |
995 | #define INIT_SELECTING 0 | 994 | #define INIT_SELECTING 0 |
996 | /* discover was sent, DHCPOFFER reply received */ | 995 | /* discover was sent, DHCPOFFER reply received */ |
@@ -1005,7 +1004,6 @@ static smallint listen_mode; | |||
1005 | #define RENEW_REQUESTED 5 | 1004 | #define RENEW_REQUESTED 5 |
1006 | /* release, possibly manually requested (SIGUSR2) */ | 1005 | /* release, possibly manually requested (SIGUSR2) */ |
1007 | #define RELEASED 6 | 1006 | #define RELEASED 6 |
1008 | static smallint state; | ||
1009 | 1007 | ||
1010 | static int udhcp_raw_socket(int ifindex) | 1008 | static int udhcp_raw_socket(int ifindex) |
1011 | { | 1009 | { |
@@ -1102,35 +1100,35 @@ static void change_listen_mode(int new_mode) | |||
1102 | : "none" | 1100 | : "none" |
1103 | ); | 1101 | ); |
1104 | 1102 | ||
1105 | listen_mode = new_mode; | 1103 | client_data.listen_mode = new_mode; |
1106 | if (sockfd >= 0) { | 1104 | if (client_data.sockfd >= 0) { |
1107 | close(sockfd); | 1105 | close(client_data.sockfd); |
1108 | sockfd = -1; | 1106 | client_data.sockfd = -1; |
1109 | } | 1107 | } |
1110 | if (new_mode == LISTEN_KERNEL) | 1108 | if (new_mode == LISTEN_KERNEL) |
1111 | 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); |
1112 | else if (new_mode != LISTEN_NONE) | 1110 | else if (new_mode != LISTEN_NONE) |
1113 | sockfd = udhcp_raw_socket(client_config.ifindex); | 1111 | client_data.sockfd = udhcp_raw_socket(client_data.ifindex); |
1114 | /* else LISTEN_NONE: sockfd stays closed */ | 1112 | /* else LISTEN_NONE: client_data.sockfd stays closed */ |
1115 | } | 1113 | } |
1116 | 1114 | ||
1117 | /* Called only on SIGUSR1 */ | 1115 | /* Called only on SIGUSR1 */ |
1118 | static void perform_renew(void) | 1116 | static void perform_renew(void) |
1119 | { | 1117 | { |
1120 | bb_error_msg("performing DHCP renew"); | 1118 | bb_info_msg("performing DHCP renew"); |
1121 | switch (state) { | 1119 | switch (client_data.state) { |
1122 | case BOUND: | 1120 | case BOUND: |
1123 | change_listen_mode(LISTEN_KERNEL); | 1121 | change_listen_mode(LISTEN_KERNEL); |
1124 | case RENEWING: | 1122 | case RENEWING: |
1125 | case REBINDING: | 1123 | case REBINDING: |
1126 | state = RENEW_REQUESTED; | 1124 | client_data.state = RENEW_REQUESTED; |
1127 | break; | 1125 | break; |
1128 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ | 1126 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ |
1129 | udhcp_run_script(NULL, "deconfig"); | 1127 | udhcp_run_script(NULL, "deconfig"); |
1130 | case REQUESTING: | 1128 | case REQUESTING: |
1131 | case RELEASED: | 1129 | case RELEASED: |
1132 | change_listen_mode(LISTEN_RAW); | 1130 | change_listen_mode(LISTEN_RAW); |
1133 | state = INIT_SELECTING; | 1131 | client_data.state = INIT_SELECTING; |
1134 | break; | 1132 | break; |
1135 | case INIT_SELECTING: | 1133 | case INIT_SELECTING: |
1136 | break; | 1134 | break; |
@@ -1143,19 +1141,19 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) | |||
1143 | struct in_addr temp_addr; | 1141 | struct in_addr temp_addr; |
1144 | 1142 | ||
1145 | /* send release packet */ | 1143 | /* send release packet */ |
1146 | if (state == BOUND | 1144 | if (client_data.state == BOUND |
1147 | || state == RENEWING | 1145 | || client_data.state == RENEWING |
1148 | || state == REBINDING | 1146 | || client_data.state == REBINDING |
1149 | || state == RENEW_REQUESTED | 1147 | || client_data.state == RENEW_REQUESTED |
1150 | ) { | 1148 | ) { |
1151 | temp_addr.s_addr = server_addr; | 1149 | temp_addr.s_addr = server_addr; |
1152 | strcpy(buffer, inet_ntoa(temp_addr)); | 1150 | strcpy(buffer, inet_ntoa(temp_addr)); |
1153 | temp_addr.s_addr = requested_ip; | 1151 | temp_addr.s_addr = requested_ip; |
1154 | bb_error_msg("unicasting a release of %s to %s", | 1152 | bb_info_msg("unicasting a release of %s to %s", |
1155 | inet_ntoa(temp_addr), buffer); | 1153 | inet_ntoa(temp_addr), buffer); |
1156 | send_release(server_addr, requested_ip); /* unicast */ | 1154 | send_release(server_addr, requested_ip); /* unicast */ |
1157 | } | 1155 | } |
1158 | bb_error_msg("entering released state"); | 1156 | bb_info_msg("entering released state"); |
1159 | /* | 1157 | /* |
1160 | * We can be here on: SIGUSR2, | 1158 | * We can be here on: SIGUSR2, |
1161 | * or on exit (SIGTERM) and -R "release on quit" is specified. | 1159 | * or on exit (SIGTERM) and -R "release on quit" is specified. |
@@ -1165,7 +1163,7 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) | |||
1165 | udhcp_run_script(NULL, "deconfig"); | 1163 | udhcp_run_script(NULL, "deconfig"); |
1166 | 1164 | ||
1167 | change_listen_mode(LISTEN_NONE); | 1165 | change_listen_mode(LISTEN_NONE); |
1168 | state = RELEASED; | 1166 | client_data.state = RELEASED; |
1169 | } | 1167 | } |
1170 | 1168 | ||
1171 | 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) |
@@ -1185,7 +1183,7 @@ static void client_background(void) | |||
1185 | bb_daemonize(0); | 1183 | bb_daemonize(0); |
1186 | logmode &= ~LOGMODE_STDIO; | 1184 | logmode &= ~LOGMODE_STDIO; |
1187 | /* rewrite pidfile, as our pid is different now */ | 1185 | /* rewrite pidfile, as our pid is different now */ |
1188 | write_pidfile(client_config.pidfile); | 1186 | write_pidfile(client_data.pidfile); |
1189 | } | 1187 | } |
1190 | #endif | 1188 | #endif |
1191 | 1189 | ||
@@ -1268,8 +1266,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1268 | /* Default options */ | 1266 | /* Default options */ |
1269 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) | 1267 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) |
1270 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) | 1268 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) |
1271 | client_config.interface = "eth0"; | 1269 | client_data.interface = "eth0"; |
1272 | client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; | 1270 | client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; |
1271 | client_data.sockfd = -1; | ||
1273 | str_V = "udhcp "BB_VER; | 1272 | str_V = "udhcp "BB_VER; |
1274 | 1273 | ||
1275 | /* Parse command line */ | 1274 | /* Parse command line */ |
@@ -1283,9 +1282,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1283 | "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */ | 1282 | "\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */ |
1284 | , udhcpc_longopts | 1283 | , udhcpc_longopts |
1285 | , &str_V, &str_h, &str_h, &str_F | 1284 | , &str_V, &str_h, &str_h, &str_F |
1286 | , &client_config.interface, &client_config.pidfile /* i,p */ | 1285 | , &client_data.interface, &client_data.pidfile /* i,p */ |
1287 | , &str_r /* r */ | 1286 | , &str_r /* r */ |
1288 | , &client_config.script /* s */ | 1287 | , &client_data.script /* s */ |
1289 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ | 1288 | , &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */ |
1290 | , &list_O | 1289 | , &list_O |
1291 | , &list_x | 1290 | , &list_x |
@@ -1296,11 +1295,11 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1296 | if (opt & (OPT_h|OPT_H)) { | 1295 | if (opt & (OPT_h|OPT_H)) { |
1297 | //msg added 2011-11 | 1296 | //msg added 2011-11 |
1298 | 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"); |
1299 | 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); |
1300 | } | 1299 | } |
1301 | if (opt & OPT_F) { | 1300 | if (opt & OPT_F) { |
1302 | /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */ | 1301 | /* FQDN option format: [0x51][len][flags][0][0]<fqdn> */ |
1303 | client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3); | 1302 | client_data.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3); |
1304 | /* Flag bits: 0000NEOS | 1303 | /* Flag bits: 0000NEOS |
1305 | * 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 |
1306 | * 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 |
@@ -1309,9 +1308,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1309 | * 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) |
1310 | * Two [0] bytes which follow are deprecated and must be 0. | 1309 | * Two [0] bytes which follow are deprecated and must be 0. |
1311 | */ | 1310 | */ |
1312 | client_config.fqdn[OPT_DATA + 0] = 0x1; | 1311 | client_data.fqdn[OPT_DATA + 0] = 0x1; |
1313 | /*client_config.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */ | 1312 | /*client_data.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */ |
1314 | /*client_config.fqdn[OPT_DATA + 2] = 0; */ | 1313 | /*client_data.fqdn[OPT_DATA + 2] = 0; */ |
1315 | } | 1314 | } |
1316 | if (opt & OPT_r) | 1315 | if (opt & OPT_r) |
1317 | requested_ip = inet_addr(str_r); | 1316 | requested_ip = inet_addr(str_r); |
@@ -1329,49 +1328,49 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1329 | n = udhcp_option_idx(optstr, dhcp_option_strings); | 1328 | n = udhcp_option_idx(optstr, dhcp_option_strings); |
1330 | n = dhcp_optflags[n].code; | 1329 | n = dhcp_optflags[n].code; |
1331 | } | 1330 | } |
1332 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 1331 | client_data.opt_mask[n >> 3] |= 1 << (n & 7); |
1333 | } | 1332 | } |
1334 | if (!(opt & OPT_o)) { | 1333 | if (!(opt & OPT_o)) { |
1335 | unsigned i, n; | 1334 | unsigned i, n; |
1336 | for (i = 0; (n = dhcp_optflags[i].code) != 0; i++) { | 1335 | for (i = 0; (n = dhcp_optflags[i].code) != 0; i++) { |
1337 | if (dhcp_optflags[i].flags & OPTION_REQ) { | 1336 | if (dhcp_optflags[i].flags & OPTION_REQ) { |
1338 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 1337 | client_data.opt_mask[n >> 3] |= 1 << (n & 7); |
1339 | } | 1338 | } |
1340 | } | 1339 | } |
1341 | } | 1340 | } |
1342 | while (list_x) { | 1341 | while (list_x) { |
1343 | char *optstr = xstrdup(llist_pop(&list_x)); | 1342 | char *optstr = xstrdup(llist_pop(&list_x)); |
1344 | udhcp_str2optset(optstr, &client_config.options, | 1343 | udhcp_str2optset(optstr, &client_data.options, |
1345 | dhcp_optflags, dhcp_option_strings, | 1344 | dhcp_optflags, dhcp_option_strings, |
1346 | /*dhcpv6:*/ 0 | 1345 | /*dhcpv6:*/ 0 |
1347 | ); | 1346 | ); |
1348 | free(optstr); | 1347 | free(optstr); |
1349 | } | 1348 | } |
1350 | 1349 | ||
1351 | if (udhcp_read_interface(client_config.interface, | 1350 | if (udhcp_read_interface(client_data.interface, |
1352 | &client_config.ifindex, | 1351 | &client_data.ifindex, |
1353 | NULL, | 1352 | NULL, |
1354 | client_config.client_mac) | 1353 | client_data.client_mac) |
1355 | ) { | 1354 | ) { |
1356 | return 1; | 1355 | return 1; |
1357 | } | 1356 | } |
1358 | 1357 | ||
1359 | clientid_mac_ptr = NULL; | 1358 | clientid_mac_ptr = NULL; |
1360 | 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)) { |
1361 | /* not suppressed and not set, set the default client ID */ | 1360 | /* not suppressed and not set, set the default client ID */ |
1362 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7); | 1361 | client_data.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7); |
1363 | client_config.clientid[OPT_DATA] = 1; /* type: ethernet */ | 1362 | client_data.clientid[OPT_DATA] = 1; /* type: ethernet */ |
1364 | clientid_mac_ptr = client_config.clientid + OPT_DATA+1; | 1363 | clientid_mac_ptr = client_data.clientid + OPT_DATA+1; |
1365 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); | 1364 | memcpy(clientid_mac_ptr, client_data.client_mac, 6); |
1366 | } | 1365 | } |
1367 | if (str_V[0] != '\0') { | 1366 | if (str_V[0] != '\0') { |
1368 | // can drop -V, str_V, client_config.vendorclass, | 1367 | // can drop -V, str_V, client_data.vendorclass, |
1369 | // but need to add "vendor" to the list of recognized | 1368 | // but need to add "vendor" to the list of recognized |
1370 | // string opts for this to work; | 1369 | // string opts for this to work; |
1371 | // and need to tweak add_client_options() too... | 1370 | // and need to tweak add_client_options() too... |
1372 | // ...so the question is, should we? | 1371 | // ...so the question is, should we? |
1373 | //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"); |
1374 | client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0); | 1373 | client_data.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0); |
1375 | } | 1374 | } |
1376 | 1375 | ||
1377 | #if !BB_MMU | 1376 | #if !BB_MMU |
@@ -1389,15 +1388,15 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1389 | /* Make sure fd 0,1,2 are open */ | 1388 | /* Make sure fd 0,1,2 are open */ |
1390 | bb_sanitize_stdio(); | 1389 | bb_sanitize_stdio(); |
1391 | /* Create pidfile */ | 1390 | /* Create pidfile */ |
1392 | write_pidfile(client_config.pidfile); | 1391 | write_pidfile(client_data.pidfile); |
1393 | /* Goes to stdout (unless NOMMU) and possibly syslog */ | 1392 | /* Goes to stdout (unless NOMMU) and possibly syslog */ |
1394 | bb_error_msg("started, v"BB_VER); | 1393 | bb_info_msg("started, v"BB_VER); |
1395 | /* Set up the signal pipe */ | 1394 | /* Set up the signal pipe */ |
1396 | udhcp_sp_setup(); | 1395 | udhcp_sp_setup(); |
1397 | /* We want random_xid to be random... */ | 1396 | /* We want random_xid to be random... */ |
1398 | srand(monotonic_us()); | 1397 | srand(monotonic_us()); |
1399 | 1398 | ||
1400 | state = INIT_SELECTING; | 1399 | client_data.state = INIT_SELECTING; |
1401 | udhcp_run_script(NULL, "deconfig"); | 1400 | udhcp_run_script(NULL, "deconfig"); |
1402 | change_listen_mode(LISTEN_RAW); | 1401 | change_listen_mode(LISTEN_RAW); |
1403 | packet_num = 0; | 1402 | packet_num = 0; |
@@ -1415,16 +1414,16 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1415 | /* silence "uninitialized!" warning */ | 1414 | /* silence "uninitialized!" warning */ |
1416 | unsigned timestamp_before_wait = timestamp_before_wait; | 1415 | unsigned timestamp_before_wait = timestamp_before_wait; |
1417 | 1416 | ||
1418 | //bb_error_msg("sockfd:%d, listen_mode:%d", sockfd, listen_mode); | 1417 | //bb_error_msg("sockfd:%d, listen_mode:%d", client_data.sockfd, client_data.listen_mode); |
1419 | 1418 | ||
1420 | /* Was opening raw or udp socket here | 1419 | /* Was opening raw or udp socket here |
1421 | * if (listen_mode != LISTEN_NONE && sockfd < 0), | 1420 | * if (client_data.listen_mode != LISTEN_NONE && client_data.sockfd < 0), |
1422 | * but on fast network renew responses return faster | 1421 | * but on fast network renew responses return faster |
1423 | * than we open sockets. Thus this code is moved | 1422 | * than we open sockets. Thus this code is moved |
1424 | * to change_listen_mode(). Thus we open listen socket | 1423 | * to change_listen_mode(). Thus we open listen socket |
1425 | * BEFORE we send renew request (see "case BOUND:"). */ | 1424 | * BEFORE we send renew request (see "case BOUND:"). */ |
1426 | 1425 | ||
1427 | udhcp_sp_fd_set(pfds, sockfd); | 1426 | udhcp_sp_fd_set(pfds, client_data.sockfd); |
1428 | 1427 | ||
1429 | tv = timeout - already_waited_sec; | 1428 | tv = timeout - already_waited_sec; |
1430 | retval = 0; | 1429 | retval = 0; |
@@ -1453,20 +1452,20 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1453 | * or if the status of the bridge changed). | 1452 | * or if the status of the bridge changed). |
1454 | * Refresh ifindex and client_mac: | 1453 | * Refresh ifindex and client_mac: |
1455 | */ | 1454 | */ |
1456 | if (udhcp_read_interface(client_config.interface, | 1455 | if (udhcp_read_interface(client_data.interface, |
1457 | &client_config.ifindex, | 1456 | &client_data.ifindex, |
1458 | NULL, | 1457 | NULL, |
1459 | client_config.client_mac) | 1458 | client_data.client_mac) |
1460 | ) { | 1459 | ) { |
1461 | goto ret0; /* iface is gone? */ | 1460 | goto ret0; /* iface is gone? */ |
1462 | } | 1461 | } |
1463 | if (clientid_mac_ptr) | 1462 | if (clientid_mac_ptr) |
1464 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); | 1463 | memcpy(clientid_mac_ptr, client_data.client_mac, 6); |
1465 | 1464 | ||
1466 | /* We will restart the wait in any case */ | 1465 | /* We will restart the wait in any case */ |
1467 | already_waited_sec = 0; | 1466 | already_waited_sec = 0; |
1468 | 1467 | ||
1469 | switch (state) { | 1468 | switch (client_data.state) { |
1470 | case INIT_SELECTING: | 1469 | case INIT_SELECTING: |
1471 | if (!discover_retries || packet_num < discover_retries) { | 1470 | if (!discover_retries || packet_num < discover_retries) { |
1472 | if (packet_num == 0) | 1471 | if (packet_num == 0) |
@@ -1481,7 +1480,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1481 | udhcp_run_script(NULL, "leasefail"); | 1480 | udhcp_run_script(NULL, "leasefail"); |
1482 | #if BB_MMU /* -b is not supported on NOMMU */ | 1481 | #if BB_MMU /* -b is not supported on NOMMU */ |
1483 | if (opt & OPT_b) { /* background if no lease */ | 1482 | if (opt & OPT_b) { /* background if no lease */ |
1484 | bb_error_msg("no lease, forking to background"); | 1483 | bb_info_msg("no lease, forking to background"); |
1485 | client_background(); | 1484 | client_background(); |
1486 | /* do not background again! */ | 1485 | /* do not background again! */ |
1487 | opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); | 1486 | opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); |
@@ -1494,7 +1493,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1494 | } else | 1493 | } else |
1495 | #endif | 1494 | #endif |
1496 | if (opt & OPT_n) { /* abort if no lease */ | 1495 | if (opt & OPT_n) { /* abort if no lease */ |
1497 | bb_error_msg("no lease, failing"); | 1496 | bb_info_msg("no lease, failing"); |
1498 | retval = 1; | 1497 | retval = 1; |
1499 | goto ret; | 1498 | goto ret; |
1500 | } | 1499 | } |
@@ -1515,12 +1514,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1515 | * were seen in the wild. Treat them similarly | 1514 | * were seen in the wild. Treat them similarly |
1516 | * to "no response to discover" case */ | 1515 | * to "no response to discover" case */ |
1517 | change_listen_mode(LISTEN_RAW); | 1516 | change_listen_mode(LISTEN_RAW); |
1518 | state = INIT_SELECTING; | 1517 | client_data.state = INIT_SELECTING; |
1519 | goto leasefail; | 1518 | goto leasefail; |
1520 | case BOUND: | 1519 | case BOUND: |
1521 | /* 1/2 lease passed, enter renewing state */ | 1520 | /* 1/2 lease passed, enter renewing state */ |
1522 | state = RENEWING; | 1521 | client_data.state = RENEWING; |
1523 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1522 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1524 | change_listen_mode(LISTEN_KERNEL); | 1523 | change_listen_mode(LISTEN_KERNEL); |
1525 | log1("entering renew state"); | 1524 | log1("entering renew state"); |
1526 | /* fall right through */ | 1525 | /* fall right through */ |
@@ -1556,7 +1555,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1556 | } | 1555 | } |
1557 | /* Timed out or error, enter rebinding state */ | 1556 | /* Timed out or error, enter rebinding state */ |
1558 | log1("entering rebinding state"); | 1557 | log1("entering rebinding state"); |
1559 | state = REBINDING; | 1558 | client_data.state = REBINDING; |
1560 | /* fall right through */ | 1559 | /* fall right through */ |
1561 | case REBINDING: | 1560 | case REBINDING: |
1562 | /* Switch to bcast receive */ | 1561 | /* Switch to bcast receive */ |
@@ -1570,10 +1569,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1570 | continue; | 1569 | continue; |
1571 | } | 1570 | } |
1572 | /* Timed out, enter init state */ | 1571 | /* Timed out, enter init state */ |
1573 | bb_error_msg("lease lost, entering init state"); | 1572 | bb_info_msg("lease lost, entering init state"); |
1574 | udhcp_run_script(NULL, "deconfig"); | 1573 | udhcp_run_script(NULL, "deconfig"); |
1575 | state = INIT_SELECTING; | 1574 | client_data.state = INIT_SELECTING; |
1576 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1575 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1577 | /*timeout = 0; - already is */ | 1576 | /*timeout = 0; - already is */ |
1578 | packet_num = 0; | 1577 | packet_num = 0; |
1579 | continue; | 1578 | continue; |
@@ -1589,10 +1588,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1589 | /* Is it a signal? */ | 1588 | /* Is it a signal? */ |
1590 | switch (udhcp_sp_read()) { | 1589 | switch (udhcp_sp_read()) { |
1591 | case SIGUSR1: | 1590 | case SIGUSR1: |
1592 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1591 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1593 | already_waited_sec = 0; | 1592 | already_waited_sec = 0; |
1594 | perform_renew(); | 1593 | perform_renew(); |
1595 | if (state == RENEW_REQUESTED) { | 1594 | if (client_data.state == RENEW_REQUESTED) { |
1596 | /* We might be either on the same network | 1595 | /* We might be either on the same network |
1597 | * (in which case renew might work), | 1596 | * (in which case renew might work), |
1598 | * or we might be on a completely different one | 1597 | * or we might be on a completely different one |
@@ -1615,7 +1614,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1615 | timeout = INT_MAX; | 1614 | timeout = INT_MAX; |
1616 | continue; | 1615 | continue; |
1617 | case SIGTERM: | 1616 | case SIGTERM: |
1618 | bb_error_msg("received %s", "SIGTERM"); | 1617 | bb_info_msg("received %s", "SIGTERM"); |
1619 | goto ret0; | 1618 | goto ret0; |
1620 | } | 1619 | } |
1621 | 1620 | ||
@@ -1627,15 +1626,15 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1627 | int len; | 1626 | int len; |
1628 | 1627 | ||
1629 | /* A packet is ready, read it */ | 1628 | /* A packet is ready, read it */ |
1630 | if (listen_mode == LISTEN_KERNEL) | 1629 | if (client_data.listen_mode == LISTEN_KERNEL) |
1631 | len = udhcp_recv_kernel_packet(&packet, sockfd); | 1630 | len = udhcp_recv_kernel_packet(&packet, client_data.sockfd); |
1632 | else | 1631 | else |
1633 | len = udhcp_recv_raw_packet(&packet, sockfd); | 1632 | len = udhcp_recv_raw_packet(&packet, client_data.sockfd); |
1634 | if (len == -1) { | 1633 | if (len == -1) { |
1635 | /* Error is severe, reopen socket */ | 1634 | /* Error is severe, reopen socket */ |
1636 | bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); | 1635 | bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); |
1637 | sleep(discover_timeout); /* 3 seconds by default */ | 1636 | sleep(discover_timeout); /* 3 seconds by default */ |
1638 | change_listen_mode(listen_mode); /* just close and reopen */ | 1637 | change_listen_mode(client_data.listen_mode); /* just close and reopen */ |
1639 | } | 1638 | } |
1640 | /* If this packet will turn out to be unrelated/bogus, | 1639 | /* If this packet will turn out to be unrelated/bogus, |
1641 | * we will go back and wait for next one. | 1640 | * we will go back and wait for next one. |
@@ -1653,7 +1652,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1653 | 1652 | ||
1654 | /* Ignore packets that aren't for us */ | 1653 | /* Ignore packets that aren't for us */ |
1655 | if (packet.hlen != 6 | 1654 | if (packet.hlen != 6 |
1656 | || memcmp(packet.chaddr, client_config.client_mac, 6) != 0 | 1655 | || memcmp(packet.chaddr, client_data.client_mac, 6) != 0 |
1657 | ) { | 1656 | ) { |
1658 | //FIXME: need to also check that last 10 bytes are zero | 1657 | //FIXME: need to also check that last 10 bytes are zero |
1659 | log1("chaddr does not match, ignoring packet"); // log2? | 1658 | log1("chaddr does not match, ignoring packet"); // log2? |
@@ -1662,11 +1661,11 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1662 | 1661 | ||
1663 | message = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); | 1662 | message = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); |
1664 | if (message == NULL) { | 1663 | if (message == NULL) { |
1665 | bb_error_msg("no message type option, ignoring packet"); | 1664 | bb_info_msg("no message type option, ignoring packet"); |
1666 | continue; | 1665 | continue; |
1667 | } | 1666 | } |
1668 | 1667 | ||
1669 | switch (state) { | 1668 | switch (client_data.state) { |
1670 | case INIT_SELECTING: | 1669 | case INIT_SELECTING: |
1671 | /* Must be a DHCPOFFER */ | 1670 | /* Must be a DHCPOFFER */ |
1672 | if (*message == DHCPOFFER) { | 1671 | if (*message == DHCPOFFER) { |
@@ -1691,7 +1690,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1691 | * might work too. | 1690 | * might work too. |
1692 | * "Next server" and router are definitely wrong ones to use, though... | 1691 | * "Next server" and router are definitely wrong ones to use, though... |
1693 | */ | 1692 | */ |
1694 | /* We used to ignore pcakets without DHCP_SERVER_ID. | 1693 | /* We used to ignore packets without DHCP_SERVER_ID. |
1695 | * I've got user reports from people who run "address-less" servers. | 1694 | * I've got user reports from people who run "address-less" servers. |
1696 | * They either supply DHCP_SERVER_ID of 0.0.0.0 or don't supply it at all. | 1695 | * They either supply DHCP_SERVER_ID of 0.0.0.0 or don't supply it at all. |
1697 | * They say ISC DHCP client supports this case. | 1696 | * They say ISC DHCP client supports this case. |
@@ -1699,7 +1698,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1699 | server_addr = 0; | 1698 | server_addr = 0; |
1700 | temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); | 1699 | temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); |
1701 | if (!temp) { | 1700 | if (!temp) { |
1702 | bb_error_msg("no server ID, using 0.0.0.0"); | 1701 | bb_info_msg("no server ID, using 0.0.0.0"); |
1703 | } else { | 1702 | } else { |
1704 | /* it IS unaligned sometimes, don't "optimize" */ | 1703 | /* it IS unaligned sometimes, don't "optimize" */ |
1705 | move_from_unaligned32(server_addr, temp); | 1704 | move_from_unaligned32(server_addr, temp); |
@@ -1708,7 +1707,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1708 | requested_ip = packet.yiaddr; | 1707 | requested_ip = packet.yiaddr; |
1709 | 1708 | ||
1710 | /* enter requesting state */ | 1709 | /* enter requesting state */ |
1711 | state = REQUESTING; | 1710 | client_data.state = REQUESTING; |
1712 | timeout = 0; | 1711 | timeout = 0; |
1713 | packet_num = 0; | 1712 | packet_num = 0; |
1714 | already_waited_sec = 0; | 1713 | already_waited_sec = 0; |
@@ -1726,7 +1725,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1726 | 1725 | ||
1727 | temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); | 1726 | temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); |
1728 | if (!temp) { | 1727 | if (!temp) { |
1729 | bb_error_msg("no lease time with ACK, using 1 hour lease"); | 1728 | bb_info_msg("no lease time with ACK, using 1 hour lease"); |
1730 | lease_seconds = 60 * 60; | 1729 | lease_seconds = 60 * 60; |
1731 | } else { | 1730 | } else { |
1732 | /* it IS unaligned sometimes, don't "optimize" */ | 1731 | /* it IS unaligned sometimes, don't "optimize" */ |
@@ -1755,19 +1754,19 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1755 | if (!arpping(packet.yiaddr, | 1754 | if (!arpping(packet.yiaddr, |
1756 | NULL, | 1755 | NULL, |
1757 | (uint32_t) 0, | 1756 | (uint32_t) 0, |
1758 | client_config.client_mac, | 1757 | client_data.client_mac, |
1759 | client_config.interface, | 1758 | client_data.interface, |
1760 | arpping_ms) | 1759 | arpping_ms) |
1761 | ) { | 1760 | ) { |
1762 | bb_error_msg("offered address is in use " | 1761 | bb_info_msg("offered address is in use " |
1763 | "(got ARP reply), declining"); | 1762 | "(got ARP reply), declining"); |
1764 | send_decline(/*xid,*/ server_addr, packet.yiaddr); | 1763 | send_decline(/*xid,*/ server_addr, packet.yiaddr); |
1765 | 1764 | ||
1766 | if (state != REQUESTING) | 1765 | if (client_data.state != REQUESTING) |
1767 | udhcp_run_script(NULL, "deconfig"); | 1766 | udhcp_run_script(NULL, "deconfig"); |
1768 | change_listen_mode(LISTEN_RAW); | 1767 | change_listen_mode(LISTEN_RAW); |
1769 | state = INIT_SELECTING; | 1768 | client_data.state = INIT_SELECTING; |
1770 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1769 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1771 | requested_ip = 0; | 1770 | requested_ip = 0; |
1772 | timeout = tryagain_timeout; | 1771 | timeout = tryagain_timeout; |
1773 | packet_num = 0; | 1772 | packet_num = 0; |
@@ -1778,12 +1777,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1778 | #endif | 1777 | #endif |
1779 | /* enter bound state */ | 1778 | /* enter bound state */ |
1780 | temp_addr.s_addr = packet.yiaddr; | 1779 | temp_addr.s_addr = packet.yiaddr; |
1781 | bb_error_msg("lease of %s obtained, lease time %u", | 1780 | bb_info_msg("lease of %s obtained, lease time %u", |
1782 | inet_ntoa(temp_addr), (unsigned)lease_seconds); | 1781 | inet_ntoa(temp_addr), (unsigned)lease_seconds); |
1783 | requested_ip = packet.yiaddr; | 1782 | requested_ip = packet.yiaddr; |
1784 | 1783 | ||
1785 | start = monotonic_sec(); | 1784 | start = monotonic_sec(); |
1786 | udhcp_run_script(&packet, state == REQUESTING ? "bound" : "renew"); | 1785 | udhcp_run_script(&packet, client_data.state == REQUESTING ? "bound" : "renew"); |
1787 | already_waited_sec = (unsigned)monotonic_sec() - start; | 1786 | already_waited_sec = (unsigned)monotonic_sec() - start; |
1788 | timeout = lease_seconds / 2; | 1787 | timeout = lease_seconds / 2; |
1789 | if ((unsigned)timeout < already_waited_sec) { | 1788 | if ((unsigned)timeout < already_waited_sec) { |
@@ -1791,7 +1790,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1791 | timeout = already_waited_sec = 0; | 1790 | timeout = already_waited_sec = 0; |
1792 | } | 1791 | } |
1793 | 1792 | ||
1794 | state = BOUND; | 1793 | client_data.state = BOUND; |
1795 | change_listen_mode(LISTEN_NONE); | 1794 | change_listen_mode(LISTEN_NONE); |
1796 | if (opt & OPT_q) { /* quit after lease */ | 1795 | if (opt & OPT_q) { /* quit after lease */ |
1797 | goto ret0; | 1796 | goto ret0; |
@@ -1831,14 +1830,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1831 | goto non_matching_svid; | 1830 | goto non_matching_svid; |
1832 | } | 1831 | } |
1833 | /* return to init state */ | 1832 | /* return to init state */ |
1834 | bb_error_msg("received %s", "DHCP NAK"); | 1833 | bb_info_msg("received %s", "DHCP NAK"); |
1835 | udhcp_run_script(&packet, "nak"); | 1834 | udhcp_run_script(&packet, "nak"); |
1836 | if (state != REQUESTING) | 1835 | if (client_data.state != REQUESTING) |
1837 | udhcp_run_script(NULL, "deconfig"); | 1836 | udhcp_run_script(NULL, "deconfig"); |
1838 | change_listen_mode(LISTEN_RAW); | 1837 | change_listen_mode(LISTEN_RAW); |
1839 | sleep(3); /* avoid excessive network traffic */ | 1838 | sleep(3); /* avoid excessive network traffic */ |
1840 | state = INIT_SELECTING; | 1839 | client_data.state = INIT_SELECTING; |
1841 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1840 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1842 | requested_ip = 0; | 1841 | requested_ip = 0; |
1843 | timeout = 0; | 1842 | timeout = 0; |
1844 | packet_num = 0; | 1843 | packet_num = 0; |
@@ -1856,7 +1855,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1856 | perform_release(server_addr, requested_ip); | 1855 | perform_release(server_addr, requested_ip); |
1857 | retval = 0; | 1856 | retval = 0; |
1858 | ret: | 1857 | ret: |
1859 | /*if (client_config.pidfile) - remove_pidfile has its own check */ | 1858 | /*if (client_data.pidfile) - remove_pidfile has its own check */ |
1860 | remove_pidfile(client_config.pidfile); | 1859 | remove_pidfile(client_data.pidfile); |
1861 | return retval; | 1860 | return retval; |
1862 | } | 1861 | } |
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 7fdbc9a6c..42fe71a36 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h | |||
@@ -7,7 +7,7 @@ | |||
7 | 7 | ||
8 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | 8 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
9 | 9 | ||
10 | struct client_config_t { | 10 | struct client_data_t { |
11 | uint8_t client_mac[6]; /* Our mac address */ | 11 | uint8_t client_mac[6]; /* Our mac address */ |
12 | IF_FEATURE_UDHCP_PORT(uint16_t port;) | 12 | IF_FEATURE_UDHCP_PORT(uint16_t port;) |
13 | int ifindex; /* Index number of the interface to use */ | 13 | int ifindex; /* Index number of the interface to use */ |
@@ -24,14 +24,18 @@ struct client_config_t { | |||
24 | 24 | ||
25 | uint16_t first_secs; | 25 | uint16_t first_secs; |
26 | uint16_t last_secs; | 26 | uint16_t last_secs; |
27 | |||
28 | int sockfd; | ||
29 | smallint listen_mode; | ||
30 | smallint state; | ||
27 | } FIX_ALIASING; | 31 | } FIX_ALIASING; |
28 | 32 | ||
29 | /* server_config sits in 1st half of bb_common_bufsiz1 */ | 33 | /* server_config sits in 1st half of bb_common_bufsiz1 */ |
30 | #define client_config (*(struct client_config_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE / 2])) | 34 | #define client_data (*(struct client_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE / 2])) |
31 | 35 | ||
32 | #if ENABLE_FEATURE_UDHCP_PORT | 36 | #if ENABLE_FEATURE_UDHCP_PORT |
33 | #define CLIENT_PORT (client_config.port) | 37 | #define CLIENT_PORT (client_data.port) |
34 | #define CLIENT_PORT6 (client_config.port) | 38 | #define CLIENT_PORT6 (client_data.port) |
35 | #else | 39 | #else |
36 | #define CLIENT_PORT 68 | 40 | #define CLIENT_PORT 68 |
37 | #define CLIENT_PORT6 546 | 41 | #define CLIENT_PORT6 546 |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 0c55fa5e4..058f86bca 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -48,14 +48,25 @@ | |||
48 | #define g_leases ((struct dyn_lease*)ptr_to_globals) | 48 | #define g_leases ((struct dyn_lease*)ptr_to_globals) |
49 | /* struct server_config_t server_config is in bb_common_bufsiz1 */ | 49 | /* struct server_config_t server_config is in bb_common_bufsiz1 */ |
50 | 50 | ||
51 | struct static_lease { | ||
52 | struct static_lease *next; | ||
53 | uint32_t nip; | ||
54 | uint8_t mac[6]; | ||
55 | uint8_t opt[1]; | ||
56 | }; | ||
57 | |||
51 | /* Takes the address of the pointer to the static_leases linked list, | 58 | /* Takes the address of the pointer to the static_leases linked list, |
52 | * address to a 6 byte mac address, | 59 | * address to a 6 byte mac address, |
53 | * 4 byte IP address */ | 60 | * 4 byte IP address */ |
54 | static void add_static_lease(struct static_lease **st_lease_pp, | 61 | static void add_static_lease(struct static_lease **st_lease_pp, |
55 | uint8_t *mac, | 62 | uint8_t *mac, |
56 | uint32_t nip) | 63 | uint32_t nip, |
64 | const char *opts) | ||
57 | { | 65 | { |
58 | struct static_lease *st_lease; | 66 | struct static_lease *st_lease; |
67 | unsigned optlen; | ||
68 | |||
69 | optlen = (opts ? 1+1+strnlen(opts, 120) : 0); | ||
59 | 70 | ||
60 | /* Find the tail of the list */ | 71 | /* Find the tail of the list */ |
61 | while ((st_lease = *st_lease_pp) != NULL) { | 72 | while ((st_lease = *st_lease_pp) != NULL) { |
@@ -63,15 +74,34 @@ static void add_static_lease(struct static_lease **st_lease_pp, | |||
63 | } | 74 | } |
64 | 75 | ||
65 | /* Add new node */ | 76 | /* Add new node */ |
66 | *st_lease_pp = st_lease = xzalloc(sizeof(*st_lease)); | 77 | *st_lease_pp = st_lease = xzalloc(sizeof(*st_lease) + optlen); |
67 | memcpy(st_lease->mac, mac, 6); | 78 | memcpy(st_lease->mac, mac, 6); |
68 | st_lease->nip = nip; | 79 | st_lease->nip = nip; |
69 | /*st_lease->next = NULL;*/ | 80 | /*st_lease->next = NULL;*/ |
81 | if (optlen) { | ||
82 | st_lease->opt[OPT_CODE] = DHCP_HOST_NAME; | ||
83 | optlen -= 2; | ||
84 | st_lease->opt[OPT_LEN] = optlen; | ||
85 | memcpy(&st_lease->opt[OPT_DATA], opts, optlen); | ||
86 | } | ||
87 | |||
88 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 | ||
89 | /* Print out static leases just to check what's going on */ | ||
90 | if (dhcp_verbose >= 2) { | ||
91 | bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", | ||
92 | st_lease->mac[0], st_lease->mac[1], st_lease->mac[2], | ||
93 | st_lease->mac[3], st_lease->mac[4], st_lease->mac[5], | ||
94 | st_lease->nip | ||
95 | ); | ||
96 | } | ||
97 | #endif | ||
70 | } | 98 | } |
71 | 99 | ||
72 | /* Find static lease IP by mac */ | 100 | /* Find static lease IP by mac */ |
73 | static uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *mac) | 101 | static uint32_t get_static_nip_by_mac(void *mac) |
74 | { | 102 | { |
103 | struct static_lease *st_lease = server_config.static_leases; | ||
104 | |||
75 | while (st_lease) { | 105 | while (st_lease) { |
76 | if (memcmp(st_lease->mac, mac, 6) == 0) | 106 | if (memcmp(st_lease->mac, mac, 6) == 0) |
77 | return st_lease->nip; | 107 | return st_lease->nip; |
@@ -81,8 +111,10 @@ static uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *mac) | |||
81 | return 0; | 111 | return 0; |
82 | } | 112 | } |
83 | 113 | ||
84 | static int is_nip_reserved(struct static_lease *st_lease, uint32_t nip) | 114 | static int is_nip_reserved_as_static(uint32_t nip) |
85 | { | 115 | { |
116 | struct static_lease *st_lease = server_config.static_leases; | ||
117 | |||
86 | while (st_lease) { | 118 | while (st_lease) { |
87 | if (st_lease->nip == nip) | 119 | if (st_lease->nip == nip) |
88 | return 1; | 120 | return 1; |
@@ -92,30 +124,6 @@ static int is_nip_reserved(struct static_lease *st_lease, uint32_t nip) | |||
92 | return 0; | 124 | return 0; |
93 | } | 125 | } |
94 | 126 | ||
95 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 | ||
96 | /* Print out static leases just to check what's going on */ | ||
97 | /* Takes the address of the pointer to the static_leases linked list */ | ||
98 | static void log_static_leases(struct static_lease **st_lease_pp) | ||
99 | { | ||
100 | struct static_lease *cur; | ||
101 | |||
102 | if (dhcp_verbose < 2) | ||
103 | return; | ||
104 | |||
105 | cur = *st_lease_pp; | ||
106 | while (cur) { | ||
107 | bb_error_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", | ||
108 | cur->mac[0], cur->mac[1], cur->mac[2], | ||
109 | cur->mac[3], cur->mac[4], cur->mac[5], | ||
110 | cur->nip | ||
111 | ); | ||
112 | cur = cur->next; | ||
113 | } | ||
114 | } | ||
115 | #else | ||
116 | # define log_static_leases(st_lease_pp) ((void)0) | ||
117 | #endif | ||
118 | |||
119 | /* Find the oldest expired lease, NULL if there are no expired leases */ | 127 | /* Find the oldest expired lease, NULL if there are no expired leases */ |
120 | static struct dyn_lease *oldest_expired_lease(void) | 128 | static struct dyn_lease *oldest_expired_lease(void) |
121 | { | 129 | { |
@@ -242,7 +250,7 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigne | |||
242 | return r; | 250 | return r; |
243 | 251 | ||
244 | temp.s_addr = nip; | 252 | temp.s_addr = nip; |
245 | bb_error_msg("%s belongs to someone, reserving it for %u seconds", | 253 | bb_info_msg("%s belongs to someone, reserving it for %u seconds", |
246 | inet_ntoa(temp), (unsigned)server_config.conflict_time); | 254 | inet_ntoa(temp), (unsigned)server_config.conflict_time); |
247 | add_lease(NULL, nip, server_config.conflict_time, NULL, 0); | 255 | add_lease(NULL, nip, server_config.conflict_time, NULL, 0); |
248 | return 0; | 256 | return 0; |
@@ -288,7 +296,7 @@ static uint32_t find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arppi | |||
288 | if (nip == server_config.server_nip) | 296 | if (nip == server_config.server_nip) |
289 | goto next_addr; | 297 | goto next_addr; |
290 | /* is this a static lease addr? */ | 298 | /* is this a static lease addr? */ |
291 | if (is_nip_reserved(server_config.static_leases, nip)) | 299 | if (is_nip_reserved_as_static(nip)) |
292 | goto next_addr; | 300 | goto next_addr; |
293 | 301 | ||
294 | lease = find_lease_by_nip(nip); | 302 | lease = find_lease_by_nip(nip); |
@@ -340,6 +348,7 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg) | |||
340 | char *line; | 348 | char *line; |
341 | char *mac_string; | 349 | char *mac_string; |
342 | char *ip_string; | 350 | char *ip_string; |
351 | char *opts; | ||
343 | struct ether_addr mac_bytes; /* it's "struct { uint8_t mac[6]; }" */ | 352 | struct ether_addr mac_bytes; /* it's "struct { uint8_t mac[6]; }" */ |
344 | uint32_t nip; | 353 | uint32_t nip; |
345 | 354 | ||
@@ -354,14 +363,16 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg) | |||
354 | if (!ip_string || !udhcp_str2nip(ip_string, &nip)) | 363 | if (!ip_string || !udhcp_str2nip(ip_string, &nip)) |
355 | return 0; | 364 | return 0; |
356 | 365 | ||
357 | add_static_lease(arg, (uint8_t*) &mac_bytes, nip); | 366 | opts = strtok_r(NULL, " \t", &line); |
367 | /* opts might be NULL, that's not an error */ | ||
358 | 368 | ||
359 | log_static_leases(arg); | 369 | add_static_lease(arg, (uint8_t*) &mac_bytes, nip, opts); |
360 | 370 | ||
361 | return 1; | 371 | return 1; |
362 | } | 372 | } |
363 | 373 | ||
364 | static int FAST_FUNC read_optset(const char *line, void *arg) { | 374 | static int FAST_FUNC read_optset(const char *line, void *arg) |
375 | { | ||
365 | return udhcp_str2optset(line, arg, | 376 | return udhcp_str2optset(line, arg, |
366 | dhcp_optflags, dhcp_option_strings, | 377 | dhcp_optflags, dhcp_option_strings, |
367 | /*dhcpv6:*/ 0 | 378 | /*dhcpv6:*/ 0 |
@@ -518,13 +529,13 @@ static NOINLINE void read_leases(const char *file) | |||
518 | expires = 0; | 529 | expires = 0; |
519 | 530 | ||
520 | /* Check if there is a different static lease for this IP or MAC */ | 531 | /* Check if there is a different static lease for this IP or MAC */ |
521 | static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac); | 532 | static_nip = get_static_nip_by_mac(lease.lease_mac); |
522 | if (static_nip) { | 533 | if (static_nip) { |
523 | /* NB: we do not add lease even if static_nip == lease.lease_nip. | 534 | /* NB: we do not add lease even if static_nip == lease.lease_nip. |
524 | */ | 535 | */ |
525 | continue; | 536 | continue; |
526 | } | 537 | } |
527 | if (is_nip_reserved(server_config.static_leases, lease.lease_nip)) | 538 | if (is_nip_reserved_as_static(lease.lease_nip)) |
528 | continue; | 539 | continue; |
529 | 540 | ||
530 | /* NB: add_lease takes "relative time", IOW, | 541 | /* NB: add_lease takes "relative time", IOW, |
@@ -602,6 +613,15 @@ static void send_packet(struct dhcp_packet *dhcp_pkt, int force_broadcast) | |||
602 | send_packet_to_client(dhcp_pkt, force_broadcast); | 613 | send_packet_to_client(dhcp_pkt, force_broadcast); |
603 | } | 614 | } |
604 | 615 | ||
616 | static void send_packet_verbose(struct dhcp_packet *dhcp_pkt, const char *fmt) | ||
617 | { | ||
618 | struct in_addr addr; | ||
619 | addr.s_addr = dhcp_pkt->yiaddr; | ||
620 | bb_info_msg(fmt, inet_ntoa(addr)); | ||
621 | /* send_packet emits error message itself if it detects failure */ | ||
622 | send_packet(dhcp_pkt, /*force_bcast:*/ 0); | ||
623 | } | ||
624 | |||
605 | static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacket, char type) | 625 | static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacket, char type) |
606 | { | 626 | { |
607 | /* Sets op, htype, hlen, cookie fields | 627 | /* Sets op, htype, hlen, cookie fields |
@@ -621,14 +641,49 @@ static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacke | |||
621 | */ | 641 | */ |
622 | static void add_server_options(struct dhcp_packet *packet) | 642 | static void add_server_options(struct dhcp_packet *packet) |
623 | { | 643 | { |
624 | struct option_set *curr = server_config.options; | 644 | struct option_set *config_opts; |
645 | uint8_t *client_hostname_opt; | ||
646 | |||
647 | client_hostname_opt = NULL; | ||
648 | if (packet->yiaddr) { /* if we aren't from send_inform()... */ | ||
649 | struct static_lease *st_lease = server_config.static_leases; | ||
650 | while (st_lease) { | ||
651 | if (st_lease->nip == packet->yiaddr) { | ||
652 | if (st_lease->opt[0] != 0) | ||
653 | client_hostname_opt = st_lease->opt; | ||
654 | break; | ||
655 | } | ||
656 | st_lease = st_lease->next; | ||
657 | } | ||
658 | } | ||
625 | 659 | ||
626 | while (curr) { | 660 | config_opts = server_config.options; |
627 | if (curr->data[OPT_CODE] != DHCP_LEASE_TIME) | 661 | while (config_opts) { |
628 | udhcp_add_binary_option(packet, curr->data); | 662 | if (config_opts->data[OPT_CODE] != DHCP_LEASE_TIME) { |
629 | curr = curr->next; | 663 | /* ^^^^ |
664 | * DHCP_LEASE_TIME is already filled, or in case of | ||
665 | * send_inform(), should not be filled at all. | ||
666 | */ | ||
667 | if (config_opts->data[OPT_CODE] != DHCP_HOST_NAME | ||
668 | || !client_hostname_opt | ||
669 | ) { | ||
670 | /* Why "!client_hostname_opt": | ||
671 | * add hostname only if client has no hostname | ||
672 | * on its static lease line. | ||
673 | * (Not that "opt hostname HOST" | ||
674 | * makes much sense in udhcpd.conf, | ||
675 | * that'd give all clients the same hostname, | ||
676 | * but it's a valid configuration). | ||
677 | */ | ||
678 | udhcp_add_binary_option(packet, config_opts->data); | ||
679 | } | ||
680 | } | ||
681 | config_opts = config_opts->next; | ||
630 | } | 682 | } |
631 | 683 | ||
684 | if (client_hostname_opt) | ||
685 | udhcp_add_binary_option(packet, client_hostname_opt); | ||
686 | |||
632 | packet->siaddr_nip = server_config.siaddr_nip; | 687 | packet->siaddr_nip = server_config.siaddr_nip; |
633 | 688 | ||
634 | if (server_config.sname) | 689 | if (server_config.sname) |
@@ -657,12 +712,11 @@ static uint32_t select_lease_time(struct dhcp_packet *packet) | |||
657 | static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | 712 | static NOINLINE void send_offer(struct dhcp_packet *oldpacket, |
658 | uint32_t static_lease_nip, | 713 | uint32_t static_lease_nip, |
659 | struct dyn_lease *lease, | 714 | struct dyn_lease *lease, |
660 | uint8_t *requested_ip_opt, | 715 | uint32_t requested_nip, |
661 | unsigned arpping_ms) | 716 | unsigned arpping_ms) |
662 | { | 717 | { |
663 | struct dhcp_packet packet; | 718 | struct dhcp_packet packet; |
664 | uint32_t lease_time_sec; | 719 | uint32_t lease_time_sec; |
665 | struct in_addr addr; | ||
666 | 720 | ||
667 | init_packet(&packet, oldpacket, DHCPOFFER); | 721 | init_packet(&packet, oldpacket, DHCPOFFER); |
668 | 722 | ||
@@ -671,7 +725,6 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | |||
671 | /* Else: */ | 725 | /* Else: */ |
672 | if (!static_lease_nip) { | 726 | if (!static_lease_nip) { |
673 | /* We have no static lease for client's chaddr */ | 727 | /* We have no static lease for client's chaddr */ |
674 | uint32_t req_nip; | ||
675 | const char *p_host_name; | 728 | const char *p_host_name; |
676 | 729 | ||
677 | if (lease) { | 730 | if (lease) { |
@@ -682,18 +735,16 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | |||
682 | packet.yiaddr = lease->lease_nip; | 735 | packet.yiaddr = lease->lease_nip; |
683 | } | 736 | } |
684 | /* Or: if client has requested an IP */ | 737 | /* Or: if client has requested an IP */ |
685 | else if (requested_ip_opt != NULL | 738 | else if (requested_nip != 0 |
686 | /* (read IP) */ | ||
687 | && (move_from_unaligned32(req_nip, requested_ip_opt), 1) | ||
688 | /* and the IP is in the lease range */ | 739 | /* and the IP is in the lease range */ |
689 | && ntohl(req_nip) >= server_config.start_ip | 740 | && ntohl(requested_nip) >= server_config.start_ip |
690 | && ntohl(req_nip) <= server_config.end_ip | 741 | && ntohl(requested_nip) <= server_config.end_ip |
691 | /* and */ | 742 | /* and */ |
692 | && ( !(lease = find_lease_by_nip(req_nip)) /* is not already taken */ | 743 | && ( !(lease = find_lease_by_nip(requested_nip)) /* is not already taken */ |
693 | || is_expired_lease(lease) /* or is taken, but expired */ | 744 | || is_expired_lease(lease) /* or is taken, but expired */ |
694 | ) | 745 | ) |
695 | ) { | 746 | ) { |
696 | packet.yiaddr = req_nip; | 747 | packet.yiaddr = requested_nip; |
697 | } | 748 | } |
698 | else { | 749 | else { |
699 | /* Otherwise, find a free IP */ | 750 | /* Otherwise, find a free IP */ |
@@ -721,10 +772,8 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | |||
721 | udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec)); | 772 | udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec)); |
722 | add_server_options(&packet); | 773 | add_server_options(&packet); |
723 | 774 | ||
724 | addr.s_addr = packet.yiaddr; | ||
725 | bb_error_msg("sending OFFER of %s", inet_ntoa(addr)); | ||
726 | /* send_packet emits error message itself if it detects failure */ | 775 | /* send_packet emits error message itself if it detects failure */ |
727 | send_packet(&packet, /*force_bcast:*/ 0); | 776 | send_packet_verbose(&packet, "sending OFFER to %s"); |
728 | } | 777 | } |
729 | 778 | ||
730 | /* NOINLINE: limit stack usage in caller */ | 779 | /* NOINLINE: limit stack usage in caller */ |
@@ -743,7 +792,6 @@ static NOINLINE void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr) | |||
743 | { | 792 | { |
744 | struct dhcp_packet packet; | 793 | struct dhcp_packet packet; |
745 | uint32_t lease_time_sec; | 794 | uint32_t lease_time_sec; |
746 | struct in_addr addr; | ||
747 | const char *p_host_name; | 795 | const char *p_host_name; |
748 | 796 | ||
749 | init_packet(&packet, oldpacket, DHCPACK); | 797 | init_packet(&packet, oldpacket, DHCPACK); |
@@ -751,12 +799,9 @@ static NOINLINE void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr) | |||
751 | 799 | ||
752 | lease_time_sec = select_lease_time(oldpacket); | 800 | lease_time_sec = select_lease_time(oldpacket); |
753 | udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec)); | 801 | udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec)); |
754 | |||
755 | add_server_options(&packet); | 802 | add_server_options(&packet); |
756 | 803 | ||
757 | addr.s_addr = yiaddr; | 804 | send_packet_verbose(&packet, "sending ACK to %s"); |
758 | bb_error_msg("sending ACK to %s", inet_ntoa(addr)); | ||
759 | send_packet(&packet, /*force_bcast:*/ 0); | ||
760 | 805 | ||
761 | p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME); | 806 | p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME); |
762 | add_lease(packet.chaddr, packet.yiaddr, | 807 | add_lease(packet.chaddr, packet.yiaddr, |
@@ -796,6 +841,7 @@ static NOINLINE void send_inform(struct dhcp_packet *oldpacket) | |||
796 | add_server_options(&packet); | 841 | add_server_options(&packet); |
797 | 842 | ||
798 | send_packet(&packet, /*force_bcast:*/ 0); | 843 | send_packet(&packet, /*force_bcast:*/ 0); |
844 | // or maybe? send_packet_verbose(&packet, "sending ACK to %s"); | ||
799 | } | 845 | } |
800 | 846 | ||
801 | int udhcpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 847 | int udhcpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
@@ -865,7 +911,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
865 | write_pidfile(server_config.pidfile); | 911 | write_pidfile(server_config.pidfile); |
866 | /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ | 912 | /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ |
867 | 913 | ||
868 | bb_error_msg("started, v"BB_VER); | 914 | bb_info_msg("started, v"BB_VER); |
869 | 915 | ||
870 | option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME); | 916 | option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME); |
871 | server_config.max_lease_sec = DEFAULT_LEASE_TIME; | 917 | server_config.max_lease_sec = DEFAULT_LEASE_TIME; |
@@ -908,7 +954,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
908 | int tv; | 954 | int tv; |
909 | uint8_t *server_id_opt; | 955 | uint8_t *server_id_opt; |
910 | uint8_t *requested_ip_opt; | 956 | uint8_t *requested_ip_opt; |
911 | uint32_t requested_nip = requested_nip; /* for compiler */ | 957 | uint32_t requested_nip; |
912 | uint32_t static_lease_nip; | 958 | uint32_t static_lease_nip; |
913 | struct dyn_lease *lease, fake_lease; | 959 | struct dyn_lease *lease, fake_lease; |
914 | 960 | ||
@@ -944,12 +990,12 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
944 | 990 | ||
945 | if (pfds[0].revents) switch (udhcp_sp_read()) { | 991 | if (pfds[0].revents) switch (udhcp_sp_read()) { |
946 | case SIGUSR1: | 992 | case SIGUSR1: |
947 | bb_error_msg("received %s", "SIGUSR1"); | 993 | bb_info_msg("received %s", "SIGUSR1"); |
948 | write_leases(); | 994 | write_leases(); |
949 | /* why not just reset the timeout, eh */ | 995 | /* why not just reset the timeout, eh */ |
950 | goto continue_with_autotime; | 996 | goto continue_with_autotime; |
951 | case SIGTERM: | 997 | case SIGTERM: |
952 | bb_error_msg("received %s", "SIGTERM"); | 998 | bb_info_msg("received %s", "SIGTERM"); |
953 | write_leases(); | 999 | write_leases(); |
954 | goto ret0; | 1000 | goto ret0; |
955 | } | 1001 | } |
@@ -973,16 +1019,16 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
973 | continue; | 1019 | continue; |
974 | } | 1020 | } |
975 | if (packet.hlen != 6) { | 1021 | if (packet.hlen != 6) { |
976 | bb_error_msg("MAC length != 6, ignoring packet"); | 1022 | bb_info_msg("MAC length != 6, ignoring packet"); |
977 | continue; | 1023 | continue; |
978 | } | 1024 | } |
979 | if (packet.op != BOOTREQUEST) { | 1025 | if (packet.op != BOOTREQUEST) { |
980 | bb_error_msg("not a REQUEST, ignoring packet"); | 1026 | bb_info_msg("not a REQUEST, ignoring packet"); |
981 | continue; | 1027 | continue; |
982 | } | 1028 | } |
983 | state = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); | 1029 | state = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); |
984 | if (state == NULL || state[0] < DHCP_MINTYPE || state[0] > DHCP_MAXTYPE) { | 1030 | if (state == NULL || state[0] < DHCP_MINTYPE || state[0] > DHCP_MAXTYPE) { |
985 | bb_error_msg("no or bad message type option, ignoring packet"); | 1031 | bb_info_msg("no or bad message type option, ignoring packet"); |
986 | continue; | 1032 | continue; |
987 | } | 1033 | } |
988 | 1034 | ||
@@ -999,9 +1045,9 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
999 | } | 1045 | } |
1000 | 1046 | ||
1001 | /* Look for a static/dynamic lease */ | 1047 | /* Look for a static/dynamic lease */ |
1002 | static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr); | 1048 | static_lease_nip = get_static_nip_by_mac(&packet.chaddr); |
1003 | if (static_lease_nip) { | 1049 | if (static_lease_nip) { |
1004 | bb_error_msg("found static lease: %x", static_lease_nip); | 1050 | bb_info_msg("found static lease: %x", static_lease_nip); |
1005 | memcpy(&fake_lease.lease_mac, &packet.chaddr, 6); | 1051 | memcpy(&fake_lease.lease_mac, &packet.chaddr, 6); |
1006 | fake_lease.lease_nip = static_lease_nip; | 1052 | fake_lease.lease_nip = static_lease_nip; |
1007 | fake_lease.expires = 0; | 1053 | fake_lease.expires = 0; |
@@ -1011,6 +1057,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
1011 | } | 1057 | } |
1012 | 1058 | ||
1013 | /* Get REQUESTED_IP if present */ | 1059 | /* Get REQUESTED_IP if present */ |
1060 | requested_nip = 0; | ||
1014 | requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP); | 1061 | requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP); |
1015 | if (requested_ip_opt) { | 1062 | if (requested_ip_opt) { |
1016 | move_from_unaligned32(requested_nip, requested_ip_opt); | 1063 | move_from_unaligned32(requested_nip, requested_ip_opt); |
@@ -1021,7 +1068,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
1021 | case DHCPDISCOVER: | 1068 | case DHCPDISCOVER: |
1022 | log1("received %s", "DISCOVER"); | 1069 | log1("received %s", "DISCOVER"); |
1023 | 1070 | ||
1024 | send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms); | 1071 | send_offer(&packet, static_lease_nip, lease, requested_nip, arpping_ms); |
1025 | break; | 1072 | break; |
1026 | 1073 | ||
1027 | case DHCPREQUEST: | 1074 | case DHCPREQUEST: |
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index b8f96b029..ba11d77e8 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
@@ -15,11 +15,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | |||
15 | #define DHCPD_CONF_FILE "/etc/udhcpd.conf" | 15 | #define DHCPD_CONF_FILE "/etc/udhcpd.conf" |
16 | 16 | ||
17 | 17 | ||
18 | struct static_lease { | 18 | struct static_lease; |
19 | struct static_lease *next; | ||
20 | uint32_t nip; | ||
21 | uint8_t mac[6]; | ||
22 | }; | ||
23 | 19 | ||
24 | struct server_config_t { | 20 | struct server_config_t { |
25 | char *interface; /* interface to use */ | 21 | char *interface; /* interface to use */ |
@@ -58,7 +54,7 @@ struct server_config_t { | |||
58 | } FIX_ALIASING; | 54 | } FIX_ALIASING; |
59 | 55 | ||
60 | #define server_config (*(struct server_config_t*)bb_common_bufsiz1) | 56 | #define server_config (*(struct server_config_t*)bb_common_bufsiz1) |
61 | /* client_config sits in 2nd half of bb_common_bufsiz1 */ | 57 | /* client_data sits in 2nd half of bb_common_bufsiz1 */ |
62 | 58 | ||
63 | #if ENABLE_FEATURE_UDHCP_PORT | 59 | #if ENABLE_FEATURE_UDHCP_PORT |
64 | #define SERVER_PORT (server_config.port) | 60 | #define SERVER_PORT (server_config.port) |
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index ff16904f7..64af802a3 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c | |||
@@ -40,7 +40,7 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet) | |||
40 | if (dhcp_verbose < 2) | 40 | if (dhcp_verbose < 2) |
41 | return; | 41 | return; |
42 | 42 | ||
43 | bb_error_msg( | 43 | bb_info_msg( |
44 | //" op %x" | 44 | //" op %x" |
45 | //" htype %x" | 45 | //" htype %x" |
46 | " hlen %x" | 46 | " hlen %x" |
@@ -73,7 +73,7 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet) | |||
73 | //, packet->options[] | 73 | //, packet->options[] |
74 | ); | 74 | ); |
75 | *bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0'; | 75 | *bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0'; |
76 | bb_error_msg(" chaddr %s", buf); | 76 | bb_info_msg(" chaddr %s", buf); |
77 | } | 77 | } |
78 | #endif | 78 | #endif |
79 | 79 | ||
@@ -92,7 +92,7 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd) | |||
92 | if (bytes < offsetof(struct dhcp_packet, options) | 92 | if (bytes < offsetof(struct dhcp_packet, options) |
93 | || packet->cookie != htonl(DHCP_MAGIC) | 93 | || packet->cookie != htonl(DHCP_MAGIC) |
94 | ) { | 94 | ) { |
95 | bb_error_msg("packet with bad magic, ignoring"); | 95 | bb_info_msg("packet with bad magic, ignoring"); |
96 | return -2; | 96 | return -2; |
97 | } | 97 | } |
98 | log1("received %s", "a packet"); | 98 | log1("received %s", "a packet"); |
diff --git a/networking/wget.c b/networking/wget.c index d907cee30..44cec2cb5 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -312,7 +312,7 @@ static void progress_meter(int flag) | |||
312 | } | 312 | } |
313 | } | 313 | } |
314 | #else | 314 | #else |
315 | static ALWAYS_INLINE void progress_meter(int flag UNUSED_PARAM) { } | 315 | static ALWAYS_INLINE void progress_meter(int flag UNUSED_PARAM) {} |
316 | #endif | 316 | #endif |
317 | 317 | ||
318 | 318 | ||
diff --git a/networking/zcip.c b/networking/zcip.c index 434762f12..f95b6f7fb 100644 --- a/networking/zcip.c +++ b/networking/zcip.c | |||
@@ -195,7 +195,7 @@ static int run(char *argv[3], const char *param, uint32_t nip) | |||
195 | putenv(env_ip); | 195 | putenv(env_ip); |
196 | fmt -= 3; | 196 | fmt -= 3; |
197 | } | 197 | } |
198 | bb_error_msg(fmt, argv[2], argv[0], addr); | 198 | bb_info_msg(fmt, argv[2], argv[0], addr); |
199 | status = spawn_and_wait(argv + 1); | 199 | status = spawn_and_wait(argv + 1); |
200 | if (nip != 0) | 200 | if (nip != 0) |
201 | bb_unsetenv_and_free(env_ip); | 201 | bb_unsetenv_and_free(env_ip); |
@@ -339,7 +339,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv) | |||
339 | #if BB_MMU | 339 | #if BB_MMU |
340 | bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/); | 340 | bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/); |
341 | #endif | 341 | #endif |
342 | bb_error_msg("start, interface %s", argv_intf); | 342 | bb_info_msg("start, interface %s", argv_intf); |
343 | } | 343 | } |
344 | 344 | ||
345 | // Run the dynamic address negotiation protocol, | 345 | // Run the dynamic address negotiation protocol, |