aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/inetpeer.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-06-09 19:27:05 -0400
committerDavid S. Miller <davem@davemloft.net>2012-06-09 19:27:05 -0400
commitc3426b47190d7c6785230c91a706fd42208b4120 (patch)
tree5444acfb2ef8a59c46e580cda8101c32fd3c2973 /net/ipv4/inetpeer.c
parent2397849baa7c44c242e5d5142d5d16d1e7ed53d0 (diff)
inet: Initialize per-netns inetpeer roots in net/ipv{4,6}/route.c
Instead of net/ipv4/inetpeer.c Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/inetpeer.c')
-rw-r--r--net/ipv4/inetpeer.c64
1 files changed, 16 insertions, 48 deletions
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index 1c8527349c86..d0d72f89b279 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -82,11 +82,13 @@ static const struct inet_peer peer_fake_node = {
82 .avl_height = 0 82 .avl_height = 0
83}; 83};
84 84
85struct inet_peer_base { 85void inet_peer_base_init(struct inet_peer_base *bp)
86 struct inet_peer __rcu *root; 86{
87 seqlock_t lock; 87 bp->root = peer_avl_empty_rcu;
88 int total; 88 seqlock_init(&bp->lock);
89}; 89 bp->total = 0;
90}
91EXPORT_SYMBOL_GPL(inet_peer_base_init);
90 92
91#define PEER_MAXDEPTH 40 /* sufficient for about 2^27 nodes */ 93#define PEER_MAXDEPTH 40 /* sufficient for about 2^27 nodes */
92 94
@@ -141,46 +143,6 @@ static void inetpeer_gc_worker(struct work_struct *work)
141 schedule_delayed_work(&gc_work, gc_delay); 143 schedule_delayed_work(&gc_work, gc_delay);
142} 144}
143 145
144static int __net_init inetpeer_net_init(struct net *net)
145{
146 net->ipv4.peers = kzalloc(sizeof(struct inet_peer_base),
147 GFP_KERNEL);
148 if (net->ipv4.peers == NULL)
149 return -ENOMEM;
150
151 net->ipv4.peers->root = peer_avl_empty_rcu;
152 seqlock_init(&net->ipv4.peers->lock);
153
154 net->ipv6.peers = kzalloc(sizeof(struct inet_peer_base),
155 GFP_KERNEL);
156 if (net->ipv6.peers == NULL)
157 goto out_ipv6;
158
159 net->ipv6.peers->root = peer_avl_empty_rcu;
160 seqlock_init(&net->ipv6.peers->lock);
161
162 return 0;
163out_ipv6:
164 kfree(net->ipv4.peers);
165 return -ENOMEM;
166}
167
168static void __net_exit inetpeer_net_exit(struct net *net)
169{
170 inetpeer_invalidate_tree(net, AF_INET);
171 kfree(net->ipv4.peers);
172 net->ipv4.peers = NULL;
173
174 inetpeer_invalidate_tree(net, AF_INET6);
175 kfree(net->ipv6.peers);
176 net->ipv6.peers = NULL;
177}
178
179static struct pernet_operations inetpeer_ops = {
180 .init = inetpeer_net_init,
181 .exit = inetpeer_net_exit,
182};
183
184/* Called from ip_output.c:ip_init */ 146/* Called from ip_output.c:ip_init */
185void __init inet_initpeers(void) 147void __init inet_initpeers(void)
186{ 148{
@@ -205,7 +167,6 @@ void __init inet_initpeers(void)
205 NULL); 167 NULL);
206 168
207 INIT_DELAYED_WORK_DEFERRABLE(&gc_work, inetpeer_gc_worker); 169 INIT_DELAYED_WORK_DEFERRABLE(&gc_work, inetpeer_gc_worker);
208 register_pernet_subsys(&inetpeer_ops);
209} 170}
210 171
211static int addr_compare(const struct inetpeer_addr *a, 172static int addr_compare(const struct inetpeer_addr *a,
@@ -603,10 +564,9 @@ static void inetpeer_inval_rcu(struct rcu_head *head)
603 schedule_delayed_work(&gc_work, gc_delay); 564 schedule_delayed_work(&gc_work, gc_delay);
604} 565}
605 566
606void inetpeer_invalidate_tree(struct net *net, int family) 567void __inetpeer_invalidate_tree(struct inet_peer_base *base)
607{ 568{
608 struct inet_peer *old, *new, *prev; 569 struct inet_peer *old, *new, *prev;
609 struct inet_peer_base *base = family_to_base(net, family);
610 570
611 write_seqlock_bh(&base->lock); 571 write_seqlock_bh(&base->lock);
612 572
@@ -625,4 +585,12 @@ void inetpeer_invalidate_tree(struct net *net, int family)
625out: 585out:
626 write_sequnlock_bh(&base->lock); 586 write_sequnlock_bh(&base->lock);
627} 587}
588EXPORT_SYMBOL(__inetpeer_invalidate_tree);
589
590void inetpeer_invalidate_tree(struct net *net, int family)
591{
592 struct inet_peer_base *base = family_to_base(net, family);
593
594 __inetpeer_invalidate_tree(base);
595}
628EXPORT_SYMBOL(inetpeer_invalidate_tree); 596EXPORT_SYMBOL(inetpeer_invalidate_tree);