aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2016-04-04 16:22:54 +0100
committerRon Yorston <rmy@pobox.com>2016-04-04 16:22:54 +0100
commit253dbd612b2d2f041f4263e15a3b94df70f41e36 (patch)
treef6c6e12a0541233058a7f7ccb1251afeb457da06 /networking
parent3cf56a021d7a62512b477640e930e1a78288075c (diff)
parentd7d4750e1e213e7448147186dddfe3bfbb47eea0 (diff)
downloadbusybox-w32-253dbd612b2d2f041f4263e15a3b94df70f41e36.tar.gz
busybox-w32-253dbd612b2d2f041f4263e15a3b94df70f41e36.tar.bz2
busybox-w32-253dbd612b2d2f041f4263e15a3b94df70f41e36.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'networking')
-rw-r--r--networking/ifupdown.c17
-rw-r--r--networking/inetd.c8
-rw-r--r--networking/ntpd.c50
-rw-r--r--networking/ntpd.diff24
-rw-r--r--networking/traceroute.c2
-rw-r--r--networking/tunctl.c2
-rw-r--r--networking/udhcp/arpping.c2
-rw-r--r--networking/udhcp/common.c27
-rw-r--r--networking/udhcp/common.h6
-rw-r--r--networking/udhcp/d6_dhcpc.c60
-rw-r--r--networking/udhcp/d6_packet.c12
-rw-r--r--networking/udhcp/d6_socket.c2
-rw-r--r--networking/udhcp/dhcpc.c88
-rw-r--r--networking/udhcp/dhcpd.c34
-rw-r--r--networking/udhcp/domain_codec.c21
-rw-r--r--networking/udhcp/files.c8
-rw-r--r--networking/udhcp/leases.c6
-rw-r--r--networking/udhcp/packet.c12
-rw-r--r--networking/udhcp/socket.c4
-rw-r--r--networking/udhcp/static_leases.c2
-rw-r--r--networking/wget.c22
-rw-r--r--networking/zcip.c4
22 files changed, 262 insertions, 151 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 766dfabbd..2c6db926f 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -850,7 +850,6 @@ static struct interfaces_file_t *read_interfaces(const char *filename, struct in
850 char *iface_name; 850 char *iface_name;
851 char *address_family_name; 851 char *address_family_name;
852 char *method_name; 852 char *method_name;
853 llist_t *iface_list;
854 853
855 currif = xzalloc(sizeof(*currif)); 854 currif = xzalloc(sizeof(*currif));
856 iface_name = next_word(&rest_of_line); 855 iface_name = next_word(&rest_of_line);
@@ -875,7 +874,20 @@ static struct interfaces_file_t *read_interfaces(const char *filename, struct in
875 currif->method = get_method(currif->address_family, method_name); 874 currif->method = get_method(currif->address_family, method_name);
876 if (!currif->method) 875 if (!currif->method)
877 bb_error_msg_and_die("unknown method \"%s\"", method_name); 876 bb_error_msg_and_die("unknown method \"%s\"", method_name);
878 877#if 0
878// Allegedly, Debian allows a duplicate definition:
879// iface eth0 inet static
880// address 192.168.0.15
881// netmask 255.255.0.0
882// gateway 192.168.0.1
883//
884// iface eth0 inet static
885// address 10.0.0.1
886// netmask 255.255.255.0
887//
888// This adds *two* addresses to eth0 (probably requires use of "ip", not "ifconfig"
889//
890 llist_t *iface_list;
879 for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) { 891 for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) {
880 struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data; 892 struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data;
881 if ((strcmp(tmp->iface, currif->iface) == 0) 893 if ((strcmp(tmp->iface, currif->iface) == 0)
@@ -884,6 +896,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename, struct in
884 bb_error_msg_and_die("duplicate interface \"%s\"", tmp->iface); 896 bb_error_msg_and_die("duplicate interface \"%s\"", tmp->iface);
885 } 897 }
886 } 898 }
899#endif
887 llist_add_to_end(&(defn->ifaces), (char*)currif); 900 llist_add_to_end(&(defn->ifaces), (char*)currif);
888 901
889 debug_noise("iface %s %s %s\n", currif->iface, address_family_name, method_name); 902 debug_noise("iface %s %s %s\n", currif->iface, address_family_name, method_name);
diff --git a/networking/inetd.c b/networking/inetd.c
index 243165a07..4f6673b12 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -834,10 +834,10 @@ static NOINLINE servtab_t *parse_one_line(void)
834 goto parse_err; 834 goto parse_err;
835 } 835 }
836 836
837// bb_info_msg( 837 //bb_error_msg(
838// "ENTRY[%s][%s][%s][%d][%d][%d][%d][%d][%s][%s][%s]", 838 // "ENTRY[%s][%s][%s][%d][%d][%d][%d][%d][%s][%s][%s]",
839// sep->se_local_hostname, sep->se_service, sep->se_proto, sep->se_wait, sep->se_proto_no, 839 // sep->se_local_hostname, sep->se_service, sep->se_proto, sep->se_wait, sep->se_proto_no,
840// sep->se_max, sep->se_count, sep->se_time, sep->se_user, sep->se_group, sep->se_program); 840 // sep->se_max, sep->se_count, sep->se_time, sep->se_user, sep->se_group, sep->se_program);
841 841
842 /* check if the hostname specifier is a comma separated list 842 /* check if the hostname specifier is a comma separated list
843 * of hostnames. we'll make new entries for each address. */ 843 * of hostnames. we'll make new entries for each address. */
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 1651670d9..410318979 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -267,6 +267,7 @@ typedef struct {
267 267
268typedef struct { 268typedef struct {
269 len_and_sockaddr *p_lsa; 269 len_and_sockaddr *p_lsa;
270 char *p_hostname;
270 char *p_dotted; 271 char *p_dotted;
271 int p_fd; 272 int p_fd;
272 int datapoint_idx; 273 int datapoint_idx;
@@ -727,7 +728,7 @@ reset_peer_stats(peer_t *p, double offset)
727 728
728 /* Used to set p->filter_datapoint[i].d_dispersion = MAXDISP 729 /* Used to set p->filter_datapoint[i].d_dispersion = MAXDISP
729 * and clear reachable bits, but this proved to be too agressive: 730 * and clear reachable bits, but this proved to be too agressive:
730 * after step (tested with suspinding laptop for ~30 secs), 731 * after step (tested with suspending laptop for ~30 secs),
731 * this caused all previous data to be considered invalid, 732 * this caused all previous data to be considered invalid,
732 * making us needing to collect full ~8 datapoins per peer 733 * making us needing to collect full ~8 datapoins per peer
733 * after step in order to start trusting them. 734 * after step in order to start trusting them.
@@ -766,11 +767,29 @@ reset_peer_stats(peer_t *p, double offset)
766static void 767static void
767add_peers(const char *s) 768add_peers(const char *s)
768{ 769{
770 llist_t *item;
769 peer_t *p; 771 peer_t *p;
770 772
771 p = xzalloc(sizeof(*p)); 773 p = xzalloc(sizeof(*p));
772 p->p_lsa = xhost2sockaddr(s, 123); 774 p->p_lsa = xhost2sockaddr(s, 123);
773 p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa); 775 p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa);
776
777 /* Names like N.<country2chars>.pool.ntp.org are randomly resolved
778 * to a pool of machines. Sometimes different N's resolve to the same IP.
779 * It is not useful to have two peers with same IP. We skip duplicates.
780 */
781 for (item = G.ntp_peers; item != NULL; item = item->link) {
782 peer_t *pp = (peer_t *) item->data;
783 if (strcmp(p->p_dotted, pp->p_dotted) == 0) {
784 bb_error_msg("duplicate peer %s (%s)", s, p->p_dotted);
785 free(p->p_lsa);
786 free(p->p_dotted);
787 free(p);
788 return;
789 }
790 }
791
792 p->p_hostname = xstrdup(s);
774 p->p_fd = -1; 793 p->p_fd = -1;
775 p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); 794 p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3);
776 p->next_action_time = G.cur_time; /* = set_next(p, 0); */ 795 p->next_action_time = G.cur_time; /* = set_next(p, 0); */
@@ -1685,8 +1704,14 @@ update_local_clock(peer_t *p)
1685 VERB4 bb_error_msg("adjtimex:%d freq:%ld offset:%+ld status:0x%x", 1704 VERB4 bb_error_msg("adjtimex:%d freq:%ld offset:%+ld status:0x%x",
1686 rc, tmx.freq, tmx.offset, tmx.status); 1705 rc, tmx.freq, tmx.offset, tmx.status);
1687 G.kernel_freq_drift = tmx.freq / 65536; 1706 G.kernel_freq_drift = tmx.freq / 65536;
1688 VERB2 bb_error_msg("update from:%s offset:%+f jitter:%f clock drift:%+.3fppm tc:%d", 1707 VERB2 bb_error_msg("update from:%s offset:%+f delay:%f jitter:%f clock drift:%+.3fppm tc:%d",
1689 p->p_dotted, offset, G.discipline_jitter, (double)tmx.freq / 65536, (int)tmx.constant); 1708 p->p_dotted,
1709 offset,
1710 p->lastpkt_delay,
1711 G.discipline_jitter,
1712 (double)tmx.freq / 65536,
1713 (int)tmx.constant
1714 );
1690 1715
1691 return 1; /* "ok to increase poll interval" */ 1716 return 1; /* "ok to increase poll interval" */
1692} 1717}
@@ -1947,8 +1972,8 @@ recv_and_process_peer_pkt(peer_t *p)
1947 adjust_poll(MINPOLL); 1972 adjust_poll(MINPOLL);
1948 } else { 1973 } else {
1949 VERB3 if (rc > 0) 1974 VERB3 if (rc > 0)
1950 bb_error_msg("want smaller poll interval: offset/jitter > %u", 1975 bb_error_msg("want smaller interval: offset/jitter = %u",
1951 POLLADJ_GATE); 1976 G.offset_to_jitter_ratio);
1952 adjust_poll(-G.poll_exp * 2); 1977 adjust_poll(-G.poll_exp * 2);
1953 } 1978 }
1954 } 1979 }
@@ -2311,6 +2336,21 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv)
2311 timeout = poll_interval(NOREPLY_INTERVAL); 2336 timeout = poll_interval(NOREPLY_INTERVAL);
2312 bb_error_msg("timed out waiting for %s, reach 0x%02x, next query in %us", 2337 bb_error_msg("timed out waiting for %s, reach 0x%02x, next query in %us",
2313 p->p_dotted, p->reachable_bits, timeout); 2338 p->p_dotted, p->reachable_bits, timeout);
2339
2340 /* What if don't see it because it changed its IP? */
2341 if (p->reachable_bits == 0) {
2342 len_and_sockaddr *lsa = host2sockaddr(p->p_hostname, 123);
2343 if (lsa) {
2344 char *dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa);
2345 //if (strcmp(dotted, p->p_dotted) != 0)
2346 // bb_error_msg("peer IP changed");
2347 free(p->p_lsa);
2348 free(p->p_dotted);
2349 p->p_lsa = lsa;
2350 p->p_dotted = dotted;
2351 }
2352 }
2353
2314 set_next(p, timeout); 2354 set_next(p, timeout);
2315 } 2355 }
2316 } 2356 }
diff --git a/networking/ntpd.diff b/networking/ntpd.diff
new file mode 100644
index 000000000..4afd7e134
--- /dev/null
+++ b/networking/ntpd.diff
@@ -0,0 +1,24 @@
1This patch scales down small offsets quadratically. Reduces sensitivity to jitter
2
3diff --git a/networking/ntpd.c b/networking/ntpd.c
4index 4695c33..ac05815 100644
5--- a/networking/ntpd.c
6+++ b/networking/ntpd.c
7@@ -1654,6 +1654,17 @@ update_local_clock(peer_t *p)
8 */
9 if (G.offset_to_jitter_ratio >= TIMECONST_HACK_GATE)
10 tmx.constant--;
11+
12+{
13+ double d = p->lastpkt_delay;
14+ if (d > SLEW_THRESHOLD)
15+ d = SLEW_THRESHOLD;
16+ d /= 2;
17+ if ((abs_offset / d) < 1) {
18+ offset *= (abs_offset / d);
19+ }
20+}
21+
22 tmx.offset = (long)(offset * 1000000); /* usec */
23 if (SLEW_THRESHOLD < STEP_THRESHOLD) {
24 if (tmx.offset > (long)(SLEW_THRESHOLD * 1000000)) {
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 642110c54..eee4f8873 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -497,7 +497,7 @@ send_probe(int seq, int ttl)
497 497
498 res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len); 498 res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len);
499 if (res != len) 499 if (res != len)
500 bb_info_msg("sent %d octets, ret=%d", len, res); 500 bb_error_msg("sent %d octets, ret=%d", len, res);
501} 501}
502 502
503#if ENABLE_FEATURE_TRACEROUTE_VERBOSE 503#if ENABLE_FEATURE_TRACEROUTE_VERBOSE
diff --git a/networking/tunctl.c b/networking/tunctl.c
index 3a0870eb5..941e8bbd3 100644
--- a/networking/tunctl.c
+++ b/networking/tunctl.c
@@ -82,7 +82,7 @@ int tunctl_main(int argc UNUSED_PARAM, char **argv)
82 // delete? 82 // delete?
83 if (opts & OPT_d) { 83 if (opts & OPT_d) {
84 IOCTL(fd, TUNSETPERSIST, (void *)(uintptr_t)0); 84 IOCTL(fd, TUNSETPERSIST, (void *)(uintptr_t)0);
85 bb_info_msg("Set '%s' %spersistent", ifr.ifr_name, "non"); 85 printf("Set '%s' nonpersistent\n", ifr.ifr_name);
86 return EXIT_SUCCESS; 86 return EXIT_SUCCESS;
87 } 87 }
88 88
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c
index fad2283c3..c98027316 100644
--- a/networking/udhcp/arpping.c
+++ b/networking/udhcp/arpping.c
@@ -132,6 +132,6 @@ int FAST_FUNC arpping(uint32_t test_nip,
132 132
133 ret: 133 ret:
134 close(s); 134 close(s);
135 log1("%srp reply received for this address", rv ? "No a" : "A"); 135 log1("%srp reply received for this address", rv ? "no a" : "A");
136 return rv; 136 return rv;
137} 137}
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index bc41c8d4d..0cf4dab63 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -142,7 +142,7 @@ const char dhcp_option_strings[] ALIGN1 =
142 * udhcp_str2optset: to determine how many bytes to allocate. 142 * udhcp_str2optset: to determine how many bytes to allocate.
143 * xmalloc_optname_optval: to estimate string length 143 * xmalloc_optname_optval: to estimate string length
144 * from binary option length: (option[LEN] / dhcp_option_lengths[opt_type]) 144 * from binary option length: (option[LEN] / dhcp_option_lengths[opt_type])
145 * is the number of elements, multiply in by one element's string width 145 * is the number of elements, multiply it by one element's string width
146 * (len_of_option_as_string[opt_type]) and you know how wide string you need. 146 * (len_of_option_as_string[opt_type]) and you know how wide string you need.
147 */ 147 */
148const uint8_t dhcp_option_lengths[] ALIGN1 = { 148const uint8_t dhcp_option_lengths[] ALIGN1 = {
@@ -162,7 +162,18 @@ const uint8_t dhcp_option_lengths[] ALIGN1 = {
162 [OPTION_S32] = 4, 162 [OPTION_S32] = 4,
163 /* Just like OPTION_STRING, we use minimum length here */ 163 /* Just like OPTION_STRING, we use minimum length here */
164 [OPTION_STATIC_ROUTES] = 5, 164 [OPTION_STATIC_ROUTES] = 5,
165 [OPTION_6RD] = 22, /* ignored by udhcp_str2optset */ 165 [OPTION_6RD] = 12, /* ignored by udhcp_str2optset */
166 /* The above value was chosen as follows:
167 * len_of_option_as_string[] for this option is >60: it's a string of the form
168 * "32 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 ".
169 * Each additional ipv4 address takes 4 bytes in binary option and appends
170 * another "255.255.255.255 " 16-byte string. We can set [OPTION_6RD] = 4
171 * but this severely overestimates string length: instead of 16 bytes,
172 * it adds >60 for every 4 bytes in binary option.
173 * We cheat and declare here that option is in units of 12 bytes.
174 * This adds more than 60 bytes for every three ipv4 addresses - more than enough.
175 * (Even 16 instead of 12 should work, but let's be paranoid).
176 */
166}; 177};
167 178
168 179
@@ -172,7 +183,7 @@ static void log_option(const char *pfx, const uint8_t *opt)
172 if (dhcp_verbose >= 2) { 183 if (dhcp_verbose >= 2) {
173 char buf[256 * 2 + 2]; 184 char buf[256 * 2 + 2];
174 *bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0'; 185 *bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0';
175 bb_info_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf); 186 bb_error_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf);
176 } 187 }
177} 188}
178#else 189#else
@@ -246,7 +257,7 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
246 continue; /* complain and return NULL */ 257 continue; /* complain and return NULL */
247 258
248 if (optionptr[OPT_CODE] == code) { 259 if (optionptr[OPT_CODE] == code) {
249 log_option("Option found", optionptr); 260 log_option("option found", optionptr);
250 return optionptr + OPT_DATA; 261 return optionptr + OPT_DATA;
251 } 262 }
252 263
@@ -258,7 +269,7 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
258 } 269 }
259 270
260 /* log3 because udhcpc uses it a lot - very noisy */ 271 /* log3 because udhcpc uses it a lot - very noisy */
261 log3("Option 0x%02x not found", code); 272 log3("option 0x%02x not found", code);
262 return NULL; 273 return NULL;
263} 274}
264 275
@@ -292,7 +303,7 @@ void FAST_FUNC udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addo
292 addopt[OPT_CODE]); 303 addopt[OPT_CODE]);
293 return; 304 return;
294 } 305 }
295 log_option("Adding option", addopt); 306 log_option("adding option", addopt);
296 memcpy(optionptr + end, addopt, len); 307 memcpy(optionptr + end, addopt, len);
297 optionptr[end + len] = DHCP_END; 308 optionptr[end + len] = DHCP_END;
298} 309}
@@ -391,7 +402,7 @@ static NOINLINE void attach_option(
391 struct option_set *new, **curr; 402 struct option_set *new, **curr;
392 403
393 /* make a new option */ 404 /* make a new option */
394 log2("Attaching option %02x to list", optflag->code); 405 log2("attaching option %02x to list", optflag->code);
395 new = xmalloc(sizeof(*new)); 406 new = xmalloc(sizeof(*new));
396 new->data = xmalloc(length + OPT_DATA); 407 new->data = xmalloc(length + OPT_DATA);
397 new->data[OPT_CODE] = optflag->code; 408 new->data[OPT_CODE] = optflag->code;
@@ -411,7 +422,7 @@ static NOINLINE void attach_option(
411 unsigned old_len; 422 unsigned old_len;
412 423
413 /* add it to an existing option */ 424 /* add it to an existing option */
414 log2("Attaching option %02x to existing member of list", optflag->code); 425 log2("attaching option %02x to existing member of list", optflag->code);
415 old_len = existing->data[OPT_LEN]; 426 old_len = existing->data[OPT_LEN];
416 if (old_len + length < 255) { 427 if (old_len + length < 255) {
417 /* actually 255 is ok too, but adding a space can overlow it */ 428 /* actually 255 is ok too, but adding a space can overlow it */
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index d20659e2f..496ab11a1 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -256,16 +256,16 @@ struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code)
256#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 256#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
257# define IF_UDHCP_VERBOSE(...) __VA_ARGS__ 257# define IF_UDHCP_VERBOSE(...) __VA_ARGS__
258extern unsigned dhcp_verbose; 258extern unsigned dhcp_verbose;
259# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0) 259# define log1(...) do { if (dhcp_verbose >= 1) bb_error_msg(__VA_ARGS__); } while (0)
260# if CONFIG_UDHCP_DEBUG >= 2 260# if CONFIG_UDHCP_DEBUG >= 2
261void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; 261void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
262# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0) 262# define log2(...) do { if (dhcp_verbose >= 2) bb_error_msg(__VA_ARGS__); } while (0)
263# else 263# else
264# define udhcp_dump_packet(...) ((void)0) 264# define udhcp_dump_packet(...) ((void)0)
265# define log2(...) ((void)0) 265# define log2(...) ((void)0)
266# endif 266# endif
267# if CONFIG_UDHCP_DEBUG >= 3 267# if CONFIG_UDHCP_DEBUG >= 3
268# define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0) 268# define log3(...) do { if (dhcp_verbose >= 3) bb_error_msg(__VA_ARGS__); } while (0)
269# else 269# else
270# define log3(...) ((void)0) 270# define log3(...) ((void)0)
271# endif 271# endif
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 4e9b705b9..422254d62 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -251,7 +251,7 @@ static void d6_run_script(struct d6_packet *packet, const char *name)
251 envp = fill_envp(packet); 251 envp = fill_envp(packet);
252 252
253 /* call script */ 253 /* call script */
254 log1("Executing %s %s", client_config.script, name); 254 log1("executing %s %s", client_config.script, name);
255 argv[0] = (char*) client_config.script; 255 argv[0] = (char*) client_config.script;
256 argv[1] = (char*) name; 256 argv[1] = (char*) name;
257 argv[2] = NULL; 257 argv[2] = NULL;
@@ -428,7 +428,7 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct in6_addr *requested_ip
428 */ 428 */
429 opt_ptr = add_d6_client_options(opt_ptr); 429 opt_ptr = add_d6_client_options(opt_ptr);
430 430
431 bb_info_msg("Sending discover..."); 431 bb_error_msg("sending %s", "discover");
432 return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); 432 return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
433} 433}
434 434
@@ -481,7 +481,7 @@ static NOINLINE int send_d6_select(uint32_t xid)
481 */ 481 */
482 opt_ptr = add_d6_client_options(opt_ptr); 482 opt_ptr = add_d6_client_options(opt_ptr);
483 483
484 bb_info_msg("Sending select..."); 484 bb_error_msg("sending %s", "select");
485 return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); 485 return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
486} 486}
487 487
@@ -550,7 +550,7 @@ static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, st
550 */ 550 */
551 opt_ptr = add_d6_client_options(opt_ptr); 551 opt_ptr = add_d6_client_options(opt_ptr);
552 552
553 bb_info_msg("Sending renew..."); 553 bb_error_msg("sending %s", "renew");
554 if (server_ipv6) 554 if (server_ipv6)
555 return d6_send_kernel_packet( 555 return d6_send_kernel_packet(
556 &packet, (opt_ptr - (uint8_t*) &packet), 556 &packet, (opt_ptr - (uint8_t*) &packet),
@@ -573,7 +573,7 @@ static int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cu
573 /* IA NA (contains our current IP) */ 573 /* IA NA (contains our current IP) */
574 opt_ptr = d6_store_blob(opt_ptr, client6_data.ia_na, client6_data.ia_na->len + 2+2); 574 opt_ptr = d6_store_blob(opt_ptr, client6_data.ia_na, client6_data.ia_na->len + 2+2);
575 575
576 bb_info_msg("Sending release..."); 576 bb_error_msg("sending %s", "release");
577 return d6_send_kernel_packet( 577 return d6_send_kernel_packet(
578 &packet, (opt_ptr - (uint8_t*) &packet), 578 &packet, (opt_ptr - (uint8_t*) &packet),
579 our_cur_ipv6, CLIENT_PORT6, 579 our_cur_ipv6, CLIENT_PORT6,
@@ -592,19 +592,19 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6
592 592
593 bytes = safe_read(fd, &packet, sizeof(packet)); 593 bytes = safe_read(fd, &packet, sizeof(packet));
594 if (bytes < 0) { 594 if (bytes < 0) {
595 log1("Packet read error, ignoring"); 595 log1("packet read error, ignoring");
596 /* NB: possible down interface, etc. Caller should pause. */ 596 /* NB: possible down interface, etc. Caller should pause. */
597 return bytes; /* returns -1 */ 597 return bytes; /* returns -1 */
598 } 598 }
599 599
600 if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) { 600 if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) {
601 log1("Packet is too short, ignoring"); 601 log1("packet is too short, ignoring");
602 return -2; 602 return -2;
603 } 603 }
604 604
605 if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) { 605 if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) {
606 /* packet is bigger than sizeof(packet), we did partial read */ 606 /* packet is bigger than sizeof(packet), we did partial read */
607 log1("Oversized packet, ignoring"); 607 log1("oversized packet, ignoring");
608 return -2; 608 return -2;
609 } 609 }
610 610
@@ -618,7 +618,7 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6
618 /* || bytes > (int) sizeof(packet) - can't happen */ 618 /* || bytes > (int) sizeof(packet) - can't happen */
619 || packet.udp.len != packet.ip6.ip6_plen 619 || packet.udp.len != packet.ip6.ip6_plen
620 ) { 620 ) {
621 log1("Unrelated/bogus packet, ignoring"); 621 log1("unrelated/bogus packet, ignoring");
622 return -2; 622 return -2;
623 } 623 }
624 624
@@ -630,11 +630,11 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6
630// check = packet.udp.check; 630// check = packet.udp.check;
631// packet.udp.check = 0; 631// packet.udp.check = 0;
632// if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { 632// if (check && check != inet_cksum((uint16_t *)&packet, bytes)) {
633// log1("Packet with bad UDP checksum received, ignoring"); 633// log1("packet with bad UDP checksum received, ignoring");
634// return -2; 634// return -2;
635// } 635// }
636 636
637 log1("Received a packet"); 637 log1("received %s", "a packet");
638 d6_dump_packet(&packet.data); 638 d6_dump_packet(&packet.data);
639 639
640 bytes -= sizeof(packet.ip6) + sizeof(packet.udp); 640 bytes -= sizeof(packet.ip6) + sizeof(packet.udp);
@@ -722,10 +722,10 @@ static int d6_raw_socket(int ifindex)
722 }; 722 };
723#endif 723#endif
724 724
725 log1("Opening raw socket on ifindex %d", ifindex); //log2? 725 log1("opening raw socket on ifindex %d", ifindex); //log2?
726 726
727 fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)); 727 fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6));
728 log1("Got raw socket fd %d", fd); //log2? 728 log1("got raw socket fd %d", fd); //log2?
729 729
730 sock.sll_family = AF_PACKET; 730 sock.sll_family = AF_PACKET;
731 sock.sll_protocol = htons(ETH_P_IPV6); 731 sock.sll_protocol = htons(ETH_P_IPV6);
@@ -738,18 +738,18 @@ static int d6_raw_socket(int ifindex)
738 /* Ignoring error (kernel may lack support for this) */ 738 /* Ignoring error (kernel may lack support for this) */
739 if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, 739 if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
740 sizeof(filter_prog)) >= 0) 740 sizeof(filter_prog)) >= 0)
741 log1("Attached filter to raw socket fd %d", fd); // log? 741 log1("attached filter to raw socket fd %d", fd); // log?
742 } 742 }
743#endif 743#endif
744 744
745 log1("Created raw socket"); 745 log1("created raw socket");
746 746
747 return fd; 747 return fd;
748} 748}
749 749
750static void change_listen_mode(int new_mode) 750static void change_listen_mode(int new_mode)
751{ 751{
752 log1("Entering listen mode: %s", 752 log1("entering listen mode: %s",
753 new_mode != LISTEN_NONE 753 new_mode != LISTEN_NONE
754 ? (new_mode == LISTEN_KERNEL ? "kernel" : "raw") 754 ? (new_mode == LISTEN_KERNEL ? "kernel" : "raw")
755 : "none" 755 : "none"
@@ -770,7 +770,7 @@ static void change_listen_mode(int new_mode)
770/* Called only on SIGUSR1 */ 770/* Called only on SIGUSR1 */
771static void perform_renew(void) 771static void perform_renew(void)
772{ 772{
773 bb_info_msg("Performing a DHCP renew"); 773 bb_error_msg("performing DHCP renew");
774 switch (state) { 774 switch (state) {
775 case BOUND: 775 case BOUND:
776 change_listen_mode(LISTEN_KERNEL); 776 change_listen_mode(LISTEN_KERNEL);
@@ -794,11 +794,11 @@ static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *ou
794{ 794{
795 /* send release packet */ 795 /* send release packet */
796 if (state == BOUND || state == RENEWING || state == REBINDING) { 796 if (state == BOUND || state == RENEWING || state == REBINDING) {
797 bb_info_msg("Unicasting a release"); 797 bb_error_msg("unicasting a release");
798 send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */ 798 send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */
799 d6_run_script(NULL, "deconfig"); 799 d6_run_script(NULL, "deconfig");
800 } 800 }
801 bb_info_msg("Entering released state"); 801 bb_error_msg("entering released state");
802 802
803 change_listen_mode(LISTEN_NONE); 803 change_listen_mode(LISTEN_NONE);
804 state = RELEASED; 804 state = RELEASED;
@@ -1034,7 +1034,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1034 /* Create pidfile */ 1034 /* Create pidfile */
1035 write_pidfile(client_config.pidfile); 1035 write_pidfile(client_config.pidfile);
1036 /* Goes to stdout (unless NOMMU) and possibly syslog */ 1036 /* Goes to stdout (unless NOMMU) and possibly syslog */
1037 bb_info_msg("%s (v"BB_VER") started", applet_name); 1037 bb_error_msg("started, v"BB_VER);
1038 /* Set up the signal pipe */ 1038 /* Set up the signal pipe */
1039 udhcp_sp_setup(); 1039 udhcp_sp_setup();
1040 /* We want random_xid to be random... */ 1040 /* We want random_xid to be random... */
@@ -1074,7 +1074,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1074 retval = 0; 1074 retval = 0;
1075 /* If we already timed out, fall through with retval = 0, else... */ 1075 /* If we already timed out, fall through with retval = 0, else... */
1076 if ((int)tv.tv_sec > 0) { 1076 if ((int)tv.tv_sec > 0) {
1077 log1("Waiting on select %u seconds", (int)tv.tv_sec); 1077 log1("waiting on select %u seconds", (int)tv.tv_sec);
1078 timestamp_before_wait = (unsigned)monotonic_sec(); 1078 timestamp_before_wait = (unsigned)monotonic_sec();
1079 retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); 1079 retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
1080 if (retval < 0) { 1080 if (retval < 0) {
@@ -1124,14 +1124,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1124 d6_run_script(NULL, "leasefail"); 1124 d6_run_script(NULL, "leasefail");
1125#if BB_MMU /* -b is not supported on NOMMU */ 1125#if BB_MMU /* -b is not supported on NOMMU */
1126 if (opt & OPT_b) { /* background if no lease */ 1126 if (opt & OPT_b) { /* background if no lease */
1127 bb_info_msg("No lease, forking to background"); 1127 bb_error_msg("no lease, forking to background");
1128 client_background(); 1128 client_background();
1129 /* do not background again! */ 1129 /* do not background again! */
1130 opt = ((opt & ~OPT_b) | OPT_f); 1130 opt = ((opt & ~OPT_b) | OPT_f);
1131 } else 1131 } else
1132#endif 1132#endif
1133 if (opt & OPT_n) { /* abort if no lease */ 1133 if (opt & OPT_n) { /* abort if no lease */
1134 bb_info_msg("No lease, failing"); 1134 bb_error_msg("no lease, failing");
1135 retval = 1; 1135 retval = 1;
1136 goto ret; 1136 goto ret;
1137 } 1137 }
@@ -1159,7 +1159,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1159 state = RENEWING; 1159 state = RENEWING;
1160 client_config.first_secs = 0; /* make secs field count from 0 */ 1160 client_config.first_secs = 0; /* make secs field count from 0 */
1161 change_listen_mode(LISTEN_KERNEL); 1161 change_listen_mode(LISTEN_KERNEL);
1162 log1("Entering renew state"); 1162 log1("entering renew state");
1163 /* fall right through */ 1163 /* fall right through */
1164 case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ 1164 case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
1165 case_RENEW_REQUESTED: 1165 case_RENEW_REQUESTED:
@@ -1179,7 +1179,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1179 continue; 1179 continue;
1180 } 1180 }
1181 /* Timed out, enter rebinding state */ 1181 /* Timed out, enter rebinding state */
1182 log1("Entering rebinding state"); 1182 log1("entering rebinding state");
1183 state = REBINDING; 1183 state = REBINDING;
1184 /* fall right through */ 1184 /* fall right through */
1185 case REBINDING: 1185 case REBINDING:
@@ -1194,7 +1194,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1194 continue; 1194 continue;
1195 } 1195 }
1196 /* Timed out, enter init state */ 1196 /* Timed out, enter init state */
1197 bb_info_msg("Lease lost, entering init state"); 1197 bb_error_msg("lease lost, entering init state");
1198 d6_run_script(NULL, "deconfig"); 1198 d6_run_script(NULL, "deconfig");
1199 state = INIT_SELECTING; 1199 state = INIT_SELECTING;
1200 client_config.first_secs = 0; /* make secs field count from 0 */ 1200 client_config.first_secs = 0; /* make secs field count from 0 */
@@ -1242,7 +1242,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1242 timeout = INT_MAX; 1242 timeout = INT_MAX;
1243 continue; 1243 continue;
1244 case SIGTERM: 1244 case SIGTERM:
1245 bb_info_msg("Received SIGTERM"); 1245 bb_error_msg("received %s", "SIGTERM");
1246 goto ret0; 1246 goto ret0;
1247 } 1247 }
1248 1248
@@ -1260,7 +1260,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1260 len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd); 1260 len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd);
1261 if (len == -1) { 1261 if (len == -1) {
1262 /* Error is severe, reopen socket */ 1262 /* Error is severe, reopen socket */
1263 bb_info_msg("Read error: %s, reopening socket", strerror(errno)); 1263 bb_error_msg("read error: %s, reopening socket", strerror(errno));
1264 sleep(discover_timeout); /* 3 seconds by default */ 1264 sleep(discover_timeout); /* 3 seconds by default */
1265 change_listen_mode(listen_mode); /* just close and reopen */ 1265 change_listen_mode(listen_mode); /* just close and reopen */
1266 } 1266 }
@@ -1298,7 +1298,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1298 option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE); 1298 option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE);
1299 if (option && option->data[4] != 0) { 1299 if (option && option->data[4] != 0) {
1300 /* return to init state */ 1300 /* return to init state */
1301 bb_info_msg("Received DHCP NAK (%u)", option->data[4]); 1301 bb_error_msg("received DHCP NAK (%u)", option->data[4]);
1302 d6_run_script(&packet, "nak"); 1302 d6_run_script(&packet, "nak");
1303 if (state != REQUESTING) 1303 if (state != REQUESTING)
1304 d6_run_script(NULL, "deconfig"); 1304 d6_run_script(NULL, "deconfig");
@@ -1453,7 +1453,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1453 lease_seconds = 0x0fffffff; 1453 lease_seconds = 0x0fffffff;
1454 /* enter bound state */ 1454 /* enter bound state */
1455 timeout = lease_seconds / 2; 1455 timeout = lease_seconds / 2;
1456 bb_info_msg("Lease obtained, lease time %u", 1456 bb_error_msg("lease obtained, lease time %u",
1457 /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); 1457 /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
1458 d6_run_script(&packet, state == REQUESTING ? "bound" : "renew"); 1458 d6_run_script(&packet, state == REQUESTING ? "bound" : "renew");
1459 1459
diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c
index 79b2946ef..e166f520d 100644
--- a/networking/udhcp/d6_packet.c
+++ b/networking/udhcp/d6_packet.c
@@ -17,12 +17,12 @@ 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_info_msg( 20 bb_error_msg(
21 " xid %x" 21 "xid %x"
22 , packet->d6_xid32 22 , packet->d6_xid32
23 ); 23 );
24 //*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0'; 24 //*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0';
25 //bb_info_msg(" chaddr %s", buf); 25 //bb_error_msg(" chaddr %s", buf);
26} 26}
27#endif 27#endif
28 28
@@ -35,15 +35,15 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6
35 memset(packet, 0, sizeof(*packet)); 35 memset(packet, 0, sizeof(*packet));
36 bytes = safe_read(fd, packet, sizeof(*packet)); 36 bytes = safe_read(fd, packet, sizeof(*packet));
37 if (bytes < 0) { 37 if (bytes < 0) {
38 log1("Packet read error, ignoring"); 38 log1("packet read error, ignoring");
39 return bytes; /* returns -1 */ 39 return bytes; /* returns -1 */
40 } 40 }
41 41
42 if (bytes < offsetof(struct d6_packet, d6_options)) { 42 if (bytes < offsetof(struct d6_packet, d6_options)) {
43 bb_info_msg("Packet with bad magic, ignoring"); 43 bb_error_msg("packet with bad magic, ignoring");
44 return -2; 44 return -2;
45 } 45 }
46 log1("Received a packet"); 46 log1("received %s", "a packet");
47 d6_dump_packet(packet); 47 d6_dump_packet(packet);
48 48
49 return bytes; 49 return bytes;
diff --git a/networking/udhcp/d6_socket.c b/networking/udhcp/d6_socket.c
index 56f69f6a1..910f296a3 100644
--- a/networking/udhcp/d6_socket.c
+++ b/networking/udhcp/d6_socket.c
@@ -13,7 +13,7 @@ int FAST_FUNC d6_listen_socket(int port, const char *inf)
13 int fd; 13 int fd;
14 struct sockaddr_in6 addr; 14 struct sockaddr_in6 addr;
15 15
16 log1("Opening listen socket on *:%d %s", port, inf); 16 log1("opening listen socket on *:%d %s", port, inf);
17 fd = xsocket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); 17 fd = xsocket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
18 18
19 setsockopt_reuseaddr(fd); 19 setsockopt_reuseaddr(fd);
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 48097bc24..660b943ce 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -113,7 +113,7 @@ static const uint8_t len_of_option_as_string[] = {
113 [OPTION_IP ] = sizeof("255.255.255.255 "), 113 [OPTION_IP ] = sizeof("255.255.255.255 "),
114 [OPTION_IP_PAIR ] = sizeof("255.255.255.255 ") * 2, 114 [OPTION_IP_PAIR ] = sizeof("255.255.255.255 ") * 2,
115 [OPTION_STATIC_ROUTES ] = sizeof("255.255.255.255/32 255.255.255.255 "), 115 [OPTION_STATIC_ROUTES ] = sizeof("255.255.255.255/32 255.255.255.255 "),
116 [OPTION_6RD ] = sizeof("32 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 "), 116 [OPTION_6RD ] = sizeof("132 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 "),
117 [OPTION_STRING ] = 1, 117 [OPTION_STRING ] = 1,
118 [OPTION_STRING_HOST ] = 1, 118 [OPTION_STRING_HOST ] = 1,
119#if ENABLE_FEATURE_UDHCP_RFC3397 119#if ENABLE_FEATURE_UDHCP_RFC3397
@@ -222,7 +222,7 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_
222 type = optflag->flags & OPTION_TYPE_MASK; 222 type = optflag->flags & OPTION_TYPE_MASK;
223 optlen = dhcp_option_lengths[type]; 223 optlen = dhcp_option_lengths[type];
224 upper_length = len_of_option_as_string[type] 224 upper_length = len_of_option_as_string[type]
225 * ((unsigned)(len + optlen - 1) / (unsigned)optlen); 225 * ((unsigned)(len + optlen) / (unsigned)optlen);
226 226
227 dest = ret = xmalloc(upper_length + strlen(opt_name) + 2); 227 dest = ret = xmalloc(upper_length + strlen(opt_name) + 2);
228 dest += sprintf(ret, "%s=", opt_name); 228 dest += sprintf(ret, "%s=", opt_name);
@@ -561,7 +561,7 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name)
561 envp = fill_envp(packet); 561 envp = fill_envp(packet);
562 562
563 /* call script */ 563 /* call script */
564 log1("Executing %s %s", client_config.script, name); 564 log1("executing %s %s", client_config.script, name);
565 argv[0] = (char*) client_config.script; 565 argv[0] = (char*) client_config.script;
566 argv[1] = (char*) name; 566 argv[1] = (char*) name;
567 argv[2] = NULL; 567 argv[2] = NULL;
@@ -675,10 +675,10 @@ static void add_client_options(struct dhcp_packet *packet)
675 * client reverts to using the IP broadcast address. 675 * client reverts to using the IP broadcast address.
676 */ 676 */
677 677
678static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet) 678static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet, uint32_t src_nip)
679{ 679{
680 return udhcp_send_raw_packet(packet, 680 return udhcp_send_raw_packet(packet,
681 /*src*/ INADDR_ANY, CLIENT_PORT, 681 /*src*/ src_nip, CLIENT_PORT,
682 /*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, 682 /*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR,
683 client_config.ifindex); 683 client_config.ifindex);
684} 684}
@@ -689,7 +689,7 @@ static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t
689 return udhcp_send_kernel_packet(packet, 689 return udhcp_send_kernel_packet(packet,
690 ciaddr, CLIENT_PORT, 690 ciaddr, CLIENT_PORT,
691 server, SERVER_PORT); 691 server, SERVER_PORT);
692 return raw_bcast_from_client_config_ifindex(packet); 692 return raw_bcast_from_client_config_ifindex(packet, ciaddr);
693} 693}
694 694
695/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ 695/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */
@@ -714,8 +714,8 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested)
714 */ 714 */
715 add_client_options(&packet); 715 add_client_options(&packet);
716 716
717 bb_info_msg("Sending discover..."); 717 bb_error_msg("sending %s", "discover");
718 return raw_bcast_from_client_config_ifindex(&packet); 718 return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
719} 719}
720 720
721/* Broadcast a DHCP request message */ 721/* Broadcast a DHCP request message */
@@ -758,8 +758,8 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste
758 add_client_options(&packet); 758 add_client_options(&packet);
759 759
760 addr.s_addr = requested; 760 addr.s_addr = requested;
761 bb_info_msg("Sending select for %s...", inet_ntoa(addr)); 761 bb_error_msg("sending select for %s", inet_ntoa(addr));
762 return raw_bcast_from_client_config_ifindex(&packet); 762 return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
763} 763}
764 764
765/* Unicast or broadcast a DHCP renew message */ 765/* Unicast or broadcast a DHCP renew message */
@@ -797,7 +797,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
797 */ 797 */
798 add_client_options(&packet); 798 add_client_options(&packet);
799 799
800 bb_info_msg("Sending renew..."); 800 bb_error_msg("sending %s", "renew");
801 return bcast_or_ucast(&packet, ciaddr, server); 801 return bcast_or_ucast(&packet, ciaddr, server);
802} 802}
803 803
@@ -826,8 +826,8 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req
826 826
827 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); 827 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
828 828
829 bb_info_msg("Sending decline..."); 829 bb_error_msg("sending %s", "decline");
830 return raw_bcast_from_client_config_ifindex(&packet); 830 return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
831} 831}
832#endif 832#endif
833 833
@@ -846,7 +846,7 @@ static int send_release(uint32_t server, uint32_t ciaddr)
846 846
847 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); 847 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
848 848
849 bb_info_msg("Sending release..."); 849 bb_error_msg("sending %s", "release");
850 /* Note: normally we unicast here since "server" is not zero. 850 /* Note: normally we unicast here since "server" is not zero.
851 * However, there _are_ people who run "address-less" DHCP servers, 851 * However, there _are_ people who run "address-less" DHCP servers,
852 * and reportedly ISC dhcp client and Windows allow that. 852 * and reportedly ISC dhcp client and Windows allow that.
@@ -881,7 +881,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
881 if (bytes < 0) { 881 if (bytes < 0) {
882 if (errno == EINTR) 882 if (errno == EINTR)
883 continue; 883 continue;
884 log1("Packet read error, ignoring"); 884 log1("packet read error, ignoring");
885 /* NB: possible down interface, etc. Caller should pause. */ 885 /* NB: possible down interface, etc. Caller should pause. */
886 return bytes; /* returns -1 */ 886 return bytes; /* returns -1 */
887 } 887 }
@@ -889,13 +889,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
889 } 889 }
890 890
891 if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { 891 if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
892 log1("Packet is too short, ignoring"); 892 log1("packet is too short, ignoring");
893 return -2; 893 return -2;
894 } 894 }
895 895
896 if (bytes < ntohs(packet.ip.tot_len)) { 896 if (bytes < ntohs(packet.ip.tot_len)) {
897 /* packet is bigger than sizeof(packet), we did partial read */ 897 /* packet is bigger than sizeof(packet), we did partial read */
898 log1("Oversized packet, ignoring"); 898 log1("oversized packet, ignoring");
899 return -2; 899 return -2;
900 } 900 }
901 901
@@ -910,7 +910,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
910 /* || bytes > (int) sizeof(packet) - can't happen */ 910 /* || bytes > (int) sizeof(packet) - can't happen */
911 || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) 911 || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip))
912 ) { 912 ) {
913 log1("Unrelated/bogus packet, ignoring"); 913 log1("unrelated/bogus packet, ignoring");
914 return -2; 914 return -2;
915 } 915 }
916 916
@@ -918,7 +918,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
918 check = packet.ip.check; 918 check = packet.ip.check;
919 packet.ip.check = 0; 919 packet.ip.check = 0;
920 if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) { 920 if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) {
921 log1("Bad IP header checksum, ignoring"); 921 log1("bad IP header checksum, ignoring");
922 return -2; 922 return -2;
923 } 923 }
924 924
@@ -943,17 +943,17 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
943 check = packet.udp.check; 943 check = packet.udp.check;
944 packet.udp.check = 0; 944 packet.udp.check = 0;
945 if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { 945 if (check && check != inet_cksum((uint16_t *)&packet, bytes)) {
946 log1("Packet with bad UDP checksum received, ignoring"); 946 log1("packet with bad UDP checksum received, ignoring");
947 return -2; 947 return -2;
948 } 948 }
949 skip_udp_sum_check: 949 skip_udp_sum_check:
950 950
951 if (packet.data.cookie != htonl(DHCP_MAGIC)) { 951 if (packet.data.cookie != htonl(DHCP_MAGIC)) {
952 bb_info_msg("Packet with bad magic, ignoring"); 952 bb_error_msg("packet with bad magic, ignoring");
953 return -2; 953 return -2;
954 } 954 }
955 955
956 log1("Received a packet"); 956 log1("received %s", "a packet");
957 udhcp_dump_packet(&packet.data); 957 udhcp_dump_packet(&packet.data);
958 958
959 bytes -= sizeof(packet.ip) + sizeof(packet.udp); 959 bytes -= sizeof(packet.ip) + sizeof(packet.udp);
@@ -992,14 +992,14 @@ static int udhcp_raw_socket(int ifindex)
992 int fd; 992 int fd;
993 struct sockaddr_ll sock; 993 struct sockaddr_ll sock;
994 994
995 log1("Opening raw socket on ifindex %d", ifindex); //log2? 995 log1("opening raw socket on ifindex %d", ifindex); //log2?
996 996
997 fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); 997 fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
998 /* ^^^^^ 998 /* ^^^^^
999 * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them) 999 * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them)
1000 * ETH_P_IP: want to receive only packets with IPv4 eth type 1000 * ETH_P_IP: want to receive only packets with IPv4 eth type
1001 */ 1001 */
1002 log1("Got raw socket fd"); //log2? 1002 log1("got raw socket fd"); //log2?
1003 1003
1004 sock.sll_family = AF_PACKET; 1004 sock.sll_family = AF_PACKET;
1005 sock.sll_protocol = htons(ETH_P_IP); 1005 sock.sll_protocol = htons(ETH_P_IP);
@@ -1055,23 +1055,23 @@ static int udhcp_raw_socket(int ifindex)
1055 /* Ignoring error (kernel may lack support for this) */ 1055 /* Ignoring error (kernel may lack support for this) */
1056 if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, 1056 if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
1057 sizeof(filter_prog)) >= 0) 1057 sizeof(filter_prog)) >= 0)
1058 log1("Attached filter to raw socket fd"); // log? 1058 log1("attached filter to raw socket fd"); // log?
1059 } 1059 }
1060#endif 1060#endif
1061 1061
1062 if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) { 1062 if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) {
1063 if (errno != ENOPROTOOPT) 1063 if (errno != ENOPROTOOPT)
1064 log1("Can't set PACKET_AUXDATA on raw socket"); 1064 log1("can't set PACKET_AUXDATA on raw socket");
1065 } 1065 }
1066 1066
1067 log1("Created raw socket"); 1067 log1("created raw socket");
1068 1068
1069 return fd; 1069 return fd;
1070} 1070}
1071 1071
1072static void change_listen_mode(int new_mode) 1072static void change_listen_mode(int new_mode)
1073{ 1073{
1074 log1("Entering listen mode: %s", 1074 log1("entering listen mode: %s",
1075 new_mode != LISTEN_NONE 1075 new_mode != LISTEN_NONE
1076 ? (new_mode == LISTEN_KERNEL ? "kernel" : "raw") 1076 ? (new_mode == LISTEN_KERNEL ? "kernel" : "raw")
1077 : "none" 1077 : "none"
@@ -1092,7 +1092,7 @@ static void change_listen_mode(int new_mode)
1092/* Called only on SIGUSR1 */ 1092/* Called only on SIGUSR1 */
1093static void perform_renew(void) 1093static void perform_renew(void)
1094{ 1094{
1095 bb_info_msg("Performing a DHCP renew"); 1095 bb_error_msg("performing DHCP renew");
1096 switch (state) { 1096 switch (state) {
1097 case BOUND: 1097 case BOUND:
1098 change_listen_mode(LISTEN_KERNEL); 1098 change_listen_mode(LISTEN_KERNEL);
@@ -1122,12 +1122,12 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip)
1122 temp_addr.s_addr = server_addr; 1122 temp_addr.s_addr = server_addr;
1123 strcpy(buffer, inet_ntoa(temp_addr)); 1123 strcpy(buffer, inet_ntoa(temp_addr));
1124 temp_addr.s_addr = requested_ip; 1124 temp_addr.s_addr = requested_ip;
1125 bb_info_msg("Unicasting a release of %s to %s", 1125 bb_error_msg("unicasting a release of %s to %s",
1126 inet_ntoa(temp_addr), buffer); 1126 inet_ntoa(temp_addr), buffer);
1127 send_release(server_addr, requested_ip); /* unicast */ 1127 send_release(server_addr, requested_ip); /* unicast */
1128 udhcp_run_script(NULL, "deconfig"); 1128 udhcp_run_script(NULL, "deconfig");
1129 } 1129 }
1130 bb_info_msg("Entering released state"); 1130 bb_error_msg("entering released state");
1131 1131
1132 change_listen_mode(LISTEN_NONE); 1132 change_listen_mode(LISTEN_NONE);
1133 state = RELEASED; 1133 state = RELEASED;
@@ -1395,7 +1395,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1395 /* Create pidfile */ 1395 /* Create pidfile */
1396 write_pidfile(client_config.pidfile); 1396 write_pidfile(client_config.pidfile);
1397 /* Goes to stdout (unless NOMMU) and possibly syslog */ 1397 /* Goes to stdout (unless NOMMU) and possibly syslog */
1398 bb_info_msg("%s (v"BB_VER") started", applet_name); 1398 bb_error_msg("started, v"BB_VER);
1399 /* Set up the signal pipe */ 1399 /* Set up the signal pipe */
1400 udhcp_sp_setup(); 1400 udhcp_sp_setup();
1401 /* We want random_xid to be random... */ 1401 /* We want random_xid to be random... */
@@ -1434,7 +1434,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1434 retval = 0; 1434 retval = 0;
1435 /* If we already timed out, fall through with retval = 0, else... */ 1435 /* If we already timed out, fall through with retval = 0, else... */
1436 if ((int)tv.tv_sec > 0) { 1436 if ((int)tv.tv_sec > 0) {
1437 log1("Waiting on select %u seconds", (int)tv.tv_sec); 1437 log1("waiting on select %u seconds", (int)tv.tv_sec);
1438 timestamp_before_wait = (unsigned)monotonic_sec(); 1438 timestamp_before_wait = (unsigned)monotonic_sec();
1439 retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); 1439 retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
1440 if (retval < 0) { 1440 if (retval < 0) {
@@ -1485,14 +1485,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1485 udhcp_run_script(NULL, "leasefail"); 1485 udhcp_run_script(NULL, "leasefail");
1486#if BB_MMU /* -b is not supported on NOMMU */ 1486#if BB_MMU /* -b is not supported on NOMMU */
1487 if (opt & OPT_b) { /* background if no lease */ 1487 if (opt & OPT_b) { /* background if no lease */
1488 bb_info_msg("No lease, forking to background"); 1488 bb_error_msg("no lease, forking to background");
1489 client_background(); 1489 client_background();
1490 /* do not background again! */ 1490 /* do not background again! */
1491 opt = ((opt & ~OPT_b) | OPT_f); 1491 opt = ((opt & ~OPT_b) | OPT_f);
1492 } else 1492 } else
1493#endif 1493#endif
1494 if (opt & OPT_n) { /* abort if no lease */ 1494 if (opt & OPT_n) { /* abort if no lease */
1495 bb_info_msg("No lease, failing"); 1495 bb_error_msg("no lease, failing");
1496 retval = 1; 1496 retval = 1;
1497 goto ret; 1497 goto ret;
1498 } 1498 }
@@ -1501,7 +1501,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1501 packet_num = 0; 1501 packet_num = 0;
1502 continue; 1502 continue;
1503 case REQUESTING: 1503 case REQUESTING:
1504 if (!discover_retries || packet_num < discover_retries) { 1504 if (packet_num < 3) {
1505 /* send broadcast select packet */ 1505 /* send broadcast select packet */
1506 send_select(xid, server_addr, requested_ip); 1506 send_select(xid, server_addr, requested_ip);
1507 timeout = discover_timeout; 1507 timeout = discover_timeout;
@@ -1520,7 +1520,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1520 state = RENEWING; 1520 state = RENEWING;
1521 client_config.first_secs = 0; /* make secs field count from 0 */ 1521 client_config.first_secs = 0; /* make secs field count from 0 */
1522 change_listen_mode(LISTEN_KERNEL); 1522 change_listen_mode(LISTEN_KERNEL);
1523 log1("Entering renew state"); 1523 log1("entering renew state");
1524 /* fall right through */ 1524 /* fall right through */
1525 case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ 1525 case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
1526 case_RENEW_REQUESTED: 1526 case_RENEW_REQUESTED:
@@ -1540,7 +1540,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1540 continue; 1540 continue;
1541 } 1541 }
1542 /* Timed out, enter rebinding state */ 1542 /* Timed out, enter rebinding state */
1543 log1("Entering rebinding state"); 1543 log1("entering rebinding state");
1544 state = REBINDING; 1544 state = REBINDING;
1545 /* fall right through */ 1545 /* fall right through */
1546 case REBINDING: 1546 case REBINDING:
@@ -1555,7 +1555,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1555 continue; 1555 continue;
1556 } 1556 }
1557 /* Timed out, enter init state */ 1557 /* Timed out, enter init state */
1558 bb_info_msg("Lease lost, entering init state"); 1558 bb_error_msg("lease lost, entering init state");
1559 udhcp_run_script(NULL, "deconfig"); 1559 udhcp_run_script(NULL, "deconfig");
1560 state = INIT_SELECTING; 1560 state = INIT_SELECTING;
1561 client_config.first_secs = 0; /* make secs field count from 0 */ 1561 client_config.first_secs = 0; /* make secs field count from 0 */
@@ -1603,7 +1603,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1603 timeout = INT_MAX; 1603 timeout = INT_MAX;
1604 continue; 1604 continue;
1605 case SIGTERM: 1605 case SIGTERM:
1606 bb_info_msg("Received SIGTERM"); 1606 bb_error_msg("received %s", "SIGTERM");
1607 goto ret0; 1607 goto ret0;
1608 } 1608 }
1609 1609
@@ -1621,7 +1621,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1621 len = udhcp_recv_raw_packet(&packet, sockfd); 1621 len = udhcp_recv_raw_packet(&packet, sockfd);
1622 if (len == -1) { 1622 if (len == -1) {
1623 /* Error is severe, reopen socket */ 1623 /* Error is severe, reopen socket */
1624 bb_info_msg("Read error: %s, reopening socket", strerror(errno)); 1624 bb_error_msg("read error: %s, reopening socket", strerror(errno));
1625 sleep(discover_timeout); /* 3 seconds by default */ 1625 sleep(discover_timeout); /* 3 seconds by default */
1626 change_listen_mode(listen_mode); /* just close and reopen */ 1626 change_listen_mode(listen_mode); /* just close and reopen */
1627 } 1627 }
@@ -1744,7 +1744,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1744 client_config.interface, 1744 client_config.interface,
1745 arpping_ms) 1745 arpping_ms)
1746 ) { 1746 ) {
1747 bb_info_msg("Offered address is in use " 1747 bb_error_msg("offered address is in use "
1748 "(got ARP reply), declining"); 1748 "(got ARP reply), declining");
1749 send_decline(/*xid,*/ server_addr, packet.yiaddr); 1749 send_decline(/*xid,*/ server_addr, packet.yiaddr);
1750 1750
@@ -1763,7 +1763,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1763#endif 1763#endif
1764 /* enter bound state */ 1764 /* enter bound state */
1765 temp_addr.s_addr = packet.yiaddr; 1765 temp_addr.s_addr = packet.yiaddr;
1766 bb_info_msg("Lease of %s obtained, lease time %u", 1766 bb_error_msg("lease of %s obtained, lease time %u",
1767 inet_ntoa(temp_addr), (unsigned)lease_seconds); 1767 inet_ntoa(temp_addr), (unsigned)lease_seconds);
1768 requested_ip = packet.yiaddr; 1768 requested_ip = packet.yiaddr;
1769 1769
@@ -1817,7 +1817,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1817 goto non_matching_svid; 1817 goto non_matching_svid;
1818 } 1818 }
1819 /* return to init state */ 1819 /* return to init state */
1820 bb_info_msg("Received DHCP NAK"); 1820 bb_error_msg("received %s", "DHCP NAK");
1821 udhcp_run_script(&packet, "nak"); 1821 udhcp_run_script(&packet, "nak");
1822 if (state != REQUESTING) 1822 if (state != REQUESTING)
1823 udhcp_run_script(NULL, "deconfig"); 1823 udhcp_run_script(NULL, "deconfig");
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 2de074f9b..2671ea3e2 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -61,11 +61,11 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc
61 || (dhcp_pkt->flags & htons(BROADCAST_FLAG)) 61 || (dhcp_pkt->flags & htons(BROADCAST_FLAG))
62 || dhcp_pkt->ciaddr == 0 62 || dhcp_pkt->ciaddr == 0
63 ) { 63 ) {
64 log1("Broadcasting packet to client"); 64 log1("broadcasting packet to client");
65 ciaddr = INADDR_BROADCAST; 65 ciaddr = INADDR_BROADCAST;
66 chaddr = MAC_BCAST_ADDR; 66 chaddr = MAC_BCAST_ADDR;
67 } else { 67 } else {
68 log1("Unicasting packet to client ciaddr"); 68 log1("unicasting packet to client ciaddr");
69 ciaddr = dhcp_pkt->ciaddr; 69 ciaddr = dhcp_pkt->ciaddr;
70 chaddr = dhcp_pkt->chaddr; 70 chaddr = dhcp_pkt->chaddr;
71 } 71 }
@@ -79,7 +79,7 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc
79/* Send a packet to gateway_nip using the kernel ip stack */ 79/* Send a packet to gateway_nip using the kernel ip stack */
80static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt) 80static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
81{ 81{
82 log1("Forwarding packet to relay"); 82 log1("forwarding packet to relay");
83 83
84 udhcp_send_kernel_packet(dhcp_pkt, 84 udhcp_send_kernel_packet(dhcp_pkt,
85 server_config.server_nip, SERVER_PORT, 85 server_config.server_nip, SERVER_PORT,
@@ -214,7 +214,7 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
214 add_server_options(&packet); 214 add_server_options(&packet);
215 215
216 addr.s_addr = packet.yiaddr; 216 addr.s_addr = packet.yiaddr;
217 bb_info_msg("Sending OFFER of %s", inet_ntoa(addr)); 217 bb_error_msg("sending OFFER of %s", inet_ntoa(addr));
218 /* send_packet emits error message itself if it detects failure */ 218 /* send_packet emits error message itself if it detects failure */
219 send_packet(&packet, /*force_bcast:*/ 0); 219 send_packet(&packet, /*force_bcast:*/ 0);
220} 220}
@@ -226,7 +226,7 @@ static NOINLINE void send_NAK(struct dhcp_packet *oldpacket)
226 226
227 init_packet(&packet, oldpacket, DHCPNAK); 227 init_packet(&packet, oldpacket, DHCPNAK);
228 228
229 log1("Sending NAK"); 229 log1("sending %s", "NAK");
230 send_packet(&packet, /*force_bcast:*/ 1); 230 send_packet(&packet, /*force_bcast:*/ 1);
231} 231}
232 232
@@ -247,7 +247,7 @@ static NOINLINE void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
247 add_server_options(&packet); 247 add_server_options(&packet);
248 248
249 addr.s_addr = yiaddr; 249 addr.s_addr = yiaddr;
250 bb_info_msg("Sending ACK to %s", inet_ntoa(addr)); 250 bb_error_msg("sending ACK to %s", inet_ntoa(addr));
251 send_packet(&packet, /*force_bcast:*/ 0); 251 send_packet(&packet, /*force_bcast:*/ 0);
252 252
253 p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME); 253 p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME);
@@ -361,7 +361,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
361 write_pidfile(server_config.pidfile); 361 write_pidfile(server_config.pidfile);
362 /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ 362 /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */
363 363
364 bb_info_msg("%s (v"BB_VER") started", applet_name); 364 bb_error_msg("started, v"BB_VER);
365 365
366 option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME); 366 option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME);
367 server_config.max_lease_sec = DEFAULT_LEASE_TIME; 367 server_config.max_lease_sec = DEFAULT_LEASE_TIME;
@@ -427,18 +427,18 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
427 goto continue_with_autotime; 427 goto continue_with_autotime;
428 } 428 }
429 if (retval < 0 && errno != EINTR) { 429 if (retval < 0 && errno != EINTR) {
430 log1("Error on select"); 430 log1("error on select");
431 continue; 431 continue;
432 } 432 }
433 433
434 switch (udhcp_sp_read(&rfds)) { 434 switch (udhcp_sp_read(&rfds)) {
435 case SIGUSR1: 435 case SIGUSR1:
436 bb_info_msg("Received SIGUSR1"); 436 bb_error_msg("received %s", "SIGUSR1");
437 write_leases(); 437 write_leases();
438 /* why not just reset the timeout, eh */ 438 /* why not just reset the timeout, eh */
439 goto continue_with_autotime; 439 goto continue_with_autotime;
440 case SIGTERM: 440 case SIGTERM:
441 bb_info_msg("Received SIGTERM"); 441 bb_error_msg("received %s", "SIGTERM");
442 write_leases(); 442 write_leases();
443 goto ret0; 443 goto ret0;
444 case 0: /* no signal: read a packet */ 444 case 0: /* no signal: read a packet */
@@ -451,7 +451,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
451 if (bytes < 0) { 451 if (bytes < 0) {
452 /* bytes can also be -2 ("bad packet data") */ 452 /* bytes can also be -2 ("bad packet data") */
453 if (bytes == -1 && errno != EINTR) { 453 if (bytes == -1 && errno != EINTR) {
454 log1("Read error: %s, reopening socket", strerror(errno)); 454 log1("read error: %s, reopening socket", strerror(errno));
455 close(server_socket); 455 close(server_socket);
456 server_socket = -1; 456 server_socket = -1;
457 } 457 }
@@ -486,7 +486,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
486 /* Look for a static/dynamic lease */ 486 /* Look for a static/dynamic lease */
487 static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr); 487 static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr);
488 if (static_lease_nip) { 488 if (static_lease_nip) {
489 bb_info_msg("Found static lease: %x", static_lease_nip); 489 bb_error_msg("found static lease: %x", static_lease_nip);
490 memcpy(&fake_lease.lease_mac, &packet.chaddr, 6); 490 memcpy(&fake_lease.lease_mac, &packet.chaddr, 6);
491 fake_lease.lease_nip = static_lease_nip; 491 fake_lease.lease_nip = static_lease_nip;
492 fake_lease.expires = 0; 492 fake_lease.expires = 0;
@@ -504,13 +504,13 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
504 switch (state[0]) { 504 switch (state[0]) {
505 505
506 case DHCPDISCOVER: 506 case DHCPDISCOVER:
507 log1("Received DISCOVER"); 507 log1("received %s", "DISCOVER");
508 508
509 send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms); 509 send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms);
510 break; 510 break;
511 511
512 case DHCPREQUEST: 512 case DHCPREQUEST:
513 log1("Received REQUEST"); 513 log1("received %s", "REQUEST");
514/* RFC 2131: 514/* RFC 2131:
515 515
516o DHCPREQUEST generated during SELECTING state: 516o DHCPREQUEST generated during SELECTING state:
@@ -635,7 +635,7 @@ o DHCPREQUEST generated during REBINDING state:
635 * chaddr must be filled in, 635 * chaddr must be filled in,
636 * ciaddr must be 0 (we do not check this) 636 * ciaddr must be 0 (we do not check this)
637 */ 637 */
638 log1("Received DECLINE"); 638 log1("received %s", "DECLINE");
639 if (server_id_opt 639 if (server_id_opt
640 && requested_ip_opt 640 && requested_ip_opt
641 && lease /* chaddr matches this lease */ 641 && lease /* chaddr matches this lease */
@@ -655,7 +655,7 @@ o DHCPREQUEST generated during REBINDING state:
655 * chaddr must be filled in, 655 * chaddr must be filled in,
656 * ciaddr must be filled in 656 * ciaddr must be filled in
657 */ 657 */
658 log1("Received RELEASE"); 658 log1("received %s", "RELEASE");
659 if (server_id_opt 659 if (server_id_opt
660 && lease /* chaddr matches this lease */ 660 && lease /* chaddr matches this lease */
661 && packet.ciaddr == lease->lease_nip 661 && packet.ciaddr == lease->lease_nip
@@ -665,7 +665,7 @@ o DHCPREQUEST generated during REBINDING state:
665 break; 665 break;
666 666
667 case DHCPINFORM: 667 case DHCPINFORM:
668 log1("Received INFORM"); 668 log1("received %s", "INFORM");
669 send_inform(&packet); 669 send_inform(&packet);
670 break; 670 break;
671 } 671 }
diff --git a/networking/udhcp/domain_codec.c b/networking/udhcp/domain_codec.c
index c1325d8be..5a923cc2c 100644
--- a/networking/udhcp/domain_codec.c
+++ b/networking/udhcp/domain_codec.c
@@ -7,6 +7,7 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */ 8 */
9#ifdef DNS_COMPR_TESTING 9#ifdef DNS_COMPR_TESTING
10# define _GNU_SOURCE
10# define FAST_FUNC /* nothing */ 11# define FAST_FUNC /* nothing */
11# define xmalloc malloc 12# define xmalloc malloc
12# include <stdlib.h> 13# include <stdlib.h>
@@ -42,7 +43,7 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre)
42 */ 43 */
43 while (1) { 44 while (1) {
44 /* note: "return NULL" below are leak-safe since 45 /* note: "return NULL" below are leak-safe since
45 * dst isn't yet allocated */ 46 * dst isn't allocated yet */
46 const uint8_t *c; 47 const uint8_t *c;
47 unsigned crtpos, retpos, depth, len; 48 unsigned crtpos, retpos, depth, len;
48 49
@@ -63,11 +64,10 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre)
63 if (crtpos + *c + 1 > clen) /* label too long? abort */ 64 if (crtpos + *c + 1 > clen) /* label too long? abort */
64 return NULL; 65 return NULL;
65 if (dst) 66 if (dst)
66 memcpy(dst + len, c + 1, *c); 67 /* \3com ---> "com." */
68 ((char*)mempcpy(dst + len, c + 1, *c))[0] = '.';
67 len += *c + 1; 69 len += *c + 1;
68 crtpos += *c + 1; 70 crtpos += *c + 1;
69 if (dst)
70 dst[len - 1] = '.';
71 } else { 71 } else {
72 /* NUL: end of current domain name */ 72 /* NUL: end of current domain name */
73 if (retpos == 0) { 73 if (retpos == 0) {
@@ -78,7 +78,10 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre)
78 crtpos = retpos; 78 crtpos = retpos;
79 retpos = depth = 0; 79 retpos = depth = 0;
80 } 80 }
81 if (dst) 81 if (dst && len != 0)
82 /* \4host\3com\0\4host and we are at \0:
83 * \3com was converted to "com.", change dot to space.
84 */
82 dst[len - 1] = ' '; 85 dst[len - 1] = ' ';
83 } 86 }
84 87
@@ -95,9 +98,8 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre)
95 if (!dst) { /* first pass? */ 98 if (!dst) { /* first pass? */
96 /* allocate dst buffer and copy pre */ 99 /* allocate dst buffer and copy pre */
97 unsigned plen = strlen(pre); 100 unsigned plen = strlen(pre);
98 ret = dst = xmalloc(plen + len); 101 ret = xmalloc(plen + len);
99 memcpy(dst, pre, plen); 102 dst = stpcpy(ret, pre);
100 dst += plen;
101 } else { 103 } else {
102 dst[len - 1] = '\0'; 104 dst[len - 1] = '\0';
103 break; 105 break;
@@ -228,6 +230,9 @@ int main(int argc, char **argv)
228 int len; 230 int len;
229 uint8_t *encoded; 231 uint8_t *encoded;
230 232
233 uint8_t str[6] = { 0x00, 0x00, 0x02, 0x65, 0x65, 0x00 };
234 printf("NUL:'%s'\n", dname_dec(str, 6, ""));
235
231#define DNAME_DEC(encoded,pre) dname_dec((uint8_t*)(encoded), sizeof(encoded), (pre)) 236#define DNAME_DEC(encoded,pre) dname_dec((uint8_t*)(encoded), sizeof(encoded), (pre))
232 printf("'%s'\n", DNAME_DEC("\4host\3com\0", "test1:")); 237 printf("'%s'\n", DNAME_DEC("\4host\3com\0", "test1:"));
233 printf("test2:'%s'\n", DNAME_DEC("\4host\3com\0\4host\3com\0", "")); 238 printf("test2:'%s'\n", DNAME_DEC("\4host\3com\0\4host\3com\0", ""));
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 1c8808c0f..7b57c6258 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -195,7 +195,11 @@ void FAST_FUNC read_leases(const char *file)
195 uint32_t static_nip; 195 uint32_t static_nip;
196 196
197 if (expires <= 0) 197 if (expires <= 0)
198 continue; 198 /* We keep expired leases: add_lease() will add
199 * a lease with 0 seconds remaining.
200 * Fewer IP address changes this way for mass reboot scenario.
201 */
202 expires = 0;
199 203
200 /* Check if there is a different static lease for this IP or MAC */ 204 /* Check if there is a different static lease for this IP or MAC */
201 static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac); 205 static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac);
@@ -222,7 +226,7 @@ void FAST_FUNC read_leases(const char *file)
222#endif 226#endif
223 } 227 }
224 } 228 }
225 log1("Read %d leases", i); 229 log1("read %d leases", i);
226 ret: 230 ret:
227 close(fd); 231 close(fd);
228} 232}
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index 844bb60b1..6642e396d 100644
--- a/networking/udhcp/leases.c
+++ b/networking/udhcp/leases.c
@@ -17,7 +17,9 @@ static struct dyn_lease *oldest_expired_lease(void)
17 /* Unexpired leases have g_leases[i].expires >= current time 17 /* Unexpired leases have g_leases[i].expires >= current time
18 * and therefore can't ever match */ 18 * and therefore can't ever match */
19 for (i = 0; i < server_config.max_leases; i++) { 19 for (i = 0; i < server_config.max_leases; i++) {
20 if (g_leases[i].expires < oldest_time) { 20 if (g_leases[i].expires == 0 /* empty entry */
21 || g_leases[i].expires < oldest_time
22 ) {
21 oldest_time = g_leases[i].expires; 23 oldest_time = g_leases[i].expires;
22 oldest_lease = &g_leases[i]; 24 oldest_lease = &g_leases[i];
23 } 25 }
@@ -131,7 +133,7 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigne
131 return r; 133 return r;
132 134
133 temp.s_addr = nip; 135 temp.s_addr = nip;
134 bb_info_msg("%s belongs to someone, reserving it for %u seconds", 136 bb_error_msg("%s belongs to someone, reserving it for %u seconds",
135 inet_ntoa(temp), (unsigned)server_config.conflict_time); 137 inet_ntoa(temp), (unsigned)server_config.conflict_time);
136 add_lease(NULL, nip, server_config.conflict_time, NULL, 0); 138 add_lease(NULL, nip, server_config.conflict_time, NULL, 0);
137 return 0; 139 return 0;
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 148f52551..0a31f2643 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -38,8 +38,8 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet)
38 if (dhcp_verbose < 2) 38 if (dhcp_verbose < 2)
39 return; 39 return;
40 40
41 bb_info_msg( 41 bb_error_msg(
42 //" op %x" 42 //"op %x"
43 //" htype %x" 43 //" htype %x"
44 " hlen %x" 44 " hlen %x"
45 //" hops %x" 45 //" hops %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_info_msg(" chaddr %s", buf); 76 bb_error_msg("chaddr %s", buf);
77} 77}
78#endif 78#endif
79 79
@@ -85,17 +85,17 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd)
85 memset(packet, 0, sizeof(*packet)); 85 memset(packet, 0, sizeof(*packet));
86 bytes = safe_read(fd, packet, sizeof(*packet)); 86 bytes = safe_read(fd, packet, sizeof(*packet));
87 if (bytes < 0) { 87 if (bytes < 0) {
88 log1("Packet read error, ignoring"); 88 log1("packet read error, ignoring");
89 return bytes; /* returns -1 */ 89 return bytes; /* returns -1 */
90 } 90 }
91 91
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_info_msg("Packet with bad magic, ignoring"); 95 bb_error_msg("packet with bad magic, ignoring");
96 return -2; 96 return -2;
97 } 97 }
98 log1("Received a packet"); 98 log1("received %s", "a packet");
99 udhcp_dump_packet(packet); 99 udhcp_dump_packet(packet);
100 100
101 return bytes; 101 return bytes;
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index a42106960..4fd79f423 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -56,7 +56,7 @@ int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t
56 close(fd); 56 close(fd);
57 return -1; 57 return -1;
58 } 58 }
59 log1("Adapter index %d", ifr->ifr_ifindex); 59 log1("adapter index %d", ifr->ifr_ifindex);
60 *ifindex = ifr->ifr_ifindex; 60 *ifindex = ifr->ifr_ifindex;
61 } 61 }
62 62
@@ -82,7 +82,7 @@ int FAST_FUNC udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf)
82 struct sockaddr_in addr; 82 struct sockaddr_in addr;
83 char *colon; 83 char *colon;
84 84
85 log1("Opening listen socket on *:%d %s", port, inf); 85 log1("opening listen socket on *:%d %s", port, inf);
86 fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); 86 fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
87 87
88 setsockopt_reuseaddr(fd); 88 setsockopt_reuseaddr(fd);
diff --git a/networking/udhcp/static_leases.c b/networking/udhcp/static_leases.c
index f4a24ab62..b7f9e5c59 100644
--- a/networking/udhcp/static_leases.c
+++ b/networking/udhcp/static_leases.c
@@ -66,7 +66,7 @@ void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp)
66 66
67 cur = *st_lease_pp; 67 cur = *st_lease_pp;
68 while (cur) { 68 while (cur) {
69 bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", 69 bb_error_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x",
70 cur->mac[0], cur->mac[1], cur->mac[2], 70 cur->mac[0], cur->mac[1], cur->mac[2],
71 cur->mac[3], cur->mac[4], cur->mac[5], 71 cur->mac[3], cur->mac[4], cur->mac[5],
72 cur->nip 72 cur->nip
diff --git a/networking/wget.c b/networking/wget.c
index edf8fd8af..87d3bbd13 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -203,7 +203,7 @@ struct globals {
203 const char *user_agent; /* "User-Agent" header field */ 203 const char *user_agent; /* "User-Agent" header field */
204#if ENABLE_FEATURE_WGET_TIMEOUT 204#if ENABLE_FEATURE_WGET_TIMEOUT
205 unsigned timeout_seconds; 205 unsigned timeout_seconds;
206 bool connecting; 206 bool die_if_timed_out;
207#endif 207#endif
208 int output_fd; 208 int output_fd;
209 int o_flags; 209 int o_flags;
@@ -333,9 +333,20 @@ static char* sanitize_string(char *s)
333static void alarm_handler(int sig UNUSED_PARAM) 333static void alarm_handler(int sig UNUSED_PARAM)
334{ 334{
335 /* This is theoretically unsafe (uses stdio and malloc in signal handler) */ 335 /* This is theoretically unsafe (uses stdio and malloc in signal handler) */
336 if (G.connecting) 336 if (G.die_if_timed_out)
337 bb_error_msg_and_die("download timed out"); 337 bb_error_msg_and_die("download timed out");
338} 338}
339static void set_alarm(void)
340{
341 if (G.timeout_seconds) {
342 alarm(G.timeout_seconds);
343 G.die_if_timed_out = 1;
344 }
345}
346# define clear_alarm() ((void)(G.die_if_timed_out = 0))
347#else
348# define set_alarm() ((void)0)
349# define clear_alarm() ((void)0)
339#endif 350#endif
340 351
341static FILE *open_socket(len_and_sockaddr *lsa) 352static FILE *open_socket(len_and_sockaddr *lsa)
@@ -343,9 +354,9 @@ static FILE *open_socket(len_and_sockaddr *lsa)
343 int fd; 354 int fd;
344 FILE *fp; 355 FILE *fp;
345 356
346 IF_FEATURE_WGET_TIMEOUT(alarm(G.timeout_seconds); G.connecting = 1;) 357 set_alarm();
347 fd = xconnect_stream(lsa); 358 fd = xconnect_stream(lsa);
348 IF_FEATURE_WGET_TIMEOUT(G.connecting = 0;) 359 clear_alarm();
349 360
350 /* glibc 2.4 seems to try seeking on it - ??! */ 361 /* glibc 2.4 seems to try seeking on it - ??! */
351 /* hopefully it understands what ESPIPE means... */ 362 /* hopefully it understands what ESPIPE means... */
@@ -357,14 +368,15 @@ static FILE *open_socket(len_and_sockaddr *lsa)
357} 368}
358 369
359/* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */ 370/* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */
360/* FIXME: does not respect FEATURE_WGET_TIMEOUT and -T N: */
361static char fgets_and_trim(FILE *fp) 371static char fgets_and_trim(FILE *fp)
362{ 372{
363 char c; 373 char c;
364 char *buf_ptr; 374 char *buf_ptr;
365 375
376 set_alarm();
366 if (fgets(G.wget_buf, sizeof(G.wget_buf) - 1, fp) == NULL) 377 if (fgets(G.wget_buf, sizeof(G.wget_buf) - 1, fp) == NULL)
367 bb_perror_msg_and_die("error getting response"); 378 bb_perror_msg_and_die("error getting response");
379 clear_alarm();
368 380
369 buf_ptr = strchrnul(G.wget_buf, '\n'); 381 buf_ptr = strchrnul(G.wget_buf, '\n');
370 c = *buf_ptr; 382 c = *buf_ptr;
diff --git a/networking/zcip.c b/networking/zcip.c
index 1d6910555..c93082619 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -176,7 +176,7 @@ static int run(char *argv[3], const char *param, uint32_t nip)
176 xsetenv("ip", addr); 176 xsetenv("ip", addr);
177 fmt -= 3; 177 fmt -= 3;
178 } 178 }
179 bb_info_msg(fmt, argv[2], argv[0], addr); 179 bb_error_msg(fmt, argv[2], argv[0], addr);
180 180
181 status = spawn_and_wait(argv + 1); 181 status = spawn_and_wait(argv + 1);
182 if (status < 0) { 182 if (status < 0) {
@@ -317,7 +317,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
317#if BB_MMU 317#if BB_MMU
318 bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/); 318 bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/);
319#endif 319#endif
320 bb_info_msg("start, interface %s", argv_intf); 320 bb_error_msg("start, interface %s", argv_intf);
321 } 321 }
322 322
323 // Run the dynamic address negotiation protocol, 323 // Run the dynamic address negotiation protocol,