Skip to content

Commit f2fc6a5

Browse files
btherydavem330
authored andcommitted
[NETNS][IPV6] route6 - move ip6_dst_ops inside the network namespace
The ip6_dst_ops is moved inside the network namespace structure. All references to this structure are now relative to the initial network namespace. Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9a7ec3a commit f2fc6a5

2 files changed

Lines changed: 32 additions & 31 deletions

File tree

‎include/net/netns/ipv6.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct netns_ipv6 {
4141
struct timer_list *ip6_fib_timer;
4242
struct hlist_head *fib_table_hash;
4343
struct fib6_table *fib6_main_tbl;
44+
struct dst_ops *ip6_dst_ops;
4445
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
4546
struct rt6_info *ip6_prohibit_entry;
4647
struct rt6_info *ip6_blk_hole_entry;

‎net/ipv6/route.c‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ static struct dst_ops ip6_dst_ops_template = {
113113
.entries = ATOMIC_INIT(0),
114114
};
115115

116-
static struct dst_ops *ip6_dst_ops;
117-
118116
static void ip6_rt_blackhole_update_pmtu(struct dst_entry *dst, u32 mtu)
119117
{
120118
}
@@ -188,9 +186,9 @@ static struct rt6_info ip6_blk_hole_entry_template = {
188186
#endif
189187

190188
/* allocate dst with ip6_dst_ops */
191-
static __inline__ struct rt6_info *ip6_dst_alloc(void)
189+
static inline struct rt6_info *ip6_dst_alloc(struct dst_ops *ops)
192190
{
193-
return (struct rt6_info *)dst_alloc(ip6_dst_ops);
191+
return (struct rt6_info *)dst_alloc(ops);
194192
}
195193

196194
static void ip6_dst_destroy(struct dst_entry *dst)
@@ -925,7 +923,7 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
925923
if (unlikely(idev == NULL))
926924
return NULL;
927925

928-
rt = ip6_dst_alloc();
926+
rt = ip6_dst_alloc(net->ipv6.ip6_dst_ops);
929927
if (unlikely(rt == NULL)) {
930928
in6_dev_put(idev);
931929
goto out;
@@ -999,18 +997,18 @@ static int ip6_dst_gc(struct dst_ops *ops)
999997
unsigned long now = jiffies;
1000998

1001999
if (time_after(last_gc + init_net.ipv6.sysctl.ip6_rt_gc_min_interval, now) &&
1002-
atomic_read(&ip6_dst_ops->entries) <= init_net.ipv6.sysctl.ip6_rt_max_size)
1000+
atomic_read(&init_net.ipv6.ip6_dst_ops->entries) <= init_net.ipv6.sysctl.ip6_rt_max_size)
10031001
goto out;
10041002

10051003
expire++;
10061004
fib6_run_gc(expire, &init_net);
10071005
last_gc = now;
1008-
if (atomic_read(&ip6_dst_ops->entries) < ip6_dst_ops->gc_thresh)
1006+
if (atomic_read(&init_net.ipv6.ip6_dst_ops->entries) < init_net.ipv6.ip6_dst_ops->gc_thresh)
10091007
expire = init_net.ipv6.sysctl.ip6_rt_gc_timeout>>1;
10101008

10111009
out:
10121010
expire -= expire>>init_net.ipv6.sysctl.ip6_rt_gc_elasticity;
1013-
return (atomic_read(&ip6_dst_ops->entries) > init_net.ipv6.sysctl.ip6_rt_max_size);
1011+
return (atomic_read(&init_net.ipv6.ip6_dst_ops->entries) > init_net.ipv6.sysctl.ip6_rt_max_size);
10141012
}
10151013

10161014
/* Clean host part of a prefix. Not necessary in radix tree,
@@ -1084,7 +1082,7 @@ int ip6_route_add(struct fib6_config *cfg)
10841082
goto out;
10851083
}
10861084

1087-
rt = ip6_dst_alloc();
1085+
rt = ip6_dst_alloc(net->ipv6.ip6_dst_ops);
10881086

10891087
if (rt == NULL) {
10901088
err = -ENOMEM;
@@ -1570,7 +1568,8 @@ void rt6_pmtu_discovery(struct in6_addr *daddr, struct in6_addr *saddr,
15701568

15711569
static struct rt6_info * ip6_rt_copy(struct rt6_info *ort)
15721570
{
1573-
struct rt6_info *rt = ip6_dst_alloc();
1571+
struct net *net = ort->rt6i_dev->nd_net;
1572+
struct rt6_info *rt = ip6_dst_alloc(net->ipv6.ip6_dst_ops);
15741573

15751574
if (rt) {
15761575
rt->u.dst.input = ort->u.dst.input;
@@ -1849,7 +1848,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
18491848
int anycast)
18501849
{
18511850
struct net *net = idev->dev->nd_net;
1852-
struct rt6_info *rt = ip6_dst_alloc();
1851+
struct rt6_info *rt = ip6_dst_alloc(net->ipv6.ip6_dst_ops);
18531852

18541853
if (rt == NULL)
18551854
return ERR_PTR(-ENOMEM);
@@ -2407,7 +2406,7 @@ static int rt6_stats_seq_show(struct seq_file *seq, void *v)
24072406
net->ipv6.rt6_stats->fib_rt_alloc,
24082407
net->ipv6.rt6_stats->fib_rt_entries,
24092408
net->ipv6.rt6_stats->fib_rt_cache,
2410-
atomic_read(&ip6_dst_ops->entries),
2409+
atomic_read(&net->ipv6.ip6_dst_ops->entries),
24112410
net->ipv6.rt6_stats->fib_discarded_routes);
24122411

24132412
return 0;
@@ -2552,7 +2551,7 @@ struct ctl_table *ipv6_route_sysctl_init(struct net *net)
25522551

25532552
if (table) {
25542553
table[0].data = &net->ipv6.sysctl.flush_delay;
2555-
table[1].data = &ip6_dst_ops_template.gc_thresh;
2554+
table[1].data = &net->ipv6.ip6_dst_ops->gc_thresh;
25562555
table[2].data = &net->ipv6.sysctl.ip6_rt_max_size;
25572556
table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval;
25582557
table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout;
@@ -2571,14 +2570,21 @@ static int ip6_route_net_init(struct net *net)
25712570
int ret = 0;
25722571

25732572
ret = -ENOMEM;
2573+
net->ipv6.ip6_dst_ops = kmemdup(&ip6_dst_ops_template,
2574+
sizeof(*net->ipv6.ip6_dst_ops),
2575+
GFP_KERNEL);
2576+
if (!net->ipv6.ip6_dst_ops)
2577+
goto out;
2578+
net->ipv6.ip6_dst_ops->dst_net = net;
2579+
25742580
net->ipv6.ip6_null_entry = kmemdup(&ip6_null_entry_template,
25752581
sizeof(*net->ipv6.ip6_null_entry),
25762582
GFP_KERNEL);
25772583
if (!net->ipv6.ip6_null_entry)
2578-
goto out;
2584+
goto out_ip6_dst_ops;
25792585
net->ipv6.ip6_null_entry->u.dst.path =
25802586
(struct dst_entry *)net->ipv6.ip6_null_entry;
2581-
net->ipv6.ip6_null_entry->u.dst.ops = ip6_dst_ops;
2587+
net->ipv6.ip6_null_entry->u.dst.ops = net->ipv6.ip6_dst_ops;
25822588

25832589
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
25842590
net->ipv6.ip6_prohibit_entry = kmemdup(&ip6_prohibit_entry_template,
@@ -2590,7 +2596,7 @@ static int ip6_route_net_init(struct net *net)
25902596
}
25912597
net->ipv6.ip6_prohibit_entry->u.dst.path =
25922598
(struct dst_entry *)net->ipv6.ip6_prohibit_entry;
2593-
net->ipv6.ip6_prohibit_entry->u.dst.ops = ip6_dst_ops;
2599+
net->ipv6.ip6_prohibit_entry->u.dst.ops = net->ipv6.ip6_dst_ops;
25942600

25952601
net->ipv6.ip6_blk_hole_entry = kmemdup(&ip6_blk_hole_entry_template,
25962602
sizeof(*net->ipv6.ip6_blk_hole_entry),
@@ -2602,7 +2608,7 @@ static int ip6_route_net_init(struct net *net)
26022608
}
26032609
net->ipv6.ip6_blk_hole_entry->u.dst.path =
26042610
(struct dst_entry *)net->ipv6.ip6_blk_hole_entry;
2605-
net->ipv6.ip6_blk_hole_entry->u.dst.ops = ip6_dst_ops;
2611+
net->ipv6.ip6_blk_hole_entry->u.dst.ops = net->ipv6.ip6_dst_ops;
26062612
#endif
26072613

26082614
#ifdef CONFIG_PROC_FS
@@ -2612,6 +2618,10 @@ static int ip6_route_net_init(struct net *net)
26122618
ret = 0;
26132619
out:
26142620
return ret;
2621+
2622+
out_ip6_dst_ops:
2623+
kfree(net->ipv6.ip6_dst_ops);
2624+
goto out;
26152625
}
26162626

26172627
static void ip6_route_net_exit(struct net *net)
@@ -2625,6 +2635,7 @@ static void ip6_route_net_exit(struct net *net)
26252635
kfree(net->ipv6.ip6_prohibit_entry);
26262636
kfree(net->ipv6.ip6_blk_hole_entry);
26272637
#endif
2638+
kfree(net->ipv6.ip6_dst_ops);
26282639
}
26292640

26302641
static struct pernet_operations ip6_route_net_ops = {
@@ -2641,20 +2652,12 @@ int __init ip6_route_init(void)
26412652
{
26422653
int ret;
26432654

2644-
ip6_dst_ops = kmemdup(&ip6_dst_ops_template,
2645-
sizeof(*ip6_dst_ops), GFP_KERNEL);
2646-
if (!ip6_dst_ops)
2647-
return -ENOMEM;
2648-
26492655
ret = -ENOMEM;
26502656
ip6_dst_ops_template.kmem_cachep =
26512657
kmem_cache_create("ip6_dst_cache", sizeof(struct rt6_info), 0,
26522658
SLAB_HWCACHE_ALIGN, NULL);
26532659
if (!ip6_dst_ops_template.kmem_cachep)
2654-
goto out_ip6_dst_ops;
2655-
2656-
ip6_dst_ops->kmem_cachep = ip6_dst_ops_template.kmem_cachep;
2657-
ip6_dst_blackhole_ops.kmem_cachep = ip6_dst_ops_template.kmem_cachep;
2660+
goto out;;
26582661

26592662
ret = register_pernet_subsys(&ip6_route_net_ops);
26602663
if (ret)
@@ -2705,9 +2708,7 @@ int __init ip6_route_init(void)
27052708
out_register_subsys:
27062709
unregister_pernet_subsys(&ip6_route_net_ops);
27072710
out_kmem_cache:
2708-
kmem_cache_destroy(ip6_dst_ops->kmem_cachep);
2709-
out_ip6_dst_ops:
2710-
kfree(ip6_dst_ops);
2711+
kmem_cache_destroy(ip6_dst_ops_template.kmem_cachep);
27112712
goto out;
27122713
}
27132714

@@ -2718,6 +2719,5 @@ void ip6_route_cleanup(void)
27182719
xfrm6_fini();
27192720
fib6_gc_cleanup();
27202721
unregister_pernet_subsys(&ip6_route_net_ops);
2721-
kmem_cache_destroy(ip6_dst_ops->kmem_cachep);
2722-
kfree(ip6_dst_ops);
2722+
kmem_cache_destroy(ip6_dst_ops_template.kmem_cachep);
27232723
}

0 commit comments

Comments
 (0)