]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv6/addrconf.c
slub: Fallback to minimal order during slab page allocation
[linux-2.6-omap-h63xx.git] / net / ipv6 / addrconf.c
index ac5d4f4b63129ede92bf20107d415f5fa379ac8d..e591e09e5e4e21ed8db7ab0eee75a3ce27813ffe 100644 (file)
@@ -222,6 +222,8 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
 const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
 const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
+const struct in6_addr in6addr_linklocal_allnodes = IN6ADDR_LINKLOCAL_ALLNODES_INIT;
+const struct in6_addr in6addr_linklocal_allrouters = IN6ADDR_LINKLOCAL_ALLROUTERS_INIT;
 
 /* Check if a valid qdisc is available */
 static inline int addrconf_qdisc_ok(struct net_device *dev)
@@ -321,7 +323,6 @@ 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();
 
@@ -371,25 +372,26 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
         */
        in6_dev_hold(ndev);
 
+#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
+       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;
+       }
+#endif
+
 #ifdef CONFIG_IPV6_PRIVACY
        setup_timer(&ndev->regen_timer, ipv6_regen_rndid, (unsigned long)ndev);
        if ((dev->flags&IFF_LOOPBACK) ||
            dev->type == ARPHRD_TUNNEL ||
-#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
+           dev->type == ARPHRD_TUNNEL6 ||
            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);
@@ -406,8 +408,7 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
        rcu_assign_pointer(dev->ip6_ptr, ndev);
 
        /* Join all-node multicast group */
-       ipv6_addr_all_nodes(&maddr);
-       ipv6_dev_mc_inc(dev, &maddr);
+       ipv6_dev_mc_inc(dev, &in6addr_linklocal_allnodes);
 
        return ndev;
 }
@@ -433,18 +434,15 @@ static void dev_forward_change(struct inet6_dev *idev)
 {
        struct net_device *dev;
        struct inet6_ifaddr *ifa;
-       struct in6_addr addr;
 
        if (!idev)
                return;
        dev = idev->dev;
        if (dev && (dev->flags & IFF_MULTICAST)) {
-               ipv6_addr_all_routers(&addr);
-
                if (idev->cnf.forwarding)
-                       ipv6_dev_mc_inc(dev, &addr);
+                       ipv6_dev_mc_inc(dev, &in6addr_linklocal_allrouters);
                else
-                       ipv6_dev_mc_dec(dev, &addr);
+                       ipv6_dev_mc_dec(dev, &in6addr_linklocal_allrouters);
        }
        for (ifa=idev->addr_list; ifa; ifa=ifa->if_next) {
                if (ifa->flags&IFA_F_TENTATIVE)
@@ -541,6 +539,25 @@ ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
        *ifap = ifp;
 }
 
+/*
+ *     Hash function taken from net_alias.c
+ */
+static u8 ipv6_addr_hash(const struct in6_addr *addr)
+{
+       __u32 word;
+
+       /*
+        * We perform the hash function over the last 64 bits of the address
+        * This will include the IEEE address token on links that support it.
+        */
+
+       word = (__force u32)(addr->s6_addr32[2] ^ addr->s6_addr32[3]);
+       word ^= (word >> 16);
+       word ^= (word >> 8);
+
+       return ((word ^ (word >> 4)) & 0x0f);
+}
+
 /* On success it returns ifp with increased reference count */
 
 static struct inet6_ifaddr *
@@ -776,6 +793,7 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *i
        struct inet6_dev *idev = ifp->idev;
        struct in6_addr addr, *tmpaddr;
        unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_cstamp, tmp_tstamp;
+       unsigned long regen_advance;
        int tmp_plen;
        int ret = 0;
        int max_addresses;
@@ -836,8 +854,23 @@ retry:
        tmp_tstamp = ifp->tstamp;
        spin_unlock_bh(&ifp->lock);
 
+       regen_advance = idev->cnf.regen_max_retry *
+                       idev->cnf.dad_transmits *
+                       idev->nd_parms->retrans_time / HZ;
        write_unlock(&idev->lock);
 
+       /* A temporary address is created only if this calculated Preferred
+        * Lifetime is greater than REGEN_ADVANCE time units.  In particular,
+        * an implementation must not create a temporary address with a zero
+        * Preferred Lifetime.
+        */
+       if (tmp_prefered_lft <= regen_advance) {
+               in6_ifa_put(ifp);
+               in6_dev_put(idev);
+               ret = -1;
+               goto out;
+       }
+
        addr_flags = IFA_F_TEMPORARY;
        /* set in addrconf_prefix_rcv() */
        if (ifp->flags & IFA_F_OPTIMISTIC)
@@ -905,7 +938,7 @@ struct ipv6_saddr_score {
 };
 
 struct ipv6_saddr_dst {
-       struct in6_addr *addr;
+       const struct in6_addr *addr;
        int ifindex;
        int scope;
        int label;
@@ -1039,7 +1072,7 @@ out:
 }
 
 int ipv6_dev_get_saddr(struct net_device *dst_dev,
-                      struct in6_addr *daddr, unsigned int prefs,
+                      const struct in6_addr *daddr, unsigned int prefs,
                       struct in6_addr *saddr)
 {
        struct ipv6_saddr_score scores[2],
@@ -1217,7 +1250,7 @@ int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
 
        read_lock_bh(&addrconf_hash_lock);
        for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
-               if (dev_net(ifp->idev->dev) != net)
+               if (!net_eq(dev_net(ifp->idev->dev), net))
                        continue;
                if (ipv6_addr_equal(&ifp->addr, addr) &&
                    !(ifp->flags&IFA_F_TENTATIVE)) {
@@ -1239,7 +1272,7 @@ int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
        u8 hash = ipv6_addr_hash(addr);
 
        for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
-               if (dev_net(ifp->idev->dev) != net)
+               if (!net_eq(dev_net(ifp->idev->dev), net))
                        continue;
                if (ipv6_addr_equal(&ifp->addr, addr)) {
                        if (dev == NULL || ifp->idev->dev == dev)
@@ -1249,7 +1282,32 @@ int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
        return ifp != NULL;
 }
 
-struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, struct in6_addr *addr,
+int ipv6_chk_prefix(struct in6_addr *addr, struct net_device *dev)
+{
+       struct inet6_dev *idev;
+       struct inet6_ifaddr *ifa;
+       int     onlink;
+
+       onlink = 0;
+       rcu_read_lock();
+       idev = __in6_dev_get(dev);
+       if (idev) {
+               read_lock_bh(&idev->lock);
+               for (ifa = idev->addr_list; ifa; ifa = ifa->if_next) {
+                       onlink = ipv6_prefix_equal(addr, &ifa->addr,
+                                                  ifa->prefix_len);
+                       if (onlink)
+                               break;
+               }
+               read_unlock_bh(&idev->lock);
+       }
+       rcu_read_unlock();
+       return onlink;
+}
+
+EXPORT_SYMBOL(ipv6_chk_prefix);
+
+struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr,
                                     struct net_device *dev, int strict)
 {
        struct inet6_ifaddr * ifp;
@@ -1257,7 +1315,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, struct in6_addr *addr,
 
        read_lock_bh(&addrconf_hash_lock);
        for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
-               if (dev_net(ifp->idev->dev) != net)
+               if (!net_eq(dev_net(ifp->idev->dev), net))
                        continue;
                if (ipv6_addr_equal(&ifp->addr, addr)) {
                        if (dev == NULL || ifp->idev->dev == dev ||
@@ -1434,6 +1492,29 @@ static int addrconf_ifid_infiniband(u8 *eui, struct net_device *dev)
        return 0;
 }
 
+int __ipv6_isatap_ifid(u8 *eui, __be32 addr)
+{
+       eui[0] = (ipv4_is_zeronet(addr) || ipv4_is_private_10(addr) ||
+                 ipv4_is_loopback(addr) || ipv4_is_linklocal_169(addr) ||
+                 ipv4_is_private_172(addr) || ipv4_is_test_192(addr) ||
+                 ipv4_is_anycast_6to4(addr) || ipv4_is_private_192(addr) ||
+                 ipv4_is_test_198(addr) || ipv4_is_multicast(addr) ||
+                 ipv4_is_lbcast(addr)) ? 0x00 : 0x02;
+       eui[1] = 0;
+       eui[2] = 0x5E;
+       eui[3] = 0xFE;
+       memcpy(eui + 4, &addr, 4);
+       return 0;
+}
+EXPORT_SYMBOL(__ipv6_isatap_ifid);
+
+static int addrconf_ifid_sit(u8 *eui, struct net_device *dev)
+{
+       if (dev->priv_flags & IFF_ISATAP)
+               return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr);
+       return -1;
+}
+
 static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
 {
        switch (dev->type) {
@@ -1446,8 +1527,7 @@ static int ipv6_generate_eui64(u8 *eui, struct net_device *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 addrconf_ifid_sit(eui, dev);
        }
        return -1;
 }
@@ -1834,6 +1914,9 @@ ok:
                                 * lifetimes of an existing temporary address
                                 * when processing a Prefix Information Option.
                                 */
+                               if (ifp != ift->ifpub)
+                                       continue;
+
                                spin_lock(&ift->lock);
                                flags = ift->flags;
                                if (ift->valid_lft > valid_lft &&
@@ -2447,7 +2530,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
 
        ASSERT_RTNL();
 
-       if (dev == init_net.loopback_dev && how == 1)
+       if ((dev->flags & IFF_LOOPBACK) && how == 1)
                how = 0;
 
        rt6_ifdown(net, dev);
@@ -2460,7 +2543,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
        /* Step 1: remove reference to ipv6 device from parent device.
                   Do not dev_put!
         */
-       if (how == 1) {
+       if (how) {
                idev->dead = 1;
 
                /* protected by rtnl_lock */
@@ -2492,12 +2575,12 @@ static int addrconf_ifdown(struct net_device *dev, int how)
        write_lock_bh(&idev->lock);
 
        /* Step 3: clear flags for stateless addrconf */
-       if (how != 1)
+       if (!how)
                idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY);
 
        /* Step 4: clear address list */
 #ifdef CONFIG_IPV6_PRIVACY
-       if (how == 1 && del_timer(&idev->regen_timer))
+       if (how && del_timer(&idev->regen_timer))
                in6_dev_put(idev);
 
        /* clear tempaddr list */
@@ -2534,7 +2617,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
 
        /* Step 5: Discard multicast list */
 
-       if (how == 1)
+       if (how)
                ipv6_mc_destroy_dev(idev);
        else
                ipv6_mc_down(idev);
@@ -2543,7 +2626,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
 
        /* Shot the device (if unregistered) */
 
-       if (how == 1) {
+       if (how) {
                addrconf_sysctl_unregister(idev);
                neigh_parms_release(&nd_tbl, idev->nd_parms);
                neigh_ifdown(&nd_tbl, dev);
@@ -2569,8 +2652,6 @@ static void addrconf_rs_timer(unsigned long data)
 
        spin_lock(&ifp->lock);
        if (ifp->probes++ < ifp->idev->cnf.rtr_solicits) {
-               struct in6_addr all_routers;
-
                /* The wait after the last probe can be shorter */
                addrconf_mod_timer(ifp, AC_RS,
                                   (ifp->probes == ifp->idev->cnf.rtr_solicits) ?
@@ -2578,9 +2659,7 @@ static void addrconf_rs_timer(unsigned long data)
                                   ifp->idev->cnf.rtr_solicit_interval);
                spin_unlock(&ifp->lock);
 
-               ipv6_addr_all_routers(&all_routers);
-
-               ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers);
+               ndisc_send_rs(ifp->idev->dev, &ifp->addr, &in6addr_linklocal_allrouters);
        } else {
                spin_unlock(&ifp->lock);
                /*
@@ -2667,7 +2746,6 @@ static void addrconf_dad_timer(unsigned long data)
 {
        struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
        struct inet6_dev *idev = ifp->idev;
-       struct in6_addr unspec;
        struct in6_addr mcaddr;
 
        read_lock_bh(&idev->lock);
@@ -2696,9 +2774,8 @@ static void addrconf_dad_timer(unsigned long data)
        read_unlock_bh(&idev->lock);
 
        /* send a neighbour solicitation for our addr */
-       memset(&unspec, 0, sizeof(unspec));
        addrconf_addr_solict_mult(&ifp->addr, &mcaddr);
-       ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &unspec);
+       ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &in6addr_any);
 out:
        in6_ifa_put(ifp);
 }
@@ -2721,16 +2798,12 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
            ifp->idev->cnf.rtr_solicits > 0 &&
            (dev->flags&IFF_LOOPBACK) == 0 &&
            (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) {
-               struct in6_addr all_routers;
-
-               ipv6_addr_all_routers(&all_routers);
-
                /*
                 *      If a host as already performed a random delay
                 *      [...] as part of DAD [...] there is no need
                 *      to delay again before sending the first RS
                 */
-               ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers);
+               ndisc_send_rs(ifp->idev->dev, &ifp->addr, &in6addr_linklocal_allrouters);
 
                spin_lock_bh(&ifp->lock);
                ifp->probes = 1;
@@ -2771,7 +2844,7 @@ static struct inet6_ifaddr *if6_get_first(struct seq_file *seq)
        for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) {
                ifa = inet6_addr_lst[state->bucket];
 
-               while (ifa && dev_net(ifa->idev->dev) != net)
+               while (ifa && !net_eq(dev_net(ifa->idev->dev), net))
                        ifa = ifa->lst_next;
                if (ifa)
                        break;
@@ -2787,7 +2860,7 @@ static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct inet6_ifad
        ifa = ifa->lst_next;
 try_again:
        if (ifa) {
-               if (dev_net(ifa->idev->dev) != net) {
+               if (!net_eq(dev_net(ifa->idev->dev), net)) {
                        ifa = ifa->lst_next;
                        goto try_again;
                }
@@ -2905,9 +2978,9 @@ int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr)
        u8 hash = ipv6_addr_hash(addr);
        read_lock_bh(&addrconf_hash_lock);
        for (ifp = inet6_addr_lst[hash]; ifp; ifp = ifp->lst_next) {
-               if (dev_net(ifp->idev->dev) != net)
+               if (!net_eq(dev_net(ifp->idev->dev), net))
                        continue;
-               if (ipv6_addr_cmp(&ifp->addr, addr) == 0 &&
+               if (ipv6_addr_equal(&ifp->addr, addr) &&
                    (ifp->flags & IFA_F_HOMEADDRESS)) {
                        ret = 1;
                        break;
@@ -3528,6 +3601,9 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
        array[DEVCONF_OPTIMISTIC_DAD] = cnf->optimistic_dad;
 #endif
+#ifdef CONFIG_IPV6_MROUTE
+       array[DEVCONF_MC_FORWARDING] = cnf->mc_forwarding;
+#endif
 }
 
 static inline size_t inet6_if_nlmsg_size(void)
@@ -3858,7 +3934,7 @@ static int addrconf_sysctl_forward_strategy(ctl_table *table,
 static struct addrconf_sysctl_table
 {
        struct ctl_table_header *sysctl_header;
-       ctl_table addrconf_vars[__NET_IPV6_MAX];
+       ctl_table addrconf_vars[DEVCONF_MAX+1];
        char *dev_name;
 } addrconf_sysctl __read_mostly = {
        .sysctl_header = NULL,
@@ -4075,6 +4151,16 @@ static struct addrconf_sysctl_table
                        .proc_handler   =       &proc_dointvec,
 
                },
+#endif
+#ifdef CONFIG_IPV6_MROUTE
+               {
+                       .ctl_name       =       CTL_UNNUMBERED,
+                       .procname       =       "mc_forwarding",
+                       .data           =       &ipv6_devconf.mc_forwarding,
+                       .maxlen         =       sizeof(int),
+                       .mode           =       0644,
+                       .proc_handler   =       &proc_dointvec,
+               },
 #endif
                {
                        .ctl_name       =       0,      /* sentinel */
@@ -4252,12 +4338,6 @@ int unregister_inet6addr_notifier(struct notifier_block *nb)
 
 EXPORT_SYMBOL(unregister_inet6addr_notifier);
 
-
-static int addrconf_net_init(struct net *net)
-{
-       return 0;
-}
-
 static void addrconf_net_exit(struct net *net)
 {
        struct net_device *dev;
@@ -4274,7 +4354,6 @@ static void addrconf_net_exit(struct net *net)
 }
 
 static struct pernet_operations addrconf_net_ops = {
-       .init = addrconf_net_init,
        .exit = addrconf_net_exit,
 };