From 6fb26a17c19d66033320debb863c0a7c9a3499aa Mon Sep 17 00:00:00 2001 From: smos Date: Mon, 19 Nov 2012 09:40:17 +0100 Subject: Add IPv6 support to this function so that IPv6 carp vips can be found --- etc/inc/interfaces.inc | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index d4a4483..a10eacd 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -3851,28 +3851,40 @@ function find_carp_interface($ip) { } function link_carp_interface_to_parent($interface) { - global $config; + global $config; - if ($interface == "") - return; + if ($interface == "") + return; - $carp_ip = get_interface_ip($interface); - if (!is_ipaddr($carp_ip)) - return; + $carp_ip = get_interface_ip($interface); + $carp_ipv6 = get_interface_ipv6($interface); - /* if list */ - $ifdescrs = get_configured_interface_list(); - foreach ($ifdescrs as $ifdescr => $ifname) { - $interfaceip = get_interface_ip($ifname); - $subnet_bits = get_interface_subnet($ifname); - $subnet_ip = gen_subnet("{$interfaceip}", "{$subnet_bits}"); - if(ip_in_subnet($carp_ip, "{$subnet_ip}/{$subnet_bits}")) - return $ifname; - } + if((!is_ipaddrv4($carp_ip)) && (!is_ipaddrv6($carp_ipv6))) + return; - return ""; + /* if list */ + $ifdescrs = get_configured_interface_list(); + foreach ($ifdescrs as $ifdescr => $ifname) { + /* check IPv4 */ + if(is_ipaddrv4($carp_ip)) { + $interfaceip = get_interface_ip($ifname); + $subnet_bits = get_interface_subnet($ifname); + $subnet_ip = gen_subnet("{$interfaceip}", "{$subnet_bits}"); + if(ip_in_subnet($carp_ip, "{$subnet_ip}/{$subnet_bits}")) + return $ifname; + } + /* Check IPv6 */ + if(is_ipaddrv6($carp_ipv6)) { + $interfaceipv6 = get_interface_ipv6($ifname); + $prefixlen = get_interface_subnetv6($ifname); + if(ip_in_subnet($carp_ipv6, "{$interfaceipv6}/{$prefixlen}")) + return $ifname; + } + } + return ""; } + /****f* interfaces/link_ip_to_carp_interface * NAME * link_ip_to_carp_interface - Find where a CARP interface links to. -- cgit v1.1