mlxsw: spectrum_dpipe: Add IPv6 host table initial support
authorArkadi Sharshevsky <arkadis@mellanox.com>
Thu, 31 Aug 2017 15:59:14 +0000 (17:59 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 31 Aug 2017 21:42:19 +0000 (14:42 -0700)
Add IPv6 host table initial support. The action behavior for both IPv4/6
tables is the same, thus the same action dump op is used. Neighbors with
link local address are ignored.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.h

index 3ea13148ed053faa0e68ef2c06d275cbc263e5a6..93ba6a6ccfb89df606902157ec24a554bd316120 100644 (file)
@@ -76,6 +76,7 @@ static struct devlink_dpipe_header *mlxsw_dpipe_headers[] = {
        &mlxsw_sp_dpipe_header_metadata,
        &devlink_dpipe_header_ethernet,
        &devlink_dpipe_header_ipv4,
+       &devlink_dpipe_header_ipv6,
 };
 
 static struct devlink_dpipe_headers mlxsw_sp_dpipe_headers = {
@@ -328,9 +329,21 @@ static int mlxsw_sp_dpipe_table_host_matches_dump(struct sk_buff *skb, int type)
        if (err)
                return err;
 
-       match.type = DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT;
-       match.header = &devlink_dpipe_header_ipv4;
-       match.field_id = DEVLINK_DPIPE_FIELD_IPV4_DST_IP;
+       switch (type) {
+       case AF_INET:
+               match.type = DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT;
+               match.header = &devlink_dpipe_header_ipv4;
+               match.field_id = DEVLINK_DPIPE_FIELD_IPV4_DST_IP;
+               break;
+       case AF_INET6:
+               match.type = DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT;
+               match.header = &devlink_dpipe_header_ipv6;
+               match.field_id = DEVLINK_DPIPE_FIELD_IPV6_DST_IP;
+               break;
+       default:
+               WARN_ON(1);
+               return -EINVAL;
+       }
 
        return devlink_dpipe_match_put(skb, &match);
 }
@@ -342,7 +355,7 @@ mlxsw_sp_dpipe_table_host4_matches_dump(void *priv, struct sk_buff *skb)
 }
 
 static int
-mlxsw_sp_dpipe_table_host4_actions_dump(void *priv, struct sk_buff *skb)
+mlxsw_sp_dpipe_table_host_actions_dump(void *priv, struct sk_buff *skb)
 {
        struct devlink_dpipe_action action = {0};
 
@@ -648,8 +661,15 @@ mlxsw_sp_dpipe_table_host_size_get(struct mlxsw_sp *mlxsw_sp, int type)
                if (!rif)
                        continue;
                mlxsw_sp_rif_neigh_for_each(neigh_entry, rif) {
-                       if (mlxsw_sp_neigh_entry_type(neigh_entry) != type)
+                       int neigh_type = mlxsw_sp_neigh_entry_type(neigh_entry);
+
+                       if (neigh_type != type)
                                continue;
+
+                       if (neigh_type == AF_INET6 &&
+                           mlxsw_sp_neigh_ipv6_ignore(neigh_entry))
+                               continue;
+
                        size++;
                }
        }
@@ -667,7 +687,7 @@ static u64 mlxsw_sp_dpipe_table_host4_size_get(void *priv)
 
 static struct devlink_dpipe_table_ops mlxsw_sp_host4_ops = {
        .matches_dump = mlxsw_sp_dpipe_table_host4_matches_dump,
-       .actions_dump = mlxsw_sp_dpipe_table_host4_actions_dump,
+       .actions_dump = mlxsw_sp_dpipe_table_host_actions_dump,
        .entries_dump = mlxsw_sp_dpipe_table_host4_entries_dump,
        .counters_set_update = mlxsw_sp_dpipe_table_host4_counters_update,
        .size_get = mlxsw_sp_dpipe_table_host4_size_get,
@@ -691,6 +711,43 @@ static void mlxsw_sp_dpipe_host4_table_fini(struct mlxsw_sp *mlxsw_sp)
                                       MLXSW_SP_DPIPE_TABLE_NAME_HOST4);
 }
 
+static int
+mlxsw_sp_dpipe_table_host6_matches_dump(void *priv, struct sk_buff *skb)
+{
+       return mlxsw_sp_dpipe_table_host_matches_dump(skb, AF_INET6);
+}
+
+static u64 mlxsw_sp_dpipe_table_host6_size_get(void *priv)
+{
+       struct mlxsw_sp *mlxsw_sp = priv;
+
+       return mlxsw_sp_dpipe_table_host_size_get(mlxsw_sp, AF_INET6);
+}
+
+static struct devlink_dpipe_table_ops mlxsw_sp_host6_ops = {
+       .matches_dump = mlxsw_sp_dpipe_table_host6_matches_dump,
+       .actions_dump = mlxsw_sp_dpipe_table_host_actions_dump,
+       .size_get = mlxsw_sp_dpipe_table_host6_size_get,
+};
+
+static int mlxsw_sp_dpipe_host6_table_init(struct mlxsw_sp *mlxsw_sp)
+{
+       struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
+
+       return devlink_dpipe_table_register(devlink,
+                                           MLXSW_SP_DPIPE_TABLE_NAME_HOST6,
+                                           &mlxsw_sp_host6_ops,
+                                           mlxsw_sp, false);
+}
+
+static void mlxsw_sp_dpipe_host6_table_fini(struct mlxsw_sp *mlxsw_sp)
+{
+       struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
+
+       devlink_dpipe_table_unregister(devlink,
+                                      MLXSW_SP_DPIPE_TABLE_NAME_HOST6);
+}
+
 int mlxsw_sp_dpipe_init(struct mlxsw_sp *mlxsw_sp)
 {
        struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
@@ -707,8 +764,14 @@ int mlxsw_sp_dpipe_init(struct mlxsw_sp *mlxsw_sp)
        err = mlxsw_sp_dpipe_host4_table_init(mlxsw_sp);
        if (err)
                goto err_host4_table_init;
+
+       err = mlxsw_sp_dpipe_host6_table_init(mlxsw_sp);
+       if (err)
+               goto err_host6_table_init;
        return 0;
 
+err_host6_table_init:
+       mlxsw_sp_dpipe_host4_table_fini(mlxsw_sp);
 err_host4_table_init:
        mlxsw_sp_dpipe_erif_table_fini(mlxsw_sp);
 err_erif_table_init:
@@ -720,6 +783,7 @@ void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp)
 {
        struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
 
+       mlxsw_sp_dpipe_host6_table_fini(mlxsw_sp);
        mlxsw_sp_dpipe_host4_table_fini(mlxsw_sp);
        mlxsw_sp_dpipe_erif_table_fini(mlxsw_sp);
        devlink_dpipe_headers_unregister(devlink);
index c56a3d92a2bb378d4851a9d2bfb55dda3d024074..283fde4e678391257588935adfe933c0b4974cd8 100644 (file)
@@ -55,5 +55,6 @@ static inline void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp)
 
 #define MLXSW_SP_DPIPE_TABLE_NAME_ERIF "mlxsw_erif"
 #define MLXSW_SP_DPIPE_TABLE_NAME_HOST4 "mlxsw_host4"
+#define MLXSW_SP_DPIPE_TABLE_NAME_HOST6 "mlxsw_host6"
 
 #endif /* _MLXSW_PIPELINE_H_*/