system: make system_routing_configure() deal with interface maps

This commit is contained in:
Franco Fichtner 2024-09-12 22:13:26 +02:00
parent bb9353dba9
commit a85bd197c2
4 changed files with 19 additions and 31 deletions

View File

@ -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 */])

View File

@ -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
*/

View File

@ -1,7 +1,7 @@
<?php
/*
* Copyright (C) 2016-2023 Franco Fichtner <franco@opnsense.org>
* Copyright (C) 2016-2024 Franco Fichtner <franco@opnsense.org>
* Copyright (C) 2004-2007 Scott Ullrich <sullrich@gmail.com>
* Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>
* 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;
}
}

View File

@ -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();