Skip to content

Commit

Permalink
interfaces: a bit for #4622
Browse files Browse the repository at this point in the history
Make sure address deletion works for IPv4 and IPv6 always.
  • Loading branch information
fichtner committed Jan 21, 2021
1 parent 0ae7e39 commit 00e6895
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
52 changes: 20 additions & 32 deletions src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -959,19 +959,13 @@ function interface_vip_bring_down($vip)
killbypid("/var/run/choparp_{$vipif}.pid");
break;
case 'ipalias':
if (does_interface_exist($vipif)) {
if (is_ipaddrv6($vip['subnet'])) {
mwexec("/sbin/ifconfig {$vipif} inet6 " . escapeshellarg($vip['subnet']) . " -alias");
} else {
legacy_interface_deladdress($vipif, $vip['subnet']);
}
}
break;
case 'carp':
if (does_interface_exist($vipif)) {
legacy_interface_deladdress($vipif, $vip['subnet']);
legacy_interface_deladdress($vipif, $vip['subnet'], is_ipaddrv6($vip['subnet']) ? 6 : 4);
}
break;
default:
break;
}
}

Expand Down Expand Up @@ -1656,17 +1650,18 @@ function interface_ipalias_configure(&$vip)
}

if (is_ipaddrv6($vip['subnet'])) {
$if = escapeshellarg(get_real_interface($vip['interface'], 'inet6'));
$if = get_real_interface($vip['interface'], 'inet6');
$af = 'inet6';
} else {
$if = escapeshellarg(get_real_interface($vip['interface']));
$if = get_real_interface($vip['interface']);
$af = 'inet';
}

$vhid = !empty($vip['vhid']) ? 'vhid ' . escapeshellarg($vip['vhid']) : '';
$gateway = !empty($vip['gateway']) ? escapeshellarg($vip['gateway']) . ' ' : '';

mwexec("/sbin/ifconfig " . $if . " {$af} " . escapeshellarg($vip['subnet']) . "/" . escapeshellarg($vip['subnet_bits']) . " alias " . $gateway . $vhid);
/* XXX use legacy_interface_setaddress */
mwexec("/sbin/ifconfig " . escapeshellarg($if). " {$af} " . escapeshellarg($vip['subnet']) . "/" . escapeshellarg($vip['subnet_bits']) . " alias " . $gateway . $vhid);
}

function interface_carp_configure(&$vip)
Expand All @@ -1677,18 +1672,11 @@ function interface_carp_configure(&$vip)
return;
}

// when CARP is temporary disabled, don't try to configure on any interface-up events
/* when CARP is temporary disabled do not try to configure on any interface up events */
if (get_single_sysctl('net.inet.carp.allow') == '0') {
return;
}

/* NOTE: Maybe its useless nowdays */
$realif = get_real_interface($vip['interface']);
if (!does_interface_exist($realif)) {
file_notice(sprintf(gettext("Interface specified for the virtual IP address %s does not exist. Skipping this VIP."), $vip['subnet']));
return;
}

$vip_password = $vip['password'];
$vip_password = escapeshellarg(addslashes(str_replace(" ", "", $vip_password)));
if ($vip['password'] != "") {
Expand All @@ -1704,6 +1692,7 @@ function interface_carp_configure(&$vip)

mwexec("/sbin/ifconfig {$realif} vhid " . escapeshellarg($vip['vhid']) . " {$advskew} {$advbase} {$password}");

/* XXX use legacy_interface_setaddress */
if (is_ipaddrv4($vip['subnet'])) {
mwexec("/sbin/ifconfig {$realif} " . escapeshellarg($vip['subnet']) . "/" . escapeshellarg($vip['subnet_bits']) . " alias vhid " . escapeshellarg($vip['vhid']));
} elseif (is_ipaddrv6($vip['subnet'])) {
Expand Down Expand Up @@ -2341,19 +2330,18 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal
if (!file_exists("/var/run/booting") && !(substr($realif, 0, 4) == "ovpn")) {
/* remove all IPv4 and IPv6 addresses */
foreach (array_keys(interfaces_addresses($realif, true)) as $tmpiface) {
if (is_ipaddrv6($tmpiface) || is_subnetv6($tmpiface)) {
if (!is_linklocal($tmpiface)) {
mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 {$tmpiface} delete");
}
} else {
if (is_subnetv4($tmpiface)) {
$tmpip = explode('/', $tmpiface);
$tmpip = $tmpip[0];
} else {
$tmpip = $tmpiface;
}
legacy_interface_deladdress($realif, $tmpip);
$tmpip = $tmpiface;
$family = 4;

if (is_linklocal($tmpip)) {
continue;
} elseif (is_ipaddrv6($tmpip) || is_subnetv6($tmpip)) {
$family = 6;
} elseif (is_subnetv4($tmpiface)) {
$tmpip = explode('/', $tmpiface)[0];
}

legacy_interface_deladdress($realif, $tmpip, $family);
}

/* only bring down the interface when both v4 and v6 are set to NONE */
Expand Down
8 changes: 4 additions & 4 deletions src/etc/inc/interfaces.lib.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ function legacy_interface_destroy($ifs)
}
}

function legacy_interface_setaddress($ifs, $addr)
function legacy_interface_setaddress($ifs, $addr, $family = 4)
{
$cmd = '/sbin/ifconfig ' . escapeshellarg($ifs) . ' alias ' . escapeshellarg($addr);
$cmd = implode(' ', ['/sbin/ifconfig', escapeshellarg($ifs), $family == 6 ? 'inet6' : 'inet', escapeshellarg($addr), 'alias']);

exec($cmd . ' 2>&1', $out, $ret);
if ($ret) {
log_error('The command `' . $cmd . '\' failed to execute');
}
}

function legacy_interface_deladdress($ifs, $addr)
function legacy_interface_deladdress($ifs, $addr, $family = 4)
{
$cmd = '/sbin/ifconfig ' . escapeshellarg($ifs) . ' -alias ' . escapeshellarg($addr);
$cmd = implode(' ', ['/sbin/ifconfig', escapeshellarg($ifs), $family == 6 ? 'inet6' : 'inet', escapeshellarg($addr), '-alias']);

exec($cmd . ' 2>&1', $out, $ret);
if ($ret) {
Expand Down

1 comment on commit 00e6895

@lattera
Copy link
Contributor

@lattera lattera commented on 00e6895 Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something about this commit in particular that breaks CARP. The CARP VIP ends up not being applied to an interface. I'm working now to determine which particular change in this commit causes the regression. Later today, I hope to submit a PR unless you know off-hand what's wrong.

# ifconfig vtnet1
vtnet1: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=80028<VLAN_MTU,JUMBO_MTU,LINKSTATE>
        ether 00:a0:98:08:3a:72
        inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255
        inet6 fe80::2a0:98ff:fe08:3a72%vtnet1 prefixlen 64 scopeid 0x2
        media: Ethernet 10Gbase-T <full-duplex>
        status: active
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

I should see the CARP IP as MASTER in that ifconfig output.

Configuration attached to this comment:

config-blackhawk-01.localdomain-20210303214411.xml.txt

Please sign in to comment.