Skip to content

Commit d615f22

Browse files
author
Ravi Sankar Penta
committed
Improve patching ovs flow rules in UpdateEgressNetworkPolicyRules
Old behavior: 1. Drop outgoing traffic 2. Examine egress np, generate and add ovs flows 3. Enable traffic Step (2) could be slow when egress np has many DNS entries. New behavior: (1) Examine egress np, generate ovs flows (not added) (2) Drop outgoing traffic (3) Add generated ovs flows in (1) (4) Enable traffic
1 parent f0a76f1 commit d615f22

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pkg/network/node/ovscontroller.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,7 @@ func (oc *ovsController) UpdateEgressNetworkPolicyRules(policies []networkapi.Eg
445445
otx.DeleteFlows("table=101, reg0=%d", vnid)
446446
otx.AddFlow("table=101, reg0=%d, priority=1, actions=drop", vnid)
447447
} else /* vnid != 0 && len(policies) == 1 */ {
448-
// Temporarily drop all outgoing traffic, to avoid race conditions while modifying the other rules
449-
otx.AddFlow("table=101, reg0=%d, cookie=1, priority=65535, actions=drop", vnid)
450-
otx.DeleteFlows("table=101, reg0=%d, cookie=0/1", vnid)
451-
448+
var flows []string
452449
dnsFound := false
453450
for i, rule := range policies[0].Spec.Egress {
454451
priority := len(policies[0].Spec.Egress) - i
@@ -482,10 +479,17 @@ func (oc *ovsController) UpdateEgressNetworkPolicyRules(policies []networkapi.Eg
482479
dst = fmt.Sprintf(", nw_dst=%s", selector)
483480
}
484481

485-
otx.AddFlow("table=101, reg0=%d, priority=%d, ip%s, actions=%s", vnid, priority, dst, action)
482+
flows = append(flows, fmt.Sprintf("table=101, reg0=%d, priority=%d, ip%s, actions=%s", vnid, priority, dst, action))
486483
}
487484
}
488485

486+
// Temporarily drop all outgoing traffic, to avoid race conditions while modifying the other rules
487+
otx.AddFlow("table=101, reg0=%d, cookie=1, priority=65535, actions=drop", vnid)
488+
otx.DeleteFlows("table=101, reg0=%d, cookie=0/1", vnid)
489+
for _, f := range flows {
490+
otx.AddFlow(f)
491+
}
492+
489493
if dnsFound {
490494
if err := common.CheckDNSResolver(); err != nil {
491495
inputErr = fmt.Errorf("DNS resolver failed: %v, dropping all traffic for namespace: %q", err, namespaces[0])

0 commit comments

Comments
 (0)