neigh: Add infrastructure for allocating device neigh privates.
authorDavid Miller <davem@davemloft.net>
Mon, 25 Jul 2011 00:01:25 +0000 (00:01 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 30 Nov 2011 23:46:43 +0000 (18:46 -0500)
netdev->neigh_priv_len records the private area length.

This will trigger for neigh_table objects which set tbl->entry_size
to zero, and the first instances of this will be forthcoming.

Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/infiniband/ulp/ipoib/ipoib_main.c
include/linux/netdevice.h
net/atm/clip.c
net/core/neighbour.c

index efd7a9636aff893b4a73e803a5b147a951a0fcb6..57ae9b9265e307163a1d4c673704ce8488d1327a 100644 (file)
@@ -1218,6 +1218,8 @@ static struct net_device *ipoib_add_port(const char *format,
        priv->dev->mtu  = IPOIB_UD_MTU(priv->max_ib_mtu);
        priv->mcast_mtu  = priv->admin_mtu = priv->dev->mtu;
 
+       priv->dev->neigh_priv_len = sizeof(struct ipoib_neigh);
+
        result = ib_query_pkey(hca, port, 0, &priv->pkey);
        if (result) {
                printk(KERN_WARNING "%s: ib_query_pkey port %d failed (ret = %d)\n",
index 97edb3215a5a76dc29bb6d5da078268402883435..5462c2cd5eab662b19d2b80537033135595ee647 100644 (file)
@@ -1080,6 +1080,7 @@ struct net_device {
        unsigned char           perm_addr[MAX_ADDR_LEN]; /* permanent hw address */
        unsigned char           addr_assign_type; /* hw address assignment type */
        unsigned char           addr_len;       /* hardware address length      */
+       unsigned char           neigh_priv_len;
        unsigned short          dev_id;         /* for shared network cards */
 
        spinlock_t              addr_list_lock;
index 11439a7f67825fe554b9ca711204f547e7147e54..aea7cad2ece1290c556d9f3ce52566093060b2c9 100644 (file)
@@ -535,6 +535,7 @@ static void clip_setup(struct net_device *dev)
 {
        dev->netdev_ops = &clip_netdev_ops;
        dev->type = ARPHRD_ATM;
+       dev->neigh_priv_len = sizeof(struct atmarp_entry);
        dev->hard_header_len = RFC1483LLC_LEN;
        dev->mtu = RFC1626_MTU;
        dev->tx_queue_len = 100;        /* "normal" queue (packets) */
index 661ad12e0cc9d6a730e194edc82c64dac91dbf75..ef750ff7497ed0384d4eab05282b6ec55e374b71 100644 (file)
@@ -273,7 +273,7 @@ int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev)
 }
 EXPORT_SYMBOL(neigh_ifdown);
 
-static struct neighbour *neigh_alloc(struct neigh_table *tbl)
+static struct neighbour *neigh_alloc(struct neigh_table *tbl, struct net_device *dev)
 {
        struct neighbour *n = NULL;
        unsigned long now = jiffies;
@@ -288,7 +288,15 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl)
                        goto out_entries;
        }
 
-       n = kzalloc(tbl->entry_size, GFP_ATOMIC);
+       if (tbl->entry_size)
+               n = kzalloc(tbl->entry_size, GFP_ATOMIC);
+       else {
+               int sz = sizeof(*n) + tbl->key_len;
+
+               sz = ALIGN(sz, NEIGH_PRIV_ALIGN);
+               sz += dev->neigh_priv_len;
+               n = kzalloc(sz, GFP_ATOMIC);
+       }
        if (!n)
                goto out_entries;
 
@@ -463,7 +471,7 @@ struct neighbour *neigh_create(struct neigh_table *tbl, const void *pkey,
        u32 hash_val;
        int key_len = tbl->key_len;
        int error;
-       struct neighbour *n1, *rc, *n = neigh_alloc(tbl);
+       struct neighbour *n1, *rc, *n = neigh_alloc(tbl, dev);
        struct neigh_hash_table *nht;
 
        if (!n) {