[NETNS][IPV6] rt6_stats - dynamically allocate the routes statistics
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Tue, 4 Mar 2008 07:33:43 +0000 (23:33 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 4 Mar 2008 07:33:43 +0000 (23:33 -0800)
This patch allocates the rt6_stats struct dynamically when the fib6 is
initialized. That provides the ability to create several instances of
this structure for the network namespaces.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Benjamin Thery <benjamin.thery@bull.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ipv6.h
net/ipv6/ip6_fib.c
net/ipv6/route.c

index 5dc8164e5d3bf22b80e4f7a4f1b757eeb89f2e57..9a00f35ae77323ffaca8948a6e0c1834d190cb4c 100644 (file)
@@ -611,7 +611,7 @@ extern void ipv6_misc_proc_exit(void);
 extern int snmp6_register_dev(struct inet6_dev *idev);
 extern int snmp6_unregister_dev(struct inet6_dev *idev);
 
-extern struct rt6_statistics rt6_stats;
+extern struct rt6_statistics *rt6_stats;
 #else
 static inline int snmp6_register_dev(struct inet6_dev *idev)
 {
index 350a970ca1e31b95e5a98c047a8d04cf685659f9..7d82ad5401400aff64b63009e42be36131579c05 100644 (file)
@@ -48,7 +48,7 @@
 #define RT6_TRACE(x...) do { ; } while (0)
 #endif
 
-struct rt6_statistics  rt6_stats;
+struct rt6_statistics *rt6_stats;
 
 static struct kmem_cache * fib6_node_kmem __read_mostly;
 
@@ -653,10 +653,10 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
        rt->rt6i_node = fn;
        atomic_inc(&rt->rt6i_ref);
        inet6_rt_notify(RTM_NEWROUTE, rt, info);
-       rt6_stats.fib_rt_entries++;
+       rt6_stats->fib_rt_entries++;
 
        if ((fn->fn_flags & RTN_RTINFO) == 0) {
-               rt6_stats.fib_route_nodes++;
+               rt6_stats->fib_route_nodes++;
                fn->fn_flags |= RTN_RTINFO;
        }
 
@@ -1093,8 +1093,8 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
        /* Unlink it */
        *rtp = rt->u.dst.rt6_next;
        rt->rt6i_node = NULL;
-       rt6_stats.fib_rt_entries--;
-       rt6_stats.fib_discarded_routes++;
+       rt6_stats->fib_rt_entries--;
+       rt6_stats->fib_discarded_routes++;
 
        /* Reset round-robin state, if necessary */
        if (fn->rr_ptr == rt)
@@ -1117,7 +1117,7 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
        /* If it was last route, expunge its radix tree node */
        if (fn->leaf == NULL) {
                fn->fn_flags &= ~RTN_RTINFO;
-               rt6_stats.fib_route_nodes--;
+               rt6_stats->fib_route_nodes--;
                fn = fib6_repair_tree(fn);
        }
 
@@ -1556,9 +1556,14 @@ int __init fib6_init(void)
        if (!fib6_node_kmem)
                goto out;
 
+       ret = -ENOMEM;
+       rt6_stats = kzalloc(sizeof(*rt6_stats), GFP_KERNEL);
+       if (!rt6_stats)
+               goto out_kmem_cache_create;
+
        ret = register_pernet_subsys(&fib6_net_ops);
        if (ret)
-               goto out_kmem_cache_create;
+               goto out_rt6_stats;
 
        ret = __rtnl_register(PF_INET6, RTM_GETROUTE, NULL, inet6_dump_fib);
        if (ret)
@@ -1568,6 +1573,8 @@ out:
 
 out_unregister_subsys:
        unregister_pernet_subsys(&fib6_net_ops);
+out_rt6_stats:
+       kfree(rt6_stats);
 out_kmem_cache_create:
        kmem_cache_destroy(fib6_node_kmem);
        goto out;
@@ -1576,5 +1583,6 @@ out_kmem_cache_create:
 void fib6_gc_cleanup(void)
 {
        unregister_pernet_subsys(&fib6_net_ops);
+       kfree(rt6_stats);
        kmem_cache_destroy(fib6_node_kmem);
 }
index b13eb0111270a085d03935485696ca8e7c8a0cf8..370f2aef69090d127fd07745ce706b49d5ecd287 100644 (file)
@@ -2354,11 +2354,11 @@ static const struct file_operations ipv6_route_proc_fops = {
 static int rt6_stats_seq_show(struct seq_file *seq, void *v)
 {
        seq_printf(seq, "%04x %04x %04x %04x %04x %04x %04x\n",
-                     rt6_stats.fib_nodes, rt6_stats.fib_route_nodes,
-                     rt6_stats.fib_rt_alloc, rt6_stats.fib_rt_entries,
-                     rt6_stats.fib_rt_cache,
+                     rt6_stats->fib_nodes, rt6_stats->fib_route_nodes,
+                     rt6_stats->fib_rt_alloc, rt6_stats->fib_rt_entries,
+                     rt6_stats->fib_rt_cache,
                      atomic_read(&ip6_dst_ops.entries),
-                     rt6_stats.fib_discarded_routes);
+                     rt6_stats->fib_discarded_routes);
 
        return 0;
 }