Skip to content

Commit

Permalink
cni: update MCS-blocking code to do both IPv4 and IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
danwinship committed Apr 22, 2020
1 parent e1098d4 commit 32c7e4b
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions go-controller/pkg/cni/helper_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/vishvananda/netlink"

"k8s.io/apimachinery/pkg/util/wait"
utilnet "k8s.io/utils/net"
)

func renameLink(curName, newName string) error {
Expand Down Expand Up @@ -308,15 +309,39 @@ func (pr *PodRequest) ConfigureInterface(namespace string, podName string, ifInf
}
}

// Block access to certain things
err = netns.Do(func(hostNS ns.NetNS) error {
// Block access to certain things
var hasIPv4, hasIPv6 bool
for _, ip := range ifInfo.IPs {
if utilnet.IsIPv6CIDR(ip) {
hasIPv6 = true
} else {
hasIPv4 = true
}
}

for _, args := range iptablesCommands {
out, err := exec.Command("iptables", args...).CombinedOutput()
if err != nil {
return fmt.Errorf("could not set up pod iptables rules: %s", string(out))
if hasIPv4 {
out, err := exec.Command("iptables", args...).CombinedOutput()
if err != nil {
return fmt.Errorf("could not set up pod iptables rules: %s", string(out))
}
}
if hasIPv6 {
out, err := exec.Command("ip6tables", args...).CombinedOutput()
if err != nil {
return fmt.Errorf("could not set up pod iptables rules: %s", string(out))
}
}
}

return nil
})
if err != nil {
return nil, err
}

err = netns.Do(func(hostNS ns.NetNS) error {
if _, err := os.Stat("/proc/sys/net/ipv6/conf/all/dad_transmits"); !os.IsNotExist(err) {
err = setSysctl("/proc/sys/net/ipv6/conf/all/dad_transmits", 0)
if err != nil {
Expand Down

0 comments on commit 32c7e4b

Please sign in to comment.