Skip to content

Commit

Permalink
pkg/ipam: convert dots to slashes in interface names for sysctl
Browse files Browse the repository at this point in the history
Since the sysctl key syntax already uses the dot as separator, dots
in interface names that appear in sysctl keys, as is the case for
the net.ipv6.conf.<iface>.* entries, must be replaced by slashes.

Also, print error message to stderr in case sysctl cannot be read
instead of silently hiding the error.

Signed-off-by: David Verbeiren <[email protected]>
  • Loading branch information
dverbeir committed Feb 18, 2021
1 parent fa48f75 commit bcc9add
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/ipam/ipam_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"net"
"os"
"strings"

"github.com/containernetworking/cni/pkg/types/current"
"github.com/containernetworking/plugins/pkg/ip"
Expand Down Expand Up @@ -64,12 +65,16 @@ func ConfigureIface(ifName string, res *current.Result) error {
// Enabled IPv6 for loopback "lo" and the interface
// being configured
for _, iface := range [2]string{"lo", ifName} {
ipv6SysctlValueName := fmt.Sprintf(DisableIPv6SysctlTemplate, iface)
// Cannot have dots in interface name for sysctl, must replace by /
ipv6SysctlValueName := fmt.Sprintf(DisableIPv6SysctlTemplate, strings.ReplaceAll(iface, ".", "/"))

// Read current sysctl value
value, err := sysctl.Sysctl(ipv6SysctlValueName)
if err != nil || value == "0" {
// FIXME: log warning if unable to read sysctl value
if err != nil {
fmt.Fprintf(os.Stderr, "ipam_linux: failed to read sysctl %q: %v\n", ipv6SysctlValueName, err)
continue
}
if value == "0" {
continue
}

Expand Down

0 comments on commit bcc9add

Please sign in to comment.