aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2023-07-03 13:16:21 -0400
committerGitHub <noreply@github.com>2023-07-03 13:16:21 -0400
commit93b400343ebd2ef92e740d804ceaaedb01da30cf (patch)
tree0190174ceb0df9c3bcd23647548d80be48425214 /Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
parent44cc3ee44286dd5b3a626df79a8a576ad4a0d34a (diff)
parente233a3b074d7696e4c05846aaf04434dafaf4031 (diff)
Merge pull request #8147 from Shadowghost/network-rewrite
Diffstat (limited to 'Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs')
-rw-r--r--Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs32
1 files changed, 18 insertions, 14 deletions
diff --git a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
index 9867c9e47..ea3c92011 100644
--- a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
+++ b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
@@ -99,7 +99,7 @@ namespace Jellyfin.Server.Extensions
}
/// <summary>
- /// Extension method for adding the jellyfin API to the service collection.
+ /// Extension method for adding the Jellyfin API to the service collection.
/// </summary>
/// <param name="serviceCollection">The service collection.</param>
/// <param name="pluginAssemblies">An IEnumerable containing all plugin assemblies with API controllers.</param>
@@ -260,7 +260,7 @@ namespace Jellyfin.Server.Extensions
}
/// <summary>
- /// Sets up the proxy configuration based on the addresses in <paramref name="allowedProxies"/>.
+ /// Sets up the proxy configuration based on the addresses/subnets in <paramref name="allowedProxies"/>.
/// </summary>
/// <param name="config">The <see cref="NetworkConfiguration"/> containing the config settings.</param>
/// <param name="allowedProxies">The string array to parse.</param>
@@ -269,33 +269,37 @@ namespace Jellyfin.Server.Extensions
{
for (var i = 0; i < allowedProxies.Length; i++)
{
- if (IPNetAddress.TryParse(allowedProxies[i], out var addr))
+ if (IPAddress.TryParse(allowedProxies[i], out var addr))
{
- AddIpAddress(config, options, addr.Address, addr.PrefixLength);
+ AddIPAddress(config, options, addr, addr.AddressFamily == AddressFamily.InterNetwork ? 32 : 128);
}
- else if (IPHost.TryParse(allowedProxies[i], out var host))
+ else if (NetworkExtensions.TryParseToSubnet(allowedProxies[i], out var subnet))
{
- foreach (var address in host.GetAddresses())
+ if (subnet != null)
{
- AddIpAddress(config, options, address, address.AddressFamily == AddressFamily.InterNetwork ? 32 : 128);
+ AddIPAddress(config, options, subnet.Prefix, subnet.PrefixLength);
+ }
+ }
+ else if (NetworkExtensions.TryParseHost(allowedProxies[i], out var addresses))
+ {
+ foreach (var address in addresses)
+ {
+ AddIPAddress(config, options, address, address.AddressFamily == AddressFamily.InterNetwork ? 32 : 128);
}
}
}
}
- private static void AddIpAddress(NetworkConfiguration config, ForwardedHeadersOptions options, IPAddress addr, int prefixLength)
+ private static void AddIPAddress(NetworkConfiguration config, ForwardedHeadersOptions options, IPAddress addr, int prefixLength)
{
- if ((!config.EnableIPV4 && addr.AddressFamily == AddressFamily.InterNetwork) || (!config.EnableIPV6 && addr.AddressFamily == AddressFamily.InterNetworkV6))
+ if ((!config.EnableIPv4 && addr.AddressFamily == AddressFamily.InterNetwork) || (!config.EnableIPv6 && addr.AddressFamily == AddressFamily.InterNetworkV6))
{
return;
}
- // In order for dual-mode sockets to be used, IP6 has to be enabled in JF and an interface has to have an IP6 address.
- if (addr.AddressFamily == AddressFamily.InterNetwork && config.EnableIPV6)
+ if (addr.IsIPv4MappedToIPv6)
{
- // If the server is using dual-mode sockets, IPv4 addresses are supplied in an IPv6 format.
- // https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-5.0 .
- addr = addr.MapToIPv6();
+ addr = addr.MapToIPv4();
}
if (prefixLength == 32)