* "Fixed" an issue with NAT Login Handler, apparently an IPv4Mask can be null on an IPv4 address. Go figure. (!?!)

0.6.6-post-fixes
Adam Frisby 2009-05-23 07:07:02 +00:00
parent 6b312d9340
commit bb363d9aa4
1 changed files with 24 additions and 1 deletions

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Net.Sockets; using System.Net.Sockets;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Reflection;
using log4net;
namespace OpenSim.Framework namespace OpenSim.Framework
{ {
@ -16,6 +18,9 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
public static class NetworkUtil public static class NetworkUtil
{ {
// Logger
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// IPv4Address, Subnet // IPv4Address, Subnet
static readonly Dictionary<IPAddress,IPAddress> m_subnets = new Dictionary<IPAddress, IPAddress>(); static readonly Dictionary<IPAddress,IPAddress> m_subnets = new Dictionary<IPAddress, IPAddress>();
@ -25,8 +30,11 @@ namespace OpenSim.Framework
foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName())) foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName()))
{ {
if (host.Equals(user) && host.AddressFamily == AddressFamily.InterNetwork) if (host.Equals(user) && host.AddressFamily == AddressFamily.InterNetwork)
{
m_log.Info("[NATROUTING] Localhost user detected, sending them '" + host + "' instead of '" + simulator + "'");
return host; return host;
} }
}
// Check for same LAN segment // Check for same LAN segment
foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets) foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets)
@ -50,8 +58,11 @@ namespace OpenSim.Framework
} }
if (valid) if (valid)
{
m_log.Info("[NATROUTING] Local LAN user detected, sending them '" + subnet.Key + "' instead of '" + simulator + "'");
return subnet.Key; return subnet.Key;
} }
}
// Otherwise, return outside address // Otherwise, return outside address
return simulator; return simulator;
@ -65,9 +76,12 @@ namespace OpenSim.Framework
foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname)) foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname))
{ {
if (host.AddressFamily == AddressFamily.InterNetworkV6) if (host.AddressFamily == AddressFamily.InterNetworkV6)
{
m_log.Info("[NATROUTING] Localhost user detected, sending them '" + host + "' instead of '" + defaultHostname + "'");
return host; return host;
} }
} }
}
if(destination.AddressFamily != AddressFamily.InterNetwork) if(destination.AddressFamily != AddressFamily.InterNetwork)
return null; return null;
@ -101,8 +115,11 @@ namespace OpenSim.Framework
} }
if (valid) if (valid)
{
m_log.Info("[NATROUTING] Local LAN user detected, sending them '" + subnet.Key + "' instead of '" + defaultHostname + "'");
return subnet.Key; return subnet.Key;
} }
}
// Check to see if we can find a IPv4 address. // Check to see if we can find a IPv4 address.
foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname)) foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname))
@ -122,8 +139,14 @@ namespace OpenSim.Framework
foreach (UnicastIPAddressInformation address in ni.GetIPProperties().UnicastAddresses) foreach (UnicastIPAddressInformation address in ni.GetIPProperties().UnicastAddresses)
{ {
if (address.Address.AddressFamily == AddressFamily.InterNetwork) if (address.Address.AddressFamily == AddressFamily.InterNetwork)
{
if (address.IPv4Mask != null)
{ {
m_subnets.Add(address.Address, address.IPv4Mask); m_subnets.Add(address.Address, address.IPv4Mask);
} else
{
m_log.Warn("[NetworkUtil] Found IPv4 Address without Subnet Mask!?");
}
} }
} }
} }