Changeset 304


Ignore:
Timestamp:
04/16/12 18:14:44 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Drop support for /31 sub-octet ranges in in-addr.arpa zone names in
favour of supporting an alternate scheme that uses the netmask as
the number after the dash. (You can't tell 24-31 -> (range) .24/29
apart from 24-31 (mask) -> .24/31 in isolation.)

Consider supporting / in the zone name too; however / is not
generally considered a valid character for domain name parts.

[ log -> ticket fixup: see #26 ]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r303 r304  
    846846# Not quite a substitution sub, but placed here as it's basically the inverse of above;
    847847# given the .arpa zone name, return the CIDR netblock the zone is for.
    848 # Supports v4 non-octet/non-classful netblocks as per the method outlined in the Cricket Book (2nd Ed p217-218)
     848# Supports v4 non-octet/non-classful netblocks as per the method outlined in the Grasshopper Book (2nd Ed p217-218)
    849849# Does NOT support non-quad v6 netblocks via the same scheme;  it shouldn't ever be necessary.
    850850# Takes a nominal .arpa zone name, returns a success code and NetAddr::IP, or a fail code and message
     
    866866
    867867    # Map result of a range manipulation to a mask length change.  Cheaper than finding the 2-root of $octets[0]+1.
    868     my %maskmap = (1 => 1, 3 => 2, 7 => 3, 15 => 4, 31 => 5, 63 => 6, 127 => 7);
     868    # Note we will not support /31 blocks, mostly due to issues telling "24-31" -> .24/29 apart from
     869    # "24-31" -> .24/31", with a litte bit of "/31 is icky".
     870    my %maskmap = (  3 => 2,  7 => 3, 15 => 4, 31 => 5, 63 => 6, 127 => 7,
     871                    30 => 2, 29 => 3, 28 => 4, 27 => 5, 26 => 6,  25 => 7
     872        );
    869873
    870874    # Handle "range" blocks, eg, 80-83.168.192.in-addr.arpa (192.168.80.0/22)
    871875    # Need to take the size of the range to offset the basic octet-based mask length,
    872876    # and make sure the first number in the range gets used as the network address for the block
     877    # Alternate form:  The second number is actually the real netmask, not the end of the range.
    873878    my $masklen = 0;
    874     if ($octs[0] =~ /(\d+)-\d+/) {      # take the range...
    875       $masklen -= $maskmap{-(eval $octs[0])};   # find the mask base...
     879    if ($octs[0] =~ /(\d+)-(\d+)/) {    # take the range...
     880      if (24 < $2 && $2 < 31) {
     881        # we have a real netmask
     882        $masklen = -$maskmap{$2};
     883      } else {
     884        # we have a range.  NB:  only real CIDR ranges are supported
     885        $masklen -= $maskmap{-(eval $octs[0])}; # find the mask base...
     886      }
    876887      $octs[0] = $1;    # set the base octet of the range...
    877888    }
    878889    @octs = reverse @octs;      # We can reverse the octet pieces now that we've extracted and munged any ranges
     890
     891# arguably we should only allow sub-octet range/mask in-addr.arpa
     892# specifications in the least significant octet, but the code is
     893# simpler if we deal with sub-octet delegations at any level.
    879894
    880895    # Now we find the "true" mask with the aid of the "base" calculated above
Note: See TracChangeset for help on using the changeset viewer.