summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-18 21:02:00 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-18 21:02:00 +0000
commitfcfe834d501b1bd0de45c7cb39ca0a259177934f (patch)
tree945faea9086418e09ada36d1fde1c02204f299e4 /networking
parent6dca70a04908f190c63ca76853ec2e7e0ea20c06 (diff)
downloadbusybox-w32-fcfe834d501b1bd0de45c7cb39ca0a259177934f.tar.gz
busybox-w32-fcfe834d501b1bd0de45c7cb39ca0a259177934f.tar.bz2
busybox-w32-fcfe834d501b1bd0de45c7cb39ca0a259177934f.zip
ifupdown: strlen(NULL) is a no-no, fixed. Also few micro-optimizations
Diffstat (limited to 'networking')
-rw-r--r--networking/ifupdown.c156
1 files changed, 76 insertions, 80 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 76ff2a830..93d7bc520 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -25,11 +25,11 @@
25#define EUNDEFVAR 10002 25#define EUNDEFVAR 10002
26#define EUNBALPER 10000 26#define EUNBALPER 10000
27 27
28#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING 28#if ENABLE_FEATURE_IFUPDOWN_MAPPING
29#define MAX_INTERFACE_LENGTH 10 29#define MAX_INTERFACE_LENGTH 10
30#endif 30#endif
31 31
32#define debug_noise(fmt, args...) 32#define debug_noise(args...) /*fprintf(stderr, args)*/
33 33
34/* Forward declaration */ 34/* Forward declaration */
35struct interface_defn_t; 35struct interface_defn_t;
@@ -109,7 +109,7 @@ static char *startup_PATH;
109 109
110#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6 110#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6
111 111
112#ifdef CONFIG_FEATURE_IFUPDOWN_IP 112#if ENABLE_FEATURE_IFUPDOWN_IP
113 113
114static unsigned count_bits(unsigned a) 114static unsigned count_bits(unsigned a)
115{ 115{
@@ -184,10 +184,10 @@ static char *get_var(const char *id, size_t idlen, struct interface_defn_t *ifd)
184 184
185static char *parse(const char *command, struct interface_defn_t *ifd) 185static char *parse(const char *command, struct interface_defn_t *ifd)
186{ 186{
187 char *result = NULL;
188 size_t old_pos[MAX_OPT_DEPTH] = { 0 }; 187 size_t old_pos[MAX_OPT_DEPTH] = { 0 };
189 int okay[MAX_OPT_DEPTH] = { 1 }; 188 int okay[MAX_OPT_DEPTH] = { 1 };
190 int opt_depth = 1; 189 int opt_depth = 1;
190 char *result = xstrdup("");
191 191
192 while (*command) { 192 while (*command) {
193 switch (*command) { 193 switch (*command) {
@@ -245,10 +245,10 @@ static char *parse(const char *command, struct interface_defn_t *ifd)
245 if (varvalue) { 245 if (varvalue) {
246 addstr(&result, varvalue, strlen(varvalue)); 246 addstr(&result, varvalue, strlen(varvalue));
247 } else { 247 } else {
248#ifdef CONFIG_FEATURE_IFUPDOWN_IP 248#if ENABLE_FEATURE_IFUPDOWN_IP
249 /* Sigh... Add a special case for 'ip' to convert from 249 /* Sigh... Add a special case for 'ip' to convert from
250 * dotted quad to bit count style netmasks. */ 250 * dotted quad to bit count style netmasks. */
251 if (strncmp(command, "bnmask", 6)==0) { 251 if (strncmp(command, "bnmask", 6) == 0) {
252 unsigned res; 252 unsigned res;
253 varvalue = get_var("netmask", 7, ifd); 253 varvalue = get_var("netmask", 7, ifd);
254 if (varvalue && (res = count_netmask_bits(varvalue)) > 0) { 254 if (varvalue && (res = count_netmask_bits(varvalue)) > 0) {
@@ -290,7 +290,7 @@ static int execute(const char *command, struct interface_defn_t *ifd, execfn *ex
290 int ret; 290 int ret;
291 291
292 out = parse(command, ifd); 292 out = parse(command, ifd);
293 if (!out) { 293 if (!out || !out[0]) {
294 return 0; 294 return 0;
295 } 295 }
296 ret = (*exec)(out); 296 ret = (*exec)(out);
@@ -303,10 +303,10 @@ static int execute(const char *command, struct interface_defn_t *ifd, execfn *ex
303} 303}
304#endif 304#endif
305 305
306#ifdef CONFIG_FEATURE_IFUPDOWN_IPV6 306#if ENABLE_FEATURE_IFUPDOWN_IPV6
307static int loopback_up6(struct interface_defn_t *ifd, execfn *exec) 307static int loopback_up6(struct interface_defn_t *ifd, execfn *exec)
308{ 308{
309#ifdef CONFIG_FEATURE_IFUPDOWN_IP 309#if ENABLE_FEATURE_IFUPDOWN_IP
310 int result; 310 int result;
311 result = execute("ip addr add ::1 dev %iface%", ifd, exec); 311 result = execute("ip addr add ::1 dev %iface%", ifd, exec);
312 result += execute("ip link set %iface% up", ifd, exec); 312 result += execute("ip link set %iface% up", ifd, exec);
@@ -318,7 +318,7 @@ static int loopback_up6(struct interface_defn_t *ifd, execfn *exec)
318 318
319static int loopback_down6(struct interface_defn_t *ifd, execfn *exec) 319static int loopback_down6(struct interface_defn_t *ifd, execfn *exec)
320{ 320{
321#ifdef CONFIG_FEATURE_IFUPDOWN_IP 321#if ENABLE_FEATURE_IFUPDOWN_IP
322 return execute("ip link set %iface% down", ifd, exec); 322 return execute("ip link set %iface% down", ifd, exec);
323#else 323#else
324 return execute("ifconfig %iface% del ::1", ifd, exec); 324 return execute("ifconfig %iface% del ::1", ifd, exec);
@@ -328,36 +328,37 @@ static int loopback_down6(struct interface_defn_t *ifd, execfn *exec)
328static int static_up6(struct interface_defn_t *ifd, execfn *exec) 328static int static_up6(struct interface_defn_t *ifd, execfn *exec)
329{ 329{
330 int result; 330 int result;
331#ifdef CONFIG_FEATURE_IFUPDOWN_IP 331#if ENABLE_FEATURE_IFUPDOWN_IP
332 result = execute("ip addr add %address%/%netmask% dev %iface% [[label %label%]]", ifd, exec); 332 result = execute("ip addr add %address%/%netmask% dev %iface%[[ label %label%]]", ifd, exec);
333 result += execute("ip link set [[mtu %mtu%]] [[address %hwaddress%]] %iface% up", ifd, exec); 333 result += execute("ip link set[[ mtu %mtu%]][[ address %hwaddress%]] %iface% up", ifd, exec);
334 result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec); 334 /* Was: "[[ ip ....%gateway% ]]". Removed extra spaces w/o checking */
335 result += execute("[[ip route add ::/0 via %gateway%]]", ifd, exec);
335#else 336#else
336 result = execute("ifconfig %iface% [[media %media%]] [[hw %hwaddress%]] [[mtu %mtu%]] up", ifd, exec); 337 result = execute("ifconfig %iface%[[ media %media%]][[ hw %hwaddress%]][[ mtu %mtu%]] up", ifd, exec);
337 result += execute("ifconfig %iface% add %address%/%netmask%", ifd, exec); 338 result += execute("ifconfig %iface% add %address%/%netmask%", ifd, exec);
338 result += execute("[[ route -A inet6 add ::/0 gw %gateway% ]]", ifd, exec); 339 result += execute("[[route -A inet6 add ::/0 gw %gateway%]]", ifd, exec);
339#endif 340#endif
340 return ((result == 3) ? 3 : 0); 341 return ((result == 3) ? 3 : 0);
341} 342}
342 343
343static int static_down6(struct interface_defn_t *ifd, execfn *exec) 344static int static_down6(struct interface_defn_t *ifd, execfn *exec)
344{ 345{
345#ifdef CONFIG_FEATURE_IFUPDOWN_IP 346#if ENABLE_FEATURE_IFUPDOWN_IP
346 return execute("ip link set %iface% down", ifd, exec); 347 return execute("ip link set %iface% down", ifd, exec);
347#else 348#else
348 return execute("ifconfig %iface% down", ifd, exec); 349 return execute("ifconfig %iface% down", ifd, exec);
349#endif 350#endif
350} 351}
351 352
352#ifdef CONFIG_FEATURE_IFUPDOWN_IP 353#if ENABLE_FEATURE_IFUPDOWN_IP
353static int v4tunnel_up(struct interface_defn_t *ifd, execfn *exec) 354static int v4tunnel_up(struct interface_defn_t *ifd, execfn *exec)
354{ 355{
355 int result; 356 int result;
356 result = execute("ip tunnel add %iface% mode sit remote " 357 result = execute("ip tunnel add %iface% mode sit remote "
357 "%endpoint% [[local %local%]] [[ttl %ttl%]]", ifd, exec); 358 "%endpoint%[[ local %local%]][[ ttl %ttl%]]", ifd, exec);
358 result += execute("ip link set %iface% up", ifd, exec); 359 result += execute("ip link set %iface% up", ifd, exec);
359 result += execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec); 360 result += execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec);
360 result += execute("[[ ip route add ::/0 via %gateway% ]]", ifd, exec); 361 result += execute("[[ip route add ::/0 via %gateway%]]", ifd, exec);
361 return ((result == 4) ? 4 : 0); 362 return ((result == 4) ? 4 : 0);
362} 363}
363 364
@@ -368,7 +369,7 @@ static int v4tunnel_down(struct interface_defn_t * ifd, execfn * exec)
368#endif 369#endif
369 370
370static const struct method_t methods6[] = { 371static const struct method_t methods6[] = {
371#ifdef CONFIG_FEATURE_IFUPDOWN_IP 372#if ENABLE_FEATURE_IFUPDOWN_IP
372 { "v4tunnel", v4tunnel_up, v4tunnel_down, }, 373 { "v4tunnel", v4tunnel_up, v4tunnel_down, },
373#endif 374#endif
374 { "static", static_up6, static_down6, }, 375 { "static", static_up6, static_down6, },
@@ -380,12 +381,12 @@ static const struct address_family_t addr_inet6 = {
380 sizeof(methods6) / sizeof(struct method_t), 381 sizeof(methods6) / sizeof(struct method_t),
381 methods6 382 methods6
382}; 383};
383#endif /* CONFIG_FEATURE_IFUPDOWN_IPV6 */ 384#endif /* FEATURE_IFUPDOWN_IPV6 */
384 385
385#ifdef CONFIG_FEATURE_IFUPDOWN_IPV4 386#if ENABLE_FEATURE_IFUPDOWN_IPV4
386static int loopback_up(struct interface_defn_t *ifd, execfn *exec) 387static int loopback_up(struct interface_defn_t *ifd, execfn *exec)
387{ 388{
388#ifdef CONFIG_FEATURE_IFUPDOWN_IP 389#if ENABLE_FEATURE_IFUPDOWN_IP
389 int result; 390 int result;
390 result = execute("ip addr add 127.0.0.1/8 dev %iface%", ifd, exec); 391 result = execute("ip addr add 127.0.0.1/8 dev %iface%", ifd, exec);
391 result += execute("ip link set %iface% up", ifd, exec); 392 result += execute("ip link set %iface% up", ifd, exec);
@@ -397,7 +398,7 @@ static int loopback_up(struct interface_defn_t *ifd, execfn *exec)
397 398
398static int loopback_down(struct interface_defn_t *ifd, execfn *exec) 399static int loopback_down(struct interface_defn_t *ifd, execfn *exec)
399{ 400{
400#ifdef CONFIG_FEATURE_IFUPDOWN_IP 401#if ENABLE_FEATURE_IFUPDOWN_IP
401 int result; 402 int result;
402 result = execute("ip addr flush dev %iface%", ifd, exec); 403 result = execute("ip addr flush dev %iface%", ifd, exec);
403 result += execute("ip link set %iface% down", ifd, exec); 404 result += execute("ip link set %iface% down", ifd, exec);
@@ -410,21 +411,21 @@ static int loopback_down(struct interface_defn_t *ifd, execfn *exec)
410static int static_up(struct interface_defn_t *ifd, execfn *exec) 411static int static_up(struct interface_defn_t *ifd, execfn *exec)
411{ 412{
412 int result; 413 int result;
413#ifdef CONFIG_FEATURE_IFUPDOWN_IP 414#if ENABLE_FEATURE_IFUPDOWN_IP
414 result = execute("ip addr add %address%/%bnmask% [[broadcast %broadcast%]] " 415 result = execute("ip addr add %address%/%bnmask%[[ broadcast %broadcast%]] "
415 "dev %iface% [[peer %pointopoint%]] [[label %label%]]", ifd, exec); 416 "dev %iface%[[ peer %pointopoint%]][[ label %label%]]", ifd, exec);
416 result += execute("ip link set [[mtu %mtu%]] [[address %hwaddress%]] %iface% up", ifd, exec); 417 result += execute("ip link set[[ mtu %mtu%]][[ address %hwaddress%]] %iface% up", ifd, exec);
417 result += execute("[[ ip route add default via %gateway% dev %iface% ]]", ifd, exec); 418 result += execute("[[ip route add default via %gateway% dev %iface%]]", ifd, exec);
418 return ((result == 3) ? 3 : 0); 419 return ((result == 3) ? 3 : 0);
419#else 420#else
420 /* ifconfig said to set iface up before it processes hw %hwaddress%, 421 /* ifconfig said to set iface up before it processes hw %hwaddress%,
421 * which then of course fails. Thus we run two separate ifconfig */ 422 * which then of course fails. Thus we run two separate ifconfig */
422 result = execute("ifconfig %iface% [[hw %hwaddress%]] [[media %media%]] [[mtu %mtu%]] up", 423 result = execute("ifconfig %iface%[[ hw %hwaddress%]][[ media %media%]][[ mtu %mtu%]] up",
423 ifd, exec); 424 ifd, exec);
424 result += execute("ifconfig %iface% %address% netmask %netmask% " 425 result += execute("ifconfig %iface% %address% netmask %netmask%"
425 "[[broadcast %broadcast%]] [[pointopoint %pointopoint%]] ", 426 "[[ broadcast %broadcast%]][[ pointopoint %pointopoint%]] ",
426 ifd, exec); 427 ifd, exec);
427 result += execute("[[ route add default gw %gateway% %iface% ]]", ifd, exec); 428 result += execute("[[route add default gw %gateway% %iface%]]", ifd, exec);
428 return ((result == 3) ? 3 : 0); 429 return ((result == 3) ? 3 : 0);
429#endif 430#endif
430} 431}
@@ -432,17 +433,17 @@ static int static_up(struct interface_defn_t *ifd, execfn *exec)
432static int static_down(struct interface_defn_t *ifd, execfn *exec) 433static int static_down(struct interface_defn_t *ifd, execfn *exec)
433{ 434{
434 int result; 435 int result;
435#ifdef CONFIG_FEATURE_IFUPDOWN_IP 436#if ENABLE_FEATURE_IFUPDOWN_IP
436 result = execute("ip addr flush dev %iface%", ifd, exec); 437 result = execute("ip addr flush dev %iface%", ifd, exec);
437 result += execute("ip link set %iface% down", ifd, exec); 438 result += execute("ip link set %iface% down", ifd, exec);
438#else 439#else
439 result = execute("[[ route del default gw %gateway% %iface% ]]", ifd, exec); 440 result = execute("[[route del default gw %gateway% %iface%]]", ifd, exec);
440 result += execute("ifconfig %iface% down", ifd, exec); 441 result += execute("ifconfig %iface% down", ifd, exec);
441#endif 442#endif
442 return ((result == 2) ? 2 : 0); 443 return ((result == 2) ? 2 : 0);
443} 444}
444 445
445#ifndef CONFIG_APP_UDHCPC 446#if !ENABLE_APP_UDHCPC
446struct dhcp_client_t 447struct dhcp_client_t
447{ 448{
448 const char *name; 449 const char *name;
@@ -452,11 +453,11 @@ struct dhcp_client_t
452 453
453static const struct dhcp_client_t ext_dhcp_clients[] = { 454static const struct dhcp_client_t ext_dhcp_clients[] = {
454 { "udhcpc", 455 { "udhcpc",
455 "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface% [[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]", 456 "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]]",
456 "kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", 457 "kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
457 }, 458 },
458 { "pump", 459 { "pump",
459 "pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]", 460 "pump -i %iface%[[ -h %hostname%]][[ -l %leasehours%]]",
460 "pump -i %iface% -k", 461 "pump -i %iface% -k",
461 }, 462 },
462 { "dhclient", 463 { "dhclient",
@@ -464,7 +465,7 @@ static const struct dhcp_client_t ext_dhcp_clients[] = {
464 "kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", 465 "kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null",
465 }, 466 },
466 { "dhcpcd", 467 { "dhcpcd",
467 "dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] [[-l %leasetime%]] %iface%", 468 "dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %clientid%]][[ -l %leasetime%]] %iface%",
468 "dhcpcd -k %iface%", 469 "dhcpcd -k %iface%",
469 }, 470 },
470}; 471};
@@ -472,9 +473,9 @@ static const struct dhcp_client_t ext_dhcp_clients[] = {
472 473
473static int dhcp_up(struct interface_defn_t *ifd, execfn *exec) 474static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
474{ 475{
475#ifdef CONFIG_APP_UDHCPC 476#if ENABLE_APP_UDHCPC
476 return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid " 477 return execute("udhcpc -R -n -p /var/run/udhcpc.%iface%.pid "
477 "-i %iface% [[-H %hostname%]] [[-c %clientid%]] [[-s %script%]]", 478 "-i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]]",
478 ifd, exec); 479 ifd, exec);
479#else 480#else
480 int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]); 481 int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
@@ -489,7 +490,7 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
489 490
490static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) 491static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
491{ 492{
492#ifdef CONFIG_APP_UDHCPC 493#if ENABLE_APP_UDHCPC
493 return execute("kill -TERM " 494 return execute("kill -TERM "
494 "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); 495 "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
495#else 496#else
@@ -510,30 +511,30 @@ static int manual_up_down(struct interface_defn_t *ifd, execfn *exec)
510 511
511static int bootp_up(struct interface_defn_t *ifd, execfn *exec) 512static int bootp_up(struct interface_defn_t *ifd, execfn *exec)
512{ 513{
513 return execute("bootpc [[--bootfile %bootfile%]] --dev %iface% " 514 return execute("bootpc[[ --bootfile %bootfile%]] --dev %iface%"
514 "[[--server %server%]] [[--hwaddr %hwaddr%]] " 515 "[[ --server %server%]][[ --hwaddr %hwaddr%]] "
515 "--returniffail --serverbcast", ifd, exec); 516 "--returniffail --serverbcast", ifd, exec);
516} 517}
517 518
518static int ppp_up(struct interface_defn_t *ifd, execfn *exec) 519static int ppp_up(struct interface_defn_t *ifd, execfn *exec)
519{ 520{
520 return execute("pon [[%provider%]]", ifd, exec); 521 return execute("pon[[ %provider%]]", ifd, exec);
521} 522}
522 523
523static int ppp_down(struct interface_defn_t *ifd, execfn *exec) 524static int ppp_down(struct interface_defn_t *ifd, execfn *exec)
524{ 525{
525 return execute("poff [[%provider%]]", ifd, exec); 526 return execute("poff[[ %provider%]]", ifd, exec);
526} 527}
527 528
528static int wvdial_up(struct interface_defn_t *ifd, execfn *exec) 529static int wvdial_up(struct interface_defn_t *ifd, execfn *exec)
529{ 530{
530 return execute("/sbin/start-stop-daemon --start -x /usr/bin/wvdial " 531 return execute("start-stop-daemon --start -x wvdial "
531 "-p /var/run/wvdial.%iface% -b -m -- [[ %provider% ]]", ifd, exec); 532 "-p /var/run/wvdial.%iface% -b -m --[[ %provider%]]", ifd, exec);
532} 533}
533 534
534static int wvdial_down(struct interface_defn_t *ifd, execfn *exec) 535static int wvdial_down(struct interface_defn_t *ifd, execfn *exec)
535{ 536{
536 return execute("/sbin/start-stop-daemon --stop -x /usr/bin/wvdial " 537 return execute("start-stop-daemon --stop -x wvdial "
537 "-p /var/run/wvdial.%iface% -s 2", ifd, exec); 538 "-p /var/run/wvdial.%iface% -s 2", ifd, exec);
538} 539}
539 540
@@ -553,7 +554,7 @@ static const struct address_family_t addr_inet = {
553 methods 554 methods
554}; 555};
555 556
556#endif /* ifdef CONFIG_FEATURE_IFUPDOWN_IPV4 */ 557#endif /* if ENABLE_FEATURE_IFUPDOWN_IPV4 */
557 558
558static char *next_word(char **buf) 559static char *next_word(char **buf)
559{ 560{
@@ -633,7 +634,7 @@ static const llist_t *find_list_string(const llist_t *list, const char *string)
633 634
634static struct interfaces_file_t *read_interfaces(const char *filename) 635static struct interfaces_file_t *read_interfaces(const char *filename)
635{ 636{
636#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING 637#if ENABLE_FEATURE_IFUPDOWN_MAPPING
637 struct mapping_defn_t *currmap = NULL; 638 struct mapping_defn_t *currmap = NULL;
638#endif 639#endif
639 struct interface_defn_t *currif = NULL; 640 struct interface_defn_t *currif = NULL;
@@ -658,7 +659,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
658 } 659 }
659 660
660 if (strcmp(firstword, "mapping") == 0) { 661 if (strcmp(firstword, "mapping") == 0) {
661#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING 662#if ENABLE_FEATURE_IFUPDOWN_MAPPING
662 currmap = xzalloc(sizeof(struct mapping_defn_t)); 663 currmap = xzalloc(sizeof(struct mapping_defn_t));
663 664
664 while ((firstword = next_word(&buf_ptr)) != NULL) { 665 while ((firstword = next_word(&buf_ptr)) != NULL) {
@@ -686,10 +687,10 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
686 currently_processing = MAPPING; 687 currently_processing = MAPPING;
687 } else if (strcmp(firstword, "iface") == 0) { 688 } else if (strcmp(firstword, "iface") == 0) {
688 static const struct address_family_t *const addr_fams[] = { 689 static const struct address_family_t *const addr_fams[] = {
689#ifdef CONFIG_FEATURE_IFUPDOWN_IPV4 690#if ENABLE_FEATURE_IFUPDOWN_IPV4
690 &addr_inet, 691 &addr_inet,
691#endif 692#endif
692#ifdef CONFIG_FEATURE_IFUPDOWN_IPV6 693#if ENABLE_FEATURE_IFUPDOWN_IPV6
693 &addr_inet6, 694 &addr_inet6,
694#endif 695#endif
695 NULL 696 NULL
@@ -802,7 +803,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
802 currif->n_options++; 803 currif->n_options++;
803 break; 804 break;
804 case MAPPING: 805 case MAPPING:
805#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING 806#if ENABLE_FEATURE_IFUPDOWN_MAPPING
806 if (strcmp(firstword, "script") == 0) { 807 if (strcmp(firstword, "script") == 0) {
807 if (currmap->script != NULL) { 808 if (currmap->script != NULL) {
808 bb_error_msg("duplicate script in mapping \"%s\"", buf); 809 bb_error_msg("duplicate script in mapping \"%s\"", buf);
@@ -908,9 +909,9 @@ static int doit(char *str)
908 909
909 fflush(NULL); 910 fflush(NULL);
910 switch (child = fork()) { 911 switch (child = fork()) {
911 case -1: /* failure */ 912 case -1: /* failure */
912 return 0; 913 return 0;
913 case 0: /* child */ 914 case 0: /* child */
914 execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, NULL, __myenviron); 915 execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, NULL, __myenviron);
915 exit(127); 916 exit(127);
916 } 917 }
@@ -941,13 +942,14 @@ static int execute_all(struct interface_defn_t *ifd, const char *opt)
941 return 1; 942 return 1;
942} 943}
943 944
944static int check(char *str) { 945static int check(char *str)
946{
945 return str != NULL; 947 return str != NULL;
946} 948}
947 949
948static int iface_up(struct interface_defn_t *iface) 950static int iface_up(struct interface_defn_t *iface)
949{ 951{
950 if (!iface->method->up(iface,check)) return -1; 952 if (!iface->method->up(iface, check)) return -1;
951 set_environ(iface, "start"); 953 set_environ(iface, "start");
952 if (!execute_all(iface, "pre-up")) return 0; 954 if (!execute_all(iface, "pre-up")) return 0;
953 if (!iface->method->up(iface, doit)) return 0; 955 if (!iface->method->up(iface, doit)) return 0;
@@ -965,7 +967,7 @@ static int iface_down(struct interface_defn_t *iface)
965 return 1; 967 return 1;
966} 968}
967 969
968#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING 970#if ENABLE_FEATURE_IFUPDOWN_MAPPING
969static int popen2(FILE **in, FILE **out, char *command, ...) 971static int popen2(FILE **in, FILE **out, char *command, ...)
970{ 972{
971 va_list ap; 973 va_list ap;
@@ -1069,7 +1071,7 @@ static char *run_mapping(char *physical, struct mapping_defn_t * map)
1069 1071
1070 return logical; 1072 return logical;
1071} 1073}
1072#endif /* CONFIG_FEATURE_IFUPDOWN_MAPPING */ 1074#endif /* FEATURE_IFUPDOWN_MAPPING */
1073 1075
1074static llist_t *find_iface_state(llist_t *state_list, const char *iface) 1076static llist_t *find_iface_state(llist_t *state_list, const char *iface)
1075{ 1077{
@@ -1088,8 +1090,6 @@ static llist_t *find_iface_state(llist_t *state_list, const char *iface)
1088 1090
1089int ifupdown_main(int argc, char **argv) 1091int ifupdown_main(int argc, char **argv)
1090{ 1092{
1091 static const char statefile[] = "/var/run/ifstate";
1092
1093 int (*cmds)(struct interface_defn_t *) = NULL; 1093 int (*cmds)(struct interface_defn_t *) = NULL;
1094 struct interfaces_file_t *defn; 1094 struct interfaces_file_t *defn;
1095 llist_t *state_list = NULL; 1095 llist_t *state_list = NULL;
@@ -1097,26 +1097,25 @@ int ifupdown_main(int argc, char **argv)
1097 const char *interfaces = "/etc/network/interfaces"; 1097 const char *interfaces = "/etc/network/interfaces";
1098 int any_failures = 0; 1098 int any_failures = 0;
1099 1099
1100 cmds = iface_down;
1100 if (applet_name[2] == 'u') { 1101 if (applet_name[2] == 'u') {
1101 /* ifup command */ 1102 /* ifup command */
1102 cmds = iface_up; 1103 cmds = iface_up;
1103 } else {
1104 /* ifdown command */
1105 cmds = iface_down;
1106 } 1104 }
1107 1105
1108 getopt32(argc, argv, OPTION_STR, &interfaces); 1106 getopt32(argc, argv, OPTION_STR, &interfaces);
1109 if (argc - optind > 0) { 1107 if (argc - optind > 0) {
1110 if (DO_ALL) bb_show_usage(); 1108 if (DO_ALL) bb_show_usage();
1111 } else 1109 } else {
1112 if (!DO_ALL) bb_show_usage(); 1110 if (!DO_ALL) bb_show_usage();
1111 }
1113 1112
1114 debug_noise("reading %s file:\n", interfaces); 1113 debug_noise("reading %s file:\n", interfaces);
1115 defn = read_interfaces(interfaces); 1114 defn = read_interfaces(interfaces);
1116 debug_noise("\ndone reading %s\n\n", interfaces); 1115 debug_noise("\ndone reading %s\n\n", interfaces);
1117 1116
1118 if (!defn) { 1117 if (!defn) {
1119 exit(EXIT_FAILURE); 1118 return EXIT_FAILURE;
1120 } 1119 }
1121 1120
1122 startup_PATH = getenv("PATH"); 1121 startup_PATH = getenv("PATH");
@@ -1179,7 +1178,7 @@ int ifupdown_main(int argc, char **argv)
1179 } 1178 }
1180 } 1179 }
1181 1180
1182#ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING 1181#if ENABLE_FEATURE_IFUPDOWN_MAPPING
1183 if ((cmds == iface_up) && !NO_MAPPINGS) { 1182 if ((cmds == iface_up) && !NO_MAPPINGS) {
1184 struct mapping_defn_t *currmap; 1183 struct mapping_defn_t *currmap;
1185 1184
@@ -1198,7 +1197,6 @@ int ifupdown_main(int argc, char **argv)
1198 } 1197 }
1199#endif 1198#endif
1200 1199
1201
1202 iface_list = defn->ifaces; 1200 iface_list = defn->ifaces;
1203 while (iface_list) { 1201 while (iface_list) {
1204 currif = (struct interface_defn_t *) iface_list->data; 1202 currif = (struct interface_defn_t *) iface_list->data;
@@ -1208,16 +1206,16 @@ int ifupdown_main(int argc, char **argv)
1208 okay = 1; 1206 okay = 1;
1209 currif->iface = iface; 1207 currif->iface = iface;
1210 1208
1211 debug_noise("\nConfiguring interface %s (%s)\n", liface, currif->address_family->name); 1209 debug_noise("\nZ Configuring interface %s (%s)\n", liface, currif->address_family->name);
1212 1210
1213 /* Call the cmds function pointer, does either iface_up() or iface_down() */ 1211 /* Call the cmds function pointer, does either iface_up() or iface_down() */
1214 cmds_ret = cmds(currif); 1212 cmds_ret = cmds(currif);
1215 if (cmds_ret == -1) { 1213 if (cmds_ret == -1) {
1216 bb_error_msg("don't seem to have all the variables for %s/%s", 1214 bb_error_msg("don't seem to have all the variables for %s/%s",
1217 liface, currif->address_family->name); 1215 liface, currif->address_family->name);
1218 any_failures += 1; 1216 any_failures = 1;
1219 } else if (cmds_ret == 0) { 1217 } else if (cmds_ret == 0) {
1220 any_failures += 1; 1218 any_failures = 1;
1221 } 1219 }
1222 1220
1223 currif->iface = oldiface; 1221 currif->iface = oldiface;
@@ -1230,7 +1228,7 @@ int ifupdown_main(int argc, char **argv)
1230 1228
1231 if (!okay && !FORCE) { 1229 if (!okay && !FORCE) {
1232 bb_error_msg("ignoring unknown interface %s", liface); 1230 bb_error_msg("ignoring unknown interface %s", liface);
1233 any_failures += 1; 1231 any_failures = 1;
1234 } else { 1232 } else {
1235 llist_t *iface_state = find_iface_state(state_list, iface); 1233 llist_t *iface_state = find_iface_state(state_list, iface);
1236 1234
@@ -1251,9 +1249,9 @@ int ifupdown_main(int argc, char **argv)
1251 1249
1252 /* Actually write the new state */ 1250 /* Actually write the new state */
1253 if (!NO_ACT) { 1251 if (!NO_ACT) {
1254 FILE *state_fp = NULL; 1252 FILE *state_fp;
1255 1253
1256 state_fp = xfopen(statefile, "w"); 1254 state_fp = xfopen("/var/run/ifstate", "w");
1257 while (state_list) { 1255 while (state_list) {
1258 if (state_list->data) { 1256 if (state_list->data) {
1259 fputs(state_list->data, state_fp); 1257 fputs(state_list->data, state_fp);
@@ -1264,7 +1262,5 @@ int ifupdown_main(int argc, char **argv)
1264 fclose(state_fp); 1262 fclose(state_fp);
1265 } 1263 }
1266 1264
1267 if (any_failures) 1265 return any_failures;
1268 return 1;
1269 return 0;
1270} 1266}