From 4d89a095ed1aea7804193de985bba65f2db25926 Mon Sep 17 00:00:00 2001 From: Tim Eisele Date: Mon, 27 Jan 2025 10:54:20 +0100 Subject: [PATCH 1/2] Fix interface ordering again --- src/Jellyfin.Networking/Manager/NetworkManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jellyfin.Networking/Manager/NetworkManager.cs b/src/Jellyfin.Networking/Manager/NetworkManager.cs index b777062129..d5328a3899 100644 --- a/src/Jellyfin.Networking/Manager/NetworkManager.cs +++ b/src/Jellyfin.Networking/Manager/NetworkManager.cs @@ -1065,7 +1065,7 @@ public class NetworkManager : INetworkManager, IDisposable // Check to see if any of the external bind interfaces are in the same subnet as the source. // If none exists, this will select the first external interface if there is one. bindAddress = externalInterfaces - .OrderBy(x => x.Subnet.Contains(source)) + .OrderByDescending(x => x.Subnet.Contains(source)) .ThenBy(x => x.Index) .Select(x => x.Address) .First(); @@ -1082,7 +1082,7 @@ public class NetworkManager : INetworkManager, IDisposable // Check to see if any of the internal bind interfaces are in the same subnet as the source. // If none exists, this will select the first internal interface if there is one. bindAddress = _interfaces.Where(x => IsInLocalNetwork(x.Address)) - .OrderBy(x => x.Subnet.Contains(source)) + .OrderByDescending(x => x.Subnet.Contains(source)) .ThenBy(x => x.Index) .Select(x => x.Address) .FirstOrDefault(); From e6c6441abf687d3438be0272d95d2f9cca3ffb29 Mon Sep 17 00:00:00 2001 From: Tim Eisele Date: Mon, 27 Jan 2025 10:59:27 +0100 Subject: [PATCH 2/2] Take subnet size into account --- src/Jellyfin.Networking/Manager/NetworkManager.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Jellyfin.Networking/Manager/NetworkManager.cs b/src/Jellyfin.Networking/Manager/NetworkManager.cs index d5328a3899..e7f097466d 100644 --- a/src/Jellyfin.Networking/Manager/NetworkManager.cs +++ b/src/Jellyfin.Networking/Manager/NetworkManager.cs @@ -1066,6 +1066,7 @@ public class NetworkManager : INetworkManager, IDisposable // If none exists, this will select the first external interface if there is one. bindAddress = externalInterfaces .OrderByDescending(x => x.Subnet.Contains(source)) + .ThenByDescending(x => x.Subnet.PrefixLength) .ThenBy(x => x.Index) .Select(x => x.Address) .First(); @@ -1083,6 +1084,7 @@ public class NetworkManager : INetworkManager, IDisposable // If none exists, this will select the first internal interface if there is one. bindAddress = _interfaces.Where(x => IsInLocalNetwork(x.Address)) .OrderByDescending(x => x.Subnet.Contains(source)) + .ThenByDescending(x => x.Subnet.PrefixLength) .ThenBy(x => x.Index) .Select(x => x.Address) .FirstOrDefault();