From 5d1ecd804a31ec1c470234d68be2cfe43977ff9e Mon Sep 17 00:00:00 2001 From: Kaido Kert Date: Mon, 12 Aug 2024 19:10:34 -0700 Subject: [PATCH] Prioritize IPv4 addresses over IPv6 Changes the default RFC3484 address ordering to prefer IPv4 for current versions of Cobalt. This restores the behavior in prior Cobalt versions. b/359376180 --- net/dns/address_sorter_posix.cc | 6 ++++++ net/dns/address_sorter_posix_unittest.cc | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/net/dns/address_sorter_posix.cc b/net/dns/address_sorter_posix.cc index 0f4afb74871c..622d4da49bdd 100644 --- a/net/dns/address_sorter_posix.cc +++ b/net/dns/address_sorter_posix.cc @@ -140,7 +140,13 @@ const AddressSorterPosix::PolicyEntry kDefaultPrecedenceTable[] = { // ::/0 -- any {{}, 0, 40}, // ::ffff:0:0/96 -- IPv4 mapped +#if defined(STARBOARD) + // Cobalt currently prioritizes IPv4 addresses higher, as + // suggested in section 10.3 of RFC3484 + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}, 96, 100}, +#else {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}, 96, 35}, +#endif // 2002::/16 -- 6to4 {{ 0x20, diff --git a/net/dns/address_sorter_posix_unittest.cc b/net/dns/address_sorter_posix_unittest.cc index a4383aefc6a6..4d35ea5479c4 100644 --- a/net/dns/address_sorter_posix_unittest.cc +++ b/net/dns/address_sorter_posix_unittest.cc @@ -386,7 +386,11 @@ TEST_P(AddressSorterPosixSyncOrAsyncTest, Rule6) { AddMapping("2001::1", "2001::10"); // Teredo const char* const addresses[] = {"2001::1", "::ffff:1234:1", "ff32::1", "::1", nullptr}; +#if defined(STARBOARD) + const int order[] = { 1, 3, 2, 0, -1 }; +#else const int order[] = { 3, 2, 1, 0, -1 }; +#endif Verify(addresses, order); }