]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv6/ip6_tunnel.c
Merge branch 'linus' into x86/ptemask
[linux-2.6-omap-h63xx.git] / net / ipv6 / ip6_tunnel.c
index 511a6c4168870a57a18e30a084a6e0a9b3ae364e..2bda3ba100b170122edc27d843d227976a3c30e9 100644 (file)
@@ -84,13 +84,12 @@ static int ip6_tnl_net_id;
 struct ip6_tnl_net {
        /* the IPv6 tunnel fallback device */
        struct net_device *fb_tnl_dev;
+       /* lists for storing tunnels in use */
+       struct ip6_tnl *tnls_r_l[HASH_SIZE];
+       struct ip6_tnl *tnls_wc[1];
+       struct ip6_tnl **tnls[2];
 };
 
-/* lists for storing tunnels in use */
-static struct ip6_tnl *tnls_r_l[HASH_SIZE];
-static struct ip6_tnl *tnls_wc[1];
-static struct ip6_tnl **tnls[2] = { tnls_wc, tnls_r_l };
-
 /* lock for the tunnel lists */
 static DEFINE_RWLOCK(ip6_tnl_lock);
 
@@ -139,14 +138,15 @@ ip6_tnl_lookup(struct net *net, struct in6_addr *remote, struct in6_addr *local)
        unsigned h0 = HASH(remote);
        unsigned h1 = HASH(local);
        struct ip6_tnl *t;
+       struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
 
-       for (t = tnls_r_l[h0 ^ h1]; t; t = t->next) {
+       for (t = ip6n->tnls_r_l[h0 ^ h1]; t; t = t->next) {
                if (ipv6_addr_equal(local, &t->parms.laddr) &&
                    ipv6_addr_equal(remote, &t->parms.raddr) &&
                    (t->dev->flags & IFF_UP))
                        return t;
        }
-       if ((t = tnls_wc[0]) != NULL && (t->dev->flags & IFF_UP))
+       if ((t = ip6n->tnls_wc[0]) != NULL && (t->dev->flags & IFF_UP))
                return t;
 
        return NULL;
@@ -175,7 +175,7 @@ ip6_tnl_bucket(struct ip6_tnl_net *ip6n, struct ip6_tnl_parm *p)
                prio = 1;
                h = HASH(remote) ^ HASH(local);
        }
-       return &tnls[prio][h];
+       return &ip6n->tnls[prio][h];
 }
 
 /**
@@ -243,6 +243,8 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct ip6_tnl_parm *p)
        if (dev == NULL)
                goto failed;
 
+       dev_net_set(dev, net);
+
        if (strchr(name, '%')) {
                if (dev_alloc_name(dev, name) < 0)
                        goto failed_free;
@@ -314,7 +316,7 @@ ip6_tnl_dev_uninit(struct net_device *dev)
 
        if (dev == ip6n->fb_tnl_dev) {
                write_lock_bh(&ip6_tnl_lock);
-               tnls_wc[0] = NULL;
+               ip6n->tnls_wc[0] = NULL;
                write_unlock_bh(&ip6_tnl_lock);
        } else {
                ip6_tnl_unlink(ip6n, t);
@@ -543,7 +545,7 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
        fl.fl4_dst = eiph->saddr;
        fl.fl4_tos = RT_TOS(eiph->tos);
        fl.proto = IPPROTO_IPIP;
-       if (ip_route_output_key(&init_net, &rt, &fl))
+       if (ip_route_output_key(dev_net(skb->dev), &rt, &fl))
                goto out;
 
        skb2->dev = rt->u.dst.dev;
@@ -555,7 +557,7 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
                fl.fl4_dst = eiph->daddr;
                fl.fl4_src = eiph->saddr;
                fl.fl4_tos = eiph->tos;
-               if (ip_route_output_key(&init_net, &rt, &fl) ||
+               if (ip_route_output_key(dev_net(skb->dev), &rt, &fl) ||
                    rt->u.dst.dev->type != ARPHRD_TUNNEL) {
                        ip_rt_put(rt);
                        goto out;
@@ -612,7 +614,8 @@ ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
                skb_reset_network_header(skb2);
 
                /* Try to guess incoming interface */
-               rt = rt6_lookup(&init_net, &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
+               rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr,
+                               NULL, 0, 0);
 
                if (rt && rt->rt6i_dev)
                        skb2->dev = rt->rt6i_dev;
@@ -656,16 +659,17 @@ static inline int ip6_tnl_rcv_ctl(struct ip6_tnl *t)
 {
        struct ip6_tnl_parm *p = &t->parms;
        int ret = 0;
+       struct net *net = dev_net(t->dev);
 
        if (p->flags & IP6_TNL_F_CAP_RCV) {
                struct net_device *ldev = NULL;
 
                if (p->link)
-                       ldev = dev_get_by_index(&init_net, p->link);
+                       ldev = dev_get_by_index(net, p->link);
 
                if ((ipv6_addr_is_multicast(&p->laddr) ||
-                    likely(ipv6_chk_addr(&init_net, &p->laddr, ldev, 0))) &&
-                   likely(!ipv6_chk_addr(&init_net, &p->raddr, NULL, 0)))
+                    likely(ipv6_chk_addr(net, &p->laddr, ldev, 0))) &&
+                   likely(!ipv6_chk_addr(net, &p->raddr, NULL, 0)))
                        ret = 1;
 
                if (ldev)
@@ -793,19 +797,20 @@ static inline int ip6_tnl_xmit_ctl(struct ip6_tnl *t)
 {
        struct ip6_tnl_parm *p = &t->parms;
        int ret = 0;
+       struct net *net = dev_net(t->dev);
 
        if (p->flags & IP6_TNL_F_CAP_XMIT) {
                struct net_device *ldev = NULL;
 
                if (p->link)
-                       ldev = dev_get_by_index(&init_net, p->link);
+                       ldev = dev_get_by_index(net, p->link);
 
-               if (unlikely(!ipv6_chk_addr(&init_net, &p->laddr, ldev, 0)))
+               if (unlikely(!ipv6_chk_addr(net, &p->laddr, ldev, 0)))
                        printk(KERN_WARNING
                               "%s xmit: Local address not yet configured!\n",
                               p->name);
                else if (!ipv6_addr_is_multicast(&p->raddr) &&
-                        unlikely(ipv6_chk_addr(&init_net, &p->raddr, NULL, 0)))
+                        unlikely(ipv6_chk_addr(net, &p->raddr, NULL, 0)))
                        printk(KERN_WARNING
                               "%s xmit: Routing loop! "
                               "Remote address found on this node!\n",
@@ -858,7 +863,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
        if ((dst = ip6_tnl_dst_check(t)) != NULL)
                dst_hold(dst);
        else {
-               dst = ip6_route_output(&init_net, NULL, fl);
+               dst = ip6_route_output(dev_net(dev), NULL, fl);
 
                if (dst->error || xfrm_lookup(&dst, fl, NULL, 0) < 0)
                        goto tx_err_link_failure;
@@ -1123,7 +1128,8 @@ static void ip6_tnl_link_config(struct ip6_tnl *t)
                int strict = (ipv6_addr_type(&p->raddr) &
                              (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
 
-               struct rt6_info *rt = rt6_lookup(&init_net, &p->raddr, &p->laddr,
+               struct rt6_info *rt = rt6_lookup(dev_net(dev),
+                                                &p->raddr, &p->laddr,
                                                 p->link, strict);
 
                if (rt == NULL)
@@ -1337,6 +1343,7 @@ static void ip6_tnl_dev_setup(struct net_device *dev)
        dev->mtu = ETH_DATA_LEN - sizeof (struct ipv6hdr);
        dev->flags |= IFF_NOARP;
        dev->addr_len = sizeof(struct in6_addr);
+       dev->features |= NETIF_F_NETNS_LOCAL;
 }
 
 
@@ -1378,10 +1385,13 @@ static int
 ip6_fb_tnl_dev_init(struct net_device *dev)
 {
        struct ip6_tnl *t = netdev_priv(dev);
+       struct net *net = dev_net(dev);
+       struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
+
        ip6_tnl_dev_init_gen(dev);
        t->parms.proto = IPPROTO_IPV6;
        dev_hold(dev);
-       tnls_wc[0] = t;
+       ip6n->tnls_wc[0] = t;
        return 0;
 }
 
@@ -1397,13 +1407,27 @@ static struct xfrm6_tunnel ip6ip6_handler = {
        .priority       =       1,
 };
 
+static void ip6_tnl_destroy_tunnels(struct ip6_tnl_net *ip6n)
+{
+       int h;
+       struct ip6_tnl *t;
+
+       for (h = 0; h < HASH_SIZE; h++) {
+               while ((t = ip6n->tnls_r_l[h]) != NULL)
+                       unregister_netdevice(t->dev);
+       }
+
+       t = ip6n->tnls_wc[0];
+       unregister_netdevice(t->dev);
+}
+
 static int ip6_tnl_init_net(struct net *net)
 {
        int err;
        struct ip6_tnl_net *ip6n;
 
        err = -ENOMEM;
-       ip6n = kmalloc(sizeof(struct ip6_tnl_net), GFP_KERNEL);
+       ip6n = kzalloc(sizeof(struct ip6_tnl_net), GFP_KERNEL);
        if (ip6n == NULL)
                goto err_alloc;
 
@@ -1411,6 +1435,9 @@ static int ip6_tnl_init_net(struct net *net)
        if (err < 0)
                goto err_assign;
 
+       ip6n->tnls[0] = ip6n->tnls_wc;
+       ip6n->tnls[1] = ip6n->tnls_r_l;
+
        err = -ENOMEM;
        ip6n->fb_tnl_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6tnl0",
                                      ip6_tnl_dev_setup);
@@ -1441,6 +1468,9 @@ static void ip6_tnl_exit_net(struct net *net)
        struct ip6_tnl_net *ip6n;
 
        ip6n = net_generic(net, ip6_tnl_net_id);
+       rtnl_lock();
+       ip6_tnl_destroy_tunnels(ip6n);
+       rtnl_unlock();
        kfree(ip6n);
 }
 
@@ -1483,20 +1513,6 @@ out:
        return err;
 }
 
-static void __exit ip6_tnl_destroy_tunnels(void)
-{
-       int h;
-       struct ip6_tnl *t;
-
-       for (h = 0; h < HASH_SIZE; h++) {
-               while ((t = tnls_r_l[h]) != NULL)
-                       unregister_netdevice(t->dev);
-       }
-
-       t = tnls_wc[0];
-       unregister_netdevice(t->dev);
-}
-
 /**
  * ip6_tunnel_cleanup - free resources and unregister protocol
  **/
@@ -1509,10 +1525,6 @@ static void __exit ip6_tunnel_cleanup(void)
        if (xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6))
                printk(KERN_INFO "ip6_tunnel close: can't deregister ip6ip6\n");
 
-       rtnl_lock();
-       ip6_tnl_destroy_tunnels();
-       rtnl_unlock();
-
        unregister_pernet_gen_device(ip6_tnl_net_id, &ip6_tnl_net_ops);
 }