hello,
here is a patch that makes dhclient modify the routes on the routing table
corresponding to the routing domain of the interface it is working on.
does it looks like something correct ?
the routing domain could be fetched directly from the dhclient-script, but i
don't know how to do that with the tools avalaible in /bin and /sbin. and the
current dhclient-script behavior is only to execute orders, not to fetch data,
so maybe its cleaner ?
laurent
Index: dhclient-script
===================================================================
RCS file: /cvs/src/sbin/dhclient/dhclient-script,v
retrieving revision 1.15
diff -u -r1.15 dhclient-script
--- dhclient-script 3 Jun 2009 05:12:51 -0000 1.15
+++ dhclient-script 28 Feb 2010 08:14:48 -0000
@@ -24,7 +24,7 @@
delete_old_address() {
if [ -n "$old_ip_address" ]; then
ifconfig $interface inet $old_ip_address delete $medium
- route delete "$old_ip_address" 127.0.0.1 >/dev/null 2>&1
+ route -T $rt delete "$old_ip_address" 127.0.0.1 >/dev/null 2>&1
fi
}
@@ -36,14 +36,14 @@
$medium
# XXX Original TIMEOUT code did not do this unless $new_routers was set?
- route add $new_ip_address 127.0.0.1 >/dev/null 2>&1
+ route -T $rt add $new_ip_address 127.0.0.1 >/dev/null 2>&1
}
delete_old_alias() {
if [ -n "$alias_ip_address" ]; then
ifconfig $interface \
inet $alias_ip_address delete > /dev/null 2>&1
- route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
+ route -T $rt delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
fi
}
@@ -51,19 +51,19 @@
if [ -n "$alias_ip_address" ]; then
ifconfig $interface inet $alias_ip_address alias netmask \
$alias_subnet_mask
- route add $alias_ip_address 127.0.0.1
+ route -T $rt add $alias_ip_address 127.0.0.1
fi
}
delete_old_routes() {
# Delete existing default route. We only allow one, so no need to
# process $old_routers list.
- route -n flush -inet -iface $interface >/dev/null 2>&1
+ route -T $rt -n flush -inet -iface $interface >/dev/null 2>&1
if [ -n "$old_static_routes" ]; then
set $old_static_routes
while [ $# -gt 1 ]; do
- route delete "$1" "$2"
+ route -T $rt delete "$1" "$2"
shift; shift
done
fi
@@ -72,12 +72,12 @@
}
add_new_routes() {
- route -n flush -inet -iface $interface >/dev/null 2>&1
+ route -T $rt -n flush -inet -iface $interface >/dev/null 2>&1
for router in $new_routers; do
if [ "$new_ip_address" = "$router" ]; then
- route add default -iface $router >/dev/null 2>&1
+ route -T $rt add default -iface $router >/dev/null 2>&1
else
- route add default $router >/dev/null 2>&1
+ route -T $rt add default $router >/dev/null 2>&1
fi
# 2nd and subsequent default routers error out, so explicitly
# stop processing the list after the first one.
@@ -87,7 +87,7 @@
if [ -n "$new_static_routes" ]; then
set $new_static_routes
while [ $# -gt 1 ]; do
- route add $1 $2
+ route -T $rt add $1 $2
shift; shift
done
fi
Index: dhclient.c
===================================================================
RCS file: /cvs/src/sbin/dhclient/dhclient.c,v
retrieving revision 1.132
diff -u -r1.132 dhclient.c
--- dhclient.c 12 Nov 2009 14:18:45 -0000 1.132
+++ dhclient.c 28 Feb 2010 08:14:49 -0000
@@ -1589,6 +1589,8 @@
void
priv_script_init(char *reason, char *medium)
{
+ char tbuf[128];
+
client->scriptEnvsize = 100;
if (client->scriptEnv == NULL)
client->scriptEnv =
@@ -1606,6 +1608,9 @@
if (medium)
script_set_env("", "medium", medium);
+
+ snprintf(tbuf, sizeof(tbuf), "%d", (u_int)ifi->rdomain);
+ script_set_env("", "rt", tbuf);
script_set_env("", "reason", reason);
}
Index: dhcpd.h
===================================================================
RCS file: /cvs/src/sbin/dhclient/dhcpd.h,v
retrieving revision 1.69
diff -u -r1.69 dhcpd.h
--- dhcpd.h 6 Jun 2009 04:02:42 -0000 1.69
+++ dhcpd.h 28 Feb 2010 08:14:49 -0000
@@ -191,6 +191,7 @@
int errors;
u_int16_t index;
int linkstat;
+ u_int rdomain;
};
struct timeout {
Index: dispatch.c
===================================================================
RCS file: /cvs/src/sbin/dhclient/dispatch.c,v
retrieving revision 1.45
diff -u -r1.45 dispatch.c
--- dispatch.c 26 Nov 2009 23:14:29 -0000 1.45
+++ dispatch.c 28 Feb 2010 08:14:49 -0000
@@ -296,6 +296,12 @@
error("ioctl(SIOCGIFFLAGS) on %s: %m", ifname);
}
+ /* get the routing domain */
+ if (ioctl(sock, SIOCGIFRTABLEID, (caddr_t)&ifr) < 0)
+ ifi->rdomain = 0;
+ else
+ ifi->rdomain = ifr.ifr_rdomainid;
+
/*
* if one of UP and RUNNING flags is dropped,
* the interface is not active.