diff options
author | Luiz Otavio O Souza <luiz@netgate.com> | 2016-12-29 16:38:10 -0600 |
---|---|---|
committer | Luiz Otavio O Souza <luiz@netgate.com> | 2016-12-29 16:44:16 -0600 |
commit | e9de838d81b603a3c5077f984583cd7bb5278e85 (patch) | |
tree | a8e32e51b3d7377332e8731ece95139bffc6a43b /src/etc/inc/interfaces.inc | |
parent | 6522505ce70705243992cfab3cae4128a8516eac (diff) | |
download | pfsense-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.inc | 20 |
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]; |