add support for defaultroute "host" dependencies
authorFelix Fietkau <nbd@openwrt.org>
Mon, 18 Jun 2012 21:19:27 +0000 (23:19 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 18 Jun 2012 21:19:27 +0000 (23:19 +0200)
interface-ip.c

index 6699d2e5616992c22c8c8236d152db6069a04ecd..d8d8606799e969a54b19db3cb48ef5844d8ed877 100644 (file)
@@ -141,6 +141,8 @@ interface_ip_add_target_route(union if_addr *addr, bool v6)
 {
        struct interface *iface;
        struct device_route *route, *r_next = NULL;
+       bool defaultroute_target = false;
+       int addrsize = v6 ? sizeof(addr->in6) : sizeof(addr->in);
 
        route = calloc(1, sizeof(*route));
        if (!route)
@@ -148,7 +150,10 @@ interface_ip_add_target_route(union if_addr *addr, bool v6)
 
        route->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4;
        route->mask = v6 ? 128 : 32;
-       memcpy(&route->addr, addr, v6 ? sizeof(addr->in6) : sizeof(addr->in));
+       if (memcmp(&route->addr, addr, addrsize) == 0)
+               defaultroute_target = true;
+       else
+               memcpy(&route->addr, addr, addrsize);
 
        vlist_for_each_element(&interfaces, iface, node) {
                /* look for locally addressable target first */
@@ -172,7 +177,10 @@ interface_ip_add_target_route(union if_addr *addr, bool v6)
 
 done:
        route->iface = iface;
-       vlist_add(&iface->host_routes, &route->node, &route->flags);
+       if (defaultroute_target)
+               free(route);
+       else
+               vlist_add(&iface->host_routes, &route->node, &route->flags);
        return iface;
 }