From b1810b233bf15a97bd55dbde829c42ccf32015f6 Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Sun, 1 Dec 2013 16:22:46 +0100 Subject: [PATCH] Set default timeout for DNS lookup to 100ms, default value for DNSLookupTimeout is now 0.0001 second. --- README | 6 +++--- SquidAnalyzer.pm | 12 ++++++------ doc/SquidAnalyzer.pod | 4 ++-- etc/squidanalyzer.conf | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README b/README index 1238ee1..768b733 100644 --- a/README +++ b/README @@ -189,11 +189,11 @@ CONFIGURATION DNS name instead. Note that you must have a working DNS resolution and that it can really slow down the generation of reports. - DNSLookupTimeout 1 + DNSLookupTimeout 0.0001 If you have enabled UseClientDNSName and have lot of ip addresses that do not resolve you may want to increase the DNS lookup timeout. - By default SquidAnalyzer will stop to lookup a DNS name after one - second. + By default SquidAnalyzer will stop to lookup a DNS name after 0.0001 + second (100 ms). NetworkAlias network-aliases_file Set path to the file containing network alias name. Network are show diff --git a/SquidAnalyzer.pm b/SquidAnalyzer.pm index 4cbb90f..c838fef 100644 --- a/SquidAnalyzer.pm +++ b/SquidAnalyzer.pm @@ -19,6 +19,7 @@ BEGIN { use POSIX qw/ strftime /; use IO::File; use Socket; + use Time::HiRes qw/ualarm/; # Set all internal variable $VERSION = '5.3'; @@ -652,7 +653,8 @@ sub _init $self->{TopUrlUser} = $options{TopUrlUser} || 0; $self->{no_year_stat} = 0; $self->{UseClientDNSName} = $options{UseClientDNSName} || 0; - $self->{DNSLookupTimeout} = $options{DNSLookupTimeout} || 1; + $self->{DNSLookupTimeout} = $options{DNSLookupTimeout} || 0.0001; + $self->{DNSLookupTimeout} = int($self->{DNSLookupTimeout} * 1000000); if ($self->{Lang}) { open(IN, "$self->{Lang}") or die "ERROR: can't open translation file $self->{Lang}, $!\n"; @@ -807,15 +809,13 @@ sub _gethostbyaddr { my ($self, $ip) = @_; - return $ip unless $ip=~/\d+\.\d+\.\d+\.\d+/; - my $host = undef; unless(exists $CACHE{$ip}) { eval { - local $SIG{ALRM} = sub { die "timeout\n" }; - alarm $self->{DNSLookupTimeout}; + local $SIG{ALRM} = sub { die "DNS lookup timeout.\n"; }; + ualarm $self->{DNSLookupTimeout}; $host = gethostbyaddr(inet_aton($ip), AF_INET); - alarm 0; + ualarm 0; }; if ($@) { $CACHE{$ip} = undef; diff --git a/doc/SquidAnalyzer.pod b/doc/SquidAnalyzer.pod index fc80722..dc15391 100644 --- a/doc/SquidAnalyzer.pod +++ b/doc/SquidAnalyzer.pod @@ -199,11 +199,11 @@ the client ip address, this allow you to use the DNS name instead. Note that you must have a working DNS resolution and that it can really slow down the generation of reports. -=item DNSLookupTimeout 1 +=item DNSLookupTimeout 0.0001 If you have enabled UseClientDNSName and have lot of ip addresses that do not resolve you may want to increase the DNS lookup timeout. By default SquidAnalyzer -will stop to lookup a DNS name after one second. +will stop to lookup a DNS name after 0.0001 second (100 ms). =item NetworkAlias network-aliases_file diff --git a/etc/squidanalyzer.conf b/etc/squidanalyzer.conf index a69e14f..370d6d5 100644 --- a/etc/squidanalyzer.conf +++ b/etc/squidanalyzer.conf @@ -22,8 +22,8 @@ UseClientDNSName 0 # If you have enabled UseClientDNSName and have lot of ip addresses that do # not resolve you may want to increase the DNS lookup timeout. By default -# SquidAnalyzer will stop to lookup a DNS name after one second. -DNSLookupTimeout 1 +# SquidAnalyzer will stop to lookup a DNS name after 0.0001 second (100 ms). +DNSLookupTimeout 0.0001 # Set the file containing network alias name. Network are # show as Ip addresses so if you want to display name instead