diff -Nur OpenSim-/Framework/NetworkUtil.cs OpenSim/Framework/NetworkUtil.cs --- OpenSim-/Framework/NetworkUtil.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Framework/NetworkUtil.cs 2018-04-22 14:28:02.537820323 +0900 @@ -60,6 +60,9 @@ // IPv4Address, Subnet static readonly Dictionary m_subnets = new Dictionary(); + // IPv4 Private Address // Fumi.Iseki + static readonly Dictionary m_private = new Dictionary(); + public static IPAddress GetIPFor(IPAddress user, IPAddress simulator) { if (m_disabled) @@ -191,9 +194,17 @@ { if (address.Address.AddressFamily == AddressFamily.InterNetwork) { - if (address.IPv4Mask != null) + // Fumi.Iseki for mono + try + { + if (address.IPv4Mask != null) + { + m_subnets.Add(address.Address, address.IPv4Mask); + } + } + catch (NotImplementedException) { - m_subnets.Add(address.Address, address.IPv4Mask); + m_subnets.Add(address.Address, IPAddress.Parse("255.255.255.0")); } } } @@ -203,6 +214,11 @@ { // Mono Sucks. } + + // Fumi.Iseki + m_private.Add(IPAddress.Parse("10.0.0.0"), IPAddress.Parse("255.0.0.0")); + m_private.Add(IPAddress.Parse("172.16.0.0"), IPAddress.Parse("255.240.0.0")); + m_private.Add(IPAddress.Parse("192.168.0.0"), IPAddress.Parse("255.255.0.0")); } public static IPAddress GetIPFor(IPEndPoint user, string defaultHostname) @@ -246,5 +262,122 @@ return defaultHostname; } + + // Fumi.Iseki + public static IPAddress GetIPfromString(string str) + { + IPAddress ip = null; + + if (str=="") + { + ip = IPAddress.Parse("0.0.0.0"); + return ip; + } + + if (IPAddress.TryParse(str, out ip)) + { + return ip; + } + + try + { + foreach (IPAddress host in Dns.GetHostAddresses(str)) + { + if (host.AddressFamily==AddressFamily.InterNetwork) + { + return host; + } + } + } + catch (System.Net.Sockets.SocketException) + { + ip = IPAddress.Parse("0.0.0.0"); + } + + return ip; + } + + + // Fumi.Iseki + public static IPAddress GetEffectiveIP(IPAddress viewer, IPAddress internalIP, IPAddress externalIP, IPAddress myExternalIP) + { + if (internalIP.Equals(externalIP)) return externalIP; // Target is outside of NAPT + + if (viewer.Equals(externalIP)) // Target is local with viewer + { + m_log.Info("[NetworkUtil.GetEffectiveIP] Local LAN[0] user detected, sending them '" + internalIP.ToString() + "'"); + return internalIP; + } + + if (IsInternalSubnet(viewer)) // Viewer is inside + { + if (myExternalIP!=null && !myExternalIP.Equals(externalIP)) // Target is outside + { + m_log.Info("[NetworkUtil.GetEffectiveIP] Remote LAN[0] user detected, sending them '" + externalIP.ToString() + "'"); + return externalIP; + } + m_log.Info("[NetworkUtil.GetEffectiveIP] Local LAN[1] user detected, sending them '" + internalIP.ToString() + "'"); + return internalIP; + } + + m_log.Info("[NetworkUtil.GetEffectiveIP] Remote LAN[1] user detected, sending them '" + externalIP.ToString() + "'"); + return externalIP; + } + + + // Fumi.Iseki + public static bool IsInternalSubnet(IPAddress address) + { + // Same as own IP + foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName())) + { + if (host.Equals(address) && host.AddressFamily==AddressFamily.InterNetwork) return true; + } + + if (IsSameNetwork(address, m_subnets)) return true; + if (IsSameNetwork(address, m_private)) return true; + + return false; + } + + + // Fumi.Iseki + public static bool IsPrivateSubnet(IPAddress address) + { + if (IsSameNetwork(address, m_private)) return true; + + return false; + } + + + // Fumi.Iseki + public static bool IsSameNetwork(IPAddress address, Dictionary subnets) + { + // Check for same LAN segment + byte[] destBytes = address.GetAddressBytes(); + + foreach (KeyValuePair subnet in subnets) + { + if (subnet.Key.AddressFamily != AddressFamily.InterNetwork) continue; + + byte[] subnetBytes = subnet.Value.GetAddressBytes(); + byte[] localBytes = subnet.Key.GetAddressBytes(); + + if (subnetBytes.Length!=destBytes.Length || subnetBytes.Length!=localBytes.Length) continue; + + bool samenet = true; + for (int i=0; i /// The x co-ordinate of this region in map tiles (e.g. 1000). /// Coordinate is scaled as world coordinates divided by the legacy region size @@ -621,6 +632,7 @@ address = IPAddress.Parse(MainConsole.Instance.CmdPrompt("Internal IP address", "0.0.0.0")); config.Set("InternalAddress", address.ToString()); } + m_internalIPAddress = address; // Fumi.Iseki for NAPT // InternalPort // @@ -685,6 +697,9 @@ m_externalHostName = addrs[0].ToString(); } + // Fumi.Iseki for NAPT + if (m_internalIPAddress.ToString()=="0.0.0.0") m_internalIPAddress = NetworkUtil.GetIPfromString(m_externalHostName); + // RegionType m_regionType = config.GetString("RegionType", String.Empty); allKeys.Remove("RegionType"); @@ -1168,6 +1183,7 @@ if ((RegionName != null) && !RegionName.Equals("")) args["region_name"] = OSD.FromString(RegionName); args["external_host_name"] = OSD.FromString(ExternalHostName); + args["internal_ip_address"] = OSD.FromString(InternalIPAddress.ToString()); // Fumi.Iseki for NAPT args["http_port"] = OSD.FromString(HttpPort.ToString()); args["server_uri"] = OSD.FromString(ServerURI); @@ -1198,6 +1214,8 @@ RegionName = args["region_name"].AsString(); if (args["external_host_name"] != null) ExternalHostName = args["external_host_name"].AsString(); + if (args["internal_ip_address"] != null) + InternalIPAddress = IPAddress.Parse(args["internal_ip_address"].AsString()); // Fumi.Iseki for NAPT if (args["http_port"] != null) UInt32.TryParse(args["http_port"].AsString(), out m_httpPort); if (args["server_uri"] != null) @@ -1242,11 +1260,14 @@ m_regionType = args["region_type"].AsString(); } - public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI) + // Fumi.Iseki for NAPT + //public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI) + public static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, IPAddress internalIP, uint httpPort, uint simPort, uint remotingPort, string serverURI) { RegionInfo regionInfo; IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(externalHostName), (int)simPort); - regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName); + //regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName); + regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, externalHostName, internalIP); regionInfo.RemotingPort = remotingPort; regionInfo.RemotingAddress = externalHostName; regionInfo.HttpPort = httpPort; diff -Nur OpenSim-/Region/CoreModules/Avatar/Lure/HGLureModule.cs OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs --- OpenSim-/Region/CoreModules/Avatar/Lure/HGLureModule.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Region/CoreModules/Avatar/Lure/HGLureModule.cs 2018-04-22 14:28:02.538820325 +0900 @@ -253,9 +253,11 @@ if (message != null) sp.ControllingClient.SendAgentAlertMessage(message, true); + // Fumi.Iseki for NAPT transferMod.DoTeleport( sp, gatekeeper, finalDestination, im.Position + new Vector3(0.5f, 0.5f, 0f), - Vector3.UnitX, teleportflags); + Vector3.UnitX, teleportflags, client); + //Vector3.UnitX, teleportflags); } } else @@ -268,4 +270,4 @@ } } } -} \ ファイル末尾に改行がありません +} diff -Nur OpenSim-/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs --- OpenSim-/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs 2018-04-22 14:28:02.540820329 +0900 @@ -363,7 +363,9 @@ } // Attempt to teleport the ScenePresence to the specified position in the specified region (spec'ed by its handle). - public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags) + // Fumi.Iseki for NAPT + //public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags) + public void Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags, IClientAPI client) { if (sp.Scene.Permissions.IsGridGod(sp.UUID)) { @@ -405,8 +407,10 @@ GridRegion finalDestination = null; try { + // Fumi.Iseki for NAP TeleportAgentToDifferentRegion( - sp, regionHandle, position, lookAt, teleportFlags, out finalDestination); + sp, regionHandle, position, lookAt, teleportFlags, out finalDestination, client); + //sp, regionHandle, position, lookAt, teleportFlags, out finalDestination); } finally { @@ -516,9 +520,11 @@ /// /// /// + // Fumi.Iseki for NAPT private void TeleportAgentToDifferentRegion( ScenePresence sp, ulong regionHandle, Vector3 position, - Vector3 lookAt, uint teleportFlags, out GridRegion finalDestination) + Vector3 lookAt, uint teleportFlags, out GridRegion finalDestination, IClientAPI client) + //Vector3 lookAt, uint teleportFlags, out GridRegion finalDestination) { // Get destination region taking into account that the address could be an offset // region inside a varregion. @@ -558,7 +564,9 @@ // // This is it // - DoTeleportInternal(sp, reg, finalDestination, position, lookAt, teleportFlags); + // Fumi.Iseki for NAPT + //DoTeleportInternal(sp, reg, finalDestination, position, lookAt, teleportFlags); + DoTeleportInternal(sp, reg, finalDestination, position, lookAt, teleportFlags, client); // // // @@ -654,9 +662,11 @@ /// /// Wraps DoTeleportInternal() and manages the transfer state. /// + // Fumi.Iseki for NAPT public void DoTeleport( ScenePresence sp, GridRegion reg, GridRegion finalDestination, - Vector3 position, Vector3 lookAt, uint teleportFlags) + Vector3 position, Vector3 lookAt, uint teleportFlags, IClientAPI client) + //Vector3 position, Vector3 lookAt, uint teleportFlags) { // Record that this agent is in transit so that we can prevent simultaneous requests and do later detection // of whether the destination region completes the teleport. @@ -671,7 +681,9 @@ try { - DoTeleportInternal(sp, reg, finalDestination, position, lookAt, teleportFlags); + // Fumi.Iseki for NAPT + //DoTeleportInternal(sp, reg, finalDestination, position, lookAt, teleportFlags); + DoTeleportInternal(sp, reg, finalDestination, position, lookAt, teleportFlags, client); } catch (Exception e) { @@ -692,9 +704,11 @@ /// Teleports the agent to another region. /// This method doesn't manage the transfer state; the caller must do that. /// + // Fumi.Iseki for NAPT private void DoTeleportInternal( ScenePresence sp, GridRegion reg, GridRegion finalDestination, - Vector3 position, Vector3 lookAt, uint teleportFlags) + Vector3 position, Vector3 lookAt, uint teleportFlags, IClientAPI client) + //Vector3 position, Vector3 lookAt, uint teleportFlags) { if (reg == null || finalDestination == null) { @@ -729,6 +743,26 @@ // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field, // it's actually doing a lot of work. IPEndPoint endPoint = finalDestination.ExternalEndPoint; + + // Fumi.Iseki for NAPT + IPAddress clientAddress = null; + if (client!=null) { + IPEndPoint cpoint = client.RemoteEndPoint; + if (cpoint!=null) clientAddress = cpoint.Address; + } + if (clientAddress==null) { + uint circuitCode = sp.ControllingClient.CircuitCode; + clientAddress = NetworkUtil.GetIPfromString(sp.Scene.AuthenticateHandler.GetAgentCircuitData(circuitCode).IPAddress); + } + if (clientAddress!=null) + { + IPAddress intrnlAddress = finalDestination.InternalIPAddress; + IPAddress extrnlAddress = finalDestination.ExternalEndPoint.Address; + IPAddress regionAddress = sourceRegion.ExternalEndPoint.Address; + IPAddress effectAddress = NetworkUtil.GetEffectiveIP(clientAddress, intrnlAddress, extrnlAddress, regionAddress); + endPoint = new IPEndPoint(effectAddress, finalDestination.ExternalEndPoint.Port); + } + if (endPoint == null || endPoint.Address == null) { sp.ControllingClient.SendTeleportFailed("Could not resolve destination Address"); @@ -1838,24 +1872,49 @@ string capsPath = neighbourRegion.ServerURI + CapsUtil.GetCapsSeedPath(agentcaps); + // Fumi.Iseki + IPAddress effectAddress = null; + string serverURI = neighbourRegion.ServerURI; + uint circuitCode = agent.ControllingClient.CircuitCode; + IPAddress clientAddress = NetworkUtil.GetIPfromString(agent.Scene.AuthenticateHandler.GetAgentCircuitData(circuitCode).IPAddress); + if (clientAddress!=null) + { + IPAddress intrnlAddress = neighbourRegion.InternalIPAddress; + IPAddress extrnlAddress = neighbourRegion.ExternalEndPoint.Address; + if (!extrnlAddress.Equals(intrnlAddress)) + { + IPAddress regionAddress = agent.Scene.RegionInfo.ExternalEndPoint.Address; + effectAddress = NetworkUtil.GetEffectiveIP(clientAddress, intrnlAddress, extrnlAddress, regionAddress); + } + } + m_log.DebugFormat("[ENTITY TRANSFER MODULE]: Sending new CAPS seed url {0} to client {1}", capsPath, agent.UUID); Vector3 vel2 = Vector3.Zero; if((agent.crossingFlags & 2) != 0) vel2 = new Vector3(agent.Velocity.X, agent.Velocity.Y, 0); + // Fumi.Iseki for NAPT + IPEndPoint endPoint = endpoint; //neighbourRegion.ExternalEndPoint; + if (effectAddress!=null) + { + endPoint = new IPEndPoint(effectAddress, endpoint.Port); + } + if (m_eqModule != null) { m_eqModule.CrossRegion( neighbourRegion.RegionHandle, pos, vel2 /* agent.Velocity */, - endpoint, capsPath, agent.UUID, agent.ControllingClient.SessionId, + //endpoint, capsPath, agent.UUID, agent.ControllingClient.SessionId, + endPoint, capsPath, agent.UUID, agent.ControllingClient.SessionId, neighbourRegion.RegionSizeX, neighbourRegion.RegionSizeY); } else { m_log.ErrorFormat("{0} Using old CrossRegion packet. Varregion will not work!!", LogHeader); agent.ControllingClient.CrossRegion(neighbourRegion.RegionHandle, pos, agent.Velocity, - endpoint,capsPath); + //endpoint,capsPath); + endPoint,capsPath); } // SUCCESS! @@ -1979,6 +2038,19 @@ } */ IPEndPoint external = region.ExternalEndPoint; + + // Fumi.Iseki for NAPT + uint circuitCode = sp.ControllingClient.CircuitCode; + IPAddress clientAddress = NetworkUtil.GetIPfromString(sp.Scene.AuthenticateHandler.GetAgentCircuitData(circuitCode).IPAddress); + if (clientAddress!=null) + { + IPAddress intrnlAddress = region.InternalIPAddress; + IPAddress extrnlAddress = region.ExternalEndPoint.Address; + IPAddress regionAddress = sp.Scene.RegionInfo.ExternalEndPoint.Address; + IPAddress effectAddress = NetworkUtil.GetEffectiveIP(clientAddress, intrnlAddress, extrnlAddress, regionAddress); + external = new IPEndPoint(effectAddress, region.ExternalEndPoint.Port); + } + if (external != null) { InformClientOfNeighbourDelegate d = InformClientOfNeighbourAsync; @@ -2143,6 +2215,11 @@ Util.FireAndForget(delegate { + // Fumi.Iseki for NAPT + uint circuitCode = sp.ControllingClient.CircuitCode; + IPAddress clientAddress = NetworkUtil.GetIPfromString(sp.Scene.AuthenticateHandler.GetAgentCircuitData(circuitCode).IPAddress); + IPAddress regionAddress = sp.Scene.RegionInfo.ExternalEndPoint.Address; + Thread.Sleep(200); // the original delay that was at InformClientOfNeighbourAsync start int count = 0; IPEndPoint ipe; @@ -2156,7 +2233,17 @@ { ipe = neighbour.ExternalEndPoint; if (ipe != null) + { + // Fumi.Iseki + if (clientAddress!=null) + { + IPAddress intrnlAddress = neighbour.InternalIPAddress; + IPAddress extrnlAddress = neighbour.ExternalEndPoint.Address; + IPAddress effectAddress = NetworkUtil.GetEffectiveIP(clientAddress, intrnlAddress, extrnlAddress, regionAddress); + ipe = new IPEndPoint(effectAddress, neighbour.ExternalEndPoint.Port); + } InformClientOfNeighbourAsync(sp, cagents[count], neighbour, ipe, true); + } else { m_log.DebugFormat("[ENTITY TRANSFER MODULE]: lost DNS resolution for neighbour {0}", neighbour.ExternalHostName); diff -Nur OpenSim-/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs --- OpenSim-/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs 2018-04-22 14:28:02.540820329 +0900 @@ -491,7 +491,10 @@ m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}", aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ServerURI, homeGatekeeper.RegionName); - DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome)); + // Fumi.Iseki for NAPT + //DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome)); + DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome), client); + return true; } @@ -549,9 +552,11 @@ return; } + // Fumi.Iseki for NAPT DoTeleport( sp, gatekeeper, finalDestination, lm.Position, Vector3.UnitX, - (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark)); + (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark), remoteClient); + //(uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark)); } } else diff -Nur OpenSim-/Region/Framework/Interfaces/IEntityTransferModule.cs OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs --- OpenSim-/Region/Framework/Interfaces/IEntityTransferModule.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs 2018-04-22 14:28:02.540820329 +0900 @@ -53,7 +53,9 @@ /// /// /// - void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags); + // Fumi.Iseki for NAPT + //void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags); + void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags, IClientAPI client); /// /// Teleports the agent for the given client to their home destination. @@ -75,8 +77,10 @@ /// /// /// + // Fumi.Iseki for NAPT void DoTeleport(ScenePresence sp, GridRegion reg, GridRegion finalDestination, - Vector3 position, Vector3 lookAt, uint teleportFlags); + Vector3 position, Vector3 lookAt, uint teleportFlags, IClientAPI client); + //Vector3 position, Vector3 lookAt, uint teleportFlags); /// /// Show whether the given agent is being teleported. diff -Nur OpenSim-/Region/Framework/Scenes/Scene.cs OpenSim/Region/Framework/Scenes/Scene.cs --- OpenSim-/Region/Framework/Scenes/Scene.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Region/Framework/Scenes/Scene.cs 2018-04-22 14:28:02.542820333 +0900 @@ -4852,7 +4852,9 @@ return; } - EntityTransferModule.Teleport(sp, regionHandle, position, lookat, teleportFlags); + // Fumi.Iseki for NAPT + //EntityTransferModule.Teleport(sp, regionHandle, position, lookat, teleportFlags); + EntityTransferModule.Teleport(sp, regionHandle, position, lookat, teleportFlags, remoteClient); } /// @@ -4876,7 +4878,9 @@ if (sp == null || sp.IsDeleted || sp.IsInTransit) return; - EntityTransferModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags); + // Fumi.Iseki for NAPT + //EntityTransferModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags); + EntityTransferModule.Teleport(sp, regionHandle, position, lookAt, teleportFlags, remoteClient); } public bool CrossAgentToNewRegion(ScenePresence agent, bool isFlying) diff -Nur OpenSim-/Server/Handlers/Hypergrid/HypergridHandlers.cs OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs --- OpenSim-/Server/Handlers/Hypergrid/HypergridHandlers.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Server/Handlers/Hypergrid/HypergridHandlers.cs 2018-04-22 14:28:02.543820335 +0900 @@ -125,6 +125,7 @@ hash["hostname"] = regInfo.ExternalHostName; hash["http_port"] = regInfo.HttpPort.ToString(); hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); + hash["internal_ip_address"] = regInfo.InternalIPAddress.ToString(); // Fumi.Iseki for NAPT hash["server_uri"] = regInfo.ServerURI; } diff -Nur OpenSim-/Server/Handlers/Hypergrid/UserAgentServerConnector.cs OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs --- OpenSim-/Server/Handlers/Hypergrid/UserAgentServerConnector.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs 2018-04-22 14:28:02.543820335 +0900 @@ -143,6 +143,7 @@ hash["internal_port"] = regInfo.InternalEndPoint.Port.ToString(); hash["position"] = position.ToString(); hash["lookAt"] = lookAt.ToString(); + hash["internal_ip_address"] = regInfo.InternalIPAddress.ToString(); // Fumi.Iseki for NAPT } XmlRpcResponse response = new XmlRpcResponse(); response.Value = hash; @@ -486,4 +487,4 @@ return response; } } -} \ ファイル末尾に改行がありません +} diff -Nur OpenSim-/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs --- OpenSim-/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs 2018-04-22 14:28:02.543820335 +0900 @@ -323,6 +323,12 @@ //m_log.Debug(">> HERE, server_uri: " + region.ServerURI); } + // Fumi.Iseki for NAPT + if (hash["internal_ip_address"] != null) + { + region.InternalIPAddress = NetworkUtil.GetIPfromString((string)hash["internal_ip_address"]); + } + // Successful return return region; } diff -Nur OpenSim-/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs --- OpenSim-/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs 2018-04-22 14:28:02.543820335 +0900 @@ -54,7 +54,9 @@ private string m_ServerURL; private GridRegion m_Gatekeeper; - public UserAgentServiceConnector(string url) : this(url, true) + // Fumi.Iseki for NAPT + //public UserAgentServiceConnector(string url) : this(url, true) + public UserAgentServiceConnector(string url) : this(url, false) { } @@ -271,6 +273,12 @@ if (hash["lookAt"] != null) Vector3.TryParse((string)hash["lookAt"], out lookAt); + // Fumi.Iseki for NAPT + if (hash["internal_ip_address"] != null) + { + region.InternalIPAddress = NetworkUtil.GetIPfromString((string)hash["internal_ip_address"]); + } + // Successful return return region; } diff -Nur OpenSim-/Services/Interfaces/IGridService.cs OpenSim/Services/Interfaces/IGridService.cs --- OpenSim-/Services/Interfaces/IGridService.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Services/Interfaces/IGridService.cs 2018-04-22 14:28:02.544820338 +0900 @@ -211,6 +211,8 @@ protected IPEndPoint m_internalEndPoint; + protected IPAddress m_internalIPAddress = null; // Fumi.Iseki for NAPT + /// /// The co-ordinate of this region in region units. /// @@ -264,6 +266,9 @@ public string RegionSecret = string.Empty; public string Token = string.Empty; + // Fumi.Iseki for NAPT + private string m_dbipcolumn = "Token"; + public GridRegion() { RegionSizeX = (int)Constants.RegionSize; @@ -288,6 +293,7 @@ RegionSizeY = (int)ConvertFrom.RegionSizeY; m_internalEndPoint = ConvertFrom.InternalEndPoint; m_externalHostName = ConvertFrom.ExternalHostName; + m_internalIPAddress = ConvertFrom.InternalIPAddress; // Fumi.Iseki for NAPT HttpPort = ConvertFrom.HttpPort; RegionID = ConvertFrom.RegionID; ServerURI = ConvertFrom.ServerURI; @@ -309,6 +315,7 @@ RegionSizeY = ConvertFrom.RegionSizeY; m_internalEndPoint = ConvertFrom.InternalEndPoint; m_externalHostName = ConvertFrom.ExternalHostName; + m_internalIPAddress = ConvertFrom.InternalIPAddress; // Fumi.Iseki for NAPT HttpPort = ConvertFrom.HttpPort; RegionID = ConvertFrom.RegionID; ServerURI = ConvertFrom.ServerURI; @@ -396,6 +403,13 @@ if (kvp.ContainsKey("Token")) Token = kvp["Token"].ToString(); + // Fumi.Iseki for NAPT + if (kvp.ContainsKey(m_dbipcolumn)) + { + InternalIPAddress = NetworkUtil.GetIPfromString(kvp[m_dbipcolumn].ToString()); + if (InternalIPAddress.ToString()=="0.0.0.0") InternalIPAddress = ExternalEndPoint.Address; + } + // m_log.DebugFormat("{0} New GridRegion. id={1}, loc=<{2},{3}>, size=<{4},{5}>", // LogHeader, RegionID, RegionLocX, RegionLocY, RegionSizeX, RegionSizeY); } @@ -425,6 +439,9 @@ kvp["Token"] = Token.ToString(); // Maturity doesn't seem to exist in the DB + // Fumi.Iseki for NAPT [if Robust server, comment out this] + if (NetworkUtil.IsPrivateSubnet(InternalIPAddress)) kvp[m_dbipcolumn] = InternalIPAddress.ToString(); + return kvp; } @@ -481,5 +498,19 @@ { get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); } } + + + // Fumi.Iseki for NAPT + public IPAddress InternalIPAddress + { + get { + if (m_internalIPAddress==null) { + m_internalIPAddress = m_internalEndPoint.Address; + if (m_internalIPAddress.ToString()=="0.0.0.0") m_internalIPAddress = ExternalEndPoint.Address; + } + return m_internalIPAddress; + } + set { m_internalIPAddress = value; } + } } } diff -Nur OpenSim-/Services/LLLoginService/LLLoginResponse.cs OpenSim/Services/LLLoginService/LLLoginResponse.cs --- OpenSim-/Services/LLLoginService/LLLoginResponse.cs 2017-08-16 02:31:06.000000000 +0900 +++ OpenSim/Services/LLLoginService/LLLoginResponse.cs 2018-04-22 14:28:02.544820338 +0900 @@ -266,7 +266,8 @@ FillOutHomeData(pinfo, home); LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z); - FillOutRegionData(destination); + //FillOutRegionData(destination); + FillOutRegionData(destination, clientIP); // Fumi.Iseki for NAPT m_log.DebugFormat("[LOGIN RESPONSE] LLLoginResponse create. sizeX={0}, sizeY={1}", RegionSizeX, RegionSizeY); FillOutSeedCap(aCircuit, destination, clientIP); @@ -387,11 +388,17 @@ } - private void FillOutRegionData(GridRegion destination) + // Fumi.Iseki for NAPT + //private void FillOutRegionData(GridRegion destination) + private void FillOutRegionData(GridRegion destination, IPEndPoint clientIP) { IPEndPoint endPoint = destination.ExternalEndPoint; if (endPoint == null) return; - SimAddress = endPoint.Address.ToString(); + //SimAddress = endPoint.Address.ToString(); + IPAddress extAddress = NetworkUtil.GetIPfromString(destination.ExternalHostName); + IPAddress simAddress = NetworkUtil.GetEffectiveIP(clientIP.Address, destination.InternalIPAddress, extAddress, null); + SimAddress = simAddress.ToString(); + // SimPort = (uint)endPoint.Port; RegionX = (uint)destination.RegionLocX; RegionY = (uint)destination.RegionLocY;