Skip to content

Commit ab92306

Browse files
fix(vpn): handle sending nil router config (coder#16267)
Previously, a `nil` Router config would cause a panic in the dylib. Normally, a nil Router config would indicate a shutdown of the service, and that settings should be reset. However, for Coder Desktop macOS the network configuration will be reset by the disconnecting of the system VPN, so we'll instead do nothing.
1 parent 76adde9 commit ab92306

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

vpn/router.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ func (*vpnRouter) Up() error {
2222
}
2323

2424
func (v *vpnRouter) Set(cfg *router.Config) error {
25-
req := convertRouterConfig(cfg)
25+
if cfg == nil {
26+
return nil
27+
}
28+
req := convertRouterConfig(*cfg)
2629
return v.tunnel.ApplyNetworkSettings(v.tunnel.ctx, req)
2730
}
2831

@@ -31,7 +34,7 @@ func (*vpnRouter) Close() error {
3134
return nil
3235
}
3336

34-
func convertRouterConfig(cfg *router.Config) *NetworkSettingsRequest {
37+
func convertRouterConfig(cfg router.Config) *NetworkSettingsRequest {
3538
v4LocalAddrs := make([]string, 0)
3639
v6LocalAddrs := make([]string, 0)
3740
for _, addrs := range cfg.LocalAddrs {

vpn/router_internal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ func TestConvertRouterConfig(t *testing.T) {
1313

1414
tests := []struct {
1515
name string
16-
cfg *router.Config
16+
cfg router.Config
1717
expected *NetworkSettingsRequest
1818
}{
1919
{
2020
name: "IPv4 and IPv6 configuration",
21-
cfg: &router.Config{
21+
cfg: router.Config{
2222
LocalAddrs: []netip.Prefix{netip.MustParsePrefix("100.64.0.1/32"), netip.MustParsePrefix("fd7a:115c:a1e0::1/128")},
2323
Routes: []netip.Prefix{netip.MustParsePrefix("192.168.0.0/24"), netip.MustParsePrefix("fd00::/64")},
2424
LocalRoutes: []netip.Prefix{netip.MustParsePrefix("10.0.0.0/8"), netip.MustParsePrefix("2001:db8::/32")},
@@ -48,7 +48,7 @@ func TestConvertRouterConfig(t *testing.T) {
4848
},
4949
{
5050
name: "Empty",
51-
cfg: &router.Config{},
51+
cfg: router.Config{},
5252
expected: &NetworkSettingsRequest{
5353
Ipv4Settings: &NetworkSettingsRequest_IPv4Settings{
5454
Addrs: []string{},

0 commit comments

Comments
 (0)