From: Ben Pfaff Date: Tue, 12 Feb 2013 07:37:41 +0000 (-0800) Subject: ofp-msgs: New function ofpraw_decode_assert(). X-Git-Tag: sliver-openvswitch-1.10.90-1~11^2~49 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=964a5f60c0b38e59993e92425709579b3394349a;p=sliver-openvswitch.git ofp-msgs: New function ofpraw_decode_assert(). This will acquire a caller in an upcoming patch. Signed-off-by: Ben Pfaff --- diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c index 057422886..efc4198af 100644 --- a/lib/ofp-msgs.c +++ b/lib/ofp-msgs.c @@ -320,6 +320,23 @@ ofpraw_decode(enum ofpraw *raw, const struct ofp_header *oh) return ofpraw_pull(raw, &msg); } +/* Does the same job as ofpraw_decode(), except that it assert-fails if + * ofpraw_decode() would have reported an error. Thus, it's able to use the + * return value for the OFPRAW_* message type instead of an error code. + * + * (It only makes sense to use this function if you previously called + * ofpraw_decode() on the message and thus know that it's OK.) */ +enum ofpraw +ofpraw_decode_assert(const struct ofp_header *oh) +{ + enum ofperr error; + enum ofpraw raw; + + error = ofpraw_decode(&raw, oh); + ovs_assert(!error); + return raw; +} + /* Determines the OFPRAW_* type of the OpenFlow message in 'msg', which starts * at 'msg->data' and has length 'msg->size' bytes. On success, returns 0 and * stores the type into '*rawp'. On failure, returns an OFPERR_* error code diff --git a/lib/ofp-msgs.h b/lib/ofp-msgs.h index 2db4fc9d0..66ec44825 100644 --- a/lib/ofp-msgs.h +++ b/lib/ofp-msgs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Nicira, Inc. + * Copyright (c) 2012, 2013 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -387,6 +387,7 @@ enum ofpraw { /* Decoding messages into OFPRAW_* values. */ enum ofperr ofpraw_decode(enum ofpraw *, const struct ofp_header *); +enum ofpraw ofpraw_decode_assert(const struct ofp_header *); enum ofperr ofpraw_pull(enum ofpraw *, struct ofpbuf *); enum ofpraw ofpraw_pull_assert(struct ofpbuf *);