Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #3516: Use uplink MAC as source if packet is output to #3528

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/agent/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 {
Expand Down
18 changes: 18 additions & 0 deletions pkg/agent/openflow/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,24 @@ func (c *client) l3FwdFlowToRemoteViaGW(
Done()
}

// l3FwdFlowToRemoteViaUplink generates the L3 forward flow to match the packets destined
// for remote Pods via uplink. It is used when the cross-Node traffic does not require
// encapsulation (in noEncap, networkPolicyOnly, or hybrid mode).
func (c *client) l3FwdFlowToRemoteViaUplink(
remoteGatewayMAC net.HardwareAddr,
peerSubnet net.IPNet,
category cookie.Category) binding.Flow {
ipProto := getIPProtocol(peerSubnet.IP)
l3FwdTable := c.pipeline[l3ForwardingTable]
return l3FwdTable.BuildFlow(priorityNormal).MatchProtocol(ipProto).
MatchDstIPNet(peerSubnet).
Action().SetSrcMAC(c.nodeConfig.UplinkNetConfig.MAC).
tnqn marked this conversation as resolved.
Show resolved Hide resolved
Action().SetDstMAC(remoteGatewayMAC).
Action().GotoTable(l3FwdTable.GetNext()).
Cookie(c.cookieAllocator.Request(category).Raw()).
Done()
}

// arpResponderFlow generates the ARP responder flow entry that replies request comes from local gateway for peer
// gateway MAC.
func (c *client) arpResponderFlow(peerGatewayIP net.IP, category cookie.Category) binding.Flow {
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/openflow/pipeline_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (c *client) l3FwdFlowToRemoteViaRouting(localGatewayMAC net.HardwareAddr, r
Action().GotoTable(conntrackCommitTable).
Cookie(c.cookieAllocator.Request(category).Raw()).
Done()}
flows = append(flows, c.l3FwdFlowToRemoteViaGW(remoteGatewayMAC, *peerPodCIDR, category))
flows = append(flows, c.l3FwdFlowToRemoteViaUplink(remoteGatewayMAC, *peerPodCIDR, category))
return flows
}
return []binding.Flow{c.l3FwdFlowToRemoteViaGW(localGatewayMAC, *peerPodCIDR, category)}
Expand Down