]> Pileus Git - ~andy/linux/blobdiff - net/ipv6/ip6_fib.c
[NETNS][IPV6] ip6_fib - dynamically allocate the fib tables
[~andy/linux] / net / ipv6 / ip6_fib.c
index 6a612a701eaaa34b35d6d7778b80c7f62c6bde31..04d774963f3cc27056bd7d811fb8aef3463c0586 100644 (file)
@@ -166,20 +166,14 @@ static __inline__ void rt6_release(struct rt6_info *rt)
                dst_free(&rt->u.dst);
 }
 
-static struct fib6_table fib6_main_tbl = {
-       .tb6_id         = RT6_TABLE_MAIN,
-       .tb6_root       = {
-               .leaf           = &ip6_null_entry,
-               .fn_flags       = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO,
-       },
-};
+static struct fib6_table *fib6_main_tbl;
 
 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
 #define FIB_TABLE_HASHSZ 256
 #else
 #define FIB_TABLE_HASHSZ 1
 #endif
-static struct hlist_head fib_table_hash[FIB_TABLE_HASHSZ];
+static struct hlist_head *fib_table_hash;
 
 static void fib6_link_table(struct fib6_table *tb)
 {
@@ -201,13 +195,8 @@ static void fib6_link_table(struct fib6_table *tb)
 }
 
 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
-static struct fib6_table fib6_local_tbl = {
-       .tb6_id         = RT6_TABLE_LOCAL,
-       .tb6_root       = {
-               .leaf           = &ip6_null_entry,
-               .fn_flags       = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO,
-       },
-};
+
+static struct fib6_table *fib6_local_tbl;
 
 static struct fib6_table *fib6_alloc_table(u32 id)
 {
@@ -263,8 +252,8 @@ struct fib6_table *fib6_get_table(u32 id)
 
 static void __init fib6_tables_init(void)
 {
-       fib6_link_table(&fib6_main_tbl);
-       fib6_link_table(&fib6_local_tbl);
+       fib6_link_table(fib6_main_tbl);
+       fib6_link_table(fib6_local_tbl);
 }
 
 #else
@@ -276,18 +265,18 @@ struct fib6_table *fib6_new_table(u32 id)
 
 struct fib6_table *fib6_get_table(u32 id)
 {
-       return &fib6_main_tbl;
+       return fib6_main_tbl;
 }
 
 struct dst_entry *fib6_rule_lookup(struct flowi *fl, int flags,
                                   pol_lookup_t lookup)
 {
-       return (struct dst_entry *) lookup(&fib6_main_tbl, fl, flags);
+       return (struct dst_entry *) lookup(fib6_main_tbl, fl, flags);
 }
 
 static void __init fib6_tables_init(void)
 {
-       fib6_link_table(&fib6_main_tbl);
+       fib6_link_table(fib6_main_tbl);
 }
 
 #endif
@@ -361,6 +350,7 @@ end:
 
 static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = skb->sk->sk_net;
        unsigned int h, s_h;
        unsigned int e = 0, s_e;
        struct rt6_rtnl_dump_arg arg;
@@ -369,6 +359,9 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
        struct hlist_node *node;
        int res = 0;
 
+       if (net != &init_net)
+               return 0;
+
        s_h = cb->args[0];
        s_e = cb->args[1];
 
@@ -677,13 +670,15 @@ static __inline__ void fib6_start_gc(struct rt6_info *rt)
 {
        if (ip6_fib_timer.expires == 0 &&
            (rt->rt6i_flags & (RTF_EXPIRES|RTF_CACHE)))
-               mod_timer(&ip6_fib_timer, jiffies + ip6_rt_gc_interval);
+               mod_timer(&ip6_fib_timer, jiffies +
+                         init_net.ipv6.sysctl.ip6_rt_gc_interval);
 }
 
 void fib6_force_start_gc(void)
 {
        if (ip6_fib_timer.expires == 0)
-               mod_timer(&ip6_fib_timer, jiffies + ip6_rt_gc_interval);
+               mod_timer(&ip6_fib_timer, jiffies +
+                         init_net.ipv6.sysctl.ip6_rt_gc_interval);
 }
 
 /*
@@ -1122,9 +1117,6 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
 
        rt->u.dst.rt6_next = NULL;
 
-       if (fn->leaf == NULL && fn->fn_flags&RTN_TL_ROOT)
-               fn->leaf = &ip6_null_entry;
-
        /* If it was last route, expunge its radix tree node */
        if (fn->leaf == NULL) {
                fn->fn_flags &= ~RTN_RTINFO;
@@ -1148,7 +1140,7 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
                        fn = fn->parent;
                }
                /* No more references are possible at this point. */
-               if (atomic_read(&rt->rt6i_ref) != 1) BUG();
+               BUG_ON(atomic_read(&rt->rt6i_ref) != 1);
        }
 
        inet6_rt_notify(RTM_DELROUTE, rt, info);
@@ -1311,15 +1303,18 @@ static int fib6_walk(struct fib6_walker_t *w)
 
 static int fib6_clean_node(struct fib6_walker_t *w)
 {
+       struct nl_info info = {
+               .nl_net = &init_net,
+       };
        int res;
        struct rt6_info *rt;
-       struct fib6_cleaner_t *c = (struct fib6_cleaner_t*)w;
+       struct fib6_cleaner_t *c = container_of(w, struct fib6_cleaner_t, w);
 
        for (rt = w->leaf; rt; rt = rt->u.dst.rt6_next) {
                res = c->func(rt, c->arg);
                if (res < 0) {
                        w->leaf = rt;
-                       res = fib6_del(rt, NULL);
+                       res = fib6_del(rt, &info);
                        if (res) {
 #if RT6_DEBUG >= 2
                                printk(KERN_DEBUG "fib6_clean_node: del failed: rt=%p@%p err=%d\n", rt, rt->rt6i_node, res);
@@ -1445,7 +1440,8 @@ void fib6_run_gc(unsigned long dummy)
 {
        if (dummy != ~0UL) {
                spin_lock_bh(&fib6_gc_lock);
-               gc_args.timeout = dummy ? (int)dummy : ip6_rt_gc_interval;
+               gc_args.timeout = dummy ? (int)dummy :
+                       init_net.ipv6.sysctl.ip6_rt_gc_interval;
        } else {
                local_bh_disable();
                if (!spin_trylock(&fib6_gc_lock)) {
@@ -1453,15 +1449,16 @@ void fib6_run_gc(unsigned long dummy)
                        local_bh_enable();
                        return;
                }
-               gc_args.timeout = ip6_rt_gc_interval;
+               gc_args.timeout = init_net.ipv6.sysctl.ip6_rt_gc_interval;
        }
        gc_args.more = 0;
 
-       ndisc_dst_gc(&gc_args.more);
+       icmp6_dst_gc(&gc_args.more);
        fib6_clean_all(fib6_age, 0, NULL);
 
        if (gc_args.more)
-               mod_timer(&ip6_fib_timer, jiffies + ip6_rt_gc_interval);
+               mod_timer(&ip6_fib_timer, jiffies +
+                         init_net.ipv6.sysctl.ip6_rt_gc_interval);
        else {
                del_timer(&ip6_fib_timer);
                ip6_fib_timer.expires = 0;
@@ -1469,20 +1466,67 @@ void fib6_run_gc(unsigned long dummy)
        spin_unlock_bh(&fib6_gc_lock);
 }
 
-void __init fib6_init(void)
+int __init fib6_init(void)
 {
+       int ret = -ENOMEM;
        fib6_node_kmem = kmem_cache_create("fib6_nodes",
                                           sizeof(struct fib6_node),
-                                          0, SLAB_HWCACHE_ALIGN|SLAB_PANIC,
+                                          0, SLAB_HWCACHE_ALIGN,
                                           NULL);
+       if (!fib6_node_kmem)
+               goto out;
+
+       fib_table_hash = kzalloc(sizeof(*fib_table_hash)*FIB_TABLE_HASHSZ,
+                                GFP_KERNEL);
+       if (!fib_table_hash)
+               goto out_kmem_cache_create;
+
+       fib6_main_tbl = kzalloc(sizeof(*fib6_main_tbl), GFP_KERNEL);
+       if (!fib6_main_tbl)
+               goto out_fib_table_hash;
+
+       fib6_main_tbl->tb6_id = RT6_TABLE_MAIN;
+       fib6_main_tbl->tb6_root.leaf = &ip6_null_entry;
+       fib6_main_tbl->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
+
+#ifdef CONFIG_IPV6_MULTIPLE_TABLES
+       fib6_local_tbl = kzalloc(sizeof(*fib6_local_tbl), GFP_KERNEL);
+       if (!fib6_local_tbl)
+               goto out_fib6_main_tbl;
+
+       fib6_local_tbl->tb6_id = RT6_TABLE_LOCAL;
+       fib6_local_tbl->tb6_root.leaf = &ip6_null_entry;
+       fib6_local_tbl->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
+#endif
 
        fib6_tables_init();
 
-       __rtnl_register(PF_INET6, RTM_GETROUTE, NULL, inet6_dump_fib);
+       ret = __rtnl_register(PF_INET6, RTM_GETROUTE, NULL, inet6_dump_fib);
+       if (ret)
+               goto out_fib6_local_tbl;
+out:
+       return ret;
+
+out_fib6_local_tbl:
+#ifdef CONFIG_IPV6_MULTIPLE_TABLES
+       kfree(fib6_local_tbl);
+out_fib6_main_tbl:
+#endif
+       kfree(fib6_main_tbl);
+out_fib_table_hash:
+       kfree(fib_table_hash);
+out_kmem_cache_create:
+       kmem_cache_destroy(fib6_node_kmem);
+       goto out;
 }
 
 void fib6_gc_cleanup(void)
 {
        del_timer(&ip6_fib_timer);
+#ifdef CONFIG_IPV6_MULTIPLE_TABLES
+       kfree(fib6_local_tbl);
+#endif
+       kfree(fib6_main_tbl);
+       kfree(fib_table_hash);
        kmem_cache_destroy(fib6_node_kmem);
 }