- Timestamp:
- 04/16/12 18:14:44 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r303 r304 846 846 # Not quite a substitution sub, but placed here as it's basically the inverse of above; 847 847 # 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 CricketBook (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) 849 849 # Does NOT support non-quad v6 netblocks via the same scheme; it shouldn't ever be necessary. 850 850 # Takes a nominal .arpa zone name, returns a success code and NetAddr::IP, or a fail code and message … … 866 866 867 867 # 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 ); 869 873 870 874 # Handle "range" blocks, eg, 80-83.168.192.in-addr.arpa (192.168.80.0/22) 871 875 # Need to take the size of the range to offset the basic octet-based mask length, 872 876 # 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. 873 878 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 } 876 887 $octs[0] = $1; # set the base octet of the range... 877 888 } 878 889 @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. 879 894 880 895 # Now we find the "true" mask with the aid of the "base" calculated above
Note:
See TracChangeset
for help on using the changeset viewer.