Skip to content

Commit

Permalink
net/mlx5e: Add helper for encap_info_equal for tunnels with options
Browse files Browse the repository at this point in the history
For tunnels with options, eg, geneve and vxlan with gbp, they share the
same way to compare the headers and options. Extract the code as a common
function for them.

Signed-off-by: Gavin Li <gavinl@nvidia.com>
Reviewed-by: Gavi Teitz <gavi@nvidia.com>
Reviewed-by: Roi Dayan <roid@nvidia.com>
Reviewed-by: Maor Dickman <maord@nvidia.com>
Acked-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Gavin Li authored and Jakub Kicinski committed Mar 18, 2023
1 parent c641e92 commit 58de53c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
3 changes: 3 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ int mlx5e_tc_tun_parse_udp_ports(struct mlx5e_priv *priv,
bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,
struct mlx5e_encap_key *b);

bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a,
struct mlx5e_encap_key *b,
__be16 tun_flags);
#endif /* CONFIG_MLX5_ESWITCH */

#endif //__MLX5_EN_TC_TUNNEL_H__
32 changes: 32 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <net/fib_notifier.h>
#include <net/nexthop.h>
#include <net/ip_tunnels.h>
#include "tc_tun_encap.h"
#include "en_tc.h"
#include "tc_tun.h"
Expand Down Expand Up @@ -571,6 +572,37 @@ bool mlx5e_tc_tun_encap_info_equal_generic(struct mlx5e_encap_key *a,
a->tc_tunnel->tunnel_type == b->tc_tunnel->tunnel_type;
}

bool mlx5e_tc_tun_encap_info_equal_options(struct mlx5e_encap_key *a,
struct mlx5e_encap_key *b,
__be16 tun_flags)
{
struct ip_tunnel_info *a_info;
struct ip_tunnel_info *b_info;
bool a_has_opts, b_has_opts;

if (!mlx5e_tc_tun_encap_info_equal_generic(a, b))
return false;

a_has_opts = !!(a->ip_tun_key->tun_flags & tun_flags);
b_has_opts = !!(b->ip_tun_key->tun_flags & tun_flags);

/* keys are equal when both don't have any options attached */
if (!a_has_opts && !b_has_opts)
return true;

if (a_has_opts != b_has_opts)
return false;

/* options stored in memory next to ip_tunnel_info struct */
a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key);
b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key);

return a_info->options_len == b_info->options_len &&
!memcmp(ip_tunnel_info_opts(a_info),
ip_tunnel_info_opts(b_info),
a_info->options_len);
}

static int cmp_decap_info(struct mlx5e_decap_key *a,
struct mlx5e_decap_key *b)
{
Expand Down
24 changes: 1 addition & 23 deletions drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,29 +337,7 @@ static int mlx5e_tc_tun_parse_geneve(struct mlx5e_priv *priv,
static bool mlx5e_tc_tun_encap_info_equal_geneve(struct mlx5e_encap_key *a,
struct mlx5e_encap_key *b)
{
struct ip_tunnel_info *a_info;
struct ip_tunnel_info *b_info;
bool a_has_opts, b_has_opts;

if (!mlx5e_tc_tun_encap_info_equal_generic(a, b))
return false;

a_has_opts = !!(a->ip_tun_key->tun_flags & TUNNEL_GENEVE_OPT);
b_has_opts = !!(b->ip_tun_key->tun_flags & TUNNEL_GENEVE_OPT);

/* keys are equal when both don't have any options attached */
if (!a_has_opts && !b_has_opts)
return true;

if (a_has_opts != b_has_opts)
return false;

/* geneve options stored in memory next to ip_tunnel_info struct */
a_info = container_of(a->ip_tun_key, struct ip_tunnel_info, key);
b_info = container_of(b->ip_tun_key, struct ip_tunnel_info, key);

return a_info->options_len == b_info->options_len &&
memcmp(a_info + 1, b_info + 1, a_info->options_len) == 0;
return mlx5e_tc_tun_encap_info_equal_options(a, b, TUNNEL_GENEVE_OPT);
}

struct mlx5e_tc_tunnel geneve_tunnel = {
Expand Down

0 comments on commit 58de53c

Please sign in to comment.