From 5420820f8bd504e2d886fe40796d2b3f7ec6778a Mon Sep 17 00:00:00 2001 From: Luiz Otavio O Souza Date: Tue, 9 Feb 2016 09:30:24 -0600 Subject: Fix get_interface_ip[v6]() to try first the IP from our configuration before ask the kernel. The OS will return the first IP it find for the interface and not necessarily the main IP address. This can cause conflicts where get_interface_ip[v6]() returns a CARP or IP alias for the interface (missing the real IP and generating a duplicated IP address). --- src/etc/inc/interfaces.inc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index dc984fd..05945d3 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -5312,6 +5312,16 @@ function get_interface_ip($interface = "wan") { return null; } + if (is_array($config['interfaces'][$interface]) && + is_ipaddr($config['interfaces'][$interface]['ipaddr'])) { + return ($config['interfaces'][$interface]['ipaddr']); + } + + /* + * Beaware that find_interface_ip() is our last option, it will + * return the first IP it find on interface, not necessarily the + * main IP address. + */ $curip = find_interface_ip($realif); if ($curip && is_ipaddr($curip) && ($curip != "0.0.0.0")) { return $curip; @@ -5351,8 +5361,15 @@ function get_interface_ipv6($interface = "wan", $flush = false) { } break; } + if (is_ipaddrv6($config['interfaces'][$interface]['ipaddrv6'])) + return ($config['interfaces'][$interface]['ipaddrv6']); } + /* + * Beaware that find_interface_ip() is our last option, it will + * return the first IP it find on interface, not necessarily the + * main IP address. + */ $curip = find_interface_ipv6($realif, $flush); if ($curip && is_ipaddrv6($curip) && ($curip != "::")) { return $curip; -- cgit v1.1