diff options
author | Ron Yorston <rmy@pobox.com> | 2019-08-16 09:42:39 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-08-16 09:45:21 +0100 |
commit | 517cf74f6265ec4308b790b637b3f9778cbdc6e0 (patch) | |
tree | be9337069b60ca1bb03565d8575bacfc71181003 /networking | |
parent | ae65dc37bcc9b1d9cef0b111131c79dc4ba1bf51 (diff) | |
parent | ac78f2ac96b3efd6551a08e7dc609efa1fb69481 (diff) | |
download | busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.tar.gz busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.tar.bz2 busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'networking')
52 files changed, 452 insertions, 362 deletions
diff --git a/networking/arp.c b/networking/arp.c index 71bfe3cbf..6519f8156 100644 --- a/networking/arp.c +++ b/networking/arp.c | |||
@@ -116,7 +116,7 @@ static int arp_del(char **args) | |||
116 | /* Resolve the host name. */ | 116 | /* Resolve the host name. */ |
117 | host = *args; | 117 | host = *args; |
118 | if (ap->input(host, &sa) < 0) { | 118 | if (ap->input(host, &sa) < 0) { |
119 | bb_herror_msg_and_die("%s", host); | 119 | bb_simple_herror_msg_and_die(host); |
120 | } | 120 | } |
121 | 121 | ||
122 | /* If a host has more than one address, use the correct one! */ | 122 | /* If a host has more than one address, use the correct one! */ |
@@ -149,7 +149,7 @@ static int arp_del(char **args) | |||
149 | #ifdef HAVE_ATF_DONTPUB | 149 | #ifdef HAVE_ATF_DONTPUB |
150 | req.arp_flags |= ATF_DONTPUB; | 150 | req.arp_flags |= ATF_DONTPUB; |
151 | #else | 151 | #else |
152 | bb_error_msg("feature ATF_DONTPUB is not supported"); | 152 | bb_simple_error_msg("feature ATF_DONTPUB is not supported"); |
153 | #endif | 153 | #endif |
154 | args++; | 154 | args++; |
155 | break; | 155 | break; |
@@ -157,7 +157,7 @@ static int arp_del(char **args) | |||
157 | #ifdef HAVE_ATF_MAGIC | 157 | #ifdef HAVE_ATF_MAGIC |
158 | req.arp_flags |= ATF_MAGIC; | 158 | req.arp_flags |= ATF_MAGIC; |
159 | #else | 159 | #else |
160 | bb_error_msg("feature ATF_MAGIC is not supported"); | 160 | bb_simple_error_msg("feature ATF_MAGIC is not supported"); |
161 | #endif | 161 | #endif |
162 | args++; | 162 | args++; |
163 | break; | 163 | break; |
@@ -173,7 +173,7 @@ static int arp_del(char **args) | |||
173 | if (strcmp(*args, "255.255.255.255") != 0) { | 173 | if (strcmp(*args, "255.255.255.255") != 0) { |
174 | host = *args; | 174 | host = *args; |
175 | if (ap->input(host, &sa) < 0) { | 175 | if (ap->input(host, &sa) < 0) { |
176 | bb_herror_msg_and_die("%s", host); | 176 | bb_simple_herror_msg_and_die(host); |
177 | } | 177 | } |
178 | memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr)); | 178 | memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr)); |
179 | req.arp_flags |= ATF_NETMASK; | 179 | req.arp_flags |= ATF_NETMASK; |
@@ -195,7 +195,7 @@ static int arp_del(char **args) | |||
195 | /* Call the kernel. */ | 195 | /* Call the kernel. */ |
196 | if (flags & 2) { | 196 | if (flags & 2) { |
197 | if (option_mask32 & ARP_OPT_v) | 197 | if (option_mask32 & ARP_OPT_v) |
198 | bb_error_msg("SIOCDARP(nopub)"); | 198 | bb_simple_error_msg("SIOCDARP(nopub)"); |
199 | err = ioctl(sockfd, SIOCDARP, &req); | 199 | err = ioctl(sockfd, SIOCDARP, &req); |
200 | if (err < 0) { | 200 | if (err < 0) { |
201 | if (errno == ENXIO) { | 201 | if (errno == ENXIO) { |
@@ -204,20 +204,20 @@ static int arp_del(char **args) | |||
204 | printf("No ARP entry for %s\n", host); | 204 | printf("No ARP entry for %s\n", host); |
205 | return -1; | 205 | return -1; |
206 | } | 206 | } |
207 | bb_perror_msg_and_die("SIOCDARP(priv)"); | 207 | bb_simple_perror_msg_and_die("SIOCDARP(priv)"); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | if ((flags & 1) && err) { | 210 | if ((flags & 1) && err) { |
211 | nopub: | 211 | nopub: |
212 | req.arp_flags |= ATF_PUBL; | 212 | req.arp_flags |= ATF_PUBL; |
213 | if (option_mask32 & ARP_OPT_v) | 213 | if (option_mask32 & ARP_OPT_v) |
214 | bb_error_msg("SIOCDARP(pub)"); | 214 | bb_simple_error_msg("SIOCDARP(pub)"); |
215 | if (ioctl(sockfd, SIOCDARP, &req) < 0) { | 215 | if (ioctl(sockfd, SIOCDARP, &req) < 0) { |
216 | if (errno == ENXIO) { | 216 | if (errno == ENXIO) { |
217 | printf("No ARP entry for %s\n", host); | 217 | printf("No ARP entry for %s\n", host); |
218 | return -1; | 218 | return -1; |
219 | } | 219 | } |
220 | bb_perror_msg_and_die("SIOCDARP(pub)"); | 220 | bb_simple_perror_msg_and_die("SIOCDARP(pub)"); |
221 | } | 221 | } |
222 | } | 222 | } |
223 | return 0; | 223 | return 0; |
@@ -233,7 +233,7 @@ static void arp_getdevhw(char *ifname, struct sockaddr *sa) | |||
233 | ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr, | 233 | ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr, |
234 | "can't get HW-Address for '%s'", ifname); | 234 | "can't get HW-Address for '%s'", ifname); |
235 | if (hw_set && (ifr.ifr_hwaddr.sa_family != hw->type)) { | 235 | if (hw_set && (ifr.ifr_hwaddr.sa_family != hw->type)) { |
236 | bb_error_msg_and_die("protocol type mismatch"); | 236 | bb_simple_error_msg_and_die("protocol type mismatch"); |
237 | } | 237 | } |
238 | memcpy(sa, &(ifr.ifr_hwaddr), sizeof(struct sockaddr)); | 238 | memcpy(sa, &(ifr.ifr_hwaddr), sizeof(struct sockaddr)); |
239 | 239 | ||
@@ -261,20 +261,20 @@ static int arp_set(char **args) | |||
261 | 261 | ||
262 | host = *args++; | 262 | host = *args++; |
263 | if (ap->input(host, &sa) < 0) { | 263 | if (ap->input(host, &sa) < 0) { |
264 | bb_herror_msg_and_die("%s", host); | 264 | bb_simple_herror_msg_and_die(host); |
265 | } | 265 | } |
266 | /* If a host has more than one address, use the correct one! */ | 266 | /* If a host has more than one address, use the correct one! */ |
267 | memcpy(&req.arp_pa, &sa, sizeof(struct sockaddr)); | 267 | memcpy(&req.arp_pa, &sa, sizeof(struct sockaddr)); |
268 | 268 | ||
269 | /* Fetch the hardware address. */ | 269 | /* Fetch the hardware address. */ |
270 | if (*args == NULL) { | 270 | if (*args == NULL) { |
271 | bb_error_msg_and_die("need hardware address"); | 271 | bb_simple_error_msg_and_die("need hardware address"); |
272 | } | 272 | } |
273 | if (option_mask32 & ARP_OPT_D) { | 273 | if (option_mask32 & ARP_OPT_D) { |
274 | arp_getdevhw(*args++, &req.arp_ha); | 274 | arp_getdevhw(*args++, &req.arp_ha); |
275 | } else { | 275 | } else { |
276 | if (hw->input(*args++, &req.arp_ha) < 0) { | 276 | if (hw->input(*args++, &req.arp_ha) < 0) { |
277 | bb_error_msg_and_die("invalid hardware address"); | 277 | bb_simple_error_msg_and_die("invalid hardware address"); |
278 | } | 278 | } |
279 | } | 279 | } |
280 | 280 | ||
@@ -302,7 +302,7 @@ static int arp_set(char **args) | |||
302 | #ifdef HAVE_ATF_DONTPUB | 302 | #ifdef HAVE_ATF_DONTPUB |
303 | flags |= ATF_DONTPUB; | 303 | flags |= ATF_DONTPUB; |
304 | #else | 304 | #else |
305 | bb_error_msg("feature ATF_DONTPUB is not supported"); | 305 | bb_simple_error_msg("feature ATF_DONTPUB is not supported"); |
306 | #endif | 306 | #endif |
307 | args++; | 307 | args++; |
308 | break; | 308 | break; |
@@ -310,7 +310,7 @@ static int arp_set(char **args) | |||
310 | #ifdef HAVE_ATF_MAGIC | 310 | #ifdef HAVE_ATF_MAGIC |
311 | flags |= ATF_MAGIC; | 311 | flags |= ATF_MAGIC; |
312 | #else | 312 | #else |
313 | bb_error_msg("feature ATF_MAGIC is not supported"); | 313 | bb_simple_error_msg("feature ATF_MAGIC is not supported"); |
314 | #endif | 314 | #endif |
315 | args++; | 315 | args++; |
316 | break; | 316 | break; |
@@ -326,7 +326,7 @@ static int arp_set(char **args) | |||
326 | if (strcmp(*args, "255.255.255.255") != 0) { | 326 | if (strcmp(*args, "255.255.255.255") != 0) { |
327 | host = *args; | 327 | host = *args; |
328 | if (ap->input(host, &sa) < 0) { | 328 | if (ap->input(host, &sa) < 0) { |
329 | bb_herror_msg_and_die("%s", host); | 329 | bb_simple_herror_msg_and_die(host); |
330 | } | 330 | } |
331 | memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr)); | 331 | memcpy(&req.arp_netmask, &sa, sizeof(struct sockaddr)); |
332 | flags |= ATF_NETMASK; | 332 | flags |= ATF_NETMASK; |
@@ -346,7 +346,7 @@ static int arp_set(char **args) | |||
346 | 346 | ||
347 | /* Call the kernel. */ | 347 | /* Call the kernel. */ |
348 | if (option_mask32 & ARP_OPT_v) | 348 | if (option_mask32 & ARP_OPT_v) |
349 | bb_error_msg("SIOCSARP()"); | 349 | bb_simple_error_msg("SIOCSARP()"); |
350 | xioctl(sockfd, SIOCSARP, &req); | 350 | xioctl(sockfd, SIOCSARP, &req); |
351 | return 0; | 351 | return 0; |
352 | } | 352 | } |
@@ -422,7 +422,7 @@ static int arp_show(char *name) | |||
422 | if (name != NULL) { | 422 | if (name != NULL) { |
423 | /* Resolve the host name. */ | 423 | /* Resolve the host name. */ |
424 | if (ap->input(name, &sa) < 0) { | 424 | if (ap->input(name, &sa) < 0) { |
425 | bb_herror_msg_and_die("%s", name); | 425 | bb_simple_herror_msg_and_die(name); |
426 | } | 426 | } |
427 | host = xstrdup(ap->sprint(&sa, 1)); | 427 | host = xstrdup(ap->sprint(&sa, 1)); |
428 | } | 428 | } |
@@ -530,7 +530,7 @@ int arp_main(int argc UNUSED_PARAM, char **argv) | |||
530 | /* Now see what we have to do here... */ | 530 | /* Now see what we have to do here... */ |
531 | if (opts & (ARP_OPT_d | ARP_OPT_s)) { | 531 | if (opts & (ARP_OPT_d | ARP_OPT_s)) { |
532 | if (argv[0] == NULL) | 532 | if (argv[0] == NULL) |
533 | bb_error_msg_and_die("need host name"); | 533 | bb_simple_error_msg_and_die("need host name"); |
534 | if (opts & ARP_OPT_s) | 534 | if (opts & ARP_OPT_s) |
535 | return arp_set(argv); | 535 | return arp_set(argv); |
536 | return arp_del(argv); | 536 | return arp_del(argv); |
diff --git a/networking/arping.c b/networking/arping.c index 901578b68..2a256aaa0 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -375,7 +375,7 @@ int arping_main(int argc UNUSED_PARAM, char **argv) | |||
375 | xconnect(probe_fd, (struct sockaddr *) &G.probe_saddr, sizeof(G.probe_saddr)); | 375 | xconnect(probe_fd, (struct sockaddr *) &G.probe_saddr, sizeof(G.probe_saddr)); |
376 | bb_getsockname(probe_fd, (struct sockaddr *) &G.probe_saddr, sizeof(G.probe_saddr)); | 376 | bb_getsockname(probe_fd, (struct sockaddr *) &G.probe_saddr, sizeof(G.probe_saddr)); |
377 | if (G.probe_saddr.sin_family != AF_INET) | 377 | if (G.probe_saddr.sin_family != AF_INET) |
378 | bb_error_msg_and_die("no IP address configured"); | 378 | bb_simple_error_msg_and_die("no IP address configured"); |
379 | src = G.probe_saddr.sin_addr; | 379 | src = G.probe_saddr.sin_addr; |
380 | } | 380 | } |
381 | close(probe_fd); | 381 | close(probe_fd); |
@@ -430,7 +430,7 @@ int arping_main(int argc UNUSED_PARAM, char **argv) | |||
430 | /* Don't allow SIGALRMs while we process the reply */ | 430 | /* Don't allow SIGALRMs while we process the reply */ |
431 | sigprocmask(SIG_BLOCK, &G.sset, NULL); | 431 | sigprocmask(SIG_BLOCK, &G.sset, NULL); |
432 | if (cc < 0) { | 432 | if (cc < 0) { |
433 | bb_perror_msg("recvfrom"); | 433 | bb_simple_perror_msg("recvfrom"); |
434 | continue; | 434 | continue; |
435 | } | 435 | } |
436 | recv_pack(G.packet, cc, &from); | 436 | recv_pack(G.packet, cc, &from); |
diff --git a/networking/brctl.c b/networking/brctl.c index f44ad9c8d..586ca9b0c 100644 --- a/networking/brctl.c +++ b/networking/brctl.c | |||
@@ -107,6 +107,7 @@ static unsigned str_to_jiffies(const char *time_str) | |||
107 | 107 | ||
108 | #define filedata bb_common_bufsiz1 | 108 | #define filedata bb_common_bufsiz1 |
109 | 109 | ||
110 | #if ENABLE_FEATURE_BRCTL_SHOW | ||
110 | static int read_file(const char *name) | 111 | static int read_file(const char *name) |
111 | { | 112 | { |
112 | int n = open_read_close(name, filedata, COMMON_BUFSIZE - 1); | 113 | int n = open_read_close(name, filedata, COMMON_BUFSIZE - 1); |
@@ -176,7 +177,9 @@ static int show_bridge(const char *name, int need_hdr) | |||
176 | bb_putchar('\n'); | 177 | bb_putchar('\n'); |
177 | return 0; | 178 | return 0; |
178 | } | 179 | } |
180 | #endif | ||
179 | 181 | ||
182 | #if ENABLE_FEATURE_BRCTL_FANCY | ||
180 | static void write_uint(const char *name, const char *leaf, unsigned val) | 183 | static void write_uint(const char *name, const char *leaf, unsigned val) |
181 | { | 184 | { |
182 | char pathbuf[IFNAMSIZ + sizeof("/bridge/bridge_id") + 32]; | 185 | char pathbuf[IFNAMSIZ + sizeof("/bridge/bridge_id") + 32]; |
@@ -193,6 +196,7 @@ static void write_uint(const char *name, const char *leaf, unsigned val) | |||
193 | bb_simple_perror_msg_and_die(name); | 196 | bb_simple_perror_msg_and_die(name); |
194 | close(fd); | 197 | close(fd); |
195 | } | 198 | } |
199 | #endif | ||
196 | 200 | ||
197 | int brctl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 201 | int brctl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
198 | int brctl_main(int argc UNUSED_PARAM, char **argv) | 202 | int brctl_main(int argc UNUSED_PARAM, char **argv) |
diff --git a/networking/dnsd.c b/networking/dnsd.c index f2c6bddc6..0ff0290fb 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -395,11 +395,11 @@ static int process_packet(struct dns_entry *conf_data, | |||
395 | 395 | ||
396 | head = (struct dns_head *)buf; | 396 | head = (struct dns_head *)buf; |
397 | if (head->nquer == 0) { | 397 | if (head->nquer == 0) { |
398 | bb_error_msg("packet has 0 queries, ignored"); | 398 | bb_simple_error_msg("packet has 0 queries, ignored"); |
399 | return 0; /* don't reply */ | 399 | return 0; /* don't reply */ |
400 | } | 400 | } |
401 | if (head->flags & htons(0x8000)) { /* QR bit */ | 401 | if (head->flags & htons(0x8000)) { /* QR bit */ |
402 | bb_error_msg("response packet, ignored"); | 402 | bb_simple_error_msg("response packet, ignored"); |
403 | return 0; /* don't reply */ | 403 | return 0; /* don't reply */ |
404 | } | 404 | } |
405 | /* QR = 1 "response", RCODE = 4 "Not Implemented" */ | 405 | /* QR = 1 "response", RCODE = 4 "Not Implemented" */ |
@@ -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_info_msg("returning positive reply"); | 477 | bb_simple_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); |
@@ -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_info_msg("got UDP packet"); | 560 | bb_simple_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/ether-wake.c b/networking/ether-wake.c index acaac16f8..f45d43609 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c | |||
@@ -182,7 +182,7 @@ static int get_wol_pw(const char *ethoptarg, unsigned char *wol_passwd) | |||
182 | byte_cnt = sscanf(ethoptarg, "%u.%u.%u.%u", | 182 | byte_cnt = sscanf(ethoptarg, "%u.%u.%u.%u", |
183 | &passwd[0], &passwd[1], &passwd[2], &passwd[3]); | 183 | &passwd[0], &passwd[1], &passwd[2], &passwd[3]); |
184 | if (byte_cnt < 4) { | 184 | if (byte_cnt < 4) { |
185 | bb_error_msg("can't read Wake-On-LAN pass"); | 185 | bb_simple_error_msg("can't read Wake-On-LAN pass"); |
186 | return 0; | 186 | return 0; |
187 | } | 187 | } |
188 | // TODO: check invalid numbers >255?? | 188 | // TODO: check invalid numbers >255?? |
@@ -266,7 +266,7 @@ int ether_wake_main(int argc UNUSED_PARAM, char **argv) | |||
266 | /* This is necessary for broadcasts to work */ | 266 | /* This is necessary for broadcasts to work */ |
267 | if (flags /* & 1 OPT_BROADCAST */) { | 267 | if (flags /* & 1 OPT_BROADCAST */) { |
268 | if (setsockopt_broadcast(s) != 0) | 268 | if (setsockopt_broadcast(s) != 0) |
269 | bb_perror_msg("SO_BROADCAST"); | 269 | bb_simple_perror_msg("SO_BROADCAST"); |
270 | } | 270 | } |
271 | 271 | ||
272 | #if defined(PF_PACKET) | 272 | #if defined(PF_PACKET) |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index bff90538f..7b6b89057 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -220,7 +220,7 @@ int ftp_receive(const char *local_path, char *server_path) | |||
220 | struct stat sbuf; | 220 | struct stat sbuf; |
221 | /* lstat would be wrong here! */ | 221 | /* lstat would be wrong here! */ |
222 | if (stat(local_path, &sbuf) < 0) { | 222 | if (stat(local_path, &sbuf) < 0) { |
223 | bb_perror_msg_and_die("stat"); | 223 | bb_simple_perror_msg_and_die("stat"); |
224 | } | 224 | } |
225 | if (sbuf.st_size > 0) { | 225 | if (sbuf.st_size > 0) { |
226 | beg_range = sbuf.st_size; | 226 | beg_range = sbuf.st_size; |
diff --git a/networking/hostname.c b/networking/hostname.c index 248d8b65a..f96daed95 100644 --- a/networking/hostname.c +++ b/networking/hostname.c | |||
@@ -61,7 +61,7 @@ static void do_sethostname(char *s, int isfile) | |||
61 | } else if (sethostname(s, strlen(s))) { | 61 | } else if (sethostname(s, strlen(s))) { |
62 | // if (errno == EPERM) | 62 | // if (errno == EPERM) |
63 | // bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); | 63 | // bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
64 | bb_perror_msg_and_die("sethostname"); | 64 | bb_simple_perror_msg_and_die("sethostname"); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
diff --git a/networking/httpd.c b/networking/httpd.c index 3f1e02ec8..1757e09c9 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1025,7 +1025,7 @@ static void log_and_exit(void) | |||
1025 | */ | 1025 | */ |
1026 | 1026 | ||
1027 | if (verbose > 2) | 1027 | if (verbose > 2) |
1028 | bb_error_msg("closed"); | 1028 | bb_simple_error_msg("closed"); |
1029 | _exit(xfunc_error_retval); | 1029 | _exit(xfunc_error_retval); |
1030 | } | 1030 | } |
1031 | 1031 | ||
@@ -1220,7 +1220,7 @@ static void send_headers(unsigned responseNum) | |||
1220 | } | 1220 | } |
1221 | if (full_write(STDOUT_FILENO, iobuf, len) != len) { | 1221 | if (full_write(STDOUT_FILENO, iobuf, len) != len) { |
1222 | if (verbose > 1) | 1222 | if (verbose > 1) |
1223 | bb_perror_msg("error"); | 1223 | bb_simple_perror_msg("error"); |
1224 | log_and_exit(); | 1224 | log_and_exit(); |
1225 | } | 1225 | } |
1226 | } | 1226 | } |
@@ -1726,8 +1726,10 @@ static NOINLINE void send_file_and_exit(const char *url, int what) | |||
1726 | ".jpg.jpeg\0" "image/jpeg\0" | 1726 | ".jpg.jpeg\0" "image/jpeg\0" |
1727 | ".gif\0" "image/gif\0" | 1727 | ".gif\0" "image/gif\0" |
1728 | ".png\0" "image/png\0" | 1728 | ".png\0" "image/png\0" |
1729 | ".svg\0" "image/svg+xml\0" | ||
1729 | /* .css line must be after .c line */ | 1730 | /* .css line must be after .c line */ |
1730 | ".css\0" "text/css\0" | 1731 | ".css\0" "text/css\0" |
1732 | ".js\0" "application/javascript\0" | ||
1731 | ".wav\0" "audio/wav\0" | 1733 | ".wav\0" "audio/wav\0" |
1732 | ".avi\0" "video/x-msvideo\0" | 1734 | ".avi\0" "video/x-msvideo\0" |
1733 | ".qt.mov\0" "video/quicktime\0" | 1735 | ".qt.mov\0" "video/quicktime\0" |
@@ -1836,7 +1838,7 @@ static NOINLINE void send_file_and_exit(const char *url, int what) | |||
1836 | if (count < 0) { | 1838 | if (count < 0) { |
1837 | IF_FEATURE_USE_SENDFILE(fin:) | 1839 | IF_FEATURE_USE_SENDFILE(fin:) |
1838 | if (verbose > 1) | 1840 | if (verbose > 1) |
1839 | bb_perror_msg("error"); | 1841 | bb_simple_perror_msg("error"); |
1840 | } | 1842 | } |
1841 | log_and_exit(); | 1843 | log_and_exit(); |
1842 | } | 1844 | } |
@@ -2147,7 +2149,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) | |||
2147 | if (rmt_ip_str) | 2149 | if (rmt_ip_str) |
2148 | applet_name = rmt_ip_str; | 2150 | applet_name = rmt_ip_str; |
2149 | if (verbose > 2) | 2151 | if (verbose > 2) |
2150 | bb_error_msg("connected"); | 2152 | bb_simple_error_msg("connected"); |
2151 | } | 2153 | } |
2152 | if_ip_denied_send_HTTP_FORBIDDEN_and_exit(remote_ip); | 2154 | if_ip_denied_send_HTTP_FORBIDDEN_and_exit(remote_ip); |
2153 | 2155 | ||
@@ -2744,7 +2746,7 @@ int httpd_main(int argc UNUSED_PARAM, char **argv) | |||
2744 | if (opt & OPT_SETUID) { | 2746 | if (opt & OPT_SETUID) { |
2745 | if (ugid.gid != (gid_t)-1) { | 2747 | if (ugid.gid != (gid_t)-1) { |
2746 | if (setgroups(1, &ugid.gid) == -1) | 2748 | if (setgroups(1, &ugid.gid) == -1) |
2747 | bb_perror_msg_and_die("setgroups"); | 2749 | bb_simple_perror_msg_and_die("setgroups"); |
2748 | xsetgid(ugid.gid); | 2750 | xsetgid(ugid.gid); |
2749 | } | 2751 | } |
2750 | xsetuid(ugid.uid); | 2752 | xsetuid(ugid.uid); |
diff --git a/networking/ifconfig.c b/networking/ifconfig.c index 5c47abc16..b566d91a9 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c | |||
@@ -361,7 +361,7 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv) | |||
361 | #if ENABLE_FEATURE_IFCONFIG_STATUS | 361 | #if ENABLE_FEATURE_IFCONFIG_STATUS |
362 | return display_interfaces(argv[0] ? argv[0] : show_all_param); | 362 | return display_interfaces(argv[0] ? argv[0] : show_all_param); |
363 | #else | 363 | #else |
364 | bb_error_msg_and_die("no support for status display"); | 364 | bb_simple_error_msg_and_die("no support for status display"); |
365 | #endif | 365 | #endif |
366 | } | 366 | } |
367 | 367 | ||
diff --git a/networking/ifplugd.c b/networking/ifplugd.c index 1426709cb..fa18edd57 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c | |||
@@ -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_info_msg("upping interface"); | 368 | bb_simple_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(); |
@@ -461,7 +461,7 @@ static smallint detect_link(void) | |||
461 | else if (option_mask32 & FLAG_IGNORE_FAIL_POSITIVE) | 461 | else if (option_mask32 & FLAG_IGNORE_FAIL_POSITIVE) |
462 | status = IFSTATUS_UP; | 462 | status = IFSTATUS_UP; |
463 | else if (G.api_mode[0] == 'a') | 463 | else if (G.api_mode[0] == 'a') |
464 | bb_error_msg("can't detect link status"); | 464 | bb_simple_error_msg("can't detect link status"); |
465 | } | 465 | } |
466 | 466 | ||
467 | if (status != G.iface_last_status) { | 467 | if (status != G.iface_last_status) { |
@@ -493,14 +493,14 @@ static NOINLINE int check_existence_through_netlink(void) | |||
493 | goto ret; | 493 | goto ret; |
494 | if (errno == EINTR) | 494 | if (errno == EINTR) |
495 | continue; | 495 | continue; |
496 | bb_perror_msg("netlink: recv"); | 496 | bb_simple_perror_msg("netlink: recv"); |
497 | return -1; | 497 | return -1; |
498 | } | 498 | } |
499 | 499 | ||
500 | mhdr = (struct nlmsghdr*)replybuf; | 500 | mhdr = (struct nlmsghdr*)replybuf; |
501 | while (bytes > 0) { | 501 | while (bytes > 0) { |
502 | if (!NLMSG_OK(mhdr, bytes)) { | 502 | if (!NLMSG_OK(mhdr, bytes)) { |
503 | bb_error_msg("netlink packet too small or truncated"); | 503 | bb_simple_error_msg("netlink packet too small or truncated"); |
504 | return -1; | 504 | return -1; |
505 | } | 505 | } |
506 | 506 | ||
@@ -509,7 +509,7 @@ static NOINLINE int check_existence_through_netlink(void) | |||
509 | int attr_len; | 509 | int attr_len; |
510 | 510 | ||
511 | if (mhdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifinfomsg))) { | 511 | if (mhdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifinfomsg))) { |
512 | bb_error_msg("netlink packet too small or truncated"); | 512 | bb_simple_error_msg("netlink packet too small or truncated"); |
513 | return -1; | 513 | return -1; |
514 | } | 514 | } |
515 | 515 | ||
@@ -591,7 +591,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
591 | } | 591 | } |
592 | 592 | ||
593 | if (pid_from_pidfile > 0 && kill(pid_from_pidfile, 0) == 0) | 593 | if (pid_from_pidfile > 0 && kill(pid_from_pidfile, 0) == 0) |
594 | bb_error_msg_and_die("daemon already running"); | 594 | bb_simple_error_msg_and_die("daemon already running"); |
595 | #endif | 595 | #endif |
596 | 596 | ||
597 | api_mode_found = strchr(api_modes, G.api_mode[0]); | 597 | api_mode_found = strchr(api_modes, G.api_mode[0]); |
@@ -604,15 +604,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
604 | 604 | ||
605 | xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), ioctl_fd); | 605 | xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), ioctl_fd); |
606 | if (opts & FLAG_MONITOR) { | 606 | if (opts & FLAG_MONITOR) { |
607 | struct sockaddr_nl addr; | 607 | int fd = create_and_bind_to_netlink(NETLINK_ROUTE, RTMGRP_LINK, 0); |
608 | int fd = xsocket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); | ||
609 | |||
610 | memset(&addr, 0, sizeof(addr)); | ||
611 | addr.nl_family = AF_NETLINK; | ||
612 | addr.nl_groups = RTMGRP_LINK; | ||
613 | addr.nl_pid = getpid(); | ||
614 | |||
615 | xbind(fd, (struct sockaddr*)&addr, sizeof(addr)); | ||
616 | xmove_fd(fd, netlink_fd); | 608 | xmove_fd(fd, netlink_fd); |
617 | } | 609 | } |
618 | 610 | ||
@@ -698,7 +690,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
698 | ) { | 690 | ) { |
699 | if (errno == EINTR) | 691 | if (errno == EINTR) |
700 | continue; | 692 | continue; |
701 | bb_perror_msg("poll"); | 693 | bb_simple_perror_msg("poll"); |
702 | goto exiting; | 694 | goto exiting; |
703 | } | 695 | } |
704 | 696 | ||
@@ -771,5 +763,5 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) | |||
771 | 763 | ||
772 | exiting: | 764 | exiting: |
773 | remove_pidfile(pidfile_name); | 765 | remove_pidfile(pidfile_name); |
774 | bb_error_msg_and_die("exiting"); | 766 | bb_simple_error_msg_and_die("exiting"); |
775 | } | 767 | } |
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 5327b0979..60ceb5a1f 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -665,7 +665,7 @@ static int FAST_FUNC dhcp_up(struct interface_defn_t *ifd, execfn *exec) | |||
665 | if (executable_exists(ext_dhcp_clients[i].name)) | 665 | if (executable_exists(ext_dhcp_clients[i].name)) |
666 | return execute(ext_dhcp_clients[i].startcmd, ifd, exec); | 666 | return execute(ext_dhcp_clients[i].startcmd, ifd, exec); |
667 | } | 667 | } |
668 | bb_error_msg("no dhcp clients found"); | 668 | bb_simple_error_msg("no dhcp clients found"); |
669 | return 0; | 669 | return 0; |
670 | } | 670 | } |
671 | # elif ENABLE_UDHCPC | 671 | # elif ENABLE_UDHCPC |
@@ -707,7 +707,7 @@ static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec) | |||
707 | } | 707 | } |
708 | 708 | ||
709 | if (!result) | 709 | if (!result) |
710 | bb_error_msg("warning: no dhcp clients found and stopped"); | 710 | bb_simple_error_msg("warning: no dhcp clients found and stopped"); |
711 | 711 | ||
712 | /* Sleep a bit, otherwise static_down tries to bring down interface too soon, | 712 | /* Sleep a bit, otherwise static_down tries to bring down interface too soon, |
713 | and it may come back up because udhcpc is still shutting down */ | 713 | and it may come back up because udhcpc is still shutting down */ |
diff --git a/networking/inetd.c b/networking/inetd.c index da6551174..3cd2b11f0 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -504,7 +504,7 @@ static void register_rpc(servtab_t *sep) | |||
504 | 504 | ||
505 | if (bb_getsockname(sep->se_fd, (struct sockaddr *) &ir_sin, sizeof(ir_sin)) < 0) { | 505 | if (bb_getsockname(sep->se_fd, (struct sockaddr *) &ir_sin, sizeof(ir_sin)) < 0) { |
506 | //TODO: verify that such failure is even possible in Linux kernel | 506 | //TODO: verify that such failure is even possible in Linux kernel |
507 | bb_perror_msg("getsockname"); | 507 | bb_simple_perror_msg("getsockname"); |
508 | return; | 508 | return; |
509 | } | 509 | } |
510 | 510 | ||
@@ -544,7 +544,7 @@ static void bump_nofile(void) | |||
544 | } | 544 | } |
545 | 545 | ||
546 | if (setrlimit(RLIMIT_NOFILE, &rl) < 0) { | 546 | if (setrlimit(RLIMIT_NOFILE, &rl) < 0) { |
547 | bb_perror_msg("setrlimit"); | 547 | bb_simple_perror_msg("setrlimit"); |
548 | return; | 548 | return; |
549 | } | 549 | } |
550 | 550 | ||
@@ -599,7 +599,7 @@ static void prepare_socket_fd(servtab_t *sep) | |||
599 | 599 | ||
600 | fd = socket(sep->se_family, sep->se_socktype, 0); | 600 | fd = socket(sep->se_family, sep->se_socktype, 0); |
601 | if (fd < 0) { | 601 | if (fd < 0) { |
602 | bb_perror_msg("socket"); | 602 | bb_simple_perror_msg("socket"); |
603 | return; | 603 | return; |
604 | } | 604 | } |
605 | setsockopt_reuseaddr(fd); | 605 | setsockopt_reuseaddr(fd); |
@@ -815,7 +815,7 @@ static NOINLINE servtab_t *parse_one_line(void) | |||
815 | n = bb_strtou(p, &p, 10); | 815 | n = bb_strtou(p, &p, 10); |
816 | if (n > INT_MAX) { | 816 | if (n > INT_MAX) { |
817 | bad_ver_spec: | 817 | bad_ver_spec: |
818 | bb_error_msg("bad rpc version"); | 818 | bb_simple_error_msg("bad rpc version"); |
819 | goto parse_err; | 819 | goto parse_err; |
820 | } | 820 | } |
821 | sep->se_rpcver_lo = sep->se_rpcver_hi = n; | 821 | sep->se_rpcver_lo = sep->se_rpcver_hi = n; |
@@ -829,7 +829,7 @@ static NOINLINE servtab_t *parse_one_line(void) | |||
829 | if (*p != '\0') | 829 | if (*p != '\0') |
830 | goto bad_ver_spec; | 830 | goto bad_ver_spec; |
831 | #else | 831 | #else |
832 | bb_error_msg("no support for rpc services"); | 832 | bb_simple_error_msg("no support for rpc services"); |
833 | goto parse_err; | 833 | goto parse_err; |
834 | #endif | 834 | #endif |
835 | } | 835 | } |
@@ -1235,7 +1235,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1235 | if (argv[0]) | 1235 | if (argv[0]) |
1236 | config_filename = argv[0]; | 1236 | config_filename = argv[0]; |
1237 | if (config_filename == NULL) | 1237 | if (config_filename == NULL) |
1238 | bb_error_msg_and_die("non-root must specify config file"); | 1238 | bb_simple_error_msg_and_die("non-root must specify config file"); |
1239 | if (!(opt & 2)) | 1239 | if (!(opt & 2)) |
1240 | bb_daemonize_or_rexec(0, argv - optind); | 1240 | bb_daemonize_or_rexec(0, argv - optind); |
1241 | else | 1241 | else |
@@ -1304,7 +1304,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1304 | ready_fd_cnt = select(maxsock + 1, &readable, NULL, NULL, NULL); | 1304 | ready_fd_cnt = select(maxsock + 1, &readable, NULL, NULL, NULL); |
1305 | if (ready_fd_cnt < 0) { | 1305 | if (ready_fd_cnt < 0) { |
1306 | if (errno != EINTR) { | 1306 | if (errno != EINTR) { |
1307 | bb_perror_msg("select"); | 1307 | bb_simple_perror_msg("select"); |
1308 | sleep(1); | 1308 | sleep(1); |
1309 | } | 1309 | } |
1310 | continue; | 1310 | continue; |
@@ -1405,7 +1405,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1405 | pid = vfork(); | 1405 | pid = vfork(); |
1406 | 1406 | ||
1407 | if (pid < 0) { /* fork error */ | 1407 | if (pid < 0) { /* fork error */ |
1408 | bb_perror_msg("vfork"+1); | 1408 | bb_simple_perror_msg("vfork"+1); |
1409 | sleep(1); | 1409 | sleep(1); |
1410 | restore_sigmask(&omask); | 1410 | restore_sigmask(&omask); |
1411 | maybe_close(new_udp_fd); | 1411 | maybe_close(new_udp_fd); |
@@ -1488,7 +1488,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1488 | } | 1488 | } |
1489 | if (real_uid != 0 && real_uid != pwd->pw_uid) { | 1489 | if (real_uid != 0 && real_uid != pwd->pw_uid) { |
1490 | /* a user running private inetd */ | 1490 | /* a user running private inetd */ |
1491 | bb_error_msg("non-root must run services as himself"); | 1491 | bb_simple_error_msg("non-root must run services as himself"); |
1492 | goto do_exit1; | 1492 | goto do_exit1; |
1493 | } | 1493 | } |
1494 | if (pwd->pw_uid != real_uid) { | 1494 | if (pwd->pw_uid != real_uid) { |
@@ -1502,7 +1502,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) | |||
1502 | } | 1502 | } |
1503 | if (rlim_ofile.rlim_cur != rlim_ofile_cur) | 1503 | if (rlim_ofile.rlim_cur != rlim_ofile_cur) |
1504 | if (setrlimit(RLIMIT_NOFILE, &rlim_ofile) < 0) | 1504 | if (setrlimit(RLIMIT_NOFILE, &rlim_ofile) < 0) |
1505 | bb_perror_msg("setrlimit"); | 1505 | bb_simple_perror_msg("setrlimit"); |
1506 | 1506 | ||
1507 | /* closelog(); - WRONG. we are after vfork, | 1507 | /* closelog(); - WRONG. we are after vfork, |
1508 | * this may confuse syslog() internal state. | 1508 | * this may confuse syslog() internal state. |
diff --git a/networking/ipcalc.c b/networking/ipcalc.c index 67f768836..09b146872 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c | |||
@@ -183,7 +183,7 @@ int ipcalc_main(int argc UNUSED_PARAM, char **argv) | |||
183 | 183 | ||
184 | if (argv[1]) { | 184 | if (argv[1]) { |
185 | if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) { | 185 | if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) { |
186 | bb_error_msg_and_die("use prefix or netmask, not both"); | 186 | bb_simple_error_msg_and_die("use prefix or netmask, not both"); |
187 | } | 187 | } |
188 | if (inet_aton(argv[1], &s_netmask) == 0) { | 188 | if (inet_aton(argv[1], &s_netmask) == 0) { |
189 | bb_error_msg_and_die("bad netmask: %s", argv[1]); | 189 | bb_error_msg_and_die("bad netmask: %s", argv[1]); |
diff --git a/networking/isrv.c b/networking/isrv.c index 97f5c6d4e..0e3f10f9a 100644 --- a/networking/isrv.c +++ b/networking/isrv.c | |||
@@ -185,7 +185,7 @@ static void handle_accept(isrv_state_t *state, int fd) | |||
185 | /* Most probably someone gave us wrong fd type | 185 | /* Most probably someone gave us wrong fd type |
186 | * (for example, non-socket). Don't want | 186 | * (for example, non-socket). Don't want |
187 | * to loop forever. */ | 187 | * to loop forever. */ |
188 | bb_perror_msg_and_die("accept"); | 188 | bb_simple_perror_msg_and_die("accept"); |
189 | } | 189 | } |
190 | 190 | ||
191 | DPRINTF("new_peer(%d)", newfd); | 191 | DPRINTF("new_peer(%d)", newfd); |
@@ -311,7 +311,7 @@ void isrv_run( | |||
311 | 311 | ||
312 | if (n < 0) { | 312 | if (n < 0) { |
313 | if (errno != EINTR) | 313 | if (errno != EINTR) |
314 | bb_perror_msg("select"); | 314 | bb_simple_perror_msg("select"); |
315 | continue; | 315 | continue; |
316 | } | 316 | } |
317 | 317 | ||
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 7b7e0154b..86cf3beea 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c | |||
@@ -119,7 +119,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) | |||
119 | //memset(tb, 0, sizeof(tb)); - parse_rtattr does this | 119 | //memset(tb, 0, sizeof(tb)); - parse_rtattr does this |
120 | parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); | 120 | parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); |
121 | if (tb[IFLA_IFNAME] == NULL) { | 121 | if (tb[IFLA_IFNAME] == NULL) { |
122 | bb_error_msg("nil ifname"); | 122 | bb_simple_error_msg("nil ifname"); |
123 | return -1; | 123 | return -1; |
124 | } | 124 | } |
125 | if (G_filter.label | 125 | if (G_filter.label |
@@ -205,7 +205,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) | |||
205 | static int flush_update(void) | 205 | static int flush_update(void) |
206 | { | 206 | { |
207 | if (rtnl_send_check(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) { |
208 | bb_perror_msg("can't send flush request"); | 208 | bb_simple_perror_msg("can't send flush request"); |
209 | return -1; | 209 | return -1; |
210 | } | 210 | } |
211 | G_filter.flushp = 0; | 211 | G_filter.flushp = 0; |
@@ -439,7 +439,7 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) | |||
439 | bb_error_msg_and_die(bb_msg_requires_arg, "flush"); | 439 | bb_error_msg_and_die(bb_msg_requires_arg, "flush"); |
440 | } | 440 | } |
441 | if (G_filter.family == AF_PACKET) { | 441 | if (G_filter.family == AF_PACKET) { |
442 | bb_error_msg_and_die("can't flush link addresses"); | 442 | bb_simple_error_msg_and_die("can't flush link addresses"); |
443 | } | 443 | } |
444 | } | 444 | } |
445 | 445 | ||
@@ -700,7 +700,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) | |||
700 | 700 | ||
701 | if (!d) { | 701 | if (!d) { |
702 | /* There was no "dev IFACE", but we need that */ | 702 | /* There was no "dev IFACE", but we need that */ |
703 | bb_error_msg_and_die("need \"dev IFACE\""); | 703 | bb_simple_error_msg_and_die("need \"dev IFACE\""); |
704 | } | 704 | } |
705 | if (l && !is_prefixed_with(l, d)) { | 705 | if (l && !is_prefixed_with(l, d)) { |
706 | bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l); | 706 | bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l); |
@@ -717,7 +717,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) | |||
717 | inet_prefix brd; | 717 | inet_prefix brd; |
718 | int i; | 718 | int i; |
719 | if (req.ifa.ifa_family != AF_INET) { | 719 | if (req.ifa.ifa_family != AF_INET) { |
720 | bb_error_msg_and_die("broadcast can be set only for IPv4 addresses"); | 720 | bb_simple_error_msg_and_die("broadcast can be set only for IPv4 addresses"); |
721 | } | 721 | } |
722 | brd = peer; | 722 | brd = peer; |
723 | if (brd.bitlen <= 30) { | 723 | if (brd.bitlen <= 30) { |
diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c index 984dd4bdd..b9b4f4b31 100644 --- a/networking/libiproute/ipneigh.c +++ b/networking/libiproute/ipneigh.c | |||
@@ -49,7 +49,7 @@ typedef struct filter_t filter_t; | |||
49 | static int flush_update(void) | 49 | static int flush_update(void) |
50 | { | 50 | { |
51 | if (rtnl_send_check(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) { |
52 | bb_perror_msg("can't send flush request"); | 52 | bb_simple_perror_msg("can't send flush request"); |
53 | return -1; | 53 | return -1; |
54 | } | 54 | } |
55 | G_filter.flushp = 0; | 55 | G_filter.flushp = 0; |
@@ -305,7 +305,7 @@ static int FAST_FUNC ipneigh_list_or_flush(char **argv, int flush) | |||
305 | xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETNEIGH); | 305 | xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETNEIGH); |
306 | G_filter.flushed = 0; | 306 | G_filter.flushed = 0; |
307 | if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { | 307 | if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { |
308 | bb_perror_msg_and_die("flush terminated"); | 308 | bb_simple_perror_msg_and_die("flush terminated"); |
309 | } | 309 | } |
310 | if (G_filter.flushed == 0) { | 310 | if (G_filter.flushed == 0) { |
311 | if (round == 0) | 311 | if (round == 0) |
@@ -325,11 +325,11 @@ static int FAST_FUNC ipneigh_list_or_flush(char **argv, int flush) | |||
325 | ndm.ndm_family = G_filter.family; | 325 | ndm.ndm_family = G_filter.family; |
326 | 326 | ||
327 | if (rtnl_dump_request(&rth, RTM_GETNEIGH, &ndm, sizeof(struct ndmsg)) < 0) { | 327 | if (rtnl_dump_request(&rth, RTM_GETNEIGH, &ndm, sizeof(struct ndmsg)) < 0) { |
328 | bb_perror_msg_and_die("can't send dump request"); | 328 | bb_simple_perror_msg_and_die("can't send dump request"); |
329 | } | 329 | } |
330 | 330 | ||
331 | if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { | 331 | if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { |
332 | bb_error_msg_and_die("dump terminated"); | 332 | bb_simple_error_msg_and_die("dump terminated"); |
333 | } | 333 | } |
334 | 334 | ||
335 | return 0; | 335 | return 0; |
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index b11078ed5..5a972f8b2 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c | |||
@@ -57,7 +57,7 @@ typedef struct filter_t filter_t; | |||
57 | static int flush_update(void) | 57 | static int flush_update(void) |
58 | { | 58 | { |
59 | if (rtnl_send_check(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) { |
60 | bb_perror_msg("can't send flush request"); | 60 | bb_simple_perror_msg("can't send flush request"); |
61 | return -1; | 61 | return -1; |
62 | } | 62 | } |
63 | G_filter.flushp = 0; | 63 | G_filter.flushp = 0; |
@@ -756,7 +756,7 @@ static void iproute_flush_cache(void) | |||
756 | } | 756 | } |
757 | 757 | ||
758 | if (write(flush_fd, "-1", 2) < 2) { | 758 | if (write(flush_fd, "-1", 2) < 2) { |
759 | bb_perror_msg("can't flush routing cache"); | 759 | bb_simple_perror_msg("can't flush routing cache"); |
760 | return; | 760 | return; |
761 | } | 761 | } |
762 | close(flush_fd); | 762 | close(flush_fd); |
@@ -948,7 +948,7 @@ static int iproute_list_or_flush(char **argv, int flush) | |||
948 | if (G_filter.tb != -1) { | 948 | if (G_filter.tb != -1) { |
949 | xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); | 949 | xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); |
950 | } else if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { | 950 | } else if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { |
951 | bb_perror_msg_and_die("can't send dump request"); | 951 | bb_simple_perror_msg_and_die("can't send dump request"); |
952 | } | 952 | } |
953 | xrtnl_dump_filter(&rth, print_route, NULL); | 953 | xrtnl_dump_filter(&rth, print_route, NULL); |
954 | 954 | ||
@@ -1041,7 +1041,7 @@ static int iproute_get(char **argv) | |||
1041 | } | 1041 | } |
1042 | 1042 | ||
1043 | if (req.r.rtm_dst_len == 0) { | 1043 | if (req.r.rtm_dst_len == 0) { |
1044 | bb_error_msg_and_die("need at least destination address"); | 1044 | bb_simple_error_msg_and_die("need at least destination address"); |
1045 | } | 1045 | } |
1046 | 1046 | ||
1047 | xrtnl_open(&rth); | 1047 | xrtnl_open(&rth); |
@@ -1077,7 +1077,7 @@ static int iproute_get(char **argv) | |||
1077 | print_route(NULL, &req.n, NULL); | 1077 | print_route(NULL, &req.n, NULL); |
1078 | 1078 | ||
1079 | if (req.n.nlmsg_type != RTM_NEWROUTE) { | 1079 | if (req.n.nlmsg_type != RTM_NEWROUTE) { |
1080 | bb_error_msg_and_die("not a route?"); | 1080 | bb_simple_error_msg_and_die("not a route?"); |
1081 | } | 1081 | } |
1082 | len -= NLMSG_LENGTH(sizeof(*r)); | 1082 | len -= NLMSG_LENGTH(sizeof(*r)); |
1083 | if (len < 0) { | 1083 | if (len < 0) { |
@@ -1091,7 +1091,7 @@ static int iproute_get(char **argv) | |||
1091 | tb[RTA_PREFSRC]->rta_type = RTA_SRC; | 1091 | tb[RTA_PREFSRC]->rta_type = RTA_SRC; |
1092 | r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]); | 1092 | r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]); |
1093 | } else if (!tb[RTA_SRC]) { | 1093 | } else if (!tb[RTA_SRC]) { |
1094 | bb_error_msg_and_die("can't connect the route"); | 1094 | bb_simple_error_msg_and_die("can't connect the route"); |
1095 | } | 1095 | } |
1096 | if (!odev && tb[RTA_OIF]) { | 1096 | if (!odev && tb[RTA_OIF]) { |
1097 | tb[RTA_OIF]->rta_type = 0; | 1097 | tb[RTA_OIF]->rta_type = 0; |
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index 4002feb78..c9fa632f3 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c | |||
@@ -338,7 +338,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) | |||
338 | 338 | ||
339 | if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) { | 339 | if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) { |
340 | if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) { | 340 | if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) { |
341 | bb_error_msg_and_die("keys are not allowed with ipip and sit"); | 341 | bb_simple_error_msg_and_die("keys are not allowed with ipip and sit"); |
342 | } | 342 | } |
343 | } | 343 | } |
344 | 344 | ||
@@ -355,7 +355,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) | |||
355 | p->o_flags |= GRE_KEY; | 355 | p->o_flags |= GRE_KEY; |
356 | } | 356 | } |
357 | if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) { | 357 | if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) { |
358 | bb_error_msg_and_die("broadcast tunnel requires a source address"); | 358 | bb_simple_error_msg_and_die("broadcast tunnel requires a source address"); |
359 | } | 359 | } |
360 | } | 360 | } |
361 | 361 | ||
@@ -367,7 +367,7 @@ static int do_add(int cmd, char **argv) | |||
367 | parse_args(argv, cmd, &p); | 367 | parse_args(argv, cmd, &p); |
368 | 368 | ||
369 | if (p.iph.ttl && p.iph.frag_off == 0) { | 369 | if (p.iph.ttl && p.iph.frag_off == 0) { |
370 | bb_error_msg_and_die("ttl != 0 and noptmudisc are incompatible"); | 370 | bb_simple_error_msg_and_die("ttl != 0 and noptmudisc are incompatible"); |
371 | } | 371 | } |
372 | 372 | ||
373 | switch (p.iph.protocol) { | 373 | switch (p.iph.protocol) { |
@@ -378,7 +378,7 @@ static int do_add(int cmd, char **argv) | |||
378 | case IPPROTO_IPV6: | 378 | case IPPROTO_IPV6: |
379 | return do_add_ioctl(cmd, "sit0", &p); | 379 | return do_add_ioctl(cmd, "sit0", &p); |
380 | default: | 380 | default: |
381 | bb_error_msg_and_die("can't determine tunnel mode (ipip, gre or sit)"); | 381 | bb_simple_error_msg_and_die("can't determine tunnel mode (ipip, gre or sit)"); |
382 | } | 382 | } |
383 | } | 383 | } |
384 | 384 | ||
@@ -485,7 +485,7 @@ static void do_tunnels_list(struct ip_tunnel_parm *p) | |||
485 | if (ptr == NULL || | 485 | if (ptr == NULL || |
486 | (*ptr++ = 0, sscanf(buf, "%s", name) != 1) | 486 | (*ptr++ = 0, sscanf(buf, "%s", name) != 1) |
487 | ) { | 487 | ) { |
488 | bb_error_msg("wrong format of /proc/net/dev"); | 488 | bb_simple_error_msg("wrong format of /proc/net/dev"); |
489 | return; | 489 | return; |
490 | } | 490 | } |
491 | if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu", | 491 | if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu", |
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index b0d4166ac..7e3473a1c 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c | |||
@@ -79,7 +79,7 @@ int FAST_FUNC rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len) | |||
79 | if (h->nlmsg_type == NLMSG_ERROR) { | 79 | if (h->nlmsg_type == NLMSG_ERROR) { |
80 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); | 80 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); |
81 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) | 81 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) |
82 | bb_error_msg("ERROR truncated"); | 82 | bb_simple_error_msg("ERROR truncated"); |
83 | else | 83 | else |
84 | errno = -err->error; | 84 | errno = -err->error; |
85 | return -1; | 85 | return -1; |
@@ -149,11 +149,11 @@ static int rtnl_dump_filter(struct rtnl_handle *rth, | |||
149 | if (status < 0) { | 149 | if (status < 0) { |
150 | if (errno == EINTR) | 150 | if (errno == EINTR) |
151 | continue; | 151 | continue; |
152 | bb_perror_msg("OVERRUN"); | 152 | bb_simple_perror_msg("OVERRUN"); |
153 | continue; | 153 | continue; |
154 | } | 154 | } |
155 | if (status == 0) { | 155 | if (status == 0) { |
156 | bb_error_msg("EOF on netlink"); | 156 | bb_simple_error_msg("EOF on netlink"); |
157 | goto ret; | 157 | goto ret; |
158 | } | 158 | } |
159 | if (msg.msg_namelen != sizeof(nladdr)) { | 159 | if (msg.msg_namelen != sizeof(nladdr)) { |
@@ -184,10 +184,10 @@ static int rtnl_dump_filter(struct rtnl_handle *rth, | |||
184 | if (h->nlmsg_type == NLMSG_ERROR) { | 184 | if (h->nlmsg_type == NLMSG_ERROR) { |
185 | struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h); | 185 | struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h); |
186 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) { | 186 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) { |
187 | bb_error_msg("ERROR truncated"); | 187 | bb_simple_error_msg("ERROR truncated"); |
188 | } else { | 188 | } else { |
189 | errno = -l_err->error; | 189 | errno = -l_err->error; |
190 | bb_perror_msg("RTNETLINK answers"); | 190 | bb_simple_perror_msg("RTNETLINK answers"); |
191 | } | 191 | } |
192 | goto ret; | 192 | goto ret; |
193 | } | 193 | } |
@@ -201,7 +201,7 @@ static int rtnl_dump_filter(struct rtnl_handle *rth, | |||
201 | h = NLMSG_NEXT(h, status); | 201 | h = NLMSG_NEXT(h, status); |
202 | } | 202 | } |
203 | if (msg.msg_flags & MSG_TRUNC) { | 203 | if (msg.msg_flags & MSG_TRUNC) { |
204 | bb_error_msg("message truncated"); | 204 | bb_simple_error_msg("message truncated"); |
205 | continue; | 205 | continue; |
206 | } | 206 | } |
207 | if (status) { | 207 | if (status) { |
@@ -221,7 +221,7 @@ int FAST_FUNC xrtnl_dump_filter(struct rtnl_handle *rth, | |||
221 | { | 221 | { |
222 | int ret = rtnl_dump_filter(rth, filter, arg1/*, NULL, NULL*/); | 222 | int ret = rtnl_dump_filter(rth, filter, arg1/*, NULL, NULL*/); |
223 | if (ret < 0) | 223 | if (ret < 0) |
224 | bb_error_msg_and_die("dump terminated"); | 224 | bb_simple_error_msg_and_die("dump terminated"); |
225 | return ret; | 225 | return ret; |
226 | } | 226 | } |
227 | 227 | ||
@@ -266,7 +266,7 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, | |||
266 | status = sendmsg(rtnl->fd, &msg, 0); | 266 | status = sendmsg(rtnl->fd, &msg, 0); |
267 | 267 | ||
268 | if (status < 0) { | 268 | if (status < 0) { |
269 | bb_perror_msg("can't talk to rtnetlink"); | 269 | bb_simple_perror_msg("can't talk to rtnetlink"); |
270 | goto ret; | 270 | goto ret; |
271 | } | 271 | } |
272 | 272 | ||
@@ -280,11 +280,11 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, | |||
280 | if (errno == EINTR) { | 280 | if (errno == EINTR) { |
281 | continue; | 281 | continue; |
282 | } | 282 | } |
283 | bb_perror_msg("OVERRUN"); | 283 | bb_simple_perror_msg("OVERRUN"); |
284 | continue; | 284 | continue; |
285 | } | 285 | } |
286 | if (status == 0) { | 286 | if (status == 0) { |
287 | bb_error_msg("EOF on netlink"); | 287 | bb_simple_error_msg("EOF on netlink"); |
288 | goto ret; | 288 | goto ret; |
289 | } | 289 | } |
290 | if (msg.msg_namelen != sizeof(nladdr)) { | 290 | if (msg.msg_namelen != sizeof(nladdr)) { |
@@ -297,7 +297,7 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, | |||
297 | 297 | ||
298 | if (l < 0 || len > status) { | 298 | if (l < 0 || len > status) { |
299 | if (msg.msg_flags & MSG_TRUNC) { | 299 | if (msg.msg_flags & MSG_TRUNC) { |
300 | bb_error_msg("truncated message"); | 300 | bb_simple_error_msg("truncated message"); |
301 | goto ret; | 301 | goto ret; |
302 | } | 302 | } |
303 | bb_error_msg_and_die("malformed message: len=%d!", len); | 303 | bb_error_msg_and_die("malformed message: len=%d!", len); |
@@ -320,7 +320,7 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, | |||
320 | if (h->nlmsg_type == NLMSG_ERROR) { | 320 | if (h->nlmsg_type == NLMSG_ERROR) { |
321 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); | 321 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); |
322 | if (l < (int)sizeof(struct nlmsgerr)) { | 322 | if (l < (int)sizeof(struct nlmsgerr)) { |
323 | bb_error_msg("ERROR truncated"); | 323 | bb_simple_error_msg("ERROR truncated"); |
324 | } else { | 324 | } else { |
325 | errno = - err->error; | 325 | errno = - err->error; |
326 | if (errno == 0) { | 326 | if (errno == 0) { |
@@ -329,7 +329,7 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, | |||
329 | } | 329 | } |
330 | goto ret_0; | 330 | goto ret_0; |
331 | } | 331 | } |
332 | bb_perror_msg("RTNETLINK answers"); | 332 | bb_simple_perror_msg("RTNETLINK answers"); |
333 | } | 333 | } |
334 | goto ret; | 334 | goto ret; |
335 | } | 335 | } |
@@ -338,13 +338,13 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, | |||
338 | goto ret_0; | 338 | goto ret_0; |
339 | } | 339 | } |
340 | 340 | ||
341 | bb_error_msg("unexpected reply!"); | 341 | bb_simple_error_msg("unexpected reply!"); |
342 | 342 | ||
343 | status -= NLMSG_ALIGN(len); | 343 | status -= NLMSG_ALIGN(len); |
344 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); | 344 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); |
345 | } | 345 | } |
346 | if (msg.msg_flags & MSG_TRUNC) { | 346 | if (msg.msg_flags & MSG_TRUNC) { |
347 | bb_error_msg("message truncated"); | 347 | bb_simple_error_msg("message truncated"); |
348 | continue; | 348 | continue; |
349 | } | 349 | } |
350 | if (status) { | 350 | if (status) { |
diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c index bf053a54b..4ce230356 100644 --- a/networking/libiproute/utils.c +++ b/networking/libiproute/utils.c | |||
@@ -230,7 +230,7 @@ uint32_t FAST_FUNC get_addr32(char *name) | |||
230 | char** FAST_FUNC next_arg(char **argv) | 230 | char** FAST_FUNC next_arg(char **argv) |
231 | { | 231 | { |
232 | if (!*++argv) | 232 | if (!*++argv) |
233 | bb_error_msg_and_die("command line is not complete, try \"help\""); | 233 | bb_simple_error_msg_and_die("command line is not complete, try \"help\""); |
234 | return argv; | 234 | return argv; |
235 | } | 235 | } |
236 | 236 | ||
diff --git a/networking/nbd-client.c b/networking/nbd-client.c index 0dc8d0c43..3db3b46f9 100644 --- a/networking/nbd-client.c +++ b/networking/nbd-client.c | |||
@@ -179,7 +179,7 @@ int nbdclient_main(int argc, char **argv) | |||
179 | if (memcmp(&nbd_header.magic1, "NBDMAGIC", | 179 | if (memcmp(&nbd_header.magic1, "NBDMAGIC", |
180 | sizeof(nbd_header.magic1)) != 0 | 180 | sizeof(nbd_header.magic1)) != 0 |
181 | ) { | 181 | ) { |
182 | bb_error_msg_and_die("login failed"); | 182 | bb_simple_error_msg_and_die("login failed"); |
183 | } | 183 | } |
184 | if (memcmp(&nbd_header.magic2, | 184 | if (memcmp(&nbd_header.magic2, |
185 | "\x00\x00\x42\x02\x81\x86\x12\x53", | 185 | "\x00\x00\x42\x02\x81\x86\x12\x53", |
@@ -189,7 +189,7 @@ int nbdclient_main(int argc, char **argv) | |||
189 | } else if (memcmp(&nbd_header.magic2, "IHAVEOPT", 8) == 0) { | 189 | } else if (memcmp(&nbd_header.magic2, "IHAVEOPT", 8) == 0) { |
190 | proto_new = 1; | 190 | proto_new = 1; |
191 | } else { | 191 | } else { |
192 | bb_error_msg_and_die("login failed"); | 192 | bb_simple_error_msg_and_die("login failed"); |
193 | } | 193 | } |
194 | 194 | ||
195 | if (!proto_new) { | 195 | if (!proto_new) { |
@@ -240,17 +240,17 @@ int nbdclient_main(int argc, char **argv) | |||
240 | } | 240 | } |
241 | 241 | ||
242 | if (ioctl(nbd, BLKROSET, &ro) < 0) { | 242 | if (ioctl(nbd, BLKROSET, &ro) < 0) { |
243 | bb_perror_msg_and_die("BLKROSET"); | 243 | bb_simple_perror_msg_and_die("BLKROSET"); |
244 | } | 244 | } |
245 | 245 | ||
246 | if (timeout) { | 246 | if (timeout) { |
247 | if (ioctl(nbd, NBD_SET_TIMEOUT, (unsigned long) timeout)) { | 247 | if (ioctl(nbd, NBD_SET_TIMEOUT, (unsigned long) timeout)) { |
248 | bb_perror_msg_and_die("NBD_SET_TIMEOUT"); | 248 | bb_simple_perror_msg_and_die("NBD_SET_TIMEOUT"); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | 251 | ||
252 | if (ioctl(nbd, NBD_SET_SOCK, sock)) { | 252 | if (ioctl(nbd, NBD_SET_SOCK, sock)) { |
253 | bb_perror_msg_and_die("NBD_SET_SOCK"); | 253 | bb_simple_perror_msg_and_die("NBD_SET_SOCK"); |
254 | } | 254 | } |
255 | 255 | ||
256 | //if (swap) mlockall(MCL_CURRENT|MCL_FUTURE); | 256 | //if (swap) mlockall(MCL_CURRENT|MCL_FUTURE); |
diff --git a/networking/nc.c b/networking/nc.c index 3e122b787..3dce6a528 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -113,7 +113,7 @@ | |||
113 | #if ENABLE_NC_EXTRA | 113 | #if ENABLE_NC_EXTRA |
114 | static void timeout(int signum UNUSED_PARAM) | 114 | static void timeout(int signum UNUSED_PARAM) |
115 | { | 115 | { |
116 | bb_error_msg_and_die("timed out"); | 116 | bb_simple_error_msg_and_die("timed out"); |
117 | } | 117 | } |
118 | #endif | 118 | #endif |
119 | 119 | ||
@@ -215,7 +215,7 @@ int nc_main(int argc, char **argv) | |||
215 | IF_NC_EXTRA(accept_again:) | 215 | IF_NC_EXTRA(accept_again:) |
216 | cfd = accept(sfd, NULL, 0); | 216 | cfd = accept(sfd, NULL, 0); |
217 | if (cfd < 0) | 217 | if (cfd < 0) |
218 | bb_perror_msg_and_die("accept"); | 218 | bb_simple_perror_msg_and_die("accept"); |
219 | if (!execparam) | 219 | if (!execparam) |
220 | close(sfd); | 220 | close(sfd); |
221 | } else { | 221 | } else { |
@@ -267,7 +267,7 @@ int nc_main(int argc, char **argv) | |||
267 | testfds = readfds; | 267 | testfds = readfds; |
268 | 268 | ||
269 | if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) | 269 | if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) |
270 | bb_perror_msg_and_die("select"); | 270 | bb_simple_perror_msg_and_die("select"); |
271 | 271 | ||
272 | fd = STDIN_FILENO; | 272 | fd = STDIN_FILENO; |
273 | while (1) { | 273 | while (1) { |
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index 42c84de45..034e03d21 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c | |||
@@ -198,8 +198,8 @@ enum { | |||
198 | #define Debug(...) do { } while (0) | 198 | #define Debug(...) do { } while (0) |
199 | #endif | 199 | #endif |
200 | 200 | ||
201 | #define holler_error(...) do { if (o_verbose) bb_error_msg(__VA_ARGS__); } while (0) | 201 | #define holler_error(msg) do { if (o_verbose) bb_simple_error_msg(msg); } while (0) |
202 | #define holler_perror(...) do { if (o_verbose) bb_perror_msg(__VA_ARGS__); } while (0) | 202 | #define holler_perror(msg) do { if (o_verbose) bb_simple_perror_msg(msg); } while (0) |
203 | 203 | ||
204 | /* catch: no-brainer interrupt handler */ | 204 | /* catch: no-brainer interrupt handler */ |
205 | static void catch(int sig) | 205 | static void catch(int sig) |
@@ -361,10 +361,10 @@ static void dolisten(int is_persistent, char **proggie) | |||
361 | rr = recv_from_to(netfd, NULL, 0, MSG_PEEK, /*was bigbuf_net, BIGSIZ*/ | 361 | rr = recv_from_to(netfd, NULL, 0, MSG_PEEK, /*was bigbuf_net, BIGSIZ*/ |
362 | &remend.u.sa, &ouraddr->u.sa, ouraddr->len); | 362 | &remend.u.sa, &ouraddr->u.sa, ouraddr->len); |
363 | if (rr < 0) | 363 | if (rr < 0) |
364 | bb_perror_msg_and_die("recvfrom"); | 364 | bb_simple_perror_msg_and_die("recvfrom"); |
365 | unarm(); | 365 | unarm(); |
366 | } else | 366 | } else |
367 | bb_error_msg_and_die("timeout"); | 367 | bb_simple_error_msg_and_die("timeout"); |
368 | /* Now we learned *to which IP* peer has connected, and we want to anchor | 368 | /* Now we learned *to which IP* peer has connected, and we want to anchor |
369 | our socket on it, so that our outbound packets will have correct local IP. | 369 | our socket on it, so that our outbound packets will have correct local IP. |
370 | Unfortunately, bind() on already bound socket will fail now (EINVAL): | 370 | Unfortunately, bind() on already bound socket will fail now (EINVAL): |
@@ -382,7 +382,7 @@ create new one, and bind() it. TODO */ | |||
382 | remend.len = LSA_SIZEOF_SA; | 382 | remend.len = LSA_SIZEOF_SA; |
383 | rr = accept(netfd, &remend.u.sa, &remend.len); | 383 | rr = accept(netfd, &remend.u.sa, &remend.len); |
384 | if (rr < 0) | 384 | if (rr < 0) |
385 | bb_perror_msg_and_die("accept"); | 385 | bb_simple_perror_msg_and_die("accept"); |
386 | if (themaddr) { | 386 | if (themaddr) { |
387 | int sv_port, port, r; | 387 | int sv_port, port, r; |
388 | 388 | ||
@@ -409,7 +409,7 @@ create new one, and bind() it. TODO */ | |||
409 | } | 409 | } |
410 | unarm(); | 410 | unarm(); |
411 | } else | 411 | } else |
412 | bb_error_msg_and_die("timeout"); | 412 | bb_simple_error_msg_and_die("timeout"); |
413 | 413 | ||
414 | if (is_persistent && proggie) { | 414 | if (is_persistent && proggie) { |
415 | /* -l -k -e PROG */ | 415 | /* -l -k -e PROG */ |
@@ -494,7 +494,7 @@ static int udptest(void) | |||
494 | 494 | ||
495 | rr = write(netfd, bigbuf_in, 1); | 495 | rr = write(netfd, bigbuf_in, 1); |
496 | if (rr != 1) | 496 | if (rr != 1) |
497 | bb_perror_msg("udptest first write"); | 497 | bb_simple_perror_msg("udptest first write"); |
498 | 498 | ||
499 | if (o_wait) | 499 | if (o_wait) |
500 | sleep(o_wait); // can be interrupted! while (t) nanosleep(&t)? | 500 | sleep(o_wait); // can be interrupted! while (t) nanosleep(&t)? |
@@ -644,7 +644,7 @@ static int readwrite(void) | |||
644 | if (rr <= 0) { | 644 | if (rr <= 0) { |
645 | if (rr < 0 && o_verbose > 1) { | 645 | if (rr < 0 && o_verbose > 1) { |
646 | /* nc 1.10 doesn't do this */ | 646 | /* nc 1.10 doesn't do this */ |
647 | bb_perror_msg("net read"); | 647 | bb_simple_perror_msg("net read"); |
648 | } | 648 | } |
649 | pfds[1].fd = -1; /* don't poll for netfd anymore */ | 649 | pfds[1].fd = -1; /* don't poll for netfd anymore */ |
650 | fds_open--; | 650 | fds_open--; |
@@ -869,7 +869,7 @@ int nc_main(int argc UNUSED_PARAM, char **argv) | |||
869 | /* apparently UDP can listen ON "port 0", | 869 | /* apparently UDP can listen ON "port 0", |
870 | but that's not useful */ | 870 | but that's not useful */ |
871 | if (!o_lport) | 871 | if (!o_lport) |
872 | bb_error_msg_and_die("UDP listen needs nonzero -p port"); | 872 | bb_simple_error_msg_and_die("UDP listen needs nonzero -p port"); |
873 | } | 873 | } |
874 | #endif | 874 | #endif |
875 | 875 | ||
diff --git a/networking/netstat.c b/networking/netstat.c index f6bcd44ba..29b891cdc 100644 --- a/networking/netstat.c +++ b/networking/netstat.c | |||
@@ -343,9 +343,9 @@ static void prg_cache_load(void) | |||
343 | return; | 343 | return; |
344 | 344 | ||
345 | if (prg_cache_loaded == 1) | 345 | if (prg_cache_loaded == 1) |
346 | bb_error_msg("can't scan /proc - are you root?"); | 346 | bb_simple_error_msg("can't scan /proc - are you root?"); |
347 | else | 347 | else |
348 | bb_error_msg("showing only processes with your user ID"); | 348 | bb_simple_error_msg("showing only processes with your user ID"); |
349 | } | 349 | } |
350 | 350 | ||
351 | #else | 351 | #else |
diff --git a/networking/nslookup.c b/networking/nslookup.c index 24e09d4f0..8adde14b8 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c | |||
@@ -549,7 +549,7 @@ static int send_queries(struct ns *ns) | |||
549 | 549 | ||
550 | recvlen = read(pfd.fd, reply, sizeof(reply)); | 550 | recvlen = read(pfd.fd, reply, sizeof(reply)); |
551 | if (recvlen < 0) { | 551 | if (recvlen < 0) { |
552 | bb_perror_msg("read"); | 552 | bb_simple_perror_msg("read"); |
553 | next: | 553 | next: |
554 | tcur = monotonic_ms(); | 554 | tcur = monotonic_ms(); |
555 | continue; | 555 | continue; |
diff --git a/networking/ntpd.c b/networking/ntpd.c index cd6da2b38..48dc1c379 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -905,7 +905,7 @@ do_sendto(int fd, | |||
905 | ret = send_to_from(fd, msg, len, MSG_DONTWAIT, to, from, addrlen); | 905 | ret = send_to_from(fd, msg, len, MSG_DONTWAIT, to, from, addrlen); |
906 | } | 906 | } |
907 | if (ret != len) { | 907 | if (ret != len) { |
908 | bb_perror_msg("send failed"); | 908 | bb_simple_perror_msg("send failed"); |
909 | return -1; | 909 | return -1; |
910 | } | 910 | } |
911 | return 0; | 911 | return 0; |
@@ -1121,7 +1121,7 @@ step_time(double offset) | |||
1121 | dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset; | 1121 | dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset; |
1122 | d_to_tv(dtime, &tvn); | 1122 | d_to_tv(dtime, &tvn); |
1123 | if (settimeofday(&tvn, NULL) == -1) | 1123 | if (settimeofday(&tvn, NULL) == -1) |
1124 | bb_perror_msg_and_die("settimeofday"); | 1124 | bb_simple_perror_msg_and_die("settimeofday"); |
1125 | 1125 | ||
1126 | VERB2 { | 1126 | VERB2 { |
1127 | tval = tvc.tv_sec; | 1127 | tval = tvc.tv_sec; |
@@ -1494,7 +1494,7 @@ select_and_cluster(void) | |||
1494 | /* Starting from 1 is ok here */ | 1494 | /* Starting from 1 is ok here */ |
1495 | for (i = 1; i < num_survivors; i++) { | 1495 | for (i = 1; i < num_survivors; i++) { |
1496 | if (G.last_update_peer == survivor[i].p) { | 1496 | if (G.last_update_peer == survivor[i].p) { |
1497 | VERB5 bb_error_msg("keeping old synced peer"); | 1497 | VERB5 bb_simple_error_msg("keeping old synced peer"); |
1498 | p = G.last_update_peer; | 1498 | p = G.last_update_peer; |
1499 | goto keep_old; | 1499 | goto keep_old; |
1500 | } | 1500 | } |
@@ -1702,7 +1702,7 @@ update_local_clock(peer_t *p) | |||
1702 | #else | 1702 | #else |
1703 | set_new_values(STATE_SYNC, offset, recv_time); | 1703 | set_new_values(STATE_SYNC, offset, recv_time); |
1704 | #endif | 1704 | #endif |
1705 | VERB4 bb_error_msg("transitioning to FREQ, datapoint ignored"); | 1705 | VERB4 bb_simple_error_msg("transitioning to FREQ, datapoint ignored"); |
1706 | return 0; /* "leave poll interval as is" */ | 1706 | return 0; /* "leave poll interval as is" */ |
1707 | 1707 | ||
1708 | #if 0 /* this is dead code for now */ | 1708 | #if 0 /* this is dead code for now */ |
@@ -1796,7 +1796,7 @@ update_local_clock(peer_t *p) | |||
1796 | VERB4 { | 1796 | VERB4 { |
1797 | memset(&tmx, 0, sizeof(tmx)); | 1797 | memset(&tmx, 0, sizeof(tmx)); |
1798 | if (adjtimex(&tmx) < 0) | 1798 | if (adjtimex(&tmx) < 0) |
1799 | bb_perror_msg_and_die("adjtimex"); | 1799 | bb_simple_perror_msg_and_die("adjtimex"); |
1800 | bb_error_msg("p adjtimex freq:%ld offset:%+ld status:0x%x tc:%ld", | 1800 | bb_error_msg("p adjtimex freq:%ld offset:%+ld status:0x%x tc:%ld", |
1801 | tmx.freq, tmx.offset, tmx.status, tmx.constant); | 1801 | tmx.freq, tmx.offset, tmx.status, tmx.constant); |
1802 | } | 1802 | } |
@@ -1906,7 +1906,7 @@ update_local_clock(peer_t *p) | |||
1906 | //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6); | 1906 | //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6); |
1907 | rc = adjtimex(&tmx); | 1907 | rc = adjtimex(&tmx); |
1908 | if (rc < 0) | 1908 | if (rc < 0) |
1909 | bb_perror_msg_and_die("adjtimex"); | 1909 | bb_simple_perror_msg_and_die("adjtimex"); |
1910 | /* NB: here kernel returns constant == G.poll_exp, not == G.poll_exp - 4. | 1910 | /* NB: here kernel returns constant == G.poll_exp, not == G.poll_exp - 4. |
1911 | * Not sure why. Perhaps it is normal. | 1911 | * Not sure why. Perhaps it is normal. |
1912 | */ | 1912 | */ |
@@ -2018,7 +2018,7 @@ recv_and_process_peer_pkt(peer_t *p) | |||
2018 | 2018 | ||
2019 | #if ENABLE_FEATURE_NTP_AUTH | 2019 | #if ENABLE_FEATURE_NTP_AUTH |
2020 | if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH && size != NTP_MSGSIZE_SHA1_AUTH) { | 2020 | if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH && size != NTP_MSGSIZE_SHA1_AUTH) { |
2021 | bb_error_msg("malformed packet received from %s", p->p_dotted); | 2021 | bb_error_msg("malformed packet received from %s: size %u", p->p_dotted, (int)size); |
2022 | return; | 2022 | return; |
2023 | } | 2023 | } |
2024 | if (p->key_entry && hashes_differ(p, &msg)) { | 2024 | if (p->key_entry && hashes_differ(p, &msg)) { |
@@ -2027,7 +2027,7 @@ recv_and_process_peer_pkt(peer_t *p) | |||
2027 | } | 2027 | } |
2028 | #else | 2028 | #else |
2029 | if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH) { | 2029 | if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH) { |
2030 | bb_error_msg("malformed packet received from %s", p->p_dotted); | 2030 | bb_error_msg("malformed packet received from %s: size %u", p->p_dotted, (int)size); |
2031 | return; | 2031 | return; |
2032 | } | 2032 | } |
2033 | #endif | 2033 | #endif |
@@ -2238,6 +2238,13 @@ recv_and_process_client_pkt(void /*int fd*/) | |||
2238 | from = xzalloc(to->len); | 2238 | from = xzalloc(to->len); |
2239 | 2239 | ||
2240 | size = recv_from_to(G_listen_fd, &msg, sizeof(msg), MSG_DONTWAIT, from, &to->u.sa, to->len); | 2240 | size = recv_from_to(G_listen_fd, &msg, sizeof(msg), MSG_DONTWAIT, from, &to->u.sa, to->len); |
2241 | |||
2242 | /* "ntpq -p" (4.2.8p13) sends a 12-byte NTPv2 request: | ||
2243 | * m_status is 0x16: leap:0 version:2 mode:6(reserved1) | ||
2244 | * https://docs.ntpsec.org/latest/mode6.html | ||
2245 | * We don't support this. | ||
2246 | */ | ||
2247 | |||
2241 | #if ENABLE_FEATURE_NTP_AUTH | 2248 | #if ENABLE_FEATURE_NTP_AUTH |
2242 | if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH && size != NTP_MSGSIZE_SHA1_AUTH) | 2249 | if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH && size != NTP_MSGSIZE_SHA1_AUTH) |
2243 | #else | 2250 | #else |
@@ -2248,7 +2255,7 @@ recv_and_process_client_pkt(void /*int fd*/) | |||
2248 | if (size < 0) { | 2255 | if (size < 0) { |
2249 | if (errno == EAGAIN) | 2256 | if (errno == EAGAIN) |
2250 | goto bail; | 2257 | goto bail; |
2251 | bb_perror_msg_and_die("recv"); | 2258 | bb_simple_perror_msg_and_die("recv"); |
2252 | } | 2259 | } |
2253 | addr = xmalloc_sockaddr2dotted_noport(from); | 2260 | addr = xmalloc_sockaddr2dotted_noport(from); |
2254 | bb_error_msg("malformed packet received from %s: size %u", addr, (int)size); | 2261 | bb_error_msg("malformed packet received from %s: size %u", addr, (int)size); |
@@ -2415,7 +2422,7 @@ static NOINLINE void ntp_init(char **argv) | |||
2415 | srand(getpid()); | 2422 | srand(getpid()); |
2416 | 2423 | ||
2417 | if (getuid()) | 2424 | if (getuid()) |
2418 | bb_error_msg_and_die(bb_msg_you_must_be_root); | 2425 | bb_simple_error_msg_and_die(bb_msg_you_must_be_root); |
2419 | 2426 | ||
2420 | /* Set some globals */ | 2427 | /* Set some globals */ |
2421 | G.discipline_jitter = G_precision_sec; | 2428 | G.discipline_jitter = G_precision_sec; |
@@ -2436,7 +2443,8 @@ static NOINLINE void ntp_init(char **argv) | |||
2436 | "d" /* compat */ | 2443 | "d" /* compat */ |
2437 | "46aAbgL" /* compat, ignored */ | 2444 | "46aAbgL" /* compat, ignored */ |
2438 | "\0" | 2445 | "\0" |
2439 | "dd:wn" /* -d: counter; -p: list; -w implies -n */ | 2446 | "=0" /* should have no arguments */ |
2447 | ":dd:wn" /* -d: counter; -p: list; -w implies -n */ | ||
2440 | IF_FEATURE_NTPD_SERVER(":Il") /* -I implies -l */ | 2448 | IF_FEATURE_NTPD_SERVER(":Il") /* -I implies -l */ |
2441 | IF_FEATURE_NTP_AUTH(, &key_file_path) | 2449 | IF_FEATURE_NTP_AUTH(, &key_file_path) |
2442 | , &peers, &G.script_name | 2450 | , &peers, &G.script_name |
@@ -2490,7 +2498,7 @@ static NOINLINE void ntp_init(char **argv) | |||
2490 | /* supports 'sha' and 'sha1' formats */ | 2498 | /* supports 'sha' and 'sha1' formats */ |
2491 | hash_type = HASH_SHA1; | 2499 | hash_type = HASH_SHA1; |
2492 | else | 2500 | else |
2493 | bb_error_msg_and_die("only MD5 and SHA1 keys supported"); | 2501 | bb_simple_error_msg_and_die("only MD5 and SHA1 keys supported"); |
2494 | /* man ntp.keys: | 2502 | /* man ntp.keys: |
2495 | * MD5 The key is 1 to 16 printable characters terminated by an EOL, | 2503 | * MD5 The key is 1 to 16 printable characters terminated by an EOL, |
2496 | * whitespace, or a # (which is the "start of comment" character). | 2504 | * whitespace, or a # (which is the "start of comment" character). |
@@ -2673,7 +2681,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |||
2673 | if (p->p_fd == -1) { | 2681 | if (p->p_fd == -1) { |
2674 | /* Time to send new req */ | 2682 | /* Time to send new req */ |
2675 | if (--cnt == 0) { | 2683 | if (--cnt == 0) { |
2676 | VERB4 bb_error_msg("disabling burst mode"); | 2684 | VERB4 bb_simple_error_msg("disabling burst mode"); |
2677 | G.polladj_count = 0; | 2685 | G.polladj_count = 0; |
2678 | G.poll_exp = MINPOLL; | 2686 | G.poll_exp = MINPOLL; |
2679 | } | 2687 | } |
diff --git a/networking/ping.c b/networking/ping.c index b534c74c7..a47342fee 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -184,8 +184,8 @@ create_icmp_socket(void) | |||
184 | sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */ | 184 | sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */ |
185 | if (sock < 0) { | 185 | if (sock < 0) { |
186 | if (errno == EPERM) | 186 | if (errno == EPERM) |
187 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); | 187 | bb_simple_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
188 | bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); | 188 | bb_simple_perror_msg_and_die(bb_msg_can_not_create_raw_socket); |
189 | } | 189 | } |
190 | 190 | ||
191 | xmove_fd(sock, pingsock); | 191 | xmove_fd(sock, pingsock); |
@@ -235,7 +235,7 @@ static void ping4(len_and_sockaddr *lsa) | |||
235 | #endif | 235 | #endif |
236 | if (c < 0) { | 236 | if (c < 0) { |
237 | if (errno != EINTR) | 237 | if (errno != EINTR) |
238 | bb_perror_msg("recvfrom"); | 238 | bb_simple_perror_msg("recvfrom"); |
239 | continue; | 239 | continue; |
240 | } | 240 | } |
241 | if (c >= 76) { /* ip + icmp */ | 241 | if (c >= 76) { /* ip + icmp */ |
@@ -280,7 +280,7 @@ static void ping6(len_and_sockaddr *lsa) | |||
280 | #endif | 280 | #endif |
281 | if (c < 0) { | 281 | if (c < 0) { |
282 | if (errno != EINTR) | 282 | if (errno != EINTR) |
283 | bb_perror_msg("recvfrom"); | 283 | bb_simple_perror_msg("recvfrom"); |
284 | continue; | 284 | continue; |
285 | } | 285 | } |
286 | if (c >= ICMP_MINLEN) { /* icmp6_hdr */ | 286 | if (c >= ICMP_MINLEN) { /* icmp6_hdr */ |
@@ -482,7 +482,7 @@ static void sendping_tail(void (*sp)(int), int size_pkt) | |||
482 | * it doesn't matter */ | 482 | * it doesn't matter */ |
483 | sz = xsendto(pingsock, G.snd_packet, size_pkt, &pingaddr.sa, sizeof(pingaddr)); | 483 | sz = xsendto(pingsock, G.snd_packet, size_pkt, &pingaddr.sa, sizeof(pingaddr)); |
484 | if (sz != size_pkt) | 484 | if (sz != size_pkt) |
485 | bb_error_msg_and_die(bb_msg_write_error); | 485 | bb_simple_error_msg_and_die(bb_msg_write_error); |
486 | 486 | ||
487 | if (pingcount == 0 || G.ntransmitted < pingcount) { | 487 | if (pingcount == 0 || G.ntransmitted < pingcount) { |
488 | /* Didn't send all pings yet - schedule next in -i SEC interval */ | 488 | /* Didn't send all pings yet - schedule next in -i SEC interval */ |
@@ -723,7 +723,7 @@ static void ping4(len_and_sockaddr *lsa) | |||
723 | if (source_lsa) { | 723 | if (source_lsa) { |
724 | if (setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_IF, | 724 | if (setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_IF, |
725 | &source_lsa->u.sa, source_lsa->len)) | 725 | &source_lsa->u.sa, source_lsa->len)) |
726 | bb_error_msg_and_die("can't set multicast source interface"); | 726 | bb_simple_error_msg_and_die("can't set multicast source interface"); |
727 | xbind(pingsock, &source_lsa->u.sa, source_lsa->len); | 727 | xbind(pingsock, &source_lsa->u.sa, source_lsa->len); |
728 | } | 728 | } |
729 | 729 | ||
@@ -757,7 +757,7 @@ static void ping4(len_and_sockaddr *lsa) | |||
757 | (struct sockaddr *) &from, &fromlen); | 757 | (struct sockaddr *) &from, &fromlen); |
758 | if (c < 0) { | 758 | if (c < 0) { |
759 | if (errno != EINTR) | 759 | if (errno != EINTR) |
760 | bb_perror_msg("recvfrom"); | 760 | bb_simple_perror_msg("recvfrom"); |
761 | continue; | 761 | continue; |
762 | } | 762 | } |
763 | c = unpack4(G.rcv_packet, c, &from); | 763 | c = unpack4(G.rcv_packet, c, &from); |
@@ -838,7 +838,7 @@ static void ping6(len_and_sockaddr *lsa) | |||
838 | c = recvmsg(pingsock, &msg, 0); | 838 | c = recvmsg(pingsock, &msg, 0); |
839 | if (c < 0) { | 839 | if (c < 0) { |
840 | if (errno != EINTR) | 840 | if (errno != EINTR) |
841 | bb_perror_msg("recvfrom"); | 841 | bb_simple_perror_msg("recvfrom"); |
842 | continue; | 842 | continue; |
843 | } | 843 | } |
844 | for (mp = CMSG_FIRSTHDR(&msg); mp; mp = CMSG_NXTHDR(&msg, mp)) { | 844 | for (mp = CMSG_FIRSTHDR(&msg); mp; mp = CMSG_NXTHDR(&msg, mp)) { |
diff --git a/networking/route.c b/networking/route.c index ac1d94c28..a5d8d7cb9 100644 --- a/networking/route.c +++ b/networking/route.c | |||
@@ -336,7 +336,7 @@ static NOINLINE void INET_setroute(int action, char **args) | |||
336 | } | 336 | } |
337 | mask = ((struct sockaddr_in *) &rt->rt_dst)->sin_addr.s_addr; | 337 | mask = ((struct sockaddr_in *) &rt->rt_dst)->sin_addr.s_addr; |
338 | if (mask & ~(uint32_t)mask_in_addr(*rt)) { | 338 | if (mask & ~(uint32_t)mask_in_addr(*rt)) { |
339 | bb_error_msg_and_die("netmask and route address conflict"); | 339 | bb_simple_error_msg_and_die("netmask and route address conflict"); |
340 | } | 340 | } |
341 | } | 341 | } |
342 | 342 | ||
@@ -532,7 +532,7 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) | |||
532 | if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */ | 532 | if ((r < 0) && feof(fp)) { /* EOF with no (nonspace) chars read. */ |
533 | break; | 533 | break; |
534 | } | 534 | } |
535 | bb_perror_msg_and_die(bb_msg_read_error); | 535 | bb_simple_perror_msg_and_die(bb_msg_read_error); |
536 | } | 536 | } |
537 | 537 | ||
538 | if (!(flgs & RTF_UP)) { /* Skip interfaces that are down. */ | 538 | if (!(flgs & RTF_UP)) { /* Skip interfaces that are down. */ |
@@ -598,7 +598,7 @@ static void INET6_displayroutes(void) | |||
598 | break; | 598 | break; |
599 | } | 599 | } |
600 | ERROR: | 600 | ERROR: |
601 | bb_perror_msg_and_die(bb_msg_read_error); | 601 | bb_simple_perror_msg_and_die(bb_msg_read_error); |
602 | } | 602 | } |
603 | 603 | ||
604 | /* Do the addr6x shift-and-insert changes to ':'-delimit addresses. | 604 | /* Do the addr6x shift-and-insert changes to ':'-delimit addresses. |
diff --git a/networking/slattach.c b/networking/slattach.c index c6feca248..659822a91 100644 --- a/networking/slattach.c +++ b/networking/slattach.c | |||
@@ -56,7 +56,7 @@ static int tcsetattr_serial_or_warn(struct termios *state) | |||
56 | 56 | ||
57 | ret = tcsetattr(serial_fd, TCSANOW, state); | 57 | ret = tcsetattr(serial_fd, TCSANOW, state); |
58 | if (ret != 0) { | 58 | if (ret != 0) { |
59 | bb_perror_msg("tcsetattr"); | 59 | bb_simple_perror_msg("tcsetattr"); |
60 | return 1; /* used as exitcode */ | 60 | return 1; /* used as exitcode */ |
61 | } | 61 | } |
62 | return ret; /* 0 */ | 62 | return ret; /* 0 */ |
@@ -159,7 +159,7 @@ int slattach_main(int argc UNUSED_PARAM, char **argv) | |||
159 | 159 | ||
160 | /* Save current tty state */ | 160 | /* Save current tty state */ |
161 | if (tcgetattr(serial_fd, &G.saved_state) != 0) | 161 | if (tcgetattr(serial_fd, &G.saved_state) != 0) |
162 | bb_perror_msg_and_die("tcgetattr"); | 162 | bb_simple_perror_msg_and_die("tcgetattr"); |
163 | /* Save line discipline */ | 163 | /* Save line discipline */ |
164 | xioctl(serial_fd, TIOCGETD, &G.saved_disc); | 164 | xioctl(serial_fd, TIOCGETD, &G.saved_disc); |
165 | 165 | ||
diff --git a/networking/tcpudp.c b/networking/tcpudp.c index a0af64981..8c4afabf6 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c | |||
@@ -325,7 +325,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) | |||
325 | client = 0; | 325 | client = 0; |
326 | if ((getuid() == 0) && !(opts & OPT_u)) { | 326 | if ((getuid() == 0) && !(opts & OPT_u)) { |
327 | xfunc_error_retval = 100; | 327 | xfunc_error_retval = 100; |
328 | bb_error_msg_and_die(bb_msg_you_must_be_root); | 328 | bb_simple_error_msg_and_die(bb_msg_you_must_be_root); |
329 | } | 329 | } |
330 | if (opts & OPT_u) | 330 | if (opts & OPT_u) |
331 | if (!uidgid_get(&sslugid, ssluser, 1)) { | 331 | if (!uidgid_get(&sslugid, ssluser, 1)) { |
@@ -419,7 +419,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) | |||
419 | sig_block(SIGCHLD); | 419 | sig_block(SIGCHLD); |
420 | if (conn < 0) { | 420 | if (conn < 0) { |
421 | if (errno != EINTR) | 421 | if (errno != EINTR) |
422 | bb_perror_msg(tcp ? "accept" : "recv"); | 422 | bb_simple_perror_msg(tcp ? "accept" : "recv"); |
423 | goto again2; | 423 | goto again2; |
424 | } | 424 | } |
425 | xmove_fd(tcp ? conn : sock, 0); | 425 | xmove_fd(tcp ? conn : sock, 0); |
@@ -484,7 +484,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) | |||
484 | 484 | ||
485 | pid = vfork(); | 485 | pid = vfork(); |
486 | if (pid == -1) { | 486 | if (pid == -1) { |
487 | bb_perror_msg("vfork"); | 487 | bb_simple_perror_msg("vfork"); |
488 | goto again; | 488 | goto again; |
489 | } | 489 | } |
490 | 490 | ||
diff --git a/networking/telnetd.c b/networking/telnetd.c index 6abecbde2..29f805de7 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -495,7 +495,7 @@ make_new_session( | |||
495 | free(ts); | 495 | free(ts); |
496 | close(fd); | 496 | close(fd); |
497 | /* sock will be closed by caller */ | 497 | /* sock will be closed by caller */ |
498 | bb_perror_msg("vfork"); | 498 | bb_simple_perror_msg("vfork"); |
499 | return NULL; | 499 | return NULL; |
500 | } | 500 | } |
501 | if (pid > 0) { | 501 | if (pid > 0) { |
diff --git a/networking/tftp.c b/networking/tftp.c index 5ebd22105..04bfe844f 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -31,6 +31,11 @@ | |||
31 | //config: default y | 31 | //config: default y |
32 | //config: depends on TFTP | 32 | //config: depends on TFTP |
33 | //config: | 33 | //config: |
34 | //config:config FEATURE_TFTP_HPA_COMPAT | ||
35 | //config: bool "tftp-hpa compat (support -c get/put FILE)" | ||
36 | //config: default y | ||
37 | //config: depends on TFTP | ||
38 | //config: | ||
34 | //config:config TFTPD | 39 | //config:config TFTPD |
35 | //config: bool "tftpd (10 kb)" | 40 | //config: bool "tftpd (10 kb)" |
36 | //config: default y | 41 | //config: default y |
@@ -101,9 +106,10 @@ | |||
101 | //usage: IF_FEATURE_TFTP_BLOCKSIZE( | 106 | //usage: IF_FEATURE_TFTP_BLOCKSIZE( |
102 | //usage: "\n -b SIZE Transfer blocks of SIZE octets" | 107 | //usage: "\n -b SIZE Transfer blocks of SIZE octets" |
103 | //usage: ) | 108 | //usage: ) |
109 | ///////: "\n -m STR Accepted and ignored ('-m binary' compat with tftp-hpa 5.2)" | ||
104 | //usage: | 110 | //usage: |
105 | //usage:#define tftpd_trivial_usage | 111 | //usage:#define tftpd_trivial_usage |
106 | //usage: "[-cr] [-u USER] [DIR]" | 112 | //usage: "[-crl] [-u USER] [DIR]" |
107 | //usage:#define tftpd_full_usage "\n\n" | 113 | //usage:#define tftpd_full_usage "\n\n" |
108 | //usage: "Transfer a file on tftp client's request\n" | 114 | //usage: "Transfer a file on tftp client's request\n" |
109 | //usage: "\n" | 115 | //usage: "\n" |
@@ -447,7 +453,7 @@ static int tftp_protocol( | |||
447 | /* fill in packet if the filename fits into xbuf */ | 453 | /* fill in packet if the filename fits into xbuf */ |
448 | len = strlen(remote_file) + 1; | 454 | len = strlen(remote_file) + 1; |
449 | if (2 + len + sizeof("octet") >= io_bufsize) { | 455 | if (2 + len + sizeof("octet") >= io_bufsize) { |
450 | bb_error_msg("remote filename is too long"); | 456 | bb_simple_error_msg("remote filename is too long"); |
451 | goto ret; | 457 | goto ret; |
452 | } | 458 | } |
453 | strcpy(cp, remote_file); | 459 | strcpy(cp, remote_file); |
@@ -462,7 +468,7 @@ static int tftp_protocol( | |||
462 | 468 | ||
463 | /* Need to add option to pkt */ | 469 | /* Need to add option to pkt */ |
464 | if ((&xbuf[io_bufsize - 1] - cp) < sizeof("blksize NNNNN tsize ") + sizeof(off_t)*3) { | 470 | if ((&xbuf[io_bufsize - 1] - cp) < sizeof("blksize NNNNN tsize ") + sizeof(off_t)*3) { |
465 | bb_error_msg("remote filename is too long"); | 471 | bb_simple_error_msg("remote filename is too long"); |
466 | goto ret; | 472 | goto ret; |
467 | } | 473 | } |
468 | expect_OACK = 1; | 474 | expect_OACK = 1; |
@@ -563,7 +569,7 @@ static int tftp_protocol( | |||
563 | retries--; | 569 | retries--; |
564 | if (retries == 0) { | 570 | if (retries == 0) { |
565 | tftp_progress_done(); | 571 | tftp_progress_done(); |
566 | bb_error_msg("timeout"); | 572 | bb_simple_error_msg("timeout"); |
567 | goto ret; /* no err packet sent */ | 573 | goto ret; /* no err packet sent */ |
568 | } | 574 | } |
569 | 575 | ||
@@ -668,7 +674,7 @@ static int tftp_protocol( | |||
668 | * must be ignored by the client and server | 674 | * must be ignored by the client and server |
669 | * as if it were never requested." */ | 675 | * as if it were never requested." */ |
670 | if (blksize != TFTP_BLKSIZE_DEFAULT) | 676 | if (blksize != TFTP_BLKSIZE_DEFAULT) |
671 | bb_error_msg("falling back to blocksize "TFTP_BLKSIZE_DEFAULT_STR); | 677 | bb_simple_error_msg("falling back to blocksize "TFTP_BLKSIZE_DEFAULT_STR); |
672 | blksize = TFTP_BLKSIZE_DEFAULT; | 678 | blksize = TFTP_BLKSIZE_DEFAULT; |
673 | io_bufsize = TFTP_BLKSIZE_DEFAULT + 4; | 679 | io_bufsize = TFTP_BLKSIZE_DEFAULT + 4; |
674 | } | 680 | } |
@@ -733,7 +739,7 @@ static int tftp_protocol( | |||
733 | strcpy(G_error_pkt_str, bb_msg_read_error); | 739 | strcpy(G_error_pkt_str, bb_msg_read_error); |
734 | send_err_pkt: | 740 | send_err_pkt: |
735 | if (G_error_pkt_str[0]) | 741 | if (G_error_pkt_str[0]) |
736 | bb_error_msg("%s", G_error_pkt_str); | 742 | bb_simple_error_msg(G_error_pkt_str); |
737 | G.error_pkt[1] = TFTP_ERROR; | 743 | G.error_pkt[1] = TFTP_ERROR; |
738 | xsendto(socket_fd, G.error_pkt, 4 + 1 + strlen(G_error_pkt_str), | 744 | xsendto(socket_fd, G.error_pkt, 4 + 1 + strlen(G_error_pkt_str), |
739 | &peer_lsa->u.sa, peer_lsa->len); | 745 | &peer_lsa->u.sa, peer_lsa->len); |
@@ -759,15 +765,54 @@ int tftp_main(int argc UNUSED_PARAM, char **argv) | |||
759 | 765 | ||
760 | INIT_G(); | 766 | INIT_G(); |
761 | 767 | ||
768 | if (ENABLE_FEATURE_TFTP_HPA_COMPAT) { | ||
769 | /* As of 2019, common tftp client in Linux distros | ||
770 | * is one maintained by H. Peter Anvin: | ||
771 | * I've seen "tftp-hpa 5.2" version. | ||
772 | * Make the following command work: | ||
773 | * "tftp HOST [PORT] -m binary -c get/put FILE" | ||
774 | * by mangling it into "....... -g/-p -r FILE" | ||
775 | * and accepting and ignoring -m STR option. | ||
776 | */ | ||
777 | unsigned i = 1; | ||
778 | while (argv[i]) { | ||
779 | /* Accept not only -c, but also | ||
780 | * -lc, -cl, -llcclcllcc etc: | ||
781 | * "-l Literal mode (do not recognize HOST:FILE)" | ||
782 | * since we do not recognize that syntax anyway, | ||
783 | * might as well allow the option. | ||
784 | */ | ||
785 | if (argv[i][0] == '-' && strchr(argv[i], 'c') | ||
786 | /*&& argv[i][1+strspn(argv[i]+1, "lc")] == '\0'*/ | ||
787 | ) { | ||
788 | if (!argv[++i]) | ||
789 | break; | ||
790 | if (strcmp(argv[i], "get") == 0) { | ||
791 | argv[i-1] = (char*)"-g"; | ||
792 | argv[i] = (char*)"-r"; | ||
793 | break; | ||
794 | } | ||
795 | if (strcmp(argv[i], "put") == 0) { | ||
796 | argv[i-1] = (char*)"-p"; | ||
797 | argv[i] = (char*)"-r"; | ||
798 | break; | ||
799 | } | ||
800 | } | ||
801 | i++; | ||
802 | } | ||
803 | } | ||
804 | |||
762 | IF_GETPUT(opt =) getopt32(argv, "^" | 805 | IF_GETPUT(opt =) getopt32(argv, "^" |
763 | IF_FEATURE_TFTP_GET("g") IF_FEATURE_TFTP_PUT("p") | 806 | IF_FEATURE_TFTP_GET("g") IF_FEATURE_TFTP_PUT("p") |
764 | "l:r:" IF_FEATURE_TFTP_BLOCKSIZE("b:") | 807 | "l:r:" IF_FEATURE_TFTP_BLOCKSIZE("b:") |
808 | IF_FEATURE_TFTP_HPA_COMPAT("m:") | ||
765 | "\0" | 809 | "\0" |
766 | /* -p or -g is mandatory, and they are mutually exclusive */ | 810 | /* -p or -g is mandatory, and they are mutually exclusive */ |
767 | IF_FEATURE_TFTP_GET("g:") IF_FEATURE_TFTP_PUT("p:") | 811 | IF_FEATURE_TFTP_GET("g:") IF_FEATURE_TFTP_PUT("p:") |
768 | IF_GETPUT("g--p:p--g:"), | 812 | IF_GETPUT("g--p:p--g:"), |
769 | &local_file, &remote_file | 813 | &local_file, &remote_file |
770 | IF_FEATURE_TFTP_BLOCKSIZE(, &blksize_str) | 814 | IF_FEATURE_TFTP_BLOCKSIZE(, &blksize_str) |
815 | IF_FEATURE_TFTP_HPA_COMPAT(, NULL) | ||
771 | ); | 816 | ); |
772 | argv += optind; | 817 | argv += optind; |
773 | 818 | ||
@@ -897,6 +942,7 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) | |||
897 | mode = local_file + strlen(local_file) + 1; | 942 | mode = local_file + strlen(local_file) + 1; |
898 | /* RFC 1350 says mode string is case independent */ | 943 | /* RFC 1350 says mode string is case independent */ |
899 | if (mode >= G.block_buf + result || strcasecmp(mode, "octet") != 0) { | 944 | if (mode >= G.block_buf + result || strcasecmp(mode, "octet") != 0) { |
945 | error_msg = "mode is not 'octet'"; | ||
900 | goto err; | 946 | goto err; |
901 | } | 947 | } |
902 | # if ENABLE_FEATURE_TFTP_BLOCKSIZE | 948 | # if ENABLE_FEATURE_TFTP_BLOCKSIZE |
@@ -944,7 +990,8 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) | |||
944 | /* tftp_protocol() will create new one, bound to particular local IP */ | 990 | /* tftp_protocol() will create new one, bound to particular local IP */ |
945 | result = tftp_protocol( | 991 | result = tftp_protocol( |
946 | our_lsa, peer_lsa, | 992 | our_lsa, peer_lsa, |
947 | local_file IF_TFTP(, NULL /*remote_file*/) | 993 | local_file |
994 | IF_TFTP(, NULL /*remote_file*/) | ||
948 | IF_FEATURE_TFTP_BLOCKSIZE(, want_transfer_size) | 995 | IF_FEATURE_TFTP_BLOCKSIZE(, want_transfer_size) |
949 | IF_FEATURE_TFTP_BLOCKSIZE(, blksize) | 996 | IF_FEATURE_TFTP_BLOCKSIZE(, blksize) |
950 | ); | 997 | ); |
diff --git a/networking/tls.c b/networking/tls.c index d1a0204ed..9e81afbad 100644 --- a/networking/tls.c +++ b/networking/tls.c | |||
@@ -452,7 +452,7 @@ static void hmac_begin(hmac_precomputed_t *pre, uint8_t *key, unsigned key_size, | |||
452 | // than INSIZE bytes will first hash the key using H and then use the | 452 | // than INSIZE bytes will first hash the key using H and then use the |
453 | // resultant OUTSIZE byte string as the actual key to HMAC." | 453 | // resultant OUTSIZE byte string as the actual key to HMAC." |
454 | if (key_size > SHA_INSIZE) { | 454 | if (key_size > SHA_INSIZE) { |
455 | bb_error_msg_and_die("HMAC key>64"); //does not happen (yet?) | 455 | bb_simple_error_msg_and_die("HMAC key>64"); //does not happen (yet?) |
456 | // md5sha_ctx_t ctx; | 456 | // md5sha_ctx_t ctx; |
457 | // begin(&ctx); | 457 | // begin(&ctx); |
458 | // md5sha_hash(&ctx, key, key_size); | 458 | // md5sha_hash(&ctx, key, key_size); |
@@ -1138,7 +1138,7 @@ static int tls_xread_record(tls_state_t *tls, const char *expected) | |||
1138 | } | 1138 | } |
1139 | } | 1139 | } |
1140 | if (sz < 0) | 1140 | if (sz < 0) |
1141 | bb_error_msg_and_die("encrypted data too short"); | 1141 | bb_simple_error_msg_and_die("encrypted data too short"); |
1142 | 1142 | ||
1143 | //dump_hex("<< %s\n", tls->inbuf, RECHDR_LEN + sz); | 1143 | //dump_hex("<< %s\n", tls->inbuf, RECHDR_LEN + sz); |
1144 | 1144 | ||
@@ -1417,7 +1417,7 @@ static void find_key_in_der_cert(tls_state_t *tls, uint8_t *der, int len) | |||
1417 | dbg("ECDSA key\n"); | 1417 | dbg("ECDSA key\n"); |
1418 | //UNUSED: tls->flags |= GOT_CERT_ECDSA_KEY_ALG; | 1418 | //UNUSED: tls->flags |= GOT_CERT_ECDSA_KEY_ALG; |
1419 | } else | 1419 | } else |
1420 | bb_error_msg_and_die("not RSA or ECDSA cert"); | 1420 | bb_simple_error_msg_and_die("not RSA or ECDSA cert"); |
1421 | } | 1421 | } |
1422 | 1422 | ||
1423 | if (tls->flags & GOT_CERT_RSA_KEY_ALG) { | 1423 | if (tls->flags & GOT_CERT_RSA_KEY_ALG) { |
@@ -1888,7 +1888,7 @@ static void process_server_key(tls_state_t *tls, int len) | |||
1888 | /* So far we only support curve_x25519 */ | 1888 | /* So far we only support curve_x25519 */ |
1889 | move_from_unaligned32(t32, keybuf); | 1889 | move_from_unaligned32(t32, keybuf); |
1890 | if (t32 != htonl(0x03001d20)) | 1890 | if (t32 != htonl(0x03001d20)) |
1891 | bb_error_msg_and_die("elliptic curve is not x25519"); | 1891 | bb_simple_error_msg_and_die("elliptic curve is not x25519"); |
1892 | 1892 | ||
1893 | memcpy(tls->hsd->ecc_pub_key32, keybuf + 4, 32); | 1893 | memcpy(tls->hsd->ecc_pub_key32, keybuf + 4, 32); |
1894 | tls->flags |= GOT_EC_KEY; | 1894 | tls->flags |= GOT_EC_KEY; |
@@ -1935,7 +1935,7 @@ static void send_client_key_exchange(tls_state_t *tls) | |||
1935 | if (!(tls->flags & NEED_EC_KEY)) { | 1935 | if (!(tls->flags & NEED_EC_KEY)) { |
1936 | /* RSA */ | 1936 | /* RSA */ |
1937 | if (!(tls->flags & GOT_CERT_RSA_KEY_ALG)) | 1937 | if (!(tls->flags & GOT_CERT_RSA_KEY_ALG)) |
1938 | bb_error_msg("server cert is not RSA"); | 1938 | bb_simple_error_msg("server cert is not RSA"); |
1939 | 1939 | ||
1940 | tls_get_random(rsa_premaster, sizeof(rsa_premaster)); | 1940 | tls_get_random(rsa_premaster, sizeof(rsa_premaster)); |
1941 | if (TLS_DEBUG_FIXED_SECRETS) | 1941 | if (TLS_DEBUG_FIXED_SECRETS) |
@@ -1965,7 +1965,7 @@ static void send_client_key_exchange(tls_state_t *tls) | |||
1965 | uint8_t privkey[CURVE25519_KEYSIZE]; //[32] | 1965 | uint8_t privkey[CURVE25519_KEYSIZE]; //[32] |
1966 | 1966 | ||
1967 | if (!(tls->flags & GOT_EC_KEY)) | 1967 | if (!(tls->flags & GOT_EC_KEY)) |
1968 | bb_error_msg("server did not provide EC key"); | 1968 | bb_simple_error_msg("server did not provide EC key"); |
1969 | 1969 | ||
1970 | /* Generate random private key, see RFC 7748 */ | 1970 | /* Generate random private key, see RFC 7748 */ |
1971 | tls_get_random(privkey, sizeof(privkey)); | 1971 | tls_get_random(privkey, sizeof(privkey)); |
@@ -2328,7 +2328,7 @@ void FAST_FUNC tls_run_copy_loop(tls_state_t *tls, unsigned flags) | |||
2328 | int nread; | 2328 | int nread; |
2329 | 2329 | ||
2330 | if (safe_poll(pfds, 2, -1) < 0) | 2330 | if (safe_poll(pfds, 2, -1) < 0) |
2331 | bb_perror_msg_and_die("poll"); | 2331 | bb_simple_perror_msg_and_die("poll"); |
2332 | 2332 | ||
2333 | if (pfds[0].revents) { | 2333 | if (pfds[0].revents) { |
2334 | void *buf; | 2334 | void *buf; |
diff --git a/networking/tls.h b/networking/tls.h index 494ed78c4..d4ac1bef8 100644 --- a/networking/tls.h +++ b/networking/tls.h | |||
@@ -90,7 +90,7 @@ void xorbuf_aligned_AES_BLOCK_SIZE(void* buf, const void* mask) FAST_FUNC; | |||
90 | #define matrixCryptoGetPrngData(buf, len, userPtr) (tls_get_random(buf, len), PS_SUCCESS) | 90 | #define matrixCryptoGetPrngData(buf, len, userPtr) (tls_get_random(buf, len), PS_SUCCESS) |
91 | 91 | ||
92 | #define psFree(p, pool) free(p) | 92 | #define psFree(p, pool) free(p) |
93 | #define psTraceCrypto(...) bb_error_msg_and_die(__VA_ARGS__) | 93 | #define psTraceCrypto(msg) bb_simple_error_msg_and_die(msg) |
94 | 94 | ||
95 | /* Secure zerofill */ | 95 | /* Secure zerofill */ |
96 | #define memset_s(A,B,C,D) memset((A),(C),(D)) | 96 | #define memset_s(A,B,C,D) memset((A),(C),(D)) |
diff --git a/networking/traceroute.c b/networking/traceroute.c index bdf451186..0435d6ba6 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -875,7 +875,7 @@ common_traceroute_main(int op, char **argv) | |||
875 | * probe (e.g., on a multi-homed host). | 875 | * probe (e.g., on a multi-homed host). |
876 | */ | 876 | */ |
877 | if (getuid() != 0) | 877 | if (getuid() != 0) |
878 | bb_error_msg_and_die(bb_msg_you_must_be_root); | 878 | bb_simple_error_msg_and_die(bb_msg_you_must_be_root); |
879 | } | 879 | } |
880 | if (op & OPT_WAITTIME) | 880 | if (op & OPT_WAITTIME) |
881 | waittime = xatou_range(waittime_str, 1, 24 * 60 * 60); | 881 | waittime = xatou_range(waittime_str, 1, 24 * 60 * 60); |
@@ -1003,7 +1003,7 @@ common_traceroute_main(int op, char **argv) | |||
1003 | if (af == AF_INET) | 1003 | if (af == AF_INET) |
1004 | if (setsockopt(sndsock, IPPROTO_IP, IP_MULTICAST_IF, | 1004 | if (setsockopt(sndsock, IPPROTO_IP, IP_MULTICAST_IF, |
1005 | &source_lsa->u.sa, source_lsa->len)) | 1005 | &source_lsa->u.sa, source_lsa->len)) |
1006 | bb_error_msg_and_die("can't set multicast source interface"); | 1006 | bb_simple_error_msg_and_die("can't set multicast source interface"); |
1007 | //TODO: we can query source port we bound to, | 1007 | //TODO: we can query source port we bound to, |
1008 | // and check it in replies... if we care enough | 1008 | // and check it in replies... if we care enough |
1009 | xbind(sndsock, &source_lsa->u.sa, source_lsa->len); | 1009 | xbind(sndsock, &source_lsa->u.sa, source_lsa->len); |
@@ -1025,7 +1025,7 @@ common_traceroute_main(int op, char **argv) | |||
1025 | /* read IP and port */ | 1025 | /* read IP and port */ |
1026 | source_lsa = get_sock_lsa(probe_fd); | 1026 | source_lsa = get_sock_lsa(probe_fd); |
1027 | if (source_lsa == NULL) | 1027 | if (source_lsa == NULL) |
1028 | bb_error_msg_and_die("can't get probe addr"); | 1028 | bb_simple_error_msg_and_die("can't get probe addr"); |
1029 | 1029 | ||
1030 | close(probe_fd); | 1030 | close(probe_fd); |
1031 | 1031 | ||
diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src index f16fc0a4f..8ef24748e 100644 --- a/networking/udhcp/Config.src +++ b/networking/udhcp/Config.src | |||
@@ -116,7 +116,7 @@ config FEATURE_UDHCP_PORT | |||
116 | 116 | ||
117 | config UDHCP_DEBUG | 117 | config UDHCP_DEBUG |
118 | int "Maximum verbosity level (0..9)" | 118 | int "Maximum verbosity level (0..9)" |
119 | default 9 | 119 | default 2 |
120 | range 0 9 | 120 | range 0 9 |
121 | depends on UDHCPD || UDHCPC || UDHCPC6 || DHCPRELAY | 121 | depends on UDHCPD || UDHCPC || UDHCPC6 || DHCPRELAY |
122 | help | 122 | help |
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index 215d023ce..a395e838d 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c | |||
@@ -53,12 +53,12 @@ int FAST_FUNC arpping(uint32_t test_nip, | |||
53 | 53 | ||
54 | s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); | 54 | s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); |
55 | if (s == -1) { | 55 | if (s == -1) { |
56 | bb_perror_msg(bb_msg_can_not_create_raw_socket); | 56 | bb_simple_perror_msg(bb_msg_can_not_create_raw_socket); |
57 | return -1; | 57 | return -1; |
58 | } | 58 | } |
59 | 59 | ||
60 | if (setsockopt_broadcast(s) == -1) { | 60 | if (setsockopt_broadcast(s) == -1) { |
61 | bb_perror_msg("can't enable bcast on raw socket"); | 61 | bb_simple_perror_msg("can't enable bcast on raw socket"); |
62 | goto ret; | 62 | goto ret; |
63 | } | 63 | } |
64 | 64 | ||
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 62ad248ce..4a452cdb9 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -240,7 +240,7 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code) | |||
240 | while (1) { | 240 | while (1) { |
241 | if (rem <= 0) { | 241 | if (rem <= 0) { |
242 | complain: | 242 | complain: |
243 | bb_error_msg("bad packet, malformed option field"); | 243 | bb_simple_error_msg("bad packet, malformed option field"); |
244 | return NULL; | 244 | return NULL; |
245 | } | 245 | } |
246 | 246 | ||
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index bba3d6037..60255eefa 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -267,26 +267,45 @@ struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code) | |||
267 | # define IF_UDHCP_VERBOSE(...) __VA_ARGS__ | 267 | # define IF_UDHCP_VERBOSE(...) __VA_ARGS__ |
268 | extern unsigned dhcp_verbose; | 268 | extern unsigned dhcp_verbose; |
269 | # define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0) | 269 | # define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0) |
270 | # define log1s(msg) do { if (dhcp_verbose >= 1) bb_simple_info_msg(msg); } while (0) | ||
270 | # if CONFIG_UDHCP_DEBUG >= 2 | 271 | # if CONFIG_UDHCP_DEBUG >= 2 |
271 | void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; | 272 | void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; |
272 | # define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0) | 273 | # define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0) |
274 | # define log2s(msg) do { if (dhcp_verbose >= 2) bb_simple_info_msg(msg); } while (0) | ||
273 | # else | 275 | # else |
274 | # define udhcp_dump_packet(...) ((void)0) | 276 | # define udhcp_dump_packet(...) ((void)0) |
275 | # define log2(...) ((void)0) | 277 | # define log2(...) ((void)0) |
278 | # define log2s(msg) ((void)0) | ||
276 | # endif | 279 | # endif |
277 | # if CONFIG_UDHCP_DEBUG >= 3 | 280 | # if CONFIG_UDHCP_DEBUG >= 3 |
278 | # define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0) | 281 | # define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0) |
282 | # define log3s(msg) do { if (dhcp_verbose >= 3) bb_simple_info_msg(msg); } while (0) | ||
279 | # else | 283 | # else |
280 | # define log3(...) ((void)0) | 284 | # define log3(...) ((void)0) |
285 | # define log3s(msg) ((void)0) | ||
281 | # endif | 286 | # endif |
282 | #else | 287 | #else |
283 | # define IF_UDHCP_VERBOSE(...) | 288 | # define IF_UDHCP_VERBOSE(...) |
284 | # define udhcp_dump_packet(...) ((void)0) | 289 | # define udhcp_dump_packet(...) ((void)0) |
285 | # define log1(...) ((void)0) | 290 | # define log1(...) ((void)0) |
291 | # define log1s(msg) ((void)0) | ||
286 | # define log2(...) ((void)0) | 292 | # define log2(...) ((void)0) |
293 | # define log2s(msg) ((void)0) | ||
287 | # define log3(...) ((void)0) | 294 | # define log3(...) ((void)0) |
295 | # define log3s(msg) ((void)0) | ||
288 | #endif | 296 | #endif |
289 | 297 | ||
298 | #if defined(__mips__) | ||
299 | /* | ||
300 | * The 'simple' message functions have a negative impact on the size of the | ||
301 | * DHCP code when compiled for MIPS, so don't use them in this case. | ||
302 | */ | ||
303 | #define bb_simple_info_msg bb_info_msg | ||
304 | #define bb_simple_error_msg bb_error_msg | ||
305 | #define bb_simple_perror_msg_and_die bb_perror_msg_and_die | ||
306 | #undef log1s | ||
307 | #define log1s log1 | ||
308 | #endif | ||
290 | 309 | ||
291 | /*** Other shared functions ***/ | 310 | /*** Other shared functions ***/ |
292 | 311 | ||
diff --git a/networking/udhcp/d6_common.h b/networking/udhcp/d6_common.h index dee2558e2..688f5d6c7 100644 --- a/networking/udhcp/d6_common.h +++ b/networking/udhcp/d6_common.h | |||
@@ -34,7 +34,7 @@ struct d6_packet { | |||
34 | uint8_t d6_msg_type; | 34 | uint8_t d6_msg_type; |
35 | uint32_t d6_xid32; | 35 | uint32_t d6_xid32; |
36 | } d6_u; | 36 | } d6_u; |
37 | uint8_t d6_options[576 - sizeof(struct iphdr) - sizeof(struct udphdr) - 4 | 37 | uint8_t d6_options[576 - sizeof(struct ip6_hdr) - sizeof(struct udphdr) - 4 |
38 | + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS]; | 38 | + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS]; |
39 | } PACKED; | 39 | } PACKED; |
40 | #define d6_msg_type d6_u.d6_msg_type | 40 | #define d6_msg_type d6_u.d6_msg_type |
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 15e9f3924..9d8e17c51 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -235,7 +235,7 @@ static char *string_option_to_env(const uint8_t *option, | |||
235 | found: | 235 | found: |
236 | val_len = (option[2] << 8) | option[3]; | 236 | val_len = (option[2] << 8) | option[3]; |
237 | if (val_len + &option[D6_OPT_DATA] > option_end) { | 237 | if (val_len + &option[D6_OPT_DATA] > option_end) { |
238 | bb_error_msg("option data exceeds option length"); | 238 | bb_simple_error_msg("option data exceeds option length"); |
239 | return NULL; | 239 | return NULL; |
240 | } | 240 | } |
241 | return xasprintf("%s=%.*s", name, val_len, (char*)option + 4); | 241 | return xasprintf("%s=%.*s", name, val_len, (char*)option + 4); |
@@ -643,7 +643,7 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct in6_addr *requested_ip | |||
643 | client6_data.ia_na = xzalloc(len); | 643 | client6_data.ia_na = xzalloc(len); |
644 | client6_data.ia_na->code = D6_OPT_IA_NA; | 644 | client6_data.ia_na->code = D6_OPT_IA_NA; |
645 | client6_data.ia_na->len = len - 4; | 645 | client6_data.ia_na->len = len - 4; |
646 | *(uint32_t*)client6_data.ia_na->data = rand(); /* IAID */ | 646 | *(bb__aliased_uint32_t*)client6_data.ia_na->data = rand(); /* IAID */ |
647 | if (requested_ipv6) { | 647 | if (requested_ipv6) { |
648 | struct d6_option *iaaddr = (void*)(client6_data.ia_na->data + 4+4+4); | 648 | struct d6_option *iaaddr = (void*)(client6_data.ia_na->data + 4+4+4); |
649 | iaaddr->code = D6_OPT_IAADDR; | 649 | iaaddr->code = D6_OPT_IAADDR; |
@@ -661,7 +661,7 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct in6_addr *requested_ip | |||
661 | client6_data.ia_pd = xzalloc(len); | 661 | client6_data.ia_pd = xzalloc(len); |
662 | client6_data.ia_pd->code = D6_OPT_IA_PD; | 662 | client6_data.ia_pd->code = D6_OPT_IA_PD; |
663 | client6_data.ia_pd->len = len - 4; | 663 | client6_data.ia_pd->len = len - 4; |
664 | *(uint32_t*)client6_data.ia_pd->data = rand(); /* IAID */ | 664 | *(bb__aliased_uint32_t*)client6_data.ia_pd->data = rand(); /* IAID */ |
665 | opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, len); | 665 | opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, len); |
666 | } | 666 | } |
667 | 667 | ||
@@ -848,19 +848,19 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6, struct d6_pac | |||
848 | 848 | ||
849 | bytes = safe_read(fd, &packet, sizeof(packet)); | 849 | bytes = safe_read(fd, &packet, sizeof(packet)); |
850 | if (bytes < 0) { | 850 | if (bytes < 0) { |
851 | log1("packet read error, ignoring"); | 851 | log1s("packet read error, ignoring"); |
852 | /* NB: possible down interface, etc. Caller should pause. */ | 852 | /* NB: possible down interface, etc. Caller should pause. */ |
853 | return bytes; /* returns -1 */ | 853 | return bytes; /* returns -1 */ |
854 | } | 854 | } |
855 | 855 | ||
856 | if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) { | 856 | if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) { |
857 | log1("packet is too short, ignoring"); | 857 | log1s("packet is too short, ignoring"); |
858 | return -2; | 858 | return -2; |
859 | } | 859 | } |
860 | 860 | ||
861 | if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) { | 861 | if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) { |
862 | /* packet is bigger than sizeof(packet), we did partial read */ | 862 | /* packet is bigger than sizeof(packet), we did partial read */ |
863 | log1("oversized packet, ignoring"); | 863 | log1s("oversized packet, ignoring"); |
864 | return -2; | 864 | return -2; |
865 | } | 865 | } |
866 | 866 | ||
@@ -874,7 +874,7 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6, struct d6_pac | |||
874 | /* || bytes > (int) sizeof(packet) - can't happen */ | 874 | /* || bytes > (int) sizeof(packet) - can't happen */ |
875 | || packet.udp.len != packet.ip6.ip6_plen | 875 | || packet.udp.len != packet.ip6.ip6_plen |
876 | ) { | 876 | ) { |
877 | log1("unrelated/bogus packet, ignoring"); | 877 | log1s("unrelated/bogus packet, ignoring"); |
878 | return -2; | 878 | return -2; |
879 | } | 879 | } |
880 | 880 | ||
@@ -981,7 +981,7 @@ static int d6_raw_socket(int ifindex) | |||
981 | log2("opening raw socket on ifindex %d", ifindex); | 981 | log2("opening raw socket on ifindex %d", ifindex); |
982 | 982 | ||
983 | fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)); | 983 | fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)); |
984 | log2("got raw socket fd %d", fd); | 984 | log3("got raw socket fd %d", fd); |
985 | 985 | ||
986 | memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ | 986 | memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ |
987 | sock.sll_family = AF_PACKET; | 987 | sock.sll_family = AF_PACKET; |
@@ -1003,7 +1003,7 @@ static int d6_raw_socket(int ifindex) | |||
1003 | } | 1003 | } |
1004 | #endif | 1004 | #endif |
1005 | 1005 | ||
1006 | log1("created raw socket"); | 1006 | log1s("created raw socket"); |
1007 | 1007 | ||
1008 | return fd; | 1008 | return fd; |
1009 | } | 1009 | } |
@@ -1031,7 +1031,7 @@ static void change_listen_mode(int new_mode) | |||
1031 | /* Called only on SIGUSR1 */ | 1031 | /* Called only on SIGUSR1 */ |
1032 | static void perform_renew(void) | 1032 | static void perform_renew(void) |
1033 | { | 1033 | { |
1034 | bb_info_msg("performing DHCP renew"); | 1034 | bb_simple_info_msg("performing DHCP renew"); |
1035 | switch (client_data.state) { | 1035 | switch (client_data.state) { |
1036 | case BOUND: | 1036 | case BOUND: |
1037 | change_listen_mode(LISTEN_KERNEL); | 1037 | change_listen_mode(LISTEN_KERNEL); |
@@ -1059,10 +1059,10 @@ static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *ou | |||
1059 | || client_data.state == REBINDING | 1059 | || client_data.state == REBINDING |
1060 | || client_data.state == RENEW_REQUESTED | 1060 | || client_data.state == RENEW_REQUESTED |
1061 | ) { | 1061 | ) { |
1062 | bb_info_msg("unicasting a release"); | 1062 | bb_simple_info_msg("unicasting a release"); |
1063 | send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */ | 1063 | send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */ |
1064 | } | 1064 | } |
1065 | bb_info_msg("entering released state"); | 1065 | bb_simple_info_msg("entering released state"); |
1066 | /* | 1066 | /* |
1067 | * We can be here on: SIGUSR2, | 1067 | * We can be here on: SIGUSR2, |
1068 | * or on exit (SIGTERM) and -R "release on quit" is specified. | 1068 | * or on exit (SIGTERM) and -R "release on quit" is specified. |
@@ -1174,6 +1174,10 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1174 | client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; | 1174 | client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; |
1175 | client_data.sockfd = -1; | 1175 | client_data.sockfd = -1; |
1176 | 1176 | ||
1177 | /* Make sure fd 0,1,2 are open */ | ||
1178 | /* Set up the signal pipe on fds 3,4 - must be before openlog() */ | ||
1179 | udhcp_sp_setup(); | ||
1180 | |||
1177 | /* Parse command line */ | 1181 | /* Parse command line */ |
1178 | opt = getopt32long(argv, "^" | 1182 | opt = getopt32long(argv, "^" |
1179 | /* O,x: list; -T,-t,-A take numeric param */ | 1183 | /* O,x: list; -T,-t,-A take numeric param */ |
@@ -1268,14 +1272,10 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1268 | logmode |= LOGMODE_SYSLOG; | 1272 | logmode |= LOGMODE_SYSLOG; |
1269 | } | 1273 | } |
1270 | 1274 | ||
1271 | /* Make sure fd 0,1,2 are open */ | ||
1272 | bb_sanitize_stdio(); | ||
1273 | /* Create pidfile */ | 1275 | /* Create pidfile */ |
1274 | write_pidfile(client_data.pidfile); | 1276 | write_pidfile(client_data.pidfile); |
1275 | /* Goes to stdout (unless NOMMU) and possibly syslog */ | 1277 | /* Goes to stdout (unless NOMMU) and possibly syslog */ |
1276 | bb_info_msg("started, v"BB_VER); | 1278 | bb_simple_info_msg("started, v"BB_VER); |
1277 | /* Set up the signal pipe */ | ||
1278 | udhcp_sp_setup(); | ||
1279 | 1279 | ||
1280 | client_data.state = INIT_SELECTING; | 1280 | client_data.state = INIT_SELECTING; |
1281 | d6_run_script_no_option("deconfig"); | 1281 | d6_run_script_no_option("deconfig"); |
@@ -1321,7 +1321,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1321 | continue; | 1321 | continue; |
1322 | } | 1322 | } |
1323 | /* Else: an error occured, panic! */ | 1323 | /* Else: an error occured, panic! */ |
1324 | bb_perror_msg_and_die("poll"); | 1324 | bb_simple_perror_msg_and_die("poll"); |
1325 | } | 1325 | } |
1326 | } | 1326 | } |
1327 | 1327 | ||
@@ -1362,7 +1362,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1362 | d6_run_script_no_option("leasefail"); | 1362 | d6_run_script_no_option("leasefail"); |
1363 | #if BB_MMU /* -b is not supported on NOMMU */ | 1363 | #if BB_MMU /* -b is not supported on NOMMU */ |
1364 | if (opt & OPT_b) { /* background if no lease */ | 1364 | if (opt & OPT_b) { /* background if no lease */ |
1365 | bb_info_msg("no lease, forking to background"); | 1365 | bb_simple_info_msg("no lease, forking to background"); |
1366 | client_background(); | 1366 | client_background(); |
1367 | /* do not background again! */ | 1367 | /* do not background again! */ |
1368 | opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); | 1368 | opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); |
@@ -1375,7 +1375,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1375 | } else | 1375 | } else |
1376 | #endif | 1376 | #endif |
1377 | if (opt & OPT_n) { /* abort if no lease */ | 1377 | if (opt & OPT_n) { /* abort if no lease */ |
1378 | bb_info_msg("no lease, failing"); | 1378 | bb_simple_info_msg("no lease, failing"); |
1379 | retval = 1; | 1379 | retval = 1; |
1380 | goto ret; | 1380 | goto ret; |
1381 | } | 1381 | } |
@@ -1403,7 +1403,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1403 | client_data.state = RENEWING; | 1403 | client_data.state = RENEWING; |
1404 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1404 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1405 | change_listen_mode(LISTEN_KERNEL); | 1405 | change_listen_mode(LISTEN_KERNEL); |
1406 | log1("entering renew state"); | 1406 | log1s("entering renew state"); |
1407 | /* fall right through */ | 1407 | /* fall right through */ |
1408 | case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ | 1408 | case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ |
1409 | case_RENEW_REQUESTED: | 1409 | case_RENEW_REQUESTED: |
@@ -1423,7 +1423,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1423 | continue; | 1423 | continue; |
1424 | } | 1424 | } |
1425 | /* Timed out, enter rebinding state */ | 1425 | /* Timed out, enter rebinding state */ |
1426 | log1("entering rebinding state"); | 1426 | log1s("entering rebinding state"); |
1427 | client_data.state = REBINDING; | 1427 | client_data.state = REBINDING; |
1428 | /* fall right through */ | 1428 | /* fall right through */ |
1429 | case REBINDING: | 1429 | case REBINDING: |
@@ -1438,7 +1438,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1438 | continue; | 1438 | continue; |
1439 | } | 1439 | } |
1440 | /* Timed out, enter init state */ | 1440 | /* Timed out, enter init state */ |
1441 | bb_info_msg("lease lost, entering init state"); | 1441 | bb_simple_info_msg("lease lost, entering init state"); |
1442 | d6_run_script_no_option("deconfig"); | 1442 | d6_run_script_no_option("deconfig"); |
1443 | client_data.state = INIT_SELECTING; | 1443 | client_data.state = INIT_SELECTING; |
1444 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1444 | client_data.first_secs = 0; /* make secs field count from 0 */ |
@@ -1560,7 +1560,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1560 | } | 1560 | } |
1561 | 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); |
1562 | if (!option) { | 1562 | if (!option) { |
1563 | bb_info_msg("no server ID, ignoring packet"); | 1563 | bb_simple_info_msg("no server ID, ignoring packet"); |
1564 | continue; | 1564 | continue; |
1565 | /* still selecting - this server looks bad */ | 1565 | /* still selecting - this server looks bad */ |
1566 | } | 1566 | } |
diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c index 01d1c930b..446497e15 100644 --- a/networking/udhcp/d6_packet.c +++ b/networking/udhcp/d6_packet.c | |||
@@ -35,12 +35,12 @@ 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 | log1s("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_simple_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/d6_socket.c b/networking/udhcp/d6_socket.c index 25e622d6f..8ddee5a8e 100644 --- a/networking/udhcp/d6_socket.c +++ b/networking/udhcp/d6_socket.c | |||
@@ -115,7 +115,7 @@ int FAST_FUNC d6_listen_socket(int port, const char *inf) | |||
115 | 115 | ||
116 | setsockopt_reuseaddr(fd); | 116 | setsockopt_reuseaddr(fd); |
117 | if (setsockopt_broadcast(fd) == -1) | 117 | if (setsockopt_broadcast(fd) == -1) |
118 | bb_perror_msg_and_die("SO_BROADCAST"); | 118 | bb_simple_perror_msg_and_die("SO_BROADCAST"); |
119 | 119 | ||
120 | /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */ | 120 | /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */ |
121 | if (setsockopt_bindtodevice(fd, inf)) | 121 | if (setsockopt_bindtodevice(fd, inf)) |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index cb85fa9e3..656295ff7 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -449,15 +449,16 @@ static char **fill_envp(struct dhcp_packet *packet) | |||
449 | 449 | ||
450 | memset(found_opts, 0, sizeof(found_opts)); | 450 | memset(found_opts, 0, sizeof(found_opts)); |
451 | 451 | ||
452 | /* We need 6 elements for: | 452 | /* We need 7 elements for: |
453 | * "interface=IFACE" | 453 | * "interface=IFACE" |
454 | * "ip=N.N.N.N" from packet->yiaddr | 454 | * "ip=N.N.N.N" from packet->yiaddr |
455 | * "giaddr=IP" from packet->gateway_nip (unless 0) | ||
455 | * "siaddr=IP" from packet->siaddr_nip (unless 0) | 456 | * "siaddr=IP" from packet->siaddr_nip (unless 0) |
456 | * "boot_file=FILE" from packet->file (unless overloaded) | 457 | * "boot_file=FILE" from packet->file (unless overloaded) |
457 | * "sname=SERVER_HOSTNAME" from packet->sname (unless overloaded) | 458 | * "sname=SERVER_HOSTNAME" from packet->sname (unless overloaded) |
458 | * terminating NULL | 459 | * terminating NULL |
459 | */ | 460 | */ |
460 | envc = 6; | 461 | envc = 7; |
461 | /* +1 element for each option, +2 for subnet option: */ | 462 | /* +1 element for each option, +2 for subnet option: */ |
462 | if (packet) { | 463 | if (packet) { |
463 | /* note: do not search for "pad" (0) and "end" (255) options */ | 464 | /* note: do not search for "pad" (0) and "end" (255) options */ |
@@ -493,9 +494,7 @@ static char **fill_envp(struct dhcp_packet *packet) | |||
493 | * uint16_t flags; // only one flag so far: bcast. Never set by server | 494 | * uint16_t flags; // only one flag so far: bcast. Never set by server |
494 | * uint32_t ciaddr; // client IP (usually == yiaddr. can it be different | 495 | * uint32_t ciaddr; // client IP (usually == yiaddr. can it be different |
495 | * // if during renew server wants to give us different IP?) | 496 | * // if during renew server wants to give us different IP?) |
496 | * uint32_t gateway_nip; // relay agent IP address | ||
497 | * uint8_t chaddr[16]; // link-layer client hardware address (MAC) | 497 | * uint8_t chaddr[16]; // link-layer client hardware address (MAC) |
498 | * TODO: export gateway_nip as $giaddr? | ||
499 | */ | 498 | */ |
500 | /* Most important one: yiaddr as $ip */ | 499 | /* Most important one: yiaddr as $ip */ |
501 | *curr = xmalloc(sizeof("ip=255.255.255.255")); | 500 | *curr = xmalloc(sizeof("ip=255.255.255.255")); |
@@ -507,6 +506,12 @@ static char **fill_envp(struct dhcp_packet *packet) | |||
507 | sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip); | 506 | sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip); |
508 | putenv(*curr++); | 507 | putenv(*curr++); |
509 | } | 508 | } |
509 | if (packet->gateway_nip) { | ||
510 | /* IP address of DHCP relay agent */ | ||
511 | *curr = xmalloc(sizeof("giaddr=255.255.255.255")); | ||
512 | sprint_nip(*curr, "giaddr=", (uint8_t *) &packet->gateway_nip); | ||
513 | putenv(*curr++); | ||
514 | } | ||
510 | if (!(overload & FILE_FIELD) && packet->file[0]) { | 515 | if (!(overload & FILE_FIELD) && packet->file[0]) { |
511 | /* watch out for invalid packets */ | 516 | /* watch out for invalid packets */ |
512 | *curr = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file); | 517 | *curr = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file); |
@@ -901,7 +906,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
901 | if (bytes < 0) { | 906 | if (bytes < 0) { |
902 | if (errno == EINTR) | 907 | if (errno == EINTR) |
903 | continue; | 908 | continue; |
904 | log1("packet read error, ignoring"); | 909 | log1s("packet read error, ignoring"); |
905 | /* NB: possible down interface, etc. Caller should pause. */ | 910 | /* NB: possible down interface, etc. Caller should pause. */ |
906 | return bytes; /* returns -1 */ | 911 | return bytes; /* returns -1 */ |
907 | } | 912 | } |
@@ -909,13 +914,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
909 | } | 914 | } |
910 | 915 | ||
911 | if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { | 916 | if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { |
912 | log1("packet is too short, ignoring"); | 917 | log1s("packet is too short, ignoring"); |
913 | return -2; | 918 | return -2; |
914 | } | 919 | } |
915 | 920 | ||
916 | if (bytes < ntohs(packet.ip.tot_len)) { | 921 | if (bytes < ntohs(packet.ip.tot_len)) { |
917 | /* packet is bigger than sizeof(packet), we did partial read */ | 922 | /* packet is bigger than sizeof(packet), we did partial read */ |
918 | log1("oversized packet, ignoring"); | 923 | log1s("oversized packet, ignoring"); |
919 | return -2; | 924 | return -2; |
920 | } | 925 | } |
921 | 926 | ||
@@ -930,7 +935,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
930 | /* || bytes > (int) sizeof(packet) - can't happen */ | 935 | /* || bytes > (int) sizeof(packet) - can't happen */ |
931 | || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) | 936 | || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) |
932 | ) { | 937 | ) { |
933 | log1("unrelated/bogus packet, ignoring"); | 938 | log1s("unrelated/bogus packet, ignoring"); |
934 | return -2; | 939 | return -2; |
935 | } | 940 | } |
936 | 941 | ||
@@ -938,7 +943,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
938 | check = packet.ip.check; | 943 | check = packet.ip.check; |
939 | packet.ip.check = 0; | 944 | packet.ip.check = 0; |
940 | if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) { | 945 | if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) { |
941 | log1("bad IP header checksum, ignoring"); | 946 | log1s("bad IP header checksum, ignoring"); |
942 | return -2; | 947 | return -2; |
943 | } | 948 | } |
944 | 949 | ||
@@ -963,13 +968,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
963 | check = packet.udp.check; | 968 | check = packet.udp.check; |
964 | packet.udp.check = 0; | 969 | packet.udp.check = 0; |
965 | if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { | 970 | if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { |
966 | log1("packet with bad UDP checksum received, ignoring"); | 971 | log1s("packet with bad UDP checksum received, ignoring"); |
967 | return -2; | 972 | return -2; |
968 | } | 973 | } |
969 | skip_udp_sum_check: | 974 | skip_udp_sum_check: |
970 | 975 | ||
971 | if (packet.data.cookie != htonl(DHCP_MAGIC)) { | 976 | if (packet.data.cookie != htonl(DHCP_MAGIC)) { |
972 | bb_info_msg("packet with bad magic, ignoring"); | 977 | bb_simple_info_msg("packet with bad magic, ignoring"); |
973 | return -2; | 978 | return -2; |
974 | } | 979 | } |
975 | 980 | ||
@@ -1017,7 +1022,7 @@ static int udhcp_raw_socket(int ifindex) | |||
1017 | * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them) | 1022 | * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them) |
1018 | * ETH_P_IP: want to receive only packets with IPv4 eth type | 1023 | * ETH_P_IP: want to receive only packets with IPv4 eth type |
1019 | */ | 1024 | */ |
1020 | log2("got raw socket fd"); | 1025 | log3("got raw socket fd %d", fd); |
1021 | 1026 | ||
1022 | memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ | 1027 | memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ |
1023 | sock.sll_family = AF_PACKET; | 1028 | sock.sll_family = AF_PACKET; |
@@ -1084,10 +1089,10 @@ static int udhcp_raw_socket(int ifindex) | |||
1084 | 1089 | ||
1085 | if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) { | 1090 | if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) { |
1086 | if (errno != ENOPROTOOPT) | 1091 | if (errno != ENOPROTOOPT) |
1087 | log1("can't set PACKET_AUXDATA on raw socket"); | 1092 | log1s("can't set PACKET_AUXDATA on raw socket"); |
1088 | } | 1093 | } |
1089 | 1094 | ||
1090 | log1("created raw socket"); | 1095 | log1s("created raw socket"); |
1091 | 1096 | ||
1092 | return fd; | 1097 | return fd; |
1093 | } | 1098 | } |
@@ -1115,7 +1120,7 @@ static void change_listen_mode(int new_mode) | |||
1115 | /* Called only on SIGUSR1 */ | 1120 | /* Called only on SIGUSR1 */ |
1116 | static void perform_renew(void) | 1121 | static void perform_renew(void) |
1117 | { | 1122 | { |
1118 | bb_info_msg("performing DHCP renew"); | 1123 | bb_simple_info_msg("performing DHCP renew"); |
1119 | switch (client_data.state) { | 1124 | switch (client_data.state) { |
1120 | case BOUND: | 1125 | case BOUND: |
1121 | change_listen_mode(LISTEN_KERNEL); | 1126 | change_listen_mode(LISTEN_KERNEL); |
@@ -1153,7 +1158,7 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) | |||
1153 | inet_ntoa(temp_addr), buffer); | 1158 | inet_ntoa(temp_addr), buffer); |
1154 | send_release(server_addr, requested_ip); /* unicast */ | 1159 | send_release(server_addr, requested_ip); /* unicast */ |
1155 | } | 1160 | } |
1156 | bb_info_msg("entering released state"); | 1161 | bb_simple_info_msg("entering released state"); |
1157 | /* | 1162 | /* |
1158 | * We can be here on: SIGUSR2, | 1163 | * We can be here on: SIGUSR2, |
1159 | * or on exit (SIGTERM) and -R "release on quit" is specified. | 1164 | * or on exit (SIGTERM) and -R "release on quit" is specified. |
@@ -1271,6 +1276,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1271 | client_data.sockfd = -1; | 1276 | client_data.sockfd = -1; |
1272 | str_V = "udhcp "BB_VER; | 1277 | str_V = "udhcp "BB_VER; |
1273 | 1278 | ||
1279 | /* Make sure fd 0,1,2 are open */ | ||
1280 | /* Set up the signal pipe on fds 3,4 - must be before openlog() */ | ||
1281 | udhcp_sp_setup(); | ||
1282 | |||
1274 | /* Parse command line */ | 1283 | /* Parse command line */ |
1275 | opt = getopt32long(argv, "^" | 1284 | opt = getopt32long(argv, "^" |
1276 | /* O,x: list; -T,-t,-A take numeric param */ | 1285 | /* O,x: list; -T,-t,-A take numeric param */ |
@@ -1294,7 +1303,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1294 | ); | 1303 | ); |
1295 | if (opt & (OPT_h|OPT_H)) { | 1304 | if (opt & (OPT_h|OPT_H)) { |
1296 | //msg added 2011-11 | 1305 | //msg added 2011-11 |
1297 | bb_error_msg("option -h NAME is deprecated, use -x hostname:NAME"); | 1306 | bb_simple_error_msg("option -h NAME is deprecated, use -x hostname:NAME"); |
1298 | client_data.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0); | 1307 | client_data.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0); |
1299 | } | 1308 | } |
1300 | if (opt & OPT_F) { | 1309 | if (opt & OPT_F) { |
@@ -1385,14 +1394,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1385 | logmode |= LOGMODE_SYSLOG; | 1394 | logmode |= LOGMODE_SYSLOG; |
1386 | } | 1395 | } |
1387 | 1396 | ||
1388 | /* Make sure fd 0,1,2 are open */ | ||
1389 | bb_sanitize_stdio(); | ||
1390 | /* Create pidfile */ | 1397 | /* Create pidfile */ |
1391 | write_pidfile(client_data.pidfile); | 1398 | write_pidfile(client_data.pidfile); |
1392 | /* Goes to stdout (unless NOMMU) and possibly syslog */ | 1399 | /* Goes to stdout (unless NOMMU) and possibly syslog */ |
1393 | bb_info_msg("started, v"BB_VER); | 1400 | bb_simple_info_msg("started, v"BB_VER); |
1394 | /* Set up the signal pipe */ | ||
1395 | udhcp_sp_setup(); | ||
1396 | /* We want random_xid to be random... */ | 1401 | /* We want random_xid to be random... */ |
1397 | srand(monotonic_us()); | 1402 | srand(monotonic_us()); |
1398 | 1403 | ||
@@ -1439,7 +1444,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1439 | continue; | 1444 | continue; |
1440 | } | 1445 | } |
1441 | /* Else: an error occurred, panic! */ | 1446 | /* Else: an error occurred, panic! */ |
1442 | bb_perror_msg_and_die("poll"); | 1447 | bb_simple_perror_msg_and_die("poll"); |
1443 | } | 1448 | } |
1444 | } | 1449 | } |
1445 | 1450 | ||
@@ -1480,7 +1485,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1480 | udhcp_run_script(NULL, "leasefail"); | 1485 | udhcp_run_script(NULL, "leasefail"); |
1481 | #if BB_MMU /* -b is not supported on NOMMU */ | 1486 | #if BB_MMU /* -b is not supported on NOMMU */ |
1482 | if (opt & OPT_b) { /* background if no lease */ | 1487 | if (opt & OPT_b) { /* background if no lease */ |
1483 | bb_info_msg("no lease, forking to background"); | 1488 | bb_simple_info_msg("no lease, forking to background"); |
1484 | client_background(); | 1489 | client_background(); |
1485 | /* do not background again! */ | 1490 | /* do not background again! */ |
1486 | opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); | 1491 | opt = ((opt & ~(OPT_b|OPT_n)) | OPT_f); |
@@ -1493,7 +1498,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1493 | } else | 1498 | } else |
1494 | #endif | 1499 | #endif |
1495 | if (opt & OPT_n) { /* abort if no lease */ | 1500 | if (opt & OPT_n) { /* abort if no lease */ |
1496 | bb_info_msg("no lease, failing"); | 1501 | bb_simple_info_msg("no lease, failing"); |
1497 | retval = 1; | 1502 | retval = 1; |
1498 | goto ret; | 1503 | goto ret; |
1499 | } | 1504 | } |
@@ -1521,7 +1526,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1521 | client_data.state = RENEWING; | 1526 | client_data.state = RENEWING; |
1522 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1527 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1523 | change_listen_mode(LISTEN_KERNEL); | 1528 | change_listen_mode(LISTEN_KERNEL); |
1524 | log1("entering renew state"); | 1529 | log1s("entering renew state"); |
1525 | /* fall right through */ | 1530 | /* fall right through */ |
1526 | case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ | 1531 | case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ |
1527 | case_RENEW_REQUESTED: | 1532 | case_RENEW_REQUESTED: |
@@ -1554,7 +1559,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1554 | */ | 1559 | */ |
1555 | } | 1560 | } |
1556 | /* Timed out or error, enter rebinding state */ | 1561 | /* Timed out or error, enter rebinding state */ |
1557 | log1("entering rebinding state"); | 1562 | log1s("entering rebinding state"); |
1558 | client_data.state = REBINDING; | 1563 | client_data.state = REBINDING; |
1559 | /* fall right through */ | 1564 | /* fall right through */ |
1560 | case REBINDING: | 1565 | case REBINDING: |
@@ -1569,7 +1574,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1569 | continue; | 1574 | continue; |
1570 | } | 1575 | } |
1571 | /* Timed out, enter init state */ | 1576 | /* Timed out, enter init state */ |
1572 | bb_info_msg("lease lost, entering init state"); | 1577 | bb_simple_info_msg("lease lost, entering init state"); |
1573 | udhcp_run_script(NULL, "deconfig"); | 1578 | udhcp_run_script(NULL, "deconfig"); |
1574 | client_data.state = INIT_SELECTING; | 1579 | client_data.state = INIT_SELECTING; |
1575 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1580 | client_data.first_secs = 0; /* make secs field count from 0 */ |
@@ -1655,13 +1660,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1655 | || memcmp(packet.chaddr, client_data.client_mac, 6) != 0 | 1660 | || memcmp(packet.chaddr, client_data.client_mac, 6) != 0 |
1656 | ) { | 1661 | ) { |
1657 | //FIXME: need to also check that last 10 bytes are zero | 1662 | //FIXME: need to also check that last 10 bytes are zero |
1658 | log1("chaddr does not match, ignoring packet"); // log2? | 1663 | log1("chaddr does not match%s", ", ignoring packet"); // log2? |
1659 | continue; | 1664 | continue; |
1660 | } | 1665 | } |
1661 | 1666 | ||
1662 | message = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); | 1667 | message = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); |
1663 | if (message == NULL) { | 1668 | if (message == NULL) { |
1664 | bb_info_msg("no message type option, ignoring packet"); | 1669 | bb_info_msg("no message type option%s", ", ignoring packet"); |
1665 | continue; | 1670 | continue; |
1666 | } | 1671 | } |
1667 | 1672 | ||
@@ -1698,7 +1703,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1698 | server_addr = 0; | 1703 | server_addr = 0; |
1699 | temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); | 1704 | temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); |
1700 | if (!temp) { | 1705 | if (!temp) { |
1701 | bb_info_msg("no server ID, using 0.0.0.0"); | 1706 | bb_simple_info_msg("no server ID, using 0.0.0.0"); |
1702 | } else { | 1707 | } else { |
1703 | /* it IS unaligned sometimes, don't "optimize" */ | 1708 | /* it IS unaligned sometimes, don't "optimize" */ |
1704 | move_from_unaligned32(server_addr, temp); | 1709 | move_from_unaligned32(server_addr, temp); |
@@ -1725,7 +1730,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1725 | 1730 | ||
1726 | temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); | 1731 | temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); |
1727 | if (!temp) { | 1732 | if (!temp) { |
1728 | bb_info_msg("no lease time with ACK, using 1 hour lease"); | 1733 | bb_simple_info_msg("no lease time with ACK, using 1 hour lease"); |
1729 | lease_seconds = 60 * 60; | 1734 | lease_seconds = 60 * 60; |
1730 | } else { | 1735 | } else { |
1731 | /* it IS unaligned sometimes, don't "optimize" */ | 1736 | /* it IS unaligned sometimes, don't "optimize" */ |
@@ -1758,7 +1763,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1758 | client_data.interface, | 1763 | client_data.interface, |
1759 | arpping_ms) | 1764 | arpping_ms) |
1760 | ) { | 1765 | ) { |
1761 | bb_info_msg("offered address is in use " | 1766 | bb_simple_info_msg("offered address is in use " |
1762 | "(got ARP reply), declining"); | 1767 | "(got ARP reply), declining"); |
1763 | send_decline(/*xid,*/ server_addr, packet.yiaddr); | 1768 | send_decline(/*xid,*/ server_addr, packet.yiaddr); |
1764 | 1769 | ||
@@ -1822,7 +1827,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1822 | if (!temp) { | 1827 | if (!temp) { |
1823 | non_matching_svid: | 1828 | non_matching_svid: |
1824 | log1("received DHCP NAK with wrong" | 1829 | log1("received DHCP NAK with wrong" |
1825 | " server ID, ignoring packet"); | 1830 | " server ID%s", ", ignoring packet"); |
1826 | continue; | 1831 | continue; |
1827 | } | 1832 | } |
1828 | move_from_unaligned32(svid, temp); | 1833 | move_from_unaligned32(svid, temp); |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 058f86bca..3e08ec011 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -37,6 +37,8 @@ | |||
37 | //usage: IF_FEATURE_UDHCP_PORT( | 37 | //usage: IF_FEATURE_UDHCP_PORT( |
38 | //usage: "\n -P N Use port N (default 67)" | 38 | //usage: "\n -P N Use port N (default 67)" |
39 | //usage: ) | 39 | //usage: ) |
40 | //usage: "\nSignals:" | ||
41 | //usage: "\n USR1 Update lease file" | ||
40 | 42 | ||
41 | #include <netinet/ether.h> | 43 | #include <netinet/ether.h> |
42 | #include <syslog.h> | 44 | #include <syslog.h> |
@@ -46,7 +48,7 @@ | |||
46 | 48 | ||
47 | /* globals */ | 49 | /* globals */ |
48 | #define g_leases ((struct dyn_lease*)ptr_to_globals) | 50 | #define g_leases ((struct dyn_lease*)ptr_to_globals) |
49 | /* struct server_config_t server_config is in bb_common_bufsiz1 */ | 51 | /* struct server_data_t server_data is in bb_common_bufsiz1 */ |
50 | 52 | ||
51 | struct static_lease { | 53 | struct static_lease { |
52 | struct static_lease *next; | 54 | struct static_lease *next; |
@@ -100,7 +102,7 @@ static void add_static_lease(struct static_lease **st_lease_pp, | |||
100 | /* Find static lease IP by mac */ | 102 | /* Find static lease IP by mac */ |
101 | static uint32_t get_static_nip_by_mac(void *mac) | 103 | static uint32_t get_static_nip_by_mac(void *mac) |
102 | { | 104 | { |
103 | struct static_lease *st_lease = server_config.static_leases; | 105 | struct static_lease *st_lease = server_data.static_leases; |
104 | 106 | ||
105 | while (st_lease) { | 107 | while (st_lease) { |
106 | if (memcmp(st_lease->mac, mac, 6) == 0) | 108 | if (memcmp(st_lease->mac, mac, 6) == 0) |
@@ -113,7 +115,7 @@ static uint32_t get_static_nip_by_mac(void *mac) | |||
113 | 115 | ||
114 | static int is_nip_reserved_as_static(uint32_t nip) | 116 | static int is_nip_reserved_as_static(uint32_t nip) |
115 | { | 117 | { |
116 | struct static_lease *st_lease = server_config.static_leases; | 118 | struct static_lease *st_lease = server_data.static_leases; |
117 | 119 | ||
118 | while (st_lease) { | 120 | while (st_lease) { |
119 | if (st_lease->nip == nip) | 121 | if (st_lease->nip == nip) |
@@ -133,7 +135,7 @@ static struct dyn_lease *oldest_expired_lease(void) | |||
133 | 135 | ||
134 | /* Unexpired leases have g_leases[i].expires >= current time | 136 | /* Unexpired leases have g_leases[i].expires >= current time |
135 | * and therefore can't ever match */ | 137 | * and therefore can't ever match */ |
136 | for (i = 0; i < server_config.max_leases; i++) { | 138 | for (i = 0; i < server_data.max_leases; i++) { |
137 | if (g_leases[i].expires == 0 /* empty entry */ | 139 | if (g_leases[i].expires == 0 /* empty entry */ |
138 | || g_leases[i].expires < oldest_time | 140 | || g_leases[i].expires < oldest_time |
139 | ) { | 141 | ) { |
@@ -151,7 +153,7 @@ static void clear_leases(const uint8_t *chaddr, uint32_t yiaddr) | |||
151 | { | 153 | { |
152 | unsigned i; | 154 | unsigned i; |
153 | 155 | ||
154 | for (i = 0; i < server_config.max_leases; i++) { | 156 | for (i = 0; i < server_data.max_leases; i++) { |
155 | if ((chaddr && memcmp(g_leases[i].lease_mac, chaddr, 6) == 0) | 157 | if ((chaddr && memcmp(g_leases[i].lease_mac, chaddr, 6) == 0) |
156 | || (yiaddr && g_leases[i].lease_nip == yiaddr) | 158 | || (yiaddr && g_leases[i].lease_nip == yiaddr) |
157 | ) { | 159 | ) { |
@@ -216,7 +218,7 @@ static struct dyn_lease *find_lease_by_mac(const uint8_t *mac) | |||
216 | { | 218 | { |
217 | unsigned i; | 219 | unsigned i; |
218 | 220 | ||
219 | for (i = 0; i < server_config.max_leases; i++) | 221 | for (i = 0; i < server_data.max_leases; i++) |
220 | if (memcmp(g_leases[i].lease_mac, mac, 6) == 0) | 222 | if (memcmp(g_leases[i].lease_mac, mac, 6) == 0) |
221 | return &g_leases[i]; | 223 | return &g_leases[i]; |
222 | 224 | ||
@@ -228,7 +230,7 @@ static struct dyn_lease *find_lease_by_nip(uint32_t nip) | |||
228 | { | 230 | { |
229 | unsigned i; | 231 | unsigned i; |
230 | 232 | ||
231 | for (i = 0; i < server_config.max_leases; i++) | 233 | for (i = 0; i < server_data.max_leases; i++) |
232 | if (g_leases[i].lease_nip == nip) | 234 | if (g_leases[i].lease_nip == nip) |
233 | return &g_leases[i]; | 235 | return &g_leases[i]; |
234 | 236 | ||
@@ -242,17 +244,17 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigne | |||
242 | int r; | 244 | int r; |
243 | 245 | ||
244 | r = arpping(nip, safe_mac, | 246 | r = arpping(nip, safe_mac, |
245 | server_config.server_nip, | 247 | server_data.server_nip, |
246 | server_config.server_mac, | 248 | server_data.server_mac, |
247 | server_config.interface, | 249 | server_data.interface, |
248 | arpping_ms); | 250 | arpping_ms); |
249 | if (r) | 251 | if (r) |
250 | return r; | 252 | return r; |
251 | 253 | ||
252 | temp.s_addr = nip; | 254 | temp.s_addr = nip; |
253 | bb_info_msg("%s belongs to someone, reserving it for %u seconds", | 255 | bb_info_msg("%s belongs to someone, reserving it for %u seconds", |
254 | inet_ntoa(temp), (unsigned)server_config.conflict_time); | 256 | inet_ntoa(temp), (unsigned)server_data.conflict_time); |
255 | add_lease(NULL, nip, server_config.conflict_time, NULL, 0); | 257 | add_lease(NULL, nip, server_data.conflict_time, NULL, 0); |
256 | return 0; | 258 | return 0; |
257 | } | 259 | } |
258 | 260 | ||
@@ -274,12 +276,12 @@ static uint32_t find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arppi | |||
274 | hash += safe_mac[i] + (hash << 6) + (hash << 16) - hash; | 276 | hash += safe_mac[i] + (hash << 6) + (hash << 16) - hash; |
275 | 277 | ||
276 | /* pick a seed based on hwaddr then iterate until we find a free address. */ | 278 | /* pick a seed based on hwaddr then iterate until we find a free address. */ |
277 | addr = server_config.start_ip | 279 | addr = server_data.start_ip |
278 | + (hash % (1 + server_config.end_ip - server_config.start_ip)); | 280 | + (hash % (1 + server_data.end_ip - server_data.start_ip)); |
279 | stop = addr; | 281 | stop = addr; |
280 | #else | 282 | #else |
281 | addr = server_config.start_ip; | 283 | addr = server_data.start_ip; |
282 | #define stop (server_config.end_ip + 1) | 284 | #define stop (server_data.end_ip + 1) |
283 | #endif | 285 | #endif |
284 | do { | 286 | do { |
285 | uint32_t nip; | 287 | uint32_t nip; |
@@ -293,7 +295,7 @@ static uint32_t find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arppi | |||
293 | goto next_addr; | 295 | goto next_addr; |
294 | nip = htonl(addr); | 296 | nip = htonl(addr); |
295 | /* skip our own address */ | 297 | /* skip our own address */ |
296 | if (nip == server_config.server_nip) | 298 | if (nip == server_data.server_nip) |
297 | goto next_addr; | 299 | goto next_addr; |
298 | /* is this a static lease addr? */ | 300 | /* is this a static lease addr? */ |
299 | if (is_nip_reserved_as_static(nip)) | 301 | if (is_nip_reserved_as_static(nip)) |
@@ -312,8 +314,8 @@ static uint32_t find_free_or_expired_nip(const uint8_t *safe_mac, unsigned arppi | |||
312 | next_addr: | 314 | next_addr: |
313 | addr++; | 315 | addr++; |
314 | #if ENABLE_FEATURE_UDHCPD_BASE_IP_ON_MAC | 316 | #if ENABLE_FEATURE_UDHCPD_BASE_IP_ON_MAC |
315 | if (addr > server_config.end_ip) | 317 | if (addr > server_data.end_ip) |
316 | addr = server_config.start_ip; | 318 | addr = server_data.start_ip; |
317 | #endif | 319 | #endif |
318 | } while (addr != stop); | 320 | } while (addr != stop); |
319 | 321 | ||
@@ -386,7 +388,7 @@ struct config_keyword { | |||
386 | const char *def; | 388 | const char *def; |
387 | }; | 389 | }; |
388 | 390 | ||
389 | #define OFS(field) offsetof(struct server_config_t, field) | 391 | #define OFS(field) offsetof(struct server_data_t, field) |
390 | 392 | ||
391 | static const struct config_keyword keywords[] = { | 393 | static const struct config_keyword keywords[] = { |
392 | /* keyword handler variable address default */ | 394 | /* keyword handler variable address default */ |
@@ -422,17 +424,17 @@ static NOINLINE void read_config(const char *file) | |||
422 | char *token[2]; | 424 | char *token[2]; |
423 | 425 | ||
424 | for (i = 0; i < KWS_WITH_DEFAULTS; i++) | 426 | for (i = 0; i < KWS_WITH_DEFAULTS; i++) |
425 | keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs); | 427 | keywords[i].handler(keywords[i].def, (char*)&server_data + keywords[i].ofs); |
426 | 428 | ||
427 | parser = config_open(file); | 429 | parser = config_open(file); |
428 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { | 430 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { |
429 | for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { | 431 | for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { |
430 | if (strcasecmp(token[0], k->keyword) == 0) { | 432 | if (strcasecmp(token[0], k->keyword) == 0) { |
431 | if (!k->handler(token[1], (char*)&server_config + k->ofs)) { | 433 | if (!k->handler(token[1], (char*)&server_data + k->ofs)) { |
432 | bb_error_msg("can't parse line %u in %s", | 434 | bb_error_msg("can't parse line %u in %s", |
433 | parser->lineno, file); | 435 | parser->lineno, file); |
434 | /* reset back to the default value */ | 436 | /* reset back to the default value */ |
435 | k->handler(k->def, (char*)&server_config + k->ofs); | 437 | k->handler(k->def, (char*)&server_data + k->ofs); |
436 | } | 438 | } |
437 | break; | 439 | break; |
438 | } | 440 | } |
@@ -440,8 +442,8 @@ static NOINLINE void read_config(const char *file) | |||
440 | } | 442 | } |
441 | config_close(parser); | 443 | config_close(parser); |
442 | 444 | ||
443 | server_config.start_ip = ntohl(server_config.start_ip); | 445 | server_data.start_ip = ntohl(server_data.start_ip); |
444 | server_config.end_ip = ntohl(server_config.end_ip); | 446 | server_data.end_ip = ntohl(server_data.end_ip); |
445 | } | 447 | } |
446 | 448 | ||
447 | static void write_leases(void) | 449 | static void write_leases(void) |
@@ -451,7 +453,7 @@ static void write_leases(void) | |||
451 | leasetime_t curr; | 453 | leasetime_t curr; |
452 | int64_t written_at; | 454 | int64_t written_at; |
453 | 455 | ||
454 | fd = open_or_warn(server_config.lease_file, O_WRONLY|O_CREAT|O_TRUNC); | 456 | fd = open_or_warn(server_data.lease_file, O_WRONLY|O_CREAT|O_TRUNC); |
455 | if (fd < 0) | 457 | if (fd < 0) |
456 | return; | 458 | return; |
457 | 459 | ||
@@ -460,7 +462,7 @@ static void write_leases(void) | |||
460 | written_at = SWAP_BE64(written_at); | 462 | written_at = SWAP_BE64(written_at); |
461 | full_write(fd, &written_at, sizeof(written_at)); | 463 | full_write(fd, &written_at, sizeof(written_at)); |
462 | 464 | ||
463 | for (i = 0; i < server_config.max_leases; i++) { | 465 | for (i = 0; i < server_data.max_leases; i++) { |
464 | leasetime_t tmp_time; | 466 | leasetime_t tmp_time; |
465 | 467 | ||
466 | if (g_leases[i].lease_nip == 0) | 468 | if (g_leases[i].lease_nip == 0) |
@@ -483,10 +485,10 @@ static void write_leases(void) | |||
483 | } | 485 | } |
484 | close(fd); | 486 | close(fd); |
485 | 487 | ||
486 | if (server_config.notify_file) { | 488 | if (server_data.notify_file) { |
487 | char *argv[3]; | 489 | char *argv[3]; |
488 | argv[0] = server_config.notify_file; | 490 | argv[0] = server_data.notify_file; |
489 | argv[1] = server_config.lease_file; | 491 | argv[1] = server_data.lease_file; |
490 | argv[2] = NULL; | 492 | argv[2] = NULL; |
491 | spawn_and_wait(argv); | 493 | spawn_and_wait(argv); |
492 | } | 494 | } |
@@ -517,7 +519,7 @@ static NOINLINE void read_leases(const char *file) | |||
517 | 519 | ||
518 | while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { | 520 | while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) { |
519 | uint32_t y = ntohl(lease.lease_nip); | 521 | uint32_t y = ntohl(lease.lease_nip); |
520 | if (y >= server_config.start_ip && y <= server_config.end_ip) { | 522 | if (y >= server_data.start_ip && y <= server_data.end_ip) { |
521 | signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed; | 523 | signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed; |
522 | uint32_t static_nip; | 524 | uint32_t static_nip; |
523 | 525 | ||
@@ -580,28 +582,28 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc | |||
580 | || (dhcp_pkt->flags & htons(BROADCAST_FLAG)) | 582 | || (dhcp_pkt->flags & htons(BROADCAST_FLAG)) |
581 | || dhcp_pkt->ciaddr == 0 | 583 | || dhcp_pkt->ciaddr == 0 |
582 | ) { | 584 | ) { |
583 | log1("broadcasting packet to client"); | 585 | log1s("broadcasting packet to client"); |
584 | ciaddr = INADDR_BROADCAST; | 586 | ciaddr = INADDR_BROADCAST; |
585 | chaddr = MAC_BCAST_ADDR; | 587 | chaddr = MAC_BCAST_ADDR; |
586 | } else { | 588 | } else { |
587 | log1("unicasting packet to client ciaddr"); | 589 | log1s("unicasting packet to client ciaddr"); |
588 | ciaddr = dhcp_pkt->ciaddr; | 590 | ciaddr = dhcp_pkt->ciaddr; |
589 | chaddr = dhcp_pkt->chaddr; | 591 | chaddr = dhcp_pkt->chaddr; |
590 | } | 592 | } |
591 | 593 | ||
592 | udhcp_send_raw_packet(dhcp_pkt, | 594 | udhcp_send_raw_packet(dhcp_pkt, |
593 | /*src*/ server_config.server_nip, SERVER_PORT, | 595 | /*src*/ server_data.server_nip, SERVER_PORT, |
594 | /*dst*/ ciaddr, CLIENT_PORT, chaddr, | 596 | /*dst*/ ciaddr, CLIENT_PORT, chaddr, |
595 | server_config.ifindex); | 597 | server_data.ifindex); |
596 | } | 598 | } |
597 | 599 | ||
598 | /* Send a packet to gateway_nip using the kernel ip stack */ | 600 | /* Send a packet to gateway_nip using the kernel ip stack */ |
599 | static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt) | 601 | static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt) |
600 | { | 602 | { |
601 | log1("forwarding packet to relay"); | 603 | log1s("forwarding packet to relay"); |
602 | 604 | ||
603 | udhcp_send_kernel_packet(dhcp_pkt, | 605 | udhcp_send_kernel_packet(dhcp_pkt, |
604 | server_config.server_nip, SERVER_PORT, | 606 | server_data.server_nip, SERVER_PORT, |
605 | dhcp_pkt->gateway_nip, SERVER_PORT); | 607 | dhcp_pkt->gateway_nip, SERVER_PORT); |
606 | } | 608 | } |
607 | 609 | ||
@@ -633,7 +635,7 @@ static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacke | |||
633 | packet->flags = oldpacket->flags; | 635 | packet->flags = oldpacket->flags; |
634 | packet->gateway_nip = oldpacket->gateway_nip; | 636 | packet->gateway_nip = oldpacket->gateway_nip; |
635 | packet->ciaddr = oldpacket->ciaddr; | 637 | packet->ciaddr = oldpacket->ciaddr; |
636 | udhcp_add_simple_option(packet, DHCP_SERVER_ID, server_config.server_nip); | 638 | udhcp_add_simple_option(packet, DHCP_SERVER_ID, server_data.server_nip); |
637 | } | 639 | } |
638 | 640 | ||
639 | /* Fill options field, siaddr_nip, and sname and boot_file fields. | 641 | /* Fill options field, siaddr_nip, and sname and boot_file fields. |
@@ -646,7 +648,7 @@ static void add_server_options(struct dhcp_packet *packet) | |||
646 | 648 | ||
647 | client_hostname_opt = NULL; | 649 | client_hostname_opt = NULL; |
648 | if (packet->yiaddr) { /* if we aren't from send_inform()... */ | 650 | if (packet->yiaddr) { /* if we aren't from send_inform()... */ |
649 | struct static_lease *st_lease = server_config.static_leases; | 651 | struct static_lease *st_lease = server_data.static_leases; |
650 | while (st_lease) { | 652 | while (st_lease) { |
651 | if (st_lease->nip == packet->yiaddr) { | 653 | if (st_lease->nip == packet->yiaddr) { |
652 | if (st_lease->opt[0] != 0) | 654 | if (st_lease->opt[0] != 0) |
@@ -657,7 +659,7 @@ static void add_server_options(struct dhcp_packet *packet) | |||
657 | } | 659 | } |
658 | } | 660 | } |
659 | 661 | ||
660 | config_opts = server_config.options; | 662 | config_opts = server_data.options; |
661 | while (config_opts) { | 663 | while (config_opts) { |
662 | if (config_opts->data[OPT_CODE] != DHCP_LEASE_TIME) { | 664 | if (config_opts->data[OPT_CODE] != DHCP_LEASE_TIME) { |
663 | /* ^^^^ | 665 | /* ^^^^ |
@@ -684,25 +686,25 @@ static void add_server_options(struct dhcp_packet *packet) | |||
684 | if (client_hostname_opt) | 686 | if (client_hostname_opt) |
685 | udhcp_add_binary_option(packet, client_hostname_opt); | 687 | udhcp_add_binary_option(packet, client_hostname_opt); |
686 | 688 | ||
687 | packet->siaddr_nip = server_config.siaddr_nip; | 689 | packet->siaddr_nip = server_data.siaddr_nip; |
688 | 690 | ||
689 | if (server_config.sname) | 691 | if (server_data.sname) |
690 | strncpy((char*)packet->sname, server_config.sname, sizeof(packet->sname) - 1); | 692 | strncpy((char*)packet->sname, server_data.sname, sizeof(packet->sname) - 1); |
691 | if (server_config.boot_file) | 693 | if (server_data.boot_file) |
692 | strncpy((char*)packet->file, server_config.boot_file, sizeof(packet->file) - 1); | 694 | strncpy((char*)packet->file, server_data.boot_file, sizeof(packet->file) - 1); |
693 | } | 695 | } |
694 | 696 | ||
695 | static uint32_t select_lease_time(struct dhcp_packet *packet) | 697 | static uint32_t select_lease_time(struct dhcp_packet *packet) |
696 | { | 698 | { |
697 | uint32_t lease_time_sec = server_config.max_lease_sec; | 699 | uint32_t lease_time_sec = server_data.max_lease_sec; |
698 | uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME); | 700 | uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME); |
699 | if (lease_time_opt) { | 701 | if (lease_time_opt) { |
700 | move_from_unaligned32(lease_time_sec, lease_time_opt); | 702 | move_from_unaligned32(lease_time_sec, lease_time_opt); |
701 | lease_time_sec = ntohl(lease_time_sec); | 703 | lease_time_sec = ntohl(lease_time_sec); |
702 | if (lease_time_sec > server_config.max_lease_sec) | 704 | if (lease_time_sec > server_data.max_lease_sec) |
703 | lease_time_sec = server_config.max_lease_sec; | 705 | lease_time_sec = server_data.max_lease_sec; |
704 | if (lease_time_sec < server_config.min_lease_sec) | 706 | if (lease_time_sec < server_data.min_lease_sec) |
705 | lease_time_sec = server_config.min_lease_sec; | 707 | lease_time_sec = server_data.min_lease_sec; |
706 | } | 708 | } |
707 | return lease_time_sec; | 709 | return lease_time_sec; |
708 | } | 710 | } |
@@ -737,8 +739,8 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | |||
737 | /* Or: if client has requested an IP */ | 739 | /* Or: if client has requested an IP */ |
738 | else if (requested_nip != 0 | 740 | else if (requested_nip != 0 |
739 | /* and the IP is in the lease range */ | 741 | /* and the IP is in the lease range */ |
740 | && ntohl(requested_nip) >= server_config.start_ip | 742 | && ntohl(requested_nip) >= server_data.start_ip |
741 | && ntohl(requested_nip) <= server_config.end_ip | 743 | && ntohl(requested_nip) <= server_data.end_ip |
742 | /* and */ | 744 | /* and */ |
743 | && ( !(lease = find_lease_by_nip(requested_nip)) /* is not already taken */ | 745 | && ( !(lease = find_lease_by_nip(requested_nip)) /* is not already taken */ |
744 | || is_expired_lease(lease) /* or is taken, but expired */ | 746 | || is_expired_lease(lease) /* or is taken, but expired */ |
@@ -752,18 +754,18 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket, | |||
752 | } | 754 | } |
753 | 755 | ||
754 | if (!packet.yiaddr) { | 756 | if (!packet.yiaddr) { |
755 | bb_error_msg("no free IP addresses. OFFER abandoned"); | 757 | bb_simple_error_msg("no free IP addresses. OFFER abandoned"); |
756 | return; | 758 | return; |
757 | } | 759 | } |
758 | /* Reserve the IP for a short time hoping to get DHCPREQUEST soon */ | 760 | /* Reserve the IP for a short time hoping to get DHCPREQUEST soon */ |
759 | p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME); | 761 | p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME); |
760 | lease = add_lease(packet.chaddr, packet.yiaddr, | 762 | lease = add_lease(packet.chaddr, packet.yiaddr, |
761 | server_config.offer_time, | 763 | server_data.offer_time, |
762 | p_host_name, | 764 | p_host_name, |
763 | p_host_name ? (unsigned char)p_host_name[OPT_LEN - OPT_DATA] : 0 | 765 | p_host_name ? (unsigned char)p_host_name[OPT_LEN - OPT_DATA] : 0 |
764 | ); | 766 | ); |
765 | if (!lease) { | 767 | if (!lease) { |
766 | bb_error_msg("no free IP addresses. OFFER abandoned"); | 768 | bb_simple_error_msg("no free IP addresses. OFFER abandoned"); |
767 | return; | 769 | return; |
768 | } | 770 | } |
769 | } | 771 | } |
@@ -863,6 +865,10 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
863 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) | 865 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) |
864 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) | 866 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) |
865 | 867 | ||
868 | /* Make sure fd 0,1,2 are open */ | ||
869 | /* Setup the signal pipe on fds 3,4 - must be before openlog() */ | ||
870 | udhcp_sp_setup(); | ||
871 | |||
866 | opt = getopt32(argv, "^" | 872 | opt = getopt32(argv, "^" |
867 | "fSI:va:"IF_FEATURE_UDHCP_PORT("P:") | 873 | "fSI:va:"IF_FEATURE_UDHCP_PORT("P:") |
868 | "\0" | 874 | "\0" |
@@ -886,7 +892,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
886 | } | 892 | } |
887 | if (opt & 4) { /* -I */ | 893 | if (opt & 4) { /* -I */ |
888 | len_and_sockaddr *lsa = xhost_and_af2sockaddr(str_I, 0, AF_INET); | 894 | len_and_sockaddr *lsa = xhost_and_af2sockaddr(str_I, 0, AF_INET); |
889 | server_config.server_nip = lsa->u.sin.sin_addr.s_addr; | 895 | server_data.server_nip = lsa->u.sin.sin_addr.s_addr; |
890 | free(lsa); | 896 | free(lsa); |
891 | } | 897 | } |
892 | #if ENABLE_FEATURE_UDHCP_PORT | 898 | #if ENABLE_FEATURE_UDHCP_PORT |
@@ -901,52 +907,46 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
901 | * otherwise NOMMU machines will parse config twice */ | 907 | * otherwise NOMMU machines will parse config twice */ |
902 | read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE); | 908 | read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE); |
903 | /* prevent poll timeout overflow */ | 909 | /* prevent poll timeout overflow */ |
904 | if (server_config.auto_time > INT_MAX / 1000) | 910 | if (server_data.auto_time > INT_MAX / 1000) |
905 | server_config.auto_time = INT_MAX / 1000; | 911 | server_data.auto_time = INT_MAX / 1000; |
906 | |||
907 | /* Make sure fd 0,1,2 are open */ | ||
908 | bb_sanitize_stdio(); | ||
909 | 912 | ||
910 | /* Create pidfile */ | 913 | /* Create pidfile */ |
911 | write_pidfile(server_config.pidfile); | 914 | write_pidfile(server_data.pidfile); |
912 | /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ | 915 | /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ |
913 | 916 | ||
914 | bb_info_msg("started, v"BB_VER); | 917 | bb_simple_info_msg("started, v"BB_VER); |
915 | 918 | ||
916 | option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME); | 919 | option = udhcp_find_option(server_data.options, DHCP_LEASE_TIME); |
917 | server_config.max_lease_sec = DEFAULT_LEASE_TIME; | 920 | server_data.max_lease_sec = DEFAULT_LEASE_TIME; |
918 | if (option) { | 921 | if (option) { |
919 | move_from_unaligned32(server_config.max_lease_sec, option->data + OPT_DATA); | 922 | move_from_unaligned32(server_data.max_lease_sec, option->data + OPT_DATA); |
920 | server_config.max_lease_sec = ntohl(server_config.max_lease_sec); | 923 | server_data.max_lease_sec = ntohl(server_data.max_lease_sec); |
921 | } | 924 | } |
922 | 925 | ||
923 | /* Sanity check */ | 926 | /* Sanity check */ |
924 | num_ips = server_config.end_ip - server_config.start_ip + 1; | 927 | num_ips = server_data.end_ip - server_data.start_ip + 1; |
925 | if (server_config.max_leases > num_ips) { | 928 | if (server_data.max_leases > num_ips) { |
926 | bb_error_msg("max_leases=%u is too big, setting to %u", | 929 | bb_error_msg("max_leases=%u is too big, setting to %u", |
927 | (unsigned)server_config.max_leases, num_ips); | 930 | (unsigned)server_data.max_leases, num_ips); |
928 | server_config.max_leases = num_ips; | 931 | server_data.max_leases = num_ips; |
929 | } | 932 | } |
930 | 933 | ||
931 | /* this sets g_leases */ | 934 | /* this sets g_leases */ |
932 | SET_PTR_TO_GLOBALS(xzalloc(server_config.max_leases * sizeof(g_leases[0]))); | 935 | SET_PTR_TO_GLOBALS(xzalloc(server_data.max_leases * sizeof(g_leases[0]))); |
933 | 936 | ||
934 | read_leases(server_config.lease_file); | 937 | read_leases(server_data.lease_file); |
935 | 938 | ||
936 | if (udhcp_read_interface(server_config.interface, | 939 | if (udhcp_read_interface(server_data.interface, |
937 | &server_config.ifindex, | 940 | &server_data.ifindex, |
938 | (server_config.server_nip == 0 ? &server_config.server_nip : NULL), | 941 | (server_data.server_nip == 0 ? &server_data.server_nip : NULL), |
939 | server_config.server_mac) | 942 | server_data.server_mac) |
940 | ) { | 943 | ) { |
941 | retval = 1; | 944 | retval = 1; |
942 | goto ret; | 945 | goto ret; |
943 | } | 946 | } |
944 | 947 | ||
945 | /* Setup the signal pipe */ | ||
946 | udhcp_sp_setup(); | ||
947 | |||
948 | continue_with_autotime: | 948 | continue_with_autotime: |
949 | timeout_end = monotonic_sec() + server_config.auto_time; | 949 | timeout_end = monotonic_sec() + server_data.auto_time; |
950 | while (1) { /* loop until universe collapses */ | 950 | while (1) { /* loop until universe collapses */ |
951 | struct pollfd pfds[2]; | 951 | struct pollfd pfds[2]; |
952 | struct dhcp_packet packet; | 952 | struct dhcp_packet packet; |
@@ -960,14 +960,14 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
960 | 960 | ||
961 | if (server_socket < 0) { | 961 | if (server_socket < 0) { |
962 | server_socket = udhcp_listen_socket(/*INADDR_ANY,*/ SERVER_PORT, | 962 | server_socket = udhcp_listen_socket(/*INADDR_ANY,*/ SERVER_PORT, |
963 | server_config.interface); | 963 | server_data.interface); |
964 | } | 964 | } |
965 | 965 | ||
966 | udhcp_sp_fd_set(pfds, server_socket); | 966 | udhcp_sp_fd_set(pfds, server_socket); |
967 | 967 | ||
968 | new_tv: | 968 | new_tv: |
969 | tv = -1; | 969 | tv = -1; |
970 | if (server_config.auto_time) { | 970 | if (server_data.auto_time) { |
971 | tv = timeout_end - monotonic_sec(); | 971 | tv = timeout_end - monotonic_sec(); |
972 | if (tv <= 0) { | 972 | if (tv <= 0) { |
973 | write_leases: | 973 | write_leases: |
@@ -985,7 +985,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
985 | if (errno == EINTR) | 985 | if (errno == EINTR) |
986 | goto new_tv; | 986 | goto new_tv; |
987 | /* < 0 and not EINTR: should not happen */ | 987 | /* < 0 and not EINTR: should not happen */ |
988 | bb_perror_msg_and_die("poll"); | 988 | bb_simple_perror_msg_and_die("poll"); |
989 | } | 989 | } |
990 | 990 | ||
991 | if (pfds[0].revents) switch (udhcp_sp_read()) { | 991 | if (pfds[0].revents) switch (udhcp_sp_read()) { |
@@ -1019,16 +1019,16 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
1019 | continue; | 1019 | continue; |
1020 | } | 1020 | } |
1021 | if (packet.hlen != 6) { | 1021 | if (packet.hlen != 6) { |
1022 | bb_info_msg("MAC length != 6, ignoring packet"); | 1022 | bb_info_msg("MAC length != 6%s", ", ignoring packet"); |
1023 | continue; | 1023 | continue; |
1024 | } | 1024 | } |
1025 | if (packet.op != BOOTREQUEST) { | 1025 | if (packet.op != BOOTREQUEST) { |
1026 | bb_info_msg("not a REQUEST, ignoring packet"); | 1026 | bb_info_msg("not a REQUEST%s", ", ignoring packet"); |
1027 | continue; | 1027 | continue; |
1028 | } | 1028 | } |
1029 | state = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); | 1029 | state = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); |
1030 | if (state == NULL || state[0] < DHCP_MINTYPE || state[0] > DHCP_MAXTYPE) { | 1030 | if (state == NULL || state[0] < DHCP_MINTYPE || state[0] > DHCP_MAXTYPE) { |
1031 | bb_info_msg("no or bad message type option, ignoring packet"); | 1031 | bb_info_msg("no or bad message type option%s", ", ignoring packet"); |
1032 | continue; | 1032 | continue; |
1033 | } | 1033 | } |
1034 | 1034 | ||
@@ -1037,9 +1037,9 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
1037 | if (server_id_opt) { | 1037 | if (server_id_opt) { |
1038 | uint32_t server_id_network_order; | 1038 | uint32_t server_id_network_order; |
1039 | move_from_unaligned32(server_id_network_order, server_id_opt); | 1039 | move_from_unaligned32(server_id_network_order, server_id_opt); |
1040 | if (server_id_network_order != server_config.server_nip) { | 1040 | if (server_id_network_order != server_data.server_nip) { |
1041 | /* client talks to somebody else */ | 1041 | /* client talks to somebody else */ |
1042 | log1("server ID doesn't match, ignoring"); | 1042 | log1("server ID doesn't match%s", ", ignoring"); |
1043 | continue; | 1043 | continue; |
1044 | } | 1044 | } |
1045 | } | 1045 | } |
@@ -1162,7 +1162,7 @@ o DHCPREQUEST generated during REBINDING state: | |||
1162 | if (!requested_ip_opt) { | 1162 | if (!requested_ip_opt) { |
1163 | requested_nip = packet.ciaddr; | 1163 | requested_nip = packet.ciaddr; |
1164 | if (requested_nip == 0) { | 1164 | if (requested_nip == 0) { |
1165 | log1("no requested IP and no ciaddr, ignoring"); | 1165 | log1("no requested IP and no ciaddr%s", ", ignoring"); |
1166 | break; | 1166 | break; |
1167 | } | 1167 | } |
1168 | } | 1168 | } |
@@ -1204,7 +1204,7 @@ o DHCPREQUEST generated during REBINDING state: | |||
1204 | && requested_nip == lease->lease_nip | 1204 | && requested_nip == lease->lease_nip |
1205 | ) { | 1205 | ) { |
1206 | memset(lease->lease_mac, 0, sizeof(lease->lease_mac)); | 1206 | memset(lease->lease_mac, 0, sizeof(lease->lease_mac)); |
1207 | lease->expires = time(NULL) + server_config.decline_time; | 1207 | lease->expires = time(NULL) + server_data.decline_time; |
1208 | } | 1208 | } |
1209 | break; | 1209 | break; |
1210 | 1210 | ||
@@ -1235,7 +1235,7 @@ o DHCPREQUEST generated during REBINDING state: | |||
1235 | ret0: | 1235 | ret0: |
1236 | retval = 0; | 1236 | retval = 0; |
1237 | ret: | 1237 | ret: |
1238 | /*if (server_config.pidfile) - server_config.pidfile is never NULL */ | 1238 | /*if (server_data.pidfile) - server_data.pidfile is never NULL */ |
1239 | remove_pidfile(server_config.pidfile); | 1239 | remove_pidfile(server_data.pidfile); |
1240 | return retval; | 1240 | return retval; |
1241 | } | 1241 | } |
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index ba11d77e8..b42849bbb 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
@@ -17,7 +17,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | |||
17 | 17 | ||
18 | struct static_lease; | 18 | struct static_lease; |
19 | 19 | ||
20 | struct server_config_t { | 20 | struct server_data_t { |
21 | char *interface; /* interface to use */ | 21 | char *interface; /* interface to use */ |
22 | //TODO: ifindex, server_nip, server_mac | 22 | //TODO: ifindex, server_nip, server_mac |
23 | // are obtained from interface name. | 23 | // are obtained from interface name. |
@@ -53,12 +53,12 @@ struct server_config_t { | |||
53 | struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ | 53 | struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ |
54 | } FIX_ALIASING; | 54 | } FIX_ALIASING; |
55 | 55 | ||
56 | #define server_config (*(struct server_config_t*)bb_common_bufsiz1) | 56 | #define server_data (*(struct server_data_t*)bb_common_bufsiz1) |
57 | /* client_data sits in 2nd half of bb_common_bufsiz1 */ | 57 | /* client_data sits in 2nd half of bb_common_bufsiz1 */ |
58 | 58 | ||
59 | #if ENABLE_FEATURE_UDHCP_PORT | 59 | #if ENABLE_FEATURE_UDHCP_PORT |
60 | #define SERVER_PORT (server_config.port) | 60 | #define SERVER_PORT (server_data.port) |
61 | #define SERVER_PORT6 (server_config.port) | 61 | #define SERVER_PORT6 (server_data.port) |
62 | #else | 62 | #else |
63 | #define SERVER_PORT 67 | 63 | #define SERVER_PORT 67 |
64 | #define SERVER_PORT6 547 | 64 | #define SERVER_PORT6 547 |
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index 86dcb1af0..ef9447b4b 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c | |||
@@ -186,7 +186,7 @@ static int sendto_ip4(int sock, const void *msg, int msg_len, struct sockaddr_in | |||
186 | err = sendto(sock, msg, msg_len, 0, (struct sockaddr*) to, sizeof(*to)); | 186 | err = sendto(sock, msg, msg_len, 0, (struct sockaddr*) to, sizeof(*to)); |
187 | err -= msg_len; | 187 | err -= msg_len; |
188 | if (err) | 188 | if (err) |
189 | bb_perror_msg("sendto"); | 189 | bb_simple_perror_msg("sendto"); |
190 | return err; | 190 | return err; |
191 | } | 191 | } |
192 | 192 | ||
@@ -273,7 +273,7 @@ int dhcprelay_main(int argc UNUSED_PARAM, char **argv) | |||
273 | bb_show_usage(); | 273 | bb_show_usage(); |
274 | if (argv[3]) { | 274 | if (argv[3]) { |
275 | if (!inet_aton(argv[3], &server_addr.sin_addr)) | 275 | if (!inet_aton(argv[3], &server_addr.sin_addr)) |
276 | bb_perror_msg_and_die("bad server IP"); | 276 | bb_simple_perror_msg_and_die("bad server IP"); |
277 | } | 277 | } |
278 | 278 | ||
279 | iface_list = make_iface_list(argv + 1, &num_sockets); | 279 | iface_list = make_iface_list(argv + 1, &num_sockets); |
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 64af802a3..6d4375237 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c | |||
@@ -85,14 +85,14 @@ 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 | log1s("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_simple_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/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c index 2ff78f0f2..7df671245 100644 --- a/networking/udhcp/signalpipe.c +++ b/networking/udhcp/signalpipe.c | |||
@@ -20,15 +20,15 @@ | |||
20 | */ | 20 | */ |
21 | #include "common.h" | 21 | #include "common.h" |
22 | 22 | ||
23 | /* Global variable: we access it from signal handler */ | 23 | #define READ_FD 3 |
24 | static struct fd_pair signal_pipe; | 24 | #define WRITE_FD 4 |
25 | 25 | ||
26 | static void signal_handler(int sig) | 26 | static void signal_handler(int sig) |
27 | { | 27 | { |
28 | int sv = errno; | 28 | int sv = errno; |
29 | unsigned char ch = sig; /* use char, avoid dealing with partial writes */ | 29 | unsigned char ch = sig; /* use char, avoid dealing with partial writes */ |
30 | if (write(signal_pipe.wr, &ch, 1) != 1) | 30 | if (write(WRITE_FD, &ch, 1) != 1) |
31 | bb_perror_msg("can't send signal"); | 31 | bb_simple_perror_msg("can't send signal"); |
32 | errno = sv; | 32 | errno = sv; |
33 | } | 33 | } |
34 | 34 | ||
@@ -36,12 +36,25 @@ static void signal_handler(int sig) | |||
36 | * and installs the signal handler */ | 36 | * and installs the signal handler */ |
37 | void FAST_FUNC udhcp_sp_setup(void) | 37 | void FAST_FUNC udhcp_sp_setup(void) |
38 | { | 38 | { |
39 | struct fd_pair signal_pipe; | ||
40 | |||
41 | /* All callers also want this, so... */ | ||
42 | bb_sanitize_stdio(); | ||
43 | |||
39 | /* was socketpair, but it needs AF_UNIX in kernel */ | 44 | /* was socketpair, but it needs AF_UNIX in kernel */ |
40 | xpiped_pair(signal_pipe); | 45 | xpiped_pair(signal_pipe); |
41 | close_on_exec_on(signal_pipe.rd); | 46 | |
42 | close_on_exec_on(signal_pipe.wr); | 47 | /* usually we get fds 3 and 4, but if we get higher ones... */ |
43 | ndelay_on(signal_pipe.rd); | 48 | if (signal_pipe.rd != READ_FD) |
44 | ndelay_on(signal_pipe.wr); | 49 | xmove_fd(signal_pipe.rd, READ_FD); |
50 | if (signal_pipe.wr != WRITE_FD) | ||
51 | xmove_fd(signal_pipe.wr, WRITE_FD); | ||
52 | |||
53 | close_on_exec_on(READ_FD); | ||
54 | close_on_exec_on(WRITE_FD); | ||
55 | ndelay_on(READ_FD); | ||
56 | ndelay_on(WRITE_FD); | ||
57 | |||
45 | bb_signals(0 | 58 | bb_signals(0 |
46 | + (1 << SIGUSR1) | 59 | + (1 << SIGUSR1) |
47 | + (1 << SIGUSR2) | 60 | + (1 << SIGUSR2) |
@@ -54,7 +67,7 @@ void FAST_FUNC udhcp_sp_setup(void) | |||
54 | */ | 67 | */ |
55 | void FAST_FUNC udhcp_sp_fd_set(struct pollfd pfds[2], int extra_fd) | 68 | void FAST_FUNC udhcp_sp_fd_set(struct pollfd pfds[2], int extra_fd) |
56 | { | 69 | { |
57 | pfds[0].fd = signal_pipe.rd; | 70 | pfds[0].fd = READ_FD; |
58 | pfds[0].events = POLLIN; | 71 | pfds[0].events = POLLIN; |
59 | pfds[1].fd = -1; | 72 | pfds[1].fd = -1; |
60 | if (extra_fd >= 0) { | 73 | if (extra_fd >= 0) { |
@@ -74,7 +87,7 @@ int FAST_FUNC udhcp_sp_read(void) | |||
74 | unsigned char sig; | 87 | unsigned char sig; |
75 | 88 | ||
76 | /* Can't block here, fd is in nonblocking mode */ | 89 | /* Can't block here, fd is in nonblocking mode */ |
77 | if (safe_read(signal_pipe.rd, &sig, 1) != 1) | 90 | if (safe_read(READ_FD, &sig, 1) != 1) |
78 | return 0; | 91 | return 0; |
79 | 92 | ||
80 | return sig; | 93 | return sig; |
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index 34049c3ee..65a1a8ead 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c | |||
@@ -87,7 +87,7 @@ int FAST_FUNC udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) | |||
87 | 87 | ||
88 | setsockopt_reuseaddr(fd); | 88 | setsockopt_reuseaddr(fd); |
89 | if (setsockopt_broadcast(fd) == -1) | 89 | if (setsockopt_broadcast(fd) == -1) |
90 | bb_perror_msg_and_die("SO_BROADCAST"); | 90 | bb_simple_perror_msg_and_die("SO_BROADCAST"); |
91 | 91 | ||
92 | /* SO_BINDTODEVICE doesn't work on ethernet aliases (ethN:M) */ | 92 | /* SO_BINDTODEVICE doesn't work on ethernet aliases (ethN:M) */ |
93 | colon = strrchr(inf, ':'); | 93 | colon = strrchr(inf, ':'); |
diff --git a/networking/wget.c b/networking/wget.c index 44cec2cb5..5b85cce1f 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -368,7 +368,7 @@ static void alarm_handler(int sig UNUSED_PARAM) | |||
368 | { | 368 | { |
369 | /* This is theoretically unsafe (uses stdio and malloc in signal handler) */ | 369 | /* This is theoretically unsafe (uses stdio and malloc in signal handler) */ |
370 | if (G.die_if_timed_out) | 370 | if (G.die_if_timed_out) |
371 | bb_error_msg_and_die("download timed out"); | 371 | bb_simple_error_msg_and_die("download timed out"); |
372 | } | 372 | } |
373 | static void set_alarm(void) | 373 | static void set_alarm(void) |
374 | { | 374 | { |
@@ -452,7 +452,7 @@ static char fgets_trim_sanitize(FILE *fp, const char *fmt) | |||
452 | 452 | ||
453 | set_alarm(); | 453 | set_alarm(); |
454 | if (fgets(G.wget_buf, sizeof(G.wget_buf), fp) == NULL) | 454 | if (fgets(G.wget_buf, sizeof(G.wget_buf), fp) == NULL) |
455 | bb_perror_msg_and_die("error getting response"); | 455 | bb_simple_perror_msg_and_die("error getting response"); |
456 | clear_alarm(); | 456 | clear_alarm(); |
457 | 457 | ||
458 | buf_ptr = strchrnul(G.wget_buf, '\n'); | 458 | buf_ptr = strchrnul(G.wget_buf, '\n'); |
@@ -639,7 +639,7 @@ static char *get_sanitized_hdr(FILE *fp) | |||
639 | 639 | ||
640 | static void reset_beg_range_to_zero(void) | 640 | static void reset_beg_range_to_zero(void) |
641 | { | 641 | { |
642 | bb_error_msg("restart failed"); | 642 | bb_simple_error_msg("restart failed"); |
643 | G.beg_range = 0; | 643 | G.beg_range = 0; |
644 | xlseek(G.output_fd, 0, SEEK_SET); | 644 | xlseek(G.output_fd, 0, SEEK_SET); |
645 | /* Done at the end instead: */ | 645 | /* Done at the end instead: */ |
@@ -657,7 +657,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) | |||
657 | 657 | ||
658 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0) | 658 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0) |
659 | /* Kernel can have AF_UNIX support disabled */ | 659 | /* Kernel can have AF_UNIX support disabled */ |
660 | bb_perror_msg_and_die("socketpair"); | 660 | bb_simple_perror_msg_and_die("socketpair"); |
661 | 661 | ||
662 | if (!strchr(host, ':')) | 662 | if (!strchr(host, ':')) |
663 | host = allocated = xasprintf("%s:%u", host, port); | 663 | host = allocated = xasprintf("%s:%u", host, port); |
@@ -731,7 +731,7 @@ static void spawn_ssl_client(const char *host, int network_fd, int flags) | |||
731 | 731 | ||
732 | if (!(option_mask32 & WGET_OPT_NO_CHECK_CERT)) { | 732 | if (!(option_mask32 & WGET_OPT_NO_CHECK_CERT)) { |
733 | option_mask32 |= WGET_OPT_NO_CHECK_CERT; | 733 | option_mask32 |= WGET_OPT_NO_CHECK_CERT; |
734 | bb_error_msg("note: TLS certificate validation not implemented"); | 734 | bb_simple_error_msg("note: TLS certificate validation not implemented"); |
735 | } | 735 | } |
736 | 736 | ||
737 | servername = xstrdup(host); | 737 | servername = xstrdup(host); |
@@ -740,7 +740,7 @@ static void spawn_ssl_client(const char *host, int network_fd, int flags) | |||
740 | 740 | ||
741 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0) | 741 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0) |
742 | /* Kernel can have AF_UNIX support disabled */ | 742 | /* Kernel can have AF_UNIX support disabled */ |
743 | bb_perror_msg_and_die("socketpair"); | 743 | bb_simple_perror_msg_and_die("socketpair"); |
744 | 744 | ||
745 | fflush_all(); | 745 | fflush_all(); |
746 | pid = BB_MMU ? xfork() : xvfork(); | 746 | pid = BB_MMU ? xfork() : xvfork(); |
@@ -818,7 +818,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
818 | #endif | 818 | #endif |
819 | 819 | ||
820 | if (ftpcmd(NULL, NULL, sfp) != 220) | 820 | if (ftpcmd(NULL, NULL, sfp) != 220) |
821 | bb_error_msg_and_die("%s", G.wget_buf); | 821 | bb_simple_error_msg_and_die(G.wget_buf); |
822 | /* note: ftpcmd() sanitizes G.wget_buf, ok to print */ | 822 | /* note: ftpcmd() sanitizes G.wget_buf, ok to print */ |
823 | 823 | ||
824 | /* Split username:password pair */ | 824 | /* Split username:password pair */ |
@@ -981,7 +981,7 @@ static void NOINLINE retrieve_file_data(FILE *dfp) | |||
981 | if (errno != EAGAIN) { | 981 | if (errno != EAGAIN) { |
982 | if (ferror(dfp)) { | 982 | if (ferror(dfp)) { |
983 | progress_meter(PROGRESS_END); | 983 | progress_meter(PROGRESS_END); |
984 | bb_perror_msg_and_die(bb_msg_read_error); | 984 | bb_simple_perror_msg_and_die(bb_msg_read_error); |
985 | } | 985 | } |
986 | break; /* EOF, not error */ | 986 | break; /* EOF, not error */ |
987 | } | 987 | } |
@@ -994,7 +994,7 @@ static void NOINLINE retrieve_file_data(FILE *dfp) | |||
994 | # if ENABLE_FEATURE_WGET_TIMEOUT | 994 | # if ENABLE_FEATURE_WGET_TIMEOUT |
995 | if (second_cnt != 0 && --second_cnt == 0) { | 995 | if (second_cnt != 0 && --second_cnt == 0) { |
996 | progress_meter(PROGRESS_END); | 996 | progress_meter(PROGRESS_END); |
997 | bb_error_msg_and_die("download timed out"); | 997 | bb_simple_error_msg_and_die("download timed out"); |
998 | } | 998 | } |
999 | # endif | 999 | # endif |
1000 | /* We used to loop back to poll here, | 1000 | /* We used to loop back to poll here, |
@@ -1047,7 +1047,7 @@ static void NOINLINE retrieve_file_data(FILE *dfp) | |||
1047 | G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ | 1047 | G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ |
1048 | progress_meter(PROGRESS_END); | 1048 | progress_meter(PROGRESS_END); |
1049 | if (G.content_len != 0) { | 1049 | if (G.content_len != 0) { |
1050 | bb_perror_msg_and_die("connection closed prematurely"); | 1050 | bb_simple_perror_msg_and_die("connection closed prematurely"); |
1051 | /* GNU wget says "DATE TIME (NN MB/s) - Connection closed at byte NNN. Retrying." */ | 1051 | /* GNU wget says "DATE TIME (NN MB/s) - Connection closed at byte NNN. Retrying." */ |
1052 | } | 1052 | } |
1053 | 1053 | ||
@@ -1381,7 +1381,7 @@ However, in real world it was observed that some web servers | |||
1381 | } | 1381 | } |
1382 | if (key == KEY_location && status >= 300) { | 1382 | if (key == KEY_location && status >= 300) { |
1383 | if (--redir_limit == 0) | 1383 | if (--redir_limit == 0) |
1384 | bb_error_msg_and_die("too many redirections"); | 1384 | bb_simple_error_msg_and_die("too many redirections"); |
1385 | fclose(sfp); | 1385 | fclose(sfp); |
1386 | if (str[0] == '/') { | 1386 | if (str[0] == '/') { |
1387 | free(redirected_path); | 1387 | free(redirected_path); |
diff --git a/networking/zcip.c b/networking/zcip.c index f95b6f7fb..134dfb2df 100644 --- a/networking/zcip.c +++ b/networking/zcip.c | |||
@@ -276,7 +276,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv) | |||
276 | if (inet_aton(l_opt, &net) == 0 | 276 | if (inet_aton(l_opt, &net) == 0 |
277 | || (net.s_addr & htonl(IN_CLASSB_NET)) != net.s_addr | 277 | || (net.s_addr & htonl(IN_CLASSB_NET)) != net.s_addr |
278 | ) { | 278 | ) { |
279 | bb_error_msg_and_die("invalid network address"); | 279 | bb_simple_error_msg_and_die("invalid network address"); |
280 | } | 280 | } |
281 | G.localnet_ip = ntohl(net.s_addr); | 281 | G.localnet_ip = ntohl(net.s_addr); |
282 | } | 282 | } |
@@ -285,7 +285,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv) | |||
285 | if (inet_aton(r_opt, &ip) == 0 | 285 | if (inet_aton(r_opt, &ip) == 0 |
286 | || (ntohl(ip.s_addr) & IN_CLASSB_NET) != G.localnet_ip | 286 | || (ntohl(ip.s_addr) & IN_CLASSB_NET) != G.localnet_ip |
287 | ) { | 287 | ) { |
288 | bb_error_msg_and_die("invalid link address"); | 288 | bb_simple_error_msg_and_die("invalid link address"); |
289 | } | 289 | } |
290 | chosen_nip = ip.s_addr; | 290 | chosen_nip = ip.s_addr; |
291 | } | 291 | } |
@@ -473,7 +473,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv) | |||
473 | 473 | ||
474 | // Read ARP packet | 474 | // Read ARP packet |
475 | if (safe_read(sock_fd, &p, sizeof(p)) < 0) { | 475 | if (safe_read(sock_fd, &p, sizeof(p)) < 0) { |
476 | bb_perror_msg_and_die(bb_msg_read_error); | 476 | bb_simple_perror_msg_and_die(bb_msg_read_error); |
477 | } | 477 | } |
478 | 478 | ||
479 | if (p.eth.ether_type != htons(ETHERTYPE_ARP)) | 479 | if (p.eth.ether_type != htons(ETHERTYPE_ARP)) |