Skip to content

Commit

Permalink
Revert "(legacy) remove cache stuff from find_interface_ip"
Browse files Browse the repository at this point in the history
This reverts commit bc6bbc4.
  • Loading branch information
fichtner committed Nov 25, 2015
1 parent a26d6c5 commit 7d00f8c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/etc/inc/gwlb.inc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ EOD;
* the if block. So using $gateway['ipprotocol'] is the better option.
*/
if ($gateway['ipprotocol'] == "inet") { // This is an IPv4 gateway...
$gwifip = find_interface_ip($gateway['interface']);
$gwifip = find_interface_ip($gateway['interface'], true);
if (!is_ipaddrv4($gwifip))
continue; //Skip this target

Expand Down
34 changes: 24 additions & 10 deletions src/etc/inc/interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,7 @@ function interface_vlan_adapt_mtu($vlanifs, $mtu) {
function interface_configure($interface = 'wan', $reloadall = false, $linkupevent = false)
{
global $config;
global $interface_sn_arr_cache;
global $interface_sn_arr_cache, $interface_ip_arr_cache;
global $interface_snv6_arr_cache, $interface_ipv6_arr_cache;

$wancfg = $config['interfaces'][$interface];
Expand Down Expand Up @@ -2956,6 +2956,7 @@ function interface_configure($interface = 'wan', $reloadall = false, $linkupeven
}

/* invalidate interface/ip/sn cache */
unset($interface_ip_arr_cache[$realif]);
unset($interface_sn_arr_cache[$realif]);
unset($interface_ipv6_arr_cache[$realif]);
unset($interface_snv6_arr_cache[$realif]);
Expand Down Expand Up @@ -4504,16 +4505,29 @@ function link_interface_to_gif($interface)
/*
* find_interface_ip($interface): return the interface ip (first found)
*/
function find_interface_ip($interface) {
$interface = trim($interface);
if (does_interface_exist($interface)) {
$ifinfo = pfSense_get_interface_addresses($interface);
if (isset($ifinfo['ipaddr'])) {
return $ifinfo['ipaddr'];
}
} else {
return null;
function find_interface_ip($interface, $flush = false) {
global $interface_ip_arr_cache;

if (!isset($interface_ip_arr_cache) || !is_array($interface_ip_arr_cache)) {
$interface_ip_arr_cache = array() ;
}

$interface = str_replace("\n", "", $interface);

if (!does_interface_exist($interface))
return;

/* Setup IP cache */
if (!isset($interface_ip_arr_cache[$interface]) or $flush) {
$ifinfo = pfSense_get_interface_addresses($interface);
if (isset($ifinfo['ipaddr'])) {
$interface_ip_arr_cache[$interface] = $ifinfo['ipaddr'];
} else {
return null;
}
}

return $interface_ip_arr_cache[$interface];
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/etc/rc.newwanip
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if (is_array($config['interfaces'][$interface]) && !isset($config['interfaces'][
if (empty($argument)) {
$curwanip = get_interface_ip();
} else {
$curwanip = find_interface_ip($interface_real);
$curwanip = find_interface_ip($interface_real, true);
if(empty($curwanip)) {
$curwanip = get_interface_ip($interface);
}
Expand Down
2 changes: 2 additions & 0 deletions src/www/carp_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ interface_carp_configure($vip);
}


unset($interface_arr_cache);
unset($carp_interface_count_cache);
unset($interface_ip_arr_cache);

$status = get_carp_status();
if ($_POST['carp_maintenancemode'] <> "") {
Expand Down

0 comments on commit 7d00f8c

Please sign in to comment.