diff options
| author | ZeusCraft10 <akhilachanta8@gmail.com> | 2025-12-30 17:31:40 -0500 |
|---|---|---|
| committer | ZeusCraft10 <akhilachanta8@gmail.com> | 2025-12-30 17:34:05 -0500 |
| commit | 72b4faa00b743dc5bbd2e25c54b216510e978a5a (patch) | |
| tree | 0ac0f91e191cac64844cd8867274c97f9e07e4f7 /src | |
| parent | d28ee6d71415b4c1f5c158f30f427b6952b8d65b (diff) | |
Fix UDP Auto-Discovery returning IPv6 for cross-subnet IPv4 requests
Fixes #15898
When a UDP discovery request is relayed from a different IPv4 subnet,
GetBindAddress() now correctly returns an IPv4 address instead of
incorrectly falling back to ::1.
Changes:
- Loopback fallback now prefers address family matching the source IP
- Interface fallback now prefers interfaces matching source address family
- Added test case for cross-subnet IPv4 request scenario
Diffstat (limited to 'src')
| -rw-r--r-- | src/Jellyfin.Networking/Manager/NetworkManager.cs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/Jellyfin.Networking/Manager/NetworkManager.cs b/src/Jellyfin.Networking/Manager/NetworkManager.cs index 126d9f15cf..10986b358f 100644 --- a/src/Jellyfin.Networking/Manager/NetworkManager.cs +++ b/src/Jellyfin.Networking/Manager/NetworkManager.cs @@ -875,7 +875,20 @@ public class NetworkManager : INetworkManager, IDisposable if (availableInterfaces.Count == 0) { // There isn't any others, so we'll use the loopback. - result = IsIPv4Enabled && !IsIPv6Enabled ? "127.0.0.1" : "::1"; + // Prefer loopback address matching the source's address family + if (source is not null && source.AddressFamily == AddressFamily.InterNetwork && IsIPv4Enabled) + { + result = "127.0.0.1"; + } + else if (source is not null && source.AddressFamily == AddressFamily.InterNetworkV6 && IsIPv6Enabled) + { + result = "::1"; + } + else + { + result = IsIPv4Enabled ? "127.0.0.1" : "::1"; + } + _logger.LogWarning("{Source}: Only loopback {Result} returned, using that as bind address.", source, result); return result; } @@ -900,9 +913,19 @@ public class NetworkManager : INetworkManager, IDisposable } } - // Fallback to first available interface + // Fallback to an interface matching the source's address family, or first available + var preferredInterface = availableInterfaces + .FirstOrDefault(x => x.Address.AddressFamily == source.AddressFamily); + + if (preferredInterface is not null) + { + result = NetworkUtils.FormatIPString(preferredInterface.Address); + _logger.LogDebug("{Source}: No matching subnet found, using interface with matching address family: {Result}", source, result); + return result; + } + result = NetworkUtils.FormatIPString(availableInterfaces[0].Address); - _logger.LogDebug("{Source}: No matching interfaces found, using preferred interface as bind address: {Result}", source, result); + _logger.LogDebug("{Source}: No matching interfaces found, using first available interface as bind address: {Result}", source, result); return result; } |
