diff mbox series

[ovs-dev,V2,1/2] lib/odp: Fix handling of set masked action in parse_odp_action

Message ID 1505019607-63461-2-git-send-email-roid@mellanox.com
State Accepted
Headers show
Series [ovs-dev,V2,1/2] lib/odp: Fix handling of set masked action in parse_odp_action | expand

Commit Message

Roi Dayan Sept. 10, 2017, 5 a.m. UTC
From: Paul Blakey <paulb@mellanox.com>

If we find that we need to change from a SET to SET_MASKED action,
then we write the mask to the actions opfbuf. But if there was netlink
pad added to the buffer when writing the key, mask won't follow the
key data as per SET_MASKED spec.

Fix that by removing the padding before writing the mask, and
readding it if needed for alignment.

Fixes: 6d670e7f0d45 ("lib/odp: Masked set action execution and printing.")
Signed-off-by: Paul Blakey <paulb@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Simon Horman <simon.horman@netronome.com>
---
 lib/odp-util.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/lib/odp-util.c b/lib/odp-util.c
index 4f1499e..6304b3d 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -1990,8 +1990,17 @@  parse_odp_action(const char *s, const struct simap *port_names,
         if (size == nl_attr_get_size(key)) {
             /* Change to masked set action if not fully masked. */
             if (!is_all_ones(mask + 1, size)) {
+                /* Remove padding of eariler key payload  */
+                actions->size -= NLA_ALIGN(key->nla_len) - key->nla_len;
+
+                /* Put mask payload right after key payload */
                 key->nla_len += size;
                 ofpbuf_put(actions, mask + 1, size);
+
+                /* Add new padding as needed */
+                ofpbuf_put_zeros(actions, NLA_ALIGN(key->nla_len) -
+                                          key->nla_len);
+
                 /* 'actions' may have been reallocated by ofpbuf_put(). */
                 nested = ofpbuf_at_assert(actions, start_ofs, sizeof *nested);
                 nested->nla_type = OVS_ACTION_ATTR_SET_MASKED;