]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Ensure that static routes are always added before routers.
authorRoy Marples <roy@marples.name>
Wed, 18 Apr 2007 12:03:23 +0000 (12:03 +0000)
committerRoy Marples <roy@marples.name>
Wed, 18 Apr 2007 12:03:23 +0000 (12:03 +0000)
ChangeLog
Makefile
configure.c
dhcp.c
interface.c

index b5a733ac711b0fe62faa9339c7178f4b09879ddd..8dbd7126b99051f8f9f1a51e90edf5552f19da43 100644 (file)
--- 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
index c1818b328b82b31bfbb7a48c96f98e2e57cab157..265bece044c1900900c6c484b20565bbcf001368 100644 (file)
--- 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
index bfd5ee8a4ba9d3bb4897b2ca8c37b473f6c554ab..01a6be285d68f8a3a431de1ef02e2cda71e58064 100644 (file)
@@ -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 ea3b8d84c2af26470ba3eaa36f82ca228d02e99f..56525606c5fdca6eb3022e1f442f8a1696c7aff9 100644 (file)
--- 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;
index 5a46181ac9b12b9e9d840833b181f774c4b379b8..9494c715bfa707f46c7dc08a4abd7337a3014cc3 100644 (file)
@@ -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) {