Skip to content

Commit a658ccf

Browse files
fix(vpn): send subnet masks and prefix lengths from router (#16317)
These were somehow missed when I wrote the router.. Also updates `coder/tailscale` to bring in the DNS changes coder/tailscale#64
1 parent d32a5e1 commit a658ccf

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ replace github.com/tcnksm/go-httpstat => github.com/coder/go-httpstat v0.0.0-202
3636

3737
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
3838
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
39-
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20250121163848-c7962497b482
39+
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20250129014916-8086c871eae6
4040

4141
// This is replaced to include
4242
// 1. a fix for a data race: c.f. https://github.com/tailscale/wireguard-go/pull/25

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ github.com/coder/serpent v0.10.0 h1:ofVk9FJXSek+SmL3yVE3GoArP83M+1tX+H7S4t8BSuM=
240240
github.com/coder/serpent v0.10.0/go.mod h1:cZFW6/fP+kE9nd/oRkEHJpG6sXCtQ+AX7WMMEHv0Y3Q=
241241
github.com/coder/ssh v0.0.0-20231128192721-70855dedb788 h1:YoUSJ19E8AtuUFVYBpXuOD6a/zVP3rcxezNsoDseTUw=
242242
github.com/coder/ssh v0.0.0-20231128192721-70855dedb788/go.mod h1:aGQbuCLyhRLMzZF067xc84Lh7JDs1FKwCmF1Crl9dxQ=
243-
github.com/coder/tailscale v1.1.1-0.20250121163848-c7962497b482 h1:hCyBW9rsYwBmyAP+jnsmUnYC0dVlyLdOuMvyFpGOiIk=
244-
github.com/coder/tailscale v1.1.1-0.20250121163848-c7962497b482/go.mod h1:1ggFFdHTRjPRu9Yc1yA7nVHBYB50w9Ce7VIXNqcW6Ko=
243+
github.com/coder/tailscale v1.1.1-0.20250129014916-8086c871eae6 h1:prDIwUcsSEKbs1Rc5FfdvtSfz2XGpW3FnJtWR+Mc7MY=
244+
github.com/coder/tailscale v1.1.1-0.20250129014916-8086c871eae6/go.mod h1:1ggFFdHTRjPRu9Yc1yA7nVHBYB50w9Ce7VIXNqcW6Ko=
245245
github.com/coder/terraform-config-inspect v0.0.0-20250107175719-6d06d90c630e h1:JNLPDi2P73laR1oAclY6jWzAbucf70ASAvf5mh2cME0=
246246
github.com/coder/terraform-config-inspect v0.0.0-20250107175719-6d06d90c630e/go.mod h1:Gz/z9Hbn+4KSp8A2FBtNszfLSdT2Tn/uAKGuVqqWmDI=
247247
github.com/coder/terraform-provider-coder v1.0.4 h1:MJldCvykIQzzqBVUDjCJpPyqvKelAAHrtJKfIIx4Qxo=

vpn/router.go

+25-8
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ func (*vpnRouter) Close() error {
3636

3737
func convertRouterConfig(cfg router.Config) *NetworkSettingsRequest {
3838
v4LocalAddrs := make([]string, 0)
39+
v4SubnetMasks := make([]string, 0)
3940
v6LocalAddrs := make([]string, 0)
41+
v6PrefixLengths := make([]uint32, 0)
4042
for _, addrs := range cfg.LocalAddrs {
4143
if addrs.Addr().Is4() {
42-
v4LocalAddrs = append(v4LocalAddrs, addrs.String())
44+
v4LocalAddrs = append(v4LocalAddrs, addrs.Addr().String())
45+
v4SubnetMasks = append(v4SubnetMasks, prefixToSubnetMask(addrs))
4346
} else if addrs.Addr().Is6() {
44-
v6LocalAddrs = append(v6LocalAddrs, addrs.String())
47+
v6LocalAddrs = append(v6LocalAddrs, addrs.Addr().String())
48+
v6PrefixLengths = append(v6PrefixLengths, uint32(addrs.Bits()))
4549
} else {
4650
continue
4751
}
@@ -69,18 +73,31 @@ func convertRouterConfig(cfg router.Config) *NetworkSettingsRequest {
6973
}
7074
}
7175

72-
return &NetworkSettingsRequest{
73-
Mtu: uint32(cfg.NewMTU),
74-
Ipv4Settings: &NetworkSettingsRequest_IPv4Settings{
76+
var v4Settings *NetworkSettingsRequest_IPv4Settings
77+
if len(v4LocalAddrs) > 0 || len(v4Routes) > 0 || len(v4ExcludedRoutes) > 0 {
78+
v4Settings = &NetworkSettingsRequest_IPv4Settings{
7579
Addrs: v4LocalAddrs,
80+
SubnetMasks: v4SubnetMasks,
7681
IncludedRoutes: v4Routes,
7782
ExcludedRoutes: v4ExcludedRoutes,
78-
},
79-
Ipv6Settings: &NetworkSettingsRequest_IPv6Settings{
83+
Router: "", // NA
84+
}
85+
}
86+
87+
var v6Settings *NetworkSettingsRequest_IPv6Settings
88+
if len(v6LocalAddrs) > 0 || len(v6Routes) > 0 || len(v6ExcludedRoutes) > 0 {
89+
v6Settings = &NetworkSettingsRequest_IPv6Settings{
8090
Addrs: v6LocalAddrs,
91+
PrefixLengths: v6PrefixLengths,
8192
IncludedRoutes: v6Routes,
8293
ExcludedRoutes: v6ExcludedRoutes,
83-
},
94+
}
95+
}
96+
97+
return &NetworkSettingsRequest{
98+
Mtu: uint32(cfg.NewMTU),
99+
Ipv4Settings: v4Settings,
100+
Ipv6Settings: v6Settings,
84101
TunnelOverheadBytes: 0, // N/A
85102
TunnelRemoteAddress: "", // N/A
86103
}

vpn/router_internal_test.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ func TestConvertRouterConfig(t *testing.T) {
2727
expected: &NetworkSettingsRequest{
2828
Mtu: 1500,
2929
Ipv4Settings: &NetworkSettingsRequest_IPv4Settings{
30-
Addrs: []string{"100.64.0.1/32"},
30+
Addrs: []string{"100.64.0.1"},
31+
SubnetMasks: []string{"255.255.255.255"},
3132
IncludedRoutes: []*NetworkSettingsRequest_IPv4Settings_IPv4Route{
3233
{Destination: "192.168.0.0", Mask: "255.255.255.0", Router: ""},
3334
},
@@ -36,7 +37,8 @@ func TestConvertRouterConfig(t *testing.T) {
3637
},
3738
},
3839
Ipv6Settings: &NetworkSettingsRequest_IPv6Settings{
39-
Addrs: []string{"fd7a:115c:a1e0::1/128"},
40+
Addrs: []string{"fd7a:115c:a1e0::1"},
41+
PrefixLengths: []uint32{128},
4042
IncludedRoutes: []*NetworkSettingsRequest_IPv6Settings_IPv6Route{
4143
{Destination: "fd00::", PrefixLength: 64, Router: ""},
4244
},
@@ -50,16 +52,8 @@ func TestConvertRouterConfig(t *testing.T) {
5052
name: "Empty",
5153
cfg: router.Config{},
5254
expected: &NetworkSettingsRequest{
53-
Ipv4Settings: &NetworkSettingsRequest_IPv4Settings{
54-
Addrs: []string{},
55-
IncludedRoutes: []*NetworkSettingsRequest_IPv4Settings_IPv4Route{},
56-
ExcludedRoutes: []*NetworkSettingsRequest_IPv4Settings_IPv4Route{},
57-
},
58-
Ipv6Settings: &NetworkSettingsRequest_IPv6Settings{
59-
Addrs: []string{},
60-
IncludedRoutes: []*NetworkSettingsRequest_IPv6Settings_IPv6Route{},
61-
ExcludedRoutes: []*NetworkSettingsRequest_IPv6Settings_IPv6Route{},
62-
},
55+
Ipv4Settings: nil,
56+
Ipv6Settings: nil,
6357
},
6458
},
6559
}

vpn/tunnel_internal_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,8 @@ func TestUpdater_createPeerUpdate(t *testing.T) {
317317
},
318318
})
319319
require.Len(t, update.UpsertedAgents, 1)
320-
slices.SortFunc(update.UpsertedAgents[0].Fqdn, func(a, b string) int {
321-
return strings.Compare(a, b)
322-
})
323-
slices.SortFunc(update.DeletedAgents[0].Fqdn, func(a, b string) int {
324-
return strings.Compare(a, b)
325-
})
320+
slices.SortFunc(update.UpsertedAgents[0].Fqdn, strings.Compare)
321+
slices.SortFunc(update.DeletedAgents[0].Fqdn, strings.Compare)
326322
require.Equal(t, update, &PeerUpdate{
327323
UpsertedWorkspaces: []*Workspace{
328324
{Id: w1ID[:], Name: "w1", Status: Workspace_Status(proto.Workspace_STARTING)},

0 commit comments

Comments
 (0)