Skip to content

fix(vpn): handle sending nil router config #16267

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 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions vpn/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func (*vpnRouter) Up() error {
}

func (v *vpnRouter) Set(cfg *router.Config) error {
req := convertRouterConfig(cfg)
if cfg == nil {
return nil
}
req := convertRouterConfig(*cfg)
return v.tunnel.ApplyNetworkSettings(v.tunnel.ctx, req)
}

Expand All @@ -31,7 +34,7 @@ func (*vpnRouter) Close() error {
return nil
}

func convertRouterConfig(cfg *router.Config) *NetworkSettingsRequest {
func convertRouterConfig(cfg router.Config) *NetworkSettingsRequest {
v4LocalAddrs := make([]string, 0)
v6LocalAddrs := make([]string, 0)
for _, addrs := range cfg.LocalAddrs {
Expand Down
6 changes: 3 additions & 3 deletions vpn/router_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func TestConvertRouterConfig(t *testing.T) {

tests := []struct {
name string
cfg *router.Config
cfg router.Config
expected *NetworkSettingsRequest
}{
{
name: "IPv4 and IPv6 configuration",
cfg: &router.Config{
cfg: router.Config{
LocalAddrs: []netip.Prefix{netip.MustParsePrefix("100.64.0.1/32"), netip.MustParsePrefix("fd7a:115c:a1e0::1/128")},
Routes: []netip.Prefix{netip.MustParsePrefix("192.168.0.0/24"), netip.MustParsePrefix("fd00::/64")},
LocalRoutes: []netip.Prefix{netip.MustParsePrefix("10.0.0.0/8"), netip.MustParsePrefix("2001:db8::/32")},
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestConvertRouterConfig(t *testing.T) {
},
{
name: "Empty",
cfg: &router.Config{},
cfg: router.Config{},
expected: &NetworkSettingsRequest{
Ipv4Settings: &NetworkSettingsRequest_IPv4Settings{
Addrs: []string{},
Expand Down
Loading