summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErmal <eri@pfsense.org>2014-11-12 13:57:12 (GMT)
committerErmal <eri@pfsense.org>2014-11-12 13:57:12 (GMT)
commitaa5acb424f4d05efd15ceed1b9e71d6a34dac674 (patch)
tree62cf850e9dc7663a147d0c2b258e0d257979f5e1
parent285acd604006006f4e5b811bdeb178fb126da2db (diff)
downloadunivnautes-aa5acb424f4d05efd15ceed1b9e71d6a34dac674.zip
univnautes-aa5acb424f4d05efd15ceed1b9e71d6a34dac674.tar.gz
univnautes-aa5acb424f4d05efd15ceed1b9e71d6a34dac674.tar.bz2
Use route command directly rather than trying to make a route search on php thorugh netstat. It Fixes #4000
-rw-r--r--etc/inc/interfaces.inc49
1 files changed, 17 insertions, 32 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc
index e01d8cc..7bb983e 100644
--- a/etc/inc/interfaces.inc
+++ b/etc/inc/interfaces.inc
@@ -4443,39 +4443,24 @@ function get_real_interface($interface = "wan", $family = "all", $realv6iface =
/* Guess the physical interface by providing a IP address */
function guess_interface_from_ip($ipaddress) {
- if(! is_ipaddr($ipaddress)) {
- return false;
- }
- if(is_ipaddrv4($ipaddress)) {
- /* create a route table we can search */
- exec("/usr/bin/netstat -rnWf inet", $output, $ret);
- foreach($output as $line) {
- if(preg_match("/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]+[ ]+link[#]/", $line)) {
- $fields = preg_split("/[ ]+/", $line);
- if(ip_in_subnet($ipaddress, $fields[0])) {
- return $fields[5];
- }
- }
- }
- }
- /* FIXME: This works from cursory testing, regexp might need fine tuning */
- if(is_ipaddrv6($ipaddress)) {
- /* create a route table we can search */
- exec("/usr/bin/netstat -rnWf inet6", $output, $ret);
- foreach($output as $line) {
- if(preg_match("/[0-9a-f]+[:]+[0-9a-f]+[:]+[\/][0-9]+/", $line)) {
- $fields = preg_split("/[ ]+/", $line);
- if(ip_in_subnet($ipaddress, $fields[0])) {
- return $fields[5];
- }
- }
- }
- }
- $ret = exec_command("/sbin/route -n get {$ipaddress} | /usr/bin/awk '/interface/ { print \$2; };'");
- if(empty($ret)) {
+
+ $family = '';
+ if(is_ipaddrv4($ipaddress))
+ $family = 'inet';
+ if (empty($family) && is_ipaddrv6($ipaddress))
+ $family = 'inet6';
+
+ if (empty($family))
return false;
- }
- return $ret;
+
+ /* create a route table we can search */
+ $output = '';
+ $_gb = exec("/sbin/route -n get -{$family} " . escapeshellarg($ipaddress) . " | /usr/bin/awk '/interface/ { print \$2; };'", $output);
+ $output[0] = trim($output[0], " \n");
+ if (!empty($output[0]))
+ return $output[0];
+
+ return false;
}
/*