summaryrefslogtreecommitdiffstats
path: root/configure.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-09-08 11:30:31 +0000
committerRoy Marples <roy@marples.name>2008-09-08 11:30:31 +0000
commitcf7a295fa370022c78bf971667e61f69450104a4 (patch)
tree3e8cd16b94b87f88e0b4c37066ef43d468169f87 /configure.c
parentc130b44207af00d374c6eee6c115b210a2b9bd49 (diff)
downloaddhcpcd-cf7a295fa370022c78bf971667e61f69450104a4.tar.xz
On Linux, fix replacing the kernel added subnet route correctly for metrics.
Diffstat (limited to 'configure.c')
-rw-r--r--configure.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/configure.c b/configure.c
index 07502eff..a4c206b7 100644
--- a/configure.c
+++ b/configure.c
@@ -301,6 +301,7 @@ static int
delete_address(struct interface *iface)
{
int retval;
+
syslog(LOG_DEBUG, "%s: deleting IP address %s/%d",
iface->name,
inet_ntoa(iface->addr),
@@ -323,7 +324,6 @@ configure(struct interface *iface, const char *reason)
#ifdef __linux__
struct in_addr dest;
struct in_addr gate;
- struct rt *rt = NULL;
#endif
/* Grab our IP config */
@@ -336,6 +336,10 @@ configure(struct interface *iface, const char *reason)
net.s_addr = get_netmask(addr.s_addr);
if (get_option_addr(&brd.s_addr, dhcp, DHO_BROADCAST) == -1)
brd.s_addr = addr.s_addr | ~net.s_addr;
+#ifdef __linux__
+ dest.s_addr = addr.s_addr & net.s_addr;
+ gate.s_addr = 0;
+#endif
} else {
/* Only reset things if we had set them before */
if (iface->addr.s_addr != 0) {
@@ -367,31 +371,20 @@ configure(struct interface *iface, const char *reason)
#ifdef __linux__
/* On linux, we need to change the subnet route to have our metric. */
- if (iface->addr.s_addr != iface->state->lease.addr.s_addr &&
- iface->metric > 0 &&
- net.s_addr != INADDR_BROADCAST)
+ if (iface->metric > 0 &&
+ (net.s_addr != iface->net.s_addr ||
+ dest.s_addr != (iface->addr.s_addr & iface->net.s_addr)))
{
- dest.s_addr = addr.s_addr & net.s_addr;
- gate.s_addr = 0;
- add_route(iface, &dest, &net, &gate, iface->metric);
+ iface->addr.s_addr = addr.s_addr;
+ iface->net.s_addr = net.s_addr;
+ change_route(iface, &dest, &net, &gate, iface->metric);
del_route(iface, &dest, &net, &gate, 0);
- rt = xmalloc(sizeof(*rt));
- rt->dest.s_addr = dest.s_addr;
- rt->net.s_addr = net.s_addr;
- rt->gate.s_addr = gate.s_addr;
}
#endif
- configure_routes(iface, dhcp);
iface->addr.s_addr = addr.s_addr;
iface->net.s_addr = net.s_addr;
-
-#ifdef __linux__
- if (rt) {
- rt->next = iface->routes;
- iface->routes = rt;
- }
-#endif
+ configure_routes(iface, dhcp);
if (!iface->state->lease.frominfo)
if (write_lease(iface, dhcp) == -1)