mlxsw: spectrum_router: Add helpers for neighbor access
authorArkadi Sharshevsky <arkadis@mellanox.com>
Thu, 24 Aug 2017 06:40:04 +0000 (08:40 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 24 Aug 2017 16:33:16 +0000 (09:33 -0700)
This is done as a preparation before introducing the ability to dump the
host table via dpipe, and to count the table size. The mlxsw's neighbor
representative struct stays private to the router module.

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_router.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h

index a0a9728af989404710c16eca496a064ea2f20441..0b989e16a4243fde12718b8b92e577de407b8ef9 100644 (file)
@@ -909,6 +909,42 @@ static const struct rhashtable_params mlxsw_sp_neigh_ht_params = {
        .key_len = sizeof(struct mlxsw_sp_neigh_key),
 };
 
+struct mlxsw_sp_neigh_entry *
+mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif,
+                       struct mlxsw_sp_neigh_entry *neigh_entry)
+{
+       if (!neigh_entry) {
+               if (list_empty(&rif->neigh_list))
+                       return NULL;
+               else
+                       return list_first_entry(&rif->neigh_list,
+                                               typeof(*neigh_entry),
+                                               rif_list_node);
+       }
+       if (neigh_entry->rif_list_node.next == &rif->neigh_list)
+               return NULL;
+       return list_next_entry(neigh_entry, rif_list_node);
+}
+
+int mlxsw_sp_neigh_entry_type(struct mlxsw_sp_neigh_entry *neigh_entry)
+{
+       return neigh_entry->key.n->tbl->family;
+}
+
+unsigned char *
+mlxsw_sp_neigh_entry_ha(struct mlxsw_sp_neigh_entry *neigh_entry)
+{
+       return neigh_entry->ha;
+}
+
+u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry)
+{
+       struct neighbour *n;
+
+       n = neigh_entry->key.n;
+       return ntohl(*((__be32 *) n->primary_key));
+}
+
 static struct mlxsw_sp_neigh_entry *
 mlxsw_sp_neigh_entry_alloc(struct mlxsw_sp *mlxsw_sp, struct neighbour *n,
                           u16 rif)
index a3e8d2b2514826977843aef052fc7c738df16517..80ac032d64a2065a82847af0b0455f0ad0ddacbd 100644 (file)
@@ -42,6 +42,8 @@ enum mlxsw_sp_rif_counter_dir {
        MLXSW_SP_RIF_COUNTER_EGRESS,
 };
 
+struct mlxsw_sp_neigh_entry;
+
 struct mlxsw_sp_rif *mlxsw_sp_rif_by_index(const struct mlxsw_sp *mlxsw_sp,
                                           u16 rif_index);
 u16 mlxsw_sp_rif_index(const struct mlxsw_sp_rif *rif);
@@ -56,5 +58,16 @@ void mlxsw_sp_rif_counter_free(struct mlxsw_sp *mlxsw_sp,
 int mlxsw_sp_rif_counter_alloc(struct mlxsw_sp *mlxsw_sp,
                               struct mlxsw_sp_rif *rif,
                               enum mlxsw_sp_rif_counter_dir dir);
+struct mlxsw_sp_neigh_entry *
+mlxsw_sp_rif_neigh_next(struct mlxsw_sp_rif *rif,
+                       struct mlxsw_sp_neigh_entry *neigh_entry);
+int mlxsw_sp_neigh_entry_type(struct mlxsw_sp_neigh_entry *neigh_entry);
+unsigned char *
+mlxsw_sp_neigh_entry_ha(struct mlxsw_sp_neigh_entry *neigh_entry);
+u32 mlxsw_sp_neigh4_entry_dip(struct mlxsw_sp_neigh_entry *neigh_entry);
+
+#define mlxsw_sp_rif_neigh_for_each(neigh_entry, rif)                          \
+       for (neigh_entry = mlxsw_sp_rif_neigh_next(rif, NULL); neigh_entry;     \
+            neigh_entry = mlxsw_sp_rif_neigh_next(rif, neigh_entry))
 
 #endif /* _MLXSW_ROUTER_H_*/