Opened 14 years ago

Closed 14 years ago

#241 closed defect (fixed)

Support IPv6 addresses

Reported by: heikki Owned by: heikki
Priority: blocker Milestone: v2.5.0
Component: General Version: v2.5.0
Keywords: Cc:

Description

AccessManager throws a runtime exception if you have an IPv6 address other than "0:0:0:0:0:0:0:1".

I propose we change AccessManager's isIntranet() method thus:

private boolean isIntranet(String ip) {

--- consider IPv4 & IPv6 loopback --- we use 'startsWith' because some addresses can be 0:0:0:0:0:0:0:1%0

if (ip.startsWith("0:0:0:0:0:0:0:1")
ip.equals("127.0.0.1")) return true;

IPv6 link-local String ipv6LinkLocalPrefix = "fe80:"; if(ip.toLowerCase().startsWith(ipv6LinkLocalPrefix.toLowerCase())) {

return true;

} other IPv6 else if(ip.indexOf(':') >= 0) {

return false;

}

IPv4

String network = settMan.getValue("system/intranet/network"); String netmask = settMan.getValue("system/intranet/netmask");

try { long lIntranetNet = getAddress(network); long lIntranetMask = getAddress(netmask); long lAddress = getAddress(ip); return (lAddress & lIntranetMask) == lIntranetNet ; } catch (Exception nfe) {

nfe.printStackTrace(); return false;

}

}

Could someone please verify this solution ?

Change History (2)

comment:1 by heikki, 14 years ago

trying again for readability

	private boolean isIntranet(String ip)
	{
		//--- consider IPv4 & IPv6 loopback
		//--- we use 'startsWith' because some addresses can be 0:0:0:0:0:0:0:1%0

		if (ip.startsWith("0:0:0:0:0:0:0:1") || ip.equals("127.0.0.1")) return true;

        // IPv6 link-local
        String ipv6LinkLocalPrefix = "fe80:";
        if(ip.toLowerCase().startsWith(ipv6LinkLocalPrefix.toLowerCase())) {
            return true;
        }
        // other IPv6
        else if(ip.indexOf(':') >= 0) {
            return false;
        }

        // IPv4

		String network = settMan.getValue("system/intranet/network");
		String netmask = settMan.getValue("system/intranet/netmask");

		try {
		long lIntranetNet  = getAddress(network);
		long lIntranetMask = getAddress(netmask);
		long lAddress      = getAddress(ip);
		return (lAddress & lIntranetMask) == lIntranetNet ;
		} catch (Exception nfe) {
			nfe.printStackTrace();
			return false;
		}
	}

comment:2 by heikki, 14 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.