}
METHOD(kernel_net_t, add_ip, status_t,
- private_kernel_android_net_t *this, host_t *virtual_ip, host_t *iface_ip)
+ private_kernel_android_net_t *this, host_t *virtual_ip, int prefix,
+ host_t *iface_ip)
{
/* we get the IP from the IKE_SA once the CHILD_SA is established */
return SUCCESS;
*/
static void reinstall_vip(host_t *vip, host_t *me)
{
- hydra->kernel_interface->del_ip(hydra->kernel_interface, vip);
- hydra->kernel_interface->add_ip(hydra->kernel_interface, vip, me);
+ hydra->kernel_interface->del_ip(hydra->kernel_interface, vip, -1);
+ hydra->kernel_interface->add_ip(hydra->kernel_interface, vip, -1, me);
}
METHOD(child_sa_t, update, status_t,
if (local)
{
DBG1(DBG_IKE, "installing new virtual IP %H", ip);
- if (hydra->kernel_interface->add_ip(hydra->kernel_interface, ip,
- this->my_host) == SUCCESS)
+ if (hydra->kernel_interface->add_ip(hydra->kernel_interface,
+ ip, -1, this->my_host) == SUCCESS)
{
this->my_vips->insert_last(this->my_vips, ip->clone(ip));
}
{
if (local)
{
- hydra->kernel_interface->del_ip(hydra->kernel_interface, vip);
+ hydra->kernel_interface->del_ip(hydra->kernel_interface, vip, -1);
}
vip->destroy(vip);
}
while (this->my_vips->remove_last(this->my_vips, (void**)&vip) == SUCCESS)
{
- hydra->kernel_interface->del_ip(hydra->kernel_interface, vip);
+ hydra->kernel_interface->del_ip(hydra->kernel_interface, vip, -1);
vip->destroy(vip);
}
this->my_vips->destroy(this->my_vips);
}
METHOD(kernel_interface_t, add_ip, status_t,
- private_kernel_interface_t *this, host_t *virtual_ip, host_t *iface_ip)
+ private_kernel_interface_t *this, host_t *virtual_ip, int prefix,
+ host_t *iface_ip)
{
if (!this->net)
{
return NOT_SUPPORTED;
}
- return this->net->add_ip(this->net, virtual_ip, iface_ip);
+ return this->net->add_ip(this->net, virtual_ip, prefix, iface_ip);
}
METHOD(kernel_interface_t, del_ip, status_t,
- private_kernel_interface_t *this, host_t *virtual_ip)
+ private_kernel_interface_t *this, host_t *virtual_ip, int prefix)
{
if (!this->net)
{
return NOT_SUPPORTED;
}
- return this->net->del_ip(this->net, virtual_ip);
+ return this->net->del_ip(this->net, virtual_ip, prefix);
}
METHOD(kernel_interface_t, add_route, status_t,
* The virtual IP is attached to the interface where the iface_ip is found.
*
* @param virtual_ip virtual ip address to assign
+ * @param prefix prefix length to install IP with, -1 for auto
* @param iface_ip IP of an interface to attach virtual IP
* @return SUCCESS if operation completed
*/
- status_t (*add_ip) (kernel_interface_t *this, host_t *virtual_ip,
+ status_t (*add_ip) (kernel_interface_t *this, host_t *virtual_ip, int prefix,
host_t *iface_ip);
/**
* The kernel interface uses refcounting, see add_ip().
*
* @param virtual_ip virtual ip address to assign
+ * @param prefix prefix length of the IP to uninstall, -1 for auto
* @return SUCCESS if operation completed
*/
- status_t (*del_ip) (kernel_interface_t *this, host_t *virtual_ip);
+ status_t (*del_ip) (kernel_interface_t *this, host_t *virtual_ip, int prefix);
/**
* Add a route.
* The virtual IP is attached to the interface where the iface_ip is found.
*
* @param virtual_ip virtual ip address to assign
+ * @param prefix prefix length to install with IP address, -1 for auto
* @param iface_ip IP of an interface to attach virtual IP
* @return SUCCESS if operation completed
*/
- status_t (*add_ip) (kernel_net_t *this, host_t *virtual_ip,
+ status_t (*add_ip) (kernel_net_t *this, host_t *virtual_ip, int prefix,
host_t *iface_ip);
/**
* The kernel interface uses refcounting, see add_ip().
*
* @param virtual_ip virtual ip address to assign
+ * @param prefix prefix length of the IP to uninstall, -1 for auto
* @return SUCCESS if operation completed
*/
- status_t (*del_ip) (kernel_net_t *this, host_t *virtual_ip);
+ status_t (*del_ip) (kernel_net_t *this, host_t *virtual_ip, int prefix);
/**
* Add a route.
* By setting the appropriate nlmsg_type, the ip will be set or unset.
*/
static status_t manage_ipaddr(private_kernel_netlink_net_t *this, int nlmsg_type,
- int flags, int if_index, host_t *ip)
+ int flags, int if_index, host_t *ip, int prefix)
{
netlink_buf_t request;
struct nlmsghdr *hdr;
msg = (struct ifaddrmsg*)NLMSG_DATA(hdr);
msg->ifa_family = ip->get_family(ip);
msg->ifa_flags = 0;
- msg->ifa_prefixlen = 8 * chunk.len;
+ msg->ifa_prefixlen = prefix < 0 ? chunk.len * 8 : prefix;
msg->ifa_scope = RT_SCOPE_UNIVERSE;
msg->ifa_index = if_index;
}
METHOD(kernel_net_t, add_ip, status_t,
- private_kernel_netlink_net_t *this, host_t *virtual_ip, host_t *iface_ip)
+ private_kernel_netlink_net_t *this, host_t *virtual_ip, int prefix,
+ host_t *iface_ip)
{
addr_map_entry_t *entry, lookup = {
.ip = virtual_ip,
iface->addrs->insert_last(iface->addrs, addr);
addr_map_entry_add(this->vips, addr, iface);
if (manage_ipaddr(this, RTM_NEWADDR, NLM_F_CREATE | NLM_F_EXCL,
- iface->ifindex, virtual_ip) == SUCCESS)
+ iface->ifindex, virtual_ip, prefix) == SUCCESS)
{
while (!is_vip_installed_or_gone(this, virtual_ip, &entry))
{ /* wait until address appears */
}
METHOD(kernel_net_t, del_ip, status_t,
- private_kernel_netlink_net_t *this, host_t *virtual_ip)
+ private_kernel_netlink_net_t *this, host_t *virtual_ip, int prefix)
{
addr_map_entry_t *entry, lookup = {
.ip = virtual_ip,
* until the entry is gone, also so we can wait below */
entry->addr->installed = FALSE;
status = manage_ipaddr(this, RTM_DELADDR, 0, entry->iface->ifindex,
- virtual_ip);
+ virtual_ip, prefix);
if (status == SUCCESS)
{ /* wait until the address is really gone */
while (is_known_vip(this, virtual_ip))
}
METHOD(kernel_net_t, add_ip, status_t,
- private_kernel_pfroute_net_t *this, host_t *virtual_ip, host_t *iface_ip)
+ private_kernel_pfroute_net_t *this, host_t *virtual_ip, int prefix,
+ host_t *iface_ip)
{
return FAILED;
}
METHOD(kernel_net_t, del_ip, status_t,
- private_kernel_pfroute_net_t *this, host_t *virtual_ip)
+ private_kernel_pfroute_net_t *this, host_t *virtual_ip, int prefix)
{
return FAILED;
}