From 1dc1ec247e2a7fe126f9c8232a3d42521a8d8291 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 19 Mar 2018 22:00:34 -0700 Subject: 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 Reviewed-by: Yifeng Sun Reviewed-by: Armando Migliaccio --- lib/match.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'lib/match.c') 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)); +} -- cgit v1.2.1