net/mlx5e: Add helper for encap_info_equal for tunnels with options
authorGavin Li <gavinl@nvidia.com>
Thu, 16 Mar 2023 07:07:56 +0000 (09:07 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 18 Mar 2023 05:41:16 +0000 (22:41 -0700)
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>
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_geneve.c

index b38f693bbb52dd885b164a5c5bb8542110140ae2..92065568bb19241f1cc21345e73ecae5c045f461 100644 (file)
@@ -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__
index 780224fd67a1df0bb045f5a409f7a968b12da121..a108e73c9f6698fca00be5ebeddbcbae08564030 100644 (file)
@@ -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"
@@ -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)
 {
index 054d80c4e65cfc15fe445d4d8cce626d984b2548..2bcd10b6d6537b9c5e3eccbfba3023489beabf3c 100644 (file)
@@ -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 = {