kernel-netlink: Routes don't require a gateway/nexthop
authorTobias Brunner <tobias@strongswan.org>
Tue, 11 Jun 2013 14:05:40 +0000 (16:05 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 21 Jun 2013 15:03:20 +0000 (17:03 +0200)
src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c

index d4cb4e1..020b36a 100644 (file)
@@ -265,7 +265,7 @@ static route_entry_t *route_entry_clone(route_entry_t *this)
        INIT(route,
                .if_name = strdup(this->if_name),
                .src_ip = this->src_ip->clone(this->src_ip),
-               .gateway = this->gateway->clone(this->gateway),
+               .gateway = this->gateway ? this->gateway->clone(this->gateway) : NULL,
                .dst_net = chunk_clone(this->dst_net),
                .prefixlen = this->prefixlen,
        );
@@ -298,10 +298,14 @@ static u_int route_entry_hash(route_entry_t *this)
  */
 static bool route_entry_equals(route_entry_t *a, route_entry_t *b)
 {
-       return a->if_name && b->if_name && streq(a->if_name, b->if_name) &&
-                  a->src_ip->ip_equals(a->src_ip, b->src_ip) &&
-                  a->gateway->ip_equals(a->gateway, b->gateway) &&
-                  chunk_equals(a->dst_net, b->dst_net) && a->prefixlen == b->prefixlen;
+       if (a->if_name && b->if_name && streq(a->if_name, b->if_name) &&
+               a->src_ip->ip_equals(a->src_ip, b->src_ip) &&
+               chunk_equals(a->dst_net, b->dst_net) && a->prefixlen == b->prefixlen)
+       {
+               return (!a->gateway && !b->gateway) || (a->gateway && b->gateway &&
+                                       a->gateway->ip_equals(a->gateway, b->gateway));
+       }
+       return FALSE;
 }
 
 typedef struct net_change_t net_change_t;