-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: zhangzujian <[email protected]>
- Loading branch information
1 parent
b197ad3
commit f1edf65
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |