summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorErmal Luçi <eri@pfsense.org>2009-04-26 13:41:26 +0000
committerErmal Luçi <eri@pfsense.org>2009-04-26 13:41:37 +0000
commit52947718175a67512a7b79c5d401f2ba7d536489 (patch)
treee43828d248bd9fc14327c113925a79b05f704dd0 /etc
parent80efb6d634e23c05a11e87b53bda9cbd9f598d11 (diff)
downloadpfsense-52947718175a67512a7b79c5d401f2ba7d536489.zip
pfsense-52947718175a67512a7b79c5d401f2ba7d536489.tar.gz
More functions moving from pfsense-utils to interfaces.inc.
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/filter.inc4
-rw-r--r--etc/inc/interfaces.inc154
-rw-r--r--etc/inc/pfsense-utils.inc167
3 files changed, 158 insertions, 167 deletions
diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc
index 44340db..970accc 100644
--- a/etc/inc/filter.inc
+++ b/etc/inc/filter.inc
@@ -116,8 +116,10 @@ function filter_configure_sync() {
filter_pflog_start();
update_filter_reload_status("Initializing");
+
/* invalidate interface cache */
get_interface_arr(true);
+
if(isset($config['system']['developerspew'])) {
$mt = microtime();
echo "filter_configure_sync() being called $mt\n";
@@ -2380,4 +2382,4 @@ EOD;
return($ipfrules);
}
-?> \ No newline at end of file
+?>
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc
index dabfc17..80ab71d 100644
--- a/etc/inc/interfaces.inc
+++ b/etc/inc/interfaces.inc
@@ -49,6 +49,36 @@ function interfaces_bring_up($interface) {
mwexec("/sbin/ifconfig " . escapeshellarg($interface) . " up");
}
+/*
+ * Return the interface array
+ */
+function get_interface_arr($flush = false) {
+ global $interface_arr_cache;
+
+ /* If the cache doesn't exist, build it */
+ if (!isset($interface_arr_cache) or $flush)
+ $interface_arr_cache = exec_command("/sbin/ifconfig -l");
+
+ return $interface_arr_cache;
+}
+
+/*
+ * does_interface_exist($interface): return true or false if a interface is
+ * detected.
+ */
+function does_interface_exist($interface) {
+ global $config;
+
+ if(!$interface)
+ return false;
+
+ $ints = get_interface_arr();
+ if(stristr($ints, $interface) !== false)
+ return true;
+ else
+ return false;
+}
+
function interfaces_loopback_configure() {
mwexec("/sbin/ifconfig lo0 127.0.0.1");
interfaces_bring_up("lo0");
@@ -2270,6 +2300,79 @@ function get_interface_subnet($interface = "wan") {
return null;
}
+function get_interface_gateway($interface) {
+ global $config, $g;
+
+ $iflist = get_configured_interface_with_descr();
+ /*
+ * XXX: BUG: This is silly at first, but we may be called with the interface
+ * descr for no apparent reason!!!
+ * Probably one of those silly strtoupper() legacy stuff!
+ */
+ foreach ($iflist as $ifent => $ifdesc) {
+ if ($ifent == $interface || $ifdesc == $interface) {
+ $interface = $ifent;
+ break;
+ }
+ }
+
+ $gw = NULL;
+
+ $gwcfg = $config['interfaces'][$interface];
+ if (is_ipaddr($gwcfg['gateway']))
+ $gw = $gwcfg['gateway'];
+ else if (!empty($gwcfg['gateway']))
+ $gw = lookup_gateway_ip_by_name($gwcfg['gateway']);
+
+ // for dynamic interfaces we handle them through the $interface_router file.
+ if (!is_ipaddr($gw)) {
+ $realif = get_real_interface($interface);
+ if (file_exists("{$g['tmp_path']}/{$realif}_router")) {
+ $gw = file_get_contents("{$g['tmp_path']}/{$realif}_router");
+ $gw = rtrim($gw);
+ }
+ }
+
+ /* return gateway */
+ return $gw;
+}
+
+/* return outside interfaces with a gateway */
+function get_interfaces_with_gateway() {
+ global $config;
+
+ $ints = array();
+
+ /* loop interfaces, check config for outbound */
+ foreach ($config['interfaces'] as $ifdescr => $ifname) {
+ switch ($$ifname['ipaddr']) {
+ case "dhcp":
+ case "carpdev-dhcp":
+ case "pppoe":
+ case "pptp":
+ $ints[] = $ifdescr;
+ break;
+ default:
+ if ($ifname['pointtopoint'])
+ $ints[] = $ifdescr;
+ else if (!empty($ifname['gateway']))
+ $ints[] = $ifdescr;
+ break;
+ }
+ }
+ return $ints;
+}
+
+/* return true if interface has a gateway */
+function interface_has_gateway($friendly) {
+
+ $friendly = strtolower($friendly);
+ if (in_array($friendly, get_interfaces_with_gateway()))
+ return true;
+
+ return false;
+}
+
/****f* interfaces/is_altq_capable
* NAME
* is_altq_capable - Test if interface is capable of using ALTQ
@@ -2298,6 +2401,27 @@ function is_altq_capable($int) {
return false;
}
+/****f* interfaces/is_interface_wireless
+ * NAME
+ * is_interface_wireless - Returns if an interface is wireless
+ * RESULT
+ * $tmp - Returns if an interface is wireless
+ ******/
+function is_interface_wireless($interface) {
+ global $config, $g;
+
+ $friendly = convert_real_interface_to_friendly_interface_name($interface);
+ if(!is_array($config['interfaces'][$friendly]['wireless'])) {
+ if (preg_match($g['wireless_regex'], $interface)) {
+ $config['interfaces'][$friendly]['wireless'] = array();
+ return true;
+ }
+ unset($config['interfaces'][$friendly]['wireless']);
+ return false;
+ } else
+ return true;
+}
+
function get_wireless_modes($interface) {
/* return wireless modes and channels */
$wireless_modes = array();
@@ -2333,6 +2457,17 @@ function get_wireless_modes($interface) {
return($wireless_modes);
}
+/****f* interfaces/get_interface_mtu
+ * NAME
+ * get_interface_mtu - Return the mtu of an interface
+ * RESULT
+ * $tmp - Returns the mtu of an interface
+ ******/
+function get_interface_mtu($interface) {
+ $mtu = `/sbin/ifconfig {$interface} | /usr/bin/grep mtu | /usr/bin/cut -d" " -f6`;
+ return $mtu;
+}
+
function get_interface_mac($interface) {
$mac = array();
exec("/sbin/ifconfig {$interface} | /usr/bin/awk '/ether/ {print $2}'", $mac);
@@ -2358,6 +2493,25 @@ function generate_random_mac_address() {
return $mac;
}
+/****f* interfaces/is_jumbo_capable
+ * NAME
+ * is_jumbo_capable - Test if interface is jumbo frame capable. Useful for determining VLAN capability.
+ * INPUTS
+ * $int - string containing interface name
+ * RESULT
+ * boolean - true or false
+ ******/
+function is_jumbo_capable($int) {
+ global $g;
+
+ $int_family = preg_split("/[0-9]+/", $int);
+
+ if (in_array($int_family[0], $g['vlan_long_frame']))
+ return true;
+ else
+ return false;
+}
+
function setup_pppoe_reset_file($interface, $status) {
define("CRON_PPPOE_CMD_FILE", "/conf/pppoe{$interface}restart");
define("CRON_PPPOE_CMD", "#!/bin/sh\necho '<?php require(\"interfaces.inc\"); interface_reconfigure({$interface}); services_dyndns_reset({$interface}); filter_configure(); ?>' | /usr/local/bin/php -q");
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc
index ea0b2b8..c814dac 100644
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -1148,38 +1148,6 @@ function is_carp_defined() {
return true;
}
-/****f* pfsense-utils/get_interface_mtu
- * NAME
- * get_interface_mtu - Return the mtu of an interface
- * RESULT
- * $tmp - Returns the mtu of an interface
- ******/
-function get_interface_mtu($interface) {
- $mtu = `/sbin/ifconfig {$interface} | /usr/bin/grep mtu | /usr/bin/cut -d" " -f6`;
- return $mtu;
-}
-
-/****f* pfsense-utils/is_interface_wireless
- * NAME
- * is_interface_wireless - Returns if an interface is wireless
- * RESULT
- * $tmp - Returns if an interface is wireless
- ******/
-function is_interface_wireless($interface) {
- global $config, $g;
- $friendly = convert_real_interface_to_friendly_interface_name($interface);
- if(!is_array($config['interfaces'][$friendly]['wireless'])) {
- if (preg_match($g['wireless_regex'], $interface)) {
- $config['interfaces'][$friendly]['wireless'] = array();
- return true;
- }
- unset($config['interfaces'][$friendly]['wireless']);
- return false;
- } else {
- return true;
- }
-}
-
/****f* pfsense-utils/find_number_of_created_carp_interfaces
* NAME
* find_number_of_created_carp_interfaces - Return the number of CARP interfaces.
@@ -1299,70 +1267,9 @@ function exec_command($command) {
return(implode("\n", $output));
}
-/****f* interfaces/is_jumbo_capable
- * NAME
- * is_jumbo_capable - Test if interface is jumbo frame capable. Useful for determining VLAN capability.
- * INPUTS
- * $int - string containing interface name
- * RESULT
- * boolean - true or false
- ******/
-function is_jumbo_capable($int) {
- /* Per:
- * http://www.freebsd.org/cgi/man.cgi?query=vlan&manpath=FreeBSD+6.0-RELEASE&format=html
- * Only the following drivers support large frames
- *
- * 'de' chipset purposely left out of this list
- * requires defining BIG_PACKET in the
- * /usr/src/sys/pci/if_de.c source file and rebuilding the
- * kernel or module. The hack works only for the 21041,
- * 21140, and 21140A chips.
- */
- global $g;
-
- $capable = $g['vlan_long_frame'];
-
- $int_family = preg_split("/[0-9]+/", $int);
-
- if (in_array($int_family[0], $capable))
- return true;
- else
- return false;
-}
-
-/*
- * Return the interface array
- */
-function get_interface_arr($flush = false) {
- global $interface_arr_cache;
-
- /* If the cache doesn't exist, build it */
- if (!isset($interface_arr_cache) or $flush)
- $interface_arr_cache = exec_command("/sbin/ifconfig -l");
-
- return $interface_arr_cache;
-}
-
-/*
- * does_interface_exist($interface): return true or false if a interface is
- * detected.
- */
-function does_interface_exist($interface) {
- global $config;
-
- if(!$interface)
- return false;
-
- $ints = get_interface_arr();
-
- if(stristr($ints, $interface) !== false)
- return true;
- else
- return false;
-}
-
/*
* convert_ip_to_network_format($ip, $subnet): converts an ip address to network form
+
*/
function convert_ip_to_network_format($ip, $subnet) {
$ipsplit = split('[.]', $ip);
@@ -2537,42 +2444,6 @@ function update_filter_reload_status($text) {
fclose($fd);
}
-function get_interface_gateway($interface) {
- global $config, $g;
-
- $iflist = get_configured_interface_with_descr();
- /*
- * XXX: This is silly at first, but we may be called with the interface
- * descr for no apparent reason!!!
- */
- foreach ($iflist as $ifent => $ifdesc) {
- if ($ifent == $interface || $ifdesc == $interface) {
- $interface = $ifent;
- break;
- }
- }
-
- $gw = NULL;
-
- $gwcfg = $config['interfaces'][$interface];
- if (is_ipaddr($gwcfg['gateway']))
- $gw = $gwcfg['gateway'];
- else if (!empty($gwcfg['gateway']))
- $gw = lookup_gateway_ip_by_name($gwcfg['gateway']);
-
- // for dynamic interfaces we handle them through the $interface_router file.
- if (!is_ipaddr($gw)) {
- $realif = get_real_interface($interface);
- if (file_exists("{$g['tmp_path']}/{$realif}_router")) {
- $gw = file_get_contents("{$g['tmp_path']}/{$realif}_router");
- $gw = rtrim($gw);
- }
- }
-
- /* return gateway */
- return $gw;
-}
-
/* DHCP enabled on any interfaces? */
function is_dhcp_server_enabled()
{
@@ -2595,42 +2466,6 @@ function is_dhcp_server_enabled()
return $dhcpdenable;
}
-/* return outside interfaces with a gateway */
-function get_interfaces_with_gateway() {
- global $config;
-
- $ints = array();
- $ifdescrs = get_configured_interface_list(false, true);
-
- /* loop interfaces, check config for outbound */
- foreach ($ifdescrs as $ifdescr => $ifname) {
- switch ($config['interfaces'][$ifname]['ipaddr']) {
- case "dhcp":
- case "carpdev-dhcp":
- case "pppoe":
- case "pptp":
- $ints[] = $ifname;
- break;
- default:
- if ($config['interfaces'][$ifname]['pointtopoint'])
- $ints[] = $ifname;
- else if (!empty($config['interfaces'][$ifname]['gateway']))
- $ints[] = $ifname;
- break;
- }
- }
- return $ints;
-}
-
-/* return true if interface has a gateway */
-function interface_has_gateway($friendly) {
- $friendly = strtolower($friendly);
- if (in_array($friendly, get_interfaces_with_gateway()))
- return true;
-
- return false;
-}
-
/****f* pfsense-utils/isAjax
* NAME
* isAjax - reports if the request is driven from prototype
OpenPOWER on IntegriCloud