From 59a86568d9539245dee30cf3a33ef6beb31f4bba Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Thu, 21 Jul 2022 22:09:54 +0200 Subject: [PATCH] Cleanup and fixes --- Jellyfin.Networking/Manager/NetworkManager.cs | 12 +++++- .../ApiServiceCollectionExtensions.cs | 8 ++-- MediaBrowser.Common/Net/INetworkManager.cs | 42 +++++++++---------- MediaBrowser.Common/Net/IPData.cs | 8 ++-- MediaBrowser.Model/Net/ISocketFactory.cs | 1 - RSSDP/SsdpCommunicationsServer.cs | 6 +-- 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Jellyfin.Networking/Manager/NetworkManager.cs b/Jellyfin.Networking/Manager/NetworkManager.cs index 12edb0e55c..0f8f1a36a0 100644 --- a/Jellyfin.Networking/Manager/NetworkManager.cs +++ b/Jellyfin.Networking/Manager/NetworkManager.cs @@ -263,7 +263,7 @@ namespace Jellyfin.Networking.Manager if (_interfaces.Count == 0) { - _logger.LogWarning("No interfaces information available. Using loopback."); + _logger.LogWarning("No interface information available. Using loopback interface(s)."); if (IsIpv4Enabled && !IsIpv6Enabled) { @@ -450,6 +450,14 @@ namespace Jellyfin.Networking.Manager _publishedServerUrls[new IPData(IPAddress.Any, new IPNetwork(IPAddress.Any, 0))] = replacement; _publishedServerUrls[new IPData(IPAddress.IPv6Any, new IPNetwork(IPAddress.IPv6Any, 0))] = replacement; } + else if (string.Equals(parts[0], "internal", StringComparison.OrdinalIgnoreCase)) + { + foreach (var lan in _lanSubnets) + { + var lanPrefix = lan.Prefix; + _publishedServerUrls[new IPData(lanPrefix, new IPNetwork(lanPrefix, lan.PrefixLength))] = replacement; + } + } else if (IPAddress.TryParse(ipParts[0], out IPAddress? result)) { var data = new IPData(result, null); @@ -469,7 +477,7 @@ namespace Jellyfin.Networking.Manager } else { - _logger.LogError("Unable to parse bind ip address. {Parts}", parts[1]); + _logger.LogError("Unable to parse bind override: {Entry}", entry); } } } diff --git a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs index a393b80db5..25516271c5 100644 --- a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs +++ b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs @@ -350,14 +350,14 @@ namespace Jellyfin.Server.Extensions } else if (NetworkExtensions.TryParseSubnets(new[] { allowedProxies[i] }, out var subnets)) { - for (var j = 0; j < subnets.Count; j++) + foreach (var subnet in subnets) { - AddIpAddress(config, options, subnets[j].Prefix, subnets[j].PrefixLength); + AddIpAddress(config, options, subnet.Prefix, subnet.PrefixLength); } } - else if (NetworkExtensions.TryParseHost(allowedProxies[i], out var host)) + else if (NetworkExtensions.TryParseHost(allowedProxies[i], out var addresses)) { - foreach (var address in host) + foreach (var address in addresses) { AddIpAddress(config, options, address, address.AddressFamily == AddressFamily.InterNetwork ? 32 : 128); } diff --git a/MediaBrowser.Common/Net/INetworkManager.cs b/MediaBrowser.Common/Net/INetworkManager.cs index 21ff982376..d462e954a8 100644 --- a/MediaBrowser.Common/Net/INetworkManager.cs +++ b/MediaBrowser.Common/Net/INetworkManager.cs @@ -17,14 +17,14 @@ namespace MediaBrowser.Common.Net event EventHandler NetworkChanged; /// - /// Gets a value indicating whether IPv6 is enabled. + /// Gets a value indicating whether IPv4 is enabled. /// - bool IsIpv6Enabled { get; } + bool IsIpv4Enabled { get; } /// - /// Gets a value indicating whether IPv4 is enabled. + /// Gets a value indicating whether IPv6 is enabled. /// - bool IsIpv4Enabled { get; } + bool IsIpv6Enabled { get; } /// /// Calculates the list of interfaces to use for Kestrel. @@ -42,7 +42,7 @@ namespace MediaBrowser.Common.Net IReadOnlyList GetLoopbacks(); /// - /// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo) + /// Retrieves the bind address to use in system URLs. (Server Discovery, PlayTo, LiveTV, SystemInfo) /// If no bind addresses are specified, an internal interface address is selected. /// The priority of selection is as follows:- /// @@ -56,40 +56,40 @@ namespace MediaBrowser.Common.Net /// /// If the source is from a public subnet address range and the user hasn't specified any bind addresses:- /// The first public interface that isn't a loopback and contains the source subnet. - /// The first public interface that isn't a loopback. Priority is given to interfaces with gateways. - /// An internal interface if there are no public ip addresses. + /// The first public interface that isn't a loopback. + /// The first internal interface that isn't a loopback. /// /// If the source is from a private subnet address range and the user hasn't specified any bind addresses:- /// The first private interface that contains the source subnet. - /// The first private interface that isn't a loopback. Priority is given to interfaces with gateways. + /// The first private interface that isn't a loopback. /// /// If no interfaces meet any of these criteria, then a loopback address is returned. /// - /// Interface that have been specifically excluded from binding are not used in any of the calculations. + /// Interfaces that have been specifically excluded from binding are not used in any of the calculations. /// /// Source of the request. /// Optional port returned, if it's part of an override. - /// IP Address to use, or loopback address if all else fails. + /// IP address to use, or loopback address if all else fails. string GetBindInterface(HttpRequest source, out int? port); /// - /// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo) + /// Retrieves the bind address to use in system URLs. (Server Discovery, PlayTo, LiveTV, SystemInfo) /// If no bind addresses are specified, an internal interface address is selected. /// (See . /// /// IP address of the request. /// Optional port returned, if it's part of an override. - /// IP Address to use, or loopback address if all else fails. + /// IP address to use, or loopback address if all else fails. string GetBindInterface(IPAddress source, out int? port); /// - /// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo) + /// Retrieves the bind address to use in system URLs. (Server Discovery, PlayTo, LiveTV, SystemInfo) /// If no bind addresses are specified, an internal interface address is selected. /// (See . /// /// Source of the request. /// Optional port returned, if it's part of an override. - /// IP Address to use, or loopback address if all else fails. + /// IP address to use, or loopback address if all else fails. string GetBindInterface(string source, out int? port); /// @@ -100,7 +100,6 @@ namespace MediaBrowser.Common.Net /// /// Returns true if the address is part of the user defined LAN. - /// The configuration option TrustIP6Interfaces overrides this functions behaviour. /// /// IP to check. /// True if endpoint is within the LAN range. @@ -108,7 +107,6 @@ namespace MediaBrowser.Common.Net /// /// Returns true if the address is part of the user defined LAN. - /// The configuration option TrustIP6Interfaces overrides this functions behaviour. /// /// IP to check. /// True if endpoint is within the LAN range. @@ -119,21 +117,21 @@ namespace MediaBrowser.Common.Net /// eg. "eth1", or "enp3s5". /// /// Interface name. - /// Resultant object's ip addresses, if successful. + /// Resulting object's IP addresses, if successful. /// Success of the operation. bool TryParseInterface(string intf, out List? result); /// - /// Returns all the internal bind interface addresses. + /// Returns all internal (LAN) bind interface addresses. /// - /// An internal list of interfaces addresses. + /// An list of internal (LAN) interfaces addresses. IReadOnlyList GetInternalBindAddresses(); /// - /// Checks to see if has access. + /// Checks if has access to the server. /// - /// IP Address of client. - /// True if has access, otherwise false. + /// IP address of the client. + /// True if it has access, otherwise false. bool HasRemoteAccess(IPAddress remoteIp); } } diff --git a/MediaBrowser.Common/Net/IPData.cs b/MediaBrowser.Common/Net/IPData.cs index 6901d6ad8a..384efe8f68 100644 --- a/MediaBrowser.Common/Net/IPData.cs +++ b/MediaBrowser.Common/Net/IPData.cs @@ -12,9 +12,9 @@ namespace MediaBrowser.Common.Net /// /// Initializes a new instance of the class. /// - /// An . + /// The . /// The . - /// The object's name. + /// The interface name. public IPData(IPAddress address, IPNetwork? subnet, string name) { Address = address; @@ -25,7 +25,7 @@ namespace MediaBrowser.Common.Net /// /// Initializes a new instance of the class. /// - /// An . + /// The . /// The . public IPData(IPAddress address, IPNetwork? subnet) : this(address, subnet, string.Empty) @@ -53,7 +53,7 @@ namespace MediaBrowser.Common.Net public string Name { get; set; } /// - /// Gets the AddressFamily of this object. + /// Gets the AddressFamily of the object. /// public AddressFamily AddressFamily { diff --git a/MediaBrowser.Model/Net/ISocketFactory.cs b/MediaBrowser.Model/Net/ISocketFactory.cs index e5cf7adbc0..f3bc31796d 100644 --- a/MediaBrowser.Model/Net/ISocketFactory.cs +++ b/MediaBrowser.Model/Net/ISocketFactory.cs @@ -1,6 +1,5 @@ #pragma warning disable CS1591 -using System.Collections.Generic; using System.Net; namespace MediaBrowser.Model.Net diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs index e6c0a44039..92c9c83c0f 100644 --- a/RSSDP/SsdpCommunicationsServer.cs +++ b/RSSDP/SsdpCommunicationsServer.cs @@ -142,11 +142,7 @@ namespace Rssdp.Infrastructure if (_BroadcastListenSockets != null) { _logger.LogInformation("{0} disposing _BroadcastListenSocket", GetType().Name); - foreach (var socket in _BroadcastListenSockets) - { - socket.Dispose(); - } - + _BroadcastListenSockets.ForEach(s => s.Dispose()); _BroadcastListenSockets = null; } }