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