2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-03 07:45:30 +00:00

classifier: New function cls_rule_move().

This function will acquire its first user in an upcoming commit.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
This commit is contained in:
Ben Pfaff
2013-08-27 12:25:48 -07:00
parent 1828ae5140
commit b2c1f00b73
6 changed files with 49 additions and 3 deletions

View File

@@ -89,7 +89,7 @@ cls_rule_init_from_minimatch(struct cls_rule *rule,
/* Initializes 'dst' as a copy of 'src'. /* 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 void
cls_rule_clone(struct cls_rule *dst, const struct cls_rule *src) 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; 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 /* Frees memory referenced by 'rule'. Doesn't free 'rule' itself (it's
* normally embedded into a larger structure). * normally embedded into a larger structure).
* *

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 *, void cls_rule_init_from_minimatch(struct cls_rule *, const struct minimatch *,
unsigned int priority); unsigned int priority);
void cls_rule_clone(struct cls_rule *, const struct cls_rule *); 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 *); void cls_rule_destroy(struct cls_rule *);
bool cls_rule_equal(const struct cls_rule *, const struct cls_rule *); bool cls_rule_equal(const struct cls_rule *, const struct cls_rule *);

View File

@@ -1136,6 +1136,21 @@ miniflow_clone(struct miniflow *dst, const struct miniflow *src)
memcpy(dst->values, src->values, n * sizeof *dst->values); 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' /* Frees any memory owned by 'flow'. Does not free the storage in which 'flow'
* itself resides; the caller is responsible for that. */ * itself resides; the caller is responsible for that. */
void void
@@ -1353,6 +1368,14 @@ minimask_clone(struct minimask *dst, const struct minimask *src)
miniflow_clone(&dst->masks, &src->masks); 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_'. /* 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 * The caller must provide room for FLOW_U32S "uint32_t"s in 'storage', for use

View File

@@ -321,6 +321,7 @@ struct miniflow {
void miniflow_init(struct miniflow *, const struct flow *); void miniflow_init(struct miniflow *, const struct flow *);
void miniflow_clone(struct miniflow *, const struct miniflow *); void miniflow_clone(struct miniflow *, const struct miniflow *);
void miniflow_move(struct miniflow *dst, struct miniflow *);
void miniflow_destroy(struct miniflow *); void miniflow_destroy(struct miniflow *);
void miniflow_expand(const struct miniflow *, struct flow *); 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_init(struct minimask *, const struct flow_wildcards *);
void minimask_clone(struct minimask *, const struct minimask *); void minimask_clone(struct minimask *, const struct minimask *);
void minimask_move(struct minimask *dst, struct minimask *src);
void minimask_combine(struct minimask *dst, void minimask_combine(struct minimask *dst,
const struct minimask *a, const struct minimask *b, const struct minimask *a, const struct minimask *b,
uint32_t storage[FLOW_U32S]); uint32_t storage[FLOW_U32S]);

View File

@@ -1104,6 +1104,15 @@ minimatch_clone(struct minimatch *dst, const struct minimatch *src)
minimask_clone(&dst->mask, &src->mask); 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 /* Frees any memory owned by 'match'. Does not free the storage in which
* 'match' itself resides; the caller is responsible for that. */ * 'match' itself resides; the caller is responsible for that. */
void void

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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_init(struct minimatch *, const struct match *);
void minimatch_clone(struct minimatch *, const struct minimatch *); void minimatch_clone(struct minimatch *, const struct minimatch *);
void minimatch_move(struct minimatch *dst, struct minimatch *src);
void minimatch_destroy(struct minimatch *); void minimatch_destroy(struct minimatch *);
void minimatch_expand(const struct minimatch *, struct match *); void minimatch_expand(const struct minimatch *, struct match *);