Move network constants to MediaBrowser.Common
This commit is contained in:
parent
fc694289a9
commit
223b156270
|
@ -5,7 +5,7 @@ using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Jellyfin.Extensions;
|
using Jellyfin.Extensions;
|
||||||
using Jellyfin.Networking.Constants;
|
using MediaBrowser.Common.Net;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
namespace Jellyfin.Networking.Extensions;
|
namespace Jellyfin.Networking.Extensions;
|
||||||
|
@ -59,7 +59,7 @@ public static partial class NetworkExtensions
|
||||||
/// <returns>String value of the subnet mask in dotted decimal notation.</returns>
|
/// <returns>String value of the subnet mask in dotted decimal notation.</returns>
|
||||||
public static IPAddress CidrToMask(byte cidr, AddressFamily family)
|
public static IPAddress CidrToMask(byte cidr, AddressFamily family)
|
||||||
{
|
{
|
||||||
uint addr = 0xFFFFFFFF << ((family == AddressFamily.InterNetwork ? Network.MinimumIPv4PrefixSize : Network.MinimumIPv6PrefixSize) - cidr);
|
uint addr = 0xFFFFFFFF << ((family == AddressFamily.InterNetwork ? NetworkConstants.MinimumIPv4PrefixSize : NetworkConstants.MinimumIPv6PrefixSize) - cidr);
|
||||||
addr = ((addr & 0xff000000) >> 24)
|
addr = ((addr & 0xff000000) >> 24)
|
||||||
| ((addr & 0x00ff0000) >> 8)
|
| ((addr & 0x00ff0000) >> 8)
|
||||||
| ((addr & 0x0000ff00) << 8)
|
| ((addr & 0x0000ff00) << 8)
|
||||||
|
@ -75,7 +75,7 @@ public static partial class NetworkExtensions
|
||||||
/// <returns>String value of the subnet mask in dotted decimal notation.</returns>
|
/// <returns>String value of the subnet mask in dotted decimal notation.</returns>
|
||||||
public static IPAddress CidrToMask(int cidr, AddressFamily family)
|
public static IPAddress CidrToMask(int cidr, AddressFamily family)
|
||||||
{
|
{
|
||||||
uint addr = 0xFFFFFFFF << ((family == AddressFamily.InterNetwork ? Network.MinimumIPv4PrefixSize : Network.MinimumIPv6PrefixSize) - cidr);
|
uint addr = 0xFFFFFFFF << ((family == AddressFamily.InterNetwork ? NetworkConstants.MinimumIPv4PrefixSize : NetworkConstants.MinimumIPv6PrefixSize) - cidr);
|
||||||
addr = ((addr & 0xff000000) >> 24)
|
addr = ((addr & 0xff000000) >> 24)
|
||||||
| ((addr & 0x00ff0000) >> 8)
|
| ((addr & 0x00ff0000) >> 8)
|
||||||
| ((addr & 0x0000ff00) << 8)
|
| ((addr & 0x0000ff00) << 8)
|
||||||
|
@ -100,7 +100,7 @@ public static partial class NetworkExtensions
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAddressBytes
|
// GetAddressBytes
|
||||||
Span<byte> bytes = stackalloc byte[mask.AddressFamily == AddressFamily.InterNetwork ? Network.IPv4MaskBytes : Network.IPv6MaskBytes];
|
Span<byte> bytes = stackalloc byte[mask.AddressFamily == AddressFamily.InterNetwork ? NetworkConstants.IPv4MaskBytes : NetworkConstants.IPv6MaskBytes];
|
||||||
if (!mask.TryWriteBytes(bytes, out var bytesWritten))
|
if (!mask.TryWriteBytes(bytes, out var bytesWritten))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Unable to write address bytes, only ${bytesWritten} bytes written.");
|
Console.WriteLine("Unable to write address bytes, only ${bytesWritten} bytes written.");
|
||||||
|
@ -230,12 +230,12 @@ public static partial class NetworkExtensions
|
||||||
}
|
}
|
||||||
else if (address.AddressFamily == AddressFamily.InterNetwork)
|
else if (address.AddressFamily == AddressFamily.InterNetwork)
|
||||||
{
|
{
|
||||||
result = address.Equals(IPAddress.Any) ? Network.IPv4Any : new IPNetwork(address, Network.MinimumIPv4PrefixSize);
|
result = address.Equals(IPAddress.Any) ? NetworkConstants.IPv4Any : new IPNetwork(address, NetworkConstants.MinimumIPv4PrefixSize);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (address.AddressFamily == AddressFamily.InterNetworkV6)
|
else if (address.AddressFamily == AddressFamily.InterNetworkV6)
|
||||||
{
|
{
|
||||||
result = address.Equals(IPAddress.IPv6Any) ? Network.IPv6Any : new IPNetwork(address, Network.MinimumIPv6PrefixSize);
|
result = address.Equals(IPAddress.IPv6Any) ? NetworkConstants.IPv6Any : new IPNetwork(address, NetworkConstants.MinimumIPv6PrefixSize);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ using System.Net.NetworkInformation;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Jellyfin.Networking.Configuration;
|
using Jellyfin.Networking.Configuration;
|
||||||
using Jellyfin.Networking.Constants;
|
|
||||||
using Jellyfin.Networking.Extensions;
|
using Jellyfin.Networking.Extensions;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
|
@ -289,12 +288,12 @@ namespace Jellyfin.Networking.Manager
|
||||||
|
|
||||||
if (IsIPv4Enabled)
|
if (IsIPv4Enabled)
|
||||||
{
|
{
|
||||||
interfaces.Add(new IPData(IPAddress.Loopback, Network.IPv4RFC5735Loopback, "lo"));
|
interfaces.Add(new IPData(IPAddress.Loopback, NetworkConstants.IPv4RFC5735Loopback, "lo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsIPv6Enabled)
|
if (IsIPv6Enabled)
|
||||||
{
|
{
|
||||||
interfaces.Add(new IPData(IPAddress.IPv6Loopback, Network.IPv6RFC4291Loopback, "lo"));
|
interfaces.Add(new IPData(IPAddress.IPv6Loopback, NetworkConstants.IPv6RFC4291Loopback, "lo"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,17 +325,17 @@ namespace Jellyfin.Networking.Manager
|
||||||
var fallbackLanSubnets = new List<IPNetwork>();
|
var fallbackLanSubnets = new List<IPNetwork>();
|
||||||
if (IsIPv6Enabled)
|
if (IsIPv6Enabled)
|
||||||
{
|
{
|
||||||
fallbackLanSubnets.Add(Network.IPv6RFC4291Loopback); // RFC 4291 (Loopback)
|
fallbackLanSubnets.Add(NetworkConstants.IPv6RFC4291Loopback); // RFC 4291 (Loopback)
|
||||||
fallbackLanSubnets.Add(Network.IPv6RFC4291SiteLocal); // RFC 4291 (Site local)
|
fallbackLanSubnets.Add(NetworkConstants.IPv6RFC4291SiteLocal); // RFC 4291 (Site local)
|
||||||
fallbackLanSubnets.Add(Network.IPv6RFC4193UniqueLocal); // RFC 4193 (Unique local)
|
fallbackLanSubnets.Add(NetworkConstants.IPv6RFC4193UniqueLocal); // RFC 4193 (Unique local)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsIPv4Enabled)
|
if (IsIPv4Enabled)
|
||||||
{
|
{
|
||||||
fallbackLanSubnets.Add(Network.IPv4RFC5735Loopback); // RFC 5735 (Loopback)
|
fallbackLanSubnets.Add(NetworkConstants.IPv4RFC5735Loopback); // RFC 5735 (Loopback)
|
||||||
fallbackLanSubnets.Add(Network.IPv4RFC1918PrivateClassA); // RFC 1918 (private Class A)
|
fallbackLanSubnets.Add(NetworkConstants.IPv4RFC1918PrivateClassA); // RFC 1918 (private Class A)
|
||||||
fallbackLanSubnets.Add(Network.IPv4RFC1918PrivateClassB); // RFC 1918 (private Class B)
|
fallbackLanSubnets.Add(NetworkConstants.IPv4RFC1918PrivateClassB); // RFC 1918 (private Class B)
|
||||||
fallbackLanSubnets.Add(Network.IPv4RFC1918PrivateClassC); // RFC 1918 (private Class C)
|
fallbackLanSubnets.Add(NetworkConstants.IPv4RFC1918PrivateClassC); // RFC 1918 (private Class C)
|
||||||
}
|
}
|
||||||
|
|
||||||
_lanSubnets = fallbackLanSubnets;
|
_lanSubnets = fallbackLanSubnets;
|
||||||
|
@ -375,12 +374,12 @@ namespace Jellyfin.Networking.Manager
|
||||||
|
|
||||||
if (bindAddresses.Contains(IPAddress.Loopback) && !interfaces.Any(i => i.Address.Equals(IPAddress.Loopback)))
|
if (bindAddresses.Contains(IPAddress.Loopback) && !interfaces.Any(i => i.Address.Equals(IPAddress.Loopback)))
|
||||||
{
|
{
|
||||||
interfaces.Add(new IPData(IPAddress.Loopback, Network.IPv4RFC5735Loopback, "lo"));
|
interfaces.Add(new IPData(IPAddress.Loopback, NetworkConstants.IPv4RFC5735Loopback, "lo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bindAddresses.Contains(IPAddress.IPv6Loopback) && !interfaces.Any(i => i.Address.Equals(IPAddress.IPv6Loopback)))
|
if (bindAddresses.Contains(IPAddress.IPv6Loopback) && !interfaces.Any(i => i.Address.Equals(IPAddress.IPv6Loopback)))
|
||||||
{
|
{
|
||||||
interfaces.Add(new IPData(IPAddress.IPv6Loopback, Network.IPv6RFC4291Loopback, "lo"));
|
interfaces.Add(new IPData(IPAddress.IPv6Loopback, NetworkConstants.IPv6RFC4291Loopback, "lo"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +441,7 @@ namespace Jellyfin.Networking.Manager
|
||||||
{
|
{
|
||||||
if (IPAddress.TryParse(ip, out var ipp))
|
if (IPAddress.TryParse(ip, out var ipp))
|
||||||
{
|
{
|
||||||
remoteAddressFilter.Add(new IPNetwork(ipp, ipp.AddressFamily == AddressFamily.InterNetwork ? Network.MinimumIPv4PrefixSize : Network.MinimumIPv6PrefixSize));
|
remoteAddressFilter.Add(new IPNetwork(ipp, ipp.AddressFamily == AddressFamily.InterNetwork ? NetworkConstants.MinimumIPv4PrefixSize : NetworkConstants.MinimumIPv6PrefixSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,13 +469,13 @@ namespace Jellyfin.Networking.Manager
|
||||||
{
|
{
|
||||||
publishedServerUrls.Add(
|
publishedServerUrls.Add(
|
||||||
new PublishedServerUriOverride(
|
new PublishedServerUriOverride(
|
||||||
new IPData(IPAddress.Any, Network.IPv4Any),
|
new IPData(IPAddress.Any, NetworkConstants.IPv4Any),
|
||||||
startupOverrideKey,
|
startupOverrideKey,
|
||||||
true,
|
true,
|
||||||
true));
|
true));
|
||||||
publishedServerUrls.Add(
|
publishedServerUrls.Add(
|
||||||
new PublishedServerUriOverride(
|
new PublishedServerUriOverride(
|
||||||
new IPData(IPAddress.IPv6Any, Network.IPv6Any),
|
new IPData(IPAddress.IPv6Any, NetworkConstants.IPv6Any),
|
||||||
startupOverrideKey,
|
startupOverrideKey,
|
||||||
true,
|
true,
|
||||||
true));
|
true));
|
||||||
|
@ -502,13 +501,13 @@ namespace Jellyfin.Networking.Manager
|
||||||
publishedServerUrls.Clear();
|
publishedServerUrls.Clear();
|
||||||
publishedServerUrls.Add(
|
publishedServerUrls.Add(
|
||||||
new PublishedServerUriOverride(
|
new PublishedServerUriOverride(
|
||||||
new IPData(IPAddress.Any, Network.IPv4Any),
|
new IPData(IPAddress.Any, NetworkConstants.IPv4Any),
|
||||||
replacement,
|
replacement,
|
||||||
true,
|
true,
|
||||||
true));
|
true));
|
||||||
publishedServerUrls.Add(
|
publishedServerUrls.Add(
|
||||||
new PublishedServerUriOverride(
|
new PublishedServerUriOverride(
|
||||||
new IPData(IPAddress.IPv6Any, Network.IPv6Any),
|
new IPData(IPAddress.IPv6Any, NetworkConstants.IPv6Any),
|
||||||
replacement,
|
replacement,
|
||||||
true,
|
true,
|
||||||
true));
|
true));
|
||||||
|
@ -518,13 +517,13 @@ namespace Jellyfin.Networking.Manager
|
||||||
{
|
{
|
||||||
publishedServerUrls.Add(
|
publishedServerUrls.Add(
|
||||||
new PublishedServerUriOverride(
|
new PublishedServerUriOverride(
|
||||||
new IPData(IPAddress.Any, Network.IPv4Any),
|
new IPData(IPAddress.Any, NetworkConstants.IPv4Any),
|
||||||
replacement,
|
replacement,
|
||||||
false,
|
false,
|
||||||
true));
|
true));
|
||||||
publishedServerUrls.Add(
|
publishedServerUrls.Add(
|
||||||
new PublishedServerUriOverride(
|
new PublishedServerUriOverride(
|
||||||
new IPData(IPAddress.IPv6Any, Network.IPv6Any),
|
new IPData(IPAddress.IPv6Any, NetworkConstants.IPv6Any),
|
||||||
replacement,
|
replacement,
|
||||||
false,
|
false,
|
||||||
true));
|
true));
|
||||||
|
@ -724,12 +723,12 @@ namespace Jellyfin.Networking.Manager
|
||||||
var loopbackNetworks = new List<IPData>();
|
var loopbackNetworks = new List<IPData>();
|
||||||
if (IsIPv4Enabled)
|
if (IsIPv4Enabled)
|
||||||
{
|
{
|
||||||
loopbackNetworks.Add(new IPData(IPAddress.Loopback, Network.IPv4RFC5735Loopback, "lo"));
|
loopbackNetworks.Add(new IPData(IPAddress.Loopback, NetworkConstants.IPv4RFC5735Loopback, "lo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsIPv6Enabled)
|
if (IsIPv6Enabled)
|
||||||
{
|
{
|
||||||
loopbackNetworks.Add(new IPData(IPAddress.IPv6Loopback, Network.IPv6RFC4291Loopback, "lo"));
|
loopbackNetworks.Add(new IPData(IPAddress.IPv6Loopback, NetworkConstants.IPv6RFC4291Loopback, "lo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return loopbackNetworks;
|
return loopbackNetworks;
|
||||||
|
@ -748,11 +747,11 @@ namespace Jellyfin.Networking.Manager
|
||||||
if (IsIPv4Enabled && IsIPv6Enabled)
|
if (IsIPv4Enabled && IsIPv6Enabled)
|
||||||
{
|
{
|
||||||
// Kestrel source code shows it uses Sockets.DualMode - so this also covers IPAddress.Any by default
|
// Kestrel source code shows it uses Sockets.DualMode - so this also covers IPAddress.Any by default
|
||||||
result.Add(new IPData(IPAddress.IPv6Any, Network.IPv6Any));
|
result.Add(new IPData(IPAddress.IPv6Any, NetworkConstants.IPv6Any));
|
||||||
}
|
}
|
||||||
else if (IsIPv4Enabled)
|
else if (IsIPv4Enabled)
|
||||||
{
|
{
|
||||||
result.Add(new IPData(IPAddress.Any, Network.IPv4Any));
|
result.Add(new IPData(IPAddress.Any, NetworkConstants.IPv4Any));
|
||||||
}
|
}
|
||||||
else if (IsIPv6Enabled)
|
else if (IsIPv6Enabled)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,10 +21,10 @@ using Jellyfin.Api.ModelBinders;
|
||||||
using Jellyfin.Data.Enums;
|
using Jellyfin.Data.Enums;
|
||||||
using Jellyfin.Extensions.Json;
|
using Jellyfin.Extensions.Json;
|
||||||
using Jellyfin.Networking.Configuration;
|
using Jellyfin.Networking.Configuration;
|
||||||
using Jellyfin.Networking.Constants;
|
|
||||||
using Jellyfin.Networking.Extensions;
|
using Jellyfin.Networking.Extensions;
|
||||||
using Jellyfin.Server.Configuration;
|
using Jellyfin.Server.Configuration;
|
||||||
using Jellyfin.Server.Filters;
|
using Jellyfin.Server.Filters;
|
||||||
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Session;
|
using MediaBrowser.Model.Session;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
@ -275,7 +275,7 @@ namespace Jellyfin.Server.Extensions
|
||||||
{
|
{
|
||||||
if (IPAddress.TryParse(allowedProxies[i], out var addr))
|
if (IPAddress.TryParse(allowedProxies[i], out var addr))
|
||||||
{
|
{
|
||||||
AddIPAddress(config, options, addr, addr.AddressFamily == AddressFamily.InterNetwork ? Network.MinimumIPv4PrefixSize : Network.MinimumIPv6PrefixSize);
|
AddIPAddress(config, options, addr, addr.AddressFamily == AddressFamily.InterNetwork ? NetworkConstants.MinimumIPv4PrefixSize : NetworkConstants.MinimumIPv6PrefixSize);
|
||||||
}
|
}
|
||||||
else if (NetworkExtensions.TryParseToSubnet(allowedProxies[i], out var subnet))
|
else if (NetworkExtensions.TryParseToSubnet(allowedProxies[i], out var subnet))
|
||||||
{
|
{
|
||||||
|
@ -288,7 +288,7 @@ namespace Jellyfin.Server.Extensions
|
||||||
{
|
{
|
||||||
foreach (var address in addresses)
|
foreach (var address in addresses)
|
||||||
{
|
{
|
||||||
AddIPAddress(config, options, address, address.AddressFamily == AddressFamily.InterNetwork ? Network.MinimumIPv4PrefixSize : Network.MinimumIPv6PrefixSize);
|
AddIPAddress(config, options, address, address.AddressFamily == AddressFamily.InterNetwork ? NetworkConstants.MinimumIPv4PrefixSize : NetworkConstants.MinimumIPv6PrefixSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ namespace Jellyfin.Server.Extensions
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefixLength == Network.MinimumIPv4PrefixSize)
|
if (prefixLength == NetworkConstants.MinimumIPv4PrefixSize)
|
||||||
{
|
{
|
||||||
options.KnownProxies.Add(addr);
|
options.KnownProxies.Add(addr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
namespace Jellyfin.Networking.Constants;
|
namespace MediaBrowser.Common.Net;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Networking constants.
|
/// Networking constants.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Network
|
public static class NetworkConstants
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IPv4 mask bytes.
|
/// IPv4 mask bytes.
|
Loading…
Reference in New Issue
Block a user