From 28bf462793fc9c15e70b73d3eb2223f6328abb84 Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Sun, 12 Jun 2016 23:21:48 +0200 Subject: Add new configuration options to enable/disable IPv6 or IPv4. When disabling IPv6 or IPv4, the looking glass will not try to use both IP protocol versions when looking for an AS routes or when pinging or tracerouting. If an IP address of a disabling IP version is used, the user will have an error in return of its command. This error will tell him that the IP version he is trying to use is disabled. Please note that when trying to ping or traceroute a hostname from a Cisco or a Juniper device, this looking glass will not prevent the device to use a disabled IP version when executing its command. This commit also contains some small changes with HTML tags. --- includes/utils.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'includes/utils.php') diff --git a/includes/utils.php b/includes/utils.php index b297d61..0fbf3f7 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -2,7 +2,7 @@ /* * Looking Glass - An easy to deploy Looking Glass - * Copyright (C) 2014 Guillaume Mazoyer + * Copyright (C) 2014-2016 Guillaume Mazoyer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -243,7 +243,20 @@ function match_aspath_regex($aspath_regex) { * @return string an IPv6 or IPv4 address based on the DNS records. */ function hostname_to_ip_address($hostname) { - $dns_record = dns_get_record($hostname, DNS_AAAA + DNS_A); + global $config; + + $record_types = DNS_AAAA + DNS_A; + + // IPv6 is disabled look for A records only + if ($config['misc']['disable_ipv6']) { + $record_types = DNS_A; + } + // IPv4 is disabled look for AAAA records only + if ($config['misc']['disabke_ipv4']) { + $record_types = DNS_AAAA; + } + + $dns_record = dns_get_record($hostname, $record_types); // No DNS record found if (!$dns_record) { @@ -265,7 +278,6 @@ function hostname_to_ip_address($hostname) { // Several records found if ($records_nb > 1) { - // TODO: this could probably be more optimal foreach ($dns_record as $record) { if ($record['type'] == 'AAAA') { return $record['ipv6']; -- cgit v1.2.3