When OF1.2+ only actions are introduced, ofpacts_put_openflow11_{actions, instructions}() will be unable to handle all ofp-actions. For such cases, allow it return error.
Signed-off-by: Isaku Yamahata <yamah...@valinux.co.jp> --- v4 - newly introduced --- lib/ofp-actions.c | 17 ++++++++++++----- lib/ofp-actions.h | 11 ++++++----- utilities/ovs-ofctl.c | 15 ++++++++++++--- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 8d9f0ba..4e7bb37 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -1305,12 +1305,13 @@ ofpact_output_to_openflow11(const struct ofpact_output *output, oao->max_len = htons(output->max_len); } -static void +static enum ofperr ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out) { switch (a->type) { case OFPACT_OUTPUT: - return ofpact_output_to_openflow11(ofpact_get_OUTPUT(a), out); + ofpact_output_to_openflow11(ofpact_get_OUTPUT(a), out); + break; case OFPACT_ENQUEUE: /* XXX */ @@ -1384,23 +1385,28 @@ ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out) ofpact_to_nxast(a, out); break; } + return 0; } /* Converts the ofpacts in 'ofpacts' (terminated by OFPACT_END) into OpenFlow * 1.1 actions in 'openflow', appending the actions to any existing data in * 'openflow'. */ -void +enum ofperr ofpacts_put_openflow11_actions(const struct ofpact ofpacts[], size_t ofpacts_len, struct ofpbuf *openflow) { const struct ofpact *a; OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { - ofpact_to_openflow11(a, openflow); + enum ofperr error = ofpact_to_openflow11(a, openflow); + if (error) { + return error; + } } + return 0; } -void +enum ofperr ofpacts_put_openflow11_instructions(const struct ofpact ofpacts[], size_t ofpacts_len, struct ofpbuf *openflow) @@ -1420,6 +1426,7 @@ ofpacts_put_openflow11_instructions(const struct ofpact ofpacts[], } else { openflow->size = ofs; } + return 0; } /* Returns true if 'action' outputs to 'port', false otherwise. */ diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h index af1792a..c8641e3 100644 --- a/lib/ofp-actions.h +++ b/lib/ofp-actions.h @@ -396,11 +396,12 @@ enum ofperr ofpacts_check(const struct ofpact[], size_t ofpacts_len, /* Converting ofpacts to OpenFlow. */ enum ofperr ofpacts_put_openflow10(const struct ofpact[], size_t ofpacts_len, struct ofpbuf *openflow); -void ofpacts_put_openflow11_actions(const struct ofpact[], size_t ofpacts_len, - struct ofpbuf *openflow); -void ofpacts_put_openflow11_instructions(const struct ofpact[], - size_t ofpacts_len, - struct ofpbuf *openflow); +enum ofperr ofpacts_put_openflow11_actions(const struct ofpact[], + size_t ofpacts_len, + struct ofpbuf *openflow); +enum ofperr ofpacts_put_openflow11_instructions(const struct ofpact[], + size_t ofpacts_len, + struct ofpbuf *openflow); /* Working with ofpacts. */ bool ofpacts_output_to_port(const struct ofpact[], size_t ofpacts_len, diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 08dd312..5abe249 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -2482,7 +2482,12 @@ ofctl_parse_ofp11_actions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) /* Convert back to ofp11 actions and print differences from input. */ ofpbuf_init(&of11_out, 0); - ofpacts_put_openflow11_actions(ofpacts.data, ofpacts.size, &of11_out); + error = ofpacts_put_openflow11_actions(ofpacts.data, ofpacts.size, + &of11_out); + if (error) { + ovs_fatal(0, "ofpacts_put_openflow11_actions returned error: %s", + ofperr_get_name(error)); + } print_differences("", of11_in.data, of11_in.size, of11_out.data, of11_out.size); @@ -2541,8 +2546,12 @@ ofctl_parse_ofp11_instructions(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) /* Convert back to ofp11 instructions and print differences from * input. */ ofpbuf_init(&of11_out, 0); - ofpacts_put_openflow11_instructions(ofpacts.data, ofpacts.size, - &of11_out); + error = ofpacts_put_openflow11_instructions(ofpacts.data, ofpacts.size, + &of11_out); + if (error) { + ovs_fatal(0, "ofpacts_put_openflow11_instructions returned error:" + " %s", ofperr_get_name(error)); + } print_differences("", of11_in.data, of11_in.size, of11_out.data, of11_out.size); -- 1.7.1.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev