Skip to content

Commit 6515fae

Browse files
Disable RA for interfaces created by CNI (#567)
1 parent 11f2d74 commit 6515fae

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

network/bridge_networkclient_linux.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ func (client *LinuxBridgeClient) CreateBridge() error {
3939
},
4040
}
4141

42-
return netlink.AddLink(&link)
42+
if err := netlink.AddLink(&link); err != nil {
43+
return err
44+
}
45+
46+
return epcommon.DisableRAForInterface(client.bridgeName)
4347
}
4448

4549
func (client *LinuxBridgeClient) DeleteBridge() error {

network/epcommon/endpoint_common.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
enableIPForwardCmd = "sysctl -w net.ipv4.ip_forward=1"
3232
toggleIPV6Cmd = "sysctl -w net.ipv6.conf.all.disable_ipv6=%d"
3333
enableIPV6ForwardCmd = "sysctl -w net.ipv6.conf.all.forwarding=1"
34+
disableRACmd = "sysctl -w net.ipv6.conf.%s.accept_ra=0"
3435
)
3536

3637
func getPrivateIPSpace() []string {
@@ -71,6 +72,10 @@ func CreateEndpoint(hostVethName string, containerVethName string) error {
7172
return err
7273
}
7374

75+
if err := DisableRAForInterface(hostVethName); err != nil {
76+
return err
77+
}
78+
7479
return nil
7580
}
7681

@@ -87,6 +92,10 @@ func SetupContainerInterface(containerVethName string, targetIfName string) erro
8792
return err
8893
}
8994

95+
if err := DisableRAForInterface(targetIfName); err != nil {
96+
return err
97+
}
98+
9099
// Bring the interface back up.
91100
log.Printf("[net] Setting link %v state up.", targetIfName)
92101
return netlink.SetLinkState(targetIfName, true)
@@ -228,3 +237,13 @@ func AddSnatRule(match string, ip net.IP) error {
228237
target := fmt.Sprintf("SNAT --to %s", ip.String())
229238
return iptables.InsertIptableRule(version, iptables.Nat, iptables.Postrouting, match, target)
230239
}
240+
241+
func DisableRAForInterface(ifName string) error {
242+
cmd := fmt.Sprintf(disableRACmd, ifName)
243+
out, err := platform.ExecuteCommand(cmd)
244+
if err != nil {
245+
log.Errorf("[net] Diabling ra failed with err: %v out: %v", err, out)
246+
}
247+
248+
return err
249+
}

network/ovs_networkclient_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/Azure/azure-container-networking/log"
9+
"github.com/Azure/azure-container-networking/network/epcommon"
910
"github.com/Azure/azure-container-networking/ovsctl"
1011
)
1112

@@ -72,6 +73,10 @@ func (client *OVSNetworkClient) CreateBridge() error {
7273
}
7374
}()
7475

76+
if err := epcommon.DisableRAForInterface(client.bridgeName); err != nil {
77+
return err
78+
}
79+
7580
return updateOVSConfig(ovsOpt)
7681
}
7782

network/ovssnat/ovssnat.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ func CreateSnatBridge(snatBridgeIP string, mainInterface string) error {
342342
return nil
343343
}
344344

345+
if err := epcommon.DisableRAForInterface(SnatBridgeName); err != nil {
346+
return err
347+
}
348+
345349
vethLink := netlink.VEthLink{
346350
LinkInfo: netlink.LinkInfo{
347351
Type: netlink.LINK_TYPE_VETH,
@@ -356,6 +360,14 @@ func CreateSnatBridge(snatBridgeIP string, mainInterface string) error {
356360
return err
357361
}
358362

363+
if err := epcommon.DisableRAForInterface(azureSnatVeth0); err != nil {
364+
return err
365+
}
366+
367+
if err := epcommon.DisableRAForInterface(azureSnatVeth1); err != nil {
368+
return err
369+
}
370+
359371
log.Printf("Assigning %v on snat bridge", snatBridgeIP)
360372

361373
ip, addr, _ := net.ParseCIDR(snatBridgeIP)

0 commit comments

Comments
 (0)