diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-19 23:02:23 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-19 23:02:23 +0000 |
commit | 6c4eb4411305f61b3f96eefe0ebb147c7f8e6c6d (patch) | |
tree | 0ae606ef45a127129680a9bd2eb5e187f664f9b8 | |
parent | 625ed8e027e703c06a82bfbb8b4e8fd4876c7779 (diff) | |
download | busybox-w32-6c4eb4411305f61b3f96eefe0ebb147c7f8e6c6d.tar.gz busybox-w32-6c4eb4411305f61b3f96eefe0ebb147c7f8e6c6d.tar.bz2 busybox-w32-6c4eb4411305f61b3f96eefe0ebb147c7f8e6c6d.zip |
ifupdown: fixes for shutdown of DHCP-managed interfaces
from Wade Berrier <wberrier AT gmail.com>
-rw-r--r-- | networking/ifupdown.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 0f90102f0..c232d86a6 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -456,7 +456,10 @@ static int static_down(struct interface_defn_t *ifd, execfn *exec) | |||
456 | result = execute("ip addr flush dev %iface%", ifd, exec); | 456 | result = execute("ip addr flush dev %iface%", ifd, exec); |
457 | result += execute("ip link set %iface% down", ifd, exec); | 457 | result += execute("ip link set %iface% down", ifd, exec); |
458 | #else | 458 | #else |
459 | result = execute("[[route del default gw %gateway% %iface%]]", ifd, exec); | 459 | /* result = execute("[[route del default gw %gateway% %iface%]]", ifd, exec); */ |
460 | /* Bringing the interface down deletes the routes in itself. | ||
461 | Otherwise this fails if we reference 'gateway' when using this from dhcp_down */ | ||
462 | result = 1; | ||
460 | result += execute("ifconfig %iface% down", ifd, exec); | 463 | result += execute("ifconfig %iface% down", ifd, exec); |
461 | #endif | 464 | #endif |
462 | return ((result == 2) ? 2 : 0); | 465 | return ((result == 2) ? 2 : 0); |
@@ -538,19 +541,40 @@ static int dhcp_up(struct interface_defn_t *ifd UNUSED_PARAM, | |||
538 | #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP | 541 | #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP |
539 | static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) | 542 | static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) |
540 | { | 543 | { |
544 | int result = 0; | ||
541 | unsigned i; | 545 | unsigned i; |
546 | |||
542 | for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { | 547 | for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { |
543 | if (exists_execable(ext_dhcp_clients[i].name)) | 548 | if (exists_execable(ext_dhcp_clients[i].name)) { |
544 | return execute(ext_dhcp_clients[i].stopcmd, ifd, exec); | 549 | result += execute(ext_dhcp_clients[i].stopcmd, ifd, exec); |
550 | if (result) | ||
551 | break; | ||
552 | } | ||
545 | } | 553 | } |
546 | bb_error_msg("no dhcp clients found, using static interface shutdown"); | 554 | |
547 | return static_down(ifd, exec); | 555 | if (!result) |
556 | bb_error_msg("warning: no dhcp clients found and stopped"); | ||
557 | |||
558 | /* Sleep a bit, otherwise static_down tries to bring down interface too soon, | ||
559 | and it may come back up because udhcpc is still shutting down */ | ||
560 | usleep(100000); | ||
561 | result += static_down(ifd, exec); | ||
562 | return ((result == 3) ? 3 : 0); | ||
548 | } | 563 | } |
549 | #elif ENABLE_APP_UDHCPC | 564 | #elif ENABLE_APP_UDHCPC |
550 | static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) | 565 | static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) |
551 | { | 566 | { |
552 | return execute("kill " | 567 | int result; |
568 | result = execute("kill " | ||
553 | "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); | 569 | "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); |
570 | /* Also bring the hardware interface down since | ||
571 | killing the dhcp client alone doesn't do it. | ||
572 | This enables consecutive ifup->ifdown->ifup */ | ||
573 | /* Sleep a bit, otherwise static_down tries to bring down interface too soon, | ||
574 | and it may come back up because udhcpc is still shutting down */ | ||
575 | usleep(100000); | ||
576 | result += static_down(ifd, exec); | ||
577 | return ((result == 3) ? 3 : 0); | ||
554 | } | 578 | } |
555 | #else | 579 | #else |
556 | static int dhcp_down(struct interface_defn_t *ifd UNUSED_PARAM, | 580 | static int dhcp_down(struct interface_defn_t *ifd UNUSED_PARAM, |