net/mlx5e: Fix matching on tunnel addresses type
authorDmytro Linkin <dmitrolin@mellanox.com>
Fri, 13 Sep 2019 10:42:21 +0000 (10:42 +0000)
committerSaeed Mahameed <saeedm@mellanox.com>
Tue, 24 Sep 2019 09:38:08 +0000 (12:38 +0300)
In mlx5 parse_tunnel_attr() function dispatch on encap IP address type
is performed by directly checking flow_rule_match_key() on
FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, and then on
FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS. However, since those are stored in
union, first check is always true if any type of encap address is set,
which leads to IPv6 tunnel encap address being parsed as IPv4 by mlx5.
Determine correct IP address type by checking control key first and if
it set, take address type from match.key->addr_type.

Fixes: d1bda7eecd88 ("net/mlx5e: Allow matching only enc_key_id/enc_dst_port for decapsulation action")
Signed-off-by: Dmytro Linkin <dmitrolin@mellanox.com>
Reviewed-by: Vlad Buslov <vladbu@mellanox.com>
Reviewed-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

index da7555fdb4d563286738c024a113161066e9a78c..3e78a727f3e68634e2fb5f7e65838dce963a90bc 100644 (file)
@@ -1664,46 +1664,63 @@ static int parse_tunnel_attr(struct mlx5e_priv *priv,
                return err;
        }
 
-       if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) {
-               struct flow_match_ipv4_addrs match;
+       if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_CONTROL)) {
+               struct flow_match_control match;
+               u16 addr_type;
 
-               flow_rule_match_enc_ipv4_addrs(rule, &match);
-               MLX5_SET(fte_match_set_lyr_2_4, headers_c,
-                        src_ipv4_src_ipv6.ipv4_layout.ipv4,
-                        ntohl(match.mask->src));
-               MLX5_SET(fte_match_set_lyr_2_4, headers_v,
-                        src_ipv4_src_ipv6.ipv4_layout.ipv4,
-                        ntohl(match.key->src));
-
-               MLX5_SET(fte_match_set_lyr_2_4, headers_c,
-                        dst_ipv4_dst_ipv6.ipv4_layout.ipv4,
-                        ntohl(match.mask->dst));
-               MLX5_SET(fte_match_set_lyr_2_4, headers_v,
-                        dst_ipv4_dst_ipv6.ipv4_layout.ipv4,
-                        ntohl(match.key->dst));
-
-               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, ethertype);
-               MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, ETH_P_IP);
-       } else if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS)) {
-               struct flow_match_ipv6_addrs match;
+               flow_rule_match_enc_control(rule, &match);
+               addr_type = match.key->addr_type;
 
-               flow_rule_match_enc_ipv6_addrs(rule, &match);
-               memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c,
-                                   src_ipv4_src_ipv6.ipv6_layout.ipv6),
-                      &match.mask->src, MLX5_FLD_SZ_BYTES(ipv6_layout, ipv6));
-               memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
-                                   src_ipv4_src_ipv6.ipv6_layout.ipv6),
-                      &match.key->src, MLX5_FLD_SZ_BYTES(ipv6_layout, ipv6));
+               /* For tunnel addr_type used same key id`s as for non-tunnel */
+               if (addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
+                       struct flow_match_ipv4_addrs match;
 
-               memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c,
-                                   dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
-                      &match.mask->dst, MLX5_FLD_SZ_BYTES(ipv6_layout, ipv6));
-               memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
-                                   dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
-                      &match.key->dst, MLX5_FLD_SZ_BYTES(ipv6_layout, ipv6));
+                       flow_rule_match_enc_ipv4_addrs(rule, &match);
+                       MLX5_SET(fte_match_set_lyr_2_4, headers_c,
+                                src_ipv4_src_ipv6.ipv4_layout.ipv4,
+                                ntohl(match.mask->src));
+                       MLX5_SET(fte_match_set_lyr_2_4, headers_v,
+                                src_ipv4_src_ipv6.ipv4_layout.ipv4,
+                                ntohl(match.key->src));
 
-               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, ethertype);
-               MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype, ETH_P_IPV6);
+                       MLX5_SET(fte_match_set_lyr_2_4, headers_c,
+                                dst_ipv4_dst_ipv6.ipv4_layout.ipv4,
+                                ntohl(match.mask->dst));
+                       MLX5_SET(fte_match_set_lyr_2_4, headers_v,
+                                dst_ipv4_dst_ipv6.ipv4_layout.ipv4,
+                                ntohl(match.key->dst));
+
+                       MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c,
+                                        ethertype);
+                       MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
+                                ETH_P_IP);
+               } else if (addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) {
+                       struct flow_match_ipv6_addrs match;
+
+                       flow_rule_match_enc_ipv6_addrs(rule, &match);
+                       memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c,
+                                           src_ipv4_src_ipv6.ipv6_layout.ipv6),
+                              &match.mask->src, MLX5_FLD_SZ_BYTES(ipv6_layout,
+                                                                  ipv6));
+                       memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
+                                           src_ipv4_src_ipv6.ipv6_layout.ipv6),
+                              &match.key->src, MLX5_FLD_SZ_BYTES(ipv6_layout,
+                                                                 ipv6));
+
+                       memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c,
+                                           dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
+                              &match.mask->dst, MLX5_FLD_SZ_BYTES(ipv6_layout,
+                                                                  ipv6));
+                       memcpy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_v,
+                                           dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
+                              &match.key->dst, MLX5_FLD_SZ_BYTES(ipv6_layout,
+                                                                 ipv6));
+
+                       MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c,
+                                        ethertype);
+                       MLX5_SET(fte_match_set_lyr_2_4, headers_v, ethertype,
+                                ETH_P_IPV6);
+               }
        }
 
        if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IP)) {