chiark / gitweb /
Suppress repetition.
authorianmdlvl <ianmdlvl>
Fri, 4 Jan 2002 22:25:56 +0000 (22:25 +0000)
committerianmdlvl <ianmdlvl>
Fri, 4 Jan 2002 22:25:56 +0000 (22:25 +0000)
scripts/named-conf
scripts/named-conf.8

index 1767fbe35a10b350a354dfeb574a194bef25f80d..054ba0f96920e0e69c82eec619c5c3294e79696f 100755 (executable)
@@ -17,9 +17,10 @@ $doall= 0;
 $etcfile= "/etc/bind/chiark-conf-gen.zones";
 $where= '<built-in>';
 $debug= 0;
-$needglue= 2;
+$needglue= 1;
 $localonly= 0;
 $verbosity= 1;
+$repeat= 0;
 
 use vars qw($dig_owner $dig_type $dig_rdata);
 
@@ -30,9 +31,10 @@ while (@ARGV && $ARGV[0] =~ m/^\-/) {
        if (m/^(yes|no|force)$/) { m/^./; $mode= $&; }
        elsif (m/^all$/) { $doall=1; }
        elsif (m/^config$/) { $etcfile= loarg(); $where= '--config option'; }
-       elsif (m/^glueless$/) { $needglue--; }
+       elsif (m/^glueless$/) { $needglue=0; }
        elsif (m/^localonly$/) { $localonly=1; }
        elsif (m/^quiet$/) { $verbosity=0; }
+       elsif (m/^repeat$/) { $repeat=1; }
        elsif (m/^verbose$/) { $verbosity=2; }
        else { usageerr("unknown option --$_"); }
     } else {
@@ -43,9 +45,10 @@ while (@ARGV && $ARGV[0] =~ m/^\-/) {
            elsif (s/^A//) { $doall=1; }
            elsif (s/^C//) { $etcfile= soarg(); $where= '-C option'; }
            elsif (s/^D//) { $debug++; }
-           elsif (s/^g//) { $needglue--; }
+           elsif (s/^g//) { $needglue=0; }
            elsif (s/^l//) { $localonly=1; }
            elsif (s/^q//) { $verbosity=0; }
+           elsif (s/^r//) { $repeat=1; }
            elsif (s/^v//) { $verbosity=2; }
            else { usageerr("unknown option -$&"); }
        }
@@ -55,7 +58,6 @@ while (@ARGV && $ARGV[0] =~ m/^\-/) {
 sub loarg() { usageerr("missing option value") if !@ARGV; return shift @ARGV; }
 sub soarg() { my ($rv); $rv=$_; $_=''; return length $rv ? $rv : loarg(); }
 
-usageerr("-g may be specified at most twice") if $needglue<0;
 usageerr("-D may be specified at most twice") if $debug>2;
 usageerr("must specify either -f|-y|-n or zones (and not both)")
     if !!$mode == !!@ARGV;
@@ -63,14 +65,20 @@ usageerr("must specify either -f|-y|-n or zones (and not both)")
 sub usageerr ($) {
     die
 "$_[0]
-usage: named-conf-regen [-rvq] -f|-y|-n|<zone>...\n".
+usage: named-conf-regen [options] -f|-y|-n|<zone>...\n".
 "operation modes:\n".
 " -f --force   install without checking\n".
 " -y --yes     check and install\n".
 " -n --no      check only\n".
 "additional options:\n".
-" -q --quiet   no output for OK zones\n".
-" -v --verbose extra verbose\n";
+" -A --all       report on zones marked ? (ones we know are broken)\n".
+" -D             debug $quis (does not help debug your DNS config)\n".
+" -g --glueless  do not warn about any glueless referrals (not recommended)\n".
+" -l --localonly full checks only on zones which we primary\n".
+" -q --quiet     no output for OK zones\n".
+" -r --repeat    repeat warnings for all sources of imperfect data\n".
+" -v --verbose   extra verbose info about each zone\n"
+" -C|--config <DIR/FILE  use FILE as default config and DIR as default dir\n";
 }
 
 cfg_fail("config filename $etcfile should not be directory")
@@ -264,7 +272,7 @@ sub process_zones (@) {
        if ($check && ($doall || $cfg->{'s'} !~ m/\?/)) {
            eval {
                if ($localonly && $cfg->{'s'} =~ m/f/) {
-                   zone_warning("foreign zone specified with -l");
+                   zone_warning("foreign zone specified with -l",'');
                } elsif ($cfg->{'s'} =~ m/\*/ ||
                         ($localonly && $cfg->{'s'} !~ m/p/)) {
                    zone_check_local();
@@ -272,7 +280,7 @@ sub process_zones (@) {
                    zone_check_full();
                }
            };
-           zone_warning("checks failed: $@") if length $@;
+           zone_warning("checks failed: $@",'') if length $@;
        }
        $output_contents{$$cfg{'output'}} .= zone_output()
            if $install;
@@ -281,12 +289,20 @@ sub process_zones (@) {
        if $warnings;
 }
 
-sub zone_warning ($) {
-    my ($w) = @_;
+sub zone_warning ($$) {
+    my ($w,$o) = @_;
+    my ($wk);
+
+    $wk= $w;
+    $wk =~ s/,.*// if !$repeat;
+    return 0 if $$warned{$w}{$wk}++;
+
     $w =~ s/\n$//;
     $w =~ s,\n, // ,g;
+
     print STDERR "$zone: warning: $w\n" or die $!;
     $warnings++;
+    return 1;
 }
 
 sub zone_warnmore ($) {
@@ -297,7 +313,7 @@ use vars qw(%delgs); # $delgs{$nameserver_list} = [ $whosaidandwhy ]
 use vars qw(%auths); # $auths{$nameserver_list} = [ $whosaidandwhy ]
 use vars qw(%glue);  # $glue{$name}{$addr_list} = [ $whosaidandwhy ]
 use vars qw(%soas);  # $soa{"$origin $serial"} = [ $whosaidandwhy ]
-use vars qw(%addr_is_ok %warned_glueless %warned_nameaddr);
+use vars qw(%addr_is_ok %warned);
 use vars qw($delg_to_us);
 use vars qw(@to_check); # ($addr,$whyask,$is_auth,$glueless_ok, ...)
 use vars qw(@to_check_soa); # ($addr,$whyask, ...)
@@ -310,9 +326,7 @@ sub zone_check_full () {
 }
 
 sub zone_reset() {
-    %delgs= %auths= %glue= %soas=
-       %warned_glueless= %warned_nameaddr=
-           %addr_is_ok= ();
+    %delgs= %auths= %glue= %soas= %warned= %addr_is_ok= ();
     $delg_to_us= 0;
     @to_check= @to_check_soa= ();
 }
@@ -348,11 +362,10 @@ sub zone_investigate() {
        if (($addr,$wa,$is_auth,$glueless_ok,@to_check) = @to_check) {
            push @to_check_soa, $addr, $wa if $is_auth;
            next if $nsrrset_checked{$addr}++;
-           zone_check_nsrrset($addr, "[$addr] $wa",
-                              $is_auth, $glueless_ok);
+           zone_check_nsrrset($addr, $wa, $is_auth, $glueless_ok);
        } elsif (($addr,$wa,@to_check_soa) = @to_check_soa) {
            next if $soa_checked{$addr}++;
-           zone_check_soa($addr,"[$addr] $wa","[$addr] NS");
+           zone_check_soa($addr, $wa, "NS [$uaddr]");
        } else {
            last;
        }
@@ -360,9 +373,10 @@ sub zone_investigate() {
 }
 
 sub zone_check_nsrrset ($$$$) {
-    my ($uaddr,$ww, $is_auth, $glueless_ok) = @_;
-    my (@s, $s, %s2g, @glue, $glue, $delgs_or_auths, $wwn);
+    my ($uaddr,$wa, $is_auth, $glueless_ok) = @_;
+    my (@s, $s, %s2g, @glue, $glue, $delgs_or_auths, $wwn, $ww);
     verbose("checking delegation by $ww");
+    $ww= "[$uaddr] $wa";
     dig(sub {
        if ($dig_type eq 'ns' && $dig_owner eq $zone) {
            $s2g{lc $dig_rdata} = [ ];
@@ -374,17 +388,19 @@ sub zone_check_nsrrset ($$$$) {
        }
     },
             $zone,'ns',$uaddr);
-    if (!%s2g) { zone_warning("unable to find NS RRset at $ww"); return; }
-    elsif (keys %s2g == 1) { zone_warning("only one nameserver at $ww"); }
+    if (!%s2g) {
+       zone_warning("unable to find NS RRset at [$uaddr]", $wa);
+       return;
+    } elsif (keys %s2g == 1) {
+       zone_warning("only one nameserver",$ww);
+    }
     @s= sort keys %s2g;
     foreach $s (@s) {
        @glue= @{ $s2g{$s} };
        if (!@glue) {
-           zone_warning("glueless NS $s,".
-                        ($needglue<=1 ? " (eg)" : "").
-                        " from $ww")
-               unless $glueless_ok || !$needglue ||
-                      ($needglue<=1 && $warned_glueless{$s}++);
+           zone_warning("glueless NS $s,".($needglue<=1 ? " (eg)" : ""),
+                        $ww)
+               unless $glueless_ok || !$needglue;
            next;
        }
        $glue= join ' ', sort @glue;
@@ -399,10 +415,10 @@ sub zone_server_addr ($$$$$) {
     my ($addr,$name,$ww,$wwq,$is_soa) = @_;
     $addr_is_ok{$addr}= "$name ($wwq)"
        if $is_soa || $cfg->{'s'} =~ m/u/;
-    zone_warning("configured as stealth but we [$addr]".
-                " are published ($name $wwq)")
+    zone_warning("configured as stealth but we [$addr] $name are published",
+                $ww)
        if $cfg->{'s'} =~ m/u/ && grep { $_ eq $addr } @self_addr;
-    zone_warning("forbidden nameserver address [$addr] $name ($wwq)")
+    zone_warning("forbidden nameserver address [$addr] $name",$ww)
        if grep { $_ eq $addr } @forbid_addr;
 
     my ($name_is_self, $addr_is_self);
@@ -411,18 +427,17 @@ sub zone_server_addr ($$$$$) {
     $addr_is_self= grep { $_ eq $addr }
         @{ $cfg->{'self_addr'} };
     if ($name_is_self && !$addr_is_self) {
-       zone_warning("our name $name with wrong address [$addr], (eg) $ww")
-           unless $warned_nameaddr{$name}{$addr}++;
+       zone_warning("our name $name with wrong address [$addr]",$ww);
     } elsif (!$name_is_self && $addr_is_self) {
        zone_warning(($is_soa ? "SOA ORIGIN maps to" : "referral to").
-                    " us [$addr] with wrong name $name, (eg) $ww")
-           unless $warned_nameaddr{$name}{$addr}++;
+                    " us [$addr] with wrong name $name",
+                    $ww);
     }
     $delg_to_us=1 if $name_is_self;
 }
 
 sub zone_check_soa ($$$) {
-    my ($uaddr,$ww,$wwq) = @_;
+    my ($uaddr,$wa,$waq) = @_;
     my ($lame,$origin,$got,$rcode,@soa_addrs,$soa_addr,$wwn);
     verbose("checking service at $wwq");
     $lame= 'dead or lame';
@@ -438,7 +453,7 @@ sub zone_check_soa ($$$) {
     },
             $zone,'soa',$uaddr);
     $lame= 'broken' if !$lame && !defined $origin;
-    if ($lame) { zone_warning("$lame server $ww"); return; }
+    if ($lame) { zone_warning("$lame server [$uaddr]",$wa); return; }
     push @{ $soas{$got} }, $ww;
     ($rcode,@soa_addrs)= lookup($origin,'a','0');
     foreach $soa_addr (@soa_addrs) {
@@ -449,7 +464,7 @@ sub zone_check_soa ($$$) {
 }
 
 sub zone_consistency() {
-    my ($d, $org_ser, $origin, $a, $h, $self_soa);
+    my ($d, $org_ser, $origin, $a, $h, $self_soa, $wa);
     zone_consistency_set('delegations',\%delgs);
     foreach $d (keys %delgs) { delete $auths{$d}; }
     zone_consistency_set('zone nameserver rrset',\%auths);
@@ -463,8 +478,10 @@ sub zone_consistency() {
            $org_ser =~ m/^(\S+) \d+$/ or die "$org_ser ?";
            $origin= $1;
            next if grep { $_ eq $origin } @$self_soa;
-           zone_warning("SOA ORIGIN $origin is not our name (@$self_soa),".
-                        " eg from ".($soas{$org_ser}[0]));
+           foreach $wa (@{ $soas{$org_ser} }) {
+               zone_warning("SOA ORIGIN $origin is not our name (@$self_soa)",
+                            $wa);
+           }
        }
     }
 }
@@ -475,7 +492,8 @@ sub zone_servers_ok () {
        $showok= 0;
        foreach $a (@{ $cfg->{'servers'} }) {
            next if exists $addr_is_ok{$a};
-           zone_warning("we slave from $a"); $showok=1;
+           zone_warning("we slave from [$a]",'')
+               and $showok=1;
        }
        if ($showok) {
            foreach $a (keys %addr_is_ok) {
@@ -485,7 +503,7 @@ sub zone_servers_ok () {
     }
     if ($cfg->{'s'} =~ m/s/ && !$delg_to_us) {
        zone_warning("we are supposedly published secondary,".
-                    " but not listed as a nameserver");
+                    " but not listed as a nameserver",'');
     }
 }
 
@@ -493,7 +511,7 @@ sub zone_consistency_set ($%) {
     my ($msg,$set) = @_;
     my ($d,$o);
     if (keys(%$set) > 1) {
-       zone_warning("inconsistent $msg:");
+       zone_warning("inconsistent $msg:",'');
        foreach $d (keys %$set) {
            foreach $o (@{ $set->{$d} }) { zone_warnmore(" $d from $o"); }
        }
index d57c5dcc8069f2e97a84ae794b8a718fad9fa5bf..d7887085775bd7f63a04bdc4b8c7e5ef5575404a 100644 (file)
@@ -64,15 +64,11 @@ increase the debugging level.  (Maximum is
 .BR -DD .)
 .TP
 .BR \-g | \-\-glueless
-Warn only once about a glueless referral for each zone and server,
-rather than once for each parent which gave out a referral without
-glue.
-
-When repeated, do not warn about glueless referrals at all.  Not
-recommended.  Note that glueless referrals usually cause extra delays
-looking up names, and can make lookups fail even if in theory they
-could succeed.  There is no generally agreed convention or standard
-for avoiding circular glueless situations such as
+Do not warn about glueless referrals.  Not recommended.  Note that
+glueless referrals usually cause extra delays looking up names, and
+can make lookups fail even if in theory they could succeed.  There is
+no generally agreed convention or standard for avoiding circular
+glueless situations such as
 .br
 .B example.com NS ns0.example.net.uk
 .br
@@ -99,6 +95,10 @@ not relevant to the local server); doing so produces a warning.
 .BR \-q | \-\-quiet
 Do not print any information about zone(s) which do not have warnings.
 .TP
+.BR \-r | \-\-repeat
+When a problem is detected, warn for all sources of the same imperfect
+data, rather than only the first we come across
+.TP
 .BR \-v | \-\-verbose
 Print additional information about each zone.
 .SH USAGE