Skip to content

Commit

Permalink
cni: always enable ipv6
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed Aug 26, 2024
1 parent b197ad3 commit f1edf65
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func cmdAdd(args *skel.CmdArgs) error {
netConf.Provider = util.OvnProvider
}

if err = sysctlEnableIPv6(args.Netns); err != nil {
return err
}

client := request.NewCniServerClient(netConf.ServerSocket)
response, err := client.Add(request.CniRequest{
CniType: netConf.Type,
Expand Down
32 changes: 32 additions & 0 deletions cmd/cni/sysctl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build !windows
// +build !windows

package main

import (
"fmt"

"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/utils/sysctl"
)

// For docker version >=17.x the "none" network will disable ipv6 by default.
// We have to enable ipv6 here to add v6 address and gateway.
// See https://github.com/containernetworking/cni/issues/531
func sysctlEnableIPv6(nsPath string) error {
return ns.WithNetNSPath(nsPath, func(_ ns.NetNS) error {
for _, conf := range [...]string{"all", "default"} {
name := fmt.Sprintf("net.ipv6.conf.%s.disable_ipv6", conf)
value, err := sysctl.Sysctl(name)
if err != nil {
return fmt.Errorf("failed to get sysctl variable %s: %w", name, err)
}
if value != "0" {
if _, err = sysctl.Sysctl(name, "0"); err != nil {
return fmt.Errorf("failed to set sysctl variable %s to 0: %w", name, err)
}
}
}
return nil
})
}
6 changes: 6 additions & 0 deletions cmd/cni/sysctl_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

func sysctlEnableIPv6(nsPath string) error {
// nothing to do on Windows
return nil
}

0 comments on commit f1edf65

Please sign in to comment.