[NETNS]: Modify the neighbour table code so it handles multiple network namespaces
[safe/jmp/linux-2.6] / net / decnet / dn_route.c
index 580e786..938ba7d 100644 (file)
@@ -293,9 +293,7 @@ static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route *
                                           dn_rt_hash_table[hash].chain);
                        rcu_assign_pointer(dn_rt_hash_table[hash].chain, rth);
 
-                       rth->u.dst.__use++;
-                       dst_hold(&rth->u.dst);
-                       rth->u.dst.lastuse = now;
+                       dst_use(&rth->u.dst, now);
                        spin_unlock_bh(&dn_rt_hash_table[hash].lock);
 
                        dnrt_drop(rt);
@@ -308,9 +306,7 @@ static int dn_insert_route(struct dn_route *rt, unsigned hash, struct dn_route *
        rcu_assign_pointer(rt->u.dst.dn_next, dn_rt_hash_table[hash].chain);
        rcu_assign_pointer(dn_rt_hash_table[hash].chain, rt);
 
-       dst_hold(&rt->u.dst);
-       rt->u.dst.__use++;
-       rt->u.dst.lastuse = now;
+       dst_use(&rt->u.dst, now);
        spin_unlock_bh(&dn_rt_hash_table[hash].lock);
        *rp = rt;
        return 0;
@@ -769,17 +765,6 @@ drop:
 }
 
 /*
- * Drop packet. This is used for endnodes and for
- * when we should not be forwarding packets from
- * this dest.
- */
-static int dn_blackhole(struct sk_buff *skb)
-{
-       kfree_skb(skb);
-       return NET_RX_DROP;
-}
-
-/*
  * Used to catch bugs. This should never normally get
  * called.
  */
@@ -887,7 +872,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
                                        .scope = RT_SCOPE_UNIVERSE,
                                     } },
                            .mark = oldflp->mark,
-                           .iif = loopback_dev.ifindex,
+                           .iif = init_net.loopback_dev->ifindex,
                            .oif = oldflp->oif };
        struct dn_route *rt = NULL;
        struct net_device *dev_out = NULL, *dev;
@@ -904,11 +889,11 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
                       "dn_route_output_slow: dst=%04x src=%04x mark=%d"
                       " iif=%d oif=%d\n", dn_ntohs(oldflp->fld_dst),
                       dn_ntohs(oldflp->fld_src),
-                      oldflp->mark, loopback_dev.ifindex, oldflp->oif);
+                      oldflp->mark, init_net.loopback_dev->ifindex, oldflp->oif);
 
        /* If we have an output interface, verify its a DECnet device */
        if (oldflp->oif) {
-               dev_out = dev_get_by_index(oldflp->oif);
+               dev_out = dev_get_by_index(&init_net, oldflp->oif);
                err = -ENODEV;
                if (dev_out && dev_out->dn_ptr == NULL) {
                        dev_put(dev_out);
@@ -929,7 +914,7 @@ static int dn_route_output_slow(struct dst_entry **pprt, const struct flowi *old
                        goto out;
                }
                read_lock(&dev_base_lock);
-               for_each_netdev(dev) {
+               for_each_netdev(&init_net, dev) {
                        if (!dev->dn_ptr)
                                continue;
                        if (!dn_dev_islocal(dev, oldflp->fld_src))
@@ -957,7 +942,7 @@ source_ok:
                err = -EADDRNOTAVAIL;
                if (dev_out)
                        dev_put(dev_out);
-               dev_out = &loopback_dev;
+               dev_out = init_net.loopback_dev;
                dev_hold(dev_out);
                if (!fl.fld_dst) {
                        fl.fld_dst =
@@ -966,7 +951,7 @@ source_ok:
                        if (!fl.fld_dst)
                                goto out;
                }
-               fl.oif = loopback_dev.ifindex;
+               fl.oif = init_net.loopback_dev->ifindex;
                res.type = RTN_LOCAL;
                goto make_route;
        }
@@ -999,7 +984,7 @@ source_ok:
                 * here
                 */
                if (!try_hard) {
-                       neigh = neigh_lookup_nodev(&dn_neigh_table, &fl.fld_dst);
+                       neigh = neigh_lookup_nodev(&dn_neigh_table, &init_net, &fl.fld_dst);
                        if (neigh) {
                                if ((oldflp->oif &&
                                    (neigh->dev->ifindex != oldflp->oif)) ||
@@ -1012,7 +997,7 @@ source_ok:
                                        if (dev_out)
                                                dev_put(dev_out);
                                        if (dn_dev_islocal(neigh->dev, fl.fld_dst)) {
-                                               dev_out = &loopback_dev;
+                                               dev_out = init_net.loopback_dev;
                                                res.type = RTN_LOCAL;
                                        } else {
                                                dev_out = neigh->dev;
@@ -1033,7 +1018,7 @@ source_ok:
                /* Possible improvement - check all devices for local addr */
                if (dn_dev_islocal(dev_out, fl.fld_dst)) {
                        dev_put(dev_out);
-                       dev_out = &loopback_dev;
+                       dev_out = init_net.loopback_dev;
                        dev_hold(dev_out);
                        res.type = RTN_LOCAL;
                        goto select_source;
@@ -1069,7 +1054,7 @@ select_source:
                        fl.fld_src = fl.fld_dst;
                if (dev_out)
                        dev_put(dev_out);
-               dev_out = &loopback_dev;
+               dev_out = init_net.loopback_dev;
                dev_hold(dev_out);
                fl.oif = dev_out->ifindex;
                if (res.fi)
@@ -1182,9 +1167,7 @@ static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *fl
                            (flp->mark == rt->fl.mark) &&
                            (rt->fl.iif == 0) &&
                            (rt->fl.oif == flp->oif)) {
-                               rt->u.dst.lastuse = jiffies;
-                               dst_hold(&rt->u.dst);
-                               rt->u.dst.__use++;
+                               dst_use(&rt->u.dst, jiffies);
                                rcu_read_unlock_bh();
                                *pprt = &rt->u.dst;
                                return 0;
@@ -1213,7 +1196,8 @@ int dn_route_output_sock(struct dst_entry **pprt, struct flowi *fl, struct sock
 
        err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
        if (err == 0 && fl->proto) {
-               err = xfrm_lookup(pprt, fl, sk, !(flags & MSG_DONTWAIT));
+               err = xfrm_lookup(pprt, fl, sk, (flags & MSG_DONTWAIT) ?
+                                               0 : XFRM_LOOKUP_WAIT);
        }
        return err;
 }
@@ -1402,7 +1386,7 @@ make_route:
                default:
                case RTN_UNREACHABLE:
                case RTN_BLACKHOLE:
-                       rt->u.dst.input = dn_blackhole;
+                       rt->u.dst.input = dst_discard;
        }
        rt->rt_flags = flags;
        if (rt->u.dst.dev)
@@ -1456,9 +1440,7 @@ int dn_route_input(struct sk_buff *skb)
                    (rt->fl.oif == 0) &&
                    (rt->fl.mark == skb->mark) &&
                    (rt->fl.iif == cb->iif)) {
-                       rt->u.dst.lastuse = jiffies;
-                       dst_hold(&rt->u.dst);
-                       rt->u.dst.__use++;
+                       dst_use(&rt->u.dst, jiffies);
                        rcu_read_unlock();
                        skb->dst = (struct dst_entry *)rt;
                        return 0;
@@ -1530,6 +1512,7 @@ rtattr_failure:
  */
 static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
 {
+       struct net *net = in_skb->sk->sk_net;
        struct rtattr **rta = arg;
        struct rtmsg *rtm = NLMSG_DATA(nlh);
        struct dn_route *rt = NULL;
@@ -1538,6 +1521,9 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void
        struct sk_buff *skb;
        struct flowi fl;
 
+       if (net != &init_net)
+               return -EINVAL;
+
        memset(&fl, 0, sizeof(fl));
        fl.proto = DNPROTO_NSP;
 
@@ -1556,7 +1542,7 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void
 
        if (fl.iif) {
                struct net_device *dev;
-               if ((dev = dev_get_by_index(fl.iif)) == NULL) {
+               if ((dev = dev_get_by_index(&init_net, fl.iif)) == NULL) {
                        kfree_skb(skb);
                        return -ENODEV;
                }
@@ -1565,7 +1551,7 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void
                        kfree_skb(skb);
                        return -ENODEV;
                }
-               skb->protocol = __constant_htons(ETH_P_DNA_RT);
+               skb->protocol = htons(ETH_P_DNA_RT);
                skb->dev = dev;
                cb->src = fl.fld_src;
                cb->dst = fl.fld_dst;
@@ -1602,7 +1588,7 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void
                goto out_free;
        }
 
-       return rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
+       return rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).pid);
 
 out_free:
        kfree_skb(skb);
@@ -1615,10 +1601,14 @@ out_free:
  */
 int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = skb->sk->sk_net;
        struct dn_route *rt;
        int h, s_h;
        int idx, s_idx;
 
+       if (net != &init_net)
+               return 0;
+
        if (NLMSG_PAYLOAD(cb->nlh, 0) < sizeof(struct rtmsg))
                return -EINVAL;
        if (!(((struct rtmsg *)NLMSG_DATA(cb->nlh))->rtm_flags&RTM_F_CLONED))
@@ -1673,12 +1663,12 @@ static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
                        break;
                rcu_read_unlock_bh();
        }
-       return rt;
+       return rcu_dereference(rt);
 }
 
 static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
 {
-       struct dn_rt_cache_iter_state *s = rcu_dereference(seq->private);
+       struct dn_rt_cache_iter_state *s = seq->private;
 
        rt = rt->u.dst.dn_next;
        while(!rt) {
@@ -1688,7 +1678,7 @@ static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_rou
                rcu_read_lock_bh();
                rt = dn_rt_hash_table[s->bucket].chain;
        }
-       return rt;
+       return rcu_dereference(rt);
 }
 
 static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
@@ -1739,23 +1729,8 @@ static const struct seq_operations dn_rt_cache_seq_ops = {
 
 static int dn_rt_cache_seq_open(struct inode *inode, struct file *file)
 {
-       struct seq_file *seq;
-       int rc = -ENOMEM;
-       struct dn_rt_cache_iter_state *s;
-
-       s = kzalloc(sizeof(*s), GFP_KERNEL);
-       if (!s)
-               goto out;
-       rc = seq_open(file, &dn_rt_cache_seq_ops);
-       if (rc)
-               goto out_kfree;
-       seq             = file->private_data;
-       seq->private    = s;
-out:
-       return rc;
-out_kfree:
-       kfree(s);
-       goto out;
+       return seq_open_private(file, &dn_rt_cache_seq_ops,
+                       sizeof(struct dn_rt_cache_iter_state));
 }
 
 static const struct file_operations dn_rt_cache_seq_fops = {
@@ -1775,8 +1750,7 @@ void __init dn_route_init(void)
        dn_dst_ops.kmem_cachep =
                kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
                                  SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
-       init_timer(&dn_route_timer);
-       dn_route_timer.function = dn_dst_check_expire;
+       setup_timer(&dn_route_timer, dn_dst_check_expire, 0);
        dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
        add_timer(&dn_route_timer);