Skip to content

Commit ecf67b4

Browse files
committed
Set NO_FLOOD to IPsec tunnel ports
Set NO_FLOOD to IPsec tunnel ports to avoid ARP flooding. Signed-off-by: Xu Liu <xliu2@vmware.com>
1 parent a63314f commit ecf67b4

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

cmd/antrea-agent/agent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ func run(o *Options) error {
278278
k8sClient,
279279
informerFactory,
280280
ofClient,
281+
ovsctl.NewClient(o.config.OVSBridge),
281282
ovsBridgeClient,
282283
routeClient,
283284
ifaceStore,

pkg/agent/controller/noderoute/node_route_controller.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"antrea.io/antrea/pkg/agent/util"
4141
"antrea.io/antrea/pkg/agent/wireguard"
4242
"antrea.io/antrea/pkg/ovs/ovsconfig"
43+
"antrea.io/antrea/pkg/ovs/ovsctl"
4344
utilip "antrea.io/antrea/pkg/util/ip"
4445
"antrea.io/antrea/pkg/util/k8s"
4546
"antrea.io/antrea/pkg/util/runtime"
@@ -65,6 +66,7 @@ type Controller struct {
6566
kubeClient clientset.Interface
6667
ovsBridgeClient ovsconfig.OVSBridgeClient
6768
ofClient openflow.Client
69+
ovsCtlClient ovsctl.OVSCtlClient
6870
routeClient route.Interface
6971
interfaceStore interfacestore.InterfaceStore
7072
networkConfig *config.NetworkConfig
@@ -92,6 +94,7 @@ func NewNodeRouteController(
9294
kubeClient clientset.Interface,
9395
informerFactory informers.SharedInformerFactory,
9496
client openflow.Client,
97+
ovsCtlClient ovsctl.OVSCtlClient,
9598
ovsBridgeClient ovsconfig.OVSBridgeClient,
9699
routeClient route.Interface,
97100
interfaceStore interfacestore.InterfaceStore,
@@ -107,6 +110,7 @@ func NewNodeRouteController(
107110
kubeClient: kubeClient,
108111
ovsBridgeClient: ovsBridgeClient,
109112
ofClient: client,
113+
ovsCtlClient: ovsCtlClient,
110114
routeClient: routeClient,
111115
interfaceStore: interfaceStore,
112116
networkConfig: networkConfig,
@@ -671,11 +675,6 @@ func (c *Controller) createIPSecTunnelPort(nodeName string, nodeIP net.IP) (int3
671675
}
672676
c.interfaceStore.DeleteInterface(interfaceConfig)
673677
exists = false
674-
} else {
675-
if interfaceConfig.OFPort != 0 {
676-
klog.V(2).InfoS("Found cached IPsec tunnel interface", "node", nodeName, "interface", interfaceConfig.InterfaceName, "port", interfaceConfig.OFPort)
677-
return interfaceConfig.OFPort, nil
678-
}
679678
}
680679
}
681680
if !exists {
@@ -715,6 +714,11 @@ func (c *Controller) createIPSecTunnelPort(nodeName string, nodeIP net.IP) (int3
715714
// Let NodeRouteController retry at errors.
716715
return 0, fmt.Errorf("failed to get of_port of IPsec tunnel port for Node %s", nodeName)
717716
}
717+
// Set the port with no-flood to reject ARP flood packets.
718+
if err := c.ovsCtlClient.SetPortNoFlood(int(ofPort)); err != nil {
719+
return 0, fmt.Errorf("failed to set port %s with no-flood config: %w", portName, err)
720+
}
721+
718722
interfaceConfig.OFPort = ofPort
719723
return ofPort, nil
720724
}

pkg/agent/controller/noderoute/node_route_controller_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"antrea.io/antrea/pkg/agent/util"
3636
"antrea.io/antrea/pkg/ovs/ovsconfig"
3737
ovsconfigtest "antrea.io/antrea/pkg/ovs/ovsconfig/testing"
38+
ovsctltest "antrea.io/antrea/pkg/ovs/ovsctl/testing"
3839
utilip "antrea.io/antrea/pkg/util/ip"
3940
)
4041

@@ -58,6 +59,7 @@ type fakeController struct {
5859
ovsClient *ovsconfigtest.MockOVSBridgeClient
5960
routeClient *routetest.MockInterface
6061
interfaceStore interfacestore.InterfaceStore
62+
ovsCtlClient *ovsctltest.MockOVSCtlClient
6163
}
6264

6365
type fakeIPsecCertificateManager struct{}
@@ -75,7 +77,9 @@ func newController(t *testing.T, networkConfig *config.NetworkConfig) (*fakeCont
7577
routeClient := routetest.NewMockInterface(ctrl)
7678
interfaceStore := interfacestore.NewInterfaceStore()
7779
ipsecCertificateManager := &fakeIPsecCertificateManager{}
78-
c := NewNodeRouteController(clientset, informerFactory, ofClient, ovsClient, routeClient, interfaceStore, networkConfig, &config.NodeConfig{GatewayConfig: &config.GatewayConfig{
80+
ovsCtlClient := ovsctltest.NewMockOVSCtlClient(ctrl)
81+
82+
c := NewNodeRouteController(clientset, informerFactory, ofClient, ovsCtlClient, ovsClient, routeClient, interfaceStore, networkConfig, &config.NodeConfig{GatewayConfig: &config.GatewayConfig{
7983
IPv4: nil,
8084
MAC: gatewayMAC,
8185
}}, nil, false, ipsecCertificateManager)
@@ -86,6 +90,7 @@ func newController(t *testing.T, networkConfig *config.NetworkConfig) (*fakeCont
8690
ofClient: ofClient,
8791
ovsClient: ovsClient,
8892
routeClient: routeClient,
93+
ovsCtlClient: ovsCtlClient,
8994
interfaceStore: interfaceStore,
9095
}, ctrl.Finish
9196
}
@@ -339,6 +344,7 @@ func TestCreateIPSecTunnelPortPSK(t *testing.T) {
339344

340345
node1PortName := util.GenerateNodeTunnelInterfaceName("xyz-k8s-0-1")
341346
node2PortName := util.GenerateNodeTunnelInterfaceName("xyz-k8s-0-2")
347+
node3PortName := util.GenerateNodeTunnelInterfaceName("xyz-k8s-0-3")
342348
c.ovsClient.EXPECT().CreateTunnelPortExt(
343349
node1PortName, ovsconfig.TunnelType("vxlan"), int32(0),
344350
false, "", nodeIP1.String(), "", "changeme", nil,
@@ -348,7 +354,11 @@ func TestCreateIPSecTunnelPortPSK(t *testing.T) {
348354
false, "", nodeIP2.String(), "", "changeme", nil,
349355
map[string]interface{}{ovsExternalIDNodeName: "xyz-k8s-0-2"}).Times(1)
350356
c.ovsClient.EXPECT().GetOFPort(node1PortName, false).Return(int32(1), nil)
357+
c.ovsCtlClient.EXPECT().SetPortNoFlood(1)
351358
c.ovsClient.EXPECT().GetOFPort(node2PortName, false).Return(int32(2), nil)
359+
c.ovsCtlClient.EXPECT().SetPortNoFlood(2)
360+
c.ovsClient.EXPECT().GetOFPort(node3PortName, false).Return(int32(5), nil)
361+
c.ovsCtlClient.EXPECT().SetPortNoFlood(5)
352362
c.ovsClient.EXPECT().DeletePort("123").Times(1)
353363

354364
tests := []struct {
@@ -407,6 +417,7 @@ func TestCreateIPSecTunnelPortCert(t *testing.T) {
407417
false, "", nodeIP1.String(), "xyz-k8s-0-1", "", nil,
408418
map[string]interface{}{ovsExternalIDNodeName: "xyz-k8s-0-1"}).Times(1)
409419
c.ovsClient.EXPECT().GetOFPort(node1PortName, false).Return(int32(1), nil)
420+
c.ovsCtlClient.EXPECT().SetPortNoFlood(1)
410421

411422
tests := []struct {
412423
name string

0 commit comments

Comments
 (0)