Skip to content

Commit

Permalink
Revise OpenFlow pipeline: using macRewriteMark as the only mark to re…
Browse files Browse the repository at this point in the history
…set dst MAC (#1597)

Some flow entries are using the global vMAC as the mark when resetting dst MAC, while
others are using macRewriteMark originally. With this change, macRewriteMark is working
as the only mark.
  • Loading branch information
wenyingd committed Jan 12, 2021
1 parent 90719c3 commit 53e407e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions pkg/agent/openflow/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,15 +809,11 @@ func (c *client) l3FwdFlowToPod(localGatewayMAC net.HardwareAddr, podInterfaceIP
var flows []binding.Flow
for _, ip := range podInterfaceIPs {
ipProtocol := getIPProtocol(ip)
flowBuilder := l3FwdTable.BuildFlow(priorityNormal).MatchProtocol(ipProtocol)
if c.enableProxy {
flowBuilder = flowBuilder.MatchRegRange(int(marksReg), macRewriteMark, macRewriteMarkRange)
} else {
flowBuilder = flowBuilder.MatchDstMAC(globalVirtualMAC)
}
// Rewrite src MAC to local gateway MAC, and rewrite dst MAC to pod MAC
flows = append(flows, flowBuilder.MatchDstIP(ip).
flows = append(flows, l3FwdTable.BuildFlow(priorityNormal).MatchProtocol(ipProtocol).
MatchRegRange(int(marksReg), macRewriteMark, macRewriteMarkRange).
MatchDstIP(ip).
Action().SetSrcMAC(localGatewayMAC).
// Rewrite src MAC to local gateway MAC, and rewrite dst MAC to pod MAC
Action().SetDstMAC(podInterfaceMAC).
Action().GotoTable(l3DecTTLTable).
Cookie(c.cookieAllocator.Request(category).Raw()).
Expand Down Expand Up @@ -1467,7 +1463,6 @@ func (c *client) hostBridgeUplinkFlows(localSubnet net.IPNet, category cookie.Ca
MatchProtocol(binding.ProtocolIP).
MatchRegRange(int(marksReg), markTrafficFromBridge, binding.Range{0, 15}).
MatchDstIPNet(localSubnet).
Action().SetDstMAC(globalVirtualMAC).
Action().LoadRegRange(int(marksReg), macRewriteMark, macRewriteMarkRange).
Action().GotoTable(conntrackTable).
Cookie(c.cookieAllocator.Request(category).Raw()).
Expand Down Expand Up @@ -1503,14 +1498,13 @@ func (c *client) uplinkSNATFlows(category cookie.Category) []binding.Flow {
Action().GotoTable(conntrackTable).
Cookie(c.cookieAllocator.Request(category).Raw()).
Done(),
// Rewrite dMAC with the global vMAC if the packet is a reply to a
// Pod from an external address.
// Mark the packet to indicate its destination MAC should be rewritten to the real MAC in the L3Forwarding
// table, if the packet is a reply to a Pod from an external address.
c.pipeline[conntrackStateTable].BuildFlow(priorityHigh).
MatchProtocol(binding.ProtocolIP).
MatchCTStateNew(false).MatchCTStateTrk(true).
MatchCTMark(snatCTMark, nil).
MatchRegRange(int(marksReg), markTrafficFromUplink, binding.Range{0, 15}).
Action().SetDstMAC(globalVirtualMAC).
Action().LoadRegRange(int(marksReg), macRewriteMark, macRewriteMarkRange).
Action().GotoTable(ctStateNext).
Cookie(c.cookieAllocator.Request(category).Raw()).
Expand Down
2 changes: 1 addition & 1 deletion test/integration/agent/openflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ func prepareExternalFlows(nodeIP net.IP, localSubnet *net.IPNet, vMAC net.Hardwa
[]*ofTestUtils.ExpectFlow{
{
MatchStr: "priority=210,ct_state=-new+trk,ct_mark=0x40,ip,reg0=0x4/0xffff",
ActStr: fmt.Sprintf("set_field:%s->eth_dst,load:0x1->NXM_NX_REG0[19],goto_table:42", vMAC.String()),
ActStr: "load:0x1->NXM_NX_REG0[19],goto_table:42",
},
{
MatchStr: fmt.Sprintf("priority=200,ip,reg0=0x4/0xffff"),
Expand Down

0 comments on commit 53e407e

Please sign in to comment.