From: Ben Pfaff Date: Mon, 24 Sep 2012 20:18:38 +0000 (-0700) Subject: ofp-actions: Allow OF1.1+ actions to be variable-length. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ddcaf2d7de751346775b3d6183d01a0c0986ce0;p=openvswitch ofp-actions: Allow OF1.1+ actions to be variable-length. Previously there was no need for this, because all implemented standard OpenFlow actions had a fixed length, but the OF1.2 "set-field" action (soon to be implemented) is variable length. Signed-off-by: Ben Pfaff Reviewed-by: Simon Horman --- diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index bb45edc0..8b85f4f7 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -282,7 +282,7 @@ ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code, switch (code) { case OFPUTIL_ACTION_INVALID: #define OFPAT10_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM: -#define OFPAT11_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM: +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM: #include "ofp-util.def" NOT_REACHED(); @@ -396,7 +396,7 @@ ofpact_from_openflow10(const union ofp_action *a, struct ofpbuf *out) switch (code) { case OFPUTIL_ACTION_INVALID: -#define OFPAT11_ACTION(ENUM, STRUCT, NAME) case OFPUTIL_##ENUM: +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM: #include "ofp-util.def" NOT_REACHED(); @@ -607,19 +607,24 @@ static enum ofperr decode_openflow11_action(const union ofp_action *a, enum ofputil_action_code *code) { + uint16_t len; + switch (a->type) { case CONSTANT_HTONS(OFPAT11_EXPERIMENTER): return decode_nxast_action(a, code); -#define OFPAT11_ACTION(ENUM, STRUCT, NAME) \ - case CONSTANT_HTONS(ENUM): \ - if (a->header.len == htons(sizeof(struct STRUCT))) { \ - *code = OFPUTIL_##ENUM; \ - return 0; \ - } else { \ - return OFPERR_OFPBAC_BAD_LEN; \ - } \ - break; +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \ + case CONSTANT_HTONS(ENUM): \ + len = ntohs(a->header.len); \ + if (EXTENSIBLE \ + ? len >= sizeof(struct STRUCT) \ + : len == sizeof(struct STRUCT)) { \ + *code = OFPUTIL_##ENUM; \ + return 0; \ + } else { \ + return OFPERR_OFPBAC_BAD_LEN; \ + } \ + NOT_REACHED(); #include "ofp-util.def" default: diff --git a/lib/ofp-util.c b/lib/ofp-util.c index e2a815be..366dcae0 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -3665,9 +3665,9 @@ ofputil_action_code_from_name(const char *name) { static const char *names[OFPUTIL_N_ACTIONS] = { NULL, -#define OFPAT10_ACTION(ENUM, STRUCT, NAME) NAME, -#define OFPAT11_ACTION(ENUM, STRUCT, NAME) NAME, -#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) NAME, +#define OFPAT10_ACTION(ENUM, STRUCT, NAME) NAME, +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) NAME, +#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) NAME, #include "ofp-util.def" }; @@ -3693,9 +3693,10 @@ ofputil_put_action(enum ofputil_action_code code, struct ofpbuf *buf) case OFPUTIL_ACTION_INVALID: NOT_REACHED(); -#define OFPAT10_ACTION(ENUM, STRUCT, NAME) \ +#define OFPAT10_ACTION(ENUM, STRUCT, NAME) \ + case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf); +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \ case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf); -#define OFPAT11_ACTION OFPAT10_ACTION #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \ case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf); #include "ofp-util.def" @@ -3719,7 +3720,8 @@ ofputil_put_action(enum ofputil_action_code code, struct ofpbuf *buf) ofputil_init_##ENUM(s); \ return s; \ } -#define OFPAT11_ACTION OFPAT10_ACTION +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \ + OFPAT10_ACTION(ENUM, STRUCT, NAME) #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \ void \ ofputil_init_##ENUM(struct STRUCT *s) \ diff --git a/lib/ofp-util.def b/lib/ofp-util.def index 2e50db16..79ae01db 100644 --- a/lib/ofp-util.def +++ b/lib/ofp-util.def @@ -17,25 +17,25 @@ OFPAT10_ACTION(OFPAT10_SET_TP_DST, ofp_action_tp_port, "mod_tp_dst") OFPAT10_ACTION(OFPAT10_ENQUEUE, ofp_action_enqueue, "enqueue") #ifndef OFPAT11_ACTION -#define OFPAT11_ACTION(ENUM, STRUCT, NAME) +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) #endif -OFPAT11_ACTION(OFPAT11_OUTPUT, ofp11_action_output, "output") -OFPAT11_ACTION(OFPAT11_SET_VLAN_VID, ofp_action_vlan_vid, "mod_vlan_vid") -OFPAT11_ACTION(OFPAT11_SET_VLAN_PCP, ofp_action_vlan_pcp, "mod_vlan_pcp") -OFPAT11_ACTION(OFPAT11_SET_DL_SRC, ofp_action_dl_addr, "mod_dl_src") -OFPAT11_ACTION(OFPAT11_SET_DL_DST, ofp_action_dl_addr, "mod_dl_dst") -OFPAT11_ACTION(OFPAT11_SET_NW_SRC, ofp_action_nw_addr, "mod_nw_src") -OFPAT11_ACTION(OFPAT11_SET_NW_DST, ofp_action_nw_addr, "mod_nw_dst") -OFPAT11_ACTION(OFPAT11_SET_NW_TOS, ofp_action_nw_tos, "mod_nw_tos") -//OFPAT11_ACTION(OFPAT11_SET_NW_ECN, ofp11_action_nw_ecn, "mod_nw_ecn") -OFPAT11_ACTION(OFPAT11_SET_TP_SRC, ofp_action_tp_port, "mod_tp_src") -OFPAT11_ACTION(OFPAT11_SET_TP_DST, ofp_action_tp_port, "mod_tp_dst") -//OFPAT11_ACTION(OFPAT11_PUSH_VLAN, ofp11_action_push, "push_vlan") -//OFPAT11_ACTION(OFPAT11_POP_VLAN, ofp_action_header, "pop_vlan") -//OFPAT11_ACTION(OFPAT11_SET_QUEUE, ofp11_action_set_queue, "set_queue") -//OFPAT11_ACTION(OFPAT11_SET_NW_TTL, ofp11_action_nw_ttl, "set_nw_ttl") -//OFPAT11_ACTION(OFPAT11_DEC_NW_TTL, ofp_action_header, "dec_ttl") -OFPAT11_ACTION(OFPAT12_SET_FIELD, ofp12_action_set_field, NULL) +OFPAT11_ACTION(OFPAT11_OUTPUT, ofp11_action_output, 0, "output") +OFPAT11_ACTION(OFPAT11_SET_VLAN_VID, ofp_action_vlan_vid, 0, "mod_vlan_vid") +OFPAT11_ACTION(OFPAT11_SET_VLAN_PCP, ofp_action_vlan_pcp, 0, "mod_vlan_pcp") +OFPAT11_ACTION(OFPAT11_SET_DL_SRC, ofp_action_dl_addr, 0, "mod_dl_src") +OFPAT11_ACTION(OFPAT11_SET_DL_DST, ofp_action_dl_addr, 0, "mod_dl_dst") +OFPAT11_ACTION(OFPAT11_SET_NW_SRC, ofp_action_nw_addr, 0, "mod_nw_src") +OFPAT11_ACTION(OFPAT11_SET_NW_DST, ofp_action_nw_addr, 0, "mod_nw_dst") +OFPAT11_ACTION(OFPAT11_SET_NW_TOS, ofp_action_nw_tos, 0, "mod_nw_tos") +//OFPAT11_ACTION(OFPAT11_SET_NW_ECN, ofp11_action_nw_ecn, "0, mod_nw_ecn") +OFPAT11_ACTION(OFPAT11_SET_TP_SRC, ofp_action_tp_port, 0, "mod_tp_src") +OFPAT11_ACTION(OFPAT11_SET_TP_DST, ofp_action_tp_port, 0, "mod_tp_dst") +//OFPAT11_ACTION(OFPAT11_PUSH_VLAN, ofp11_action_push, 0, "push_vlan") +//OFPAT11_ACTION(OFPAT11_POP_VLAN, ofp_action_header, 0, "pop_vlan") +//OFPAT11_ACTION(OFPAT11_SET_QUEUE, ofp11_action_set_queue, 0, "set_queue") +//OFPAT11_ACTION(OFPAT11_SET_NW_TTL, ofp11_action_nw_ttl, 0, "set_nw_ttl") +//OFPAT11_ACTION(OFPAT11_DEC_NW_TTL, ofp_action_header, 0, "dec_ttl") +OFPAT11_ACTION(OFPAT12_SET_FIELD, ofp12_action_set_field, 1, NULL) #ifndef NXAST_ACTION #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) diff --git a/lib/ofp-util.h b/lib/ofp-util.h index 6b5f3672..38e7b029 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -558,17 +558,17 @@ bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *); */ enum OVS_PACKED_ENUM ofputil_action_code { OFPUTIL_ACTION_INVALID, -#define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM, -#define OFPAT11_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM, -#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM, +#define OFPAT10_ACTION(ENUM, STRUCT, NAME) OFPUTIL_##ENUM, +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM, +#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM, #include "ofp-util.def" }; /* The number of values of "enum ofputil_action_code". */ enum { -#define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1 -#define OFPAT11_ACTION(ENUM, STRUCT, NAME) + 1 -#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1 +#define OFPAT10_ACTION(ENUM, STRUCT, NAME) + 1 +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1 +#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1 OFPUTIL_N_ACTIONS = 1 #include "ofp-util.def" }; @@ -594,7 +594,7 @@ void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf); #define OFPAT10_ACTION(ENUM, STRUCT, NAME) \ void ofputil_init_##ENUM(struct STRUCT *); \ struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *); -#define OFPAT11_ACTION(ENUM, STRUCT, NAME) \ +#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \ void ofputil_init_##ENUM(struct STRUCT *); \ struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *); #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) \