From: Roy Marples Date: Mon, 27 Sep 2010 19:24:10 +0000 (+0000) Subject: Some DHCP servers assign a host route via static routes by setting the X-Git-Tag: v5.2.9~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73b25eb9bfaef6ac0e813a6af768164e5fd6cd21;p=thirdparty%2Fdhcpcd.git Some DHCP servers assign a host route via static routes by setting the 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. --- diff --git a/configure.c b/configure.c index f2a52c98..fb28669b 100644 --- a/configure.c +++ b/configure.c @@ -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);