ofproto: Report correct errors for unsupported stats/multipart requests.
[sliver-openvswitch.git] / lib / ofp-msgs.c
index d136f73..9f1b453 100644 (file)
@@ -260,22 +260,48 @@ ofphdrs_decode_assert(struct ofphdrs *hdrs,
 }
 
 static bool
-ofphdrs_is_stat(const struct ofphdrs *hdrs)
+ofp_is_stat_request(enum ofp_version version, uint8_t type)
 {
-    switch ((enum ofp_version) hdrs->version) {
+    switch (version) {
+    case OFP10_VERSION:
+        return type == OFPT10_STATS_REQUEST;
+    case OFP11_VERSION:
+    case OFP12_VERSION:
+    case OFP13_VERSION:
+        return type == OFPT11_STATS_REQUEST;
+    }
+
+    return false;
+}
+
+static bool
+ofp_is_stat_reply(enum ofp_version version, uint8_t type)
+{
+    switch (version) {
     case OFP10_VERSION:
-        return (hdrs->type == OFPT10_STATS_REQUEST ||
-                hdrs->type == OFPT10_STATS_REPLY);
+        return type == OFPT10_STATS_REPLY;
     case OFP11_VERSION:
     case OFP12_VERSION:
     case OFP13_VERSION:
-        return (hdrs->type == OFPT11_STATS_REQUEST ||
-                hdrs->type == OFPT11_STATS_REPLY);
+        return type == OFPT11_STATS_REPLY;
     }
 
     return false;
 }
 
+static bool
+ofp_is_stat(enum ofp_version version, uint8_t type)
+{
+    return (ofp_is_stat_request(version, type) ||
+            ofp_is_stat_reply(version, type));
+}
+
+static bool
+ofphdrs_is_stat(const struct ofphdrs *hdrs)
+{
+    return ofp_is_stat(hdrs->version, hdrs->type);
+}
+
 size_t
 ofphdrs_len(const struct ofphdrs *hdrs)
 {
@@ -811,6 +837,13 @@ ofpmsg_body(const struct ofp_header *oh)
     ofphdrs_decode_assert(&hdrs, oh, ntohs(oh->length));
     return (const uint8_t *) oh + ofphdrs_len(&hdrs);
 }
+
+/* Return if it's a stat/multipart (OFPST) request message. */
+bool
+ofpmsg_is_stat_request(const struct ofp_header *oh)
+{
+    return ofp_is_stat_request(oh->version, oh->type);
+}
 \f
 static ovs_be16 *ofpmp_flags__(const struct ofp_header *);