aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Networking/Manager/NetworkManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Jellyfin.Networking/Manager/NetworkManager.cs')
-rw-r--r--src/Jellyfin.Networking/Manager/NetworkManager.cs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/Jellyfin.Networking/Manager/NetworkManager.cs b/src/Jellyfin.Networking/Manager/NetworkManager.cs
index b285b836b..dd01e9533 100644
--- a/src/Jellyfin.Networking/Manager/NetworkManager.cs
+++ b/src/Jellyfin.Networking/Manager/NetworkManager.cs
@@ -27,7 +27,7 @@ public class NetworkManager : INetworkManager, IDisposable
/// <summary>
/// Threading lock for network properties.
/// </summary>
- private readonly object _initLock;
+ private readonly Lock _initLock;
private readonly ILogger<NetworkManager> _logger;
@@ -35,7 +35,7 @@ public class NetworkManager : INetworkManager, IDisposable
private readonly IConfiguration _startupConfig;
- private readonly object _networkEventLock;
+ private readonly Lock _networkEventLock;
/// <summary>
/// Holds the published server URLs and the IPs to use them on.
@@ -57,7 +57,7 @@ public class NetworkManager : INetworkManager, IDisposable
/// <summary>
/// Dictionary containing interface addresses and their subnets.
/// </summary>
- private IReadOnlyList<IPData> _interfaces;
+ private List<IPData> _interfaces;
/// <summary>
/// Unfiltered user defined LAN subnets (<see cref="NetworkConfiguration.LocalNetworkSubnets"/>)
@@ -81,7 +81,6 @@ public class NetworkManager : INetworkManager, IDisposable
/// <param name="configurationManager">The <see cref="IConfigurationManager"/> instance.</param>
/// <param name="startupConfig">The <see cref="IConfiguration"/> instance holding startup parameters.</param>
/// <param name="logger">Logger to use for messages.</param>
-#pragma warning disable CS8618 // Non-nullable field is uninitialized. : Values are set in UpdateSettings function. Compiler doesn't yet recognise this.
public NetworkManager(IConfigurationManager configurationManager, IConfiguration startupConfig, ILogger<NetworkManager> logger)
{
ArgumentNullException.ThrowIfNull(logger);
@@ -94,7 +93,7 @@ public class NetworkManager : INetworkManager, IDisposable
_interfaces = new List<IPData>();
_macAddresses = new List<PhysicalAddress>();
_publishedServerUrls = new List<PublishedServerUriOverride>();
- _networkEventLock = new object();
+ _networkEventLock = new();
_remoteAddressFilter = new List<IPNetwork>();
_ = bool.TryParse(startupConfig[DetectNetworkChangeKey], out var detectNetworkChange);
@@ -109,7 +108,6 @@ public class NetworkManager : INetworkManager, IDisposable
_configurationManager.NamedConfigurationUpdated += ConfigurationUpdated;
}
-#pragma warning restore CS8618 // Non-nullable field is uninitialized.
/// <summary>
/// Event triggered on network changes.
@@ -312,6 +310,7 @@ public class NetworkManager : INetworkManager, IDisposable
/// <summary>
/// Initializes internal LAN cache.
/// </summary>
+ [MemberNotNull(nameof(_lanSubnets), nameof(_excludedSubnets))]
private void InitializeLan(NetworkConfiguration config)
{
lock (_initLock)
@@ -591,6 +590,7 @@ public class NetworkManager : INetworkManager, IDisposable
/// Reloads all settings and re-Initializes the instance.
/// </summary>
/// <param name="configuration">The <see cref="NetworkConfiguration"/> to use.</param>
+ [MemberNotNull(nameof(_lanSubnets), nameof(_excludedSubnets))]
public void UpdateSettings(object configuration)
{
ArgumentNullException.ThrowIfNull(configuration);
@@ -702,7 +702,7 @@ public class NetworkManager : INetworkManager, IDisposable
return false;
}
}
- else if (!_lanSubnets.Any(x => x.Contains(remoteIP)))
+ else if (!IsInLocalNetwork(remoteIP))
{
// Remote not enabled. So everyone should be LAN.
return false;
@@ -973,7 +973,7 @@ public class NetworkManager : INetworkManager, IDisposable
bindPreference = string.Empty;
int? port = null;
- // Only consider subnets including the source IP, prefering specific overrides
+ // Only consider subnets including the source IP, preferring specific overrides
List<PublishedServerUriOverride> validPublishedServerUrls;
if (!isInExternalSubnet)
{
@@ -997,7 +997,9 @@ public class NetworkManager : INetworkManager, IDisposable
// Get interface matching override subnet
var intf = _interfaces.OrderBy(x => x.Index).FirstOrDefault(x => data.Data.Subnet.Contains(x.Address));
- if (intf?.Address is not null)
+ if (intf?.Address is not null
+ || (data.Data.AddressFamily == AddressFamily.InterNetwork && data.Data.Address.Equals(IPAddress.Any))
+ || (data.Data.AddressFamily == AddressFamily.InterNetworkV6 && data.Data.Address.Equals(IPAddress.IPv6Any)))
{
// If matching interface is found, use override
bindPreference = data.OverrideUri;
@@ -1025,6 +1027,7 @@ public class NetworkManager : INetworkManager, IDisposable
}
_logger.LogDebug("{Source}: Matching bind address override found: {Address}", source, bindPreference);
+
return true;
}
@@ -1063,6 +1066,7 @@ public class NetworkManager : INetworkManager, IDisposable
// If none exists, this will select the first external interface if there is one.
bindAddress = externalInterfaces
.OrderByDescending(x => x.Subnet.Contains(source))
+ .ThenByDescending(x => x.Subnet.PrefixLength)
.ThenBy(x => x.Index)
.Select(x => x.Address)
.First();
@@ -1080,6 +1084,7 @@ public class NetworkManager : INetworkManager, IDisposable
// If none exists, this will select the first internal interface if there is one.
bindAddress = _interfaces.Where(x => IsInLocalNetwork(x.Address))
.OrderByDescending(x => x.Subnet.Contains(source))
+ .ThenByDescending(x => x.Subnet.PrefixLength)
.ThenBy(x => x.Index)
.Select(x => x.Address)
.FirstOrDefault();