From 69b6be193fcb99f87fb0f6747b3b708edd4305a0 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 10 Nov 2010 16:22:18 -0800 Subject: [PATCH] ofp-util: Add OFP_ACTION_ALIGN macro to header. It seems that this should really be in openflow.h but so far it isn't. --- lib/ofp-print.c | 7 ++++--- lib/ofp-util.c | 17 +++++++---------- lib/ofp-util.h | 3 +++ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/ofp-print.c b/lib/ofp-print.c index bc777568b..87ae185e5 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -30,6 +30,7 @@ #include "compiler.h" #include "dynamic-string.h" #include "flow.h" +#include "ofp-util.h" #include "ofpbuf.h" #include "openflow/openflow.h" #include "openflow/nicira-ext.h" @@ -294,10 +295,10 @@ ofp_print_action(struct ds *string, const struct ofp_action_header *ah, return -1; } - if ((len % 8) != 0) { + if ((len % OFP_ACTION_ALIGN) != 0) { ds_put_format(string, - "***action %"PRIu16" length not a multiple of 8***\n", - type); + "***action %"PRIu16" length not a multiple of %d***\n", + type, OFP_ACTION_ALIGN); return -1; } diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 81a5dadf5..4d632efec 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -461,9 +461,6 @@ flow_stats_next(struct flow_stats_iterator *iter) return fs; } -/* Alignment of ofp_actions. */ -#define ACTION_ALIGNMENT 8 - static int check_action_exact_len(const union ofp_action *a, unsigned int len, unsigned int required_len) @@ -637,7 +634,7 @@ validate_actions(const union ofp_action *actions, size_t n_actions, for (i = 0; i < n_actions; ) { const union ofp_action *a = &actions[i]; unsigned int len = ntohs(a->header.len); - unsigned int n_slots = len / ACTION_ALIGNMENT; + unsigned int n_slots = len / OFP_ACTION_ALIGN; unsigned int slots_left = &actions[n_actions] - a; int error; @@ -649,9 +646,9 @@ validate_actions(const union ofp_action *actions, size_t n_actions, } else if (!len) { VLOG_DBG_RL(&bad_ofmsg_rl, "action has invalid length 0"); return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_BAD_LEN); - } else if (len % ACTION_ALIGNMENT) { + } else if (len % OFP_ACTION_ALIGN) { VLOG_DBG_RL(&bad_ofmsg_rl, "action length %u is not a multiple " - "of %d", len, ACTION_ALIGNMENT); + "of %d", len, OFP_ACTION_ALIGN); return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_BAD_LEN); } @@ -696,7 +693,7 @@ actions_next(struct actions_iterator *iter) if (iter->pos != iter->end) { const union ofp_action *a = iter->pos; unsigned int len = ntohs(a->header.len); - iter->pos += len / ACTION_ALIGNMENT; + iter->pos += len / OFP_ACTION_ALIGN; return a; } else { return NULL; @@ -926,9 +923,9 @@ int ofputil_pull_actions(struct ofpbuf *b, unsigned int actions_len, union ofp_action **actionsp, size_t *n_actionsp) { - if (actions_len % ACTION_ALIGNMENT != 0) { + if (actions_len % OFP_ACTION_ALIGN != 0) { VLOG_DBG_RL(&bad_ofmsg_rl, "OpenFlow message actions length %u " - "is not a multiple of %d", actions_len, ACTION_ALIGNMENT); + "is not a multiple of %d", actions_len, OFP_ACTION_ALIGN); goto error; } @@ -940,7 +937,7 @@ ofputil_pull_actions(struct ofpbuf *b, unsigned int actions_len, goto error; } - *n_actionsp = actions_len / ACTION_ALIGNMENT; + *n_actionsp = actions_len / OFP_ACTION_ALIGN; return 0; error: diff --git a/lib/ofp-util.h b/lib/ofp-util.h index 6f8c2594f..3467366ef 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -26,6 +26,9 @@ struct ofpbuf; struct ofp_action_header; +/* Alignment of ofp_actions. */ +#define OFP_ACTION_ALIGN 8 + /* OpenFlow protocol utility functions. */ void *make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **); void *make_nxmsg(size_t openflow_len, uint32_t subtype, struct ofpbuf **); -- 2.43.0