From: Paul Blakey <pa...@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 <pa...@mellanox.com>
Reviewed-by: Roi Dayan <r...@mellanox.com>
Acked-by: Simon Horman <simon.hor...@netronome.com>
---
 lib/odp-util.c | 9 +++++++++
 1 file changed, 9 insertions(+)

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;
-- 
2.7.5

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to