interfaces: add per-device worker to get rid of batch vxlan_prepare #5411

This commit is contained in:
Franco Fichtner 2022-05-18 17:09:00 +02:00
parent 59ae67c55c
commit 06bb115fce
3 changed files with 30 additions and 19 deletions

View File

@ -731,11 +731,6 @@ function interfaces_configure($verbose = false)
$dhcp6c = []; /* dhcp6c interfaces load last */
foreach (legacy_config_get_interfaces(['enable' => true, 'virtual' => false]) as $if => $ifcfg) {
if (strstr($ifcfg['if'], 'vxlan')) {
// XXX device configuration is responsible for interface setup too when trying to init all.
continue;
}
/* XXX use this to figure out when bridges can be configured */
$interfaces[$if] = $ifcfg['if'];
@ -770,7 +765,6 @@ function interfaces_configure($verbose = false)
/* XXX: temporary plugin spot for device creation (independent of other devices) */
plugins_configure('loopback_prepare', $verbose);
plugins_configure('openvpn_prepare', $verbose);
plugins_configure('vxlan_prepare', $verbose);
/* run through priority lists */
foreach ([$hardware, $virtual, $track6, $bridge, $dhcp6c] as $list) {

View File

@ -29,8 +29,8 @@
function vxlan_configure()
{
return array(
'vxlan_prepare' => array('vxlan_configure_interface'),
'newwanip' => array('vxlan_configure_interface'),
'newwanip' => array('vxlan_configure_do'),
'vxlan' => array('vxlan_configure_do'),
);
}
@ -43,7 +43,7 @@ function vxlan_devices()
}
return [[
'function' => 'vxlan_configure_interface',
'function' => 'vxlan_configure_device',
'configurable' => true,
'pattern' => '^vxlan',
'volatile' => true,
@ -52,13 +52,15 @@ function vxlan_devices()
]];
}
function vxlan_configure_interface($verbose = false)
function vxlan_configure_do($verbose = false, $device = null)
{
$cnf = OPNsense\Core\Config::getInstance()->object();
$interfaces_details = legacy_interfaces_details();
$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...';
flush();
@ -77,18 +79,25 @@ function vxlan_configure_interface($verbose = false)
// (re)configure vxlan devices
foreach ($vxlans as $vxlan) {
$device_name = "vxlan{$vxlan->deviceId}";
if ($device !== null && $device != $device_name) {
continue;
}
if (!in_array((string)$vxlan->vxlanlocal, $known_addresses)) {
// skip when interface address is not assigned (yet)
continue;
}
$device_name = "vxlan{$vxlan->deviceId}";
$configured_devices[] = $device_name;
$current_settings = array(
"vxlanid" => null,
"vxlanlocal" => null,
"vxlanremote" => null,
"vxlangroup" => null
);
$current_settings = [
'vxlanid' => null,
'vxlanlocal' => null,
'vxlanremote' => null,
'vxlangroup' => null,
];
if (empty($interfaces_details[$device_name])) {
// new device
mwexecf('/sbin/ifconfig vxlan create name %s', array($device_name));
@ -126,6 +135,7 @@ function vxlan_configure_interface($verbose = false)
$changed_devices[] = $device_name;
}
}
// destroy non existing interfaces
foreach ($interfaces_details as $intf => $data) {
if (strpos($intf, "vxlan") === 0) {
@ -134,9 +144,11 @@ function vxlan_configure_interface($verbose = false)
}
}
}
if ($verbose && !empty($vxlans)) {
echo "done.\n";
}
// configure interface when device has changed
foreach ($changed_devices as $device_name) {
$friendly_if = convert_real_interface_to_friendly_interface_name($device_name);
@ -145,3 +157,8 @@ function vxlan_configure_interface($verbose = false)
}
}
}
function vxlan_configure_device($device)
{
vxlan_configure_do(false, $device);
}

View File

@ -111,8 +111,8 @@ type:script_output
message:list gateway status
[vxlan.configure]
command: /usr/local/sbin/pluginctl -c vxlan_prepare
message: Reconfiguring vxlan
command: /usr/local/sbin/pluginctl -c vxlan
message: Reconfiguring VXLAN
type: script
[vlan.configure]