On 7/11/21 7:15 AM, Eli Britstein wrote:
> Compile with -Werror and -Wcast-align:
> 
> lib/netdev-offload-dpdk.c:578:30: error: cast increases required alignment
>     of target type [-Werror=cast-align]
>   578 |    ipv6_format_addr((struct in6_addr *) &set_ipv6->ipv6_addr, s);
>       |                     ^
> 
> Fix it.
> 
> Fixes: b6207b1d2711 ("netdev-offload-dpdk: Support offload of set IPv6 
> actions.")
> Signed-off-by: Eli Britstein <[email protected]>
> ---
>  lib/netdev-offload-dpdk.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/netdev-offload-dpdk.c b/lib/netdev-offload-dpdk.c
> index 6bd5b6c9f..a24f92782 100644
> --- a/lib/netdev-offload-dpdk.c
> +++ b/lib/netdev-offload-dpdk.c
> @@ -568,8 +568,12 @@ dump_flow_action(struct ds *s, struct ds *s_extra,
>  
>          ds_put_format(s, "set_ipv6_%s ", dirstr);
>          if (set_ipv6) {
> +            BUILD_ASSERT_DECL(
> +                offsetof(struct rte_flow_action_set_ipv6, ipv6_addr) %
> +                sizeof(struct in6_addr) == 0);
>              ds_put_cstr(s, "ipv6_addr ");
> -            ipv6_format_addr((struct in6_addr *) &set_ipv6->ipv6_addr, s);
> +            ipv6_format_addr(ALIGNED_CAST(struct in6_addr *,
> +                                          &set_ipv6->ipv6_addr), s);
>              ds_put_cstr(s, " ");
>          }
>          ds_put_cstr(s, "/ ");
> 

Build assertions are not reliable, because we also need to know the
alignment of the memory chunk that contains the structure.  It's
not a problem in a current code, because the structure seems to be
directly allocated with malloc, hence has a good alignment, but it
might become a problem, if the field will be part of another array
or a structure.

Since it's not a performance critical code, I'd suggest to just
memcpy() it the same way as we already do in the dump_vxlan_encap().
It will also be much more readable.

Best regards, Ilya Maximets.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to