summaryrefslogtreecommitdiffstats
path: root/src/etc/inc/interfaces.inc
diff options
context:
space:
mode:
authorLuiz Otavio O Souza <luiz@netgate.com>2016-12-29 16:38:10 -0600
committerLuiz Otavio O Souza <luiz@netgate.com>2016-12-29 16:44:16 -0600
commite9de838d81b603a3c5077f984583cd7bb5278e85 (patch)
treea8e32e51b3d7377332e8731ece95139bffc6a43b /src/etc/inc/interfaces.inc
parent6522505ce70705243992cfab3cae4128a8516eac (diff)
downloadpfsense-e9de838d81b603a3c5077f984583cd7bb5278e85.zip
pfsense-e9de838d81b603a3c5077f984583cd7bb5278e85.tar.gz
Implement a different method to obtain the 'main' IP (v4) for the interface.
The last interface IP is always saved in /var/db/${interface}_ip. Use that file, if it exist, to find the main interface IP. The file is created by the same process and function that call 'ifconfig setfirst', so the presence of that file should produce a very similar behavior. If the file does not exist, fallback to previous behavior (return the first IPv4 found on interface). Ticket #7042
Diffstat (limited to 'src/etc/inc/interfaces.inc')
-rw-r--r--src/etc/inc/interfaces.inc20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc
index 58074fb..c1fe817 100644
--- a/src/etc/inc/interfaces.inc
+++ b/src/etc/inc/interfaces.inc
@@ -5228,9 +5228,23 @@ function find_interface_ip($interface, $flush = false) {
/* Setup IP cache */
if (!isset($interface_ip_arr_cache[$interface]) or $flush) {
- $ifinfo = pfSense_get_interface_addresses($interface);
- $interface_ip_arr_cache[$interface] = $ifinfo['ipaddr'];
- $interface_sn_arr_cache[$interface] = $ifinfo['subnetbits'];
+ if (file_exists("/var/db/${interface}_ip")) {
+ $ifip = chop(file_get_contents("/var/db/${interface}_ip"));
+ $ifaddrs = pfSense_getall_interface_addresses($interface);
+ foreach ($ifaddrs as $ifaddr) {
+ list($ip, $mask) = explode("/", $ifaddr);
+ if ($ip == $ifip) {
+ $interface_ip_arr_cache[$interface] = $ip;
+ $interface_sn_arr_cache[$interface] = $mask;
+ break;
+ }
+ }
+ }
+ if (!isset($interface_ip_arr_cache[$interface])) {
+ $ifinfo = pfSense_get_interface_addresses($interface);
+ $interface_ip_arr_cache[$interface] = $ifinfo['ipaddr'];
+ $interface_sn_arr_cache[$interface] = $ifinfo['subnetbits'];
+ }
}
return $interface_ip_arr_cache[$interface];
OpenPOWER on IntegriCloud