diff options
author | Guillaume Mazoyer <respawneral@gmail.com> | 2014-12-12 13:01:43 +0100 |
---|---|---|
committer | Guillaume Mazoyer <respawneral@gmail.com> | 2014-12-12 13:01:43 +0100 |
commit | 464ae23f92b5056cc1dc1bf7bf701a58187447c3 (patch) | |
tree | 4f4cb47d2cd129ec8358fe0c684d6d73ad81b307 /routers/router.php | |
parent | 7436934fe3e1d28ca4c1124ccec5bbcdecdc986f (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/router.php')
-rw-r--r-- | routers/router.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/routers/router.php b/routers/router.php index c878342..d68c2f4 100644 --- a/routers/router.php +++ b/routers/router.php @@ -77,6 +77,37 @@ abstract class Router { return $displayable; } + protected function has_source_interface_id() { + return isset($this->config['source-interface-id']); + } + + protected function get_source_interface_id($ip_version = null) { + // No source interface ID specified + if (!$this->has_source_interface_id()) { + return null; + } + + $source_interface_id = $this->config['source-interface-id']; + + // Generic interface ID (interface name) + if (!is_array($source_interface_id)) { + return $source_interface_id; + } + + // Composed interface ID (IPv4 and IPv6 address) + if (($ip_version == null) || ($ip_version == 'ipv4')) { + return $source_interface_id['ipv4']; + } else if ($ip_version == 'ipv6') { + return $source_interface_id['ipv6']; + } + + return null; + } + + protected abstract function build_ping($destination); + + protected abstract function build_traceroute($destination); + protected abstract function build_commands($command, $parameters); public function send_command($command, $parameters) { |