diff options
author | Diva Canto | 2010-08-18 16:22:50 -0700 |
---|---|---|
committer | Diva Canto | 2010-08-18 16:22:50 -0700 |
commit | e47608fc62647a28be91dd9caf6e446826fdb54c (patch) | |
tree | 367a2773accb017e9a6c328558a3281d7754cdb5 /OpenSim/Framework/NetworkUtil.cs | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-e47608fc62647a28be91dd9caf6e446826fdb54c.zip opensim-SC-e47608fc62647a28be91dd9caf6e446826fdb54c.tar.gz opensim-SC-e47608fc62647a28be91dd9caf6e446826fdb54c.tar.bz2 opensim-SC-e47608fc62647a28be91dd9caf6e446826fdb54c.tar.xz |
One more go at GetExternalIpOf(user). Addresses mantis #4955 and #4943.
(Files .xml and .txt also want to be committed)
Diffstat (limited to 'OpenSim/Framework/NetworkUtil.cs')
-rw-r--r-- | OpenSim/Framework/NetworkUtil.cs | 68 |
1 files changed, 40 insertions, 28 deletions
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 | |||
274 | } | 274 | } |
275 | } | 275 | } |
276 | 276 | ||
277 | // Check for same LAN segment | 277 | // Check for private networks |
278 | foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets) | 278 | if (user.ToString().StartsWith("192.168")) |
279 | { | 279 | { |
280 | byte[] subnetBytes = subnet.Value.GetAddressBytes(); | 280 | m_log.Info("[NetworkUtil] Private network user detected, sending '" + externalIPAddress + "' instead of '" + user + "'"); |
281 | byte[] localBytes = subnet.Key.GetAddressBytes(); | 281 | return externalIPAddress; |
282 | byte[] destBytes = user.GetAddressBytes(); | ||
283 | |||
284 | if (subnetBytes.Length != destBytes.Length || subnetBytes.Length != localBytes.Length) | ||
285 | return user; | ||
286 | |||
287 | bool valid = true; | ||
288 | |||
289 | for (int i = 0; i < subnetBytes.Length; i++) | ||
290 | { | ||
291 | if ((localBytes[i] & subnetBytes[i]) != (destBytes[i] & subnetBytes[i])) | ||
292 | { | ||
293 | valid = false; | ||
294 | break; | ||
295 | } | ||
296 | } | ||
297 | |||
298 | if (subnet.Key.AddressFamily != AddressFamily.InterNetwork) | ||
299 | valid = false; | ||
300 | |||
301 | if (valid) | ||
302 | { | ||
303 | m_log.Info("[NetworkUtil] Local LAN user detected, sending '" + externalIPAddress + "' instead of '" + user + "'"); | ||
304 | return externalIPAddress; | ||
305 | } | ||
306 | } | 282 | } |
307 | 283 | ||
284 | // We may need to do more fancy configuration-based checks... I'm not entirely sure there is | ||
285 | // a 100% algorithmic manner of dealing with all the network setups out there. This code | ||
286 | // will evolve as people bump into problems. | ||
287 | |||
288 | //// Check for same LAN segment -- I don't think we want to do this in general. Leaving it here | ||
289 | //// for now as a reminder | ||
290 | //foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets) | ||
291 | //{ | ||
292 | // byte[] subnetBytes = subnet.Value.GetAddressBytes(); | ||
293 | // byte[] localBytes = subnet.Key.GetAddressBytes(); | ||
294 | // byte[] destBytes = user.GetAddressBytes(); | ||
295 | |||
296 | // if (subnetBytes.Length != destBytes.Length || subnetBytes.Length != localBytes.Length) | ||
297 | // return user; | ||
298 | |||
299 | // bool valid = true; | ||
300 | |||
301 | // for (int i = 0; i < subnetBytes.Length; i++) | ||
302 | // { | ||
303 | // if ((localBytes[i] & subnetBytes[i]) != (destBytes[i] & subnetBytes[i])) | ||
304 | // { | ||
305 | // valid = false; | ||
306 | // break; | ||
307 | // } | ||
308 | // } | ||
309 | |||
310 | // if (subnet.Key.AddressFamily != AddressFamily.InterNetwork) | ||
311 | // valid = false; | ||
312 | |||
313 | // if (valid) | ||
314 | // { | ||
315 | // m_log.Info("[NetworkUtil] Local LAN user detected, sending '" + externalIPAddress + "' instead of '" + user + "'"); | ||
316 | // return externalIPAddress; | ||
317 | // } | ||
318 | //} | ||
319 | |||
308 | // Otherwise, return user address | 320 | // Otherwise, return user address |
309 | return user; | 321 | return user; |
310 | } | 322 | } |