]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Always add a link-local route unless we're given a non-private address by the DHCP...
authorRoy Marples <roy@marples.name>
Fri, 12 Oct 2007 11:19:29 +0000 (11:19 +0000)
committerRoy Marples <roy@marples.name>
Fri, 12 Oct 2007 11:19:29 +0000 (11:19 +0000)
ChangeLog
configure.c
interface.h

index 4b8c6bebdb42e563af103a83b7b179ae42780639..e7a543afaf79f1388978326a1f0d384ad1f0317b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+Always add a link-local route unless we're given a non-private
+address by the DHCP server.
 Reduce stack usage by using malloc more.
 If we're on a different subnet from the one we get DHCP for, don't
 use our current address in messages. Thanks to Wilson Callan.
index 0847b2eab0966e9b9ba38ce7cda07e97adb2ba1a..067131e4c8080359c1dc6921e5911f3d098ac37d 100644 (file)
@@ -49,6 +49,9 @@
 #ifdef ENABLE_INFO
 # include "info.h"
 #endif
+#ifdef ENABLE_IPV4LL
+# include "ipv4ll.h"
+#endif
 #include "interface.h"
 #include "dhcpcd.h"
 #include "logger.h"
@@ -335,10 +338,15 @@ int configure (const options_t *options, interface_t *iface,
                           const dhcp_t *dhcp, bool up)
 {
        route_t *route = NULL;
+       route_t *new_routes = NULL;
        route_t *new_route = NULL;
        route_t *old_route = NULL;
        char *newhostname = NULL;
        char *curhostname = NULL;
+       int remember;
+#ifdef ENABLE_IPV4LL
+       bool haslinklocal = false;
+#endif
 
        if (! options || ! iface || ! dhcp)
                return (-1);
@@ -453,13 +461,18 @@ int configure (const options_t *options, interface_t *iface,
 
        /* Remember added routes */
        if (dhcp->routes) {
-               route_t *new_routes = NULL;
-               int remember;
 #ifdef THERE_IS_NO_FORK
                int skip = 0;
 #endif
 
                for (route = dhcp->routes; route; route = route->next) {
+#ifdef ENABLE_IPV4LL
+                       /* Check if we have already got a link locale route dished
+                        * out by the DHCP server */
+                       if (route->destination.s_addr == htonl (LINKLOCAL_ADDR) &&
+                               route->netmask.s_addr == htonl (LINKLOCAL_MASK))
+                               haslinklocal = true;
+#endif
                        /* Don't set default routes if not asked to */
                        if (route->destination.s_addr == 0 && route->netmask.s_addr == 0
                                && ! options->dogateway)
@@ -510,11 +523,45 @@ int configure (const options_t *options, interface_t *iface,
 #endif
                }
 
-               if (iface->previous_routes)
-                       free_route (iface->previous_routes);
+       }
 
-               iface->previous_routes = new_routes;
+#ifdef ENABLE_IPV4LL
+       /* Ensure we always add the link local route if we got a private
+        * address and isn't link local itself */
+       if (options-> doipv4ll &&
+               ! haslinklocal &&
+               IN_PRIVATE (dhcp->address.s_addr))
+       {
+               struct in_addr dest;
+               struct in_addr mask;
+               struct in_addr gate;
+
+               dest.s_addr = htonl (LINKLOCAL_ADDR);
+               mask.s_addr = htonl (LINKLOCAL_MASK);
+               gate.s_addr = 0;
+               remember = add_route (iface->name, dest, mask, gate,
+                                                         options->metric);
+
+               if (remember >= 0) {
+                       if (! new_routes) {
+                               new_routes = xmalloc (sizeof (route_t));
+                               memset (new_routes, 0, sizeof (route_t));
+                               new_route = new_routes;
+                       } else {
+                               new_route->next = xmalloc (sizeof (route_t));
+                               new_route = new_route->next;
+                               new_route->next = NULL;
+                       }
+                       new_route->destination.s_addr = dest.s_addr;
+                       new_route->netmask.s_addr = mask.s_addr;
+                       new_route->gateway.s_addr = gate.s_addr;
+               }
        }
+#endif
+
+       if (iface->previous_routes)
+               free_route (iface->previous_routes);
+       iface->previous_routes = new_routes;
 
        if (options->dodns && dhcp->dnsservers)
                make_resolv(iface->name, dhcp);
index f3bf0505cb3503349c400b25a4a47360e4240156..59f5024f896aca8d95081280bd176195b7358aca 100644 (file)
 #  define ARPHRD_INFINIBAND            27
 #endif
 
-#define HWADDR_LEN                             20      
+#define HWADDR_LEN                             20
+
+/* Work out if we have a private address or not
+ * 10/8
+ * 172.16/12
+ * 192.168/16
+ */
+#ifndef IN_PRIVATE
+# define IN_PRIVATE(addr) (((ntohl (addr) & IN_CLASSA_NET) == 0x0a000000) || \
+                                                  ((ntohl (addr) & 0xfff00000)    == 0xac100000) || \
+                                                  ((ntohl (addr) & IN_CLASSB_NET) == 0xc0a80000))
+#endif
 
 typedef struct route_t
 {