summaryrefslogtreecommitdiff
path: root/lib/match.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2018-03-19 22:00:34 -0700
committerBen Pfaff <blp@ovn.org>2018-03-31 11:32:10 -0700
commit1dc1ec247e2a7fe126f9c8232a3d42521a8d8291 (patch)
treee078e45ff32146eafdbf4fa9c28b32f71dbc41d3 /lib/match.c
parentf825fdd4ff99fda707fb3b73596bf7d6bc7a1389 (diff)
downloadopenvswitch-1dc1ec247e2a7fe126f9c8232a3d42521a8d8291.tar.gz
flow, match, classifier: Add new functions for miniflow and minimatch.
The miniflow and minimatch APIs lack several of the features of the flow and match APIs. This commit adds a few of the missing functions. These functions will be used for the first time in an upcoming commit. Signed-off-by: Ben Pfaff <blp@ovn.org> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com> Reviewed-by: Armando Migliaccio <armamig@gmail.com>
Diffstat (limited to 'lib/match.c')
-rw-r--r--lib/match.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/match.c b/lib/match.c
index 3eab0fd5d..2e9a80329 100644
--- a/lib/match.c
+++ b/lib/match.c
@@ -1667,6 +1667,15 @@ minimatch_init(struct minimatch *dst, const struct match *src)
dst->tun_md = tun_metadata_allocation_clone(&src->tun_md);
}
+/* Initializes 'match' as a "catch-all" match that matches every packet. */
+void
+minimatch_init_catchall(struct minimatch *match)
+{
+ match->flows[0] = xcalloc(2, sizeof *match->flow);
+ match->flows[1] = match->flows[0] + 1;
+ match->tun_md = NULL;
+}
+
/* Initializes 'dst' as a copy of 'src'. The caller must eventually free 'dst'
* with minimatch_destroy(). */
void
@@ -1718,6 +1727,16 @@ minimatch_equal(const struct minimatch *a, const struct minimatch *b)
&& miniflow_equal(a->flow, b->flow);
}
+/* Returns a hash value for the flow and wildcards in 'match', starting from
+ * 'basis'. */
+uint32_t
+minimatch_hash(const struct minimatch *match, uint32_t basis)
+{
+ size_t n_values = miniflow_n_values(match->flow);
+ size_t flow_size = sizeof *match->flow + MINIFLOW_VALUES_SIZE(n_values);
+ return hash_bytes(match->flow, 2 * flow_size, basis);
+}
+
/* Returns true if 'target' satisifies 'match', that is, if each bit for which
* 'match' specifies a particular value has the correct value in 'target'.
*
@@ -1771,3 +1790,28 @@ minimatch_to_string(const struct minimatch *match,
minimatch_expand(match, &megamatch);
return match_to_string(&megamatch, port_map, priority);
}
+
+static bool
+minimatch_has_default_recirc_id(const struct minimatch *m)
+{
+ uint32_t flow_recirc_id = miniflow_get_recirc_id(m->flow);
+ uint32_t mask_recirc_id = miniflow_get_recirc_id(&m->mask->masks);
+ return flow_recirc_id == 0 && (mask_recirc_id == UINT32_MAX ||
+ mask_recirc_id == 0);
+}
+
+static bool
+minimatch_has_default_dp_hash(const struct minimatch *m)
+{
+ return (!miniflow_get_dp_hash(m->flow)
+ && !miniflow_get_dp_hash(&m->mask->masks));
+}
+
+/* Return true if the hidden fields of the match are set to the default values.
+ * The default values equals to those set up by match_init_hidden_fields(). */
+bool
+minimatch_has_default_hidden_fields(const struct minimatch *m)
+{
+ return (minimatch_has_default_recirc_id(m)
+ && minimatch_has_default_dp_hash(m));
+}