From 18ddadc2e96279c69b1960af57da7af9332fbb21 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 26 May 2011 16:49:10 -0700 Subject: [PATCH] ofp-util: New functions ofputil_actions_equal(), ofputil_actions_clone(). I found that introducing these helper functions provided a very modest increase in readability. --- lib/ofp-util.c | 13 +++++++++++++ lib/ofp-util.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/lib/ofp-util.c b/lib/ofp-util.c index aa8df777..37eb073e 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -2565,3 +2565,16 @@ error: *n_actionsp = 0; return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN); } + +bool +ofputil_actions_equal(const union ofp_action *a, size_t n_a, + const union ofp_action *b, size_t n_b) +{ + return n_a == n_b && (!n_a || !memcmp(a, b, n_a * sizeof *a)); +} + +union ofp_action * +ofputil_actions_clone(const union ofp_action *actions, size_t n) +{ + return n ? xmemdup(actions, n * sizeof *actions) : NULL; +} diff --git a/lib/ofp-util.h b/lib/ofp-util.h index 5ff274eb..0190caaf 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -291,6 +291,10 @@ bool action_outputs_to_port(const union ofp_action *, ovs_be16 port); int ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len, union ofp_action **, size_t *); + +bool ofputil_actions_equal(const union ofp_action *a, size_t n_a, + const union ofp_action *b, size_t n_b); +union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n); /* OpenFlow vendors. * -- 2.30.2