ide: update references to Documentation/ide/ide.txt (v2)
[safe/jmp/linux-2.6] / net / ipv6 / addrconf.c
index b2c38b3..101e0e7 100644 (file)
@@ -3,7 +3,7 @@
  *     Linux INET6 implementation
  *
  *     Authors:
- *     Pedro Roque             <roque@di.fc.ul.pt>     
+ *     Pedro Roque             <roque@di.fc.ul.pt>
  *     Alexey Kuznetsov        <kuznet@ms2.inr.ac.ru>
  *
  *     $Id: addrconf.c,v 1.69 2001/10/31 21:55:54 davem Exp $
@@ -44,7 +44,6 @@
 #include <linux/types.h>
 #include <linux/socket.h>
 #include <linux/sockios.h>
-#include <linux/sched.h>
 #include <linux/net.h>
 #include <linux/in6.h>
 #include <linux/netdevice.h>
@@ -63,6 +62,7 @@
 #include <linux/notifier.h>
 #include <linux/string.h>
 
+#include <net/net_namespace.h>
 #include <net/sock.h>
 #include <net/snmp.h>
 
@@ -74,6 +74,7 @@
 #include <net/tcp.h>
 #include <net/ip.h>
 #include <net/netlink.h>
+#include <net/pkt_sched.h>
 #include <linux/if_tunnel.h>
 #include <linux/rtnetlink.h>
 
@@ -82,6 +83,7 @@
 #endif
 
 #include <asm/uaccess.h>
+#include <asm/unaligned.h>
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b)))
 
 #ifdef CONFIG_SYSCTL
-static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p);
-static void addrconf_sysctl_unregister(struct ipv6_devconf *p);
+static void addrconf_sysctl_register(struct inet6_dev *idev);
+static void addrconf_sysctl_unregister(struct inet6_dev *idev);
+#else
+static inline void addrconf_sysctl_register(struct inet6_dev *idev)
+{
+}
+
+static inline void addrconf_sysctl_unregister(struct inet6_dev *idev)
+{
+}
 #endif
 
 #ifdef CONFIG_IPV6_PRIVACY
 static int __ipv6_regen_rndid(struct inet6_dev *idev);
-static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr); 
+static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr);
 static void ipv6_regen_rndid(unsigned long data);
 
 static int desync_factor = MAX_DESYNC_FACTOR * HZ;
@@ -119,9 +129,6 @@ static int ipv6_count_addresses(struct inet6_dev *idev);
 static struct inet6_ifaddr             *inet6_addr_lst[IN6_ADDR_HSIZE];
 static DEFINE_RWLOCK(addrconf_hash_lock);
 
-/* Protects inet6 devices */
-DEFINE_RWLOCK(addrconf_lock);
-
 static void addrconf_verify(unsigned long);
 
 static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0);
@@ -140,9 +147,10 @@ static void addrconf_rs_timer(unsigned long data);
 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
 
-static void inet6_prefix_notify(int event, struct inet6_dev *idev, 
+static void inet6_prefix_notify(int event, struct inet6_dev *idev,
                                struct prefix_info *pinfo);
-static int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev);
+static int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
+                             struct net_device *dev);
 
 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain);
 
@@ -175,6 +183,8 @@ struct ipv6_devconf ipv6_devconf __read_mostly = {
        .accept_ra_rt_info_max_plen = 0,
 #endif
 #endif
+       .proxy_ndp              = 0,
+       .accept_source_route    = 0,    /* we do not accept RH0 by default. */
 };
 
 static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
@@ -205,80 +215,18 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
        .accept_ra_rt_info_max_plen = 0,
 #endif
 #endif
+       .proxy_ndp              = 0,
+       .accept_source_route    = 0,    /* we do not accept RH0 by default. */
 };
 
 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
-#if 0
 const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
-#endif
 const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
 
-#define IPV6_ADDR_SCOPE_TYPE(scope)    ((scope) << 16)
-
-static inline unsigned ipv6_addr_scope2type(unsigned scope)
+/* Check if a valid qdisc is available */
+static inline int addrconf_qdisc_ok(struct net_device *dev)
 {
-       switch(scope) {
-       case IPV6_ADDR_SCOPE_NODELOCAL:
-               return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_NODELOCAL) |
-                       IPV6_ADDR_LOOPBACK);
-       case IPV6_ADDR_SCOPE_LINKLOCAL:
-               return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL) |
-                       IPV6_ADDR_LINKLOCAL);
-       case IPV6_ADDR_SCOPE_SITELOCAL:
-               return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL) |
-                       IPV6_ADDR_SITELOCAL);
-       }
-       return IPV6_ADDR_SCOPE_TYPE(scope);
-}
-
-int __ipv6_addr_type(const struct in6_addr *addr)
-{
-       u32 st;
-
-       st = addr->s6_addr32[0];
-
-       /* Consider all addresses with the first three bits different of
-          000 and 111 as unicasts.
-        */
-       if ((st & htonl(0xE0000000)) != htonl(0x00000000) &&
-           (st & htonl(0xE0000000)) != htonl(0xE0000000))
-               return (IPV6_ADDR_UNICAST | 
-                       IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL));
-
-       if ((st & htonl(0xFF000000)) == htonl(0xFF000000)) {
-               /* multicast */
-               /* addr-select 3.1 */
-               return (IPV6_ADDR_MULTICAST |
-                       ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr)));
-       }
-
-       if ((st & htonl(0xFFC00000)) == htonl(0xFE800000))
-               return (IPV6_ADDR_LINKLOCAL | IPV6_ADDR_UNICAST | 
-                       IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL));               /* addr-select 3.1 */
-       if ((st & htonl(0xFFC00000)) == htonl(0xFEC00000))
-               return (IPV6_ADDR_SITELOCAL | IPV6_ADDR_UNICAST |
-                       IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL));               /* addr-select 3.1 */
-
-       if ((addr->s6_addr32[0] | addr->s6_addr32[1]) == 0) {
-               if (addr->s6_addr32[2] == 0) {
-                       if (addr->s6_addr32[3] == 0)
-                               return IPV6_ADDR_ANY;
-
-                       if (addr->s6_addr32[3] == htonl(0x00000001))
-                               return (IPV6_ADDR_LOOPBACK | IPV6_ADDR_UNICAST |
-                                       IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL));       /* addr-select 3.4 */
-
-                       return (IPV6_ADDR_COMPATv4 | IPV6_ADDR_UNICAST |
-                               IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL));  /* addr-select 3.3 */
-               }
-
-               if (addr->s6_addr32[2] == htonl(0x0000ffff))
-                       return (IPV6_ADDR_MAPPED | 
-                               IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL));  /* addr-select 3.3 */
-       }
-
-       return (IPV6_ADDR_RESERVED | 
-               IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL));  /* addr-select 3.4 */
+       return (dev->qdisc != &noop_qdisc);
 }
 
 static void addrconf_del_timer(struct inet6_ifaddr *ifp)
@@ -314,8 +262,43 @@ static void addrconf_mod_timer(struct inet6_ifaddr *ifp,
        add_timer(&ifp->timer);
 }
 
+static int snmp6_alloc_dev(struct inet6_dev *idev)
+{
+       if (snmp_mib_init((void **)idev->stats.ipv6,
+                         sizeof(struct ipstats_mib)) < 0)
+               goto err_ip;
+       if (snmp_mib_init((void **)idev->stats.icmpv6,
+                         sizeof(struct icmpv6_mib)) < 0)
+               goto err_icmp;
+       if (snmp_mib_init((void **)idev->stats.icmpv6msg,
+                         sizeof(struct icmpv6msg_mib)) < 0)
+               goto err_icmpmsg;
+
+       return 0;
+
+err_icmpmsg:
+       snmp_mib_free((void **)idev->stats.icmpv6);
+err_icmp:
+       snmp_mib_free((void **)idev->stats.ipv6);
+err_ip:
+       return -ENOMEM;
+}
+
+static void snmp6_free_dev(struct inet6_dev *idev)
+{
+       snmp_mib_free((void **)idev->stats.icmpv6msg);
+       snmp_mib_free((void **)idev->stats.icmpv6);
+       snmp_mib_free((void **)idev->stats.ipv6);
+}
+
 /* Nobody refers to this device, we may destroy it. */
 
+static void in6_dev_finish_destroy_rcu(struct rcu_head *head)
+{
+       struct inet6_dev *idev = container_of(head, struct inet6_dev, rcu);
+       kfree(idev);
+}
+
 void in6_dev_finish_destroy(struct inet6_dev *idev)
 {
        struct net_device *dev = idev->dev;
@@ -330,26 +313,29 @@ void in6_dev_finish_destroy(struct inet6_dev *idev)
                return;
        }
        snmp6_free_dev(idev);
-       kfree(idev);
+       call_rcu(&idev->rcu, in6_dev_finish_destroy_rcu);
 }
 
+EXPORT_SYMBOL(in6_dev_finish_destroy);
+
 static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
 {
        struct inet6_dev *ndev;
+       struct in6_addr maddr;
 
        ASSERT_RTNL();
 
        if (dev->mtu < IPV6_MIN_MTU)
                return NULL;
 
-       ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
+       ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
 
-       if (ndev == NULL)
-               return NULL;
+       if (ndev == NULL)
+               return NULL;
 
        rwlock_init(&ndev->lock);
        ndev->dev = dev;
-       memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf));
+       memcpy(&ndev->cnf, dev->nd_net->ipv6.devconf_dflt, sizeof(ndev->cnf));
        ndev->cnf.mtu6 = dev->mtu;
        ndev->cnf.sysctl = NULL;
        ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
@@ -386,39 +372,43 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
        in6_dev_hold(ndev);
 
 #ifdef CONFIG_IPV6_PRIVACY
-       init_timer(&ndev->regen_timer);
-       ndev->regen_timer.function = ipv6_regen_rndid;
-       ndev->regen_timer.data = (unsigned long) ndev;
+       setup_timer(&ndev->regen_timer, ipv6_regen_rndid, (unsigned long)ndev);
        if ((dev->flags&IFF_LOOPBACK) ||
            dev->type == ARPHRD_TUNNEL ||
-           dev->type == ARPHRD_NONE ||
-           dev->type == ARPHRD_SIT) {
+#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
+           dev->type == ARPHRD_SIT ||
+#endif
+           dev->type == ARPHRD_NONE) {
                printk(KERN_INFO
                       "%s: Disabled Privacy Extensions\n",
                       dev->name);
                ndev->cnf.use_tempaddr = -1;
+
+               if (dev->type == ARPHRD_SIT && (dev->priv_flags & IFF_ISATAP)) {
+                       printk(KERN_INFO
+                              "%s: Disabled Multicast RS\n",
+                              dev->name);
+                       ndev->cnf.rtr_solicits = 0;
+               }
        } else {
                in6_dev_hold(ndev);
                ipv6_regen_rndid((unsigned long) ndev);
        }
 #endif
 
-       if (netif_carrier_ok(dev))
+       if (netif_running(dev) && addrconf_qdisc_ok(dev))
                ndev->if_flags |= IF_READY;
 
-       write_lock_bh(&addrconf_lock);
-       dev->ip6_ptr = ndev;
-       write_unlock_bh(&addrconf_lock);
-
        ipv6_mc_init_dev(ndev);
        ndev->tstamp = jiffies;
-#ifdef CONFIG_SYSCTL
-       neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6,
-                             NET_IPV6_NEIGH, "ipv6",
-                             &ndisc_ifinfo_sysctl_change,
-                             NULL);
-       addrconf_sysctl_register(ndev, &ndev->cnf);
-#endif
+       addrconf_sysctl_register(ndev);
+       /* protected by rtnl_lock */
+       rcu_assign_pointer(dev->ip6_ptr, ndev);
+
+       /* Join all-node multicast group */
+       ipv6_addr_all_nodes(&maddr);
+       ipv6_dev_mc_inc(dev, &maddr);
+
        return ndev;
 }
 
@@ -450,13 +440,15 @@ static void dev_forward_change(struct inet6_dev *idev)
        dev = idev->dev;
        if (dev && (dev->flags & IFF_MULTICAST)) {
                ipv6_addr_all_routers(&addr);
-       
+
                if (idev->cnf.forwarding)
                        ipv6_dev_mc_inc(dev, &addr);
                else
                        ipv6_dev_mc_dec(dev, &addr);
        }
        for (ifa=idev->addr_list; ifa; ifa=ifa->if_next) {
+               if (ifa->flags&IFA_F_TENTATIVE)
+                       continue;
                if (idev->cnf.forwarding)
                        addrconf_join_anycast(ifa);
                else
@@ -465,25 +457,44 @@ static void dev_forward_change(struct inet6_dev *idev)
 }
 
 
-static void addrconf_forward_change(void)
+static void addrconf_forward_change(struct net *net, __s32 newf)
 {
        struct net_device *dev;
        struct inet6_dev *idev;
 
        read_lock(&dev_base_lock);
-       for (dev=dev_base; dev; dev=dev->next) {
-               read_lock(&addrconf_lock);
+       for_each_netdev(net, dev) {
+               rcu_read_lock();
                idev = __in6_dev_get(dev);
                if (idev) {
-                       int changed = (!idev->cnf.forwarding) ^ (!ipv6_devconf.forwarding);
-                       idev->cnf.forwarding = ipv6_devconf.forwarding;
+                       int changed = (!idev->cnf.forwarding) ^ (!newf);
+                       idev->cnf.forwarding = newf;
                        if (changed)
                                dev_forward_change(idev);
                }
-               read_unlock(&addrconf_lock);
+               rcu_read_unlock();
        }
        read_unlock(&dev_base_lock);
 }
+
+static void addrconf_fixup_forwarding(struct ctl_table *table, int *p, int old)
+{
+       struct net *net;
+
+       net = (struct net *)table->extra2;
+       if (p == &net->ipv6.devconf_dflt->forwarding)
+               return;
+
+       if (p == &net->ipv6.devconf_all->forwarding) {
+               __s32 newf = net->ipv6.devconf_all->forwarding;
+               net->ipv6.devconf_dflt->forwarding = newf;
+               addrconf_forward_change(net, newf);
+       } else if ((!*p) ^ (!old))
+               dev_forward_change((struct inet6_dev *)table->extra1);
+
+       if (*p)
+               rt6_purge_dflt_routers();
+}
 #endif
 
 /* Nobody refers to this ifaddr, destroy it */
@@ -541,7 +552,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
        int hash;
        int err = 0;
 
-       read_lock_bh(&addrconf_lock);
+       rcu_read_lock_bh();
        if (idev->dead) {
                err = -ENODEV;                  /*XXX*/
                goto out2;
@@ -550,7 +561,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
        write_lock(&addrconf_hash_lock);
 
        /* Ignore adding duplicate addresses on an interface */
-       if (ipv6_chk_same_addr(addr, idev->dev)) {
+       if (ipv6_chk_same_addr(&init_net, addr, idev->dev)) {
                ADBG(("ipv6_add_addr: already assigned\n"));
                err = -EEXIST;
                goto out;
@@ -582,6 +593,16 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
 
        ifa->rt = rt;
 
+       /*
+        * part one of RFC 4429, section 3.3
+        * We should not configure an address as
+        * optimistic if we do not yet know the link
+        * layer address of our nexhop router
+        */
+
+       if (rt->rt6i_nexthop == NULL)
+               ifa->flags &= ~IFA_F_OPTIMISTIC;
+
        ifa->idev = idev;
        in6_dev_hold(idev);
        /* For caller */
@@ -610,7 +631,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
        in6_ifa_hold(ifa);
        write_unlock(&idev->lock);
 out2:
-       read_unlock_bh(&addrconf_lock);
+       rcu_read_unlock_bh();
 
        if (likely(err == 0))
                atomic_notifier_call_chain(&inet6addr_chain, NETDEV_UP, ifa);
@@ -758,6 +779,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *i
        int tmp_plen;
        int ret = 0;
        int max_addresses;
+       u32 addr_flags;
 
        write_lock(&idev->lock);
        if (ift) {
@@ -805,8 +827,8 @@ retry:
        tmp_valid_lft = min_t(__u32,
                              ifp->valid_lft,
                              idev->cnf.temp_valid_lft);
-       tmp_prefered_lft = min_t(__u32, 
-                                ifp->prefered_lft, 
+       tmp_prefered_lft = min_t(__u32,
+                                ifp->prefered_lft,
                                 idev->cnf.temp_prefered_lft - desync_factor / HZ);
        tmp_plen = ifp->prefix_len;
        max_addresses = idev->cnf.max_addresses;
@@ -815,10 +837,17 @@ retry:
        spin_unlock_bh(&ifp->lock);
 
        write_unlock(&idev->lock);
+
+       addr_flags = IFA_F_TEMPORARY;
+       /* set in addrconf_prefix_rcv() */
+       if (ifp->flags & IFA_F_OPTIMISTIC)
+               addr_flags |= IFA_F_OPTIMISTIC;
+
        ift = !max_addresses ||
-             ipv6_count_addresses(idev) < max_addresses ? 
+             ipv6_count_addresses(idev) < max_addresses ?
                ipv6_add_addr(idev, &addr, tmp_plen,
-                             ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK, IFA_F_TEMPORARY) : NULL;
+                             ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK,
+                             addr_flags) : NULL;
        if (!ift || IS_ERR(ift)) {
                in6_ifa_put(ifp);
                in6_dev_put(idev);
@@ -863,7 +892,7 @@ struct ipv6_saddr_score {
 #define IPV6_SADDR_SCORE_LABEL         0x0020
 #define IPV6_SADDR_SCORE_PRIVACY       0x0040
 
-static int inline ipv6_saddr_preferred(int type)
+static inline int ipv6_saddr_preferred(int type)
 {
        if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|
                    IPV6_ADDR_LOOPBACK|IPV6_ADDR_RESERVED))
@@ -871,35 +900,6 @@ static int inline ipv6_saddr_preferred(int type)
        return 0;
 }
 
-/* static matching label */
-static int inline ipv6_saddr_label(const struct in6_addr *addr, int type)
-{
- /*
-  *    prefix (longest match)  label
-  *    -----------------------------
-  *    ::1/128                 0
-  *    ::/0                    1
-  *    2002::/16               2
-  *    ::/96                   3
-  *    ::ffff:0:0/96           4
-  *    fc00::/7                5
-  *    2001::/32               6
-  */
-       if (type & IPV6_ADDR_LOOPBACK)
-               return 0;
-       else if (type & IPV6_ADDR_COMPATv4)
-               return 3;
-       else if (type & IPV6_ADDR_MAPPED)
-               return 4;
-       else if (addr->s6_addr32[0] == htonl(0x20010000))
-               return 6;
-       else if (addr->s6_addr16[0] == htons(0x2002))
-               return 2;
-       else if ((addr->s6_addr[0] & 0xfe) == 0xfc)
-               return 5;
-       return 1;
-}
-
 int ipv6_dev_get_saddr(struct net_device *daddr_dev,
                       struct in6_addr *daddr, struct in6_addr *saddr)
 {
@@ -907,15 +907,16 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev,
        struct inet6_ifaddr *ifa_result = NULL;
        int daddr_type = __ipv6_addr_type(daddr);
        int daddr_scope = __ipv6_addr_src_scope(daddr_type);
-       u32 daddr_label = ipv6_saddr_label(daddr, daddr_type);
+       int daddr_ifindex = daddr_dev ? daddr_dev->ifindex : 0;
+       u32 daddr_label = ipv6_addr_label(daddr, daddr_type, daddr_ifindex);
        struct net_device *dev;
 
        memset(&hiscore, 0, sizeof(hiscore));
 
        read_lock(&dev_base_lock);
-       read_lock(&addrconf_lock);
+       rcu_read_lock();
 
-       for (dev = dev_base; dev; dev=dev->next) {
+       for_each_netdev(&init_net, dev) {
                struct inet6_dev *idev;
                struct inet6_ifaddr *ifa;
 
@@ -950,18 +951,19 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev,
                         * - Tentative Address (RFC2462 section 5.4)
                         *  - A tentative address is not considered
                         *    "assigned to an interface" in the traditional
-                        *    sense.
+                        *    sense, unless it is also flagged as optimistic.
                         * - Candidate Source Address (section 4)
                         *  - In any case, anycast addresses, multicast
                         *    addresses, and the unspecified address MUST
                         *    NOT be included in a candidate set.
                         */
-                       if (ifa->flags & IFA_F_TENTATIVE)
+                       if ((ifa->flags & IFA_F_TENTATIVE) &&
+                           (!(ifa->flags & IFA_F_OPTIMISTIC)))
                                continue;
                        if (unlikely(score.addr_type == IPV6_ADDR_ANY ||
                                     score.addr_type & IPV6_ADDR_MULTICAST)) {
                                LIMIT_NETDEBUG(KERN_DEBUG
-                                              "ADDRCONF: unspecified / multicast address"
+                                              "ADDRCONF: unspecified / multicast address "
                                               "assigned as unicast address on %s",
                                               dev->name);
                                continue;
@@ -1015,15 +1017,17 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev,
                                }
                        }
 
-                       /* Rule 3: Avoid deprecated address */
+                       /* Rule 3: Avoid deprecated and optimistic addresses */
                        if (hiscore.rule < 3) {
                                if (ipv6_saddr_preferred(hiscore.addr_type) ||
-                                   !(ifa_result->flags & IFA_F_DEPRECATED))
+                                  (((ifa_result->flags &
+                                   (IFA_F_DEPRECATED|IFA_F_OPTIMISTIC)) == 0)))
                                        hiscore.attrs |= IPV6_SADDR_SCORE_PREFERRED;
                                hiscore.rule++;
                        }
                        if (ipv6_saddr_preferred(score.addr_type) ||
-                           !(ifa->flags & IFA_F_DEPRECATED)) {
+                          (((ifa->flags &
+                           (IFA_F_DEPRECATED|IFA_F_OPTIMISTIC)) == 0))) {
                                score.attrs |= IPV6_SADDR_SCORE_PREFERRED;
                                if (!(hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)) {
                                        score.rule = 3;
@@ -1034,9 +1038,27 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev,
                                        continue;
                        }
 
-                       /* Rule 4: Prefer home address -- not implemented yet */
+                       /* Rule 4: Prefer home address */
+#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
+                       if (hiscore.rule < 4) {
+                               if (ifa_result->flags & IFA_F_HOMEADDRESS)
+                                       hiscore.attrs |= IPV6_SADDR_SCORE_HOA;
+                               hiscore.rule++;
+                       }
+                       if (ifa->flags & IFA_F_HOMEADDRESS) {
+                               score.attrs |= IPV6_SADDR_SCORE_HOA;
+                               if (!(ifa_result->flags & IFA_F_HOMEADDRESS)) {
+                                       score.rule = 4;
+                                       goto record_it;
+                               }
+                       } else {
+                               if (hiscore.attrs & IPV6_SADDR_SCORE_HOA)
+                                       continue;
+                       }
+#else
                        if (hiscore.rule < 4)
                                hiscore.rule++;
+#endif
 
                        /* Rule 5: Prefer outgoing interface */
                        if (hiscore.rule < 5) {
@@ -1059,11 +1081,15 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev,
 
                        /* Rule 6: Prefer matching label */
                        if (hiscore.rule < 6) {
-                               if (ipv6_saddr_label(&ifa_result->addr, hiscore.addr_type) == daddr_label)
+                               if (ipv6_addr_label(&ifa_result->addr,
+                                                   hiscore.addr_type,
+                                                   ifa_result->idev->dev->ifindex) == daddr_label)
                                        hiscore.attrs |= IPV6_SADDR_SCORE_LABEL;
                                hiscore.rule++;
                        }
-                       if (ipv6_saddr_label(&ifa->addr, score.addr_type) == daddr_label) {
+                       if (ipv6_addr_label(&ifa->addr,
+                                           score.addr_type,
+                                           ifa->idev->dev->ifindex) == daddr_label) {
                                score.attrs |= IPV6_SADDR_SCORE_LABEL;
                                if (!(hiscore.attrs & IPV6_SADDR_SCORE_LABEL)) {
                                        score.rule = 6;
@@ -1125,12 +1151,12 @@ record_it:
                }
                read_unlock_bh(&idev->lock);
        }
-       read_unlock(&addrconf_lock);
+       rcu_read_unlock();
        read_unlock(&dev_base_lock);
 
        if (!ifa_result)
                return -EADDRNOTAVAIL;
-       
+
        ipv6_addr_copy(saddr, &ifa_result->addr);
        in6_ifa_put(ifa_result);
        return 0;
@@ -1140,22 +1166,24 @@ record_it:
 int ipv6_get_saddr(struct dst_entry *dst,
                   struct in6_addr *daddr, struct in6_addr *saddr)
 {
-       return ipv6_dev_get_saddr(dst ? ((struct rt6_info *)dst)->rt6i_idev->dev : NULL, daddr, saddr);
+       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
 }
 
+EXPORT_SYMBOL(ipv6_get_saddr);
 
-int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr)
+int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
+                   unsigned char banned_flags)
 {
        struct inet6_dev *idev;
        int err = -EADDRNOTAVAIL;
 
-       read_lock(&addrconf_lock);
+       rcu_read_lock();
        if ((idev = __in6_dev_get(dev)) != NULL) {
                struct inet6_ifaddr *ifp;
 
                read_lock_bh(&idev->lock);
                for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
-                       if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
+                       if (ifp->scope == IFA_LINK && !(ifp->flags & banned_flags)) {
                                ipv6_addr_copy(addr, &ifp->addr);
                                err = 0;
                                break;
@@ -1163,7 +1191,7 @@ int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr)
                }
                read_unlock_bh(&idev->lock);
        }
-       read_unlock(&addrconf_lock);
+       rcu_read_unlock();
        return err;
 }
 
@@ -1179,13 +1207,16 @@ static int ipv6_count_addresses(struct inet6_dev *idev)
        return cnt;
 }
 
-int ipv6_chk_addr(struct in6_addr *addr, struct net_device *dev, int strict)
+int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
+                 struct net_device *dev, int strict)
 {
        struct inet6_ifaddr * ifp;
        u8 hash = ipv6_addr_hash(addr);
 
        read_lock_bh(&addrconf_hash_lock);
        for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
+               if (ifp->idev->dev->nd_net != net)
+                       continue;
                if (ipv6_addr_equal(&ifp->addr, addr) &&
                    !(ifp->flags&IFA_F_TENTATIVE)) {
                        if (dev == NULL || ifp->idev->dev == dev ||
@@ -1196,14 +1227,18 @@ int ipv6_chk_addr(struct in6_addr *addr, struct net_device *dev, int strict)
        read_unlock_bh(&addrconf_hash_lock);
        return ifp != NULL;
 }
+EXPORT_SYMBOL(ipv6_chk_addr);
 
 static
-int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev)
+int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
+                      struct net_device *dev)
 {
        struct inet6_ifaddr * ifp;
        u8 hash = ipv6_addr_hash(addr);
 
        for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
+               if (ifp->idev->dev->nd_net != net)
+                       continue;
                if (ipv6_addr_equal(&ifp->addr, addr)) {
                        if (dev == NULL || ifp->idev->dev == dev)
                                break;
@@ -1212,13 +1247,16 @@ int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev)
        return ifp != NULL;
 }
 
-struct inet6_ifaddr * ipv6_get_ifaddr(struct in6_addr *addr, struct net_device *dev, int strict)
+struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, struct in6_addr *addr,
+                                    struct net_device *dev, int strict)
 {
        struct inet6_ifaddr * ifp;
        u8 hash = ipv6_addr_hash(addr);
 
        read_lock_bh(&addrconf_hash_lock);
        for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
+               if (ifp->idev->dev->nd_net != net)
+                       continue;
                if (ipv6_addr_equal(&ifp->addr, addr)) {
                        if (dev == NULL || ifp->idev->dev == dev ||
                            !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) {
@@ -1236,8 +1274,8 @@ int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
 {
        const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
        const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
-       u32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
-       u32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
+       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
+       __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
        int sk_ipv6only = ipv6_only_sock(sk);
        int sk2_ipv6only = inet_v6_ipv6only(sk2);
        int addr_type = ipv6_addr_type(sk_rcv_saddr6);
@@ -1405,6 +1443,9 @@ static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
                return addrconf_ifid_arcnet(eui, dev);
        case ARPHRD_INFINIBAND:
                return addrconf_ifid_infiniband(eui, dev);
+       case ARPHRD_SIT:
+               if (dev->priv_flags & IFF_ISATAP)
+                       return ipv6_isatap_eui64(eui, *(__be32 *)dev->dev_addr);
        }
        return -1;
 }
@@ -1440,12 +1481,12 @@ regen:
         *
         *  - Reserved subnet anycast (RFC 2526)
         *      11111101 11....11 1xxxxxxx
-        *  - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1
+        *  - ISATAP (RFC4214) 6.1
         *      00-00-5E-FE-xx-xx-xx-xx
         *  - value 0
         *  - XXX: already assigned to an address on the device
         */
-       if (idev->rndid[0] == 0xfd && 
+       if (idev->rndid[0] == 0xfd &&
            (idev->rndid[1]&idev->rndid[2]&idev->rndid[3]&idev->rndid[4]&idev->rndid[5]&idev->rndid[6]) == 0xff &&
            (idev->rndid[7]&0x80))
                goto regen;
@@ -1464,7 +1505,7 @@ static void ipv6_regen_rndid(unsigned long data)
        struct inet6_dev *idev = (struct inet6_dev *) data;
        unsigned long expires;
 
-       read_lock_bh(&addrconf_lock);
+       rcu_read_lock_bh();
        write_lock_bh(&idev->lock);
 
        if (idev->dead)
@@ -1472,9 +1513,9 @@ static void ipv6_regen_rndid(unsigned long data)
 
        if (__ipv6_regen_rndid(idev) < 0)
                goto out;
-       
+
        expires = jiffies +
-               idev->cnf.temp_prefered_lft * HZ - 
+               idev->cnf.temp_prefered_lft * HZ -
                idev->cnf.regen_max_retry * idev->cnf.dad_transmits * idev->nd_parms->retrans_time - desync_factor;
        if (time_before(expires, jiffies)) {
                printk(KERN_WARNING
@@ -1488,7 +1529,7 @@ static void ipv6_regen_rndid(unsigned long data)
 
 out:
        write_unlock_bh(&idev->lock);
-       read_unlock_bh(&addrconf_lock);
+       rcu_read_unlock_bh();
        in6_dev_put(idev);
 }
 
@@ -1516,6 +1557,7 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
                .fc_expires = expires,
                .fc_dst_len = plen,
                .fc_flags = RTF_UP | flags,
+               .fc_nlinfo.nl_net = &init_net,
        };
 
        ipv6_addr_copy(&cfg.fc_dst, pfx);
@@ -1524,8 +1566,10 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
           This thing is done here expecting that the whole
           class of non-broadcast devices need not cloning.
         */
+#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
        if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT))
                cfg.fc_flags |= RTF_NONEXTHOP;
+#endif
 
        ip6_route_add(&cfg);
 }
@@ -1540,6 +1584,7 @@ static void addrconf_add_mroute(struct net_device *dev)
                .fc_ifindex = dev->ifindex,
                .fc_dst_len = 8,
                .fc_flags = RTF_UP,
+               .fc_nlinfo.nl_net = &init_net,
        };
 
        ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
@@ -1547,6 +1592,7 @@ static void addrconf_add_mroute(struct net_device *dev)
        ip6_route_add(&cfg);
 }
 
+#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
 static void sit_route_add(struct net_device *dev)
 {
        struct fib6_config cfg = {
@@ -1555,11 +1601,13 @@ static void sit_route_add(struct net_device *dev)
                .fc_ifindex = dev->ifindex,
                .fc_dst_len = 96,
                .fc_flags = RTF_UP | RTF_NONEXTHOP,
+               .fc_nlinfo.nl_net = &init_net,
        };
 
        /* prefix length - 96 bits "::d.d.d.d" */
        ip6_route_add(&cfg);
 }
+#endif
 
 static void addrconf_add_lroute(struct net_device *dev)
 {
@@ -1596,12 +1644,12 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
        struct inet6_dev *in6_dev;
 
        pinfo = (struct prefix_info *) opt;
-       
+
        if (len < sizeof(struct prefix_info)) {
                ADBG(("addrconf: prefix option too short\n"));
                return;
        }
-       
+
        /*
         *      Validation checks ([ADDRCONF], page 19)
         */
@@ -1697,10 +1745,17 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
 
 ok:
 
-               ifp = ipv6_get_ifaddr(&addr, dev, 1);
+               ifp = ipv6_get_ifaddr(&init_net, &addr, dev, 1);
 
                if (ifp == NULL && valid_lft) {
                        int max_addresses = in6_dev->cnf.max_addresses;
+                       u32 addr_flags = 0;
+
+#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
+                       if (in6_dev->cnf.optimistic_dad &&
+                           !ipv6_devconf.forwarding)
+                               addr_flags = IFA_F_OPTIMISTIC;
+#endif
 
                        /* Do not allow to create too much of autoconfigured
                         * addresses; this would be too easy way to crash kernel.
@@ -1708,7 +1763,8 @@ ok:
                        if (!max_addresses ||
                            ipv6_count_addresses(in6_dev) < max_addresses)
                                ifp = ipv6_add_addr(in6_dev, &addr, pinfo->prefix_len,
-                                                   addr_type&IPV6_ADDR_SCOPE_MASK, 0);
+                                                   addr_type&IPV6_ADDR_SCOPE_MASK,
+                                                   addr_flags);
 
                        if (!ifp || IS_ERR(ifp)) {
                                in6_dev_put(in6_dev);
@@ -1793,7 +1849,7 @@ ok:
                                 * When a new public address is created as described in [ADDRCONF],
                                 * also create a new temporary address.
                                 */
-                               read_unlock_bh(&in6_dev->lock); 
+                               read_unlock_bh(&in6_dev->lock);
                                ipv6_create_tempaddr(ifp, NULL);
                        } else {
                                read_unlock_bh(&in6_dev->lock);
@@ -1824,12 +1880,13 @@ int addrconf_set_dstaddr(void __user *arg)
        if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
                goto err_exit;
 
-       dev = __dev_get_by_index(ireq.ifr6_ifindex);
+       dev = __dev_get_by_index(&init_net, ireq.ifr6_ifindex);
 
        err = -ENODEV;
        if (dev == NULL)
                goto err_exit;
 
+#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
        if (dev->type == ARPHRD_SIT) {
                struct ifreq ifr;
                mm_segment_t    oldfs;
@@ -1846,7 +1903,7 @@ int addrconf_set_dstaddr(void __user *arg)
                p.iph.ihl = 5;
                p.iph.protocol = IPPROTO_IPV6;
                p.iph.ttl = 64;
-               ifr.ifr_ifru.ifru_data = (void __user *)&p;
+               ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
 
                oldfs = get_fs(); set_fs(KERNEL_DS);
                err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
@@ -1854,11 +1911,12 @@ int addrconf_set_dstaddr(void __user *arg)
 
                if (err == 0) {
                        err = -ENOBUFS;
-                       if ((dev = __dev_get_by_name(p.name)) == NULL)
+                       if ((dev = __dev_get_by_name(&init_net, p.name)) == NULL)
                                goto err_exit;
                        err = dev_open(dev);
                }
        }
+#endif
 
 err_exit:
        rtnl_unlock();
@@ -1869,34 +1927,32 @@ err_exit:
  *     Manual configuration of address on an interface
  */
 static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
-                         __u32 prefered_lft, __u32 valid_lft)
+                         __u8 ifa_flags, __u32 prefered_lft, __u32 valid_lft)
 {
        struct inet6_ifaddr *ifp;
        struct inet6_dev *idev;
        struct net_device *dev;
-       __u8 ifa_flags = 0;
        int scope;
+       u32 flags = RTF_EXPIRES;
 
        ASSERT_RTNL();
-       
+
        /* check the lifetime */
        if (!valid_lft || prefered_lft > valid_lft)
                return -EINVAL;
 
-       if ((dev = __dev_get_by_index(ifindex)) == NULL)
+       if ((dev = __dev_get_by_index(&init_net, ifindex)) == NULL)
                return -ENODEV;
-       
-       if (!(dev->flags&IFF_UP))
-               return -ENETDOWN;
 
        if ((idev = addrconf_add_dev(dev)) == NULL)
                return -ENOBUFS;
 
        scope = ipv6_addr_scope(pfx);
 
-       if (valid_lft == INFINITY_LIFE_TIME)
+       if (valid_lft == INFINITY_LIFE_TIME) {
                ifa_flags |= IFA_F_PERMANENT;
-       else if (valid_lft >= 0x7FFFFFFF/HZ)
+               flags = 0;
+       } else if (valid_lft >= 0x7FFFFFFF/HZ)
                valid_lft = 0x7FFFFFFF/HZ;
 
        if (prefered_lft == 0)
@@ -1914,6 +1970,13 @@ static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
                ifp->tstamp = jiffies;
                spin_unlock_bh(&ifp->lock);
 
+               addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev,
+                                     jiffies_to_clock_t(valid_lft * HZ), flags);
+               /*
+                * Note that section 3.1 of RFC 4429 indicates
+                * that the Optimistic flag should not be set for
+                * manually configured addresses
+                */
                addrconf_dad_start(ifp, 0);
                in6_ifa_put(ifp);
                addrconf_verify(0);
@@ -1928,8 +1991,8 @@ static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen)
        struct inet6_ifaddr *ifp;
        struct inet6_dev *idev;
        struct net_device *dev;
-       
-       if ((dev = __dev_get_by_index(ifindex)) == NULL)
+
+       if ((dev = __dev_get_by_index(&init_net, ifindex)) == NULL)
                return -ENODEV;
 
        if ((idev = __in6_dev_get(dev)) == NULL)
@@ -1941,7 +2004,7 @@ static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen)
                    ipv6_addr_equal(pfx, &ifp->addr)) {
                        in6_ifa_hold(ifp);
                        read_unlock_bh(&idev->lock);
-                       
+
                        ipv6_del_addr(ifp);
 
                        /* If the last address is deleted administratively,
@@ -1961,16 +2024,16 @@ int addrconf_add_ifaddr(void __user *arg)
 {
        struct in6_ifreq ireq;
        int err;
-       
+
        if (!capable(CAP_NET_ADMIN))
                return -EPERM;
-       
+
        if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
                return -EFAULT;
 
        rtnl_lock();
        err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen,
-                            INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
+                            IFA_F_PERMANENT, INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
        rtnl_unlock();
        return err;
 }
@@ -1979,7 +2042,7 @@ int addrconf_del_ifaddr(void __user *arg)
 {
        struct in6_ifreq ireq;
        int err;
-       
+
        if (!capable(CAP_NET_ADMIN))
                return -EPERM;
 
@@ -1992,6 +2055,7 @@ int addrconf_del_ifaddr(void __user *arg)
        return err;
 }
 
+#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
 static void sit_add_v4_addrs(struct inet6_dev *idev)
 {
        struct inet6_ifaddr * ifp;
@@ -2023,7 +2087,7 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
                return;
        }
 
-        for (dev = dev_base; dev != NULL; dev = dev->next) {
+       for_each_netdev(&init_net, dev) {
                struct in_device * in_dev = __in_dev_get_rtnl(dev);
                if (in_dev && (dev->flags & IFF_UP)) {
                        struct in_ifaddr * ifa;
@@ -2058,8 +2122,9 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
                                }
                        }
                }
-        }
+       }
 }
+#endif
 
 static void init_loopback(struct net_device *dev)
 {
@@ -2088,9 +2153,18 @@ static void init_loopback(struct net_device *dev)
 static void addrconf_add_linklocal(struct inet6_dev *idev, struct in6_addr *addr)
 {
        struct inet6_ifaddr * ifp;
+       u32 addr_flags = IFA_F_PERMANENT;
+
+#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
+       if (idev->cnf.optimistic_dad &&
+           !ipv6_devconf.forwarding)
+               addr_flags |= IFA_F_OPTIMISTIC;
+#endif
+
 
-       ifp = ipv6_add_addr(idev, addr, 64, IFA_LINK, IFA_F_PERMANENT);
+       ifp = ipv6_add_addr(idev, addr, 64, IFA_LINK, addr_flags);
        if (!IS_ERR(ifp)) {
+               addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0);
                addrconf_dad_start(ifp, 0);
                in6_ifa_put(ifp);
        }
@@ -2103,7 +2177,7 @@ static void addrconf_dev_config(struct net_device *dev)
 
        ASSERT_RTNL();
 
-       if ((dev->type != ARPHRD_ETHER) && 
+       if ((dev->type != ARPHRD_ETHER) &&
            (dev->type != ARPHRD_FDDI) &&
            (dev->type != ARPHRD_IEEE802_TR) &&
            (dev->type != ARPHRD_ARCNET) &&
@@ -2123,15 +2197,16 @@ static void addrconf_dev_config(struct net_device *dev)
                addrconf_add_linklocal(idev, &addr);
 }
 
+#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
 static void addrconf_sit_config(struct net_device *dev)
 {
        struct inet6_dev *idev;
 
        ASSERT_RTNL();
 
-       /* 
-        * Configure the tunnel with one of our IPv4 
-        * addresses... we should configure all of 
+       /*
+        * Configure the tunnel with one of our IPv4
+        * addresses... we should configure all of
         * our v4 addrs in the tunnel
         */
 
@@ -2140,6 +2215,16 @@ static void addrconf_sit_config(struct net_device *dev)
                return;
        }
 
+       if (dev->priv_flags & IFF_ISATAP) {
+               struct in6_addr addr;
+
+               ipv6_addr_set(&addr,  htonl(0xFE800000), 0, 0, 0);
+               addrconf_prefix_route(&addr, 64, dev, 0, 0);
+               if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
+                       addrconf_add_linklocal(idev, &addr);
+               return;
+       }
+
        sit_add_v4_addrs(idev);
 
        if (dev->flags&IFF_POINTOPOINT) {
@@ -2148,13 +2233,14 @@ static void addrconf_sit_config(struct net_device *dev)
        } else
                sit_route_add(dev);
 }
+#endif
 
 static inline int
 ipv6_inherit_linklocal(struct inet6_dev *idev, struct net_device *link_dev)
 {
        struct in6_addr lladdr;
 
-       if (!ipv6_get_lladdr(link_dev, &lladdr)) {
+       if (!ipv6_get_lladdr(link_dev, &lladdr, IFA_F_TENTATIVE)) {
                addrconf_add_linklocal(idev, &lladdr);
                return 0;
        }
@@ -2167,12 +2253,12 @@ static void ip6_tnl_add_linklocal(struct inet6_dev *idev)
 
        /* first try to inherit the link-local address from the link device */
        if (idev->dev->iflink &&
-           (link_dev = __dev_get_by_index(idev->dev->iflink))) {
+           (link_dev = __dev_get_by_index(&init_net, idev->dev->iflink))) {
                if (!ipv6_inherit_linklocal(idev, link_dev))
                        return;
        }
        /* then try to inherit it from any device */
-       for (link_dev = dev_base; link_dev; link_dev = link_dev->next) {
+       for_each_netdev(&init_net, link_dev) {
                if (!ipv6_inherit_linklocal(idev, link_dev))
                        return;
        }
@@ -2197,18 +2283,32 @@ static void addrconf_ip6_tnl_config(struct net_device *dev)
        ip6_tnl_add_linklocal(idev);
 }
 
-static int addrconf_notify(struct notifier_block *this, unsigned long event, 
+static int addrconf_notify(struct notifier_block *this, unsigned long event,
                           void * data)
 {
        struct net_device *dev = (struct net_device *) data;
        struct inet6_dev *idev = __in6_dev_get(dev);
        int run_pending = 0;
+       int err;
+
+       if (dev->nd_net != &init_net)
+               return NOTIFY_DONE;
 
        switch(event) {
+       case NETDEV_REGISTER:
+               if (!idev && dev->mtu >= IPV6_MIN_MTU) {
+                       idev = ipv6_add_dev(dev);
+                       if (!idev)
+                               return notifier_from_errno(-ENOMEM);
+               }
+               break;
        case NETDEV_UP:
        case NETDEV_CHANGE:
+               if (dev->flags & IFF_SLAVE)
+                       break;
+
                if (event == NETDEV_UP) {
-                       if (!netif_carrier_ok(dev)) {
+                       if (!addrconf_qdisc_ok(dev)) {
                                /* device is not ready yet. */
                                printk(KERN_INFO
                                        "ADDRCONF(NETDEV_UP): %s: "
@@ -2217,10 +2317,13 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
                                break;
                        }
 
+                       if (!idev && dev->mtu >= IPV6_MIN_MTU)
+                               idev = ipv6_add_dev(dev);
+
                        if (idev)
                                idev->if_flags |= IF_READY;
                } else {
-                       if (!netif_carrier_ok(dev)) {
+                       if (!addrconf_qdisc_ok(dev)) {
                                /* device is still not ready. */
                                break;
                        }
@@ -2242,9 +2345,11 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
                }
 
                switch(dev->type) {
+#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
                case ARPHRD_SIT:
                        addrconf_sit_config(dev);
                        break;
+#endif
                case ARPHRD_TUNNEL6:
                        addrconf_ip6_tnl_config(dev);
                        break;
@@ -2255,7 +2360,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
                default:
                        addrconf_dev_config(dev);
                        break;
-               };
+               }
                if (idev) {
                        if (run_pending)
                                addrconf_dad_run(idev);
@@ -2279,12 +2384,18 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
                break;
 
        case NETDEV_CHANGEMTU:
-               if ( idev && dev->mtu >= IPV6_MIN_MTU) {
+               if (idev && dev->mtu >= IPV6_MIN_MTU) {
                        rt6_mtu_change(dev, dev->mtu);
                        idev->cnf.mtu6 = dev->mtu;
                        break;
                }
 
+               if (!idev && dev->mtu >= IPV6_MIN_MTU) {
+                       idev = ipv6_add_dev(dev);
+                       if (idev)
+                               break;
+               }
+
                /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
 
        case NETDEV_DOWN:
@@ -2296,19 +2407,16 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
                break;
 
        case NETDEV_CHANGENAME:
-#ifdef CONFIG_SYSCTL
                if (idev) {
-                       addrconf_sysctl_unregister(&idev->cnf);
-                       neigh_sysctl_unregister(idev->nd_parms);
-                       neigh_sysctl_register(dev, idev->nd_parms,
-                                             NET_IPV6, NET_IPV6_NEIGH, "ipv6",
-                                             &ndisc_ifinfo_sysctl_change,
-                                             NULL);
-                       addrconf_sysctl_register(idev, &idev->cnf);
+                       snmp6_unregister_dev(idev);
+                       addrconf_sysctl_unregister(idev);
+                       addrconf_sysctl_register(idev);
+                       err = snmp6_register_dev(idev);
+                       if (err)
+                               return notifier_from_errno(err);
                }
-#endif
                break;
-       };
+       }
 
        return NOTIFY_OK;
 }
@@ -2329,7 +2437,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
 
        ASSERT_RTNL();
 
-       if (dev == &loopback_dev && how == 1)
+       if (dev == init_net.loopback_dev && how == 1)
                how = 0;
 
        rt6_ifdown(dev);
@@ -2340,13 +2448,13 @@ static int addrconf_ifdown(struct net_device *dev, int how)
                return -ENODEV;
 
        /* Step 1: remove reference to ipv6 device from parent device.
-                  Do not dev_put!
+                  Do not dev_put!
         */
        if (how == 1) {
-               write_lock_bh(&addrconf_lock);
-               dev->ip6_ptr = NULL;
                idev->dead = 1;
-               write_unlock_bh(&addrconf_lock);
+
+               /* protected by rtnl_lock */
+               rcu_assign_pointer(dev->ip6_ptr, NULL);
 
                /* Step 1.5: remove snmp6 entry */
                snmp6_unregister_dev(idev);
@@ -2407,6 +2515,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
                write_unlock_bh(&idev->lock);
 
                __ipv6_ifa_notify(RTM_DELADDR, ifa);
+               atomic_notifier_call_chain(&inet6addr_chain, NETDEV_DOWN, ifa);
                in6_ifa_put(ifa);
 
                write_lock_bh(&idev->lock);
@@ -2420,17 +2529,12 @@ static int addrconf_ifdown(struct net_device *dev, int how)
        else
                ipv6_mc_down(idev);
 
-       /* Step 5: netlink notification of this interface */
        idev->tstamp = jiffies;
-       inet6_ifinfo_notify(RTM_DELLINK, idev);
-       
+
        /* Shot the device (if unregistered) */
 
        if (how == 1) {
-#ifdef CONFIG_SYSCTL
-               addrconf_sysctl_unregister(&idev->cnf);
-               neigh_sysctl_unregister(idev->nd_parms);
-#endif
+               addrconf_sysctl_unregister(idev);
                neigh_parms_release(&nd_tbl, idev->nd_parms);
                neigh_ifdown(&nd_tbl, dev);
                in6_dev_put(idev);
@@ -2489,7 +2593,11 @@ static void addrconf_dad_kick(struct inet6_ifaddr *ifp)
        unsigned long rand_num;
        struct inet6_dev *idev = ifp->idev;
 
-       rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1);
+       if (ifp->flags & IFA_F_OPTIMISTIC)
+               rand_num = 0;
+       else
+               rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1);
+
        ifp->probes = idev->cnf.dad_transmits;
        addrconf_mod_timer(ifp, AC_DAD, rand_num);
 }
@@ -2501,10 +2609,6 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
 
        addrconf_join_solict(dev, &ifp->addr);
 
-       if (ifp->prefix_len != 128 && (ifp->flags&IFA_F_PERMANENT))
-               addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, 0,
-                                       flags);
-
        net_srandom(ifp->addr.s6_addr32[3]);
 
        read_lock_bh(&idev->lock);
@@ -2513,8 +2617,9 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
        spin_lock_bh(&ifp->lock);
 
        if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) ||
-           !(ifp->flags&IFA_F_TENTATIVE)) {
-               ifp->flags &= ~IFA_F_TENTATIVE;
+           !(ifp->flags&IFA_F_TENTATIVE) ||
+           ifp->flags & IFA_F_NODAD) {
+               ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC);
                spin_unlock_bh(&ifp->lock);
                read_unlock_bh(&idev->lock);
 
@@ -2534,6 +2639,14 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
                addrconf_dad_stop(ifp);
                return;
        }
+
+       /*
+        * Optimistic nodes can start receiving
+        * Frames right away
+        */
+       if(ifp->flags & IFA_F_OPTIMISTIC)
+               ip6_ins_rt(ifp->rt);
+
        addrconf_dad_kick(ifp);
        spin_unlock_bh(&ifp->lock);
 out:
@@ -2558,7 +2671,7 @@ static void addrconf_dad_timer(unsigned long data)
                 * DAD was successful
                 */
 
-               ifp->flags &= ~IFA_F_TENTATIVE;
+               ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC);
                spin_unlock_bh(&ifp->lock);
                read_unlock_bh(&idev->lock);
 
@@ -2635,6 +2748,7 @@ static void addrconf_dad_run(struct inet6_dev *idev) {
 
 #ifdef CONFIG_PROC_FS
 struct if6_iter_state {
+       struct seq_net_private p;
        int bucket;
 };
 
@@ -2642,9 +2756,13 @@ static struct inet6_ifaddr *if6_get_first(struct seq_file *seq)
 {
        struct inet6_ifaddr *ifa = NULL;
        struct if6_iter_state *state = seq->private;
+       struct net *net = state->p.net;
 
        for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) {
                ifa = inet6_addr_lst[state->bucket];
+
+               while (ifa && ifa->idev->dev->nd_net != net)
+                       ifa = ifa->lst_next;
                if (ifa)
                        break;
        }
@@ -2654,13 +2772,22 @@ static struct inet6_ifaddr *if6_get_first(struct seq_file *seq)
 static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct inet6_ifaddr *ifa)
 {
        struct if6_iter_state *state = seq->private;
+       struct net *net = state->p.net;
 
        ifa = ifa->lst_next;
 try_again:
+       if (ifa) {
+               if (ifa->idev->dev->nd_net != net) {
+                       ifa = ifa->lst_next;
+                       goto try_again;
+               }
+       }
+
        if (!ifa && ++state->bucket < IN6_ADDR_HSIZE) {
                ifa = inet6_addr_lst[state->bucket];
                goto try_again;
        }
+
        return ifa;
 }
 
@@ -2675,6 +2802,7 @@ static struct inet6_ifaddr *if6_get_idx(struct seq_file *seq, loff_t pos)
 }
 
 static void *if6_seq_start(struct seq_file *seq, loff_t *pos)
+       __acquires(addrconf_hash_lock)
 {
        read_lock_bh(&addrconf_hash_lock);
        return if6_get_idx(seq, *pos);
@@ -2690,6 +2818,7 @@ static void *if6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void if6_seq_stop(struct seq_file *seq, void *v)
+       __releases(addrconf_hash_lock)
 {
        read_unlock_bh(&addrconf_hash_lock);
 }
@@ -2708,7 +2837,7 @@ static int if6_seq_show(struct seq_file *seq, void *v)
        return 0;
 }
 
-static struct seq_operations if6_seq_ops = {
+static const struct seq_operations if6_seq_ops = {
        .start  = if6_seq_start,
        .next   = if6_seq_next,
        .show   = if6_seq_show,
@@ -2717,47 +2846,68 @@ static struct seq_operations if6_seq_ops = {
 
 static int if6_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct if6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
-
-       if (!s)
-               goto out;
-
-       rc = seq_open(file, &if6_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_net(inode, file, &if6_seq_ops,
+                           sizeof(struct if6_iter_state));
 }
 
-static struct file_operations if6_fops = {
+static const struct file_operations if6_fops = {
        .owner          = THIS_MODULE,
        .open           = if6_seq_open,
        .read           = seq_read,
        .llseek         = seq_lseek,
-       .release        = seq_release_private,
+       .release        = seq_release_net,
 };
 
-int __init if6_proc_init(void)
+static int if6_proc_net_init(struct net *net)
 {
-       if (!proc_net_fops_create("if_inet6", S_IRUGO, &if6_fops))
+       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)
+{
+       proc_net_remove(net, "if_inet6");
+}
+
+static struct pernet_operations if6_proc_net_ops = {
+       .init = if6_proc_net_init,
+       .exit = if6_proc_net_exit,
+};
+
+int __init if6_proc_init(void)
+{
+       return register_pernet_subsys(&if6_proc_net_ops);
+}
+
 void if6_proc_exit(void)
 {
-       proc_net_remove("if_inet6");
+       unregister_pernet_subsys(&if6_proc_net_ops);
 }
 #endif /* CONFIG_PROC_FS */
 
+#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
+/* Check if address is a home address configured on any interface. */
+int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr)
+{
+       int ret = 0;
+       struct inet6_ifaddr * ifp;
+       u8 hash = ipv6_addr_hash(addr);
+       read_lock_bh(&addrconf_hash_lock);
+       for (ifp = inet6_addr_lst[hash]; ifp; ifp = ifp->lst_next) {
+               if (ifp->idev->dev->nd_net != net)
+                       continue;
+               if (ipv6_addr_cmp(&ifp->addr, addr) == 0 &&
+                   (ifp->flags & IFA_F_HOMEADDRESS)) {
+                       ret = 1;
+                       break;
+               }
+       }
+       read_unlock_bh(&addrconf_hash_lock);
+       return ret;
+}
+#endif
+
 /*
  *     Periodic address status verification
  */
@@ -2791,8 +2941,8 @@ restart:
                        age = (now - ifp->tstamp) / HZ;
 
 #ifdef CONFIG_IPV6_PRIVACY
-                       regen_advance = ifp->idev->cnf.regen_max_retry * 
-                                       ifp->idev->cnf.dad_transmits * 
+                       regen_advance = ifp->idev->cnf.regen_max_retry *
+                                       ifp->idev->cnf.dad_transmits *
                                        ifp->idev->nd_parms->retrans_time / HZ;
 #endif
 
@@ -2885,7 +3035,7 @@ static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local)
        return pfx;
 }
 
-static struct nla_policy ifa_ipv6_policy[IFA_MAX+1] __read_mostly = {
+static const struct nla_policy ifa_ipv6_policy[IFA_MAX+1] = {
        [IFA_ADDRESS]           = { .len = sizeof(struct in6_addr) },
        [IFA_LOCAL]             = { .len = sizeof(struct in6_addr) },
        [IFA_CACHEINFO]         = { .len = sizeof(struct ifa_cacheinfo) },
@@ -2894,11 +3044,15 @@ static struct nla_policy ifa_ipv6_policy[IFA_MAX+1] __read_mostly = {
 static int
 inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 {
+       struct net *net = skb->sk->sk_net;
        struct ifaddrmsg *ifm;
        struct nlattr *tb[IFA_MAX+1];
        struct in6_addr *pfx;
        int err;
 
+       if (net != &init_net)
+               return -EINVAL;
+
        err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
        if (err < 0)
                return err;
@@ -2911,41 +3065,28 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
        return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
 }
 
-static int
-inet6_addr_modify(int ifindex, struct in6_addr *pfx,
-                 __u32 prefered_lft, __u32 valid_lft)
+static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
+                            u32 prefered_lft, u32 valid_lft)
 {
-       struct inet6_ifaddr *ifp = NULL;
-       struct net_device *dev;
-       int ifa_flags = 0;
-
-       if ((dev = __dev_get_by_index(ifindex)) == NULL)
-               return -ENODEV;
-
-       if (!(dev->flags&IFF_UP))
-               return -ENETDOWN;
+       u32 flags = RTF_EXPIRES;
 
        if (!valid_lft || (prefered_lft > valid_lft))
                return -EINVAL;
 
-       ifp = ipv6_get_ifaddr(pfx, dev, 1);
-       if (ifp == NULL)
-               return -ENOENT;
-
-       if (valid_lft == INFINITY_LIFE_TIME)
-               ifa_flags = IFA_F_PERMANENT;
-       else if (valid_lft >= 0x7FFFFFFF/HZ)
+       if (valid_lft == INFINITY_LIFE_TIME) {
+               ifa_flags |= IFA_F_PERMANENT;
+               flags = 0;
+       } else if (valid_lft >= 0x7FFFFFFF/HZ)
                valid_lft = 0x7FFFFFFF/HZ;
 
        if (prefered_lft == 0)
-               ifa_flags = IFA_F_DEPRECATED;
+               ifa_flags |= IFA_F_DEPRECATED;
        else if ((prefered_lft >= 0x7FFFFFFF/HZ) &&
                 (prefered_lft != INFINITY_LIFE_TIME))
                prefered_lft = 0x7FFFFFFF/HZ;
 
        spin_lock_bh(&ifp->lock);
-       ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED|IFA_F_PERMANENT)) | ifa_flags;
-
+       ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | IFA_F_HOMEADDRESS)) | ifa_flags;
        ifp->tstamp = jiffies;
        ifp->valid_lft = valid_lft;
        ifp->prefered_lft = prefered_lft;
@@ -2953,8 +3094,9 @@ inet6_addr_modify(int ifindex, struct in6_addr *pfx,
        spin_unlock_bh(&ifp->lock);
        if (!(ifp->flags&IFA_F_TENTATIVE))
                ipv6_ifa_notify(0, ifp);
-       in6_ifa_put(ifp);
 
+       addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev,
+                             jiffies_to_clock_t(valid_lft * HZ), flags);
        addrconf_verify(0);
 
        return 0;
@@ -2963,12 +3105,19 @@ inet6_addr_modify(int ifindex, struct in6_addr *pfx,
 static int
 inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 {
+       struct net *net = skb->sk->sk_net;
        struct ifaddrmsg *ifm;
        struct nlattr *tb[IFA_MAX+1];
        struct in6_addr *pfx;
-       u32 valid_lft, preferred_lft;
+       struct inet6_ifaddr *ifa;
+       struct net_device *dev;
+       u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME;
+       u8 ifa_flags;
        int err;
 
+       if (net != &init_net)
+               return -EINVAL;
+
        err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
        if (err < 0)
                return err;
@@ -2989,141 +3138,165 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
                valid_lft = INFINITY_LIFE_TIME;
        }
 
-       if (nlh->nlmsg_flags & NLM_F_REPLACE) {
-               err = inet6_addr_modify(ifm->ifa_index, pfx,
-                                       preferred_lft, valid_lft);
-               if (err == 0 || !(nlh->nlmsg_flags & NLM_F_CREATE))
-                       return err;
+       dev =  __dev_get_by_index(&init_net, ifm->ifa_index);
+       if (dev == NULL)
+               return -ENODEV;
+
+       /* We ignore other flags so far. */
+       ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS);
+
+       ifa = ipv6_get_ifaddr(net, pfx, dev, 1);
+       if (ifa == NULL) {
+               /*
+                * It would be best to check for !NLM_F_CREATE here but
+                * userspace alreay relies on not having to provide this.
+                */
+               return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen,
+                                     ifa_flags, preferred_lft, valid_lft);
        }
 
-       return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen,
-                             preferred_lft, valid_lft);
+       if (nlh->nlmsg_flags & NLM_F_EXCL ||
+           !(nlh->nlmsg_flags & NLM_F_REPLACE))
+               err = -EEXIST;
+       else
+               err = inet6_addr_modify(ifa, ifa_flags, preferred_lft, valid_lft);
+
+       in6_ifa_put(ifa);
+
+       return err;
 }
 
-/* Maximum length of ifa_cacheinfo attributes */
-#define INET6_IFADDR_RTA_SPACE \
-               RTA_SPACE(16) /* IFA_ADDRESS */ + \
-               RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */
+static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags,
+                         u8 scope, int ifindex)
+{
+       struct ifaddrmsg *ifm;
+
+       ifm = nlmsg_data(nlh);
+       ifm->ifa_family = AF_INET6;
+       ifm->ifa_prefixlen = prefixlen;
+       ifm->ifa_flags = flags;
+       ifm->ifa_scope = scope;
+       ifm->ifa_index = ifindex;
+}
+
+static int put_cacheinfo(struct sk_buff *skb, unsigned long cstamp,
+                        unsigned long tstamp, u32 preferred, u32 valid)
+{
+       struct ifa_cacheinfo ci;
+
+       ci.cstamp = (u32)(TIME_DELTA(cstamp, INITIAL_JIFFIES) / HZ * 100
+                       + TIME_DELTA(cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
+       ci.tstamp = (u32)(TIME_DELTA(tstamp, INITIAL_JIFFIES) / HZ * 100
+                       + TIME_DELTA(tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
+       ci.ifa_prefered = preferred;
+       ci.ifa_valid = valid;
+
+       return nla_put(skb, IFA_CACHEINFO, sizeof(ci), &ci);
+}
+
+static inline int rt_scope(int ifa_scope)
+{
+       if (ifa_scope & IFA_HOST)
+               return RT_SCOPE_HOST;
+       else if (ifa_scope & IFA_LINK)
+               return RT_SCOPE_LINK;
+       else if (ifa_scope & IFA_SITE)
+               return RT_SCOPE_SITE;
+       else
+               return RT_SCOPE_UNIVERSE;
+}
+
+static inline int inet6_ifaddr_msgsize(void)
+{
+       return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
+              + nla_total_size(16) /* IFA_ADDRESS */
+              + nla_total_size(sizeof(struct ifa_cacheinfo));
+}
 
 static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
                             u32 pid, u32 seq, int event, unsigned int flags)
 {
-       struct ifaddrmsg *ifm;
        struct nlmsghdr  *nlh;
-       struct ifa_cacheinfo ci;
-       unsigned char    *b = skb->tail;
+       u32 preferred, valid;
+
+       nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
+       if (nlh == NULL)
+               return -EMSGSIZE;
+
+       put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope),
+                     ifa->idev->dev->ifindex);
 
-       nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
-       ifm = NLMSG_DATA(nlh);
-       ifm->ifa_family = AF_INET6;
-       ifm->ifa_prefixlen = ifa->prefix_len;
-       ifm->ifa_flags = ifa->flags;
-       ifm->ifa_scope = RT_SCOPE_UNIVERSE;
-       if (ifa->scope&IFA_HOST)
-               ifm->ifa_scope = RT_SCOPE_HOST;
-       else if (ifa->scope&IFA_LINK)
-               ifm->ifa_scope = RT_SCOPE_LINK;
-       else if (ifa->scope&IFA_SITE)
-               ifm->ifa_scope = RT_SCOPE_SITE;
-       ifm->ifa_index = ifa->idev->dev->ifindex;
-       RTA_PUT(skb, IFA_ADDRESS, 16, &ifa->addr);
        if (!(ifa->flags&IFA_F_PERMANENT)) {
-               ci.ifa_prefered = ifa->prefered_lft;
-               ci.ifa_valid = ifa->valid_lft;
-               if (ci.ifa_prefered != INFINITY_LIFE_TIME) {
+               preferred = ifa->prefered_lft;
+               valid = ifa->valid_lft;
+               if (preferred != INFINITY_LIFE_TIME) {
                        long tval = (jiffies - ifa->tstamp)/HZ;
-                       ci.ifa_prefered -= tval;
-                       if (ci.ifa_valid != INFINITY_LIFE_TIME)
-                               ci.ifa_valid -= tval;
+                       preferred -= tval;
+                       if (valid != INFINITY_LIFE_TIME)
+                               valid -= tval;
                }
        } else {
-               ci.ifa_prefered = INFINITY_LIFE_TIME;
-               ci.ifa_valid = INFINITY_LIFE_TIME;
+               preferred = INFINITY_LIFE_TIME;
+               valid = INFINITY_LIFE_TIME;
        }
-       ci.cstamp = (__u32)(TIME_DELTA(ifa->cstamp, INITIAL_JIFFIES) / HZ * 100
-                   + TIME_DELTA(ifa->cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
-       ci.tstamp = (__u32)(TIME_DELTA(ifa->tstamp, INITIAL_JIFFIES) / HZ * 100
-                   + TIME_DELTA(ifa->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
-       RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
-       nlh->nlmsg_len = skb->tail - b;
-       return skb->len;
 
-nlmsg_failure:
-rtattr_failure:
-       skb_trim(skb, b - skb->data);
-       return -1;
+       if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0 ||
+           put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) {
+               nlmsg_cancel(skb, nlh);
+               return -EMSGSIZE;
+       }
+
+       return nlmsg_end(skb, nlh);
 }
 
 static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca,
                                u32 pid, u32 seq, int event, u16 flags)
 {
-       struct ifaddrmsg *ifm;
        struct nlmsghdr  *nlh;
-       struct ifa_cacheinfo ci;
-       unsigned char    *b = skb->tail;
-
-       nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
-       ifm = NLMSG_DATA(nlh);
-       ifm->ifa_family = AF_INET6;     
-       ifm->ifa_prefixlen = 128;
-       ifm->ifa_flags = IFA_F_PERMANENT;
-       ifm->ifa_scope = RT_SCOPE_UNIVERSE;
-       if (ipv6_addr_scope(&ifmca->mca_addr)&IFA_SITE)
-               ifm->ifa_scope = RT_SCOPE_SITE;
-       ifm->ifa_index = ifmca->idev->dev->ifindex;
-       RTA_PUT(skb, IFA_MULTICAST, 16, &ifmca->mca_addr);
-       ci.cstamp = (__u32)(TIME_DELTA(ifmca->mca_cstamp, INITIAL_JIFFIES) / HZ
-                   * 100 + TIME_DELTA(ifmca->mca_cstamp, INITIAL_JIFFIES) % HZ
-                   * 100 / HZ);
-       ci.tstamp = (__u32)(TIME_DELTA(ifmca->mca_tstamp, INITIAL_JIFFIES) / HZ
-                   * 100 + TIME_DELTA(ifmca->mca_tstamp, INITIAL_JIFFIES) % HZ
-                   * 100 / HZ);
-       ci.ifa_prefered = INFINITY_LIFE_TIME;
-       ci.ifa_valid = INFINITY_LIFE_TIME;
-       RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
-       nlh->nlmsg_len = skb->tail - b;
-       return skb->len;
+       u8 scope = RT_SCOPE_UNIVERSE;
+       int ifindex = ifmca->idev->dev->ifindex;
+
+       if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE)
+               scope = RT_SCOPE_SITE;
+
+       nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
+       if (nlh == NULL)
+               return -EMSGSIZE;
+
+       put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
+       if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 ||
+           put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
+                         INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
+               nlmsg_cancel(skb, nlh);
+               return -EMSGSIZE;
+       }
 
-nlmsg_failure:
-rtattr_failure:
-       skb_trim(skb, b - skb->data);
-       return -1;
+       return nlmsg_end(skb, nlh);
 }
 
 static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
                                u32 pid, u32 seq, int event, unsigned int flags)
 {
-       struct ifaddrmsg *ifm;
        struct nlmsghdr  *nlh;
-       struct ifa_cacheinfo ci;
-       unsigned char    *b = skb->tail;
-
-       nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
-       ifm = NLMSG_DATA(nlh);
-       ifm->ifa_family = AF_INET6;     
-       ifm->ifa_prefixlen = 128;
-       ifm->ifa_flags = IFA_F_PERMANENT;
-       ifm->ifa_scope = RT_SCOPE_UNIVERSE;
-       if (ipv6_addr_scope(&ifaca->aca_addr)&IFA_SITE)
-               ifm->ifa_scope = RT_SCOPE_SITE;
-       ifm->ifa_index = ifaca->aca_idev->dev->ifindex;
-       RTA_PUT(skb, IFA_ANYCAST, 16, &ifaca->aca_addr);
-       ci.cstamp = (__u32)(TIME_DELTA(ifaca->aca_cstamp, INITIAL_JIFFIES) / HZ
-                   * 100 + TIME_DELTA(ifaca->aca_cstamp, INITIAL_JIFFIES) % HZ
-                   * 100 / HZ);
-       ci.tstamp = (__u32)(TIME_DELTA(ifaca->aca_tstamp, INITIAL_JIFFIES) / HZ
-                   * 100 + TIME_DELTA(ifaca->aca_tstamp, INITIAL_JIFFIES) % HZ
-                   * 100 / HZ);
-       ci.ifa_prefered = INFINITY_LIFE_TIME;
-       ci.ifa_valid = INFINITY_LIFE_TIME;
-       RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
-       nlh->nlmsg_len = skb->tail - b;
-       return skb->len;
+       u8 scope = RT_SCOPE_UNIVERSE;
+       int ifindex = ifaca->aca_idev->dev->ifindex;
+
+       if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE)
+               scope = RT_SCOPE_SITE;
+
+       nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
+       if (nlh == NULL)
+               return -EMSGSIZE;
+
+       put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
+       if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 ||
+           put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
+                         INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
+               nlmsg_cancel(skb, nlh);
+               return -EMSGSIZE;
+       }
 
-nlmsg_failure:
-rtattr_failure:
-       skb_trim(skb, b - skb->data);
-       return -1;
+       return nlmsg_end(skb, nlh);
 }
 
 enum addr_type_t
@@ -3147,16 +3320,16 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
 
        s_idx = cb->args[0];
        s_ip_idx = ip_idx = cb->args[1];
-       read_lock(&dev_base_lock);
-       
-       for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) {
+
+       idx = 0;
+       for_each_netdev(&init_net, dev) {
                if (idx < s_idx)
-                       continue;
+                       goto cont;
                if (idx > s_idx)
                        s_ip_idx = 0;
                ip_idx = 0;
                if ((idev = in6_dev_get(dev)) == NULL)
-                       continue;
+                       goto cont;
                read_lock_bh(&idev->lock);
                switch (type) {
                case UNICAST_ADDR:
@@ -3165,24 +3338,24 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
                             ifa = ifa->if_next, ip_idx++) {
                                if (ip_idx < s_ip_idx)
                                        continue;
-                               if ((err = inet6_fill_ifaddr(skb, ifa, 
-                                   NETLINK_CB(cb->skb).pid, 
-                                   cb->nlh->nlmsg_seq, RTM_NEWADDR,
-                                   NLM_F_MULTI)) <= 0)
-                                       goto done;
+                               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; 
+                       for (ifmca = idev->mc_list; ifmca;
                             ifmca = ifmca->next, ip_idx++) {
                                if (ip_idx < s_ip_idx)
                                        continue;
-                               if ((err = inet6_fill_ifmcaddr(skb, ifmca, 
-                                   NETLINK_CB(cb->skb).pid, 
-                                   cb->nlh->nlmsg_seq, RTM_GETMULTICAST,
-                                   NLM_F_MULTI)) <= 0)
-                                       goto done;
+                               err = inet6_fill_ifmcaddr(skb, ifmca,
+                                                         NETLINK_CB(cb->skb).pid,
+                                                         cb->nlh->nlmsg_seq,
+                                                         RTM_GETMULTICAST,
+                                                         NLM_F_MULTI);
                        }
                        break;
                case ANYCAST_ADDR:
@@ -3191,11 +3364,11 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
                             ifaca = ifaca->aca_next, ip_idx++) {
                                if (ip_idx < s_ip_idx)
                                        continue;
-                               if ((err = inet6_fill_ifacaddr(skb, ifaca, 
-                                   NETLINK_CB(cb->skb).pid, 
-                                   cb->nlh->nlmsg_seq, RTM_GETANYCAST,
-                                   NLM_F_MULTI)) <= 0) 
-                                       goto done;
+                               err = inet6_fill_ifacaddr(skb, ifaca,
+                                                         NETLINK_CB(cb->skb).pid,
+                                                         cb->nlh->nlmsg_seq,
+                                                         RTM_GETANYCAST,
+                                                         NLM_F_MULTI);
                        }
                        break;
                default:
@@ -3203,13 +3376,12 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
                }
                read_unlock_bh(&idev->lock);
                in6_dev_put(idev);
+
+               if (err <= 0)
+                       break;
+cont:
+               idx++;
        }
-done:
-       if (err <= 0) {
-               read_unlock_bh(&idev->lock);
-               in6_dev_put(idev);
-       }
-       read_unlock(&dev_base_lock);
        cb->args[0] = idx;
        cb->args[1] = ip_idx;
        return skb->len;
@@ -3217,35 +3389,53 @@ done:
 
 static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = skb->sk->sk_net;
        enum addr_type_t type = UNICAST_ADDR;
+
+       if (net != &init_net)
+               return 0;
+
        return inet6_dump_addr(skb, cb, type);
 }
 
 static int inet6_dump_ifmcaddr(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = skb->sk->sk_net;
        enum addr_type_t type = MULTICAST_ADDR;
+
+       if (net != &init_net)
+               return 0;
+
        return inet6_dump_addr(skb, cb, type);
 }
 
 
 static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = skb->sk->sk_net;
        enum addr_type_t type = ANYCAST_ADDR;
+
+       if (net != &init_net)
+               return 0;
+
        return inet6_dump_addr(skb, cb, type);
 }
 
 static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh,
                             void *arg)
 {
+       struct net *net = in_skb->sk->sk_net;
        struct ifaddrmsg *ifm;
        struct nlattr *tb[IFA_MAX+1];
        struct in6_addr *addr = NULL;
        struct net_device *dev = NULL;
        struct inet6_ifaddr *ifa;
        struct sk_buff *skb;
-       int payload = sizeof(struct ifaddrmsg) + INET6_IFADDR_RTA_SPACE;
        int err;
 
+       if (net != &init_net)
+               return -EINVAL;
+
        err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
        if (err < 0)
                goto errout;
@@ -3258,14 +3448,14 @@ static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh,
 
        ifm = nlmsg_data(nlh);
        if (ifm->ifa_index)
-               dev = __dev_get_by_index(ifm->ifa_index);
+               dev = __dev_get_by_index(&init_net, ifm->ifa_index);
 
-       if ((ifa = ipv6_get_ifaddr(addr, dev, 1)) == NULL) {
+       if ((ifa = ipv6_get_ifaddr(net, addr, dev, 1)) == NULL) {
                err = -EADDRNOTAVAIL;
                goto errout;
        }
 
-       if ((skb = nlmsg_new(nlmsg_total_size(payload), GFP_KERNEL)) == NULL) {
+       if ((skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL)) == NULL) {
                err = -ENOBUFS;
                goto errout_ifa;
        }
@@ -3273,11 +3463,12 @@ static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh,
        err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).pid,
                                nlh->nlmsg_seq, RTM_NEWADDR, 0);
        if (err < 0) {
+               /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
+               WARN_ON(err == -EMSGSIZE);
                kfree_skb(skb);
                goto errout_ifa;
        }
-
-       err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
+       err = rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).pid);
 errout_ifa:
        in6_ifa_put(ifa);
 errout:
@@ -3287,28 +3478,30 @@ errout:
 static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
 {
        struct sk_buff *skb;
-       int payload = sizeof(struct ifaddrmsg) + INET6_IFADDR_RTA_SPACE;
        int err = -ENOBUFS;
 
-       skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC);
+       skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC);
        if (skb == NULL)
                goto errout;
 
        err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0);
        if (err < 0) {
+               /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
+               WARN_ON(err == -EMSGSIZE);
                kfree_skb(skb);
                goto errout;
        }
-
-       err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
+       err = rtnl_notify(skb, &init_net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
 errout:
        if (err < 0)
-               rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err);
+               rtnl_set_sk_err(&init_net, RTNLGRP_IPV6_IFADDR, err);
 }
 
-static void inline ipv6_store_devconf(struct ipv6_devconf *cnf,
+static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
                                __s32 *array, int bytes)
 {
+       BUG_ON(bytes < (DEVCONF_MAX * 4));
+
        memset(array, 0, bytes);
        array[DEVCONF_FORWARDING] = cnf->forwarding;
        array[DEVCONF_HOPLIMIT] = cnf->hop_limit;
@@ -3334,106 +3527,155 @@ static void inline ipv6_store_devconf(struct ipv6_devconf *cnf,
 #ifdef CONFIG_IPV6_ROUTER_PREF
        array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref;
        array[DEVCONF_RTR_PROBE_INTERVAL] = cnf->rtr_probe_interval;
-#ifdef CONFIV_IPV6_ROUTE_INFO
+#ifdef CONFIG_IPV6_ROUTE_INFO
        array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen;
 #endif
 #endif
+       array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp;
+       array[DEVCONF_ACCEPT_SOURCE_ROUTE] = cnf->accept_source_route;
+#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
+       array[DEVCONF_OPTIMISTIC_DAD] = cnf->optimistic_dad;
+#endif
+}
+
+static inline size_t inet6_if_nlmsg_size(void)
+{
+       return NLMSG_ALIGN(sizeof(struct ifinfomsg))
+              + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
+              + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
+              + nla_total_size(4) /* IFLA_MTU */
+              + nla_total_size(4) /* IFLA_LINK */
+              + nla_total_size( /* IFLA_PROTINFO */
+                       nla_total_size(4) /* IFLA_INET6_FLAGS */
+                       + nla_total_size(sizeof(struct ifla_cacheinfo))
+                       + nla_total_size(DEVCONF_MAX * 4) /* IFLA_INET6_CONF */
+                       + nla_total_size(IPSTATS_MIB_MAX * 8) /* IFLA_INET6_STATS */
+                       + nla_total_size(ICMP6_MIB_MAX * 8) /* IFLA_INET6_ICMP6STATS */
+                );
+}
+
+static inline void __snmp6_fill_stats(u64 *stats, void **mib, int items,
+                                     int bytes)
+{
+       int i;
+       int pad = bytes - sizeof(u64) * items;
+       BUG_ON(pad < 0);
+
+       /* Use put_unaligned() because stats may not be aligned for u64. */
+       put_unaligned(items, &stats[0]);
+       for (i = 1; i < items; i++)
+               put_unaligned(snmp_fold_field(mib, i), &stats[i]);
+
+       memset(&stats[items], 0, pad);
+}
+
+static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int attrtype,
+                            int bytes)
+{
+       switch(attrtype) {
+       case IFLA_INET6_STATS:
+               __snmp6_fill_stats(stats, (void **)idev->stats.ipv6, IPSTATS_MIB_MAX, bytes);
+               break;
+       case IFLA_INET6_ICMP6STATS:
+               __snmp6_fill_stats(stats, (void **)idev->stats.icmpv6, ICMP6_MIB_MAX, bytes);
+               break;
+       }
 }
 
-/* Maximum length of ifinfomsg attributes */
-#define INET6_IFINFO_RTA_SPACE \
-               RTA_SPACE(IFNAMSIZ) /* IFNAME */ + \
-               RTA_SPACE(MAX_ADDR_LEN) /* ADDRESS */ + \
-               RTA_SPACE(sizeof(u32)) /* MTU */ + \
-               RTA_SPACE(sizeof(int)) /* LINK */ + \
-               RTA_SPACE(0) /* PROTINFO */ + \
-               RTA_SPACE(sizeof(u32)) /* FLAGS */ + \
-               RTA_SPACE(sizeof(struct ifla_cacheinfo)) /* CACHEINFO */ + \
-               RTA_SPACE(sizeof(__s32[DEVCONF_MAX])) /* CONF */
-
-static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, 
+static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
                             u32 pid, u32 seq, int event, unsigned int flags)
 {
-       struct net_device       *dev = idev->dev;
-       __s32                   *array = NULL;
-       struct ifinfomsg        *r;
-       struct nlmsghdr         *nlh;
-       unsigned char           *b = skb->tail;
-       struct rtattr           *subattr;
-       __u32                   mtu = dev->mtu;
-       struct ifla_cacheinfo   ci;
-
-       nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
-       r = NLMSG_DATA(nlh);
-       r->ifi_family = AF_INET6;
-       r->__ifi_pad = 0;
-       r->ifi_type = dev->type;
-       r->ifi_index = dev->ifindex;
-       r->ifi_flags = dev_get_flags(dev);
-       r->ifi_change = 0;
-
-       RTA_PUT(skb, IFLA_IFNAME, strlen(dev->name)+1, dev->name);
+       struct net_device *dev = idev->dev;
+       struct nlattr *nla;
+       struct ifinfomsg *hdr;
+       struct nlmsghdr *nlh;
+       void *protoinfo;
+       struct ifla_cacheinfo ci;
+
+       nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags);
+       if (nlh == NULL)
+               return -EMSGSIZE;
+
+       hdr = nlmsg_data(nlh);
+       hdr->ifi_family = AF_INET6;
+       hdr->__ifi_pad = 0;
+       hdr->ifi_type = dev->type;
+       hdr->ifi_index = dev->ifindex;
+       hdr->ifi_flags = dev_get_flags(dev);
+       hdr->ifi_change = 0;
+
+       NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name);
 
        if (dev->addr_len)
-               RTA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
+               NLA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
 
-       RTA_PUT(skb, IFLA_MTU, sizeof(mtu), &mtu);
+       NLA_PUT_U32(skb, IFLA_MTU, dev->mtu);
        if (dev->ifindex != dev->iflink)
-               RTA_PUT(skb, IFLA_LINK, sizeof(int), &dev->iflink);
-                       
-       subattr = (struct rtattr*)skb->tail;
+               NLA_PUT_U32(skb, IFLA_LINK, dev->iflink);
 
-       RTA_PUT(skb, IFLA_PROTINFO, 0, NULL);
+       protoinfo = nla_nest_start(skb, IFLA_PROTINFO);
+       if (protoinfo == NULL)
+               goto nla_put_failure;
 
-       /* return the device flags */
-       RTA_PUT(skb, IFLA_INET6_FLAGS, sizeof(__u32), &idev->if_flags);
+       NLA_PUT_U32(skb, IFLA_INET6_FLAGS, idev->if_flags);
 
-       /* return interface cacheinfo */
        ci.max_reasm_len = IPV6_MAXPLEN;
        ci.tstamp = (__u32)(TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) / HZ * 100
                    + TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
        ci.reachable_time = idev->nd_parms->reachable_time;
        ci.retrans_time = idev->nd_parms->retrans_time;
-       RTA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci);
-       
-       /* return the device sysctl params */
-       if ((array = kmalloc(DEVCONF_MAX * sizeof(*array), GFP_ATOMIC)) == NULL)
-               goto rtattr_failure;
-       ipv6_store_devconf(&idev->cnf, array, DEVCONF_MAX * sizeof(*array));
-       RTA_PUT(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(*array), array);
-
-       /* XXX - Statistics/MC not implemented */
-       subattr->rta_len = skb->tail - (u8*)subattr;
-
-       nlh->nlmsg_len = skb->tail - b;
-       kfree(array);
-       return skb->len;
+       NLA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci);
 
-nlmsg_failure:
-rtattr_failure:
-       kfree(array);
-       skb_trim(skb, b - skb->data);
-       return -1;
+       nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32));
+       if (nla == NULL)
+               goto nla_put_failure;
+       ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla));
+
+       /* XXX - MC not implemented */
+
+       nla = nla_reserve(skb, IFLA_INET6_STATS, IPSTATS_MIB_MAX * sizeof(u64));
+       if (nla == NULL)
+               goto nla_put_failure;
+       snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_STATS, nla_len(nla));
+
+       nla = nla_reserve(skb, IFLA_INET6_ICMP6STATS, ICMP6_MIB_MAX * sizeof(u64));
+       if (nla == NULL)
+               goto nla_put_failure;
+       snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_ICMP6STATS, nla_len(nla));
+
+       nla_nest_end(skb, protoinfo);
+       return nlmsg_end(skb, nlh);
+
+nla_put_failure:
+       nlmsg_cancel(skb, nlh);
+       return -EMSGSIZE;
 }
 
 static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = skb->sk->sk_net;
        int idx, err;
        int s_idx = cb->args[0];
        struct net_device *dev;
        struct inet6_dev *idev;
 
+       if (net != &init_net)
+               return 0;
+
        read_lock(&dev_base_lock);
-       for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) {
+       idx = 0;
+       for_each_netdev(&init_net, dev) {
                if (idx < s_idx)
-                       continue;
+                       goto cont;
                if ((idev = in6_dev_get(dev)) == NULL)
-                       continue;
-               err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid, 
+                       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;
+cont:
+               idx++;
        }
        read_unlock(&dev_base_lock);
        cb->args[0] = idx;
@@ -3444,41 +3686,45 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
 void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
 {
        struct sk_buff *skb;
-       int payload = sizeof(struct ifinfomsg) + INET6_IFINFO_RTA_SPACE;
        int err = -ENOBUFS;
-       
-       skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC);
+
+       skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC);
        if (skb == NULL)
                goto errout;
 
        err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
        if (err < 0) {
+               /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */
+               WARN_ON(err == -EMSGSIZE);
                kfree_skb(skb);
                goto errout;
        }
-
-       err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
+       err = rtnl_notify(skb, &init_net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
 errout:
        if (err < 0)
-               rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err);
+               rtnl_set_sk_err(&init_net, RTNLGRP_IPV6_IFADDR, err);
 }
 
-/* Maximum length of prefix_cacheinfo attributes */
-#define INET6_PREFIX_RTA_SPACE \
-               RTA_SPACE(sizeof(((struct prefix_info *)NULL)->prefix)) /* ADDRESS */ + \
-               RTA_SPACE(sizeof(struct prefix_cacheinfo)) /* CACHEINFO */
+static inline size_t inet6_prefix_nlmsg_size(void)
+{
+       return NLMSG_ALIGN(sizeof(struct prefixmsg))
+              + nla_total_size(sizeof(struct in6_addr))
+              + nla_total_size(sizeof(struct prefix_cacheinfo));
+}
 
 static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev,
-                       struct prefix_info *pinfo, u32 pid, u32 seq, 
-                       int event, unsigned int flags)
+                            struct prefix_info *pinfo, u32 pid, u32 seq,
+                            int event, unsigned int flags)
 {
-       struct prefixmsg        *pmsg;
-       struct nlmsghdr         *nlh;
-       unsigned char           *b = skb->tail;
+       struct prefixmsg *pmsg;
+       struct nlmsghdr *nlh;
        struct prefix_cacheinfo ci;
 
-       nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*pmsg), flags);
-       pmsg = NLMSG_DATA(nlh);
+       nlh = nlmsg_put(skb, pid, seq, event, sizeof(*pmsg), flags);
+       if (nlh == NULL)
+               return -EMSGSIZE;
+
+       pmsg = nlmsg_data(nlh);
        pmsg->prefix_family = AF_INET6;
        pmsg->prefix_pad1 = 0;
        pmsg->prefix_pad2 = 0;
@@ -3486,75 +3732,62 @@ static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev,
        pmsg->prefix_len = pinfo->prefix_len;
        pmsg->prefix_type = pinfo->type;
        pmsg->prefix_pad3 = 0;
-       
        pmsg->prefix_flags = 0;
        if (pinfo->onlink)
                pmsg->prefix_flags |= IF_PREFIX_ONLINK;
        if (pinfo->autoconf)
                pmsg->prefix_flags |= IF_PREFIX_AUTOCONF;
 
-       RTA_PUT(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix);
+       NLA_PUT(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix);
 
        ci.preferred_time = ntohl(pinfo->prefered);
        ci.valid_time = ntohl(pinfo->valid);
-       RTA_PUT(skb, PREFIX_CACHEINFO, sizeof(ci), &ci);
+       NLA_PUT(skb, PREFIX_CACHEINFO, sizeof(ci), &ci);
 
-       nlh->nlmsg_len = skb->tail - b;
-       return skb->len;
+       return nlmsg_end(skb, nlh);
 
-nlmsg_failure:
-rtattr_failure:
-       skb_trim(skb, b - skb->data);
-       return -1;
+nla_put_failure:
+       nlmsg_cancel(skb, nlh);
+       return -EMSGSIZE;
 }
 
-static void inet6_prefix_notify(int event, struct inet6_dev *idev, 
+static void inet6_prefix_notify(int event, struct inet6_dev *idev,
                         struct prefix_info *pinfo)
 {
        struct sk_buff *skb;
-       int payload = sizeof(struct prefixmsg) + INET6_PREFIX_RTA_SPACE;
        int err = -ENOBUFS;
 
-       skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC);
+       skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC);
        if (skb == NULL)
                goto errout;
 
        err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
        if (err < 0) {
+               /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */
+               WARN_ON(err == -EMSGSIZE);
                kfree_skb(skb);
                goto errout;
        }
-
-       err = rtnl_notify(skb, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC);
+       err = rtnl_notify(skb, &init_net, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC);
 errout:
        if (err < 0)
-               rtnl_set_sk_err(RTNLGRP_IPV6_PREFIX, err);
+               rtnl_set_sk_err(&init_net, RTNLGRP_IPV6_PREFIX, err);
 }
 
-static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = {
-       [RTM_GETLINK - RTM_BASE] = { .dumpit    = inet6_dump_ifinfo, },
-       [RTM_NEWADDR - RTM_BASE] = { .doit      = inet6_rtm_newaddr, },
-       [RTM_DELADDR - RTM_BASE] = { .doit      = inet6_rtm_deladdr, },
-       [RTM_GETADDR - RTM_BASE] = { .doit      = inet6_rtm_getaddr,
-                                    .dumpit    = inet6_dump_ifaddr, },
-       [RTM_GETMULTICAST - RTM_BASE] = { .dumpit = inet6_dump_ifmcaddr, },
-       [RTM_GETANYCAST - RTM_BASE] = { .dumpit = inet6_dump_ifacaddr, },
-       [RTM_NEWROUTE - RTM_BASE] = { .doit     = inet6_rtm_newroute, },
-       [RTM_DELROUTE - RTM_BASE] = { .doit     = inet6_rtm_delroute, },
-       [RTM_GETROUTE - RTM_BASE] = { .doit     = inet6_rtm_getroute,
-                                     .dumpit   = inet6_dump_fib, },
-#ifdef CONFIG_IPV6_MULTIPLE_TABLES
-       [RTM_GETRULE  - RTM_BASE] = { .dumpit   = fib6_rules_dump,   },
-#endif
-};
-
 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
 {
        inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
 
        switch (event) {
        case RTM_NEWADDR:
-               ip6_ins_rt(ifp->rt);
+               /*
+                * If the address was optimistic
+                * we inserted the route at the start of
+                * our DAD process, so we don't need
+                * to do it again
+                */
+               if (!(ifp->rt->rt6i_node))
+                       ip6_ins_rt(ifp->rt);
                if (ifp->idev->cnf.forwarding)
                        addrconf_join_anycast(ifp);
                break;
@@ -3571,10 +3804,10 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
 
 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
 {
-       read_lock_bh(&addrconf_lock);
+       rcu_read_lock_bh();
        if (likely(ifp->idev->dead == 0))
                __ipv6_ifa_notify(event, ifp);
-       read_unlock_bh(&addrconf_lock);
+       rcu_read_unlock_bh();
 }
 
 #ifdef CONFIG_SYSCTL
@@ -3589,33 +3822,19 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
 
        ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
 
-       if (write && valp != &ipv6_devconf_dflt.forwarding) {
-               if (valp != &ipv6_devconf.forwarding) {
-                       if ((!*valp) ^ (!val)) {
-                               struct inet6_dev *idev = (struct inet6_dev *)ctl->extra1;
-                               if (idev == NULL)
-                                       return ret;
-                               dev_forward_change(idev);
-                       }
-               } else {
-                       ipv6_devconf_dflt.forwarding = ipv6_devconf.forwarding;
-                       addrconf_forward_change();
-               }
-               if (*valp)
-                       rt6_purge_dflt_routers();
-       }
-
-        return ret;
+       if (write)
+               addrconf_fixup_forwarding(ctl, valp, val);
+       return ret;
 }
 
-static int addrconf_sysctl_forward_strategy(ctl_table *table, 
+static int addrconf_sysctl_forward_strategy(ctl_table *table,
                                            int __user *name, int nlen,
                                            void __user *oldval,
                                            size_t __user *oldlenp,
-                                           void __user *newval, size_t newlen,
-                                           void **context)
+                                           void __user *newval, size_t newlen)
 {
        int *valp = table->data;
+       int val = *valp;
        int new;
 
        if (!newval || !newlen)
@@ -3640,26 +3859,8 @@ static int addrconf_sysctl_forward_strategy(ctl_table *table,
                }
        }
 
-       if (valp != &ipv6_devconf_dflt.forwarding) {
-               if (valp != &ipv6_devconf.forwarding) {
-                       struct inet6_dev *idev = (struct inet6_dev *)table->extra1;
-                       int changed;
-                       if (unlikely(idev == NULL))
-                               return -ENODEV;
-                       changed = (!*valp) ^ (!new);
-                       *valp = new;
-                       if (changed)
-                               dev_forward_change(idev);
-               } else {
-                       *valp = new;
-                       addrconf_forward_change();
-               }
-
-               if (*valp)
-                       rt6_purge_dflt_routers();
-       } else
-               *valp = new;
-
+       *valp = new;
+       addrconf_fixup_forwarding(table, valp, val);
        return 1;
 }
 
@@ -3667,26 +3868,23 @@ static struct addrconf_sysctl_table
 {
        struct ctl_table_header *sysctl_header;
        ctl_table addrconf_vars[__NET_IPV6_MAX];
-       ctl_table addrconf_dev[2];
-       ctl_table addrconf_conf_dir[2];
-       ctl_table addrconf_proto_dir[2];
-       ctl_table addrconf_root_dir[2];
+       char *dev_name;
 } addrconf_sysctl __read_mostly = {
        .sysctl_header = NULL,
        .addrconf_vars = {
-               {
+               {
                        .ctl_name       =       NET_IPV6_FORWARDING,
                        .procname       =       "forwarding",
-                       .data           =       &ipv6_devconf.forwarding,
+                       .data           =       &ipv6_devconf.forwarding,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &addrconf_sysctl_forward,
+                       .proc_handler   =       &addrconf_sysctl_forward,
                        .strategy       =       &addrconf_sysctl_forward_strategy,
                },
                {
                        .ctl_name       =       NET_IPV6_HOP_LIMIT,
                        .procname       =       "hop_limit",
-                       .data           =       &ipv6_devconf.hop_limit,
+                       .data           =       &ipv6_devconf.hop_limit,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
                        .proc_handler   =       proc_dointvec,
@@ -3695,116 +3893,116 @@ static struct addrconf_sysctl_table
                        .ctl_name       =       NET_IPV6_MTU,
                        .procname       =       "mtu",
                        .data           =       &ipv6_devconf.mtu6,
-                       .maxlen         =       sizeof(int),
+                       .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_ACCEPT_RA,
                        .procname       =       "accept_ra",
-                       .data           =       &ipv6_devconf.accept_ra,
+                       .data           =       &ipv6_devconf.accept_ra,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_ACCEPT_REDIRECTS,
                        .procname       =       "accept_redirects",
-                       .data           =       &ipv6_devconf.accept_redirects,
+                       .data           =       &ipv6_devconf.accept_redirects,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_AUTOCONF,
                        .procname       =       "autoconf",
-                       .data           =       &ipv6_devconf.autoconf,
+                       .data           =       &ipv6_devconf.autoconf,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_DAD_TRANSMITS,
                        .procname       =       "dad_transmits",
-                       .data           =       &ipv6_devconf.dad_transmits,
+                       .data           =       &ipv6_devconf.dad_transmits,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_RTR_SOLICITS,
                        .procname       =       "router_solicitations",
-                       .data           =       &ipv6_devconf.rtr_solicits,
+                       .data           =       &ipv6_devconf.rtr_solicits,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_RTR_SOLICIT_INTERVAL,
                        .procname       =       "router_solicitation_interval",
-                       .data           =       &ipv6_devconf.rtr_solicit_interval,
+                       .data           =       &ipv6_devconf.rtr_solicit_interval,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec_jiffies,
+                       .proc_handler   =       &proc_dointvec_jiffies,
                        .strategy       =       &sysctl_jiffies,
                },
                {
                        .ctl_name       =       NET_IPV6_RTR_SOLICIT_DELAY,
                        .procname       =       "router_solicitation_delay",
-                       .data           =       &ipv6_devconf.rtr_solicit_delay,
+                       .data           =       &ipv6_devconf.rtr_solicit_delay,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec_jiffies,
+                       .proc_handler   =       &proc_dointvec_jiffies,
                        .strategy       =       &sysctl_jiffies,
                },
                {
                        .ctl_name       =       NET_IPV6_FORCE_MLD_VERSION,
                        .procname       =       "force_mld_version",
-                       .data           =       &ipv6_devconf.force_mld_version,
+                       .data           =       &ipv6_devconf.force_mld_version,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
 #ifdef CONFIG_IPV6_PRIVACY
                {
                        .ctl_name       =       NET_IPV6_USE_TEMPADDR,
                        .procname       =       "use_tempaddr",
-                       .data           =       &ipv6_devconf.use_tempaddr,
+                       .data           =       &ipv6_devconf.use_tempaddr,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_TEMP_VALID_LFT,
                        .procname       =       "temp_valid_lft",
-                       .data           =       &ipv6_devconf.temp_valid_lft,
+                       .data           =       &ipv6_devconf.temp_valid_lft,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_TEMP_PREFERED_LFT,
                        .procname       =       "temp_prefered_lft",
-                       .data           =       &ipv6_devconf.temp_prefered_lft,
+                       .data           =       &ipv6_devconf.temp_prefered_lft,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_REGEN_MAX_RETRY,
                        .procname       =       "regen_max_retry",
-                       .data           =       &ipv6_devconf.regen_max_retry,
+                       .data           =       &ipv6_devconf.regen_max_retry,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_MAX_DESYNC_FACTOR,
                        .procname       =       "max_desync_factor",
-                       .data           =       &ipv6_devconf.max_desync_factor,
+                       .data           =       &ipv6_devconf.max_desync_factor,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
 #endif
                {
@@ -3818,18 +4016,18 @@ static struct addrconf_sysctl_table
                {
                        .ctl_name       =       NET_IPV6_ACCEPT_RA_DEFRTR,
                        .procname       =       "accept_ra_defrtr",
-                       .data           =       &ipv6_devconf.accept_ra_defrtr,
+                       .data           =       &ipv6_devconf.accept_ra_defrtr,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
                        .ctl_name       =       NET_IPV6_ACCEPT_RA_PINFO,
                        .procname       =       "accept_ra_pinfo",
-                       .data           =       &ipv6_devconf.accept_ra_pinfo,
+                       .data           =       &ipv6_devconf.accept_ra_pinfo,
                        .maxlen         =       sizeof(int),
                        .mode           =       0644,
-                       .proc_handler   =       &proc_dointvec,
+                       .proc_handler   =       &proc_dointvec,
                },
 #ifdef CONFIG_IPV6_ROUTER_PREF
                {
@@ -3849,7 +4047,7 @@ static struct addrconf_sysctl_table
                        .proc_handler   =       &proc_dointvec_jiffies,
                        .strategy       =       &sysctl_jiffies,
                },
-#ifdef CONFIV_IPV6_ROUTE_INFO
+#ifdef CONFIG_IPV6_ROUTE_INFO
                {
                        .ctl_name       =       NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN,
                        .procname       =       "accept_ra_rt_info_max_plen",
@@ -3861,128 +4059,189 @@ static struct addrconf_sysctl_table
 #endif
 #endif
                {
-                       .ctl_name       =       0,      /* sentinel */
-               }
-       },
-       .addrconf_dev = {
-               {
-                       .ctl_name       =       NET_PROTO_CONF_ALL,
-                       .procname       =       "all",
-                       .mode           =       0555,
-                       .child          =       addrconf_sysctl.addrconf_vars,
-               },
-               {
-                       .ctl_name       =       0,      /* sentinel */
-               }
-       },
-       .addrconf_conf_dir = {
-               {
-                       .ctl_name       =       NET_IPV6_CONF,
-                       .procname       =       "conf",
-                       .mode           =       0555,
-                       .child          =       addrconf_sysctl.addrconf_dev,
+                       .ctl_name       =       NET_IPV6_PROXY_NDP,
+                       .procname       =       "proxy_ndp",
+                       .data           =       &ipv6_devconf.proxy_ndp,
+                       .maxlen         =       sizeof(int),
+                       .mode           =       0644,
+                       .proc_handler   =       &proc_dointvec,
                },
                {
-                       .ctl_name       =       0,      /* sentinel */
-               }
-       },
-       .addrconf_proto_dir = {
-               {
-                       .ctl_name       =       NET_IPV6,
-                       .procname       =       "ipv6",
-                       .mode           =       0555,
-                       .child          =       addrconf_sysctl.addrconf_conf_dir,
+                       .ctl_name       =       NET_IPV6_ACCEPT_SOURCE_ROUTE,
+                       .procname       =       "accept_source_route",
+                       .data           =       &ipv6_devconf.accept_source_route,
+                       .maxlen         =       sizeof(int),
+                       .mode           =       0644,
+                       .proc_handler   =       &proc_dointvec,
                },
+#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
                {
-                       .ctl_name       =       0,      /* sentinel */
-               }
-       },
-       .addrconf_root_dir = {
-               {
-                       .ctl_name       =       CTL_NET,
-                       .procname       =       "net",
-                       .mode           =       0555,
-                       .child          =       addrconf_sysctl.addrconf_proto_dir,
+                       .ctl_name       =       CTL_UNNUMBERED,
+                       .procname       =       "optimistic_dad",
+                       .data           =       &ipv6_devconf.optimistic_dad,
+                       .maxlen         =       sizeof(int),
+                       .mode           =       0644,
+                       .proc_handler   =       &proc_dointvec,
+
                },
+#endif
                {
                        .ctl_name       =       0,      /* sentinel */
                }
        },
 };
 
-static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p)
+static int __addrconf_sysctl_register(struct net *net, char *dev_name,
+               int ctl_name, struct inet6_dev *idev, struct ipv6_devconf *p)
 {
        int i;
-       struct net_device *dev = idev ? idev->dev : NULL;
        struct addrconf_sysctl_table *t;
-       char *dev_name = NULL;
 
-       t = kmalloc(sizeof(*t), GFP_KERNEL);
+#define ADDRCONF_CTL_PATH_DEV  3
+
+       struct ctl_path addrconf_ctl_path[] = {
+               { .procname = "net", .ctl_name = CTL_NET, },
+               { .procname = "ipv6", .ctl_name = NET_IPV6, },
+               { .procname = "conf", .ctl_name = NET_IPV6_CONF, },
+               { /* to be set */ },
+               { },
+       };
+
+
+       t = kmemdup(&addrconf_sysctl, sizeof(*t), GFP_KERNEL);
        if (t == NULL)
-               return;
-       memcpy(t, &addrconf_sysctl, sizeof(*t));
+               goto out;
+
        for (i=0; t->addrconf_vars[i].data; i++) {
                t->addrconf_vars[i].data += (char*)p - (char*)&ipv6_devconf;
-               t->addrconf_vars[i].de = NULL;
                t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */
-       }
-       if (dev) {
-               dev_name = dev->name; 
-               t->addrconf_dev[0].ctl_name = dev->ifindex;
-       } else {
-               dev_name = "default";
-               t->addrconf_dev[0].ctl_name = NET_PROTO_CONF_DEFAULT;
+               t->addrconf_vars[i].extra2 = net;
        }
 
-       /* 
-        * Make a copy of dev_name, because '.procname' is regarded as const 
+       /*
+        * Make a copy of dev_name, because '.procname' is regarded as const
         * by sysctl and we wouldn't want anyone to change it under our feet
         * (see SIOCSIFNAME).
-        */     
-       dev_name = kstrdup(dev_name, GFP_KERNEL);
-       if (!dev_name)
-           goto free;
-
-       t->addrconf_dev[0].procname = dev_name;
-
-       t->addrconf_dev[0].child = t->addrconf_vars;
-       t->addrconf_dev[0].de = NULL;
-       t->addrconf_conf_dir[0].child = t->addrconf_dev;
-       t->addrconf_conf_dir[0].de = NULL;
-       t->addrconf_proto_dir[0].child = t->addrconf_conf_dir;
-       t->addrconf_proto_dir[0].de = NULL;
-       t->addrconf_root_dir[0].child = t->addrconf_proto_dir;
-       t->addrconf_root_dir[0].de = NULL;
-
-       t->sysctl_header = register_sysctl_table(t->addrconf_root_dir, 0);
+        */
+       t->dev_name = kstrdup(dev_name, GFP_KERNEL);
+       if (!t->dev_name)
+               goto free;
+
+       addrconf_ctl_path[ADDRCONF_CTL_PATH_DEV].procname = t->dev_name;
+       addrconf_ctl_path[ADDRCONF_CTL_PATH_DEV].ctl_name = ctl_name;
+
+       t->sysctl_header = register_net_sysctl_table(net, addrconf_ctl_path,
+                       t->addrconf_vars);
        if (t->sysctl_header == NULL)
                goto free_procname;
-       else
-               p->sysctl = t;
-       return;
 
-       /* error path */
- free_procname:
-       kfree(dev_name);
- free:
+       p->sysctl = t;
+       return 0;
+
+free_procname:
+       kfree(t->dev_name);
+free:
        kfree(t);
+out:
+       return -ENOBUFS;
+}
+
+static void __addrconf_sysctl_unregister(struct ipv6_devconf *p)
+{
+       struct addrconf_sysctl_table *t;
+
+       if (p->sysctl == NULL)
+               return;
 
-       return;
+       t = p->sysctl;
+       p->sysctl = NULL;
+       unregister_sysctl_table(t->sysctl_header);
+       kfree(t->dev_name);
+       kfree(t);
 }
 
-static void addrconf_sysctl_unregister(struct ipv6_devconf *p)
+static void addrconf_sysctl_register(struct inet6_dev *idev)
 {
-       if (p->sysctl) {
-               struct addrconf_sysctl_table *t = p->sysctl;
-               p->sysctl = NULL;
-               unregister_sysctl_table(t->sysctl_header);
-               kfree(t->addrconf_dev[0].procname);
-               kfree(t);
-       }
+       neigh_sysctl_register(idev->dev, idev->nd_parms, NET_IPV6,
+                             NET_IPV6_NEIGH, "ipv6",
+                             &ndisc_ifinfo_sysctl_change,
+                             NULL);
+       __addrconf_sysctl_register(idev->dev->nd_net, idev->dev->name,
+                       idev->dev->ifindex, idev, &idev->cnf);
 }
 
+static void addrconf_sysctl_unregister(struct inet6_dev *idev)
+{
+       __addrconf_sysctl_unregister(&idev->cnf);
+       neigh_sysctl_unregister(idev->nd_parms);
+}
 
+
+#endif
+
+static int addrconf_init_net(struct net *net)
+{
+       int err;
+       struct ipv6_devconf *all, *dflt;
+
+       err = -ENOMEM;
+       all = &ipv6_devconf;
+       dflt = &ipv6_devconf_dflt;
+
+       if (net != &init_net) {
+               all = kmemdup(all, sizeof(ipv6_devconf), GFP_KERNEL);
+               if (all == NULL)
+                       goto err_alloc_all;
+
+               dflt = kmemdup(dflt, sizeof(ipv6_devconf_dflt), GFP_KERNEL);
+               if (dflt == NULL)
+                       goto err_alloc_dflt;
+       }
+
+       net->ipv6.devconf_all = all;
+       net->ipv6.devconf_dflt = dflt;
+
+#ifdef CONFIG_SYSCTL
+       err = __addrconf_sysctl_register(net, "all", NET_PROTO_CONF_ALL,
+                       NULL, all);
+       if (err < 0)
+               goto err_reg_all;
+
+       err = __addrconf_sysctl_register(net, "default", NET_PROTO_CONF_DEFAULT,
+                       NULL, dflt);
+       if (err < 0)
+               goto err_reg_dflt;
 #endif
+       return 0;
+
+#ifdef CONFIG_SYSCTL
+err_reg_dflt:
+       __addrconf_sysctl_unregister(all);
+err_reg_all:
+       kfree(dflt);
+#endif
+err_alloc_dflt:
+       kfree(all);
+err_alloc_all:
+       return err;
+}
+
+static void 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) {
+               kfree(net->ipv6.devconf_dflt);
+               kfree(net->ipv6.devconf_all);
+       }
+}
+
+static struct pernet_operations addrconf_ops = {
+       .init = addrconf_init_net,
+       .exit = addrconf_exit_net,
+};
 
 /*
  *      Device notifier
@@ -3990,21 +4249,33 @@ static void addrconf_sysctl_unregister(struct ipv6_devconf *p)
 
 int register_inet6addr_notifier(struct notifier_block *nb)
 {
-        return atomic_notifier_chain_register(&inet6addr_chain, nb);
+       return atomic_notifier_chain_register(&inet6addr_chain, nb);
 }
 
+EXPORT_SYMBOL(register_inet6addr_notifier);
+
 int unregister_inet6addr_notifier(struct notifier_block *nb)
 {
-        return atomic_notifier_chain_unregister(&inet6addr_chain,nb);
+       return atomic_notifier_chain_unregister(&inet6addr_chain,nb);
 }
 
+EXPORT_SYMBOL(unregister_inet6addr_notifier);
+
 /*
  *     Init / cleanup code
  */
 
 int __init addrconf_init(void)
 {
-       int err = 0;
+       int err;
+
+       if ((err = ipv6_addr_label_init()) < 0) {
+               printk(KERN_CRIT "IPv6 Addrconf: cannot initialize default policy table: %d.\n",
+                       err);
+               return err;
+       }
+
+       register_pernet_subsys(&addrconf_ops);
 
        /* The addrconf netdev notifier requires that loopback_dev
         * has it's ipv6 private information allocated and setup
@@ -4025,41 +4296,56 @@ int __init addrconf_init(void)
         * device and it being up should be removed.
         */
        rtnl_lock();
-       if (!ipv6_add_dev(&loopback_dev))
+       if (!ipv6_add_dev(init_net.loopback_dev))
                err = -ENOMEM;
        rtnl_unlock();
        if (err)
-               return err;
+               goto errlo;
 
-       ip6_null_entry.rt6i_idev = in6_dev_get(&loopback_dev);
+       ip6_null_entry.u.dst.dev = init_net.loopback_dev;
+       ip6_null_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
+#ifdef CONFIG_IPV6_MULTIPLE_TABLES
+       ip6_prohibit_entry.u.dst.dev = init_net.loopback_dev;
+       ip6_prohibit_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
+       ip6_blk_hole_entry.u.dst.dev = init_net.loopback_dev;
+       ip6_blk_hole_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
+#endif
 
        register_netdevice_notifier(&ipv6_dev_notf);
 
        addrconf_verify(0);
-       rtnetlink_links[PF_INET6] = inet6_rtnetlink_table;
-#ifdef CONFIG_SYSCTL
-       addrconf_sysctl.sysctl_header =
-               register_sysctl_table(addrconf_sysctl.addrconf_root_dir, 0);
-       addrconf_sysctl_register(NULL, &ipv6_devconf_dflt);
-#endif
+
+       err = __rtnl_register(PF_INET6, RTM_GETLINK, NULL, inet6_dump_ifinfo);
+       if (err < 0)
+               goto errout;
+
+       /* Only the first call to __rtnl_register can fail */
+       __rtnl_register(PF_INET6, RTM_NEWADDR, inet6_rtm_newaddr, NULL);
+       __rtnl_register(PF_INET6, RTM_DELADDR, inet6_rtm_deladdr, NULL);
+       __rtnl_register(PF_INET6, RTM_GETADDR, inet6_rtm_getaddr, inet6_dump_ifaddr);
+       __rtnl_register(PF_INET6, RTM_GETMULTICAST, NULL, inet6_dump_ifmcaddr);
+       __rtnl_register(PF_INET6, RTM_GETANYCAST, NULL, inet6_dump_ifacaddr);
+
+       ipv6_addr_label_rtnl_register();
 
        return 0;
+errout:
+       unregister_netdevice_notifier(&ipv6_dev_notf);
+errlo:
+       unregister_pernet_subsys(&addrconf_ops);
+
+       return err;
 }
 
-void __exit addrconf_cleanup(void)
+void addrconf_cleanup(void)
 {
-       struct net_device *dev;
-       struct inet6_dev *idev;
-       struct inet6_ifaddr *ifa;
+       struct net_device *dev;
+       struct inet6_ifaddr *ifa;
        int i;
 
        unregister_netdevice_notifier(&ipv6_dev_notf);
 
-       rtnetlink_links[PF_INET6] = NULL;
-#ifdef CONFIG_SYSCTL
-       addrconf_sysctl_unregister(&ipv6_devconf_dflt);
-       addrconf_sysctl_unregister(&ipv6_devconf);
-#endif
+       unregister_pernet_subsys(&addrconf_ops);
 
        rtnl_lock();
 
@@ -4067,12 +4353,12 @@ void __exit addrconf_cleanup(void)
         *      clean dev list.
         */
 
-       for (dev=dev_base; dev; dev=dev->next) {
-               if ((idev = __in6_dev_get(dev)) == NULL)
+       for_each_netdev(&init_net, dev) {
+               if (__in6_dev_get(dev) == NULL)
                        continue;
                addrconf_ifdown(dev, 1);
        }
-       addrconf_ifdown(&loopback_dev, 2);
+       addrconf_ifdown(init_net.loopback_dev, 2);
 
        /*
         *      Check hash table.
@@ -4096,8 +4382,4 @@ void __exit addrconf_cleanup(void)
        del_timer(&addr_chk_timer);
 
        rtnl_unlock();
-
-#ifdef CONFIG_PROC_FS
-       proc_net_remove("if_inet6");
-#endif
 }