Changeset 875 for trunk/DNSDB


Ignore:
Timestamp:
10/05/22 13:54:50 (2 years ago)
Author:
Kris Deugau
Message:

/trunk

BIND export, unwinding dev saves, 27 of many many

  • Tweak domain record export order for consistency/predictability
  • Refine template expansion for forward zones, first iteration
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB/ExportBIND.pm

    r874 r875  
    203203  $soasth = $dnsdb->{dbh}->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location ".
    204204        "FROM records WHERE domain_id=? AND type=6");
    205   # record order doesn't strictly matter, but ordering by conventional zone
    206   # file order doesn't really have a lever without tweaking the table structure.
     205  # record order needs to match reverse zone ordering for IP values, or A+PTR
     206  # template records don't cascade/expand correctly to match the reverse zones.
     207  # order by record_id at least makes the zone consistent from export to export,
     208  # otherwise the records could (theoretically) be returned in any old order by
     209  # the DB engine
    207210  # ordering by nominal parent-child label hierarchy (as actually found live
    208   # in some AXFRed zone files) would be even hairier.
    209   # ordering by record_id has the advantage of consistent order export to export
     211  # in some AXFRed zone files) would take a lot of chewing on data
    210212  $recsth = $dnsdb->{dbh}->prepare("SELECT host,type,val,distance,weight,port,ttl,record_id,location,extract(epoch from stamp),expires,stampactive ".
    211         "FROM records WHERE domain_id=? AND NOT type=6 ORDER BY record_id");
     213        "FROM records WHERE domain_id=? AND NOT type=6 ".
     214        "ORDER BY masklen(inetlazy(val)) DESC, inetlazy(val), record_id");
    212215#      "FROM records WHERE domain_id=? AND type < 65280");     # Just exclude all types relating to rDNS
    213216
     
    303306      $recsth->execute($domid);
    304307      while (my ($host,$type,$val,$dist,$weight,$port,$ttl,$recid,$loc,$stamp,$expires,$stampactive) = $recsth->fetchrow_array) {
     308##work  need more subtle check - $recflags{$val} eq 'ptr' maybe?
    305309        next if $recflags{$recid};
     310#next if $recflags{$val} && $type == 65280;# && !$dnsdb->{template_always_publish_a};
    306311
    307312        # Spaces are evil.
     
    533538
    534539  elsif ($typemap{$type} eq 'PTR') {
    535     $$recflags{$val}++;
     540#    $$recflags{$val}++;
     541       # maybe track exclusions like this?  so we can publish "all
     542       # A and/or PTR records" irrespective of template records
     543    $$recflags{$val} = 'ptr';
    536544    if ($revrec eq 'y') {
    537545
     
    576584    # Recurse to PTR or A as appropriate because BIND et al don't share
    577585    # the tinydns concept of merged forward/reverse records
    578     $$recflags{$val}++;
     586# %recflags gets updated in the PTR branch just above
     587#    $$recflags{$val}++;
    579588    if ($revrec eq 'y') {
    580589      publishrec_bind($zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, 12, $val, $distance, $weight, $port, $ttl,
    581590       $loc, $stamp, $expires, $stampactive);
     591# ... but we need to tweak it for this case?  so the A record gets published...
     592#$$recflags{$val} = 'a+ptr';
    582593#print {$zonefiles->{$loc}} "=$host:$val:$ttl:$stamp:$loc\n" or die $!;
    583594#          publishrec_bind(\%zonefiles, $recid, 'y', \@loclist, $revzone,
     
    587598    } else {
    588599      publishrec_bind($zonefiles, $loclist, $recid, $revrec, $recflags, $zone, $host, 1, $val, $distance, $weight, $port, $ttl,
    589        $loc, $stamp, $expires, $stampactive);
     600        $loc, $stamp, $expires, $stampactive);
     601      # set a unique flag to skip template expansion for this IP in forward zones
     602      $$recflags{$val} = 'a';
    590603    }
    591604  } # A+PTR
     
    638651  my $stamp = shift;
    639652  my $loc = shift;
    640   my $zone = new NetAddr::IP shift;
     653  my $zpass = shift;
     654  my $zone = new NetAddr::IP $zpass;
     655#  my $zone = new NetAddr::IP shift;
    641656  my $revrec = shift || 'y';
    642657#  my $ptrflag = shift || 0;    ##fixme:  default to PTR instead of A record for the BIND variant of this sub?
     
    657672    # %blank% also needs to be per-IP here to properly cascade overrides with
    658673    # multiple nested templates
    659     next if $$recflags{$ip}; # && $self->{skip_bcast_255}
    660     $$recflags{$ip}++;
     674#    next if $$recflags{$ip}; # && $self->{skip_bcast_255}
     675
     676#    next if $$recflags{$ip} && ($$recflags{$ip} eq 'ptr' || $$recflags{$ip} eq 'a+ptr');
     677
     678    if ($revrec eq 'y') {
     679      next if $$recflags{$ip};  # blanket exclusion;  we do reverse records first
     680    } else {
     681##fixme:  A record side templates not cascading correctly
     682      # excluding ptr does NOT work, as it excludes ALL previously covered A+PTR template entries.
     683      # we only want to exclude the singleton (A+)PTR ones
     684      #if ($$recflags{$ip} && ($$recflags{$ip} eq 'a' || $$recflags{$ip} eq 'ptr')) {
     685      if ($$recflags{$ip} && ($$recflags{$ip} eq 'a' || $$recflags{$ip} eq 'atemplate' || $$recflags{$ip} eq 'ptr')) {
     686        # default skip case
     687        next;
     688      }
     689    } # revrec branch for skipping template member expansion
     690
     691    # set a forward/reverse-unique flag in %recflags
     692    $$recflags{$ip} = ($revrec eq 'y' ? 'ptrtemplate' : 'atemplate');
    661693    next if $hpat eq '%blank%';
    662694
Note: See TracChangeset for help on using the changeset viewer.