nfsd4: filehandle leak or error exit from fh_compose()
[safe/jmp/linux-2.6] / net / core / dev_mcast.c
index 99aece1..9e2fa39 100644 (file)
@@ -6,7 +6,7 @@
  *             Richard Underwood <richard@wuzz.demon.co.uk>
  *
  *     Stir fried together from the IP multicast and CAP patches above
- *             Alan Cox <Alan.Cox@linux.org>
+ *             Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *     Fixes:
  *             Alan Cox        :       Update the device on a real delete
@@ -41,6 +41,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/init.h>
+#include <net/net_namespace.h>
 #include <net/ip.h>
 #include <net/route.h>
 #include <linux/skbuff.h>
@@ -71,7 +72,7 @@ int dev_mc_delete(struct net_device *dev, void *addr, int alen, int glbl)
 {
        int err;
 
-       netif_tx_lock_bh(dev);
+       netif_addr_lock_bh(dev);
        err = __dev_addr_delete(&dev->mc_list, &dev->mc_count,
                                addr, alen, glbl);
        if (!err) {
@@ -82,7 +83,7 @@ int dev_mc_delete(struct net_device *dev, void *addr, int alen, int glbl)
 
                __dev_set_rx_mode(dev);
        }
-       netif_tx_unlock_bh(dev);
+       netif_addr_unlock_bh(dev);
        return err;
 }
 
@@ -94,11 +95,11 @@ int dev_mc_add(struct net_device *dev, void *addr, int alen, int glbl)
 {
        int err;
 
-       netif_tx_lock_bh(dev);
+       netif_addr_lock_bh(dev);
        err = __dev_addr_add(&dev->mc_list, &dev->mc_count, addr, alen, glbl);
        if (!err)
                __dev_set_rx_mode(dev);
-       netif_tx_unlock_bh(dev);
+       netif_addr_unlock_bh(dev);
        return err;
 }
 
@@ -112,32 +113,18 @@ int dev_mc_add(struct net_device *dev, void *addr, int alen, int glbl)
  *     locked by netif_tx_lock_bh.
  *
  *     This function is intended to be called from the dev->set_multicast_list
- *     function of layered software devices.
+ *     or dev->set_rx_mode function of layered software devices.
  */
 int dev_mc_sync(struct net_device *to, struct net_device *from)
 {
-       struct dev_addr_list *da;
        int err = 0;
 
-       netif_tx_lock_bh(to);
-       for (da = from->mc_list; da != NULL; da = da->next) {
-               if (!da->da_synced) {
-                       err = __dev_addr_add(&to->mc_list, &to->mc_count,
-                                            da->da_addr, da->da_addrlen, 0);
-                       if (err < 0)
-                               break;
-                       da->da_synced = 1;
-                       da->da_users++;
-               } else if (da->da_users == 1) {
-                       __dev_addr_delete(&to->mc_list, &to->mc_count,
-                                         da->da_addr, da->da_addrlen, 0);
-                       __dev_addr_delete(&from->mc_list, &from->mc_count,
-                                         da->da_addr, da->da_addrlen, 0);
-               }
-       }
+       netif_addr_lock_bh(to);
+       err = __dev_addr_sync(&to->mc_list, &to->mc_count,
+                             &from->mc_list, &from->mc_count);
        if (!err)
                __dev_set_rx_mode(to);
-       netif_tx_unlock_bh(to);
+       netif_addr_unlock_bh(to);
 
        return err;
 }
@@ -156,59 +143,28 @@ EXPORT_SYMBOL(dev_mc_sync);
  */
 void dev_mc_unsync(struct net_device *to, struct net_device *from)
 {
-       struct dev_addr_list *da;
-
-       netif_tx_lock_bh(from);
-       netif_tx_lock_bh(to);
-
-       for (da = from->mc_list; da != NULL; da = da->next) {
-               if (!da->da_synced)
-                       continue;
-               __dev_addr_delete(&to->mc_list, &to->mc_count,
-                                 da->da_addr, da->da_addrlen, 0);
-               da->da_synced = 0;
-               __dev_addr_delete(&from->mc_list, &from->mc_count,
-                                 da->da_addr, da->da_addrlen, 0);
-       }
+       netif_addr_lock_bh(from);
+       netif_addr_lock(to);
+
+       __dev_addr_unsync(&to->mc_list, &to->mc_count,
+                         &from->mc_list, &from->mc_count);
        __dev_set_rx_mode(to);
 
-       netif_tx_unlock_bh(to);
-       netif_tx_unlock_bh(from);
+       netif_addr_unlock(to);
+       netif_addr_unlock_bh(from);
 }
 EXPORT_SYMBOL(dev_mc_unsync);
 
 #ifdef CONFIG_PROC_FS
-static void *dev_mc_seq_start(struct seq_file *seq, loff_t *pos)
-{
-       struct net_device *dev;
-       loff_t off = 0;
-
-       read_lock(&dev_base_lock);
-       for_each_netdev(dev) {
-               if (off++ == *pos)
-                       return dev;
-       }
-       return NULL;
-}
-
-static void *dev_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
-{
-       ++*pos;
-       return next_net_device((struct net_device *)v);
-}
-
-static void dev_mc_seq_stop(struct seq_file *seq, void *v)
-{
-       read_unlock(&dev_base_lock);
-}
-
-
 static int dev_mc_seq_show(struct seq_file *seq, void *v)
 {
        struct dev_addr_list *m;
        struct net_device *dev = v;
 
-       netif_tx_lock_bh(dev);
+       if (v == SEQ_START_TOKEN)
+               return 0;
+
+       netif_addr_lock_bh(dev);
        for (m = dev->mc_list; m; m = m->next) {
                int i;
 
@@ -220,20 +176,21 @@ static int dev_mc_seq_show(struct seq_file *seq, void *v)
 
                seq_putc(seq, '\n');
        }
-       netif_tx_unlock_bh(dev);
+       netif_addr_unlock_bh(dev);
        return 0;
 }
 
 static const struct seq_operations dev_mc_seq_ops = {
-       .start = dev_mc_seq_start,
-       .next  = dev_mc_seq_next,
-       .stop  = dev_mc_seq_stop,
+       .start = dev_seq_start,
+       .next  = dev_seq_next,
+       .stop  = dev_seq_stop,
        .show  = dev_mc_seq_show,
 };
 
 static int dev_mc_seq_open(struct inode *inode, struct file *file)
 {
-       return seq_open(file, &dev_mc_seq_ops);
+       return seq_open_net(inode, file, &dev_mc_seq_ops,
+                           sizeof(struct seq_net_private));
 }
 
 static const struct file_operations dev_mc_seq_fops = {
@@ -241,14 +198,31 @@ static const struct file_operations dev_mc_seq_fops = {
        .open    = dev_mc_seq_open,
        .read    = seq_read,
        .llseek  = seq_lseek,
-       .release = seq_release,
+       .release = seq_release_net,
 };
 
 #endif
 
+static int __net_init dev_mc_net_init(struct net *net)
+{
+       if (!proc_net_fops_create(net, "dev_mcast", 0, &dev_mc_seq_fops))
+               return -ENOMEM;
+       return 0;
+}
+
+static void __net_exit dev_mc_net_exit(struct net *net)
+{
+       proc_net_remove(net, "dev_mcast");
+}
+
+static struct pernet_operations __net_initdata dev_mc_net_ops = {
+       .init = dev_mc_net_init,
+       .exit = dev_mc_net_exit,
+};
+
 void __init dev_mcast_init(void)
 {
-       proc_net_fops_create("dev_mcast", 0, &dev_mc_seq_fops);
+       register_pernet_subsys(&dev_mc_net_ops);
 }
 
 EXPORT_SYMBOL(dev_mc_add);