Don't ignore loopback devices and allow addresses on them being enumerated
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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, ¤t))
|
||||
{
|
||||
@@ -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(
|
||||
|
||||
@@ -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, ¤t))
|
||||
|
||||
Reference in New Issue
Block a user