aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/NetworkUtil.cs72
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs4
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs11
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginService.cs6
4 files changed, 84 insertions, 9 deletions
diff --git a/OpenSim/Framework/NetworkUtil.cs b/OpenSim/Framework/NetworkUtil.cs
index 5fe343d..7c30bd3 100644
--- a/OpenSim/Framework/NetworkUtil.cs
+++ b/OpenSim/Framework/NetworkUtil.cs
@@ -31,6 +31,7 @@ using System.Net.Sockets;
31using System.Net; 31using System.Net;
32using System.Net.NetworkInformation; 32using System.Net.NetworkInformation;
33using System.Reflection; 33using System.Reflection;
34using System.Text;
34using log4net; 35using log4net;
35 36
36namespace OpenSim.Framework 37namespace OpenSim.Framework
@@ -180,10 +181,14 @@ namespace OpenSim.Framework
180 throw new ArgumentException("[NetworkUtil] Unable to resolve defaultHostname to an IPv4 address for an IPv4 client"); 181 throw new ArgumentException("[NetworkUtil] Unable to resolve defaultHostname to an IPv4 address for an IPv4 client");
181 } 182 }
182 183
184 static IPAddress externalIPAddress;
185
183 static NetworkUtil() 186 static NetworkUtil()
184 { 187 {
185 try 188 try
186 { 189 {
190 externalIPAddress = GetExternalIP();
191
187 foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) 192 foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
188 { 193 {
189 foreach (UnicastIPAddressInformation address in ni.GetIPProperties().UnicastAddresses) 194 foreach (UnicastIPAddressInformation address in ni.GetIPProperties().UnicastAddresses)
@@ -244,5 +249,72 @@ namespace OpenSim.Framework
244 } 249 }
245 return defaultHostname; 250 return defaultHostname;
246 } 251 }
252
253 public static IPAddress GetExternalIPOf(IPAddress user)
254 {
255 // Check if we're accessing localhost.
256 foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName()))
257 {
258 if (host.Equals(user) && host.AddressFamily == AddressFamily.InterNetwork)
259 {
260 m_log.Info("[NetworkUtil] Localhost user detected, sending '" + externalIPAddress + "' instead of '" + user + "'");
261 return externalIPAddress;
262 }
263 }
264
265 // Check for same LAN segment
266 foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets)
267 {
268 byte[] subnetBytes = subnet.Value.GetAddressBytes();
269 byte[] localBytes = subnet.Key.GetAddressBytes();
270 byte[] destBytes = user.GetAddressBytes();
271
272 if (subnetBytes.Length != destBytes.Length || subnetBytes.Length != localBytes.Length)
273 return user;
274
275 bool valid = true;
276
277 for (int i = 0; i < subnetBytes.Length; i++)
278 {
279 if ((localBytes[i] & subnetBytes[i]) != (destBytes[i] & subnetBytes[i]))
280 {
281 valid = false;
282 break;
283 }
284 }
285
286 if (subnet.Key.AddressFamily != AddressFamily.InterNetwork)
287 valid = false;
288
289 if (valid)
290 {
291 m_log.Info("[NetworkUtil] Local LAN user detected, sending '" + externalIPAddress + "' instead of '" + user + "'");
292 return externalIPAddress;
293 }
294 }
295
296 // Otherwise, return user address
297 return user;
298 }
299
300 private static IPAddress GetExternalIP()
301 {
302 string whatIsMyIp = "http://www.whatismyip.com/automation/n09230945.asp";
303 WebClient wc = new WebClient();
304 UTF8Encoding utf8 = new UTF8Encoding();
305 string requestHtml = "";
306 try
307 {
308 requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));
309 }
310 catch (WebException we)
311 {
312 // do something with exception
313 m_log.Info("[NetworkUtil]: Exception in GetExternalIP: " + we.ToString());
314 }
315
316 IPAddress externalIp = IPAddress.Parse(requestHtml);
317 return externalIp;
318 }
247 } 319 }
248} 320}
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 091fdeb..f1828da 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -2728,7 +2728,9 @@ namespace OpenSim.Region.Framework.Scenes
2728 IUserAgentVerificationModule userVerification = RequestModuleInterface<IUserAgentVerificationModule>(); 2728 IUserAgentVerificationModule userVerification = RequestModuleInterface<IUserAgentVerificationModule>();
2729 if (userVerification != null && ep != null) 2729 if (userVerification != null && ep != null)
2730 { 2730 {
2731 if (!userVerification.VerifyClient(aCircuit, ep.Address.ToString())) 2731 System.Net.IPAddress addr = NetworkUtil.GetExternalIPOf(ep.Address);
2732
2733 if (!userVerification.VerifyClient(aCircuit, /*ep.Address.ToString() */ addr.ToString()))
2732 { 2734 {
2733 // uh-oh, this is fishy 2735 // uh-oh, this is fishy
2734 m_log.DebugFormat("[Scene]: User Client Verification for {0} {1} in {2} returned false", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName); 2736 m_log.DebugFormat("[Scene]: User Client Verification for {0} {1} in {2} returned false", aCircuit.firstname, aCircuit.lastname, RegionInfo.RegionName);
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs
index 2f1fed4..aec82e8 100644
--- a/OpenSim/Services/HypergridService/UserAgentService.cs
+++ b/OpenSim/Services/HypergridService/UserAgentService.cs
@@ -63,6 +63,8 @@ namespace OpenSim.Services.HypergridService
63 protected static IGridService m_GridService; 63 protected static IGridService m_GridService;
64 protected static GatekeeperServiceConnector m_GatekeeperConnector; 64 protected static GatekeeperServiceConnector m_GatekeeperConnector;
65 65
66 protected static bool m_BypassClientVerification;
67
66 public UserAgentService(IConfigSource config) 68 public UserAgentService(IConfigSource config)
67 { 69 {
68 if (!m_Initialized) 70 if (!m_Initialized)
@@ -76,6 +78,8 @@ namespace OpenSim.Services.HypergridService
76 string gridService = serverConfig.GetString("GridService", String.Empty); 78 string gridService = serverConfig.GetString("GridService", String.Empty);
77 string gridUserService = serverConfig.GetString("GridUserService", String.Empty); 79 string gridUserService = serverConfig.GetString("GridUserService", String.Empty);
78 80
81 m_BypassClientVerification = serverConfig.GetBoolean("BypassClientVerification", false);
82
79 if (gridService == string.Empty || gridUserService == string.Empty) 83 if (gridService == string.Empty || gridUserService == string.Empty)
80 throw new Exception(String.Format("Incomplete specifications, UserAgent Service cannot function.")); 84 throw new Exception(String.Format("Incomplete specifications, UserAgent Service cannot function."));
81 85
@@ -212,11 +216,10 @@ namespace OpenSim.Services.HypergridService
212 216
213 public bool VerifyClient(UUID sessionID, string token) 217 public bool VerifyClient(UUID sessionID, string token)
214 { 218 {
215 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with token {1}", sessionID, token); 219 if (m_BypassClientVerification)
216 //return true; 220 return true;
217 221
218 // Commenting this for now until I understand better what part of a sender's 222 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with token {1}", sessionID, token);
219 // info stays unchanged throughout a session
220 223
221 if (m_TravelingAgents.ContainsKey(sessionID)) 224 if (m_TravelingAgents.ContainsKey(sessionID))
222 return m_TravelingAgents[sessionID].ClientToken == token; 225 return m_TravelingAgents[sessionID].ClientToken == token;
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
index f4e045c..036bec6 100644
--- a/OpenSim/Services/LLLoginService/LLLoginService.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -754,10 +754,8 @@ namespace OpenSim.Services.LLLoginService
754 m_log.Debug("[LLOGIN SERVICE] Launching agent at " + destination.RegionName); 754 m_log.Debug("[LLOGIN SERVICE] Launching agent at " + destination.RegionName);
755 if (m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason)) 755 if (m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason))
756 { 756 {
757 // We may need to do this at some point, 757 IPAddress addr = NetworkUtil.GetExternalIPOf(clientIP.Address);
758 // so leaving it here in comments. 758 m_UserAgentService.SetClientToken(aCircuit.SessionID, addr.ToString() /* clientIP.Address.ToString() */);
759 //IPAddress addr = NetworkUtil.GetIPFor(clientIP.Address, destination.ExternalEndPoint.Address);
760 m_UserAgentService.SetClientToken(aCircuit.SessionID, /*addr.Address.ToString() */ clientIP.Address.ToString());
761 return true; 759 return true;
762 } 760 }
763 return false; 761 return false;