|
|
@ -45,6 +45,8 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IConfigurationManager _configurationManager;
|
|
|
|
private readonly IConfigurationManager _configurationManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly object _eventFireLock;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Holds the bind address overrides.
|
|
|
|
/// Holds the bind address overrides.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -106,6 +108,7 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
_macAddresses = new List<PhysicalAddress>();
|
|
|
|
_macAddresses = new List<PhysicalAddress>();
|
|
|
|
_interfaceNames = new Dictionary<string, int>();
|
|
|
|
_interfaceNames = new Dictionary<string, int>();
|
|
|
|
_publishedServerUrls = new Dictionary<IPNetAddress, string>();
|
|
|
|
_publishedServerUrls = new Dictionary<IPNetAddress, string>();
|
|
|
|
|
|
|
|
_eventFireLock = new object();
|
|
|
|
|
|
|
|
|
|
|
|
NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged;
|
|
|
|
NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged;
|
|
|
|
NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;
|
|
|
|
NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;
|
|
|
@ -158,11 +161,8 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
public List<PhysicalAddress> GetMacAddresses()
|
|
|
|
public List<PhysicalAddress> GetMacAddresses()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Populated in construction - so always has values.
|
|
|
|
// Populated in construction - so always has values.
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _macAddresses.ToList();
|
|
|
|
return _macAddresses.ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool IsGatewayInterface(object? addressObj)
|
|
|
|
public bool IsGatewayInterface(object? addressObj)
|
|
|
@ -174,10 +174,7 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
_ => IPAddress.None
|
|
|
|
_ => IPAddress.None
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
return _internalInterfaces.Any(i => i.Address.Equals(address) && i.Tag < 0);
|
|
|
|
{
|
|
|
|
|
|
|
|
return _internalInterfaces.Where(i => i.Address.Equals(address) && i.Tag < 0).Any();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
@ -224,14 +221,14 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (v.StartsWith("[", StringComparison.OrdinalIgnoreCase) && v.EndsWith("]", StringComparison.OrdinalIgnoreCase))
|
|
|
|
if (v.StartsWith('[') && v.EndsWith(']'))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (bracketed)
|
|
|
|
if (bracketed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AddToCollection(col, v.Remove(v.Length - 1).Substring(1));
|
|
|
|
AddToCollection(col, v.Substring(1, v.Length - 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (v.StartsWith("!", StringComparison.OrdinalIgnoreCase))
|
|
|
|
else if (v.StartsWith('!'))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (bracketed)
|
|
|
|
if (bracketed)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -254,8 +251,6 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public NetCollection GetAllBindInterfaces(bool individualInterfaces = false)
|
|
|
|
public NetCollection GetAllBindInterfaces(bool individualInterfaces = false)
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int count = _bindAddresses.Count;
|
|
|
|
int count = _bindAddresses.Count;
|
|
|
|
|
|
|
|
|
|
|
@ -291,7 +286,6 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
// Remove any excluded bind interfaces.
|
|
|
|
// Remove any excluded bind interfaces.
|
|
|
|
return _bindAddresses.Exclude(_bindExclusions);
|
|
|
|
return _bindAddresses.Exclude(_bindExclusions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public string GetBindInterface(string source, out int? port)
|
|
|
|
public string GetBindInterface(string source, out int? port)
|
|
|
@ -351,18 +345,16 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
|
|
|
|
|
|
|
|
isExternal = !IsInLocalNetwork(source);
|
|
|
|
isExternal = !IsInLocalNetwork(source);
|
|
|
|
|
|
|
|
|
|
|
|
if (MatchesPublishedServerUrl(source, isExternal, out string result, out port))
|
|
|
|
if (MatchesPublishedServerUrl(source, isExternal, out string res, out port))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogInformation("{0}: Using BindAddress {1}:{2}", source, result, port);
|
|
|
|
_logger.LogInformation("{0}: Using BindAddress {1}:{2}", source, res, port);
|
|
|
|
return result;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogDebug("GetBindInterface: Souce: {0}, External: {1}:", haveSource, isExternal);
|
|
|
|
_logger.LogDebug("GetBindInterface: Source: {0}, External: {1}:", haveSource, isExternal);
|
|
|
|
|
|
|
|
|
|
|
|
// No preference given, so move on to bind addresses.
|
|
|
|
// No preference given, so move on to bind addresses.
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (MatchesBindInterface(source, isExternal, out string result))
|
|
|
|
if (MatchesBindInterface(source, isExternal, out string result))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
@ -406,12 +398,9 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
_logger.LogWarning("{0}: GetBindInterface: Loopback return.", source, result);
|
|
|
|
_logger.LogWarning("{0}: GetBindInterface: Loopback return.", source, result);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public NetCollection GetInternalBindAddresses()
|
|
|
|
public NetCollection GetInternalBindAddresses()
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int count = _bindAddresses.Count;
|
|
|
|
int count = _bindAddresses.Count;
|
|
|
|
|
|
|
|
|
|
|
@ -429,7 +418,6 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
|
|
|
|
|
|
|
|
return new NetCollection(_bindAddresses);
|
|
|
|
return new NetCollection(_bindAddresses);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool IsInLocalNetwork(IPObject address)
|
|
|
|
public bool IsInLocalNetwork(IPObject address)
|
|
|
@ -450,23 +438,17 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// As private addresses can be redefined by Configuration.LocalNetworkAddresses
|
|
|
|
// As private addresses can be redefined by Configuration.LocalNetworkAddresses
|
|
|
|
return _lanSubnets.Contains(address) && !_excludedSubnets.Contains(address);
|
|
|
|
return _lanSubnets.Contains(address) && !_excludedSubnets.Contains(address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool IsInLocalNetwork(string address)
|
|
|
|
public bool IsInLocalNetwork(string address)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (IPHost.TryParse(address, out IPHost ep))
|
|
|
|
if (IPHost.TryParse(address, out IPHost ep))
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _lanSubnets.Contains(ep) && !_excludedSubnets.Contains(ep);
|
|
|
|
return _lanSubnets.Contains(ep) && !_excludedSubnets.Contains(ep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -485,12 +467,9 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// As private addresses can be redefined by Configuration.LocalNetworkAddresses
|
|
|
|
// As private addresses can be redefined by Configuration.LocalNetworkAddresses
|
|
|
|
return _lanSubnets.Contains(address) && !_excludedSubnets.Contains(address);
|
|
|
|
return _lanSubnets.Contains(address) && !_excludedSubnets.Contains(address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool IsPrivateAddressRange(IPObject address)
|
|
|
|
public bool IsPrivateAddressRange(IPObject address)
|
|
|
@ -513,17 +492,12 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool IsExcludedInterface(IPAddress address)
|
|
|
|
public bool IsExcludedInterface(IPAddress address)
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _bindExclusions.Contains(address);
|
|
|
|
return _bindExclusions.Contains(address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public NetCollection GetFilteredLANSubnets(NetCollection? filter = null)
|
|
|
|
public NetCollection GetFilteredLANSubnets(NetCollection? filter = null)
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (filter == null)
|
|
|
|
if (filter == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -532,16 +506,12 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
|
|
|
|
|
|
|
|
return _lanSubnets.Exclude(filter);
|
|
|
|
return _lanSubnets.Exclude(filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool IsValidInterfaceAddress(IPAddress address)
|
|
|
|
public bool IsValidInterfaceAddress(IPAddress address)
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_intLock)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return _interfaceAddresses.Contains(address);
|
|
|
|
return _interfaceAddresses.Contains(address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool TryParseInterface(string token, out NetCollection? result)
|
|
|
|
public bool TryParseInterface(string token, out NetCollection? result)
|
|
|
@ -583,7 +553,7 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NetworkConfiguration config = (NetworkConfiguration)configuration ?? throw new ArgumentNullException(nameof(configuration));
|
|
|
|
NetworkConfiguration config = (NetworkConfiguration)configuration ?? throw new ArgumentNullException(nameof(configuration));
|
|
|
|
|
|
|
|
|
|
|
|
IsIP4Enabled = Socket.OSSupportsIPv6 && config.EnableIPV4;
|
|
|
|
IsIP4Enabled = Socket.OSSupportsIPv4 && config.EnableIPV4;
|
|
|
|
IsIP6Enabled = Socket.OSSupportsIPv6 && config.EnableIPV6;
|
|
|
|
IsIP6Enabled = Socket.OSSupportsIPv6 && config.EnableIPV6;
|
|
|
|
|
|
|
|
|
|
|
|
if (!IsIP6Enabled && !IsIP4Enabled)
|
|
|
|
if (!IsIP6Enabled && !IsIP4Enabled)
|
|
|
@ -761,7 +731,7 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
/// Handler for network change events.
|
|
|
|
/// Handler for network change events.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender">Sender.</param>
|
|
|
|
/// <param name="sender">Sender.</param>
|
|
|
|
/// <param name="e">Network availablity information.</param>
|
|
|
|
/// <param name="e">Network availability information.</param>
|
|
|
|
private void OnNetworkAvailabilityChanged(object? sender, NetworkAvailabilityEventArgs e)
|
|
|
|
private void OnNetworkAvailabilityChanged(object? sender, NetworkAvailabilityEventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogDebug("Network availability changed.");
|
|
|
|
_logger.LogDebug("Network availability changed.");
|
|
|
@ -804,13 +774,16 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
/// Triggers our event, and re-loads interface information.
|
|
|
|
/// Triggers our event, and re-loads interface information.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private void OnNetworkChanged()
|
|
|
|
private void OnNetworkChanged()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_eventFireLock)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!_eventfire)
|
|
|
|
if (!_eventfire)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogDebug("Network Address Change Event.");
|
|
|
|
_logger.LogDebug("Network Address Change Event.");
|
|
|
|
// As network events tend to fire one after the other only fire once every second.
|
|
|
|
// As network events tend to fire one after the other only fire once every second.
|
|
|
|
_eventfire = true;
|
|
|
|
_eventfire = true;
|
|
|
|
_ = OnNetworkChangeAsync();
|
|
|
|
OnNetworkChangeAsync().GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -881,8 +854,7 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
lanAddresses = lanAddresses[0].Split(',');
|
|
|
|
lanAddresses = lanAddresses[0].Split(',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: end fix.
|
|
|
|
// TODO: end fix: https://github.com/jellyfin/jellyfin-web/issues/1334
|
|
|
|
// TODO: end fix.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add virtual machine interface names to the list of bind exclusions, so that they are auto-excluded.
|
|
|
|
// Add virtual machine interface names to the list of bind exclusions, so that they are auto-excluded.
|
|
|
|
if (config.IgnoreVirtualInterfaces)
|
|
|
|
if (config.IgnoreVirtualInterfaces)
|
|
|
@ -924,7 +896,7 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
// If no LAN addresses are specified - all private subnets are deemed to be the LAN
|
|
|
|
// If no LAN addresses are specified - all private subnets are deemed to be the LAN
|
|
|
|
_usingPrivateAddresses = _lanSubnets.Count == 0;
|
|
|
|
_usingPrivateAddresses = _lanSubnets.Count == 0;
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: The order of the commands in this statement matters, otherwise the lists won't initialise correctly.
|
|
|
|
// NOTE: The order of the commands in this statement matters.
|
|
|
|
if (_usingPrivateAddresses)
|
|
|
|
if (_usingPrivateAddresses)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogDebug("Using LAN interface addresses as user provided no LAN details.");
|
|
|
|
_logger.LogDebug("Using LAN interface addresses as user provided no LAN details.");
|
|
|
@ -975,7 +947,7 @@ namespace Jellyfin.Networking.Manager
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Generate a list of all the interface ip addresses and submasks where that are in the active/unknown state.
|
|
|
|
/// Generate a list of all the interface ip addresses and submasks where that are in the active/unknown state.
|
|
|
|
/// Generate a list of all active mac addresses that aren't loopback addreses.
|
|
|
|
/// Generate a list of all active mac addresses that aren't loopback addresses.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private void InitialiseInterfaces()
|
|
|
|
private void InitialiseInterfaces()
|
|
|
|
{
|
|
|
|
{
|
|
|
|