Skip to content

Commit

Permalink
interfaces: decouple PPP configure/reset from IPv4/IPv6 modes #7446
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Aug 12, 2024
1 parent 3a9f988 commit 182bab3
Showing 1 changed file with 57 additions and 58 deletions.
115 changes: 57 additions & 58 deletions src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -858,23 +858,6 @@ function interface_reset($interface, $ifacecfg = false, $suspend = false)
}

switch ($ifcfg['ipaddr'] ?? 'none') {
case 'ppp':
case 'pppoe':
case 'pptp':
case 'l2tp':
if (!empty($ppps)) {
foreach ($ppps as $ppp) {
if ($ifcfg['if'] == $ppp['if']) {
if (isset($ppp['ondemand']) && $suspend) {
configdp_run('interface reconfigure', [$interface], true);
} else {
killbypid("/var/run/{$ppp['type']}_{$interface}.pid");
}
break;
}
}
}
break;
case 'dhcp':
killbypid("/var/run/dhclient.{$realif}.pid");
break;
Expand All @@ -894,6 +877,9 @@ function interface_reset($interface, $ifacecfg = false, $suspend = false)
}
}

/* check reset of running PPP configuration inside function */
interface_ppps_reset($interface, $suspend, $ifcfg, $ppps);

/* clear stale state associated with this interface */
mwexecf('/usr/local/sbin/ifctl -4c -i %s', $realif);
mwexecf('/usr/local/sbin/ifctl -6c -i %s', $realifv6);
Expand Down Expand Up @@ -971,15 +957,56 @@ function interface_ppps_capable($ifcfg, $ppps)
return false;
}

function interface_ppps_hardware($device)
{
$devices = [$device];

foreach (config_read_array('ppps', 'ppp') as $ppp) {
if ($device == $ppp['if']) {
$devices = [];
foreach (explode(',', $ppp['ports']) as $port) {
/*
* XXX We only have get_real_interface() here because
* PPP may be assigned to an assigned interface! :(
*/
$devices[] = get_real_interface($port);
}
break;
}
}

return $devices;
}

function interface_ppps_reset($interface, $suspend, $ifcfg, $ppps)
{
if (!interface_ppps_capable($ifcfg, $ppps)) {
return;
}

foreach ($ppps as $ppp) {
if ($ifcfg['if'] == $ppp['if']) {
if (isset($ppp['ondemand']) && $suspend) {
configdp_run('interface reconfigure', [$interface], true);
} else {
killbypid("/var/run/{$ppp['type']}_{$interface}.pid");
}
break;
}
}
}

function interface_ppps_configure($interface)
{
global $config;

/* Return for unassigned interfaces. This is a minimum requirement. */
if (empty($config['interfaces'][$interface])) {
$ifcfg = $config['interfaces'][$interface] ?? null;
$ppps = $config['ppps']['ppp'] ?? null;

if (!interface_ppps_capable($ifcfg, $ppps)) {
return;
}
$ifcfg = $config['interfaces'][$interface];

if (!isset($ifcfg['enable'])) {
return;
}
Expand Down Expand Up @@ -1017,12 +1044,10 @@ function interface_ppps_configure($interface)

$ppp = null;

if (isset($config['ppps']['ppp'])) {
foreach ($config['ppps']['ppp'] as $tmp) {
if ($ifcfg['if'] == $tmp['if']) {
$ppp = $tmp;
break;
}
foreach ($ppps as $tmp) {
if ($ifcfg['if'] == $tmp['if']) {
$ppp = $tmp;
break;
}
}

Expand Down Expand Up @@ -2258,19 +2283,8 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal
$realif = get_real_interface($interface);
$realifv6 = get_real_interface($interface, 'inet6');

switch ($wancfg['ipaddr'] ?? 'none') {
case 'l2tp':
case 'ppp':
case 'pppoe':
case 'pptp':
/* hardware device underneath software node */
$realhwif = get_ppp_parent($realif);
break;
default:
/* hardware device remains a hardware device */
$realhwif = $realif;
break;
}
/* get the correct hardware interface if PPP is involved or return the one we have */
$realhwif = interface_ppps_hardware($realif)[0]; /* XXX support all MLPPP devices */

if ($reload) {
foreach (plugins_devices() as $device) {
Expand Down Expand Up @@ -2352,16 +2366,13 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal
interface_configure_mtu($realhwif, $wancfg['mtu'], $ifconfig_details);
}

/* since the connectivity can include IPv4 and/or IPv6 let the function decide */
interface_ppps_configure($interface);

switch ($wancfg['ipaddr'] ?? 'none') {
case 'dhcp':
interface_dhcp_configure($interface);
break;
case 'l2tp':
case 'ppp':
case 'pppoe':
case 'pptp':
interface_ppps_configure($interface);
break;
default:
interface_static_configure($interface, $wancfg);
break;
Expand Down Expand Up @@ -3497,18 +3508,6 @@ function convert_friendly_interface_to_friendly_descr($interface)
return $ifdesc;
}

function get_ppp_parent($ifcfg_if)
{
foreach (config_read_array('ppps', 'ppp') as $ppp) {
if ($ifcfg_if == $ppp['if']) {
$ports = explode(',', $ppp['ports']);
return get_real_interface($ports[0]);
}
}

return null;
}

/* collect hardware device parents for VLAN, LAGG and bridges */
function interface_parent_devices($device, $as_interface = false)
{
Expand Down Expand Up @@ -3604,7 +3603,7 @@ function get_real_interface($interface = 'wan', $family = 'all')
case 'pppoe':
case 'pptp':
/* except for "ppp" all have parent interfaces */
$realif = get_ppp_parent($realif);
$realif = interface_ppps_hardware($realif)[0];
break;
default:
break;
Expand Down

0 comments on commit 182bab3

Please sign in to comment.