diff options
author | Ermal Luçi <eri@pfsense.org> | 2008-11-16 23:02:01 +0000 |
---|---|---|
committer | Ermal Luçi <eri@pfsense.org> | 2008-11-16 23:02:01 +0000 |
commit | 31b24870eaf6397e0a4d08878e4826db4a770b52 (patch) | |
tree | 79838f4dffc33b4e8c20a743ec5db2eb61ba4802 /etc | |
parent | 96fcbfd0f66a09a704e20baa6cf1f936d9066ea5 (diff) | |
download | pfsense-31b24870eaf6397e0a4d08878e4826db4a770b52.zip pfsense-31b24870eaf6397e0a4d08878e4826db4a770b52.tar.gz |
Introduce 2 new functions
find_interface_subnet and get_interface_subnet
similar to their ip ones
find_interface_ip and get_interface_ip
to easy getting this info for dynamic interfaces.
Diffstat (limited to 'etc')
-rw-r--r-- | etc/inc/interfaces.inc | 21 | ||||
-rw-r--r-- | etc/inc/pfsense-utils.inc | 17 |
2 files changed, 35 insertions, 3 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 8893522..c7cdd0b 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -1253,6 +1253,7 @@ function find_dhclient_process($interface) function interface_configure($interface = "wan") { global $config, $g; + global $interface_sn_arr_cache, $interface_ip_arr_cache; $wancfg = $config['interfaces'][$interface]; @@ -1298,8 +1299,10 @@ function interface_configure($interface = "wan") mwexec($cmd); } - /* invalidate interface cache */ + /* invalidate interface/ip/sn cache */ get_interface_arr(true); + unset($interface_ip_arr_cache[$realif]); + unset($interface_sn_arr_cache[$realif]); switch ($wancfg['ipaddr']) { @@ -1847,8 +1850,6 @@ function get_real_interface($interface = "wan") function get_interface_ip($interface = "wan") { - global $config, $g; - $realif = get_real_interface($interface); /* Do we really come here for these interfaces ?! */ if (in_array($realif, array("pptp", "pppoe", "openvpn", "enc0" /* , "ppp" */))) @@ -1861,6 +1862,20 @@ function get_interface_ip($interface = "wan") return null; } +function get_interface_subnet($interface = "wan") +{ + $realif = get_real_interface($interface); + /* Do we really come here for these interfaces ?! */ + if (in_array($realif, array("pptp", "pppoe", "openvpn", "enc0" /* , "ppp" */))) + return ""; + + $cursn = find_interface_subnet($realif); + if (!empty($cursn)) + return $cursn; + + return null; +} + /****f* interfaces/is_altq_capable * NAME * is_altq_capable - Test if interface is capable of using ALTQ diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index e42fd44..f297ee8 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -1439,6 +1439,23 @@ function find_interface_ip($interface, $flush = false) { return $interface_ip_arr_cache[$interface]; } +function find_interface_subnet($interface, $flush = false) +{ + global $interface_sn_arr_cache; + + $interface = str_replace("\n", "", $interface); + if (does_interface_exist($interface) == false) + return; + + if (!isset($interface_sn_arr_cache[$interface]) or $flush) { + $interface_sn_arr_cache[$interface] = exec_command("/sbin/ifconfig {$interface} | /usr/bin/grep -w \"inet\" | /usr/bin/cut -d\" \" -f 4 | /usr/bin/head -1"); + $interface_sn_arr_cache[$interface] = strlen(str_replace("0", "", base_convert(str_replace("\n", "", $interface_sn_arr_cache[$interface]),16, 2))); + log_error("int:{$interface} - generated subnet mask {$interface_sn_arr_cache[$interface]}"); + } + + return $interface_sn_arr_cache[$interface]; +} + function guess_interface_from_ip($ipaddress) { $ret = exec_command("/sbin/route -n get {$ipaddress} | /usr/bin/grep interface | /usr/bin/awk '{ print \$2; };'"); return $ret; |