[NETNS][IPV6] route6 - Pass the network namespace parameter to rt6_lookup
[safe/jmp/linux-2.6] / net / ipv6 / anycast.c
index e5ef597..96868b9 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 
+#include <net/net_namespace.h>
 #include <net/sock.h>
 #include <net/snmp.h>
 
@@ -88,7 +89,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
                return -EPERM;
        if (ipv6_addr_is_multicast(addr))
                return -EINVAL;
-       if (ipv6_chk_addr(addr, NULL, 0))
+       if (ipv6_chk_addr(&init_net, addr, NULL, 0))
                return -EINVAL;
 
        pac = sock_kmalloc(sk, sizeof(struct ipv6_ac_socklist), GFP_KERNEL);
@@ -100,7 +101,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
        if (ifindex == 0) {
                struct rt6_info *rt;
 
-               rt = rt6_lookup(addr, NULL, 0, 0);
+               rt = rt6_lookup(&init_net, addr, NULL, 0, 0);
                if (rt) {
                        dev = rt->rt6i_dev;
                        dev_hold(dev);
@@ -111,10 +112,10 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
                } else {
                        /* router, no matching interface: just pick one */
 
-                       dev = dev_get_by_flags(IFF_UP, IFF_UP|IFF_LOOPBACK);
+                       dev = dev_get_by_flags(&init_net, IFF_UP, IFF_UP|IFF_LOOPBACK);
                }
        } else
-               dev = dev_get_by_index(ifindex);
+               dev = dev_get_by_index(&init_net, ifindex);
 
        if (dev == NULL) {
                err = -ENODEV;
@@ -195,7 +196,7 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, struct in6_addr *addr)
 
        write_unlock_bh(&ipv6_sk_ac_lock);
 
-       dev = dev_get_by_index(pac->acl_ifindex);
+       dev = dev_get_by_index(&init_net, pac->acl_ifindex);
        if (dev) {
                ipv6_dev_ac_dec(dev, &pac->acl_addr);
                dev_put(dev);
@@ -223,7 +224,7 @@ void ipv6_sock_ac_close(struct sock *sk)
                if (pac->acl_ifindex != prev_index) {
                        if (dev)
                                dev_put(dev);
-                       dev = dev_get_by_index(pac->acl_ifindex);
+                       dev = dev_get_by_index(&init_net, pac->acl_ifindex);
                        prev_index = pac->acl_ifindex;
                }
                if (dev)
@@ -413,7 +414,7 @@ static int ipv6_chk_acast_dev(struct net_device *dev, struct in6_addr *addr)
                                break;
                read_unlock_bh(&idev->lock);
                in6_dev_put(idev);
-               return aca != 0;
+               return aca != NULL;
        }
        return 0;
 }
@@ -423,14 +424,18 @@ static int ipv6_chk_acast_dev(struct net_device *dev, struct in6_addr *addr)
  */
 int ipv6_chk_acast_addr(struct net_device *dev, struct in6_addr *addr)
 {
+       int found = 0;
+
        if (dev)
                return ipv6_chk_acast_dev(dev, addr);
        read_lock(&dev_base_lock);
-       for (dev=dev_base; dev; dev=dev->next)
-               if (ipv6_chk_acast_dev(dev, addr))
+       for_each_netdev(&init_net, dev)
+               if (ipv6_chk_acast_dev(dev, addr)) {
+                       found = 1;
                        break;
+               }
        read_unlock(&dev_base_lock);
-       return dev != 0;
+       return found;
 }
 
 
@@ -447,9 +452,8 @@ static inline struct ifacaddr6 *ac6_get_first(struct seq_file *seq)
        struct ifacaddr6 *im = NULL;
        struct ac6_iter_state *state = ac6_seq_private(seq);
 
-       for (state->dev = dev_base, state->idev = NULL;
-            state->dev;
-            state->dev = state->dev->next) {
+       state->idev = NULL;
+       for_each_netdev(&init_net, state->dev) {
                struct inet6_dev *idev;
                idev = in6_dev_get(state->dev);
                if (!idev)
@@ -461,6 +465,7 @@ static inline struct ifacaddr6 *ac6_get_first(struct seq_file *seq)
                        break;
                }
                read_unlock_bh(&idev->lock);
+               in6_dev_put(idev);
        }
        return im;
 }
@@ -475,7 +480,7 @@ static struct ifacaddr6 *ac6_get_next(struct seq_file *seq, struct ifacaddr6 *im
                        read_unlock_bh(&state->idev->lock);
                        in6_dev_put(state->idev);
                }
-               state->dev = state->dev->next;
+               state->dev = next_net_device(state->dev);
                if (!state->dev) {
                        state->idev = NULL;
                        break;
@@ -499,6 +504,7 @@ static struct ifacaddr6 *ac6_get_idx(struct seq_file *seq, loff_t pos)
 }
 
 static void *ac6_seq_start(struct seq_file *seq, loff_t *pos)
+       __acquires(dev_base_lock)
 {
        read_lock(&dev_base_lock);
        return ac6_get_idx(seq, *pos);
@@ -513,6 +519,7 @@ static void *ac6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void ac6_seq_stop(struct seq_file *seq, void *v)
+       __releases(dev_base_lock)
 {
        struct ac6_iter_state *state = ac6_seq_private(seq);
        if (likely(state->idev != NULL)) {
@@ -535,7 +542,7 @@ static int ac6_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations ac6_seq_ops = {
+static const struct seq_operations ac6_seq_ops = {
        .start  =       ac6_seq_start,
        .next   =       ac6_seq_next,
        .stop   =       ac6_seq_stop,
@@ -544,24 +551,8 @@ static struct seq_operations ac6_seq_ops = {
 
 static int ac6_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct ac6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
-
-       if (!s)
-               goto out;
-
-       rc = seq_open(file, &ac6_seq_ops);
-       if (rc)
-               goto out_kfree;
-
-       seq = file->private_data;
-       seq->private = s;
-out:
-       return rc;
-out_kfree:
-       kfree(s);
-       goto out;
+       return seq_open_private(file, &ac6_seq_ops,
+                       sizeof(struct ac6_iter_state));
 }
 
 static const struct file_operations ac6_seq_fops = {
@@ -574,7 +565,7 @@ static const struct file_operations ac6_seq_fops = {
 
 int __init ac6_proc_init(void)
 {
-       if (!proc_net_fops_create("anycast6", S_IRUGO, &ac6_seq_fops))
+       if (!proc_net_fops_create(&init_net, "anycast6", S_IRUGO, &ac6_seq_fops))
                return -ENOMEM;
 
        return 0;
@@ -582,7 +573,7 @@ int __init ac6_proc_init(void)
 
 void ac6_proc_exit(void)
 {
-       proc_net_remove("anycast6");
+       proc_net_remove(&init_net, "anycast6");
 }
 #endif