Make it easy to check if an address is locally usable via changed get_interface() method

This commit is contained in:
Tobias Brunner
2012-09-21 18:16:26 +02:00
parent aed33805ce
commit 9ba36c0f7f
10 changed files with 64 additions and 67 deletions
@@ -2169,14 +2169,13 @@ static status_t add_policy_internal(private_kernel_netlink_ipsec_t *this,
route->gateway = hydra->kernel_interface->get_nexthop(
hydra->kernel_interface, ipsec->src,
ipsec->dst);
/* install route via outgoing interface */
route->if_name = hydra->kernel_interface->get_interface(
hydra->kernel_interface, ipsec->dst);
route->dst_net = chunk_alloc(policy->sel.family == AF_INET ? 4 : 16);
memcpy(route->dst_net.ptr, &policy->sel.saddr, route->dst_net.len);
route->prefixlen = policy->sel.prefixlen_s;
if (!route->if_name)
/* install route via outgoing interface */
if (!hydra->kernel_interface->get_interface(hydra->kernel_interface,
ipsec->dst, &route->if_name))
{
this->mutex->unlock(this->mutex);
route_entry_destroy(route);
@@ -365,13 +365,15 @@ static job_requeue_t reinstall_routes(private_kernel_netlink_net_t *this)
change = this->net_changes->get(this->net_changes, &lookup);
if (!change)
{ /* in case src_ip is not on the outgoing interface */
lookup.if_name = this->public.interface.get_interface(
&this->public.interface, route->src_ip);
if (lookup.if_name && !streq(lookup.if_name, route->if_name))
if (this->public.interface.get_interface(&this->public.interface,
route->src_ip, &lookup.if_name))
{
change = this->net_changes->get(this->net_changes, &lookup);
if (!streq(lookup.if_name, route->if_name))
{
change = this->net_changes->get(this->net_changes, &lookup);
}
free(lookup.if_name);
}
free(lookup.if_name);
}
if (change)
{
@@ -999,15 +1001,13 @@ METHOD(kernel_net_t, create_address_enumerator, enumerator_t*,
(void*)address_enumerator_destroy);
}
METHOD(kernel_net_t, get_interface_name, char*,
private_kernel_netlink_net_t *this, host_t* ip)
METHOD(kernel_net_t, get_interface_name, bool,
private_kernel_netlink_net_t *this, host_t* ip, char **name)
{
enumerator_t *ifaces, *addrs;
iface_entry_t *iface;
addr_entry_t *addr;
char *name = NULL;
DBG2(DBG_KNL, "getting interface name for %H", ip);
bool found = FALSE;
this->mutex->lock(this->mutex);
ifaces = this->ifaces->create_enumerator(this->ifaces);
@@ -1018,12 +1018,16 @@ METHOD(kernel_net_t, get_interface_name, char*,
{
if (ip->ip_equals(ip, addr->ip))
{
name = strdup(iface->ifname);
found = TRUE;
if (name)
{
*name = strdup(iface->ifname);
}
break;
}
}
addrs->destroy(addrs);
if (name)
if (found)
{
break;
}
@@ -1031,15 +1035,15 @@ METHOD(kernel_net_t, get_interface_name, char*,
ifaces->destroy(ifaces);
this->mutex->unlock(this->mutex);
if (name)
{
DBG2(DBG_KNL, "%H is on interface %s", ip, name);
}
else
if (!found)
{
DBG2(DBG_KNL, "%H is not a local address", ip);
}
return name;
else if (name)
{
DBG2(DBG_KNL, "%H is on interface %s", ip, *name);
}
return found;
}
/**