|
@@ -1,6 +1,5 @@
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
-using System.Collections.ObjectModel;
|
|
|
|
using System.Globalization;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net;
|
|
@@ -47,7 +46,7 @@ namespace Jellyfin.Networking.Manager
|
|
/// </summary>
|
|
/// </summary>
|
|
private readonly Dictionary<IPData, string> _publishedServerUrls;
|
|
private readonly Dictionary<IPData, string> _publishedServerUrls;
|
|
|
|
|
|
- private Collection<IPNetwork> _remoteAddressFilter;
|
|
|
|
|
|
+ private List<IPNetwork> _remoteAddressFilter;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Used to stop "event-racing conditions".
|
|
/// Used to stop "event-racing conditions".
|
|
@@ -58,12 +57,12 @@ namespace Jellyfin.Networking.Manager
|
|
/// Unfiltered user defined LAN subnets (<see cref="NetworkConfiguration.LocalNetworkSubnets"/>)
|
|
/// Unfiltered user defined LAN subnets (<see cref="NetworkConfiguration.LocalNetworkSubnets"/>)
|
|
/// or internal interface network subnets if undefined by user.
|
|
/// or internal interface network subnets if undefined by user.
|
|
/// </summary>
|
|
/// </summary>
|
|
- private Collection<IPNetwork> _lanSubnets;
|
|
|
|
|
|
+ private List<IPNetwork> _lanSubnets;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// User defined list of subnets to excluded from the LAN.
|
|
/// User defined list of subnets to excluded from the LAN.
|
|
/// </summary>
|
|
/// </summary>
|
|
- private Collection<IPNetwork> _excludedSubnets;
|
|
|
|
|
|
+ private List<IPNetwork> _excludedSubnets;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// List of interfaces to bind to.
|
|
/// List of interfaces to bind to.
|
|
@@ -95,7 +94,7 @@ namespace Jellyfin.Networking.Manager
|
|
_macAddresses = new List<PhysicalAddress>();
|
|
_macAddresses = new List<PhysicalAddress>();
|
|
_publishedServerUrls = new Dictionary<IPData, string>();
|
|
_publishedServerUrls = new Dictionary<IPData, string>();
|
|
_eventFireLock = new object();
|
|
_eventFireLock = new object();
|
|
- _remoteAddressFilter = new Collection<IPNetwork>();
|
|
|
|
|
|
+ _remoteAddressFilter = new List<IPNetwork>();
|
|
|
|
|
|
UpdateSettings(_configurationManager.GetNetworkConfiguration());
|
|
UpdateSettings(_configurationManager.GetNetworkConfiguration());
|
|
|
|
|
|
@@ -225,8 +224,8 @@ namespace Jellyfin.Networking.Manager
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- IPInterfaceProperties ipProperties = adapter.GetIPProperties();
|
|
|
|
- PhysicalAddress mac = adapter.GetPhysicalAddress();
|
|
|
|
|
|
+ var ipProperties = adapter.GetIPProperties();
|
|
|
|
+ var mac = adapter.GetPhysicalAddress();
|
|
|
|
|
|
// Populate MAC list
|
|
// Populate MAC list
|
|
if (adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback && PhysicalAddress.None.Equals(mac))
|
|
if (adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback && PhysicalAddress.None.Equals(mac))
|
|
@@ -235,7 +234,7 @@ namespace Jellyfin.Networking.Manager
|
|
}
|
|
}
|
|
|
|
|
|
// Populate interface list
|
|
// Populate interface list
|
|
- foreach (UnicastIPAddressInformation info in ipProperties.UnicastAddresses)
|
|
|
|
|
|
+ foreach (var info in ipProperties.UnicastAddresses)
|
|
{
|
|
{
|
|
if (IsIpv4Enabled && info.Address.AddressFamily == AddressFamily.InterNetwork)
|
|
if (IsIpv4Enabled && info.Address.AddressFamily == AddressFamily.InterNetwork)
|
|
{
|
|
{
|
|
@@ -364,8 +363,8 @@ namespace Jellyfin.Networking.Manager
|
|
// Use explicit bind addresses
|
|
// Use explicit bind addresses
|
|
if (config.LocalNetworkAddresses.Length > 0)
|
|
if (config.LocalNetworkAddresses.Length > 0)
|
|
{
|
|
{
|
|
- _bindAddresses = config.LocalNetworkAddresses.Select(p => IPAddress.TryParse(p, out var address)
|
|
|
|
- ? address
|
|
|
|
|
|
+ _bindAddresses = config.LocalNetworkAddresses.Select(p => IPAddress.TryParse(p, out var addresses)
|
|
|
|
+ ? addresses
|
|
: (_interfaces.Where(x => x.Name.Equals(p, StringComparison.OrdinalIgnoreCase)).Select(x => x.Address).FirstOrDefault() ?? IPAddress.None)).ToList();
|
|
: (_interfaces.Where(x => x.Name.Equals(p, StringComparison.OrdinalIgnoreCase)).Select(x => x.Address).FirstOrDefault() ?? IPAddress.None)).ToList();
|
|
_bindAddresses.RemoveAll(x => x == IPAddress.None);
|
|
_bindAddresses.RemoveAll(x => x == IPAddress.None);
|
|
}
|
|
}
|
|
@@ -525,13 +524,11 @@ namespace Jellyfin.Networking.Manager
|
|
var address = IPAddress.Parse(split[0]);
|
|
var address = IPAddress.Parse(split[0]);
|
|
var network = new IPNetwork(address, int.Parse(split[1], CultureInfo.InvariantCulture));
|
|
var network = new IPNetwork(address, int.Parse(split[1], CultureInfo.InvariantCulture));
|
|
var index = int.Parse(parts[1], CultureInfo.InvariantCulture);
|
|
var index = int.Parse(parts[1], CultureInfo.InvariantCulture);
|
|
- if (address.AddressFamily == AddressFamily.InterNetwork)
|
|
|
|
|
|
+ if (address.AddressFamily == AddressFamily.InterNetwork || address.AddressFamily == AddressFamily.InterNetworkV6)
|
|
{
|
|
{
|
|
- _interfaces.Add(new IPData(address, network, parts[2]));
|
|
|
|
- }
|
|
|
|
- else if (address.AddressFamily == AddressFamily.InterNetworkV6)
|
|
|
|
- {
|
|
|
|
- _interfaces.Add(new IPData(address, network, parts[2]));
|
|
|
|
|
|
+ var data = new IPData(address, network, parts[2]);
|
|
|
|
+ data.Index = index;
|
|
|
|
+ _interfaces.Add(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -562,9 +559,9 @@ namespace Jellyfin.Networking.Manager
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
- public bool TryParseInterface(string intf, out Collection<IPData> result)
|
|
|
|
|
|
+ public bool TryParseInterface(string intf, out List<IPData> result)
|
|
{
|
|
{
|
|
- result = new Collection<IPData>();
|
|
|
|
|
|
+ result = new List<IPData>();
|
|
if (string.IsNullOrEmpty(intf))
|
|
if (string.IsNullOrEmpty(intf))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
@@ -573,7 +570,7 @@ namespace Jellyfin.Networking.Manager
|
|
if (_interfaces != null)
|
|
if (_interfaces != null)
|
|
{
|
|
{
|
|
// Match all interfaces starting with names starting with token
|
|
// Match all interfaces starting with names starting with token
|
|
- var matchedInterfaces = _interfaces.Where(s => s.Name.Equals(intf.ToLowerInvariant(), StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
+ var matchedInterfaces = _interfaces.Where(s => s.Name.Equals(intf.ToLowerInvariant(), StringComparison.OrdinalIgnoreCase)).OrderBy(x => x.Index);
|
|
if (matchedInterfaces.Any())
|
|
if (matchedInterfaces.Any())
|
|
{
|
|
{
|
|
_logger.LogInformation("Interface {Token} used in settings. Using its interface addresses.", intf);
|
|
_logger.LogInformation("Interface {Token} used in settings. Using its interface addresses.", intf);
|
|
@@ -626,14 +623,14 @@ namespace Jellyfin.Networking.Manager
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
- public IReadOnlyCollection<PhysicalAddress> GetMacAddresses()
|
|
|
|
|
|
+ public IReadOnlyList<PhysicalAddress> GetMacAddresses()
|
|
{
|
|
{
|
|
// Populated in construction - so always has values.
|
|
// Populated in construction - so always has values.
|
|
return _macAddresses;
|
|
return _macAddresses;
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
- public List<IPData> GetLoopbacks()
|
|
|
|
|
|
+ public IReadOnlyList<IPData> GetLoopbacks()
|
|
{
|
|
{
|
|
var loopbackNetworks = new List<IPData>();
|
|
var loopbackNetworks = new List<IPData>();
|
|
if (IsIpv4Enabled)
|
|
if (IsIpv4Enabled)
|
|
@@ -650,7 +647,7 @@ namespace Jellyfin.Networking.Manager
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
- public List<IPData> GetAllBindInterfaces(bool individualInterfaces = false)
|
|
|
|
|
|
+ public IReadOnlyList<IPData> GetAllBindInterfaces(bool individualInterfaces = false)
|
|
{
|
|
{
|
|
if (_bindAddresses.Count == 0)
|
|
if (_bindAddresses.Count == 0)
|
|
{
|
|
{
|
|
@@ -816,7 +813,7 @@ namespace Jellyfin.Networking.Manager
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
- public List<IPData> GetInternalBindAddresses()
|
|
|
|
|
|
+ public IReadOnlyList<IPData> GetInternalBindAddresses()
|
|
{
|
|
{
|
|
if (_bindAddresses.Count == 0)
|
|
if (_bindAddresses.Count == 0)
|
|
{
|
|
{
|
|
@@ -833,7 +830,8 @@ namespace Jellyfin.Networking.Manager
|
|
// Select all local bind addresses
|
|
// Select all local bind addresses
|
|
return _interfaces.Where(x => _bindAddresses.Contains(x.Address))
|
|
return _interfaces.Where(x => _bindAddresses.Contains(x.Address))
|
|
.Where(x => IsInLocalNetwork(x.Address))
|
|
.Where(x => IsInLocalNetwork(x.Address))
|
|
- .OrderBy(x => x.Index).ToList();
|
|
|
|
|
|
+ .OrderBy(x => x.Index)
|
|
|
|
+ .ToList();
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
@@ -892,7 +890,7 @@ namespace Jellyfin.Networking.Manager
|
|
interfaces = interfaces.Where(x => IsInLocalNetwork(x.Address)).ToList();
|
|
interfaces = interfaces.Where(x => IsInLocalNetwork(x.Address)).ToList();
|
|
}
|
|
}
|
|
|
|
|
|
- foreach (var intf in _interfaces)
|
|
|
|
|
|
+ foreach (var intf in interfaces)
|
|
{
|
|
{
|
|
if (intf.Subnet.Contains(address))
|
|
if (intf.Subnet.Contains(address))
|
|
{
|
|
{
|
|
@@ -942,7 +940,7 @@ namespace Jellyfin.Networking.Manager
|
|
foreach (var data in validPublishedServerUrls)
|
|
foreach (var data in validPublishedServerUrls)
|
|
{
|
|
{
|
|
// Get address interface
|
|
// Get address interface
|
|
- var intf = _interfaces.FirstOrDefault(s => s.Subnet.Contains(data.Key.Address));
|
|
|
|
|
|
+ var intf = _interfaces.OrderBy(x => x.Index).FirstOrDefault(s => s.Subnet.Contains(data.Key.Address));
|
|
|
|
|
|
// Remaining. Match anything.
|
|
// Remaining. Match anything.
|
|
if (data.Key.Address.Equals(IPAddress.Broadcast))
|
|
if (data.Key.Address.Equals(IPAddress.Broadcast))
|
|
@@ -1017,7 +1015,7 @@ namespace Jellyfin.Networking.Manager
|
|
defaultGateway = addr;
|
|
defaultGateway = addr;
|
|
}
|
|
}
|
|
|
|
|
|
- var intf = _interfaces.Where(x => x.Subnet.Contains(addr)).FirstOrDefault();
|
|
|
|
|
|
+ var intf = _interfaces.Where(x => x.Subnet.Contains(addr)).OrderBy(x => x.Index).FirstOrDefault();
|
|
|
|
|
|
if (bindAddress == null && intf != null && intf.Subnet.Contains(source))
|
|
if (bindAddress == null && intf != null && intf.Subnet.Contains(source))
|
|
{
|
|
{
|
|
@@ -1082,7 +1080,7 @@ namespace Jellyfin.Networking.Manager
|
|
{
|
|
{
|
|
result = string.Empty;
|
|
result = string.Empty;
|
|
// Get the first WAN interface address that isn't a loopback.
|
|
// Get the first WAN interface address that isn't a loopback.
|
|
- var extResult = _interfaces.Where(p => !IsInLocalNetwork(p.Address));
|
|
|
|
|
|
+ var extResult = _interfaces.Where(p => !IsInLocalNetwork(p.Address)).OrderBy(x => x.Index);
|
|
|
|
|
|
IPAddress? hasResult = null;
|
|
IPAddress? hasResult = null;
|
|
// Does the request originate in one of the interface subnets?
|
|
// Does the request originate in one of the interface subnets?
|