Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: graysonwu <wgrayson@vmware.com>
  • Loading branch information
GraysonWu committed Aug 16, 2023
1 parent e7ff6aa commit 4c16e5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
22 changes: 9 additions & 13 deletions pkg/agent/openflow/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ var (
MatchLabelID = types.NewMatchKey(binding.ProtocolIP, types.LabelIDAddr, "tun_id")
MatchTCPFlags = types.NewMatchKey(binding.ProtocolTCP, types.TCPFlagsAddr, "tcp_flags")
MatchTCPv6Flags = types.NewMatchKey(binding.ProtocolTCPv6, types.TCPFlagsAddr, "tcp_flags")
// Match value of MatchCTStatePositive will be used as positive CT state match(+).
// The value should follow the format "state1,state2".
// For example, if the match value is "rpl,trk", it will be translated to ct_state=+rpl+trk.
MatchCTStatePositive = types.NewMatchKey(binding.ProtocolIP, types.CTStateAddr, "ct_state")
Unsupported = types.NewMatchKey(binding.ProtocolIP, types.UnSupported, "unknown")
// MatchCTStateRpl should be used with nil matchValue. MatchPair with
// MatchCTStateRpl as the matchKey will be automatically translated to
// `ct_state=+rpl+trk`.
MatchCTStateRpl = types.NewMatchKey(binding.ProtocolIP, types.CTStateAddr, "ct_state")
Unsupported = types.NewMatchKey(binding.ProtocolIP, types.UnSupported, "unknown")

// metricFlowIdentifier is used to identify metric flows in metric table.
// There could be other flows like default flow and Traceflow flows in the table. Only metric flows are supposed to
Expand Down Expand Up @@ -731,8 +731,7 @@ func (c *client) NewDNSPacketInConjunction(id uint32) error {
matchValue: types.BitRange{Value: uint16(dnsPort)},
},
{
matchKey: MatchCTStatePositive,
matchValue: "rpl,trk",
matchKey: MatchCTStateRpl,
},
}
udpMatch.matchPairs = []matchPair{
Expand All @@ -741,8 +740,7 @@ func (c *client) NewDNSPacketInConjunction(id uint32) error {
matchValue: types.BitRange{Value: uint16(dnsPort)},
},
{
matchKey: MatchCTStatePositive,
matchValue: "rpl,trk",
matchKey: MatchCTStateRpl,
},
}
} else if proto == binding.ProtocolIPv6 {
Expand All @@ -752,8 +750,7 @@ func (c *client) NewDNSPacketInConjunction(id uint32) error {
matchValue: types.BitRange{Value: uint16(dnsPort)},
},
{
matchKey: MatchCTStatePositive,
matchValue: "rpl,trk",
matchKey: MatchCTStateRpl,
},
}
udpMatch.matchPairs = []matchPair{
Expand All @@ -762,8 +759,7 @@ func (c *client) NewDNSPacketInConjunction(id uint32) error {
matchValue: types.BitRange{Value: uint16(dnsPort)},
},
{
matchKey: MatchCTStatePositive,
matchValue: "rpl,trk",
matchKey: MatchCTStateRpl,
},
}
}
Expand Down
14 changes: 3 additions & 11 deletions pkg/agent/openflow/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"net"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -2095,16 +2094,9 @@ func (f *featureNetworkPolicy) addFlowMatch(fb binding.FlowBuilder, matchKey *ty
fb = fb.MatchProtocol(matchKey.GetOFProtocol())
tcpFlag := matchValue.(TCPFlags)
fb = fb.MatchTCPFlags(tcpFlag.Flag, tcpFlag.Mask)
case MatchCTStatePositive:
states := matchValue.(string)
for _, state := range strings.Split(states, ",") {
switch state {
case "rpl":
fb = fb.MatchCTStateRpl(true)
case "trk":
fb = fb.MatchCTStateTrk(true)
}
}
case MatchCTStateRpl:
fb = fb.MatchCTStateRpl(true).
MatchCTStateTrk(true)
}
return fb
}
Expand Down

0 comments on commit 4c16e5e

Please sign in to comment.