From b2c1f00b730c3b92e8c1ff37b7d0f8c7a9a44934 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 27 Aug 2013 12:25:48 -0700 Subject: [PATCH] classifier: New function cls_rule_move(). This function will acquire its first user in an upcoming commit. Signed-off-by: Ben Pfaff Acked-by: Ethan Jackson --- lib/classifier.c | 12 +++++++++++- lib/classifier.h | 3 ++- lib/flow.c | 23 +++++++++++++++++++++++ lib/flow.h | 2 ++ lib/match.c | 9 +++++++++ lib/match.h | 3 ++- 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/lib/classifier.c b/lib/classifier.c index 556278f3d..93ee977bc 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -89,7 +89,7 @@ cls_rule_init_from_minimatch(struct cls_rule *rule, /* Initializes 'dst' as a copy of 'src'. * - * The caller must eventually destroy 'rule' with cls_rule_destroy(). */ + * The caller must eventually destroy 'dst' with cls_rule_destroy(). */ void cls_rule_clone(struct cls_rule *dst, const struct cls_rule *src) { @@ -97,6 +97,16 @@ cls_rule_clone(struct cls_rule *dst, const struct cls_rule *src) dst->priority = src->priority; } +/* Initializes 'dst' with the data in 'src', destroying 'src'. + * + * The caller must eventually destroy 'dst' with cls_rule_destroy(). */ +void +cls_rule_move(struct cls_rule *dst, struct cls_rule *src) +{ + minimatch_move(&dst->match, &src->match); + dst->priority = src->priority; +} + /* Frees memory referenced by 'rule'. Doesn't free 'rule' itself (it's * normally embedded into a larger structure). * diff --git a/lib/classifier.h b/lib/classifier.h index 3f89196f9..5a454586e 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,6 +86,7 @@ void cls_rule_init(struct cls_rule *, const struct match *, void cls_rule_init_from_minimatch(struct cls_rule *, const struct minimatch *, unsigned int priority); void cls_rule_clone(struct cls_rule *, const struct cls_rule *); +void cls_rule_move(struct cls_rule *dst, struct cls_rule *src); void cls_rule_destroy(struct cls_rule *); bool cls_rule_equal(const struct cls_rule *, const struct cls_rule *); diff --git a/lib/flow.c b/lib/flow.c index ab49b8002..52cc54823 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -1136,6 +1136,21 @@ miniflow_clone(struct miniflow *dst, const struct miniflow *src) memcpy(dst->values, src->values, n * sizeof *dst->values); } +/* Initializes 'dst' with the data in 'src', destroying 'src'. + * The caller must eventually free 'dst' with miniflow_destroy(). */ +void +miniflow_move(struct miniflow *dst, struct miniflow *src) +{ + int n = miniflow_n_values(src); + if (n <= MINI_N_INLINE) { + dst->values = dst->inline_values; + memcpy(dst->values, src->values, n * sizeof *dst->values); + } else { + dst->values = src->values; + } + memcpy(dst->map, src->map, sizeof dst->map); +} + /* Frees any memory owned by 'flow'. Does not free the storage in which 'flow' * itself resides; the caller is responsible for that. */ void @@ -1353,6 +1368,14 @@ minimask_clone(struct minimask *dst, const struct minimask *src) miniflow_clone(&dst->masks, &src->masks); } +/* Initializes 'dst' with the data in 'src', destroying 'src'. + * The caller must eventually free 'dst' with minimask_destroy(). */ +void +minimask_move(struct minimask *dst, struct minimask *src) +{ + miniflow_clone(&dst->masks, &src->masks); +} + /* Initializes 'dst_' as the bit-wise "and" of 'a_' and 'b_'. * * The caller must provide room for FLOW_U32S "uint32_t"s in 'storage', for use diff --git a/lib/flow.h b/lib/flow.h index ecd850a6c..75d95e8ec 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -321,6 +321,7 @@ struct miniflow { void miniflow_init(struct miniflow *, const struct flow *); void miniflow_clone(struct miniflow *, const struct miniflow *); +void miniflow_move(struct miniflow *dst, struct miniflow *); void miniflow_destroy(struct miniflow *); void miniflow_expand(const struct miniflow *, struct flow *); @@ -350,6 +351,7 @@ struct minimask { void minimask_init(struct minimask *, const struct flow_wildcards *); void minimask_clone(struct minimask *, const struct minimask *); +void minimask_move(struct minimask *dst, struct minimask *src); void minimask_combine(struct minimask *dst, const struct minimask *a, const struct minimask *b, uint32_t storage[FLOW_U32S]); diff --git a/lib/match.c b/lib/match.c index c038d48e1..51ed1b969 100644 --- a/lib/match.c +++ b/lib/match.c @@ -1104,6 +1104,15 @@ minimatch_clone(struct minimatch *dst, const struct minimatch *src) minimask_clone(&dst->mask, &src->mask); } +/* Initializes 'dst' with the data in 'src', destroying 'src'. The caller must + * eventually free 'dst' with minimatch_destroy(). */ +void +minimatch_move(struct minimatch *dst, struct minimatch *src) +{ + miniflow_move(&dst->flow, &src->flow); + minimask_move(&dst->mask, &src->mask); +} + /* Frees any memory owned by 'match'. Does not free the storage in which * 'match' itself resides; the caller is responsible for that. */ void diff --git a/lib/match.h b/lib/match.h index 57887219f..7b104ee12 100644 --- a/lib/match.h +++ b/lib/match.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -146,6 +146,7 @@ struct minimatch { void minimatch_init(struct minimatch *, const struct match *); void minimatch_clone(struct minimatch *, const struct minimatch *); +void minimatch_move(struct minimatch *dst, struct minimatch *src); void minimatch_destroy(struct minimatch *); void minimatch_expand(const struct minimatch *, struct match *); -- 2.20.1