mlxsw: spectrum_flower: Split iif parsing to a separate function
authorIdo Schimmel <idosch@nvidia.com>
Mon, 29 May 2023 11:48:32 +0000 (14:48 +0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 31 May 2023 06:37:00 +0000 (23:37 -0700)
Currently, mlxsw only supports the 'ingress_ifindex' field in the
'FLOW_DISSECTOR_KEY_META' key, but subsequent patches are going to add
support for the 'l2_miss' field as well. Split the parsing of the
'ingress_ifindex' field to a separate function to avoid nesting. No
functional changes intended.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c

index 6fec9223250b7ca0029289e2a68b969583d3979d..2b0bae847eb990bce89a9a80fb9485d9c4cad1dc 100644 (file)
@@ -281,45 +281,35 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
        return 0;
 }
 
-static int mlxsw_sp_flower_parse_meta(struct mlxsw_sp_acl_rule_info *rulei,
-                                     struct flow_cls_offload *f,
-                                     struct mlxsw_sp_flow_block *block)
+static int
+mlxsw_sp_flower_parse_meta_iif(struct mlxsw_sp_acl_rule_info *rulei,
+                              const struct mlxsw_sp_flow_block *block,
+                              const struct flow_match_meta *match,
+                              struct netlink_ext_ack *extack)
 {
-       struct flow_rule *rule = flow_cls_offload_flow_rule(f);
        struct mlxsw_sp_port *mlxsw_sp_port;
        struct net_device *ingress_dev;
-       struct flow_match_meta match;
-
-       if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_META))
-               return 0;
-
-       flow_rule_match_meta(rule, &match);
 
-       if (match.mask->l2_miss) {
-               NL_SET_ERR_MSG_MOD(f->common.extack, "Can't match on \"l2_miss\"");
-               return -EOPNOTSUPP;
-       }
-
-       if (match.mask->ingress_ifindex != 0xFFFFFFFF) {
-               NL_SET_ERR_MSG_MOD(f->common.extack, "Unsupported ingress ifindex mask");
+       if (match->mask->ingress_ifindex != 0xFFFFFFFF) {
+               NL_SET_ERR_MSG_MOD(extack, "Unsupported ingress ifindex mask");
                return -EINVAL;
        }
 
        ingress_dev = __dev_get_by_index(block->net,
-                                        match.key->ingress_ifindex);
+                                        match->key->ingress_ifindex);
        if (!ingress_dev) {
-               NL_SET_ERR_MSG_MOD(f->common.extack, "Can't find specified ingress port to match on");
+               NL_SET_ERR_MSG_MOD(extack, "Can't find specified ingress port to match on");
                return -EINVAL;
        }
 
        if (!mlxsw_sp_port_dev_check(ingress_dev)) {
-               NL_SET_ERR_MSG_MOD(f->common.extack, "Can't match on non-mlxsw ingress port");
+               NL_SET_ERR_MSG_MOD(extack, "Can't match on non-mlxsw ingress port");
                return -EINVAL;
        }
 
        mlxsw_sp_port = netdev_priv(ingress_dev);
        if (mlxsw_sp_port->mlxsw_sp != block->mlxsw_sp) {
-               NL_SET_ERR_MSG_MOD(f->common.extack, "Can't match on a port from different device");
+               NL_SET_ERR_MSG_MOD(extack, "Can't match on a port from different device");
                return -EINVAL;
        }
 
@@ -327,9 +317,31 @@ static int mlxsw_sp_flower_parse_meta(struct mlxsw_sp_acl_rule_info *rulei,
                                       MLXSW_AFK_ELEMENT_SRC_SYS_PORT,
                                       mlxsw_sp_port->local_port,
                                       0xFFFFFFFF);
+
        return 0;
 }
 
+static int mlxsw_sp_flower_parse_meta(struct mlxsw_sp_acl_rule_info *rulei,
+                                     struct flow_cls_offload *f,
+                                     struct mlxsw_sp_flow_block *block)
+{
+       struct flow_rule *rule = flow_cls_offload_flow_rule(f);
+       struct flow_match_meta match;
+
+       if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_META))
+               return 0;
+
+       flow_rule_match_meta(rule, &match);
+
+       if (match.mask->l2_miss) {
+               NL_SET_ERR_MSG_MOD(f->common.extack, "Can't match on \"l2_miss\"");
+               return -EOPNOTSUPP;
+       }
+
+       return mlxsw_sp_flower_parse_meta_iif(rulei, block, &match,
+                                             f->common.extack);
+}
+
 static void mlxsw_sp_flower_parse_ipv4(struct mlxsw_sp_acl_rule_info *rulei,
                                       struct flow_cls_offload *f)
 {