net: spread __net_init, __net_exit
[safe/jmp/linux-2.6] / net / ipv6 / addrconf.c
index f918399..1593289 100644 (file)
@@ -481,9 +481,8 @@ static void addrconf_forward_change(struct net *net, __s32 newf)
        struct net_device *dev;
        struct inet6_dev *idev;
 
-       read_lock(&dev_base_lock);
-       for_each_netdev(net, dev) {
-               rcu_read_lock();
+       rcu_read_lock();
+       for_each_netdev_rcu(net, dev) {
                idev = __in6_dev_get(dev);
                if (idev) {
                        int changed = (!idev->cnf.forwarding) ^ (!newf);
@@ -491,9 +490,8 @@ static void addrconf_forward_change(struct net *net, __s32 newf)
                        if (changed)
                                dev_forward_change(idev);
                }
-               rcu_read_unlock();
        }
-       read_unlock(&dev_base_lock);
+       rcu_read_unlock();
 }
 
 static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int old)
@@ -1137,10 +1135,9 @@ int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
        hiscore->rule = -1;
        hiscore->ifa = NULL;
 
-       read_lock(&dev_base_lock);
        rcu_read_lock();
 
-       for_each_netdev(net, dev) {
+       for_each_netdev_rcu(net, dev) {
                struct inet6_dev *idev;
 
                /* Candidate Source Address (section 4)
@@ -1235,7 +1232,6 @@ try_nextdev:
                read_unlock_bh(&idev->lock);
        }
        rcu_read_unlock();
-       read_unlock(&dev_base_lock);
 
        if (!hiscore->ifa)
                return -EADDRNOTAVAIL;
@@ -3031,14 +3027,14 @@ static const struct file_operations if6_fops = {
        .release        = seq_release_net,
 };
 
-static int if6_proc_net_init(struct net *net)
+static int __net_init if6_proc_net_init(struct net *net)
 {
        if (!proc_net_fops_create(net, "if_inet6", S_IRUGO, &if6_fops))
                return -ENOMEM;
        return 0;
 }
 
-static void if6_proc_net_exit(struct net *net)
+static void __net_exit if6_proc_net_exit(struct net *net)
 {
        proc_net_remove(net, "if_inet6");
 }
@@ -3485,85 +3481,114 @@ enum addr_type_t
        ANYCAST_ADDR,
 };
 
+/* called with rcu_read_lock() */
+static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb,
+                         struct netlink_callback *cb, enum addr_type_t type,
+                         int s_ip_idx, int *p_ip_idx)
+{
+       struct inet6_ifaddr *ifa;
+       struct ifmcaddr6 *ifmca;
+       struct ifacaddr6 *ifaca;
+       int err = 1;
+       int ip_idx = *p_ip_idx;
+
+       read_lock_bh(&idev->lock);
+       switch (type) {
+       case UNICAST_ADDR:
+               /* unicast address incl. temp addr */
+               for (ifa = idev->addr_list; ifa;
+                    ifa = ifa->if_next, ip_idx++) {
+                       if (ip_idx < s_ip_idx)
+                               continue;
+                       err = inet6_fill_ifaddr(skb, ifa,
+                                               NETLINK_CB(cb->skb).pid,
+                                               cb->nlh->nlmsg_seq,
+                                               RTM_NEWADDR,
+                                               NLM_F_MULTI);
+                       if (err <= 0)
+                               break;
+               }
+               break;
+       case MULTICAST_ADDR:
+               /* multicast address */
+               for (ifmca = idev->mc_list; ifmca;
+                    ifmca = ifmca->next, ip_idx++) {
+                       if (ip_idx < s_ip_idx)
+                               continue;
+                       err = inet6_fill_ifmcaddr(skb, ifmca,
+                                                 NETLINK_CB(cb->skb).pid,
+                                                 cb->nlh->nlmsg_seq,
+                                                 RTM_GETMULTICAST,
+                                                 NLM_F_MULTI);
+                       if (err <= 0)
+                               break;
+               }
+               break;
+       case ANYCAST_ADDR:
+               /* anycast address */
+               for (ifaca = idev->ac_list; ifaca;
+                    ifaca = ifaca->aca_next, ip_idx++) {
+                       if (ip_idx < s_ip_idx)
+                               continue;
+                       err = inet6_fill_ifacaddr(skb, ifaca,
+                                                 NETLINK_CB(cb->skb).pid,
+                                                 cb->nlh->nlmsg_seq,
+                                                 RTM_GETANYCAST,
+                                                 NLM_F_MULTI);
+                       if (err <= 0)
+                               break;
+               }
+               break;
+       default:
+               break;
+       }
+       read_unlock_bh(&idev->lock);
+       *p_ip_idx = ip_idx;
+       return err;
+}
+
 static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
                           enum addr_type_t type)
 {
+       struct net *net = sock_net(skb->sk);
+       int h, s_h;
        int idx, ip_idx;
        int s_idx, s_ip_idx;
-       int err = 1;
        struct net_device *dev;
-       struct inet6_dev *idev = NULL;
-       struct inet6_ifaddr *ifa;
-       struct ifmcaddr6 *ifmca;
-       struct ifacaddr6 *ifaca;
-       struct net *net = sock_net(skb->sk);
-
-       s_idx = cb->args[0];
-       s_ip_idx = ip_idx = cb->args[1];
+       struct inet6_dev *idev;
+       struct hlist_head *head;
+       struct hlist_node *node;
 
-       idx = 0;
-       for_each_netdev(net, dev) {
-               if (idx < s_idx)
-                       goto cont;
-               if (idx > s_idx)
-                       s_ip_idx = 0;
-               ip_idx = 0;
-               if ((idev = in6_dev_get(dev)) == NULL)
-                       goto cont;
-               read_lock_bh(&idev->lock);
-               switch (type) {
-               case UNICAST_ADDR:
-                       /* unicast address incl. temp addr */
-                       for (ifa = idev->addr_list; ifa;
-                            ifa = ifa->if_next, ip_idx++) {
-                               if (ip_idx < s_ip_idx)
-                                       continue;
-                               err = inet6_fill_ifaddr(skb, ifa,
-                                                       NETLINK_CB(cb->skb).pid,
-                                                       cb->nlh->nlmsg_seq,
-                                                       RTM_NEWADDR,
-                                                       NLM_F_MULTI);
-                       }
-                       break;
-               case MULTICAST_ADDR:
-                       /* multicast address */
-                       for (ifmca = idev->mc_list; ifmca;
-                            ifmca = ifmca->next, ip_idx++) {
-                               if (ip_idx < s_ip_idx)
-                                       continue;
-                               err = inet6_fill_ifmcaddr(skb, ifmca,
-                                                         NETLINK_CB(cb->skb).pid,
-                                                         cb->nlh->nlmsg_seq,
-                                                         RTM_GETMULTICAST,
-                                                         NLM_F_MULTI);
-                       }
-                       break;
-               case ANYCAST_ADDR:
-                       /* anycast address */
-                       for (ifaca = idev->ac_list; ifaca;
-                            ifaca = ifaca->aca_next, ip_idx++) {
-                               if (ip_idx < s_ip_idx)
-                                       continue;
-                               err = inet6_fill_ifacaddr(skb, ifaca,
-                                                         NETLINK_CB(cb->skb).pid,
-                                                         cb->nlh->nlmsg_seq,
-                                                         RTM_GETANYCAST,
-                                                         NLM_F_MULTI);
-                       }
-                       break;
-               default:
-                       break;
-               }
-               read_unlock_bh(&idev->lock);
-               in6_dev_put(idev);
+       s_h = cb->args[0];
+       s_idx = idx = cb->args[1];
+       s_ip_idx = ip_idx = cb->args[2];
 
-               if (err <= 0)
-                       break;
+       rcu_read_lock();
+       for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
+               idx = 0;
+               head = &net->dev_index_head[h];
+               hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
+                       if (idx < s_idx)
+                               goto cont;
+                       if (idx > s_idx)
+                               s_ip_idx = 0;
+                       ip_idx = 0;
+                       if ((idev = __in6_dev_get(dev)) == NULL)
+                               goto cont;
+
+                       if (in6_dump_addrs(idev, skb, cb, type,
+                                          s_ip_idx, &ip_idx) <= 0)
+                               goto done;
 cont:
-               idx++;
+                       idx++;
+               }
        }
-       cb->args[0] = idx;
-       cb->args[1] = ip_idx;
+done:
+       rcu_read_unlock();
+       cb->args[0] = h;
+       cb->args[1] = idx;
+       cb->args[2] = ip_idx;
+
        return skb->len;
 }
 
@@ -3708,6 +3733,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
 #endif
        array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6;
        array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad;
+       array[DEVCONF_FORCE_TLLAO] = cnf->force_tllao;
 }
 
 static inline size_t inet6_if_nlmsg_size(void)
@@ -3826,28 +3852,39 @@ nla_put_failure:
 static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 {
        struct net *net = sock_net(skb->sk);
-       int idx, err;
-       int s_idx = cb->args[0];
+       int h, s_h;
+       int idx = 0, s_idx;
        struct net_device *dev;
        struct inet6_dev *idev;
+       struct hlist_head *head;
+       struct hlist_node *node;
 
-       read_lock(&dev_base_lock);
-       idx = 0;
-       for_each_netdev(net, dev) {
-               if (idx < s_idx)
-                       goto cont;
-               if ((idev = in6_dev_get(dev)) == NULL)
-                       goto cont;
-               err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
-                               cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI);
-               in6_dev_put(idev);
-               if (err <= 0)
-                       break;
+       s_h = cb->args[0];
+       s_idx = cb->args[1];
+
+       rcu_read_lock();
+       for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
+               idx = 0;
+               head = &net->dev_index_head[h];
+               hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
+                       if (idx < s_idx)
+                               goto cont;
+                       idev = __in6_dev_get(dev);
+                       if (!idev)
+                               goto cont;
+                       if (inet6_fill_ifinfo(skb, idev,
+                                             NETLINK_CB(cb->skb).pid,
+                                             cb->nlh->nlmsg_seq,
+                                             RTM_NEWLINK, NLM_F_MULTI) <= 0)
+                               goto out;
 cont:
-               idx++;
+                       idx++;
+               }
        }
-       read_unlock(&dev_base_lock);
-       cb->args[0] = idx;
+out:
+       rcu_read_unlock();
+       cb->args[1] = idx;
+       cb->args[0] = h;
 
        return skb->len;
 }
@@ -4016,9 +4053,8 @@ static void addrconf_disable_change(struct net *net, __s32 newf)
        struct net_device *dev;
        struct inet6_dev *idev;
 
-       read_lock(&dev_base_lock);
-       for_each_netdev(net, dev) {
-               rcu_read_lock();
+       rcu_read_lock();
+       for_each_netdev_rcu(net, dev) {
                idev = __in6_dev_get(dev);
                if (idev) {
                        int changed = (!idev->cnf.disable_ipv6) ^ (!newf);
@@ -4026,9 +4062,8 @@ static void addrconf_disable_change(struct net *net, __s32 newf)
                        if (changed)
                                dev_disable_change(idev);
                }
-               rcu_read_unlock();
        }
-       read_unlock(&dev_base_lock);
+       rcu_read_unlock();
 }
 
 static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int old)
@@ -4285,6 +4320,13 @@ static struct addrconf_sysctl_table
                        .proc_handler   =       proc_dointvec,
                },
                {
+                       .procname       = "force_tllao",
+                       .data           = &ipv6_devconf.force_tllao,
+                       .maxlen         = sizeof(int),
+                       .mode           = 0644,
+                       .proc_handler   = proc_dointvec
+               },
+               {
                        /* sentinel */
                }
        },
@@ -4376,7 +4418,7 @@ static void addrconf_sysctl_unregister(struct inet6_dev *idev)
 
 #endif
 
-static int addrconf_init_net(struct net *net)
+static int __net_init addrconf_init_net(struct net *net)
 {
        int err;
        struct ipv6_devconf *all, *dflt;
@@ -4385,7 +4427,7 @@ static int addrconf_init_net(struct net *net)
        all = &ipv6_devconf;
        dflt = &ipv6_devconf_dflt;
 
-       if (net != &init_net) {
+       if (!net_eq(net, &init_net)) {
                all = kmemdup(all, sizeof(ipv6_devconf), GFP_KERNEL);
                if (all == NULL)
                        goto err_alloc_all;
@@ -4425,13 +4467,13 @@ err_alloc_all:
        return err;
 }
 
-static void addrconf_exit_net(struct net *net)
+static void __net_exit addrconf_exit_net(struct net *net)
 {
 #ifdef CONFIG_SYSCTL
        __addrconf_sysctl_unregister(net->ipv6.devconf_dflt);
        __addrconf_sysctl_unregister(net->ipv6.devconf_all);
 #endif
-       if (net != &init_net) {
+       if (!net_eq(net, &init_net)) {
                kfree(net->ipv6.devconf_dflt);
                kfree(net->ipv6.devconf_all);
        }