aboutsummaryrefslogtreecommitdiffstats
path: root/src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2012-11-09 15:46:58 +0100
committerMartin Willi <martin@revosec.ch>2012-11-29 10:22:51 +0100
commit50bd755871fefa59857510a620ae66c1400577df (patch)
tree925ee7840a14417ad03cb0dbce1bb0eb98d7bb43 /src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
parentfdd94fc846ca2057ab2994e92e712da63f760580 (diff)
downloadstrongswan-50bd755871fefa59857510a620ae66c1400577df.tar.bz2
strongswan-50bd755871fefa59857510a620ae66c1400577df.tar.xz
Add an optional kernel-interface parameter to install IPs with a custom prefix
Diffstat (limited to 'src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c')
-rw-r--r--src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c b/src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
index 7653d470c..7db51fc85 100644
--- a/src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
+++ b/src/libhydra/plugins/kernel_netlink/kernel_netlink_net.c
@@ -1634,7 +1634,7 @@ METHOD(kernel_net_t, get_nexthop, host_t*,
* 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;
@@ -1653,7 +1653,7 @@ static status_t manage_ipaddr(private_kernel_netlink_net_t *this, int nlmsg_type
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;
@@ -1663,7 +1663,8 @@ static status_t manage_ipaddr(private_kernel_netlink_net_t *this, int nlmsg_type
}
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,
@@ -1738,7 +1739,7 @@ METHOD(kernel_net_t, add_ip, status_t,
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 */
@@ -1763,7 +1764,7 @@ METHOD(kernel_net_t, add_ip, status_t,
}
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,
@@ -1802,7 +1803,7 @@ METHOD(kernel_net_t, del_ip, status_t,
* 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))