From 0f2cf2a1c47192e8394cbcec6ee291b7e753ac4b Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 22 Dec 2016 17:42:14 +0545 Subject: Fix #7031 Allow interfaces that use DHCP for OpenVPN even though the interface (or gateway group) has not yet actually received an IP address. This is useful when setting up a new system that is currently offline. --- src/etc/inc/interfaces.inc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/etc/inc/interfaces.inc') diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 60248eb..795be7b 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -5972,6 +5972,52 @@ function get_failover_interface($interface, $family = "all") { return get_real_interface($interface, $family); } +/****f* interfaces/interface_has_dhcp + * NAME + * interface_has_dhcp - determine if the interface or gateway group uses DHCP + * INPUTS + * interface or gateway group name + * family - 4 (check for IPv4 DHCP) or 6 (check for IPv6 DHCP) + * RESULT + * true - if the interface uses DHCP/DHCP6, or the name is a gateway group which has any member that uses DHCP/DHCP6 + * false - otherwise (DHCP/DHCP6 not in use, or the name is not an interface or gateway group) + ******/ +function interface_has_dhcp($interface, $family = 4) { + global $config; + + if ($config['interfaces'][$interface]) { + if (($family == 4) && ($config['interfaces'][$interface]['ipaddr'] == "dhcp")) { + return true; + } + if (($family == 6) && ($config['interfaces'][$interface]['ipaddrv6'] == "dhcp6")) { + return true; + } + } else { + if (is_array($config['gateways']['gateway_group'])) { + if ($family == 6) { + $dhcp_string = "_DHCP6"; + } else { + $dhcp_string = "_DHCP"; + } + + foreach ($config['gateways']['gateway_group'] as $group) { + if ($group['name'] == $interface) { + if (is_array($group['item'])) { + foreach ($group['item'] as $item) { + $item_data = explode("|", $item); + if (substr($item_data[0], -strlen($dhcp_string)) == $dhcp_string) { + return true; + } + } + } + } + } + } + } + + return false; +} + function remove_ifindex($ifname) { return preg_replace("/[0-9]+$/", "", $ifname); } -- cgit v1.1