kernel-pfroute: Provide name of interfaces on which virtual IPs are installed
authorTobias Brunner <tobias@strongswan.org>
Wed, 10 Jul 2013 13:37:35 +0000 (15:37 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 17 Jul 2013 15:45:18 +0000 (17:45 +0200)
src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c

index 020b36a..c29aff4 100644 (file)
@@ -1266,7 +1266,7 @@ METHOD(kernel_net_t, get_interface_name, bool,
                if (name)
                {
                        *name = strdup(entry->iface->ifname);
-                       DBG2(DBG_KNL, "virtual %H is on interface %s", ip, *name);
+                       DBG2(DBG_KNL, "virtual IP %H is on interface %s", ip, *name);
                }
                this->lock->unlock(this->lock);
                return TRUE;
index d4a5957..ca9e069 100644 (file)
@@ -174,6 +174,15 @@ static bool addr_map_entry_match_up_and_usable(addr_map_entry_t *a,
 }
 
 /**
+ * Used with get_match this finds an address entry if it is installed as virtual
+ * IP address
+ */
+static bool addr_map_entry_match_virtual(addr_map_entry_t *a, addr_map_entry_t *b)
+{
+       return b->addr->virtual && a->ip->ip_equals(a->ip, b->ip);
+}
+
+/**
  * Used with get_match this finds an address entry if it is installed on
  * any active local interface
  */
@@ -1060,6 +1069,19 @@ METHOD(kernel_net_t, get_interface_name, bool,
                this->lock->unlock(this->lock);
                return TRUE;
        }
+       /* check if it is a virtual IP */
+       entry = this->addrs->get_match(this->addrs, &lookup,
+                                                                 (void*)addr_map_entry_match_virtual);
+       if (entry)
+       {
+               if (name)
+               {
+                       *name = strdup(entry->iface->ifname);
+                       DBG2(DBG_KNL, "virtual IP %H is on interface %s", ip, *name);
+               }
+               this->lock->unlock(this->lock);
+               return TRUE;
+       }
        /* maybe it is installed on an ignored interface */
        entry = this->addrs->get_match(this->addrs, &lookup,
                                                                  (void*)addr_map_entry_match_up);