Don't ignore loopback devices and allow addresses on them being enumerated
authorTobias Brunner <tobias@strongswan.org>
Fri, 14 Sep 2012 13:03:09 +0000 (15:03 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 21 Sep 2012 16:16:26 +0000 (18:16 +0200)
src/libcharon/plugins/stroke/stroke_list.c
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_listener.c
src/libcharon/sa/ikev2/tasks/ike_me.c
src/libcharon/sa/ikev2/tasks/ike_mobike.c
src/libcharon/sa/ikev2/tasks/ike_natd.c
src/libhydra/kernel/kernel_interface.c
src/libhydra/kernel/kernel_interface.h
src/libhydra/kernel/kernel_net.h
src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c

index 1381e58..10254c8 100644 (file)
@@ -517,7 +517,7 @@ METHOD(stroke_list_t, status, void,
                enumerator->destroy(enumerator);
 
                enumerator = hydra->kernel_interface->create_address_enumerator(
-                                                                       hydra->kernel_interface, FALSE, FALSE);
+                                                               hydra->kernel_interface, FALSE, FALSE, FALSE);
                fprintf(out, "Listening IP addresses:\n");
                while (enumerator->enumerate(enumerator, (void**)&host))
                {
index 4fd3369..6902bcb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Andreas Steffen 
+ * Copyright (C) 2011 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -49,7 +49,7 @@ static bool publish_device_ip_addresses(private_tnc_ifmap_listener_t *this)
        bool success = TRUE;
 
        enumerator = hydra->kernel_interface->create_address_enumerator(
-                                                       hydra->kernel_interface, FALSE, FALSE);
+                                                       hydra->kernel_interface, FALSE, FALSE, FALSE);
        while (enumerator->enumerate(enumerator, &host))
        {
                if (!this->ifmap->publish_device_ip(this->ifmap, host))
@@ -87,7 +87,7 @@ static bool reload_metadata(private_tnc_ifmap_listener_t *this)
                }
        }
        enumerator->destroy(enumerator);
-       
+
        return success;
 }
 
index e193499..779f525 100644 (file)
@@ -136,7 +136,7 @@ static void gather_and_add_endpoints(private_ike_me_t *this, message_t *message)
        port = host->get_port(host);
 
        enumerator = hydra->kernel_interface->create_address_enumerator(
-                                                                               hydra->kernel_interface, FALSE, FALSE);
+                                                               hydra->kernel_interface, FALSE, FALSE, FALSE);
        while (enumerator->enumerate(enumerator, (void**)&addr))
        {
                host = addr->clone(addr);
index 8c30ed9..285009f 100644 (file)
@@ -192,7 +192,7 @@ static void build_address_list(private_ike_mobike_t *this, message_t *message)
 
        me = this->ike_sa->get_my_host(this->ike_sa);
        enumerator = hydra->kernel_interface->create_address_enumerator(
-                                                                               hydra->kernel_interface, FALSE, FALSE);
+                                                               hydra->kernel_interface, FALSE, FALSE, FALSE);
        while (enumerator->enumerate(enumerator, (void**)&host))
        {
                if (me->ip_equals(me, host))
index b97b372..dc8a000 100644 (file)
@@ -341,7 +341,7 @@ METHOD(task_t, build_i, status_t,
                else
                {       /* 3. */
                        enumerator = hydra->kernel_interface->create_address_enumerator(
-                                                                               hydra->kernel_interface, FALSE, FALSE);
+                                                               hydra->kernel_interface, FALSE, FALSE, FALSE);
                        while (enumerator->enumerate(enumerator, (void**)&host))
                        {
                                /* apply port 500 to host, but work on a copy */
index cd162b7..8e3f6a6 100644 (file)
@@ -303,14 +303,14 @@ METHOD(kernel_interface_t, get_interface, char*,
 
 METHOD(kernel_interface_t, create_address_enumerator, enumerator_t*,
        private_kernel_interface_t *this, bool include_down_ifaces,
-       bool include_virtual_ips)
+       bool include_virtual_ips, bool include_loopback)
 {
        if (!this->net)
        {
                return enumerator_create_empty();
        }
        return this->net->create_address_enumerator(this->net, include_down_ifaces,
-                                                                                               include_virtual_ips);
+                                                                               include_virtual_ips, include_loopback);
 }
 
 METHOD(kernel_interface_t, add_ip, status_t,
@@ -423,7 +423,7 @@ METHOD(kernel_interface_t, get_address_by_ts, status_t,
        }
        host->destroy(host);
 
-       addrs = create_address_enumerator(this, TRUE, TRUE);
+       addrs = create_address_enumerator(this, TRUE, TRUE, TRUE);
        while (addrs->enumerate(addrs, (void**)&host))
        {
                if (ts->includes(ts, host))
index 72af397..5396dad 100644 (file)
@@ -320,11 +320,13 @@ struct kernel_interface_t {
         * The hosts are read-only, do not modify of free.
         *
         * @param include_down_ifaces   TRUE to enumerate addresses from down interfaces
-        * @param include_virtual_ips   TRUE to enumerate virtual ip addresses
+        * @param include_virtual_ips   TRUE to enumerate virtual IP addresses
+        * @param include_loopback              TRUE to enumerate addresses on loopback interfaces
         * @return                                              enumerator over host_t's
         */
        enumerator_t *(*create_address_enumerator) (kernel_interface_t *this,
-                                               bool include_down_ifaces, bool include_virtual_ips);
+                                                       bool include_down_ifaces, bool include_virtual_ips,
+                                                       bool include_loopback);
 
        /**
         * Add a virtual IP to an interface.
index a9b6fba..772ccac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Tobias Brunner
+ * Copyright (C) 2008-2012 Tobias Brunner
  * Copyright (C) 2007 Martin Willi
  * Hochschule fuer Technik Rapperswil
  *
@@ -80,11 +80,13 @@ struct kernel_net_t {
         * The hosts are read-only, do not modify of free.
         *
         * @param include_down_ifaces   TRUE to enumerate addresses from down interfaces
-        * @param include_virtual_ips   TRUE to enumerate virtual ip addresses
+        * @param include_virtual_ips   TRUE to enumerate virtual IP addresses
+        * @param include_loopback              TRUE to enumerate addresses on loopback interfaces
         * @return                                              enumerator over host_t's
         */
        enumerator_t *(*create_address_enumerator) (kernel_net_t *this,
-                                               bool include_down_ifaces, bool include_virtual_ips);
+                                                       bool include_down_ifaces, bool include_virtual_ips,
+                                                       bool include_loopback);
 
        /**
         * Add a virtual IP to an interface.
index ecd265d..52671a2 100644 (file)
@@ -589,10 +589,6 @@ static void process_link(private_kernel_netlink_net_t *this,
        {
                case RTM_NEWLINK:
                {
-                       if (msg->ifi_flags & IFF_LOOPBACK)
-                       {       /* ignore loopback interfaces */
-                               break;
-                       }
                        enumerator = this->ifaces->create_enumerator(this->ifaces);
                        while (enumerator->enumerate(enumerator, &current))
                        {
@@ -924,6 +920,8 @@ typedef struct {
        bool include_down_ifaces;
        /** whether to enumerate virtual ip addresses */
        bool include_virtual_ips;
+       /** whether to enumerate loopback interfaces */
+       bool include_loopback;
 } address_enumerator_t;
 
 /**
@@ -970,6 +968,10 @@ static enumerator_t *create_iface_enumerator(iface_entry_t *iface,
 static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in,
                                                          iface_entry_t** out)
 {
+       if (!data->include_loopback && ((*in)->flags & IFF_LOOPBACK))
+       {       /* ignore loopback devices */
+               return FALSE;
+       }
        if (!data->include_down_ifaces && !((*in)->flags & IFF_UP))
        {       /* skip interfaces not up */
                return FALSE;
@@ -980,12 +982,13 @@ static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in,
 
 METHOD(kernel_net_t, create_address_enumerator, enumerator_t*,
        private_kernel_netlink_net_t *this,
-       bool include_down_ifaces, bool include_virtual_ips)
+       bool include_down_ifaces, bool include_virtual_ips, bool include_loopback)
 {
        address_enumerator_t *data = malloc_thing(address_enumerator_t);
        data->this = this;
        data->include_down_ifaces = include_down_ifaces;
        data->include_virtual_ips = include_virtual_ips;
+       data->include_loopback = include_loopback;
 
        this->mutex->lock(this->mutex);
        return enumerator_create_nested(
index 7f38a9d..8785737 100644 (file)
@@ -284,11 +284,6 @@ static void process_link(private_kernel_pfroute_net_t *this,
        iface_entry_t *iface;
        bool roam = FALSE;
 
-       if (msg->ifm_flags & IFF_LOOPBACK)
-       {       /* ignore loopback interfaces */
-               return;
-       }
-
        this->mutex->lock(this->mutex);
        enumerator = this->ifaces->create_enumerator(this->ifaces);
        while (enumerator->enumerate(enumerator, &iface))
@@ -393,6 +388,8 @@ typedef struct {
        bool include_down_ifaces;
        /** whether to enumerate virtual ip addresses */
        bool include_virtual_ips;
+       /** whether to enumerate loopback interfaces */
+       bool include_loopback;
 } address_enumerator_t;
 
 /**
@@ -444,6 +441,10 @@ static enumerator_t *create_iface_enumerator(iface_entry_t *iface,
 static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in,
                                                          iface_entry_t** out)
 {
+       if (!data->include_loopback && ((*in)->flags & IFF_LOOPBACK))
+       {       /* ignore loopback devices */
+               return FALSE;
+       }
        if (!data->include_down_ifaces && !((*in)->flags & IFF_UP))
        {   /* skip interfaces not up */
                return FALSE;
@@ -454,12 +455,13 @@ static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in,
 
 METHOD(kernel_net_t, create_address_enumerator, enumerator_t*,
        private_kernel_pfroute_net_t *this,
-       bool include_down_ifaces, bool include_virtual_ips)
+       bool include_down_ifaces, bool include_virtual_ips, bool include_loopback)
 {
        address_enumerator_t *data = malloc_thing(address_enumerator_t);
        data->this = this;
        data->include_down_ifaces = include_down_ifaces;
        data->include_virtual_ips = include_virtual_ips;
+       data->include_loopback = include_loopback;
 
        this->mutex->lock(this->mutex);
        return enumerator_create_nested(
@@ -581,11 +583,6 @@ static status_t init_address_list(private_kernel_pfroute_net_t *this)
                        case AF_INET:
                        case AF_INET6:
                        {
-                               if (ifa->ifa_flags & IFF_LOOPBACK)
-                               {       /* ignore loopback interfaces */
-                                       continue;
-                               }
-
                                iface = NULL;
                                ifaces = this->ifaces->create_enumerator(this->ifaces);
                                while (ifaces->enumerate(ifaces, &current))