Skip to content

Commit

Permalink
Set net.ipv4.conf.antrea-gw0.arp_announce to 1
Browse files Browse the repository at this point in the history
Fix #5451
Set arp_announce to 1 on Linux platform to make the ARP requests from host to gateway
interface always use gateway IP as source IP. These ARP requests without gateway IP will
be dropped by ARP SpoofGuard flow.

Signed-off-by: gran <gran@vmware.com>
  • Loading branch information
gran-vmv committed Nov 3, 2023
1 parent e8f5d93 commit 2c59098
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
9 changes: 9 additions & 0 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,15 @@ func (i *Initializer) setupGatewayInterface() error {
if err := i.setInterfaceMTU(i.hostGateway, i.networkConfig.InterfaceMTU); err != nil {
return err
}
// Fix #5451
// Set arp_announce to 1 on Linux platform to make the ARP requests from host to gateway
// interface always use gateway IP as source IP. These ARP requests without gateway IP will
// be dropped by ARP SpoofGuard flow.
if i.nodeConfig.GatewayConfig.IPv4 != nil {
if err := setInterfaceARPAnnounce(gatewayIface.InterfaceName, 1); err != nil {
return err
}
}

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/agent/agent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ var (

// getAllIPNetsByName is meant to be overridden for testing.
getAllIPNetsByName = util.GetAllIPNetsByName

// setInterfaceARPAnnounce is meant to be overridden for testing.
setInterfaceARPAnnounce = util.EnsureARPAnnounceOnInterface
)

// prepareHostNetwork returns immediately on Linux.
Expand Down
9 changes: 9 additions & 0 deletions pkg/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ func TestSetupGatewayInterface(t *testing.T) {
mockSetLinkUp(t, fakeMAC, 10, nil)
mockConfigureLinkAddress(t, nil)
mockSetInterfaceMTU(t, nil)
mockSetInterfaceARPAnnounce(t, nil)

controller := mock.NewController(t)

Expand Down Expand Up @@ -694,6 +695,14 @@ func mockConfigureLinkAddress(t *testing.T, returnedErr error) {
t.Cleanup(func() { configureLinkAddresses = originalConfigureLinkAddresses })
}

func mockSetInterfaceARPAnnounce(t *testing.T, returnedErr error) {
originalSetInterfaceARPAnnounce := setInterfaceARPAnnounce
setInterfaceARPAnnounce = func(ifaceName string, value int) error {
return returnedErr
}
t.Cleanup(func() { setInterfaceARPAnnounce = originalSetInterfaceARPAnnounce })
}

func TestRestorePortConfigs(t *testing.T) {
tests := []struct {
name string
Expand Down
3 changes: 3 additions & 0 deletions pkg/agent/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import (
var (
// setInterfaceMTU is meant to be overridden for testing
setInterfaceMTU = util.SetInterfaceMTU

// setInterfaceARPAnnounce is meant to be overridden for testing.
setInterfaceARPAnnounce = func(ifaceName string, value int) error { return nil }
)

func (i *Initializer) prepareHostNetwork() error {
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/openflow/pod_connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func (f *featurePodConnectivity) initFlows() []*openflow15.FlowMod {
flows = append(flows, f.arpSpoofGuardFlow(f.gatewayIPs[ipProtocol], gatewayMAC, f.gatewayPort))
if f.connectUplinkToBridge {
flows = append(flows, f.arpResponderFlow(f.gatewayIPs[ipProtocol], gatewayMAC))
flows = append(flows, f.arpSpoofGuardFlow(f.nodeConfig.NodeIPv4Addr.IP, gatewayMAC, f.gatewayPort))
flows = append(flows, f.hostBridgeUplinkVLANFlows()...)
}
if runtime.IsWindowsPlatform() || f.connectUplinkToBridge {
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/openflow/pod_connectivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func podConnectivityInitFlows(trafficEncapMode config.TrafficEncapModeType, conn
flows = append(flows,
"cookie=0x1010000000000, table=ARPSpoofGuard, priority=210,arp,in_port=4 actions=NORMAL",
"cookie=0x1010000000000, table=ARPSpoofGuard, priority=210,arp,in_port=4294967294 actions=NORMAL",
"cookie=0x1010000000000, table=ARPSpoofGuard, priority=200,arp,in_port=2,arp_spa=192.168.77.100,arp_sha=0a:00:00:00:00:01 actions=goto_table:ARPResponder",
"cookie=0x1010000000000, table=ARPResponder, priority=200,arp,arp_tpa=10.10.0.1,arp_op=1 actions=move:NXM_OF_ETH_SRC[]->NXM_OF_ETH_DST[],set_field:0a:00:00:00:00:01->eth_src,set_field:2->arp_op,move:NXM_NX_ARP_SHA[]->NXM_NX_ARP_THA[],set_field:0a:00:00:00:00:01->arp_sha,move:NXM_OF_ARP_SPA[]->NXM_OF_ARP_TPA[],set_field:10.10.0.1->arp_spa,IN_PORT",
"cookie=0x1010000000000, table=Classifier, priority=200,in_port=4 actions=output:4294967294",
"cookie=0x1010000000000, table=Classifier, priority=200,in_port=4294967294 actions=output:4",
Expand Down
5 changes: 5 additions & 0 deletions pkg/agent/util/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ func EnsureIPv6EnabledOnInterface(ifaceName string) error {
return sysctl.EnsureSysctlNetValue(path, 0)
}

func EnsureARPAnnounceOnInterface(ifaceName string, value int) error {
path := fmt.Sprintf("ipv4/conf/%s/arp_announce", ifaceName)
return sysctl.EnsureSysctlNetValue(path, value)
}

func getRoutesOnInterface(linkIndex int) ([]interface{}, error) {
link, err := netlinkUtil.LinkByIndex(linkIndex)
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions test/integration/agent/openflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,12 +1304,6 @@ func prepareGatewayFlows(gwIPs []net.IP, gwMAC net.HardwareAddr, vMAC net.Hardwa
},
},
)
if connectUplinkToBridge {
flows[len(flows)-1].flows = append(flows[len(flows)-1].flows, &ofTestUtils.ExpectFlow{
MatchStr: fmt.Sprintf("priority=200,arp,in_port=%d,arp_spa=%s,arp_sha=%s", agentconfig.HostGatewayOFPort, nodeConfig.NodeIPv4Addr.IP.String(), gwMAC),
ActStr: "goto_table:ARPResponder",
})
}
} else {
ipProtoStr = "ipv6"
nwSrcStr = "ipv6_src"
Expand Down

0 comments on commit 2c59098

Please sign in to comment.