- * Ignores target->priority.
- *
- * 'callback' is allowed to delete the rule that is passed as its argument, but
- * it must not delete (or move) any other rules in 'cls' that have the same
- * wildcards as the argument rule. */
-void
-classifier_for_each_match(const struct classifier *cls_,
- const struct cls_rule *target,
- int include, cls_cb_func *callback, void *aux)
-{
- struct classifier *cls = (struct classifier *) cls_;
- struct cls_table *table, *next_table;
-
- for (table = classifier_first_table(cls); table; table = next_table) {
- if (should_include(table, include)
- && !flow_wildcards_has_extra(&table->wc, &target->wc)) {
- /* We have eliminated the "no" case in the truth table above. Two
- * of the three remaining cases are trivial. We only need to check
- * the fourth case, where both 'rule' and 'target' require an exact
- * match. */
- struct cls_rule *head, *next_head;
-
- table->n_refs++;
- HMAP_FOR_EACH_SAFE (head, next_head, hmap_node, &table->rules) {
- if (flow_equal_except(&head->flow, &target->flow,
- &target->wc)) {
- struct cls_rule *rule, *next_rule;
-
- FOR_EACH_RULE_IN_LIST_SAFE (rule, next_rule, head) {
- callback(rule, aux);
- }
- }
- }
- next_table = classifier_next_table(cls, table);
- if (!--table->n_refs && !table->n_table_rules) {
- destroy_table(cls, table);
+ * Ignores rule->priority. */
+bool
+cls_rule_is_loose_match(const struct cls_rule *rule,
+ const struct minimatch *criteria)
+{
+ return (!minimask_has_extra(&rule->match.mask, &criteria->mask)
+ && miniflow_equal_in_minimask(&rule->match.flow, &criteria->flow,
+ &criteria->mask));
+}
+\f
+/* Iteration. */
+
+static bool
+rule_matches(const struct cls_rule *rule, const struct cls_rule *target)
+{
+ return (!target
+ || miniflow_equal_in_minimask(&rule->match.flow,
+ &target->match.flow,
+ &target->match.mask));
+}
+
+static struct cls_rule *
+search_subtable(const struct cls_subtable *subtable,
+ const struct cls_rule *target)
+{
+ if (!target || !minimask_has_extra(&subtable->mask, &target->match.mask)) {
+ struct cls_rule *rule;
+
+ HMAP_FOR_EACH (rule, hmap_node, &subtable->rules) {
+ if (rule_matches(rule, target)) {
+ return rule;