Skip to content

Commit

Permalink
interfaces: second step -- deduplicate code
Browse files Browse the repository at this point in the history
While here we can actually flip over the ifdisabled bit for SLAAC
trackers.  And rename ominous $linkupevent and $linkdownevent flags.
  • Loading branch information
fichtner committed Feb 2, 2022
1 parent a7e3d36 commit f5b2d20
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2535,7 +2535,7 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal
interfaces_staticarp_configure($interface);
}

function interface_track6_configure($interface = 'lan', $lancfg, $linkupevent = false)
function interface_track6_configure($interface = 'lan', $lancfg, $restart = false)
{
global $config;

Expand All @@ -2549,22 +2549,6 @@ function interface_track6_configure($interface = 'lan', $lancfg, $linkupevent =
return;
}

if (!isset($lancfg['enable'])) {
switch ($trackcfg['ipaddrv6']) {
/* deconfiguring 6to4 and 6rd is done elsewhere as it simply removes addresses */
case 'slaac':
case 'dhcp6':
interface_dhcpv6_prepare($lancfg['track6-interface'], $trackcfg);
killbypid('/var/run/dhcp6c.pid', 'HUP');
break;
default:
break;
}

/* exit now as there are only linkup-related bits following */
return;
}

switch ($trackcfg['ipaddrv6']) {
case '6to4':
interface_track6_6to4_configure($interface, $lancfg);
Expand All @@ -2573,28 +2557,29 @@ function interface_track6_configure($interface = 'lan', $lancfg, $linkupevent =
interface_track6_6rd_configure($interface, $lancfg);
break;
case 'slaac':
interface_track6_slaac_configure($interface, $lancfg);
mwexecf('/sbin/ifconfig %s inet6 accept_rtadv %sifdisabled', [
get_real_interface($interface, 'inet6'),
isset($lancfg['enable']) ? '-' : '',
]);
/* FALLTHROUGH */
case 'dhcp6':
if ($linkupevent) {
if ($restart || !isset($lancfg['enable'])) {
interface_dhcpv6_prepare($lancfg['track6-interface'], $trackcfg);
killbypid('/var/run/dhcp6c.pid', 'HUP');
}
break;
}
}

function interface_track6_slaac_configure($interface = 'lan', $lancfg)
{
$realifv6 = get_real_interface($interface, 'inet6');
log_error("Accept router advertisements on interface {$realifv6}");
mwexecf('/sbin/ifconfig %s inet6 accept_rtadv -ifdisabled', $realifv6);
}

function interface_track6_6rd_configure($interface = 'lan', $lancfg)
{
global $config;

if (!isset($lancfg['enable'])) {
/* deconfiguring is done elsewhere as it simply removes addresses */
return;
}

$wancfg = $config['interfaces'][$lancfg['track6-interface']];

if (empty($wancfg)) {
Expand Down Expand Up @@ -2647,6 +2632,11 @@ function interface_track6_6rd_configure($interface = 'lan', $lancfg)

function interface_track6_6to4_configure($interface = 'lan', $lancfg)
{
if (!isset($lancfg['enable'])) {
/* deconfiguring is done elsewhere as it simply removes addresses */
return;
}

$ip4address = get_interface_ip($lancfg['track6-interface']);

if (!is_ipaddrv4($ip4address) || is_private_ip($ip4address)) {
Expand Down Expand Up @@ -2920,7 +2910,7 @@ function interface_dhcpv6_id($interface)
return $id;
}

function interface_dhcpv6_prepare($interface = 'wan', $wancfg, $linkdownevent = false)
function interface_dhcpv6_prepare($interface = 'wan', $wancfg, $cleanup = false)
{
if (!is_array($wancfg)) {
return;
Expand Down Expand Up @@ -2948,7 +2938,7 @@ function interface_dhcpv6_prepare($interface = 'wan', $wancfg, $linkdownevent =
}
}

if (!$linkdownevent) {
if (!$cleanup) {
@file_put_contents("/var/etc/dhcp6c_{$interface}.conf", $dhcp6cconf);
} else {
@unlink("/var/etc/dhcp6c_{$interface}.conf");
Expand Down

0 comments on commit f5b2d20

Please sign in to comment.