Main repository for pfSense
Go to file
stilez e89d2995bb Tighten and IPv6-ify gen_subnet() etc
Tightens, canonicalises and improves for IPv6, the functions
gen_subnet(), gen_subnetv6(), gen_subnet_max(), gen_subnetv6_max()

Changes are transparent to calling code.

Issues:

1) gen_subnet() and gen_subnet_max() will validate both IPv4 and IPv6 as valid args, but will then try to process an IPv6 subnet bitwise as x32 LONG without further checking, causing erroneous but apparently valid responses.

2) None of the functions properly sanitise their input: if $bits is >32 or >128, or even a non-integer, erroneous results will be passed back to the calling code as valid data without checking, again causing erroneous but apparently valid responses.

3) 3 of the 4 functions return an empty string for invalid but gen_subnetv6_max() returns a numeric value for invalid. Both responses loose-evaluate as False, but consistency is better.

Fixes and improvements:

1) The unspecified functions gen_subnet() and gen_subnet_max() now handle all args correctly, and don't mishandle if unexpectedly passed IPv6 or bad data.

2) Names are now canonical: gen_subnet(), gen_subnet_max() are now IPv4/v6 agnostic, and IPv4-only versions gen_subnetv4() and gen_subnetv4_max() are added as expected to exist, to match existing functions gen_subnetv6() and gen_subnetv6_max().

3) The return value for bad args is made consistent (empty string = False).

4) gen_subnetv6_max() now uses Net_IPv6's Ip2Bin() and Bin2Ip() functions and simple string manipulation rather than bitwise operations, so it's guaranteed 32-bit safe (compared to 128-bit bitwise operations in current code which seem less certain?)

5) Changes are transparent - the canonical functions still work exactly as before on IPv4 (only with proper bad arg validation) but also now work on IPv6 transparently, and on arbitrary IPv4/IPv6 data, similar to other functions like is_ipaddr().

Tested and handles valid but uncommon edge cases of /0, /32 (IPv4) and /128 (IPv6) correctly. Also avoids inet_ntop/pton if that's a real issue (previous PR comment had asked to avoid these functions)
2015-01-06 15:14:51 -02:00
boot setting nmbclusters to 0 just results in an error, remove unnecessary line 2014-11-04 18:44:29 -06:00
cf/conf Its long overdue the ez-ipupdate.cache file 2014-04-26 09:59:37 +00:00
conf.default Fix #4090: 2015-01-05 15:44:29 -02:00
etc Tighten and IPv6-ify gen_subnet() etc 2015-01-06 15:14:51 -02:00
root Set proxy env vars on interactive shell and also on crontab to make all scripts be able to use it. Ticket #3789 2014-11-11 11:57:38 -02:00
sbin Set this to /8 instead since that's how it's done in stock FreeBSD 10.1. Ticket #3941 2014-11-10 21:52:52 -06:00
tmp Deal correct with filenames with spaces 2014-11-14 07:46:57 -02:00
usr OpenVPN backend authentication fix key and translation 2015-01-06 07:27:36 +05:45
.gitattributes include gettext locales in line encoding list 2014-01-13 22:05:10 -05:00
.gitignore Ignore vim swap files 2013-03-08 14:41:01 -03:00
license.txt Welcome 2015 2014-12-31 16:22:00 -02:00