From 483c3f31ee0aac34c1a2b4903ea3d54fca6a5f72 Mon Sep 17 00:00:00 2001 From: wenyingd Date: Tue, 22 Mar 2022 16:18:31 +0800 Subject: [PATCH] [Windows] Use uplink MAC as source if packet is output to uplink With noEncap mode the Pod packet to remote Pod/Node is output to the uplink interface directly. This change modifies the source MAC with the uplink interface's MAC, so that it doesn't require hybrid configurations on the host interface. Signed-off-by: wenyingd --- pkg/agent/agent_windows.go | 4 ++++ pkg/agent/openflow/pipeline.go | 1 + pkg/agent/openflow/pipeline_windows.go | 1 + 3 files changed, 6 insertions(+) diff --git a/pkg/agent/agent_windows.go b/pkg/agent/agent_windows.go index d17fd821779..3ecb469e307 100644 --- a/pkg/agent/agent_windows.go +++ b/pkg/agent/agent_windows.go @@ -43,6 +43,10 @@ func (i *Initializer) prepareHostNetwork() error { } // Save the uplink adapter name to check if the OVS uplink port has been created in prepareOVSBridge stage. i.nodeConfig.UplinkNetConfig.Name = hnsNetwork.NetworkAdapterName + + // Save the uplink adapter MAC to modify Pod traffic source MAC if the packet is directly output to the uplink + // interface in OVS pipeline. + i.nodeConfig.UplinkNetConfig.MAC, _ = net.ParseMAC(hnsNetwork.SourceMac) return nil } if _, ok := err.(hcsshim.NetworkNotFoundError); !ok { diff --git a/pkg/agent/openflow/pipeline.go b/pkg/agent/openflow/pipeline.go index e082b43b61d..449532a1980 100644 --- a/pkg/agent/openflow/pipeline.go +++ b/pkg/agent/openflow/pipeline.go @@ -1357,6 +1357,7 @@ func (f *featurePodConnectivity) l3FwdFlowToRemoteViaUplink(remoteGatewayMAC net MatchProtocol(ipProtocol). MatchRegMark(NotAntreaFlexibleIPAMRegMark). MatchDstIPNet(peerSubnet). + Action().SetSrcMAC(f.nodeConfig.UplinkNetConfig.MAC). Action().SetDstMAC(remoteGatewayMAC). Action().GotoTable(L3DecTTLTable.GetID()). Done() diff --git a/pkg/agent/openflow/pipeline_windows.go b/pkg/agent/openflow/pipeline_windows.go index 486911d26ae..59c6dbe54ac 100644 --- a/pkg/agent/openflow/pipeline_windows.go +++ b/pkg/agent/openflow/pipeline_windows.go @@ -85,6 +85,7 @@ func (f *featurePodConnectivity) l3FwdFlowToRemoteViaRouting(localGatewayMAC net MatchDstIP(peerIP). MatchCTStateRpl(true). MatchCTStateTrk(true). + Action().SetSrcMAC(f.nodeConfig.UplinkNetConfig.MAC). Action().SetDstMAC(remoteGatewayMAC). Action().NextTable(). Done(),