mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 10:47:35 +00:00
wgengine/magicsock: prefer IPv6 transport if roughly equivalent latency
Fixes #1566 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
e2b3d9aa5f
commit
c99f260e40
@ -3670,6 +3670,17 @@ func betterAddr(a, b addrLatency) bool {
|
|||||||
if a.IsZero() {
|
if a.IsZero() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if a.IP.Is6() && b.IP.Is4() {
|
||||||
|
// Prefer IPv6 for being a bit more robust, as long as
|
||||||
|
// the latencies are roughly equivalent.
|
||||||
|
if a.latency/10*9 < b.latency {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else if a.IP.Is4() && b.IP.Is6() {
|
||||||
|
if betterAddr(b, a) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
return a.latency < b.latency
|
return a.latency < b.latency
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1867,6 +1867,29 @@ func TestBetterAddr(t *testing.T) {
|
|||||||
{a: zero, b: al("10.0.0.2:123", 5*ms), want: false},
|
{a: zero, b: al("10.0.0.2:123", 5*ms), want: false},
|
||||||
{a: al("10.0.0.2:123", 5*ms), b: al("1.2.3.4:555", 6*ms), want: true},
|
{a: al("10.0.0.2:123", 5*ms), b: al("1.2.3.4:555", 6*ms), want: true},
|
||||||
{a: al("10.0.0.2:123", 5*ms), b: al("10.0.0.2:123", 10*ms), want: false}, // same IPPort
|
{a: al("10.0.0.2:123", 5*ms), b: al("10.0.0.2:123", 10*ms), want: false}, // same IPPort
|
||||||
|
|
||||||
|
// Prefer IPv6 if roughly equivalent:
|
||||||
|
{
|
||||||
|
a: al("[2001::5]:123", 100*ms),
|
||||||
|
b: al("1.2.3.4:555", 91*ms),
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: al("1.2.3.4:555", 91*ms),
|
||||||
|
b: al("[2001::5]:123", 100*ms),
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
// But not if IPv4 is much faster:
|
||||||
|
{
|
||||||
|
a: al("[2001::5]:123", 100*ms),
|
||||||
|
b: al("1.2.3.4:555", 30*ms),
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: al("1.2.3.4:555", 30*ms),
|
||||||
|
b: al("[2001::5]:123", 100*ms),
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
got := betterAddr(tt.a, tt.b)
|
got := betterAddr(tt.a, tt.b)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user