Updated networkmanager to the lastest.

pull/4125/head
Greenback 4 years ago
parent 39754b840d
commit 8a4f81c9a7

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

Loading…
Cancel
Save