diff options
author | Guillaume Mazoyer <respawneral@gmail.com> | 2014-12-10 20:47:56 +0100 |
---|---|---|
committer | Guillaume Mazoyer <respawneral@gmail.com> | 2014-12-10 20:47:56 +0100 |
commit | 7436934fe3e1d28ca4c1124ccec5bbcdecdc986f (patch) | |
tree | e6c5fac19adeccb4cc3c360b0e101d6f669614b8 /routers/bird.php | |
parent | bcb3cc4dc275098c33ebc46fb49ef0397242b1ba (diff) |
Add option to specify an interface or an address for routers.
The interface is used on routers to source ping and traceroute.
On software routers, an address is required instead of the interface.
Diffstat (limited to 'routers/bird.php')
-rw-r--r-- | routers/bird.php | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/routers/bird.php b/routers/bird.php index b86315b..71a8602 100644 --- a/routers/bird.php +++ b/routers/bird.php @@ -63,10 +63,23 @@ final class Bird extends Router { break; case 'ping': + $append = null; + if (isset($this->config['source-interface-id'])) { + $append = ' -I '.$this->config['source-interface-id']; + } + if (match_ipv4($parameters)) { - $commands[] = 'ping -A -c 10 '.$parameters; + $ping = 'ping -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_ipv6($parameters)) { - $commands[] = 'ping6 -A -c 10 '.$parameters; + $ping = 'ping6 -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_fqdn($parameters)) { $ip_address = fqdn_to_ip_address($parameters); @@ -75,9 +88,17 @@ final class Bird extends Router { } if (match_ipv4($ip_address)) { - $commands[] = 'ping -A -c 10 '.$parameters; + $ping = 'ping -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } else if (match_ipv6($ip_address)) { - $commands[] = 'ping6 -A -c 10 '.$parameters; + $ping = 'ping6 -A -c 10 '.$parameters; + if ($append != null) { + $ping .= $append; + } + $commands[] = $ping; } } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); @@ -85,10 +106,23 @@ final class Bird extends Router { break; case 'traceroute': + $append = null; + if (isset($this->config['source-interface-id'])) { + $append = ' -s '.$this->config['source-interface-id']; + } + if (match_ipv4($parameters)) { - $commands[] = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else if (match_ipv6($parameters)) { - $commands[] = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else if (match_fqdn($parameters)) { $ip_address = fqdn_to_ip_address($parameters); @@ -97,9 +131,17 @@ final class Bird extends Router { } if (match_ipv4($ip_address)) { - $commands[] = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -4 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } else if (match_ipv6($ip_address)) { - $commands[] = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + $traceroute = 'traceroute -6 -A -q1 -N32 -w1 -m15 '.$parameters; + if ($append != null) { + $traceroute .= $append; + } + $commands[] = $traceroute; } } else { throw new Exception('The parameter is not an IPv4/IPv6 address.'); |