summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-11 22:16:56 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-11 22:16:56 +0000
commitf6f43df60bbd69ae5ea83b9012beb953a2baf116 (patch)
tree80c51cd39201fcffaa9537c5abd1b10da3811ad0 /networking
parent8de82bf84f7311bd74b08d9f4b4d4a6fef4649b9 (diff)
downloadbusybox-w32-f6f43df60bbd69ae5ea83b9012beb953a2baf116.tar.gz
busybox-w32-f6f43df60bbd69ae5ea83b9012beb953a2baf116.tar.bz2
busybox-w32-f6f43df60bbd69ae5ea83b9012beb953a2baf116.zip
ifupdown: stop emitting annoying/misleading error messages.
Patch by Gabriel Somlo <somlo at cmu.edu>
Diffstat (limited to 'networking')
-rw-r--r--networking/ifupdown.c88
1 files changed, 55 insertions, 33 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index f572b487d..c1dc1d35d 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -133,7 +133,7 @@ static int count_netmask_bits(char *dotted_quad)
133} 133}
134#endif 134#endif
135 135
136static void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t str_length) 136static void addstr(char **buf, size_t *len, size_t *pos, const char *str, size_t str_length)
137{ 137{
138 if (*pos + str_length >= *len) { 138 if (*pos + str_length >= *len) {
139 char *newbuf; 139 char *newbuf;
@@ -150,7 +150,7 @@ static void addstr(char **buf, size_t *len, size_t *pos, char *str, size_t str_l
150 (*buf)[*pos] = '\0'; 150 (*buf)[*pos] = '\0';
151} 151}
152 152
153static int strncmpz(char *l, char *r, size_t llen) 153static int strncmpz(const char *l, const char *r, size_t llen)
154{ 154{
155 int i = strncmp(l, r, llen); 155 int i = strncmp(l, r, llen);
156 156
@@ -161,7 +161,7 @@ static int strncmpz(char *l, char *r, size_t llen)
161 } 161 }
162} 162}
163 163
164static char *get_var(char *id, size_t idlen, struct interface_defn_t *ifd) 164static char *get_var(const char *id, size_t idlen, struct interface_defn_t *ifd)
165{ 165{
166 int i; 166 int i;
167 167
@@ -188,7 +188,7 @@ static char *get_var(char *id, size_t idlen, struct interface_defn_t *ifd)
188 return NULL; 188 return NULL;
189} 189}
190 190
191static char *parse(char *command, struct interface_defn_t *ifd) 191static char *parse(const char *command, struct interface_defn_t *ifd)
192{ 192{
193 193
194 char *result = NULL; 194 char *result = NULL;
@@ -294,7 +294,7 @@ static char *parse(char *command, struct interface_defn_t *ifd)
294} 294}
295 295
296/* execute() returns 1 for success and 0 for failure */ 296/* execute() returns 1 for success and 0 for failure */
297static int execute(char *command, struct interface_defn_t *ifd, execfn *exec) 297static int execute(const char *command, struct interface_defn_t *ifd, execfn *exec)
298{ 298{
299 char *out; 299 char *out;
300 int ret; 300 int ret;
@@ -449,43 +449,65 @@ static int static_down(struct interface_defn_t *ifd, execfn *exec)
449 return ((result == 2) ? 2 : 0); 449 return ((result == 2) ? 2 : 0);
450} 450}
451 451
452static int dhcp_up(struct interface_defn_t *ifd, execfn *exec) 452#ifndef CONFIG_APP_UDHCPC
453struct dhcp_client_t
453{ 454{
454 if (execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface% " 455 const char *name;
455 "[[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]", ifd, exec)) 456 const char *startcmd;
456 return 1; 457 const char *stopcmd;
457 458};
458 /* 2006-09-30: The following are deprecated, and should eventually be
459 * removed. For non-busybox (i.e., other than udhcpc) clients, use
460 * 'iface foo inet manual' in /etc/network/interfaces, and supply
461 * start/stop commands explicitly via up/down. */
462 459
463 if (execute("pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]", 460static const struct dhcp_client_t ext_dhcp_clients[] = {
464 ifd, exec)) return 1; 461 { "udhcpc",
465 if (execute("dhclient -pf /var/run/dhclient.%iface%.pid %iface%", 462 "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface% [[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]",
466 ifd, exec)) return 1; 463 "kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
467 if (execute("dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] " 464 },
468 "[[-l %leasetime%]] %iface%", ifd, exec)) return 1; 465 { "pump",
466 "pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]",
467 "pump -i %iface% -k",
468 },
469 { "dhclient",
470 "dhclient -pf /var/run/dhclient.%iface%.pid %iface%",
471 "kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null",
472 },
473 { "dhcpcd",
474 "dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] [[-l %leasetime%]] %iface%",
475 "dhcpcd -k %iface%",
476 },
477};
478#endif
469 479
480static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
481{
482#ifdef CONFIG_APP_UDHCPC
483 return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid "
484 "-i %iface% [[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]",
485 ifd, exec);
486#else
487 int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
488 for (i = 0; i < nclients; i++) {
489 if (exists_execable(ext_dhcp_clients[i].name))
490 return execute(ext_dhcp_clients[i].startcmd, ifd, exec);
491 }
492 bb_error_msg("no dhcp clients found");
470 return 0; 493 return 0;
494#endif
471} 495}
472 496
473static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) 497static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
474{ 498{
475 if (execute("kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", 499#ifdef CONFIG_APP_UDHCPC
476 ifd, exec)) return 1; 500 return execute("kill -TERM "
477 501 "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
478 /* 2006-09-30: The following are deprecated, and should eventually be 502#else
479 * removed. For non-busybox (i.e., other than udhcpc) clients, use 503 int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
480 * 'iface foo inet manual' in /etc/network/interfaces, and supply 504 for (i = 0; i < nclients; i++) {
481 * start/stop commands explicitly via up/down. */ 505 if (exists_execable(ext_dhcp_clients[i].name))
482 506 return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
483 if (execute("pump -i %iface% -k", ifd, exec)) return 1; 507 }
484 if (execute("kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", 508 bb_error_msg("no dhcp clients found, using static interface shutdown");
485 ifd, exec)) return 1;
486 if (execute("dhcpcd -k %iface%", ifd, exec)) return 1;
487
488 return static_down(ifd, exec); 509 return static_down(ifd, exec);
510#endif
489} 511}
490 512
491static int manual_up_down(struct interface_defn_t *ifd, execfn *exec) 513static int manual_up_down(struct interface_defn_t *ifd, execfn *exec)