Make ofperr_encode_msg__() use correct Open Flow version in the header of messages.
Signed-off-by: Simon Horman <ho...@verge.net.au> --- v4 * Initial post --- lib/ofp-errors.c | 34 ++++++++++++++++++++-------------- lib/ofp-errors.h | 2 +- lib/vconn.c | 5 ++--- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/ofp-errors.c b/lib/ofp-errors.c index 5d2fb47..a93dcd7 100644 --- a/lib/ofp-errors.c +++ b/lib/ofp-errors.c @@ -144,13 +144,15 @@ ofperr_get_pair__(enum ofperr error, const struct ofperr_domain *domain) } static struct ofpbuf * -ofperr_encode_msg__(enum ofperr error, const struct ofperr_domain *domain, +ofperr_encode_msg__(enum ofperr error, uint8_t ofp_version, ovs_be32 xid, const void *data, size_t data_len) { struct ofp_error_msg *oem; const struct pair *pair; struct ofpbuf *buf; + const struct ofperr_domain *domain; + domain = ofperr_domain_from_version(ofp_version); if (!domain) { return NULL; } @@ -176,7 +178,7 @@ ofperr_encode_msg__(enum ofperr error, const struct ofperr_domain *domain, pair = ofperr_get_pair__(error, domain); if (!ofperr_is_nx_extension(error)) { - oem = make_openflow_xid(data_len + sizeof *oem, OFP10_VERSION, + oem = make_openflow_xid(data_len + sizeof *oem, ofp_version, OFPT_ERROR, xid, &buf); oem->type = htons(pair->type); oem->code = htons(pair->code); @@ -184,7 +186,7 @@ ofperr_encode_msg__(enum ofperr error, const struct ofperr_domain *domain, struct nx_vendor_error *nve; oem = make_openflow_xid(data_len + sizeof *oem + sizeof *nve, - OFP10_VERSION, OFPT_ERROR, xid, &buf); + ofp_version, OFPT_ERROR, xid, &buf); oem->type = htons(NXET_VENDOR); oem->code = htons(NXVC_VENDOR_ERROR); @@ -217,31 +219,35 @@ ofperr_encode_msg__(enum ofperr error, const struct ofperr_domain *domain, struct ofpbuf * ofperr_encode_reply(enum ofperr error, const struct ofp_header *oh) { - const struct ofperr_domain *domain; uint16_t len = ntohs(oh->length); - domain = ofperr_domain_from_version(oh->version); - return ofperr_encode_msg__(error, domain, oh->xid, oh, MIN(len, 64)); + return ofperr_encode_msg__(error, oh->version, oh->xid, oh, MIN(len, 64)); } /* Creates and returns an OpenFlow message of type OFPT_ERROR that conveys the * given 'error', in the error domain 'domain'. The error message will include * the additional null-terminated text string 's'. * - * If 'domain' is NULL, uses the OpenFlow 1.0 error domain. OFPET_HELLO_FAILED - * error messages are supposed to be backward-compatible, so in theory this - * should work. + * If 'version' is an unknown version then OFP10_VERSION is used. + * OFPET_HELLO_FAILED error messages are supposed to be backward-compatible, + * so in theory this should work. * * Returns NULL if 'error' is not an OpenFlow error code or if 'error' cannot * be encoded in 'domain'. */ struct ofpbuf * -ofperr_encode_hello(enum ofperr error, const struct ofperr_domain *domain, - const char *s) +ofperr_encode_hello(enum ofperr error, uint8_t ofp_version, const char *s) { - if (!domain) { - domain = &ofperr_of10; + switch (ofp_version) { + case OFP10_VERSION: + case OFP11_VERSION: + case OFP12_VERSION: + break; + + default: + ofp_version = OFP10_VERSION; } - return ofperr_encode_msg__(error, domain, htonl(0), s, strlen(s)); + + return ofperr_encode_msg__(error, ofp_version, htonl(0), s, strlen(s)); } /* Returns the value that would go into an OFPT_ERROR message's 'type' for diff --git a/lib/ofp-errors.h b/lib/ofp-errors.h index 1a5ecd6..5767e65 100644 --- a/lib/ofp-errors.h +++ b/lib/ofp-errors.h @@ -500,7 +500,7 @@ enum ofperr ofperr_from_name(const char *); enum ofperr ofperr_decode_msg(const struct ofp_header *, size_t *payload_ofs); struct ofpbuf *ofperr_encode_reply(enum ofperr, const struct ofp_header *); -struct ofpbuf *ofperr_encode_hello(enum ofperr, const struct ofperr_domain *, +struct ofpbuf *ofperr_encode_hello(enum ofperr, uint8_t ofp_version, const char *); int ofperr_get_type(enum ofperr, const struct ofperr_domain *); int ofperr_get_code(enum ofperr, const struct ofperr_domain *); diff --git a/lib/vconn.c b/lib/vconn.c index ae6c8a2..de55dc7 100644 --- a/lib/vconn.c +++ b/lib/vconn.c @@ -463,9 +463,8 @@ vcs_send_error(struct vconn *vconn) snprintf(s, sizeof s, "We support versions 0x%02x to 0x%02x inclusive but " "you support no later than version 0x%02"PRIx8".", - vconn->min_version, OFP10_VERSION, vconn->version); - b = ofperr_encode_hello(OFPERR_OFPHFC_INCOMPATIBLE, - ofperr_domain_from_version(vconn->version), s); + vconn->min_version, OFP12_VERSION, vconn->version); + b = ofperr_encode_hello(OFPERR_OFPHFC_INCOMPATIBLE, vconn->version, s); retval = do_send(vconn, b); if (retval) { ofpbuf_delete(b); -- 1.7.10.2.484.gcd07cc5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev