udhcp and busybox
Devin Bayer
devin at freeshell.org
Tue Mar 28 14:38:55 PST 2006
Rob Landley wrote:
> On Monday 27 March 2006 5:04 pm, Devin Bayer wrote:
>
>>>Even the common case of a router wouldn't need this, because you only run
>>>the dhcp _client_ on one interface.
>>
>>In the common case of a router, you do need this. If you have a running
>>system with a gateway and then run udhcpc, it'll create two gateways and
>>knock your system off all the networks.
>>
>>Well, that's all I have to say; I won't argue anymore.
>
> It must remove the existing default gateway (if any) when adding a new default
> gateway, yes. Since you can only have one default gateway (this would be
> what "default" means), the route command should do this for a "route add
> default gw" invocation.
OK, that's good. It works. FYI, it differs from the net-tools route behavior.
Just to be clear, you are saying the new udhcpc will use the route command?
Here is my patch to route. Before adding a gateway, it deletes all other gateways
with the same target network. Tested in linux 2.6.11.
text data bss dec hex filename
2255 0 0 2255 8cf networking/route-orig.o
2255 0 0 2255 8cf networking/route-new.o
2466 0 0 2466 9a2 networking/route-nodupes.o
--
Devin Bayer
-------------- next part --------------
Index: networking/route.c
===================================================================
--- networking/route.c (revision 14682)
+++ networking/route.c (working copy)
@@ -342,6 +342,20 @@
bb_perror_msg_and_die("socket");
}
+ /* Only allow a single default route */
+ if (ENABLE_FEATURE_ROUTE_NO_DUPES && rt.rt_flags & RTF_GATEWAY)
+ {
+ struct rtentry remover = {
+ .rt_dst = rt.rt_dst,
+ .rt_genmask = rt.rt_genmask,
+ .rt_flags = rt.rt_flags & (RTF_HOST|RTF_UP)
+ };
+
+ while(0 <= ioctl(skfd, SIOCDELRT, &remover)) {
+ /* delete all of them */;
+ }
+ }
+
if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
}
Index: networking/Config.in
===================================================================
--- networking/Config.in (revision 14682)
+++ networking/Config.in (working copy)
@@ -508,6 +508,15 @@
help
Route displays or manipulates the kernel's IP routing tables.
+config CONFIG_FEATURE_ROUTE_NO_DUPES
+ bool " Delete duplicate routes before adding a new route"
+ default y
+ depends on CONFIG_ROUTE
+ help
+ Linux allows multiple routes for a single destination network,
+ but they can't be used because Linux may then mis-route packets.
+ This feature doesn't let the route command create these dupes.
+
config CONFIG_TELNET
bool "telnet"
default n
More information about the busybox
mailing list