diff options
author | jim-p <jimp@pfsense.org> | 2011-06-09 12:35:55 -0400 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2011-06-09 12:35:55 -0400 |
commit | 7638901b02b1a6d708e6f027ecb6ecae21fa08f3 (patch) | |
tree | 7d60f5cb2749bfd14140dbca4f3bb7215379ae23 /config/tinydns/tinydns.inc | |
parent | f13b5d60c7b350ee5ec2ceebddd1e685d934334b (diff) | |
download | pfsense-packages-7638901b02b1a6d708e6f027ecb6ecae21fa08f3.tar.gz pfsense-packages-7638901b02b1a6d708e6f027ecb6ecae21fa08f3.tar.bz2 pfsense-packages-7638901b02b1a6d708e6f027ecb6ecae21fa08f3.zip |
Fixup masking, add comments.
Diffstat (limited to 'config/tinydns/tinydns.inc')
-rw-r--r-- | config/tinydns/tinydns.inc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/config/tinydns/tinydns.inc b/config/tinydns/tinydns.inc index f8bc0a53..51ec13f7 100644 --- a/config/tinydns/tinydns.inc +++ b/config/tinydns/tinydns.inc @@ -866,15 +866,25 @@ function tinydns_get_ip_subnet_arpa($ip, $ipmask) { return array($subnet,$arpaip); } -/* ip6.arpa IP calculated from expanding IPv6 fully and reversing. Masking not yet supported. */ +/* ip6.arpa IP calculated from expanding IPv6 fully and reversing. */ function tinydns_get_ip6_subnet_arpa($ip, $ipmask=128) { require_once("IPv6.inc"); + $subnet = Net_IPv6::compress(Net_IPv6::getNetmask($ip, $ipmask)); + + /* Uncompress the v6 IP so we have all of the sections we need */ $fullip = explode(":", Net_IPv6::uncompress($ip)); + + /* Expand even more so we have a digit in every possible place */ foreach ($fullip as & $q) { $q = sprintf("%04s", $q); } - $subnet = Net_IPv6::compress(implode(":", $fullip)); - $arpaip = implode(".", array_reverse(str_split(implode("", $fullip)))) . ".ip6.arpa"; + + /* Turn the IP into an array of digits and then trim off the bits that have been masked away. */ + $prefixlen = intval($ipmask/4); + $fullip = array_slice(str_split(implode("", $fullip)), 0, $prefixlen); + + /* Reverse the IP and make a proper ip6.arpa of it */ + $arpaip = implode(".", array_reverse($fullip)) . ".ip6.arpa"; return array($subnet, $arpaip); } |