From 07e1223e34adeec83a5ea02bedebceb0dbc1ad5d Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 12 Feb 2025 08:34:03 +0100 Subject: [PATCH] interfaces: move function to only caller --- src/etc/inc/interfaces.inc | 42 ----------------------------------- src/etc/rc.filter_synchronize | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 7eaaa96d1..01cf99001 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -3571,48 +3571,6 @@ function get_real_interface($interface = 'wan', $family = 'all') return $realif; } -function guess_interface_from_ip($ipaddress) -{ - if (is_ipaddrv4($ipaddress)) { - $family = "inet"; - } elseif (is_ipaddrv6($ipaddress)) { - $family = "inet6"; - } else { - return false; - } - - /* create a route table we can search */ - exec("/usr/bin/netstat -rnWf " . $family, $output, $ret); - - /* search for the route with the largest subnet mask */ - $largest_mask = 0; - $best_if = null; - - foreach ($output as $line) { - $fields = preg_split("/\s+/", $line); - if (is_subnet($fields[0])) { - if (ip_in_subnet($ipaddress, $fields[0])) { - list($ip, $mask) = explode('/', $fields[0]); - if ($mask > $largest_mask) { - $best_if = $fields[5]; - $largest_mask = $mask; - } - } - } - } - - if (!empty($best_if)) { - return $best_if; - } - - $ret = shell_safe('/sbin/route -n get %s | /usr/bin/awk \'/interface/ { print $2; };\'', $ipaddress); - if (empty($ret)) { - return false; - } - - return $ret; -} - function get_interface_number_track6($wanif, $targetif) { $list = link_interface_to_track6($wanif); diff --git a/src/etc/rc.filter_synchronize b/src/etc/rc.filter_synchronize index 1db86699c..cf0046776 100755 --- a/src/etc/rc.filter_synchronize +++ b/src/etc/rc.filter_synchronize @@ -40,6 +40,48 @@ require_once("XMLRPC_Client.inc"); exit_on_bootup(); +function guess_interface_from_ip($ipaddress) +{ + if (is_ipaddrv4($ipaddress)) { + $family = "inet"; + } elseif (is_ipaddrv6($ipaddress)) { + $family = "inet6"; + } else { + return false; + } + + /* create a route table we can search */ + exec("/usr/bin/netstat -rnWf " . $family, $output, $ret); + + /* search for the route with the largest subnet mask */ + $largest_mask = 0; + $best_if = null; + + foreach ($output as $line) { + $fields = preg_split("/\s+/", $line); + if (is_subnet($fields[0])) { + if (ip_in_subnet($ipaddress, $fields[0])) { + list($ip, $mask) = explode('/', $fields[0]); + if ($mask > $largest_mask) { + $best_if = $fields[5]; + $largest_mask = $mask; + } + } + } + } + + if (!empty($best_if)) { + return $best_if; + } + + $ret = shell_safe('/sbin/route -n get %s | /usr/bin/awk \'/interface/ { print $2; };\'', $ipaddress); + if (empty($ret)) { + return false; + } + + return $ret; +} + /** * fetch carp vips from config with modified advskew for the backup host to use * @return array