]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-utun: filter address enumeration based on passed "which" flags
authorMartin Willi <martin@revosec.ch>
Mon, 15 Apr 2013 14:43:42 +0000 (16:43 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 18 Apr 2013 12:43:56 +0000 (14:43 +0200)
src/libhydra/plugins/kernel_utun/kernel_utun_net.c

index a32b850100dab699deb8988044d15f058f6f980c..8cfc4a7464628eff48f6c4e581ecdd4ff1795bc1 100644 (file)
@@ -16,6 +16,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <ifaddrs.h>
+#include <net/if.h>
 #include <errno.h>
 
 #include "kernel_utun_net.h"
@@ -46,6 +47,8 @@ typedef struct {
        struct ifaddrs *current;
        /** current host */
        host_t *host;
+       /** which address types to filter */
+       kernel_address_type_t which;
 } addr_enumerator_t;
 
 METHOD(enumerator_t, addr_enumerate, bool,
@@ -71,7 +74,21 @@ METHOD(enumerator_t, addr_enumerate, bool,
                {
                        return FALSE;
                }
-               /* TODO: filter based on "which" */
+               if (!(this->which & ADDR_TYPE_LOOPBACK) &&
+                       (this->current->ifa_flags & IFF_LOOPBACK))
+               {       /* ignore loopback devices */
+                       continue;
+               }
+               if (!(this->which & ADDR_TYPE_DOWN) &&
+                       !(this->current->ifa_flags & IFF_UP))
+               {       /* skip interfaces not up */
+                       continue;
+               }
+               if (!(this->which & ADDR_TYPE_VIRTUAL) &&
+                       strneq(this->current->ifa_name, "utun", strlen("utun")))
+               {       /* skip virtual IPs on utun devices */
+                       continue;
+               }
                this->host = host_create_from_sockaddr(this->current->ifa_addr);
                if (!this->host)
                {
@@ -109,6 +126,7 @@ METHOD(kernel_net_t, create_address_enumerator, enumerator_t*,
                        .destroy = _addr_destroy,
                },
                .orig = ifa,
+               .which = which,
        );
        return &enumerator->public;
 }