summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko2008-08-19 23:02:23 +0000
committerDenis Vlasenko2008-08-19 23:02:23 +0000
commit6c4eb4411305f61b3f96eefe0ebb147c7f8e6c6d (patch)
tree0ae606ef45a127129680a9bd2eb5e187f664f9b8 /networking
parent625ed8e027e703c06a82bfbb8b4e8fd4876c7779 (diff)
downloadbusybox-6c4eb4411305f61b3f96eefe0ebb147c7f8e6c6d.zip
busybox-6c4eb4411305f61b3f96eefe0ebb147c7f8e6c6d.tar.gz
ifupdown: fixes for shutdown of DHCP-managed interfaces
from Wade Berrier <wberrier AT gmail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/ifupdown.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 0f90102..c232d86 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -456,7 +456,10 @@ static int static_down(struct interface_defn_t *ifd, execfn *exec)
result = execute("ip addr flush dev %iface%", ifd, exec);
result += execute("ip link set %iface% down", ifd, exec);
#else
- result = execute("[[route del default gw %gateway% %iface%]]", ifd, exec);
+ /* result = execute("[[route del default gw %gateway% %iface%]]", ifd, exec); */
+ /* Bringing the interface down deletes the routes in itself.
+ Otherwise this fails if we reference 'gateway' when using this from dhcp_down */
+ result = 1;
result += execute("ifconfig %iface% down", ifd, exec);
#endif
return ((result == 2) ? 2 : 0);
@@ -538,19 +541,40 @@ static int dhcp_up(struct interface_defn_t *ifd UNUSED_PARAM,
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
{
+ int result = 0;
unsigned i;
+
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
- if (exists_execable(ext_dhcp_clients[i].name))
- return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
+ if (exists_execable(ext_dhcp_clients[i].name)) {
+ result += execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
+ if (result)
+ break;
+ }
}
- bb_error_msg("no dhcp clients found, using static interface shutdown");
- return static_down(ifd, exec);
+
+ if (!result)
+ bb_error_msg("warning: no dhcp clients found and stopped");
+
+ /* Sleep a bit, otherwise static_down tries to bring down interface too soon,
+ and it may come back up because udhcpc is still shutting down */
+ usleep(100000);
+ result += static_down(ifd, exec);
+ return ((result == 3) ? 3 : 0);
}
#elif ENABLE_APP_UDHCPC
static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
{
- return execute("kill "
+ int result;
+ result = execute("kill "
"`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
+ /* Also bring the hardware interface down since
+ killing the dhcp client alone doesn't do it.
+ This enables consecutive ifup->ifdown->ifup */
+ /* Sleep a bit, otherwise static_down tries to bring down interface too soon,
+ and it may come back up because udhcpc is still shutting down */
+ usleep(100000);
+ result += static_down(ifd, exec);
+ return ((result == 3) ? 3 : 0);
}
#else
static int dhcp_down(struct interface_defn_t *ifd UNUSED_PARAM,