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
This commit is contained in:
ZeusCraft10
2025-12-30 17:31:40 -05:00
parent d28ee6d714
commit 72b4faa00b
3 changed files with 29 additions and 3 deletions

View File

@@ -377,6 +377,8 @@ namespace Jellyfin.Networking.Tests
[InlineData("192.168.1.208/24,-16,eth16|10.0.0.1/24,10,eth7", "192.168.1.0/24", "10.0.0.1", "192.168.1.209", "10.0.0.1")] // LAN not bound, so return external.
[InlineData("192.168.1.208/24,-16,eth16|10.0.0.1/24,10,eth7", "192.168.1.0/24", "192.168.1.208,10.0.0.1", "8.8.8.8", "10.0.0.1")] // return external bind address
[InlineData("192.168.1.208/24,-16,eth16|10.0.0.1/24,10,eth7", "192.168.1.0/24", "192.168.1.208,10.0.0.1", "192.168.1.210", "192.168.1.208")] // return LAN bind address
// Cross-subnet IPv4 request should return IPv4, not IPv6 (Issue #15898)
[InlineData("192.168.1.208/24,-16,eth16|fd00::1/64,10,eth7", "192.168.1.0/24", "", "192.168.2.100", "192.168.1.208")]
public void GetBindInterface_ValidSourceGiven_Success(string interfaces, string lan, string bind, string source, string result)
{
var conf = new NetworkConfiguration