From 06bb115fce28b3f6d98a10a645d119c25fc7c834 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 18 May 2022 17:09:00 +0200 Subject: [PATCH] interfaces: add per-device worker to get rid of batch vxlan_prepare #5411 --- src/etc/inc/interfaces.inc | 6 --- src/etc/inc/plugins.inc.d/vxlan.inc | 39 +++++++++++++------ .../conf/actions.d/actions_interface.conf | 4 +- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index eebba09a3..ede393a94 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -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) { diff --git a/src/etc/inc/plugins.inc.d/vxlan.inc b/src/etc/inc/plugins.inc.d/vxlan.inc index 7427242e0..800adcdfa 100644 --- a/src/etc/inc/plugins.inc.d/vxlan.inc +++ b/src/etc/inc/plugins.inc.d/vxlan.inc @@ -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); +} diff --git a/src/opnsense/service/conf/actions.d/actions_interface.conf b/src/opnsense/service/conf/actions.d/actions_interface.conf index f2940e0c0..83a0daf7e 100644 --- a/src/opnsense/service/conf/actions.d/actions_interface.conf +++ b/src/opnsense/service/conf/actions.d/actions_interface.conf @@ -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]