From 9707712d393710537e68e24fb362cdb5c4f8bf41 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 5 Oct 2017 14:10:46 -0400 Subject: update logging --- Emby.Server.Implementations/Networking/NetworkManager.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'Emby.Server.Implementations/Networking/NetworkManager.cs') diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs index b47c058df..5fb8f7fc9 100644 --- a/Emby.Server.Implementations/Networking/NetworkManager.cs +++ b/Emby.Server.Implementations/Networking/NetworkManager.cs @@ -29,7 +29,7 @@ namespace Emby.Server.Implementations.Networking public List GetLocalIpAddresses() { - const int cacheMinutes = 5; + const int cacheMinutes = 10; lock (_localIpAddressSyncLock) { @@ -198,12 +198,6 @@ namespace Emby.Server.Implementations.Networking return Dns.GetHostAddressesAsync(hostName); } - private readonly List _validNetworkInterfaceTypes = new List - { - NetworkInterfaceType.Ethernet, - NetworkInterfaceType.Wireless80211 - }; - private List GetIPsDefault() { NetworkInterface[] interfaces; @@ -227,7 +221,8 @@ namespace Emby.Server.Implementations.Networking try { - Logger.Debug("Querying interface: {0}. Type: {1}. Status: {2}", network.Name, network.NetworkInterfaceType, network.OperationalStatus); + // suppress logging because it might be causing nas device wake up + //Logger.Debug("Querying interface: {0}. Type: {1}. Status: {2}", network.Name, network.NetworkInterfaceType, network.OperationalStatus); var ipProperties = network.GetIPProperties(); -- cgit v1.2.3 From 329305230eb0b0f12e5de4cdb04188dcb89e4a0c Mon Sep 17 00:00:00 2001 From: randomevents Date: Tue, 10 Oct 2017 23:35:30 -0400 Subject: Test for matching subnet of IP's (VPN request) test available ip4 host address against the endpoint (only local addresses, 10 127 192.68 169), if there's a preliminary match, it finds the subnet of the host ip (255.255.255.0) and makes sure's there's a match between host (255.255.255) and endpoint --- .../Networking/NetworkManager.cs | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'Emby.Server.Implementations/Networking/NetworkManager.cs') diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs index 5fb8f7fc9..7f0eef0b9 100644 --- a/Emby.Server.Implementations/Networking/NetworkManager.cs +++ b/Emby.Server.Implementations/Networking/NetworkManager.cs @@ -93,12 +93,36 @@ namespace Emby.Server.Implementations.Networking } return - endpoint.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) || + IsInPrivateAddressSpaceAndLocalSubnet(endpoint); + } + + public bool IsInPrivateAddressSpaceAndLocalSubnet(string endpoint) + { + string subnet_Match = ""; + if ( endpoint.StartsWith("127.", StringComparison.OrdinalIgnoreCase) || endpoint.StartsWith("10.", StringComparison.OrdinalIgnoreCase) || endpoint.StartsWith("192.168", StringComparison.OrdinalIgnoreCase) || - endpoint.StartsWith("169.", StringComparison.OrdinalIgnoreCase); + endpoint.StartsWith("169.", StringComparison.OrdinalIgnoreCase) + ) + { + foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) + foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses) + if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpoint.Split('.')[0] == unicastIPAddressInformation.Address.ToString().Split('.')[0]) + { + int subnet_Test = 0; + foreach (string part in unicastIPAddressInformation.IPv4Mask.ToString().Split('.')) + { + if (part.Equals("0")) break; + subnet_Test++; + } + + subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); + } + } + + return endpoint.StartsWith(subnet_Match + ".", StringComparison.OrdinalIgnoreCase); } private bool Is172AddressPrivate(string endpoint) -- cgit v1.2.3 From 3e0cfd3af36f024b685ed512d4fa5f8c9b3fbe59 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 11 Oct 2017 00:45:21 -0400 Subject: fixes #1769 - IsInLocalNetwork returns wrong value --- .../Networking/NetworkManager.cs | 57 ++++++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'Emby.Server.Implementations/Networking/NetworkManager.cs') diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs index 7f0eef0b9..66b2cba39 100644 --- a/Emby.Server.Implementations/Networking/NetworkManager.cs +++ b/Emby.Server.Implementations/Networking/NetworkManager.cs @@ -81,8 +81,18 @@ namespace Emby.Server.Implementations.Networking return true; } - // Handle ipv4 mapped to ipv6 - endpoint = endpoint.Replace("::ffff:", string.Empty); + // ipv6 + if (endpoint.Split('.').Length > 4) + { + // Handle ipv4 mapped to ipv6 + var originalEndpoint = endpoint; + endpoint = endpoint.Replace("::ffff:", string.Empty); + + if (string.Equals(endpoint, originalEndpoint, StringComparison.OrdinalIgnoreCase)) + { + return false; + } + } // Private address space: // http://en.wikipedia.org/wiki/Private_network @@ -92,13 +102,15 @@ namespace Emby.Server.Implementations.Networking return Is172AddressPrivate(endpoint); } - return - endpoint.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) || + return endpoint.StartsWith("localhost", StringComparison.OrdinalIgnoreCase) || + endpoint.StartsWith("127.0.0.1", StringComparison.OrdinalIgnoreCase) || IsInPrivateAddressSpaceAndLocalSubnet(endpoint); } public bool IsInPrivateAddressSpaceAndLocalSubnet(string endpoint) { + var endpointFirstPart = endpoint.Split('.')[0]; + string subnet_Match = ""; if ( endpoint.StartsWith("127.", StringComparison.OrdinalIgnoreCase) || @@ -109,7 +121,7 @@ namespace Emby.Server.Implementations.Networking { foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses) - if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpoint.Split('.')[0] == unicastIPAddressInformation.Address.ToString().Split('.')[0]) + if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpointFirstPart == unicastIPAddressInformation.Address.ToString().Split('.')[0]) { int subnet_Test = 0; foreach (string part in unicastIPAddressInformation.IPv4Mask.ToString().Split('.')) @@ -125,6 +137,41 @@ namespace Emby.Server.Implementations.Networking return endpoint.StartsWith(subnet_Match + ".", StringComparison.OrdinalIgnoreCase); } + private Dictionary _subnetLookup = new Dictionary(StringComparer.Ordinal); + private string GetSubnet(string endpointFirstPart) + { + string subnet_Match = ""; + + lock (_subnetLookup) + { + if (_subnetLookup.TryGetValue(endpointFirstPart, out subnet_Match)) + { + return subnet_Match; + } + + foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) + foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses) + if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpointFirstPart == unicastIPAddressInformation.Address.ToString().Split('.')[0]) + { + int subnet_Test = 0; + foreach (string part in unicastIPAddressInformation.IPv4Mask.ToString().Split('.')) + { + if (part.Equals("0")) break; + subnet_Test++; + } + + subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); + } + + if (!string.IsNullOrWhiteSpace(subnet_Match)) + { + _subnetLookup[endpointFirstPart] = subnet_Match; + } + } + + return subnet_Match; + } + private bool Is172AddressPrivate(string endpoint) { for (var i = 16; i <= 31; i++) -- cgit v1.2.3