@@ -11,28 +11,38 @@ import (
1111 "github.com/containernetworking/plugins/pkg/utils/sysctl"
1212)
1313
14+ var ipv6SysctlSettings = []struct {
15+ key string
16+ value string
17+ }{
18+ {"disable_ipv6" , "0" },
19+ {"accept_ra" , "0" },
20+ }
21+
1422// For docker version >=17.x the "none" network will disable ipv6 by default.
1523// We have to enable ipv6 here to add v6 address and gateway.
1624// See https://github.com/containernetworking/cni/issues/531
1725func sysctlEnableIPv6 (nsPath string ) error {
1826 return ns .WithNetNSPath (nsPath , func (_ ns.NetNS ) error {
1927 for _ , conf := range [... ]string {"all" , "default" } {
20- name := fmt .Sprintf ("net.ipv6.conf.%s.disable_ipv6" , conf )
21- value , err := sysctl .Sysctl (name )
22- if err != nil {
23- if os .IsNotExist (err ) {
24- // The sysctl variable doesn't exist, so we can't set it
25- continue
26- }
27- return fmt .Errorf ("failed to get sysctl variable %s: %w" , name , err )
28- }
29- if value != "0" {
30- if _ , err = sysctl .Sysctl (name , "0" ); err != nil {
31- if os .IsPermission (err ) {
32- // We don't have permission to set the sysctl variable, so we can't set it
28+ for _ , settings := range ipv6SysctlSettings {
29+ name := fmt .Sprintf ("net.ipv6.conf.%s.%s" , conf , settings .key )
30+ value , err := sysctl .Sysctl (name )
31+ if err != nil {
32+ if os .IsNotExist (err ) {
33+ // The sysctl variable doesn't exist, so we can't set it
3334 continue
3435 }
35- return fmt .Errorf ("failed to set sysctl variable %s to 0: %w" , name , err )
36+ return fmt .Errorf ("failed to get sysctl variable %s: %w" , name , err )
37+ }
38+ if value != settings .value {
39+ if _ , err = sysctl .Sysctl (name , settings .value ); err != nil {
40+ if os .IsPermission (err ) {
41+ // We don't have permission to set the sysctl variable, so we can't set it
42+ continue
43+ }
44+ return fmt .Errorf ("failed to set sysctl variable %s to %s: %w" , name , settings .value , err )
45+ }
3646 }
3747 }
3848 }
0 commit comments