Index: /trunk/dns-rpc.cgi
===================================================================
--- /trunk/dns-rpc.cgi	(revision 459)
+++ /trunk/dns-rpc.cgi	(revision 460)
@@ -450,5 +450,5 @@
       if (scalar(@$reclist) == 0) {
         # Aren't Magic Numbers Fun?  See pseudotype list in dnsadmin.
-        my $type = ($cidr->{isv6} ? 65282 : ($cidr->masklen == 32 ? 65280 : 65283) );
+        my $type = ($cidr->{isv6} ? 65284 : ($cidr->masklen == 32 ? 65280 : 65283) );
         addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id}, type => $type,
           address => "$cidr", %args);
@@ -534,4 +534,6 @@
           my $reccidr = new NetAddr::IP $rec->{val};
           next unless $cidr->contains($reccidr);
+          next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
+                      $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
           ##fixme:  multiple records, wanna wax'em all, how to report errors?
           if ($args{delforward} ||
@@ -543,4 +545,10 @@
           }
         }
+        if ($args{parpatt} && $zone == $cidr) {
+          # Edge case;  we've just gone and axed all the records in the reverse zone.
+          # Re-add one to match the parent if we've been given a pattern to use.
+          addRec(defrec =>'n', revrec => 'y', parent_id => $zonelist->[0]->{rdns_id},
+                 type => ($zone->{isv6} ? 65284 : 65283), address => "$cidr", %args);
+        }
 
       } else {
@@ -554,4 +562,6 @@
           my $reccidr = new NetAddr::IP $rec->{val};
           next unless $cidr == $reccidr;
+          next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
+                      $rec->{type} == 65282 || $rec->{type} == 65283 ||$rec->{type} == 65284;
           if ($args{delforward} || $rec->{type} == 12) {
             my ($code,$msg) = DNSDB::delRec($dbh, 'n', 'y', $rec->{record_id});
@@ -575,19 +585,32 @@
     # that spans multiple reverse zones (eg, /23 CIDR -> 2 /24 rzones)
     foreach my $zdata (@$zonelist) {
-      my $reclist = DNSDB::getDomRecs($dbh, defrec => 'n', revrec => 'y',
-        id => $zdata->{rdns_id}, filter => $zdata->{revnet});
+      my $reclist = DNSDB::getDomRecs($dbh, defrec => 'n', revrec => 'y', id => $zdata->{rdns_id});
       if (scalar(@$reclist) == 0) {
-        my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) );
-        addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type,
-          address => "$args{cidr}", %args);
+# nothing to do?  or do we (re)add a record based on the parent?
+# yes, yes we do, past the close of the else
+#        my $type = ($args{cidr}->{isv6} ? 65282 : ($args{cidr}->masklen == 32 ? 65280 : 65283) );
+#        addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id}, type => $type,
+#          address => "$args{cidr}", %args);
       } else {
         foreach my $rec (@$reclist) {
-          # only the composite and/or template types;  pure PTR or nontemplate composite
-          # types are nominally impossible here.
-          next unless $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
-          updateRec(defrec =>'n', revrec => 'y', id => $rec->{record_id},
-            parent_id => $zdata->{rdns_id}, %args);
-          last;	# only do one record.
+          next unless $rec->{type} == 12 || $rec->{type} == 65280 || $rec->{type} == 65281 ||
+                      $rec->{type} == 65282 || $rec->{type} == 65283 || $rec->{type} == 65284;
+          # Template types are only useful when attached to a reverse zone.
+##fixme  ..... or ARE THEY?
+          if ($args{delforward} ||
+              $rec->{type} == 12 || $rec->{type} == 65282 ||
+              $rec->{type} == 65283 || $rec->{type} == 65284) {
+            my ($code,$msg) = DNSDB::delRec($dbh, 'n', 'y', $rec->{record_id});
+          } else {
+            my $ret = DNSDB::downconvert($dbh, $rec->{record_id}, $DNSDB::reverse_typemap{A});
+          }
         } # foreach @$reclist
+      } # nrecs != 0
+      if ($args{parpatt}) {
+        # We've just gone and axed all the records in the reverse zone.
+        # Re-add one to match the parent if we've been given a pattern to use.
+        addRec(defrec =>'n', revrec => 'y', parent_id => $zdata->{rdns_id},
+               type => ($cidr->{isv6} ? 65284 : 65283),
+               address => $zdata->{revnet}, name => $args{parpatt}, %args);
       }
     } # iterate zones within $cidr
