mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-25 10:41:14 +00:00
cmd/derper: randomize IPs on refreshBootstrapDNS (#7440)
This is to address a possible DNS failure on startup. Before this change IPv6 addresses would be listed first, and the client dialer would fail for hosts without IPv6 connectivity.
This commit is contained in:
parent
27575cd52d
commit
d92ef4c215
@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"expvar"
|
"expvar"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@ -52,6 +53,13 @@ func refreshBootstrapDNS() {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), refreshTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), refreshTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
dnsEntries := resolveList(ctx, strings.Split(*bootstrapDNS, ","))
|
dnsEntries := resolveList(ctx, strings.Split(*bootstrapDNS, ","))
|
||||||
|
// Randomize the order of the IPs for each name to avoid the client biasing
|
||||||
|
// to IPv6
|
||||||
|
for k := range dnsEntries {
|
||||||
|
ips := dnsEntries[k]
|
||||||
|
rand.Shuffle(len(ips), func(i, j int) { ips[i], ips[j] = ips[j], ips[i] })
|
||||||
|
dnsEntries[k] = ips
|
||||||
|
}
|
||||||
j, err := json.MarshalIndent(dnsEntries, "", "\t")
|
j, err := json.MarshalIndent(dnsEntries, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// leave the old values in place
|
// leave the old values in place
|
||||||
|
Loading…
x
Reference in New Issue
Block a user