diff options
author | Guillaume Mazoyer <gmazoyer@gravitons.in> | 2016-06-13 11:41:49 +0200 |
---|---|---|
committer | Guillaume Mazoyer <gmazoyer@gravitons.in> | 2016-06-13 11:41:49 +0200 |
commit | f35e3e3efe4c724f19594e2a41772b329d890cb8 (patch) | |
tree | cb619a8963c09217f8c2eedc3b078f44d0336969 | |
parent | 931788ad45b4f1114e97e6ac2869ab84efa767e2 (diff) |
Fix hostname_to_ip_address.
Get only AAAA or A record based on the router config if provided.
-rw-r--r-- | includes/utils.php | 8 | ||||
-rw-r--r-- | routers/bird.php | 4 | ||||
-rw-r--r-- | routers/quagga.php | 4 |
3 files changed, 7 insertions, 9 deletions
diff --git a/includes/utils.php b/includes/utils.php index 0fbf3f7..e8a7098 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -242,17 +242,15 @@ function match_aspath_regex($aspath_regex) { * databases. * @return string an IPv6 or IPv4 address based on the DNS records. */ -function hostname_to_ip_address($hostname) { - global $config; - +function hostname_to_ip_address($hostname, $config = null) { $record_types = DNS_AAAA + DNS_A; // IPv6 is disabled look for A records only - if ($config['misc']['disable_ipv6']) { + if (($config != null) && $config['disable_ipv6']) { $record_types = DNS_A; } // IPv4 is disabled look for AAAA records only - if ($config['misc']['disabke_ipv4']) { + if (($config != null) && $config['disable_ipv4']) { $record_types = DNS_AAAA; } diff --git a/routers/bird.php b/routers/bird.php index 9a6c869..fee3736 100644 --- a/routers/bird.php +++ b/routers/bird.php @@ -28,7 +28,7 @@ final class Bird extends Router { if (match_hostname($destination)) { $hostname = $destination; - $destination = hostname_to_ip_address($hostname); + $destination = hostname_to_ip_address($hostname, $this->config); if (!$destination) { throw new Exception('No record found for '.$hostname); @@ -65,7 +65,7 @@ final class Bird extends Router { if (match_hostname($destination)) { $hostname = $destination; - $destination = hostname_to_ip_address($hostname); + $destination = hostname_to_ip_address($hostname, $this->config); if (!$destination) { throw new Exception('No record found for '.$hostname); diff --git a/routers/quagga.php b/routers/quagga.php index d451e94..2f930df 100644 --- a/routers/quagga.php +++ b/routers/quagga.php @@ -28,7 +28,7 @@ final class Quagga extends Router { if (match_hostname($destination)) { $hostname = $destination; - $destination = hostname_to_ip_address($hostname); + $destination = hostname_to_ip_address($hostname, $this->config); if (!$destination) { throw new Exception('No record found for '.$hostname); @@ -65,7 +65,7 @@ final class Quagga extends Router { if (match_hostname($destination)) { $hostname = $destination; - $destination = hostname_to_ip_address($hostname); + $destination = hostname_to_ip_address($hostname, $this->config); if (!$destination) { throw new Exception('No record found for '.$hostname); |