- Timestamp:
- 04/17/12 18:09:44 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r304 r307 877 877 # Alternate form: The second number is actually the real netmask, not the end of the range. 878 878 my $masklen = 0; 879 if ($octs[0] =~ / (\d+)-(\d+)/) { # take the range...880 if (24 < $ 2 && $2< 31) {879 if ($octs[0] =~ /^((\d+)-(\d+))$/) { # take the range... 880 if (24 < $3 && $3 < 31) { 881 881 # we have a real netmask 882 $masklen = -$maskmap{$ 2};882 $masklen = -$maskmap{$3}; 883 883 } else { 884 884 # we have a range. NB: only real CIDR ranges are supported 885 $masklen -= $maskmap{-(eval $ octs[0])}; # find the mask base...885 $masklen -= $maskmap{-(eval $1)}; # find the mask base... 886 886 } 887 $octs[0] = $ 1; # set the base octet of the range...887 $octs[0] = $2; # set the base octet of the range... 888 888 } 889 889 @octs = reverse @octs; # We can reverse the octet pieces now that we've extracted and munged any ranges … … 3326 3326 $rechost .= ":" if ++$nc % 4 == 0 && $nc < 32; 3327 3327 } 3328 $rechost .= ":" if $nc < 32 && $rechost !~ /\*$/; # close netblock records? 3329 print "$rechost\n"; 3328 $rechost .= ":" if $nc < 32 && $rechost !~ /\*$/; # close netblock records? 3329 ##fixme: there's a case that ends up with a partial entry here: 3330 # ip:add:re:ss:: 3331 # can't reproduce after letting it sit overnight after discovery. :( 3332 #print "$rechost\n"; 3330 3333 # canonicalize with NetAddr::IP 3331 3334 $rechost = NetAddr::IP->new($rechost)->addr unless $rechost =~ /\*$/; … … 3375 3378 " VALUES (?,?,?,?,?,?,?,?,?)"); 3376 3379 3380 # Stash info about sub-octet v4 revzones here so we don't have 3381 # to store the CNAMEs used to delegate a suboctet zone 3382 # $suboct{zone}{ns}[] -> array of nameservers 3383 # $suboct{zone}{cname}[] -> array of extant CNAMEs (Just In Case someone did something bizarre) 3384 ## commented pending actual use of this data. for now, we'll just 3385 ## auto-(re)create the CNAMEs in revzones on export 3386 # my %suboct; 3387 3377 3388 while (my $rr = $res->axfr_next()) { 3378 3389 … … 3423 3434 $host = $rr->nsdname; 3424 3435 $logfrag = "Added record '$val $type $host', TTL $ttl"; 3436 # Tag and preserve. For now this is commented for a no-op, but we have Ideas for 3437 # another custom storage type ("DELEGATE") that will use these subzone-delegation records 3438 #if ($val ne "$cidr") { 3439 # push @{$suboct{$val}{ns}}, $host; 3440 #} 3425 3441 } else { 3426 3442 $val = $rr->nsdname; … … 3434 3450 ($host,$val) = _revswap($host,$rr->cname); 3435 3451 $logfrag = "Added record '$val $type $host', TTL $ttl"; 3452 # Tag and preserve in case we want to commit them as-is later, but mostly we don't care. 3453 # Commented pending actually doing something with possibly new type DELEGATE 3454 #my $tmprev = $host; 3455 #$tmprev =~ s/^\d+\.//; 3456 #($code,$tmprev) = _zone2cidr($tmprev); 3457 #push @{$suboct{"$tmprev"}{cname}}, $val; 3458 # Silently skip CNAMEs in revzones. 3459 next; 3436 3460 } else { 3437 3461 $val = $rr->cname; … … 3439 3463 } elsif ($type eq 'SOA') { 3440 3464 next if $rwsoa; 3441 $host = $rr-> mname.":".$rr->rname;3465 $host = $rr->rname.":".$rr->mname; 3442 3466 $val = $rr->refresh.":".$rr->retry.":".$rr->expire.":".$rr->minimum; 3443 3467 $soaflag = 1; … … 3455 3479 # rdatastr returns a BIND-targetted logical string, including opening and closing quotes 3456 3480 # char_str_list returns a list of the individual string fragments in the record 3457 # txtdata returns the more useful all-in-one form. 3481 # txtdata returns the more useful all-in-one form (since we want to push such protocol 3482 # details as far down the stack as we can) 3458 3483 # NB: this may turn out to be more troublesome if we ever have need of >512-byte TXT records. 3459 3484 if ($rev eq 'y') { … … 3485 3510 my $logentry = "[AXFR ".($rev eq 'n' ? $zone : $cidr)."] "; 3486 3511 3487 $merge = 1; 3488 if ($merge) {3489 if ($rev eq 'n') { 3490 # importing a domain; we have A and AAAA records that could be merged with matching PTR records 3491 my $etype; 3492 my ($erdns,$erid,$ettl) = $dbh->selectrow_array("SELECT rdns_id,record_id,ttl FROM records ". 3493 "WHERE host=? AND val=? AND type=12",3494 undef, ($host, $val) ); 3495 if ($erid) { 3496 if ($type eq 'A') { # PTR -> A+PTR 3497 $etype = 65280;3498 $logentry .= "Merged A record with existing PTR record '$host A+PTR $val', TTL $ettl";3499 } 3500 if ($type eq 'AAAA') { # PTR -> AAAA+PTR 3501 $etype = 65281;3502 $logentry .= "Merged AAAA record with existing PTR record '$host AAAA+PTR $val', TTL $ettl";3503 } 3504 $ettl = ($ettl < $ttl ? $ettl : $ttl); # use lower TTL 3505 $dbh->do("UPDATE records SET domain_id=?,ttl=?,type=? WHERE record_id=?", undef, 3506 ($domain_id, $ettl, $etype, $erid));3507 $nrecs++;3508 _log($dbh, (group_id => $group, domain_id => $domain_id, rdns_id => $erdns, entry => $logentry) ); 3509 next; # while axfr_next 3510 } 3511 }else {3512 3513 3514 "WHERE host=? AND val=? AND (type=1 OR type=28)",3515 3516 3517 3518 $etype = 65280;3519 $logentry .= "Merged PTR record with existing matching A record '$host A+PTR $val', TTL $ettl";3520 3521 3522 $etype = 65281;3523 $logentry .= "Merged PTR record with existing matching AAAA record '$host AAAA+PTR $val', TTL $ettl";3524 3525 3526 3527 ($rdns_id, $ettl, $etype, $erid));3528 3529 3530 3531 3532 } 3533 } 3512 if ($merge) { 3513 if ($rev eq 'n') { 3514 # importing a domain; we have A and AAAA records that could be merged with matching PTR records 3515 my $etype; 3516 my ($erdns,$erid,$ettl) = $dbh->selectrow_array("SELECT rdns_id,record_id,ttl FROM records ". 3517 "WHERE host=? AND val=? AND type=12", 3518 undef, ($host, $val) ); 3519 if ($erid) { 3520 if ($type eq 'A') { # PTR -> A+PTR 3521 $etype = 65280; 3522 $logentry .= "Merged A record with existing PTR record '$host A+PTR $val', TTL $ettl"; 3523 } 3524 if ($type eq 'AAAA') { # PTR -> AAAA+PTR 3525 $etype = 65281; 3526 $logentry .= "Merged AAAA record with existing PTR record '$host AAAA+PTR $val', TTL $ettl"; 3527 } 3528 $ettl = ($ettl < $ttl ? $ettl : $ttl); # use lower TTL 3529 $dbh->do("UPDATE records SET domain_id=?,ttl=?,type=? WHERE record_id=?", undef, 3530 ($domain_id, $ettl, $etype, $erid)); 3531 $nrecs++; 3532 _log($dbh, (group_id => $group, domain_id => $domain_id, rdns_id => $erdns, entry => $logentry) ); 3533 next; # while axfr_next 3534 } 3535 } # $rev eq 'n' 3536 else { 3537 # importing a revzone, we have PTR records that could be merged with matching A/AAAA records 3538 my ($domid,$erid,$ettl,$etype) = $dbh->selectrow_array("SELECT domain_id,record_id,ttl,type FROM records ". 3539 "WHERE host=? AND val=? AND (type=1 OR type=28)", 3540 undef, ($host, $val) ); 3541 if ($erid) { 3542 if ($etype == 1) { # A -> A+PTR 3543 $etype = 65280; 3544 $logentry .= "Merged PTR record with existing matching A record '$host A+PTR $val', TTL $ettl"; 3545 } 3546 if ($etype == 28) { # AAAA -> AAAA+PTR 3547 $etype = 65281; 3548 $logentry .= "Merged PTR record with existing matching AAAA record '$host AAAA+PTR $val', TTL $ettl"; 3549 } 3550 $ettl = ($ettl < $ttl ? $ettl : $ttl); # use lower TTL 3551 $dbh->do("UPDATE records SET rdns_id=?,ttl=?,type=? WHERE record_id=?", undef, 3552 ($rdns_id, $ettl, $etype, $erid)); 3553 $nrecs++; 3554 _log($dbh, (group_id => $group, domain_id => $domid, rdns_id => $rdns_id, entry => $logentry) ); 3555 next; # while axfr_next 3556 } 3557 } # $rev eq 'y' 3558 } # if $merge 3534 3559 3535 3560 # Insert the new record … … 3558 3583 } # while axfr_next 3559 3584 3585 # Detect and handle delegated subzones 3586 # Placeholder for when we decide what to actually do with this, see previous comments in NS and CNAME handling. 3587 #foreach (keys %suboct) { 3588 # print "found ".($suboct{$_}{ns} ? @{$suboct{$_}{ns}} : '0')." NS records and ". 3589 # ($suboct{$_}{cname} ? @{$suboct{$_}{cname}} : '0')." CNAMEs for $_\n"; 3590 #} 3591 3560 3592 # Overwrite SOA record 3561 3593 if ($rwsoa) { … … 3588 3620 die "Bad zone: No NS records!\n" if !$nsflag; 3589 3621 3590 #die "horribly\n";3591 3622 $dbh->commit; 3592 3623
Note:
See TracChangeset
for help on using the changeset viewer.