diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 7da4031d3..db2bc3f19 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -3779,12 +3779,13 @@ function interfaces_restart_by_device($verbose, $devices, $reconfigure = true) } } - foreach (array_keys($restartifs) as $ifname) { - if ($reconfigure) { + if ($reconfigure) { + foreach (array_keys($restartifs) as $ifname) { interface_configure($verbose, $ifname); } - system_routing_configure($verbose, $ifname); } + + system_routing_configure($verbose, array_keys($restartifs)); } function link_interface_to_bridge($interface, $attach_device = null, $ifconfig_details = [/* must be set for attach to work */]) diff --git a/src/etc/inc/plugins.inc.d/core.inc b/src/etc/inc/plugins.inc.d/core.inc index 1597098d4..b9c435c04 100644 --- a/src/etc/inc/plugins.inc.d/core.inc +++ b/src/etc/inc/plugins.inc.d/core.inc @@ -465,7 +465,7 @@ function core_configure() /* XXX these are all specialized and try to avoid extra script use */ 'dns_reload' => ['system_resolver_configure'], 'firmware_reload' => ['system_firmware_configure'], - 'route_reload' => ['core_routing_batch:2'], + 'route_reload' => ['system_routing_configure:2'], 'syslog_reset' => ['system_syslog_reset'], 'trust_reload' => ['system_trust_configure'], 'user_changed' => ['core_user_changed_groups:2'], @@ -480,17 +480,6 @@ function core_run() ]; } -function core_routing_batch($verbose, $interfaces = [null]) -{ - if (!is_array($interfaces)) { - $interfaces = [$interfaces]; - } - - foreach ($interfaces as $interface) { - system_routing_configure($verbose, $interface); - } -} - /** * user changed event, synchronize attached system groups for requested user */ diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index ef76a5629..49cc19eaa 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -1,7 +1,7 @@ + * Copyright (C) 2016-2024 Franco Fichtner * Copyright (C) 2004-2007 Scott Ullrich * Copyright (C) 2003-2004 Manuel Kasper * All rights reserved. @@ -649,18 +649,18 @@ function system_default_route($gw, $routes) mwexecf('/sbin/route add -%s default %s', [$family, $gateway]); } -function system_routing_configure($verbose = false, $interface = null, $monitor = true, $family = null) +function system_routing_configure($verbose = false, $interface_map = null, $monitor = true, $family = null) { global $config; - service_log(sprintf('Setting up routes%s...', empty($interface) ? '' : " for {$interface}"), $verbose); - - if (!empty($interface)) { - log_msg("ROUTING: entering configure using '{$interface}'", LOG_DEBUG); - } else { - log_msg("ROUTING: entering configure using defaults", LOG_DEBUG); + if (!plugins_argument_map($interface_map)) { + return; } + log_msg(sprintf('ROUTING: entering configure using %s', empty($interface_map) ? 'defaults' : join(', ', $interface_map)), LOG_DEBUG); + + service_log(sprintf('Setting up routes%s...', empty($interface_map) ? '' : ' for ' . join(', ', $interface_map)), $verbose); + $ifdetails = legacy_interfaces_details(); $gateways = new \OPNsense\Routing\Gateways(); $down_gateways = isset($config['system']['gw_switch_default']) ? return_down_gateways() : []; @@ -670,7 +670,7 @@ function system_routing_configure($verbose = false, $interface = null, $monitor /* check if we need to add a required interface route to the gateway (IPv4 only) */ if ($gateway['ipprotocol'] !== 'inet' || ($family !== null && $family !== 'inet')) { continue; - } elseif (!empty($interface) && $interface != $gateway['interface']) { + } elseif (!empty($interface_map) && !in_array($gateway['interface'], $interface_map)) { continue; } @@ -696,7 +696,7 @@ function system_routing_configure($verbose = false, $interface = null, $monitor continue; } - if (isset($config['system']['gw_switch_default']) || empty($interface) || $interface == $gateway['interface']) { + if (isset($config['system']['gw_switch_default']) || empty($interface_map) || in_array($gateway['interface'], $interface_map)) { if (empty($ifdetails[$gateway['if']][$type][0])) { log_msg("ROUTING: refusing to set {$ipproto} gateway on addressless {$gateway['interface']}({$gateway['if']})", LOG_ERR); continue; @@ -717,7 +717,7 @@ function system_routing_configure($verbose = false, $interface = null, $monitor continue; } $gateway = $gateways_arr[$rtent['gateway']]; - if (!empty($interface) && $interface != $gateway['interface']) { + if (!empty($interface_map) && !in_array($gateway['interface'], $interface_map)) { continue; } @@ -774,7 +774,7 @@ function system_routing_configure($verbose = false, $interface = null, $monitor service_log("done.\n", $verbose); if ($monitor) { - if (!empty($interface)) { + if (!empty($interface_map)) { $reloads = []; foreach ($gateways->gatewaysIndexedByName() as $name => $gateway) { @@ -782,7 +782,7 @@ function system_routing_configure($verbose = false, $interface = null, $monitor continue; } - if ($interface == $gateway['interface']) { + if (in_array($gateway['interface'], $interface_map)) { $reloads[] = $name; } } diff --git a/src/etc/rc.newwanipv6 b/src/etc/rc.newwanipv6 index 1ed7f7062..178815c2a 100755 --- a/src/etc/rc.newwanipv6 +++ b/src/etc/rc.newwanipv6 @@ -120,9 +120,7 @@ interfaces_restart_by_device(false, array_merge($greifs, $gififs)); $interfaces = array_keys(link_interface_to_track6($interface, true)); array_unshift($interfaces, $interface); -foreach ($interfaces as $interface) { - system_routing_configure(false, $interface, true, 'inet6'); -} +system_routing_configure(false, $interfaces, true, 'inet6'); filter_configure_sync();