Cleanup and fixes

This commit is contained in:
Shadowghost 2022-07-21 22:09:54 +02:00
parent ff22f597d2
commit 59a86568d9
6 changed files with 40 additions and 39 deletions

View File

@ -263,7 +263,7 @@ namespace Jellyfin.Networking.Manager
if (_interfaces.Count == 0) 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) 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.Any, new IPNetwork(IPAddress.Any, 0))] = replacement;
_publishedServerUrls[new IPData(IPAddress.IPv6Any, new IPNetwork(IPAddress.IPv6Any, 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)) else if (IPAddress.TryParse(ipParts[0], out IPAddress? result))
{ {
var data = new IPData(result, null); var data = new IPData(result, null);
@ -469,7 +477,7 @@ namespace Jellyfin.Networking.Manager
} }
else else
{ {
_logger.LogError("Unable to parse bind ip address. {Parts}", parts[1]); _logger.LogError("Unable to parse bind override: {Entry}", entry);
} }
} }
} }

View File

@ -350,14 +350,14 @@ namespace Jellyfin.Server.Extensions
} }
else if (NetworkExtensions.TryParseSubnets(new[] { allowedProxies[i] }, out var subnets)) 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); AddIpAddress(config, options, address, address.AddressFamily == AddressFamily.InterNetwork ? 32 : 128);
} }

View File

@ -16,16 +16,16 @@ namespace MediaBrowser.Common.Net
/// </summary> /// </summary>
event EventHandler NetworkChanged; event EventHandler NetworkChanged;
/// <summary>
/// Gets a value indicating whether IPv6 is enabled.
/// </summary>
bool IsIpv6Enabled { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether IPv4 is enabled. /// Gets a value indicating whether IPv4 is enabled.
/// </summary> /// </summary>
bool IsIpv4Enabled { get; } bool IsIpv4Enabled { get; }
/// <summary>
/// Gets a value indicating whether IPv6 is enabled.
/// </summary>
bool IsIpv6Enabled { get; }
/// <summary> /// <summary>
/// Calculates the list of interfaces to use for Kestrel. /// Calculates the list of interfaces to use for Kestrel.
/// </summary> /// </summary>
@ -42,7 +42,7 @@ namespace MediaBrowser.Common.Net
IReadOnlyList<IPData> GetLoopbacks(); IReadOnlyList<IPData> GetLoopbacks();
/// <summary> /// <summary>
/// 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. /// If no bind addresses are specified, an internal interface address is selected.
/// The priority of selection is as follows:- /// 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:- /// 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 and contains the source subnet.
/// The first public interface that isn't a loopback. Priority is given to interfaces with gateways. /// The first public interface that isn't a loopback.
/// An internal interface if there are no public ip addresses. /// 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:- /// 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 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. /// 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.
/// </summary> /// </summary>
/// <param name="source">Source of the request.</param> /// <param name="source">Source of the request.</param>
/// <param name="port">Optional port returned, if it's part of an override.</param> /// <param name="port">Optional port returned, if it's part of an override.</param>
/// <returns>IP Address to use, or loopback address if all else fails.</returns> /// <returns>IP address to use, or loopback address if all else fails.</returns>
string GetBindInterface(HttpRequest source, out int? port); string GetBindInterface(HttpRequest source, out int? port);
/// <summary> /// <summary>
/// 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. /// If no bind addresses are specified, an internal interface address is selected.
/// (See <see cref="GetBindInterface(IPAddress, out int?)"/>. /// (See <see cref="GetBindInterface(IPAddress, out int?)"/>.
/// </summary> /// </summary>
/// <param name="source">IP address of the request.</param> /// <param name="source">IP address of the request.</param>
/// <param name="port">Optional port returned, if it's part of an override.</param> /// <param name="port">Optional port returned, if it's part of an override.</param>
/// <returns>IP Address to use, or loopback address if all else fails.</returns> /// <returns>IP address to use, or loopback address if all else fails.</returns>
string GetBindInterface(IPAddress source, out int? port); string GetBindInterface(IPAddress source, out int? port);
/// <summary> /// <summary>
/// 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. /// If no bind addresses are specified, an internal interface address is selected.
/// (See <see cref="GetBindInterface(IPAddress, out int?)"/>. /// (See <see cref="GetBindInterface(IPAddress, out int?)"/>.
/// </summary> /// </summary>
/// <param name="source">Source of the request.</param> /// <param name="source">Source of the request.</param>
/// <param name="port">Optional port returned, if it's part of an override.</param> /// <param name="port">Optional port returned, if it's part of an override.</param>
/// <returns>IP Address to use, or loopback address if all else fails.</returns> /// <returns>IP address to use, or loopback address if all else fails.</returns>
string GetBindInterface(string source, out int? port); string GetBindInterface(string source, out int? port);
/// <summary> /// <summary>
@ -100,7 +100,6 @@ namespace MediaBrowser.Common.Net
/// <summary> /// <summary>
/// Returns true if the address is part of the user defined LAN. /// Returns true if the address is part of the user defined LAN.
/// The configuration option TrustIP6Interfaces overrides this functions behaviour.
/// </summary> /// </summary>
/// <param name="address">IP to check.</param> /// <param name="address">IP to check.</param>
/// <returns>True if endpoint is within the LAN range.</returns> /// <returns>True if endpoint is within the LAN range.</returns>
@ -108,7 +107,6 @@ namespace MediaBrowser.Common.Net
/// <summary> /// <summary>
/// Returns true if the address is part of the user defined LAN. /// Returns true if the address is part of the user defined LAN.
/// The configuration option TrustIP6Interfaces overrides this functions behaviour.
/// </summary> /// </summary>
/// <param name="address">IP to check.</param> /// <param name="address">IP to check.</param>
/// <returns>True if endpoint is within the LAN range.</returns> /// <returns>True if endpoint is within the LAN range.</returns>
@ -119,21 +117,21 @@ namespace MediaBrowser.Common.Net
/// eg. "eth1", or "enp3s5". /// eg. "eth1", or "enp3s5".
/// </summary> /// </summary>
/// <param name="intf">Interface name.</param> /// <param name="intf">Interface name.</param>
/// <param name="result">Resultant object's ip addresses, if successful.</param> /// <param name="result">Resulting object's IP addresses, if successful.</param>
/// <returns>Success of the operation.</returns> /// <returns>Success of the operation.</returns>
bool TryParseInterface(string intf, out List<IPData>? result); bool TryParseInterface(string intf, out List<IPData>? result);
/// <summary> /// <summary>
/// Returns all the internal bind interface addresses. /// Returns all internal (LAN) bind interface addresses.
/// </summary> /// </summary>
/// <returns>An internal list of interfaces addresses.</returns> /// <returns>An list of internal (LAN) interfaces addresses.</returns>
IReadOnlyList<IPData> GetInternalBindAddresses(); IReadOnlyList<IPData> GetInternalBindAddresses();
/// <summary> /// <summary>
/// Checks to see if <paramref name="remoteIp"/> has access. /// Checks if <paramref name="remoteIp"/> has access to the server.
/// </summary> /// </summary>
/// <param name="remoteIp">IP Address of client.</param> /// <param name="remoteIp">IP address of the client.</param>
/// <returns><b>True</b> if has access, otherwise <b>false</b>.</returns> /// <returns><b>True</b> if it has access, otherwise <b>false</b>.</returns>
bool HasRemoteAccess(IPAddress remoteIp); bool HasRemoteAccess(IPAddress remoteIp);
} }
} }

View File

@ -12,9 +12,9 @@ namespace MediaBrowser.Common.Net
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="IPData"/> class. /// Initializes a new instance of the <see cref="IPData"/> class.
/// </summary> /// </summary>
/// <param name="address">An <see cref="IPAddress"/>.</param> /// <param name="address">The <see cref="IPAddress"/>.</param>
/// <param name="subnet">The <see cref="IPNetwork"/>.</param> /// <param name="subnet">The <see cref="IPNetwork"/>.</param>
/// <param name="name">The object's name.</param> /// <param name="name">The interface name.</param>
public IPData(IPAddress address, IPNetwork? subnet, string name) public IPData(IPAddress address, IPNetwork? subnet, string name)
{ {
Address = address; Address = address;
@ -25,7 +25,7 @@ namespace MediaBrowser.Common.Net
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="IPData"/> class. /// Initializes a new instance of the <see cref="IPData"/> class.
/// </summary> /// </summary>
/// <param name="address">An <see cref="IPAddress"/>.</param> /// <param name="address">The <see cref="IPAddress"/>.</param>
/// <param name="subnet">The <see cref="IPNetwork"/>.</param> /// <param name="subnet">The <see cref="IPNetwork"/>.</param>
public IPData(IPAddress address, IPNetwork? subnet) public IPData(IPAddress address, IPNetwork? subnet)
: this(address, subnet, string.Empty) : this(address, subnet, string.Empty)
@ -53,7 +53,7 @@ namespace MediaBrowser.Common.Net
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// Gets the AddressFamily of this object. /// Gets the AddressFamily of the object.
/// </summary> /// </summary>
public AddressFamily AddressFamily public AddressFamily AddressFamily
{ {

View File

@ -1,6 +1,5 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
using System.Collections.Generic;
using System.Net; using System.Net;
namespace MediaBrowser.Model.Net namespace MediaBrowser.Model.Net

View File

@ -142,11 +142,7 @@ namespace Rssdp.Infrastructure
if (_BroadcastListenSockets != null) if (_BroadcastListenSockets != null)
{ {
_logger.LogInformation("{0} disposing _BroadcastListenSocket", GetType().Name); _logger.LogInformation("{0} disposing _BroadcastListenSocket", GetType().Name);
foreach (var socket in _BroadcastListenSockets) _BroadcastListenSockets.ForEach(s => s.Dispose());
{
socket.Dispose();
}
_BroadcastListenSockets = null; _BroadcastListenSockets = null;
} }
} }