util.ip: Improve comparison, == doesn't necessarily handle IPv6 addresses correctly if they aren't normalized (case, ::, etc.)
authorMatthew Wild <mwild1@gmail.com>
Sun, 22 Nov 2015 15:30:27 +0000
changeset 6929 d96b2aa7a11d
parent 6927 c37ad3e1fdd9
child 6930 566e1cfcb814
util.ip: Improve comparison, == doesn't necessarily handle IPv6 addresses correctly if they aren't normalized (case, ::, etc.)
util/ip.lua
--- a/util/ip.lua	Tue Nov 17 17:04:04 2015 +0000
+++ b/util/ip.lua	Sun Nov 22 15:30:27 2015 +0000
@@ -229,13 +229,10 @@
 
 local function match(ipA, ipB, bits)
 	local common_bits = commonPrefixLength(ipA, ipB);
-	if not bits then
-		return ipA == ipB;
-	end
 	if bits and ipB.proto == "IPv4" then
 		common_bits = common_bits - 96; -- v6 mapped addresses always share these bits
 	end
-	return common_bits >= bits;
+	return common_bits >= (bits or 128);
 end
 
 return {new_ip = new_ip,