Also added an option to enumerate addresses on ignored interfaces.
enumerator->destroy(enumerator);
enumerator = hydra->kernel_interface->create_address_enumerator(
- hydra->kernel_interface, FALSE, FALSE, FALSE);
+ hydra->kernel_interface, ADDR_TYPE_REGULAR);
fprintf(out, "Listening IP addresses:\n");
while (enumerator->enumerate(enumerator, (void**)&host))
{
bool success = TRUE;
enumerator = hydra->kernel_interface->create_address_enumerator(
- hydra->kernel_interface, FALSE, FALSE, FALSE);
+ hydra->kernel_interface, ADDR_TYPE_REGULAR);
while (enumerator->enumerate(enumerator, &host))
{
if (!this->ifmap->publish_device_ip(this->ifmap, host))
port = host->get_port(host);
enumerator = hydra->kernel_interface->create_address_enumerator(
- hydra->kernel_interface, FALSE, FALSE, FALSE);
+ hydra->kernel_interface, ADDR_TYPE_REGULAR);
while (enumerator->enumerate(enumerator, (void**)&addr))
{
host = addr->clone(addr);
me = this->ike_sa->get_my_host(this->ike_sa);
enumerator = hydra->kernel_interface->create_address_enumerator(
- hydra->kernel_interface, FALSE, FALSE, FALSE);
+ hydra->kernel_interface, ADDR_TYPE_REGULAR);
while (enumerator->enumerate(enumerator, (void**)&host))
{
if (me->ip_equals(me, host))
else
{ /* 3. */
enumerator = hydra->kernel_interface->create_address_enumerator(
- hydra->kernel_interface, FALSE, FALSE, FALSE);
+ hydra->kernel_interface, ADDR_TYPE_REGULAR);
while (enumerator->enumerate(enumerator, (void**)&host))
{
/* apply port 500 to host, but work on a copy */
}
METHOD(kernel_interface_t, create_address_enumerator, enumerator_t*,
- private_kernel_interface_t *this, bool include_down_ifaces,
- bool include_virtual_ips, bool include_loopback)
+ private_kernel_interface_t *this, kernel_address_type_t which)
{
if (!this->net)
{
return enumerator_create_empty();
}
- return this->net->create_address_enumerator(this->net, include_down_ifaces,
- include_virtual_ips, include_loopback);
+ return this->net->create_address_enumerator(this->net, which);
}
METHOD(kernel_interface_t, add_ip, status_t,
}
host->destroy(host);
- addrs = create_address_enumerator(this, TRUE, TRUE, TRUE);
+ addrs = create_address_enumerator(this, ADDR_TYPE_ALL);
while (addrs->enumerate(addrs, (void**)&host))
{
if (ts->includes(ts, host))
* enumerator gets destroyed.
* 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_loopback TRUE to enumerate addresses on loopback interfaces
- * @return enumerator over host_t's
+ * @param which a combination of address types to enumerate
+ * @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_loopback);
+ kernel_address_type_t which);
/**
* Add a virtual IP to an interface.
#define KERNEL_NET_H_
typedef struct kernel_net_t kernel_net_t;
+typedef enum kernel_address_type_t kernel_address_type_t;
#include <utils/enumerator.h>
#include <utils/host.h>
#include <plugins/plugin.h>
/**
+ * Type of addresses (e.g. when enumerating them)
+ */
+enum kernel_address_type_t {
+ /** normal addresses (on regular, up, non-ignored) interfaces */
+ ADDR_TYPE_REGULAR = 0,
+ /** addresses on down interfaces */
+ ADDR_TYPE_DOWN = (1 << 0),
+ /** addresses on ignored interfaces */
+ ADDR_TYPE_IGNORED = (1 << 1),
+ /** addresses on loopback interfaces */
+ ADDR_TYPE_LOOPBACK = (1 << 2),
+ /** virtual IP addresses */
+ ADDR_TYPE_VIRTUAL = (1 << 3),
+ /** to enumerate all available addresses */
+ ADDR_TYPE_ALL = (1 << 4) - 1,
+};
+
+/**
* Interface to the network subsystem of the kernel.
*
* The kernel network interface handles the communication with the kernel
* enumerator gets destroyed.
* 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_loopback TRUE to enumerate addresses on loopback interfaces
- * @return enumerator over host_t's
+ * @param which a combination of address types to enumerate
+ * @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_loopback);
+ kernel_address_type_t which);
/**
* Add a virtual IP to an interface.
/** enumerator over addresses */
typedef struct {
private_kernel_netlink_net_t* this;
- /** whether to enumerate down interfaces */
- bool include_down_ifaces;
- /** whether to enumerate virtual ip addresses */
- bool include_virtual_ips;
- /** whether to enumerate loopback interfaces */
- bool include_loopback;
+ /** which addresses to enumerate */
+ kernel_address_type_t which;
} address_enumerator_t;
/**
static bool filter_addresses(address_enumerator_t *data,
addr_entry_t** in, host_t** out)
{
- if (!data->include_virtual_ips && (*in)->virtual)
+ if (!(data->which & ADDR_TYPE_VIRTUAL) && (*in)->virtual)
{ /* skip virtual interfaces added by us */
return FALSE;
}
static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in,
iface_entry_t** out)
{
- if (!(*in)->usable)
+ if (!(data->which & ADDR_TYPE_IGNORED) && !(*in)->usable)
{ /* skip interfaces excluded by config */
return FALSE;
}
- if (!data->include_loopback && ((*in)->flags & IFF_LOOPBACK))
+ if (!(data->which & ADDR_TYPE_LOOPBACK) && ((*in)->flags & IFF_LOOPBACK))
{ /* ignore loopback devices */
return FALSE;
}
- if (!data->include_down_ifaces && !((*in)->flags & IFF_UP))
+ if (!(data->which & ADDR_TYPE_DOWN) && !((*in)->flags & IFF_UP))
{ /* skip interfaces not up */
return FALSE;
}
}
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_loopback)
+ private_kernel_netlink_net_t *this, kernel_address_type_t which)
{
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;
+ data->which = which;
this->mutex->lock(this->mutex);
return enumerator_create_nested(
/** enumerator over addresses */
typedef struct {
private_kernel_pfroute_net_t* this;
- /** whether to enumerate down interfaces */
- bool include_down_ifaces;
- /** whether to enumerate virtual ip addresses */
- bool include_virtual_ips;
- /** whether to enumerate loopback interfaces */
- bool include_loopback;
+ /** which addresses to enumerate */
+ address_type_t which;
} address_enumerator_t;
/**
addr_entry_t** in, host_t** out)
{
host_t *ip;
- if (!data->include_virtual_ips && (*in)->virtual)
+ if (!(data->which & ADDR_TYPE_VIRTUAL) && (*in)->virtual)
{ /* skip virtual interfaces added by us */
return FALSE;
}
static bool filter_interfaces(address_enumerator_t *data, iface_entry_t** in,
iface_entry_t** out)
{
- if (!(*in)->usable)
+ if (!(data->which & ADDR_TYPE_IGNORED) && !(*in)->usable)
{ /* skip interfaces excluded by config */
return FALSE;
}
- if (!data->include_loopback && ((*in)->flags & IFF_LOOPBACK))
+ if (!(data->which & ADDR_TYPE_LOOPBACK) && ((*in)->flags & IFF_LOOPBACK))
{ /* ignore loopback devices */
return FALSE;
}
- if (!data->include_down_ifaces && !((*in)->flags & IFF_UP))
- { /* skip interfaces not up */
+ if (!(data->which & ADDR_TYPE_DOWN) && !((*in)->flags & IFF_UP))
+ { /* skip interfaces not up */
return FALSE;
}
*out = *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_loopback)
+ private_kernel_pfroute_net_t *this, address_type_t which)
{
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;
+ data->which = which;
this->mutex->lock(this->mutex);
return enumerator_create_nested(