Skip to content

fix(vpn): send subnet masks and prefix lengths from router #16317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(vpn): send subnet masks and prefix lengths from router
  • Loading branch information
ethanndickson committed Jan 29, 2025
commit d53a4d800b54d73c48c65d87997e2dbf440bf611
33 changes: 25 additions & 8 deletions vpn/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ func (*vpnRouter) Close() error {

func convertRouterConfig(cfg router.Config) *NetworkSettingsRequest {
v4LocalAddrs := make([]string, 0)
v4SubnetMasks := make([]string, 0)
v6LocalAddrs := make([]string, 0)
v6PrefixLengths := make([]uint32, 0)
for _, addrs := range cfg.LocalAddrs {
if addrs.Addr().Is4() {
v4LocalAddrs = append(v4LocalAddrs, addrs.String())
v4LocalAddrs = append(v4LocalAddrs, addrs.Addr().String())
v4SubnetMasks = append(v4SubnetMasks, prefixToSubnetMask(addrs))
} else if addrs.Addr().Is6() {
v6LocalAddrs = append(v6LocalAddrs, addrs.String())
v6LocalAddrs = append(v6LocalAddrs, addrs.Addr().String())
v6PrefixLengths = append(v6PrefixLengths, uint32(addrs.Bits()))
} else {
continue
}
Expand Down Expand Up @@ -69,18 +73,31 @@ func convertRouterConfig(cfg router.Config) *NetworkSettingsRequest {
}
}

return &NetworkSettingsRequest{
Mtu: uint32(cfg.NewMTU),
Ipv4Settings: &NetworkSettingsRequest_IPv4Settings{
var v4Settings *NetworkSettingsRequest_IPv4Settings
if len(v4LocalAddrs) > 0 || len(v4Routes) > 0 || len(v4ExcludedRoutes) > 0 {
Copy link
Member Author

@ethanndickson ethanndickson Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS complains if you supply the V4 & v6 Settings types with all the fields empty, but they can be nil, so we'll send that instead.

v4Settings = &NetworkSettingsRequest_IPv4Settings{
Addrs: v4LocalAddrs,
SubnetMasks: v4SubnetMasks,
IncludedRoutes: v4Routes,
ExcludedRoutes: v4ExcludedRoutes,
},
Ipv6Settings: &NetworkSettingsRequest_IPv6Settings{
Router: "", // NA
}
}

var v6Settings *NetworkSettingsRequest_IPv6Settings
if len(v6LocalAddrs) > 0 || len(v6Routes) > 0 || len(v6ExcludedRoutes) > 0 {
v6Settings = &NetworkSettingsRequest_IPv6Settings{
Addrs: v6LocalAddrs,
PrefixLengths: v6PrefixLengths,
IncludedRoutes: v6Routes,
ExcludedRoutes: v6ExcludedRoutes,
},
}
}

return &NetworkSettingsRequest{
Mtu: uint32(cfg.NewMTU),
Ipv4Settings: v4Settings,
Ipv6Settings: v6Settings,
TunnelOverheadBytes: 0, // N/A
TunnelRemoteAddress: "", // N/A
}
Expand Down
8 changes: 2 additions & 6 deletions vpn/tunnel_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,8 @@ func TestUpdater_createPeerUpdate(t *testing.T) {
},
})
require.Len(t, update.UpsertedAgents, 1)
slices.SortFunc(update.UpsertedAgents[0].Fqdn, func(a, b string) int {
return strings.Compare(a, b)
})
slices.SortFunc(update.DeletedAgents[0].Fqdn, func(a, b string) int {
return strings.Compare(a, b)
})
slices.SortFunc(update.UpsertedAgents[0].Fqdn, strings.Compare)
slices.SortFunc(update.DeletedAgents[0].Fqdn, strings.Compare)
require.Equal(t, update, &PeerUpdate{
UpsertedWorkspaces: []*Workspace{
{Id: w1ID[:], Name: "w1", Status: Workspace_Status(proto.Workspace_STARTING)},
Expand Down
Loading