]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Some DHCP servers assign a host route via static routes by setting the
authorRoy Marples <roy@marples.name>
Mon, 27 Sep 2010 19:24:10 +0000 (19:24 +0000)
committerRoy Marples <roy@marples.name>
Mon, 27 Sep 2010 19:24:10 +0000 (19:24 +0000)
gateway address to the leased address. This differs from the normal
approach of making the gateway address match the destination address,
so we change it when building our routing table.

configure.c

index f2a52c98eb815dea82a607a83af426b905cdf120..fb28669b93e10c00f5e38eb82a10f312f71d244f 100644 (file)
@@ -551,6 +551,21 @@ get_routes(const struct interface *iface)
            iface->name, &iface->state->options->options);
 }
 
+/* Some DHCP servers add set host routes by setting the gateway
+ * to the assinged IP address. This differs from our notion of a host route
+ * where the gateway is the destination address, so we fix it. */
+static struct rt *
+massage_host_routes(struct rt *rt, const struct interface *iface)
+{
+       struct rt *r;
+
+       for (r = rt; r; r = r->next)
+               if (r->gate.s_addr == iface->addr.s_addr &&
+                   r->net.s_addr == INADDR_BROADCAST)
+                       r->gate.s_addr = r->dest.s_addr;
+       return rt;
+}
+
 static struct rt *
 add_destination_route(struct rt *rt, const struct interface *iface)
 {
@@ -629,6 +644,7 @@ build_routes(void)
                if (ifp->state->new == NULL)
                        continue;
                dnr = get_routes(ifp);
+               dnr = massage_host_routes(dnr, ifp);
                dnr = add_subnet_route(dnr, ifp);
                dnr = add_router_host_route(dnr, ifp);
                dnr = add_destination_route(dnr, ifp);