Changeset 717 for trunk


Ignore:
Timestamp:
04/15/16 12:23:03 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Rollup of refinements mainly for IPDB RPC calls

  • Tweak stripping of CIDR mask length to avoid missing a record
  • Extra canonicalization of IP addresses to avoid missing a record
  • Pass RPC flag in all getRecList() calls except direct RPC shim, so that callers not dealing natively with actual records can just send in the IPs
  • Fix a couple of corner cases where detection of existing records didn't fire when it should (causing duplicates), or fired when it shouldn't (causing missing records)
  • Refine handling of record sets so that deletes happen when they should
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns-rpc.cgi

    r710 r717  
    580580    my $zone = new NetAddr::IP $zonelist->[0]->{revnet};
    581581    if ($zone->contains($cidr)) {
    582       # We need to strip the CIDR mask on IPv4 /32 assignments, or we just add a new record all the time.
    583       my $filt = ($cidr->{isv6} || $cidr->masklen != 32 ? "$cidr" : $cidr->addr);
    584       my $reclist = $dnsdb->getRecList(defrec => 'n', revrec => 'y',
     582      # We need to strip the CIDR mask on IPv4 /32 or v6 /128 assignments, or we just add a new record all the time.
     583      my $filt = ( $cidr->{isv6} ? ($cidr->masklen != 128 ? "$cidr" : $cidr->addr) :
     584                   ($cidr->masklen != 32 ? "$cidr" : $cidr->addr) );
     585      my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y',
    585586        id => $zonelist->[0]->{rdns_id}, filter => $filt);
    586587##fixme: Figure some new magic to automerge new incoming A(AAA)+PTR requests
     
    598599                || $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
    599600          next unless $rec->{val} eq $filt;     # make sure we really update the record we want to update.
    600           my %newrec = (host => $args{name}, val => $args{cidr}, type => $args{type});
     601          # canonicalize the IP values so funny IPv6 short forms don't
     602          # cause non-updates by not being literally string-equal
     603          $rec->{val} = new NetAddr::IP $rec->{val};
     604          my $tmpcidr = new NetAddr::IP $args{cidr};
     605          my %newrec = (host => $args{name}, val => $tmpcidr, type => $args{type});
    601606          rpc_updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id},
    602607                parent_id => $zonelist->[0]->{rdns_id}, address => "$cidr", %args)
     
    620625    # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones)
    621626    foreach my $zdata (@$zonelist) {
    622       my $reclist = $dnsdb->getRecList(defrec => 'n', revrec => 'y',
     627      my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y',
    623628        id => $zdata->{rdns_id}, filter => $zdata->{revnet});
    624629      if (scalar(@$reclist) == 0) {
     
    627632          address => "$args{cidr}", %args);
    628633      } else {
     634        my $updflag = 0;
    629635        foreach my $rec (@$reclist) {
    630636          # only the composite and/or template types;  pure PTR or nontemplate composite
    631637          # types are nominally impossible here.
    632638          next unless $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
     639          my %newrec = (host => $args{name}, val => $zdata->{revnet}, type => $args{type});
    633640          rpc_updateRec(defrec => 'n', revrec => 'y', id => $rec->{record_id},
    634             parent_id => $zdata->{rdns_id}, %args);
     641            parent_id => $zdata->{rdns_id}, %args)
     642            if _checkRecMod($rec, \%newrec);    # and only do the update if there really is something to change
     643          $updflag = 1;
    635644          last; # only do one record.
    636645        }
    637       }
     646        # catch the case of "oops, no zone-sized template record and need to add a new one",
     647        # because the SOA and NS records will be returned from the getRecList() call above
     648        unless ($updflag) {
     649          my $type = ($cidr->{isv6} ? 65284 : 65283);
     650          rpc_addRec(defrec => 'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type,
     651            address => $zdata->{revnet}, %args);
     652        }
     653      } # scalar(@$reclist) != 0
    638654    } # iterate zones within $cidr
    639655  } # done $cidr-contains-zones
     
    658674  # now we check the parts of the block that didn't get passed to see if they should be deleted
    659675  my $block = new NetAddr::IP $args{cidr};
    660   foreach my $ip (@{$block->splitref(32)}) {
    661     my $bare = $ip->addr;
    662     next if $args{"host_$bare"};
    663     delByCIDR(delforward => 1, delsubs => 0, cidr => $bare, location => $args{location},
     676  if (!$block->{isv6}) {
     677    foreach my $ip (@{$block->splitref(32)}) {
     678      my $bare = $ip->addr;
     679      next if $args{"host_$bare"};
     680      delByCIDR(delforward => 1, delsubs => 0, cidr => $bare, location => $args{location},
    664681        rpcuser => $args{rpcuser}, rpcsystem => $args{rpcsystem});
     682    }
    665683  }
    666684
     
    687705    if ($zone->contains($cidr)) {
    688706      # Find the first record in the reverse zone that matches the CIDR we're splitting...
    689       my $reclist = $dnsdb->getRecList(defrec => 'n', revrec => 'y',
     707      my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y',
    690708        id => $zonelist->[0]->{rdns_id}, filter => $cidr, sortby => 'val', sortorder => 'DESC');
    691709      my $oldrec;
     
    896914  $args{delforward} = 0 if !$args{delforward};
    897915
     916  # make sure this is set if not passed
     917  $args{location} = '' if !$args{location};
     918
    898919  # much like addOrUpdateRevRec()
    899920  my $zonelist = $dnsdb->getZonesByCIDR(%args);
     
    909930      if ($args{delsubs}) {
    910931        # Delete ALL EVARYTHING!!one11!! in $args{cidr}
    911         my $reclist = $dnsdb->getRecList(defrec => 'n', revrec => 'y', id => $zonelist->[0]->{rdns_id});
     932        my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', id => $zonelist->[0]->{rdns_id});
    912933        foreach my $rec (@$reclist) {
    913934          my $reccidr = new NetAddr::IP $rec->{val};
     
    935956        # Selectively delete only exact matches on $args{cidr}
    936957        # We need to strip the CIDR mask on IPv4 /32 assignments, or we can't find single-IP records
    937         my $filt = ($cidr->{isv6} || $cidr->masklen != 32 ? "$cidr" : $cidr->addr);
    938         my $reclist = $dnsdb->getRecList(defrec => 'n', revrec => 'y',
     958        my $filt = ( $cidr->{isv6} ? ($cidr->masklen != 128 ? "$cidr" : $cidr->addr) :
     959                     ($cidr->masklen != 32 ? "$cidr" : $cidr->addr) );
     960        my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', location => $args{location},
    939961          id => $zonelist->[0]->{rdns_id}, filter => $filt, sortby => 'val', sortorder => 'DESC');
    940962        foreach my $rec (@$reclist) {
    941963          my $reccidr = new NetAddr::IP $rec->{val};
    942964          next unless $cidr == $reccidr;
    943           # restrict to the right location
    944           next unless ( defined($rec->{locname}) && defined($args{location}) &&
    945                       $rec->{locname} eq $args{location} );
    946965          next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
    947966                      $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
     
    967986    # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones)
    968987    foreach my $zdata (@$zonelist) {
    969       my $reclist = $dnsdb->getRecList(defrec => 'n', revrec => 'y', id => $zdata->{rdns_id});
     988      my $reclist = $dnsdb->getRecList(rpc => 1, defrec => 'n', revrec => 'y', id => $zdata->{rdns_id});
    970989      if (scalar(@$reclist) == 0) {
    971990# nothing to do?  or do we (re)add a record based on the parent?
Note: See TracChangeset for help on using the changeset viewer.