Skip to content

Commit

Permalink
pkg/ipam: use slash as sysctl separator so interface name can have dot
Browse files Browse the repository at this point in the history
A dot is a valid character in interface names and is often used in the
names of VLAN interfaces. The sysctl net.ipv6.conf.<ifname>.disable_ipv6
key path cannot use dots both in the ifname and as path separator.
We switch to using / as key path separator so dots are allowed in the
ifname.

This works because sysctl.Sysctl() accepts key paths with either dots
or slashes as separators.

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 22, 2021
1 parent fa48f75 commit 9b09f16
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/ipam/ipam_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
)

const (
DisableIPv6SysctlTemplate = "net.ipv6.conf.%s.disable_ipv6"
// Note: use slash as separator so we can have dots in interface name (VLANs)
DisableIPv6SysctlTemplate = "net/ipv6/conf/%s/disable_ipv6"
)

// ConfigureIface takes the result of IPAM plugin and
Expand Down Expand Up @@ -68,8 +69,11 @@ func ConfigureIface(ifName string, res *current.Result) error {

// 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 9b09f16

Please sign in to comment.