all: add Node.HomeDERP int, phase out "127.3.3.40:$region" hack [capver 111]

This deprecates the old "DERP string" packing a DERP region ID into an
IP:port of 127.3.3.40:$REGION_ID and just uses an integer, like
PeerChange.DERPRegion does.

We still support servers sending the old form; they're converted to
the new form internally right when they're read off the network.

Updates #14636

Change-Id: I9427ec071f02a2c6d75ccb0fcbf0ecff9f19f26f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2025-01-14 10:19:52 -08:00
committed by Brad Fitzpatrick
parent 66269dc934
commit 2fc4455e6d
19 changed files with 171 additions and 97 deletions

View File

@@ -287,11 +287,8 @@ func printPeerConcise(buf *strings.Builder, p tailcfg.NodeView) {
epStrs[i] = fmt.Sprintf("%21v", e+strings.Repeat(" ", spaces))
}
derp := p.DERP()
const derpPrefix = "127.3.3.40:"
if strings.HasPrefix(derp, derpPrefix) {
derp = "D" + derp[len(derpPrefix):]
}
derp := fmt.Sprintf("D%d", p.HomeDERP())
var discoShort string
if !p.DiscoKey().IsZero() {
discoShort = p.DiscoKey().ShortString() + " "
@@ -311,7 +308,7 @@ func printPeerConcise(buf *strings.Builder, p tailcfg.NodeView) {
// nodeConciseEqual reports whether a and b are equal for the fields accessed by printPeerConcise.
func nodeConciseEqual(a, b tailcfg.NodeView) bool {
return a.Key() == b.Key() &&
a.DERP() == b.DERP() &&
a.HomeDERP() == b.HomeDERP() &&
a.DiscoKey() == b.DiscoKey() &&
views.SliceEqual(a.AllowedIPs(), b.AllowedIPs()) &&
views.SliceEqual(a.Endpoints(), b.Endpoints())

View File

@@ -63,12 +63,12 @@ func TestNetworkMapConcise(t *testing.T) {
Peers: nodeViews([]*tailcfg.Node{
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
Key: testNodeKey(3),
DERP: "127.3.3.40:4",
HomeDERP: 4,
Endpoints: eps("10.2.0.100:12", "10.1.0.100:12345"),
},
}),
@@ -102,7 +102,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: nodeViews([]*tailcfg.Node{
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
@@ -112,7 +112,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: nodeViews([]*tailcfg.Node{
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
@@ -126,7 +126,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: nodeViews([]*tailcfg.Node{
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
@@ -136,7 +136,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: nodeViews([]*tailcfg.Node{
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
@@ -151,7 +151,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
@@ -162,19 +162,19 @@ func TestConciseDiffFrom(t *testing.T) {
{
ID: 1,
Key: testNodeKey(1),
DERP: "127.3.3.40:1",
HomeDERP: 1,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
ID: 3,
Key: testNodeKey(3),
DERP: "127.3.3.40:3",
HomeDERP: 3,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
@@ -189,19 +189,19 @@ func TestConciseDiffFrom(t *testing.T) {
{
ID: 1,
Key: testNodeKey(1),
DERP: "127.3.3.40:1",
HomeDERP: 1,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
ID: 3,
Key: testNodeKey(3),
DERP: "127.3.3.40:3",
HomeDERP: 3,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
@@ -212,7 +212,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
@@ -227,7 +227,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "1.1.1.1:1"),
},
}),
@@ -238,7 +238,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:12", "1.1.1.1:2"),
},
}),
@@ -253,7 +253,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:41641", "1.1.1.1:41641"),
DiscoKey: testDiscoKey("f00f00f00f"),
AllowedIPs: []netip.Prefix{netip.PrefixFrom(netaddr.IPv4(100, 102, 103, 104), 32)},
@@ -266,7 +266,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
HomeDERP: 2,
Endpoints: eps("192.168.0.100:41641", "1.1.1.1:41641"),
DiscoKey: testDiscoKey("ba4ba4ba4b"),
AllowedIPs: []netip.Prefix{netip.PrefixFrom(netaddr.IPv4(100, 102, 103, 104), 32)},

View File

@@ -5,7 +5,6 @@ package netmap
import (
"cmp"
"fmt"
"net/netip"
"reflect"
"slices"
@@ -35,7 +34,7 @@ type NodeMutationDERPHome struct {
}
func (m NodeMutationDERPHome) Apply(n *tailcfg.Node) {
n.DERP = fmt.Sprintf("127.3.3.40:%v", m.DERPRegion)
n.HomeDERP = m.DERPRegion
}
// NodeMutation is a NodeMutation that says a node's endpoints have changed.