Browse Source

[NET]: Move destructor from neigh->ops to neigh_params

struct neigh_ops currently has a destructor field, which no in-kernel
drivers outside of infiniband use.  The infiniband/ulp/ipoib in-tree
driver stashes some info in the neighbour structure (the results of
the second-stage lookup from ARP results to real link-level path), and
it uses neigh->ops->destructor to get a callback so it can clean up
this extra info when a neighbour is freed.  We've run into problems
with this: since the destructor is in an ops field that is shared
between neighbours that may belong to different net devices, there's
no way to set/clear it safely.

The following patch moves this field to neigh_parms where it can be
safely set, together with its twin neigh_setup.  Two additional
patches in the patch series update ipoib to use this new interface.

Signed-off-by: Michael S. Tsirkin <mst@mellanox.co.il>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Michael S. Tsirkin 19 years ago
parent
commit
c5ecd62c25
3 changed files with 4 additions and 18 deletions
  1. 1 15
      drivers/infiniband/ulp/ipoib/ipoib_main.c
  2. 1 1
      include/net/neighbour.h
  3. 2 2
      net/core/neighbour.c

+ 1 - 15
drivers/infiniband/ulp/ipoib/ipoib_main.c

@@ -247,7 +247,6 @@ static void path_free(struct net_device *dev, struct ipoib_path *path)
 		if (neigh->ah)
 		if (neigh->ah)
 			ipoib_put_ah(neigh->ah);
 			ipoib_put_ah(neigh->ah);
 		*to_ipoib_neigh(neigh->neighbour) = NULL;
 		*to_ipoib_neigh(neigh->neighbour) = NULL;
-		neigh->neighbour->ops->destructor = NULL;
 		kfree(neigh);
 		kfree(neigh);
 	}
 	}
 
 
@@ -530,7 +529,6 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
 err:
 err:
 	*to_ipoib_neigh(skb->dst->neighbour) = NULL;
 	*to_ipoib_neigh(skb->dst->neighbour) = NULL;
 	list_del(&neigh->list);
 	list_del(&neigh->list);
-	neigh->neighbour->ops->destructor = NULL;
 	kfree(neigh);
 	kfree(neigh);
 
 
 	++priv->stats.tx_dropped;
 	++priv->stats.tx_dropped;
@@ -769,21 +767,9 @@ static void ipoib_neigh_destructor(struct neighbour *n)
 		ipoib_put_ah(ah);
 		ipoib_put_ah(ah);
 }
 }
 
 
-static int ipoib_neigh_setup(struct neighbour *neigh)
-{
-	/*
-	 * Is this kosher?  I can't find anybody in the kernel that
-	 * sets neigh->destructor, so we should be able to set it here
-	 * without trouble.
-	 */
-	neigh->ops->destructor = ipoib_neigh_destructor;
-
-	return 0;
-}
-
 static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
 static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
 {
 {
-	parms->neigh_setup = ipoib_neigh_setup;
+	parms->neigh_destructor = ipoib_neigh_destructor;
 
 
 	return 0;
 	return 0;
 }
 }

+ 1 - 1
include/net/neighbour.h

@@ -68,6 +68,7 @@ struct neigh_parms
 	struct net_device *dev;
 	struct net_device *dev;
 	struct neigh_parms *next;
 	struct neigh_parms *next;
 	int	(*neigh_setup)(struct neighbour *);
 	int	(*neigh_setup)(struct neighbour *);
+	void	(*neigh_destructor)(struct neighbour *);
 	struct neigh_table *tbl;
 	struct neigh_table *tbl;
 
 
 	void	*sysctl_table;
 	void	*sysctl_table;
@@ -145,7 +146,6 @@ struct neighbour
 struct neigh_ops
 struct neigh_ops
 {
 {
 	int			family;
 	int			family;
-	void			(*destructor)(struct neighbour *);
 	void			(*solicit)(struct neighbour *, struct sk_buff*);
 	void			(*solicit)(struct neighbour *, struct sk_buff*);
 	void			(*error_report)(struct neighbour *, struct sk_buff*);
 	void			(*error_report)(struct neighbour *, struct sk_buff*);
 	int			(*output)(struct sk_buff*);
 	int			(*output)(struct sk_buff*);

+ 2 - 2
net/core/neighbour.c

@@ -586,8 +586,8 @@ void neigh_destroy(struct neighbour *neigh)
 			kfree(hh);
 			kfree(hh);
 	}
 	}
 
 
-	if (neigh->ops && neigh->ops->destructor)
-		(neigh->ops->destructor)(neigh);
+	if (neigh->parms->neigh_destructor)
+		(neigh->parms->neigh_destructor)(neigh);
 
 
 	skb_queue_purge(&neigh->arp_queue);
 	skb_queue_purge(&neigh->arp_queue);