aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/NetworkUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/NetworkUtil.cs')
-rw-r--r--OpenSim/Framework/NetworkUtil.cs68
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 }