Merge pull request #113 from nyren/master
Explicitly enable IPv6 sysctl
This commit is contained in:
commit
dd8ff8a5cf
@ -21,10 +21,15 @@ import (
|
|||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types/current"
|
"github.com/containernetworking/cni/pkg/types/current"
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
|
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DisableIPv6SysctlTemplate = "net.ipv6.conf.%s.disable_ipv6"
|
||||||
|
)
|
||||||
|
|
||||||
// ConfigureIface takes the result of IPAM plugin and
|
// ConfigureIface takes the result of IPAM plugin and
|
||||||
// applies to the ifName interface
|
// applies to the ifName interface
|
||||||
func ConfigureIface(ifName string, res *current.Result) error {
|
func ConfigureIface(ifName string, res *current.Result) error {
|
||||||
@ -42,6 +47,7 @@ func ConfigureIface(ifName string, res *current.Result) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var v4gw, v6gw net.IP
|
var v4gw, v6gw net.IP
|
||||||
|
var has_enabled_ipv6 bool = false
|
||||||
for _, ipc := range res.IPs {
|
for _, ipc := range res.IPs {
|
||||||
if ipc.Interface == nil {
|
if ipc.Interface == nil {
|
||||||
continue
|
continue
|
||||||
@ -52,6 +58,30 @@ func ConfigureIface(ifName string, res *current.Result) error {
|
|||||||
return fmt.Errorf("failed to add IP addr %v to %q: invalid interface index", ipc, ifName)
|
return fmt.Errorf("failed to add IP addr %v to %q: invalid interface index", ipc, ifName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure sysctl "disable_ipv6" is 0 if we are about to add
|
||||||
|
// an IPv6 address to the interface
|
||||||
|
if !has_enabled_ipv6 && ipc.Version == "6" {
|
||||||
|
// Enabled IPv6 for loopback "lo" and the interface
|
||||||
|
// being configured
|
||||||
|
for _, iface := range [2]string{"lo", ifName} {
|
||||||
|
ipv6SysctlValueName := fmt.Sprintf(DisableIPv6SysctlTemplate, iface)
|
||||||
|
|
||||||
|
// Read current sysctl value
|
||||||
|
value, err := sysctl.Sysctl(ipv6SysctlValueName)
|
||||||
|
if err != nil || value == "0" {
|
||||||
|
// FIXME: log warning if unable to read sysctl value
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write sysctl to enable IPv6
|
||||||
|
_, err = sysctl.Sysctl(ipv6SysctlValueName, "0")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to enable IPv6 for interface %q (%s=%s): %v", iface, ipv6SysctlValueName, value, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
has_enabled_ipv6 = true
|
||||||
|
}
|
||||||
|
|
||||||
addr := &netlink.Addr{IPNet: &ipc.Address, Label: ""}
|
addr := &netlink.Addr{IPNet: &ipc.Address, Label: ""}
|
||||||
if err = netlink.AddrAdd(link, addr); err != nil {
|
if err = netlink.AddrAdd(link, addr); err != nil {
|
||||||
return fmt.Errorf("failed to add IP addr %v to %q: %v", ipc, ifName, err)
|
return fmt.Errorf("failed to add IP addr %v to %q: %v", ipc, ifName, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user