On Thu, 2008-08-07 at 15:15 -0600, Wade Berrier wrote:
> Hi,
>
> According to: http://www.annodex.net/cgi-bin/man/man2html?interfaces
>
> it is possible to set a custom mac address when using dhcp.
>
> The attached patch allows this for both 'ifconfig' and 'ip'.
>
> Wade
Also is attached a patch to make 'ifdown' work.
Without this patch, ifdown doesn't bring down the interface. So when do
you ifup after running ifdown, it tries to set the hwaddress and thus
fails.
This patch calls static_down in dhcp_down in order to properly bring
down the interface.
(Side note: I had to sleep for a bit because it appeared that bringing
down the interface too soon brought it right back up presumptuously
because udhcpc was still in the process of shutting down).
Wade
Index: busybox/networking/ifupdown.c
===================================================================
--- busybox/networking/ifupdown.c (revision 23082)
+++ busybox/networking/ifupdown.c (working copy)
@@ -456,7 +456,10 @@
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,37 @@
#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 (0 == result)
+ bb_error_msg("warning: no dhcp clients found and stopped");
+
+ 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 will 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,
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox