From b8beea435dc581cbbb6ee8a39d4a043bba379a7b Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 3 Feb 2020 07:27:43 -0300 Subject: [PATCH] dhcp: blacklist aliases in IPv6 case #3310 This code is probably relevant in other parts as well. --- src/etc/inc/plugins.inc.d/dhcpd.inc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/etc/inc/plugins.inc.d/dhcpd.inc b/src/etc/inc/plugins.inc.d/dhcpd.inc index c6d3ce24a..7d33ca35d 100644 --- a/src/etc/inc/plugins.inc.d/dhcpd.inc +++ b/src/etc/inc/plugins.inc.d/dhcpd.inc @@ -1,7 +1,7 @@ + * Copyright (C) 2014-2020 Franco Fichtner * Copyright (C) 2010 Ermal Luçi * Copyright (C) 2005-2006 Colin Smith * Copyright (C) 2003-2004 Manuel Kasper @@ -1419,9 +1419,27 @@ EOD; } $realif = get_real_interface($dhcpv6if, 'inet6'); + $ifcfgipv6 = $networkv6 = null; - $ifcfgipv6 = find_interface_ipv6($realif, $ifconfig_details); - $networkv6 = find_interface_networkv6($realif, true, $ifconfig_details); + foreach (interfaces_addresses($realif, true, $ifconfig_details) as $tmpaddr => $info) { + if ($info['family'] != 'inet6' || $info['scope']) { + /* only care about IPv6 without a scope set */ + continue; + } + + $addrparts = explode('/', $tmpaddr); + + foreach (config_read_array('virtualip', 'vip') as $vip) { + if ($vip['interface'] == $dhcpv6if && $vip['mode'] == 'ipalias' && $vip['subnet'] == $addrparts[0]) { + /* do not care about alias */ + continue 2; + } + } + + $networkv6 = gen_subnetv6($addrparts[0], $addrparts[1]) . "/{$addrparts[1]}"; + $ifcfgipv6 = $addrparts[0]; + break; /* all done */ + } if (!is_ipaddrv6($ifcfgipv6) || !is_subnetv6($networkv6)) { log_error("Warning! dhcpd_dhcp6_configure() found no suitable IPv6 address on {$dhcpv6if}");