lib/odp-util: Do not use mask if it doesn't exist.
[sliver-openvswitch.git] / lib / odp-util.c
index 956fef1..cc73413 100644 (file)
@@ -605,7 +605,7 @@ parse_odp_action(const char *s, const struct simap *port_names,
             ofpbuf_init(&buf, 16);
             end = ofpbuf_put_hex(&buf, &s[n], NULL);
             if (end[0] == ')' && end[1] == ')') {
-                odp_put_userspace_action(pid, buf.data, buf.size, actions);
+                odp_put_userspace_action(pid, ofpbuf_data(&buf), ofpbuf_size(&buf), actions);
                 ofpbuf_uninit(&buf);
                 return (end + 2) - s;
             }
@@ -715,7 +715,7 @@ odp_actions_from_string(const char *s, const struct simap *port_names,
         return 0;
     }
 
-    old_size = actions->size;
+    old_size = ofpbuf_size(actions);
     for (;;) {
         int retval;
 
@@ -726,7 +726,7 @@ odp_actions_from_string(const char *s, const struct simap *port_names,
 
         retval = parse_odp_action(s, port_names, actions);
         if (retval < 0 || !strchr(delimiters, s[retval])) {
-            actions->size = old_size;
+            ofpbuf_set_size(actions, old_size);
             return -retval;
         }
         s += retval;
@@ -1009,22 +1009,22 @@ format_odp_key_attr(const struct nlattr *a, const struct nlattr *ma,
         expected_len = odp_flow_key_attr_len(nl_attr_type(a));
         if (expected_len != -2) {
             bool bad_key_len = nl_attr_get_size(a) != expected_len;
-            bool bad_mask_len = ma && nl_attr_get_size(a) != expected_len;
+            bool bad_mask_len = ma && nl_attr_get_size(ma) != expected_len;
 
             if (bad_key_len || bad_mask_len) {
                 if (bad_key_len) {
                     ds_put_format(ds, "(bad key length %"PRIuSIZE", expected %d)(",
-                                  nl_attr_get_size(a),
-                                  odp_flow_key_attr_len(nl_attr_type(a)));
+                                  nl_attr_get_size(a), expected_len);
                 }
                 format_generic_odp_key(a, ds);
-                if (bad_mask_len) {
+                if (ma) {
                     ds_put_char(ds, '/');
-                    ds_put_format(ds, "(bad mask length %"PRIuSIZE", expected %d)(",
-                                  nl_attr_get_size(ma),
-                                  odp_flow_key_attr_len(nl_attr_type(ma)));
+                    if (bad_mask_len) {
+                        ds_put_format(ds, "(bad mask length %"PRIuSIZE", expected %d)(",
+                                      nl_attr_get_size(ma), expected_len);
+                    }
+                    format_generic_odp_key(ma, ds);
                 }
-                format_generic_odp_key(ma, ds);
                 ds_put_char(ds, ')');
                 return;
             }
@@ -1442,7 +1442,7 @@ generate_all_wildcard_mask(struct ofpbuf *ofp, const struct nlattr *key)
         nl_msg_end_nested(ofp, nested_mask);
     }
 
-    return ofp->base;
+    return ofpbuf_base(ofp);
 }
 
 /* Appends to 'ds' a string representation of the 'key_len' bytes of
@@ -2430,7 +2430,7 @@ int
 odp_flow_from_string(const char *s, const struct simap *port_names,
                      struct ofpbuf *key, struct ofpbuf *mask)
 {
-    const size_t old_size = key->size;
+    const size_t old_size = ofpbuf_size(key);
     for (;;) {
         int retval;
 
@@ -2441,7 +2441,7 @@ odp_flow_from_string(const char *s, const struct simap *port_names,
 
         retval = parse_odp_key_mask_attr(s, port_names, key, mask);
         if (retval < 0) {
-            key->size = old_size;
+            ofpbuf_set_size(key, old_size);
             return -retval;
         }
         s += retval;
@@ -3448,7 +3448,7 @@ odp_put_userspace_action(uint32_t pid,
     offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_USERSPACE);
     nl_msg_put_u32(odp_actions, OVS_USERSPACE_ATTR_PID, pid);
     if (userdata) {
-        userdata_ofs = odp_actions->size + NLA_HDRLEN;
+        userdata_ofs = ofpbuf_size(odp_actions) + NLA_HDRLEN;
 
         /* The OVS kernel module before OVS 1.11 and the upstream Linux kernel
          * module before Linux 3.10 required the userdata to be exactly 8 bytes