From e47608fc62647a28be91dd9caf6e446826fdb54c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 18 Aug 2010 16:22:50 -0700 Subject: One more go at GetExternalIpOf(user). Addresses mantis #4955 and #4943. (Files .xml and .txt also want to be committed) --- OpenSim/Framework/NetworkUtil.cs | 68 +++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/NetworkUtil.cs b/OpenSim/Framework/NetworkUtil.cs index 831ff70..5649131 100644 --- a/OpenSim/Framework/NetworkUtil.cs +++ b/OpenSim/Framework/NetworkUtil.cs @@ -274,37 +274,49 @@ namespace OpenSim.Framework } } - // Check for same LAN segment - foreach (KeyValuePair subnet in m_subnets) + // Check for private networks + if (user.ToString().StartsWith("192.168")) { - byte[] subnetBytes = subnet.Value.GetAddressBytes(); - byte[] localBytes = subnet.Key.GetAddressBytes(); - byte[] destBytes = user.GetAddressBytes(); - - if (subnetBytes.Length != destBytes.Length || subnetBytes.Length != localBytes.Length) - return user; - - bool valid = true; - - for (int i = 0; i < subnetBytes.Length; i++) - { - if ((localBytes[i] & subnetBytes[i]) != (destBytes[i] & subnetBytes[i])) - { - valid = false; - break; - } - } - - if (subnet.Key.AddressFamily != AddressFamily.InterNetwork) - valid = false; - - if (valid) - { - m_log.Info("[NetworkUtil] Local LAN user detected, sending '" + externalIPAddress + "' instead of '" + user + "'"); - return externalIPAddress; - } + m_log.Info("[NetworkUtil] Private network user detected, sending '" + externalIPAddress + "' instead of '" + user + "'"); + return externalIPAddress; } + // We may need to do more fancy configuration-based checks... I'm not entirely sure there is + // a 100% algorithmic manner of dealing with all the network setups out there. This code + // will evolve as people bump into problems. + + //// Check for same LAN segment -- I don't think we want to do this in general. Leaving it here + //// for now as a reminder + //foreach (KeyValuePair subnet in m_subnets) + //{ + // byte[] subnetBytes = subnet.Value.GetAddressBytes(); + // byte[] localBytes = subnet.Key.GetAddressBytes(); + // byte[] destBytes = user.GetAddressBytes(); + + // if (subnetBytes.Length != destBytes.Length || subnetBytes.Length != localBytes.Length) + // return user; + + // bool valid = true; + + // for (int i = 0; i < subnetBytes.Length; i++) + // { + // if ((localBytes[i] & subnetBytes[i]) != (destBytes[i] & subnetBytes[i])) + // { + // valid = false; + // break; + // } + // } + + // if (subnet.Key.AddressFamily != AddressFamily.InterNetwork) + // valid = false; + + // if (valid) + // { + // m_log.Info("[NetworkUtil] Local LAN user detected, sending '" + externalIPAddress + "' instead of '" + user + "'"); + // return externalIPAddress; + // } + //} + // Otherwise, return user address return user; } -- cgit v1.1