-classifier_for_each_match(const struct classifier *cls_,
- const struct cls_rule *target,
- 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 (!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);
- }
- } else {
- next_table = classifier_next_table(cls, table);
+cls_cursor_init(struct cls_cursor *cursor, const struct classifier *cls,
+ const struct cls_rule *target)
+{
+ cursor->cls = cls;
+ cursor->target = target;
+}
+
+/* Returns the first matching cls_rule in 'cursor''s iteration, or a null
+ * pointer if there are no matches. */
+struct cls_rule *
+cls_cursor_first(struct cls_cursor *cursor)
+{
+ struct cls_table *table;
+
+ for (table = classifier_first_table(cursor->cls); table;
+ table = classifier_next_table(cursor->cls, table)) {
+ struct cls_rule *rule = search_table(table, cursor->target);
+ if (rule) {
+ cursor->table = table;
+ return rule;