summaryrefslogtreecommitdiff
path: root/routers/cisco.php
diff options
context:
space:
mode:
authorGuillaume Mazoyer <respawneral@gmail.com>2014-12-12 13:01:43 +0100
committerGuillaume Mazoyer <respawneral@gmail.com>2014-12-12 13:01:43 +0100
commit464ae23f92b5056cc1dc1bf7bf701a58187447c3 (patch)
tree4f4cb47d2cd129ec8358fe0c684d6d73ad81b307 /routers/cisco.php
parent7436934fe3e1d28ca4c1124ccec5bbcdecdc986f (diff)
Improve 'source-interface-id' option.
On software router, an IPv4 and IPv6 addresses need to be specified. Not specifying one of them or both will result in the router trying to use the best address to contact the destination. This fix the bug where software routers could not ping or traceroute IPv6 destination with only a IPv4 source address (obviously).
Diffstat (limited to 'routers/cisco.php')
-rw-r--r--routers/cisco.php58
1 files changed, 42 insertions, 16 deletions
diff --git a/routers/cisco.php b/routers/cisco.php
index 285653a..5a135c0 100644
--- a/routers/cisco.php
+++ b/routers/cisco.php
@@ -23,6 +23,40 @@ require_once('router.php');
require_once('includes/utils.php');
final class Cisco extends Router {
+ protected function build_ping($destination) {
+ $ping = null;
+
+ if (match_ipv4($destination) || match_ipv6($destination) ||
+ match_fqdn($destination)) {
+ $ping = 'ping '.$destination.' repeat 10';
+ } else {
+ throw new Exception('The parameter is not an IPv4/IPv6 address or a FQDN.');
+ }
+
+ if (($ping != null) && $this->has_source_interface_id()) {
+ $ping .= ' source '.$this->get_source_interface_id();
+ }
+
+ return $ping;
+ }
+
+ protected function build_traceroute($destination) {
+ $traceroute = null;
+
+ if (match_ipv4($destination) || match_ipv6($destination) ||
+ match_fqdn($destination)) {
+ $traceroute = 'traceroute '.$destination;
+ } else {
+ throw new Exception('The parameter is not an IPv4/IPv6 address or a FQDN.');
+ }
+
+ if (($traceroute != null) && $this->has_source_interface_id()) {
+ $traceroute .= ' source '.$this->get_source_interface_id();
+ }
+
+ return $traceroute;
+ }
+
protected function build_commands($command, $parameters) {
$commands = array();
@@ -56,26 +90,18 @@ final class Cisco extends Router {
break;
case 'ping':
- if (match_ipv4($parameters) || match_ipv6($parameters) || match_fqdn($parameters)) {
- $ping = 'ping '.$parameters.' repeat 10';
- if (isset($this->config['source-interface-id'])) {
- $ping .= ' source '.$this->config['source-interface-id'];
- }
- $commands[] = $ping;
- } else {
- throw new Exception('The parameter is not an IPv4/IPv6 address.');
+ try {
+ $commands[] = $this->build_ping($parameters);
+ } catch (Exception $e) {
+ throw $e;
}
break;
case 'traceroute':
- if (match_ipv4($parameters) || match_ipv6($parameters) || match_fqdn($parameters)) {
- $traceroute = 'traceroute '.$parameters;
- if (isset($this->config['source-interface-id'])) {
- $traceroute .= ' source '.$this->config['source-interface-id'];
- }
- $commands[] = $traceroute;
- } else {
- throw new Exception('The parameter is not an IPv4/IPv6 address.');
+ try {
+ $commands[] = $this->build_traceroute($parameters);
+ } catch (Exception $e) {
+ throw $e;
}
break;