mlxsw: spectrum_router: Break nexthop group entry validation to a separate function
authorIdo Schimmel <idosch@nvidia.com>
Mon, 22 Mar 2021 15:58:51 +0000 (17:58 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Mar 2021 20:45:46 +0000 (13:45 -0700)
The validation of a nexthop group entry is also necessary for resilient
nexthop groups, so break the validation to a separate function to allow
for code reuse in subsequent patches.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

index 6be225e..fa190e2 100644 (file)
@@ -4297,6 +4297,29 @@ mlxsw_sp_nexthop_obj_single_validate(struct mlxsw_sp *mlxsw_sp,
 }
 
 static int
+mlxsw_sp_nexthop_obj_group_entry_validate(struct mlxsw_sp *mlxsw_sp,
+                                         const struct nh_notifier_single_info *nh,
+                                         struct netlink_ext_ack *extack)
+{
+       int err;
+
+       err = mlxsw_sp_nexthop_obj_single_validate(mlxsw_sp, nh, extack);
+       if (err)
+               return err;
+
+       /* Device only nexthops with an IPIP device are programmed as
+        * encapsulating adjacency entries.
+        */
+       if (!nh->gw_family && !nh->is_reject &&
+           !mlxsw_sp_netdev_ipip_type(mlxsw_sp, nh->dev, NULL)) {
+               NL_SET_ERR_MSG_MOD(extack, "Nexthop group entry does not have a gateway");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int
 mlxsw_sp_nexthop_obj_group_validate(struct mlxsw_sp *mlxsw_sp,
                                    const struct nh_notifier_grp_info *nh_grp,
                                    struct netlink_ext_ack *extack)
@@ -4313,19 +4336,10 @@ mlxsw_sp_nexthop_obj_group_validate(struct mlxsw_sp *mlxsw_sp,
                int err;
 
                nh = &nh_grp->nh_entries[i].nh;
-               err = mlxsw_sp_nexthop_obj_single_validate(mlxsw_sp, nh,
-                                                          extack);
+               err = mlxsw_sp_nexthop_obj_group_entry_validate(mlxsw_sp, nh,
+                                                               extack);
                if (err)
                        return err;
-
-               /* Device only nexthops with an IPIP device are programmed as
-                * encapsulating adjacency entries.
-                */
-               if (!nh->gw_family && !nh->is_reject &&
-                   !mlxsw_sp_netdev_ipip_type(mlxsw_sp, nh->dev, NULL)) {
-                       NL_SET_ERR_MSG_MOD(extack, "Nexthop group entry does not have a gateway");
-                       return -EINVAL;
-               }
        }
 
        return 0;