mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 00:54:41 +00:00
interfaces: convert loopback for #5411
This commit is contained in:
parent
4641e84eb2
commit
83a2d2feeb
@ -763,7 +763,6 @@ function interfaces_configure($verbose = false)
|
||||
interfaces_vlan_configure($verbose);
|
||||
|
||||
/* XXX: temporary plugin spot for device creation (independent of other devices) */
|
||||
plugins_configure('loopback_prepare', $verbose);
|
||||
plugins_configure('openvpn_prepare', $verbose);
|
||||
|
||||
/* run through priority lists */
|
||||
|
||||
@ -28,26 +28,36 @@
|
||||
|
||||
function loopback_configure()
|
||||
{
|
||||
return array(
|
||||
'loopback_prepare' => array('loopback_configure_interface')
|
||||
);
|
||||
return [
|
||||
'loopback' => ['loopback_configure_do']
|
||||
];
|
||||
}
|
||||
|
||||
function loopback_devices()
|
||||
{
|
||||
$devices = array();
|
||||
$names = [];
|
||||
|
||||
$devices[] = array('pattern' => '^lo', 'volatile' => true, 'configurable' => true);
|
||||
foreach (iterator_to_array((new \OPNsense\Interfaces\Loopback())->loopback->iterateItems()) as $loopback) {
|
||||
$names[] = "lo{$loopback->deviceId}";
|
||||
}
|
||||
|
||||
return $devices;
|
||||
return [[
|
||||
'function' => 'loopback_configure_device',
|
||||
'configurable' => true,
|
||||
'pattern' => '^lo',
|
||||
'volatile' => true,
|
||||
'type' => 'loopback',
|
||||
'names' => $names,
|
||||
]];
|
||||
}
|
||||
|
||||
function loopback_configure_interface($verbose = false)
|
||||
function loopback_configure_do($verbose = false, $device = null)
|
||||
{
|
||||
$cnf = OPNsense\Core\Config::getInstance()->object();
|
||||
$configured_interfaces = legacy_interface_listget();
|
||||
$configured_devices = ['lo0']; // lo0 should always be configured
|
||||
$loopbacks = iterator_to_array((new \OPNsense\Interfaces\Loopback())->loopback->iterateItems());
|
||||
|
||||
if ($verbose && !empty($loopbacks)) {
|
||||
echo 'Configuring Loopback interfaces...';
|
||||
flush();
|
||||
@ -56,21 +66,32 @@ function loopback_configure_interface($verbose = false)
|
||||
// (re)configure loopback devices
|
||||
foreach ($loopbacks as $loopback) {
|
||||
$device_name = "lo{$loopback->deviceId}";
|
||||
|
||||
if ($device !== null && $device != $device_name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$configured_devices[] = $device_name;
|
||||
if (!in_array($device_name, $configured_interfaces)) {
|
||||
echo $device_name;
|
||||
mwexecf('/sbin/ifconfig %s create', array($device_name));
|
||||
mwexecf('/sbin/ifconfig %s create', [$device_name]);
|
||||
}
|
||||
}
|
||||
|
||||
// destroy non existing interfaces
|
||||
foreach ($configured_interfaces as $intf) {
|
||||
if (strpos($intf, "lo") === 0) {
|
||||
if (!in_array($intf, $configured_devices)) {
|
||||
mwexecf('/sbin/ifconfig %s destroy', array($intf));
|
||||
mwexecf('/sbin/ifconfig %s destroy', [$intf]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($verbose && !empty($loopbacks)) {
|
||||
echo "done.\n";
|
||||
}
|
||||
}
|
||||
|
||||
function loopback_configure_device($device)
|
||||
{
|
||||
loopback_configure_do(false, $device);
|
||||
}
|
||||
|
||||
@ -59,7 +59,6 @@ function vxlan_configure_do($verbose = false, $device = null)
|
||||
$configured_devices = array();
|
||||
$changed_devices = array();
|
||||
$vxlans = iterator_to_array((new \OPNsense\Interfaces\VxLan())->vxlan->iterateItems());
|
||||
$verbose = $device === null ? $verbose : false;
|
||||
|
||||
if ($verbose && !empty($vxlans)) {
|
||||
echo 'Configuring VXLAN interfaces...';
|
||||
|
||||
@ -121,7 +121,7 @@ message: Reconfiguring vlan
|
||||
type: script
|
||||
|
||||
[loopback.configure]
|
||||
command: /usr/local/sbin/pluginctl -c loopback_prepare
|
||||
command: /usr/local/sbin/pluginctl -c loopback
|
||||
message: Reconfiguring loopbacks
|
||||
type: script
|
||||
|
||||
|
||||
@ -83,9 +83,11 @@ if (isset($opts['h'])) {
|
||||
if (empty($args[0])) {
|
||||
echo $device['type'] . PHP_EOL;
|
||||
} elseif ($args[0] == $device['type']) {
|
||||
echo implode(PHP_EOL, $device['names']) . PHP_EOL;
|
||||
foreach ($device['names'] as $name) {
|
||||
echo $name . PHP_EOL;
|
||||
}
|
||||
} elseif (in_array($args[0], $device['names'])) {
|
||||
echo "Reconfiguring {$args[0]}...";
|
||||
echo "Reconfiguring {$args[0]}...";
|
||||
flush();
|
||||
call_user_func_array($device['function'], [$args[0]]);
|
||||
echo "done.\n";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user