[Fix] NetworkManager binding to [::] (#4549)
* Autodiscovery enable/disable patch * Fixed [::] issue on bind. Altered test. * Update UdpServerEntryPoint.cs * Update Jellyfin.Networking.Tests.csproj * Update Jellyfin.Networking.Tests.csproj * Update INetworkManager.cs
This commit is contained in:
parent
6676ca4d1b
commit
50e375020a
|
@ -84,7 +84,7 @@ namespace Jellyfin.Networking.Manager
|
|||
private Collection<IPObject> _internalInterfaces;
|
||||
|
||||
/// <summary>
|
||||
/// Flag set when no custom LAN has been defined in the config.
|
||||
/// Flag set when no custom LAN has been defined in the configuration.
|
||||
/// </summary>
|
||||
private bool _usingPrivateAddresses;
|
||||
|
||||
|
@ -228,7 +228,7 @@ namespace Jellyfin.Networking.Manager
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Collection<IPObject> CreateIPCollection(string[] values, bool bracketed = false)
|
||||
public Collection<IPObject> CreateIPCollection(string[] values, bool negated = false)
|
||||
{
|
||||
Collection<IPObject> col = new Collection<IPObject>();
|
||||
if (values == null)
|
||||
|
@ -242,21 +242,14 @@ namespace Jellyfin.Networking.Manager
|
|||
|
||||
try
|
||||
{
|
||||
if (v.StartsWith('[') && v.EndsWith(']'))
|
||||
if (v.StartsWith('!'))
|
||||
{
|
||||
if (bracketed)
|
||||
{
|
||||
AddToCollection(col, v[1..^1]);
|
||||
}
|
||||
}
|
||||
else if (v.StartsWith('!'))
|
||||
{
|
||||
if (bracketed)
|
||||
if (negated)
|
||||
{
|
||||
AddToCollection(col, v[1..]);
|
||||
}
|
||||
}
|
||||
else if (!bracketed)
|
||||
else if (!negated)
|
||||
{
|
||||
AddToCollection(col, v);
|
||||
}
|
||||
|
@ -730,7 +723,7 @@ namespace Jellyfin.Networking.Manager
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a string and adds it into the the collection, replacing any interface references.
|
||||
/// Parses a string and adds it into the collection, replacing any interface references.
|
||||
/// </summary>
|
||||
/// <param name="col"><see cref="Collection{IPObject}"/>Collection.</param>
|
||||
/// <param name="token">String value to parse.</param>
|
||||
|
@ -755,7 +748,19 @@ namespace Jellyfin.Networking.Manager
|
|||
}
|
||||
else if (TryParse(token, out IPObject obj))
|
||||
{
|
||||
if (!IsIP6Enabled)
|
||||
// Expand if the ip address is "any".
|
||||
if ((obj.Address.Equals(IPAddress.Any) && IsIP4Enabled)
|
||||
|| (obj.Address.Equals(IPAddress.IPv6Any) && IsIP6Enabled))
|
||||
{
|
||||
foreach (IPNetAddress iface in _interfaceAddresses)
|
||||
{
|
||||
if (obj.AddressFamily == iface.AddressFamily)
|
||||
{
|
||||
col.AddItem(iface);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!IsIP6Enabled)
|
||||
{
|
||||
// Remove IP6 addresses from multi-homed IPHosts.
|
||||
obj.Remove(AddressFamily.InterNetworkV6);
|
||||
|
@ -872,7 +877,7 @@ namespace Jellyfin.Networking.Manager
|
|||
else
|
||||
{
|
||||
var replacement = parts[1].Trim();
|
||||
if (string.Equals(parts[0], "remaining", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(parts[0], "all", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_publishedServerUrls[new IPNetAddress(IPAddress.Broadcast)] = replacement;
|
||||
}
|
||||
|
@ -956,7 +961,7 @@ namespace Jellyfin.Networking.Manager
|
|||
{
|
||||
_logger.LogDebug("Refreshing LAN information.");
|
||||
|
||||
// Get config options.
|
||||
// Get configuration options.
|
||||
string[] subnets = config.LocalNetworkSubnets;
|
||||
|
||||
// Create lists from user settings.
|
||||
|
|
|
@ -149,7 +149,7 @@ namespace MediaBrowser.Common.Net
|
|||
|
||||
/// <summary>
|
||||
/// Returns true if the address is a private address.
|
||||
/// The config option TrustIP6Interfaces overrides this functions behaviour.
|
||||
/// The configuration option TrustIP6Interfaces overrides this functions behaviour.
|
||||
/// </summary>
|
||||
/// <param name="address">Address to check.</param>
|
||||
/// <returns>True or False.</returns>
|
||||
|
@ -157,7 +157,7 @@ namespace MediaBrowser.Common.Net
|
|||
|
||||
/// <summary>
|
||||
/// Returns true if the address is part of the user defined LAN.
|
||||
/// The config option TrustIP6Interfaces overrides this functions behaviour.
|
||||
/// The configuration option TrustIP6Interfaces overrides this functions behaviour.
|
||||
/// </summary>
|
||||
/// <param name="address">IP to check.</param>
|
||||
/// <returns>True if endpoint is within the LAN range.</returns>
|
||||
|
@ -165,7 +165,7 @@ namespace MediaBrowser.Common.Net
|
|||
|
||||
/// <summary>
|
||||
/// Returns true if the address is part of the user defined LAN.
|
||||
/// The config option TrustIP6Interfaces overrides this functions behaviour.
|
||||
/// The configuration option TrustIP6Interfaces overrides this functions behaviour.
|
||||
/// </summary>
|
||||
/// <param name="address">IP to check.</param>
|
||||
/// <returns>True if endpoint is within the LAN range.</returns>
|
||||
|
@ -173,7 +173,7 @@ namespace MediaBrowser.Common.Net
|
|||
|
||||
/// <summary>
|
||||
/// Returns true if the address is part of the user defined LAN.
|
||||
/// The config option TrustIP6Interfaces overrides this functions behaviour.
|
||||
/// The configuration option TrustIP6Interfaces overrides this functions behaviour.
|
||||
/// </summary>
|
||||
/// <param name="address">IP to check.</param>
|
||||
/// <returns>True if endpoint is within the LAN range.</returns>
|
||||
|
@ -192,9 +192,9 @@ namespace MediaBrowser.Common.Net
|
|||
/// Parses an array of strings into a Collection{IPObject}.
|
||||
/// </summary>
|
||||
/// <param name="values">Values to parse.</param>
|
||||
/// <param name="bracketed">When true, only include values in []. When false, ignore bracketed values.</param>
|
||||
/// <param name="negated">When true, only include values beginning with !. When false, ignore ! values.</param>
|
||||
/// <returns>IPCollection object containing the value strings.</returns>
|
||||
Collection<IPObject> CreateIPCollection(string[] values, bool bracketed = false);
|
||||
Collection<IPObject> CreateIPCollection(string[] values, bool negated = false);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all the internal Bind interface addresses.
|
||||
|
|
|
@ -135,6 +135,7 @@ namespace Jellyfin.Networking.Tests
|
|||
[InlineData("127.0.0.1#")]
|
||||
[InlineData("localhost!")]
|
||||
[InlineData("fd23:184f:2029:0:3139:7386:67d7:d517:1231")]
|
||||
[InlineData("[fd23:184f:2029:0:3139:7386:67d7:d517:1231]")]
|
||||
public void InvalidAddressString(string address)
|
||||
{
|
||||
Assert.False(TryParse(address, out _));
|
||||
|
@ -157,7 +158,7 @@ namespace Jellyfin.Networking.Tests
|
|||
"[]",
|
||||
"[]",
|
||||
"[]")]
|
||||
[InlineData("[127.0.0.1]",
|
||||
[InlineData("!127.0.0.1",
|
||||
"[]",
|
||||
"[]",
|
||||
"[127.0.0.1/32]",
|
||||
|
@ -169,18 +170,19 @@ namespace Jellyfin.Networking.Tests
|
|||
"[]",
|
||||
"[]",
|
||||
"[]")]
|
||||
[InlineData(
|
||||
"192.158.1.2/16, localhost, fd23:184f:2029:0:3139:7386:67d7:d517, !10.10.10.10",
|
||||
"[192.158.1.2/16,127.0.0.1/32,fd23:184f:2029:0:3139:7386:67d7:d517/128]",
|
||||
"[192.158.1.2/16,127.0.0.1/32]",
|
||||
"[10.10.10.10/32]",
|
||||
"[10.10.10.10/32]",
|
||||
"[192.158.0.0/16,127.0.0.1/32,fd23:184f:2029:0:3139:7386:67d7:d517/128]")]
|
||||
[InlineData("192.158.1.2/255.255.0.0,192.169.1.2/8",
|
||||
"[192.158.1.2/16,192.169.1.2/8]",
|
||||
"[192.158.1.2/16,192.169.1.2/8]",
|
||||
"[]",
|
||||
"[]",
|
||||
"[192.158.0.0/16,192.0.0.0/8]")]
|
||||
[InlineData("192.158.1.2/16, localhost, fd23:184f:2029:0:3139:7386:67d7:d517, [10.10.10.10]",
|
||||
"[192.158.1.2/16,127.0.0.1/32,fd23:184f:2029:0:3139:7386:67d7:d517/128]",
|
||||
"[192.158.1.2/16,127.0.0.1/32]",
|
||||
"[10.10.10.10/32]",
|
||||
"[10.10.10.10/32]",
|
||||
"[192.158.0.0/16,127.0.0.1/32,fd23:184f:2029:0:3139:7386:67d7:d517/128]")]
|
||||
public void TestCollections(string settings, string result1, string result2, string result3, string result4, string result5)
|
||||
{
|
||||
if (settings == null)
|
||||
|
|
Loading…
Reference in New Issue
Block a user