Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: graysonwu <[email protected]>
  • Loading branch information
GraysonWu committed Aug 17, 2023
1 parent a321c66 commit 2d131de
Showing 1 changed file with 29 additions and 40 deletions.
69 changes: 29 additions & 40 deletions pkg/agent/openflow/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ func (c *client) NewDNSPacketInConjunction(id uint32) error {
if err := c.ofEntryOperations.AddAll(conj.actionFlows); err != nil {
return fmt.Errorf("error when adding action flows for the DNS conjunction: %w", err)
}

dnsPriority := priorityDNSIntercept
dnsCTState := &openflow15.CTStates{
// Use ct_state=+trk+rpl as matching condition.
Expand All @@ -716,6 +717,8 @@ func (c *client) NewDNSPacketInConjunction(id uint32) error {
Data: 0b00101000,
Mask: 0b00101000,
}
dnsPortMatchValue := types.BitRange{Value: uint16(dnsPort)}

conj.serviceClause = conj.newClause(1, 2, getTableByID(conj.ruleTableID), nil)
conj.toClause = conj.newClause(2, 2, getTableByID(conj.ruleTableID), nil)
c.featureNetworkPolicy.conjMatchFlowLock.Lock()
Expand All @@ -725,57 +728,43 @@ func (c *client) NewDNSPacketInConjunction(id uint32) error {
tcpMatch := &conjunctiveMatch{
tableID: conj.serviceClause.ruleTable.GetID(),
priority: &dnsPriority,
}
udpMatch := &conjunctiveMatch{
tableID: conj.serviceClause.ruleTable.GetID(),
priority: &dnsPriority,
}
if proto == binding.ProtocolIP {
tcpMatch.matchPairs = []matchPair{
{
matchKey: MatchTCPSrcPort,
matchValue: types.BitRange{Value: uint16(dnsPort)},
},
matchPairs: []matchPair{
{
matchKey: MatchCTState,
matchValue: dnsCTState,
},
}
udpMatch.matchPairs = []matchPair{
{
matchKey: MatchUDPSrcPort,
matchValue: types.BitRange{Value: uint16(dnsPort)},
},
},
}
udpMatch := &conjunctiveMatch{
tableID: conj.serviceClause.ruleTable.GetID(),
priority: &dnsPriority,
matchPairs: []matchPair{
// Add CTState for UDP as well to make sure only solicited DNS responses are sent
// to userspace.
{
matchKey: MatchCTState,
matchValue: dnsCTState,
},
}
},
}
if proto == binding.ProtocolIP {
tcpMatch.matchPairs = append(tcpMatch.matchPairs, matchPair{
matchKey: MatchTCPSrcPort,
matchValue: dnsPortMatchValue,
})
udpMatch.matchPairs = append(udpMatch.matchPairs, matchPair{
matchKey: MatchUDPSrcPort,
matchValue: dnsPortMatchValue,
})
} else if proto == binding.ProtocolIPv6 {
tcpMatch.matchPairs = []matchPair{
{
matchKey: MatchTCPv6SrcPort,
matchValue: types.BitRange{Value: uint16(dnsPort)},
},
{
matchKey: MatchCTState,
matchValue: dnsCTState,
},
}
udpMatch.matchPairs = []matchPair{
{
matchKey: MatchUDPv6SrcPort,
matchValue: types.BitRange{Value: uint16(dnsPort)},
},
// Add CTState for UDP as well to make sure only solicited DNS responses are sent
// to userspace.
{
matchKey: MatchCTState,
matchValue: dnsCTState,
},
}
tcpMatch.matchPairs = append(tcpMatch.matchPairs, matchPair{
matchKey: MatchTCPv6SrcPort,
matchValue: dnsPortMatchValue,
})
udpMatch.matchPairs = append(udpMatch.matchPairs, matchPair{
matchKey: MatchUDPv6SrcPort,
matchValue: dnsPortMatchValue,
})
}
tcpCtxChange := conj.serviceClause.addConjunctiveMatchFlow(c.featureNetworkPolicy, tcpMatch, false, false)
udpCtxChange := conj.serviceClause.addConjunctiveMatchFlow(c.featureNetworkPolicy, udpMatch, false, false)
Expand Down

0 comments on commit 2d131de

Please sign in to comment.