Fix build, fix loopback binding, exclude unsupported IPs from bind

pull/8147/head
Shadowghost 3 years ago
parent 2d3a16ad0f
commit 358642c2d9

@ -183,7 +183,7 @@ namespace Jellyfin.Networking.Manager
var networkConfig = _configurationManager.GetNetworkConfiguration(); var networkConfig = _configurationManager.GetNetworkConfiguration();
InitialiseLan(networkConfig); InitialiseLan(networkConfig);
InitialiseInterfaces(); InitialiseInterfaces();
EnforceBindRestrictions(networkConfig); EnforceBindSettings(networkConfig);
NetworkChanged?.Invoke(this, EventArgs.Empty); NetworkChanged?.Invoke(this, EventArgs.Empty);
} }
@ -261,6 +261,8 @@ namespace Jellyfin.Networking.Manager
_logger.LogError(ex, "Error obtaining interfaces."); _logger.LogError(ex, "Error obtaining interfaces.");
} }
if (_interfaces.Count == 0)
{
_logger.LogWarning("No interfaces information available. Using loopback."); _logger.LogWarning("No interfaces information available. Using loopback.");
if (IsIpv4Enabled && !IsIpv6Enabled) if (IsIpv4Enabled && !IsIpv6Enabled)
@ -272,6 +274,7 @@ namespace Jellyfin.Networking.Manager
{ {
_interfaces.Add(new IPData(IPAddress.IPv6Loopback, new IPNetwork(IPAddress.IPv6Loopback, 128), "lo")); _interfaces.Add(new IPData(IPAddress.IPv6Loopback, new IPNetwork(IPAddress.IPv6Loopback, 128), "lo"));
} }
}
_logger.LogDebug("Discovered {0} interfaces.", _interfaces.Count); _logger.LogDebug("Discovered {0} interfaces.", _interfaces.Count);
_logger.LogDebug("Interfaces addresses : {0}", _interfaces.Select(s => s.Address).ToString()); _logger.LogDebug("Interfaces addresses : {0}", _interfaces.Select(s => s.Address).ToString());
@ -321,7 +324,7 @@ namespace Jellyfin.Networking.Manager
/// <summary> /// <summary>
/// Enforce bind addresses and exclusions on available interfaces. /// Enforce bind addresses and exclusions on available interfaces.
/// </summary> /// </summary>
private void EnforceBindRestrictions(NetworkConfiguration config) private void EnforceBindSettings(NetworkConfiguration config)
{ {
lock (_initLock) lock (_initLock)
{ {
@ -329,7 +332,7 @@ namespace Jellyfin.Networking.Manager
var localNetworkAddresses = config.LocalNetworkAddresses; var localNetworkAddresses = config.LocalNetworkAddresses;
if (localNetworkAddresses.Length > 0 && !string.IsNullOrWhiteSpace(localNetworkAddresses.First())) if (localNetworkAddresses.Length > 0 && !string.IsNullOrWhiteSpace(localNetworkAddresses.First()))
{ {
var bindAddresses = config.LocalNetworkAddresses.Select(p => IPAddress.TryParse(p, out var addresses) var bindAddresses = localNetworkAddresses.Select(p => IPAddress.TryParse(p, out var addresses)
? addresses ? addresses
: (_interfaces.Where(x => x.Name.Equals(p, StringComparison.OrdinalIgnoreCase)) : (_interfaces.Where(x => x.Name.Equals(p, StringComparison.OrdinalIgnoreCase))
.Select(x => x.Address) .Select(x => x.Address)
@ -337,6 +340,16 @@ namespace Jellyfin.Networking.Manager
.ToList(); .ToList();
bindAddresses.RemoveAll(x => x == IPAddress.None); bindAddresses.RemoveAll(x => x == IPAddress.None);
_interfaces = _interfaces.Where(x => bindAddresses.Contains(x.Address)).ToList(); _interfaces = _interfaces.Where(x => bindAddresses.Contains(x.Address)).ToList();
if (bindAddresses.Contains(IPAddress.Loopback))
{
_interfaces.Add(new IPData(IPAddress.Loopback, new IPNetwork(IPAddress.Loopback, 8), "lo"));
}
if (bindAddresses.Contains(IPAddress.IPv6Loopback))
{
_interfaces.Add(new IPData(IPAddress.IPv6Loopback, new IPNetwork(IPAddress.IPv6Loopback, 128), "lo"));
}
} }
// Remove all interfaces matching any virtual machine interface prefix // Remove all interfaces matching any virtual machine interface prefix
@ -358,6 +371,16 @@ namespace Jellyfin.Networking.Manager
} }
} }
if (!IsIpv4Enabled)
{
_interfaces.RemoveAll(x => x.AddressFamily == AddressFamily.InterNetwork);
}
if (!IsIpv6Enabled)
{
_interfaces.RemoveAll(x => x.AddressFamily == AddressFamily.InterNetworkV6);
}
_logger.LogInformation("Using bind addresses: {0}", _interfaces.Select(x => x.Address)); _logger.LogInformation("Using bind addresses: {0}", _interfaces.Select(x => x.Address));
} }
} }
@ -492,7 +515,7 @@ namespace Jellyfin.Networking.Manager
} }
} }
EnforceBindRestrictions(config); EnforceBindSettings(config);
InitialiseOverrides(config); InitialiseOverrides(config);
} }
@ -892,7 +915,7 @@ namespace Jellyfin.Networking.Manager
{ {
result = string.Empty; result = string.Empty;
int count = _interfaces.Count(); int count = _interfaces.Count;
if (count == 1 && (_interfaces[0].Equals(IPAddress.Any) || _interfaces[0].Equals(IPAddress.IPv6Any))) if (count == 1 && (_interfaces[0].Equals(IPAddress.Any) || _interfaces[0].Equals(IPAddress.IPv6Any)))
{ {
// Ignore IPAny addresses. // Ignore IPAny addresses.

Loading…
Cancel
Save