diff mbox series

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

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

Commit Message

Roi Dayan Aug. 29, 2017, 4:30 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>
---
 lib/odp-util.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Simon Horman Sept. 7, 2017, 4:13 p.m. UTC | #1
On Tue, Aug 29, 2017 at 07:30:23AM +0300, Roi Dayan wrote:
> 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>

Some minor nits below but that notwithstanding

Acked-by: Simon Horman <simon.horman@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..0594840 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 back the netlink padding, if needed */

Maybe:

                 /* Add new padding as needed */

> +                ofpbuf_put_zeros(actions, NLA_ALIGN(key->nla_len) -
> +                                          key->nla_len);

The indentation of the above seems wrong:

+                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.0
>
diff mbox series

Patch

diff --git a/lib/odp-util.c b/lib/odp-util.c
index 4f1499e..0594840 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 back the netlink padding, if 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;