From: Roy Marples Date: Wed, 18 Apr 2007 12:03:23 +0000 (+0000) Subject: Ensure that static routes are always added before routers. X-Git-Tag: v3.2.3~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd58cd5aa3854ab65b05b0909a7aa2d9430f30b7;p=thirdparty%2Fdhcpcd.git Ensure that static routes are always added before routers. --- diff --git a/ChangeLog b/ChangeLog index b5a733ac..8dbd7126 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +Ensure that static routes are always added before routers. Use getnameinfo instead of gethostbyaddr. Remove gateways from the ROUTES and add to GATEWAYS define #INFO_COMPAT if you wish your .info file to add support for some diff --git a/Makefile b/Makefile index c1818b32..265bece0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 3.0.17 +VERSION = 3.0.18_pre1 CFLAGS ?= -O2 -pipe # Should work for both GNU make and BSD make diff --git a/configure.c b/configure.c index bfd5ee8a..01a6be28 100644 --- a/configure.c +++ b/configure.c @@ -674,7 +674,6 @@ int configure (const options_t *options, interface_t *iface, salen = sizeof (struct sockaddr); memset (&su.sa, 0, salen); su.sin.sin_family = AF_INET; - su.sin.sin_len = sizeof (struct sockaddr_in); memcpy (&su.sin.sin_addr, &dhcp->address, sizeof (struct in_addr)); if (getnameinfo (&su.sa, salen, addr, sizeof (addr), @@ -686,7 +685,7 @@ int configure (const options_t *options, interface_t *iface, if (getaddrinfo (addr, "0", &hints, &res) == 0) { freeaddrinfo (res); addr[0] = '\0'; - logger (LOG_DEBUG, "malicious PTR record detected"); + logger (LOG_ERR, "malicious PTR record detected"); } } diff --git a/dhcp.c b/dhcp.c index ea3b8d84..56525606 100644 --- a/dhcp.c +++ b/dhcp.c @@ -407,33 +407,17 @@ void free_dhcp (dhcp_t *dhcp) if (! dhcp) return; - if (dhcp->routes) - free_route (dhcp->routes); - - if (dhcp->hostname) - free (dhcp->hostname); - - if (dhcp->dnsservers) - free_address (dhcp->dnsservers); - if (dhcp->dnsdomain) - free (dhcp->dnsdomain); - if (dhcp->dnssearch) - free (dhcp->dnssearch); - - if (dhcp->ntpservers) - free_address (dhcp->ntpservers); - - if (dhcp->nisdomain) - free (dhcp->nisdomain); - if (dhcp->nisservers) - free_address (dhcp->nisservers); - - if (dhcp->rootpath) - free (dhcp->rootpath); - + free_route (dhcp->routes); + free (dhcp->hostname); + free_address (dhcp->dnsservers); + free (dhcp->dnsdomain); + free (dhcp->dnssearch); + free_address (dhcp->ntpservers); + free (dhcp->nisdomain); + free_address (dhcp->nisservers); + free (dhcp->rootpath); if (dhcp->fqdn) { - if (dhcp->fqdn->name) - free (dhcp->fqdn->name); + free (dhcp->fqdn->name); free (dhcp->fqdn); } } @@ -474,15 +458,14 @@ int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) unsigned int len = 0; int i; int retval = -1; - route_t *first_route = xmalloc (sizeof (route_t)); - route_t *route = first_route; - route_t *last_route = NULL; + route_t *routers = NULL; + route_t *routersp = NULL; + route_t *static_routes = NULL; + route_t *static_routesp = NULL; route_t *csr = NULL; end += sizeof (message->options); - memset (first_route, 0, sizeof (route_t)); - dhcp->address.s_addr = message->yiaddr; strlcpy (dhcp->servername, message->servername, sizeof (dhcp->servername)); @@ -496,7 +479,7 @@ int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) while (p < end) { option = *p++; - if (!option) + if (! option) continue; length = *p++; @@ -630,8 +613,7 @@ int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) case DHCP_DNSSEARCH: MIN_LENGTH (1); - if (dhcp->dnssearch) - free (dhcp->dnssearch); + free (dhcp->dnssearch); if ((len = decode_search (p, length, NULL)) > 0) { dhcp->dnssearch = xmalloc (len); decode_search (p, length, dhcp->dnssearch); @@ -640,21 +622,23 @@ int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) case DHCP_CSR: MIN_LENGTH (5); - if (csr) - free_route (csr); + free_route (csr); csr = decodeCSR (p, length); break; case DHCP_STATICROUTE: MULT_LENGTH (8); for (i = 0; i < length; i += 8) { - memcpy (&route->destination.s_addr, p + i, 4); - memcpy (&route->gateway.s_addr, p + i + 4, 4); - route->netmask.s_addr = getnetmask (route->destination.s_addr); - last_route = route; - route->next = xmalloc (sizeof (route_t)); - route = route->next; - memset (route, 0, sizeof (route_t)); + if (static_routesp) { + static_routesp->next = xmalloc (sizeof (route_t)); + static_routesp = static_routesp->next; + } else + static_routesp = static_routes = xmalloc (sizeof (route_t)); + memset (static_routesp, 0, sizeof (route_t)); + memcpy (&static_routesp->destination.s_addr, p + i, 4); + memcpy (&static_routesp->gateway.s_addr, p + i + 4, 4); + static_routesp->netmask.s_addr = + getnetmask (static_routesp->destination.s_addr); } break; @@ -662,11 +646,13 @@ int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) MULT_LENGTH (4); for (i = 0; i < length; i += 4) { - memcpy (&route->gateway.s_addr, p + i, 4); - last_route = route; - route->next = xmalloc (sizeof (route_t)); - route = route->next; - memset (route, 0, sizeof (route_t)); + if (routersp) { + routersp->next = xmalloc (sizeof (route_t)); + routersp = routersp->next; + } else + routersp = routers = xmalloc (sizeof (route_t)); + memset (routersp, 0, sizeof (route_t)); + memcpy (&routersp->gateway.s_addr, p + i, 4); } break; @@ -693,16 +679,16 @@ eexit: static routes and routers according to RFC 3442 */ if (csr) { dhcp->routes = csr; - free_route (first_route); + free_route (routers); + free_route (static_routes); } else { - dhcp->routes = first_route; - if (last_route) { - free (last_route->next); - last_route->next = NULL; - } else { - free_route (dhcp->routes); - dhcp->routes = NULL; - } + /* Ensure that we apply static routes before routers */ + if (static_routes) + { + dhcp->routes = static_routes; + static_routesp->next = routers; + } else + dhcp->routes = routers; } return retval; diff --git a/interface.c b/interface.c index 5a46181a..9494c715 100644 --- a/interface.c +++ b/interface.c @@ -84,7 +84,7 @@ void free_route (route_t *routes) route_t *p = routes; route_t *n = NULL; - if (!routes) + if (! routes) return; while (p) {