Changeset 345


Ignore:
Timestamp:
06/12/12 17:59:39 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Checkpoint adding delegation type. See #26.

  • stuck on how to mask the parent zone's NS records if a delegated segment has records for the same "level" of v4 netblock, without blocking the ability to have multiple NS records and delegation records for any given block
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r344 r345  
    871871  }
    872872
    873   # check domain, if nonexistent coerce down to PTR template
    874873  return ('OK','OK');
    875874} # done AAAA+PTR template record
     
    881880
    882881# Delegation record
     882# This is essentially a specialized clone of the NS record, primarily useful
     883# for delegating IPv4 sub-/24 reverse blocks
    883884sub _validate_65285 {
     885  my $dbh = shift;
     886
     887  my %args = @_;
     888
     889# Almost, but not quite, identical to NS record validation.
     890
     891  # Check that the target of the record is within the parent.
     892  # Yes, host<->val are mixed up here;  can't see a way to avoid it.  :(
     893  if ($args{defrec} eq 'n') {
     894    # Check if IP/address/zone/"subzone" is within the parent
     895    if ($args{revrec} eq 'y') {
     896      my $tmpip = NetAddr::IP->new(${$args{val}});
     897      my $pname = revName($dbh,$args{id});
     898      return ('FAIL',"${$args{val}} not within $pname")
     899         unless _ipparent($dbh, $args{defrec}, $args{revrec}, $args{val}, $args{id}, \$tmpip);
     900      # Normalize
     901      ${$args{val}} = "$tmpip";
     902    } else {
     903      my $pname = domainName($dbh,$args{id});
     904      ${$args{host}} =~ s/\.*$/\.$pname/ if ${$args{host}} !~ /$pname$/;
     905    }
     906  } else {
     907    return ('FAIL',"Delegation records are not permitted in default record sets");
     908  }
    884909  return ('OK','OK');
    885910}
     
    17941819      $sth->execute($reverse_typemap{AAAA}, $zoneid, 65281);
    17951820# We don't have an "A template" or "AAAA template" type, although it might be useful for symmetry.
    1796 #      $sth->execute(65285?, $zoneid, 65283);
    1797 #      $sth->execute(65285?, $zoneid, 65284);
     1821#      $sth->execute(65286?, $zoneid, 65283);
     1822#      $sth->execute(65286?, $zoneid, 65284);
    17981823      $failmsg = "Failure removing reverse records";
    17991824      $dbh->do("DELETE FROM records WHERE rdns_id=?", undef, ($zoneid));
     
    32723297      push @vallist, 0;
    32733298    }
     3299  }
     3300  # fix fat-finger-originated record type changes
     3301  if ($$rectype == 65285) {
     3302    $fields .= ",rdns_id" if $revrec eq 'n';
     3303    $fields .= ",domain_id" if $revrec eq 'y';
     3304    push @vallist, 0;
    32743305  }
    32753306  if ($defrec eq 'n') {
     
    43194350
    43204351        if ($revrec eq 'y') {
     4352
     4353print "$zone has\t$val NS $host\n";
    43214354          $val = NetAddr::IP->new($val);
    4322           print $datafile '&'._ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa').
    4323                 "::$host:$ttl:$stamp:$loc\n";
     4355          $zone = NetAddr::IP->new($zone);
     4356#print "$val NS $host\n";
     4357          # handle split-n-multiply SOA for off-octet (8 < mask < 16) or (16 < mask < 24) v4 zones
     4358          if (!$val->{isv6} && ($val->masklen < 24) && ($val->masklen % 8 != 0)) {
     4359            foreach my $szone ($zone->split($val->masklen + (8 - $val->masklen % 8))) {
     4360              my $szone2 = _ZONE($szone, 'ZONE.in-addr.arpa', 'r', '.');
     4361next if $$recflags{"$szone2-sub"} && $zone != $val;
     4362print " $szone2-sub     NS $host\n";
     4363# && $zone == $val;
     4364              print $datafile "\&$szone2"."::$host:$ttl:$stamp:$loc\n";
     4365              $$recflags{"$szone2-sub"}++ if $zone != $val;
     4366            }
     4367#print "recflags should have stuff set?\n";
     4368            return; # skips "default" bits just below
     4369          }
     4370my $val2 = _ZONE($val, 'ZONE', 'r', '.').($val->{isv6} ? '.ip6.arpa' : '.in-addr.arpa');
     4371#print "checking recflags for $val\n";
     4372#return if $$recflags{$val};
     4373          print $datafile '&'.$val2."::$host:$ttl:$stamp:$loc\n";
     4374          $$recflags{"$val2-sub"}++ if $val == $zone;
     4375print "$zone;\t$val2-sub NS $host\n";
     4376##NSfixme
    43244377        } else {
    43254378          print $datafile "\&$host"."::$val:$ttl:$stamp:$loc\n";
     
    44774530        # (eg http://search.cpan.org/dist/AllKnowingDNS/ )
    44784531
     4532      } elsif ($type == 65285) { # Delegation
     4533        # This is intended for reverse zones, but may prove useful in forward zones.
     4534
     4535if ($revrec eq 'n') {
     4536  # It's an NS record.  Recurse and handle.
     4537  _printrec_tiny($datafile,$revrec,$recflags,$zone,$host,$reverse_typemap{'NS'},
     4538        $val,$dist,$weight,$port,$ttl,$loc,$stamp);
     4539} else {
     4540  # It's a delegation.  We may need to actually generate several NS records, and
     4541  # for IPv4 we may also need to generate a set of CNAMEs for sub-/24 blocks.
     4542#  print "delegation $val to $host\n";
     4543  my $dblock = NetAddr::IP->new($val);
     4544  if ($dblock->{isv6}) {
     4545    my @subs = $dblock->split($dblock->masklen + (4 - $dblock->masklen % 4) % 4);
     4546    foreach (@subs) {
     4547      _printrec_tiny($datafile, $revrec, $recflags, $zone, $host, $reverse_typemap{'NS'},
     4548        "$_", $dist, $weight, $port, $ttl, $loc, $stamp);
     4549    }
     4550  } else {
     4551    my @subs = $dblock->split($dblock->masklen + (8 - $dblock->masklen % 8) % 8);
     4552    foreach (@subs) {
     4553      if ($dblock->masklen <= 24) {
     4554        _printrec_tiny($datafile, $revrec, $recflags, $zone, $host, $reverse_typemap{'NS'},
     4555                "$_", $dist, $weight, $port, $ttl, $loc, $stamp);
     4556#print $datafile "$_ NS $host\n";
     4557##nsdeleg
     4558      } else {
     4559        my ($oct) = ($_->addr =~ /(\d+)$/);
     4560        #print "$_ CNAME $oct."._ZONE($dblock, 'ZONE.in-addr.arpa', 'r', '.')."\n";
     4561      }
     4562    }
     4563  }
     4564
     4565#print $datafile "C$host:$val:$ttl:$stamp:$loc\n";
     4566}
     4567
    44794568      } else {
    44804569        # raw record.  we don't know what's in here, so we ASS-U-ME the user has
Note: See TracChangeset for help on using the changeset viewer.