fix(connlib): retain order of system/upstream DNS servers (#10773)

Right now, connlib hands out a `BiMap` of sentinel IPs <> upstream
servers whenever it emits a `TunInterfaceUpdated` event. This `BiMap`
internally uses two `HashMap`s. The iteration order of `HashMap`s is
non-deterministic and therefore, we lose the order in which the upstream
/ system resolvers have been passed to us originally.

To prevent that, we now emit a dedicated `DnsMapping` type that does not
expose its internal data structure but only getters for retrieving the
sentinel and upstream servers. Internally, it uses a `Vec` to store this
mapping and thus retains the original order. This is asserted as part of
our proptests by comparing the resulting `Vec`s.

This fix is preceded by a few refactorings that encapsulate the code for
creating and updating this DNS mapping.

Resolves: #8439
This commit is contained in:
Thomas Eizinger
2025-11-04 04:55:48 +11:00
committed by GitHub
parent 1b7313622a
commit 804ef7a3fb
13 changed files with 314 additions and 242 deletions

View File

@@ -495,7 +495,7 @@ impl<'a> Handler<'a> {
self.tun_device.set_ips(config.ip.v4, config.ip.v6).await?;
self.dns_controller
.set_dns(config.dns_sentinel_ips(), config.search_domain)
.set_dns(config.dns_by_sentinel.sentinel_ips(), config.search_domain)
.await?;
self.tun_device
.set_routes(config.ipv4_routes, config.ipv6_routes)