aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/ip6mr.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv6/ip6mr.c')
-rw-r--r--net/ipv6/ip6mr.c490
1 files changed, 293 insertions, 197 deletions
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 0524769632e7..3c51b2d827f4 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -49,9 +49,6 @@
49#include <net/addrconf.h> 49#include <net/addrconf.h>
50#include <linux/netfilter_ipv6.h> 50#include <linux/netfilter_ipv6.h>
51 51
52struct sock *mroute6_socket;
53
54
55/* Big lock, protecting vif table, mrt cache and mroute socket state. 52/* Big lock, protecting vif table, mrt cache and mroute socket state.
56 Note that the changes are semaphored via rtnl_lock. 53 Note that the changes are semaphored via rtnl_lock.
57 */ 54 */
@@ -62,22 +59,9 @@ static DEFINE_RWLOCK(mrt_lock);
62 * Multicast router control variables 59 * Multicast router control variables
63 */ 60 */
64 61
65static struct mif_device vif6_table[MAXMIFS]; /* Devices */ 62#define MIF_EXISTS(_net, _idx) ((_net)->ipv6.vif6_table[_idx].dev != NULL)
66static int maxvif;
67
68#define MIF_EXISTS(idx) (vif6_table[idx].dev != NULL)
69
70static int mroute_do_assert; /* Set in PIM assert */
71#ifdef CONFIG_IPV6_PIMSM_V2
72static int mroute_do_pim;
73#else
74#define mroute_do_pim 0
75#endif
76
77static struct mfc6_cache *mfc6_cache_array[MFC6_LINES]; /* Forwarding cache */
78 63
79static struct mfc6_cache *mfc_unres_queue; /* Queue of unresolved entries */ 64static struct mfc6_cache *mfc_unres_queue; /* Queue of unresolved entries */
80static atomic_t cache_resolve_queue_len; /* Size of unresolved */
81 65
82/* Special spinlock for queue of unresolved entries */ 66/* Special spinlock for queue of unresolved entries */
83static DEFINE_SPINLOCK(mfc_unres_lock); 67static DEFINE_SPINLOCK(mfc_unres_lock);
@@ -93,8 +77,10 @@ static DEFINE_SPINLOCK(mfc_unres_lock);
93static struct kmem_cache *mrt_cachep __read_mostly; 77static struct kmem_cache *mrt_cachep __read_mostly;
94 78
95static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache); 79static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache);
96static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert); 80static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt,
81 mifi_t mifi, int assert);
97static int ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm); 82static int ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm);
83static void mroute_clean_tables(struct net *net);
98 84
99#ifdef CONFIG_IPV6_PIMSM_V2 85#ifdef CONFIG_IPV6_PIMSM_V2
100static struct inet6_protocol pim6_protocol; 86static struct inet6_protocol pim6_protocol;
@@ -106,19 +92,22 @@ static struct timer_list ipmr_expire_timer;
106#ifdef CONFIG_PROC_FS 92#ifdef CONFIG_PROC_FS
107 93
108struct ipmr_mfc_iter { 94struct ipmr_mfc_iter {
95 struct seq_net_private p;
109 struct mfc6_cache **cache; 96 struct mfc6_cache **cache;
110 int ct; 97 int ct;
111}; 98};
112 99
113 100
114static struct mfc6_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos) 101static struct mfc6_cache *ipmr_mfc_seq_idx(struct net *net,
102 struct ipmr_mfc_iter *it, loff_t pos)
115{ 103{
116 struct mfc6_cache *mfc; 104 struct mfc6_cache *mfc;
117 105
118 it->cache = mfc6_cache_array; 106 it->cache = net->ipv6.mfc6_cache_array;
119 read_lock(&mrt_lock); 107 read_lock(&mrt_lock);
120 for (it->ct = 0; it->ct < ARRAY_SIZE(mfc6_cache_array); it->ct++) 108 for (it->ct = 0; it->ct < MFC6_LINES; it->ct++)
121 for (mfc = mfc6_cache_array[it->ct]; mfc; mfc = mfc->next) 109 for (mfc = net->ipv6.mfc6_cache_array[it->ct];
110 mfc; mfc = mfc->next)
122 if (pos-- == 0) 111 if (pos-- == 0)
123 return mfc; 112 return mfc;
124 read_unlock(&mrt_lock); 113 read_unlock(&mrt_lock);
@@ -126,7 +115,8 @@ static struct mfc6_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos)
126 it->cache = &mfc_unres_queue; 115 it->cache = &mfc_unres_queue;
127 spin_lock_bh(&mfc_unres_lock); 116 spin_lock_bh(&mfc_unres_lock);
128 for (mfc = mfc_unres_queue; mfc; mfc = mfc->next) 117 for (mfc = mfc_unres_queue; mfc; mfc = mfc->next)
129 if (pos-- == 0) 118 if (net_eq(mfc6_net(mfc), net) &&
119 pos-- == 0)
130 return mfc; 120 return mfc;
131 spin_unlock_bh(&mfc_unres_lock); 121 spin_unlock_bh(&mfc_unres_lock);
132 122
@@ -142,17 +132,19 @@ static struct mfc6_cache *ipmr_mfc_seq_idx(struct ipmr_mfc_iter *it, loff_t pos)
142 */ 132 */
143 133
144struct ipmr_vif_iter { 134struct ipmr_vif_iter {
135 struct seq_net_private p;
145 int ct; 136 int ct;
146}; 137};
147 138
148static struct mif_device *ip6mr_vif_seq_idx(struct ipmr_vif_iter *iter, 139static struct mif_device *ip6mr_vif_seq_idx(struct net *net,
140 struct ipmr_vif_iter *iter,
149 loff_t pos) 141 loff_t pos)
150{ 142{
151 for (iter->ct = 0; iter->ct < maxvif; ++iter->ct) { 143 for (iter->ct = 0; iter->ct < net->ipv6.maxvif; ++iter->ct) {
152 if (!MIF_EXISTS(iter->ct)) 144 if (!MIF_EXISTS(net, iter->ct))
153 continue; 145 continue;
154 if (pos-- == 0) 146 if (pos-- == 0)
155 return &vif6_table[iter->ct]; 147 return &net->ipv6.vif6_table[iter->ct];
156 } 148 }
157 return NULL; 149 return NULL;
158} 150}
@@ -160,23 +152,26 @@ static struct mif_device *ip6mr_vif_seq_idx(struct ipmr_vif_iter *iter,
160static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos) 152static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos)
161 __acquires(mrt_lock) 153 __acquires(mrt_lock)
162{ 154{
155 struct net *net = seq_file_net(seq);
156
163 read_lock(&mrt_lock); 157 read_lock(&mrt_lock);
164 return (*pos ? ip6mr_vif_seq_idx(seq->private, *pos - 1) 158 return *pos ? ip6mr_vif_seq_idx(net, seq->private, *pos - 1)
165 : SEQ_START_TOKEN); 159 : SEQ_START_TOKEN;
166} 160}
167 161
168static void *ip6mr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos) 162static void *ip6mr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos)
169{ 163{
170 struct ipmr_vif_iter *iter = seq->private; 164 struct ipmr_vif_iter *iter = seq->private;
165 struct net *net = seq_file_net(seq);
171 166
172 ++*pos; 167 ++*pos;
173 if (v == SEQ_START_TOKEN) 168 if (v == SEQ_START_TOKEN)
174 return ip6mr_vif_seq_idx(iter, 0); 169 return ip6mr_vif_seq_idx(net, iter, 0);
175 170
176 while (++iter->ct < maxvif) { 171 while (++iter->ct < net->ipv6.maxvif) {
177 if (!MIF_EXISTS(iter->ct)) 172 if (!MIF_EXISTS(net, iter->ct))
178 continue; 173 continue;
179 return &vif6_table[iter->ct]; 174 return &net->ipv6.vif6_table[iter->ct];
180 } 175 }
181 return NULL; 176 return NULL;
182} 177}
@@ -189,6 +184,8 @@ static void ip6mr_vif_seq_stop(struct seq_file *seq, void *v)
189 184
190static int ip6mr_vif_seq_show(struct seq_file *seq, void *v) 185static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
191{ 186{
187 struct net *net = seq_file_net(seq);
188
192 if (v == SEQ_START_TOKEN) { 189 if (v == SEQ_START_TOKEN) {
193 seq_puts(seq, 190 seq_puts(seq,
194 "Interface BytesIn PktsIn BytesOut PktsOut Flags\n"); 191 "Interface BytesIn PktsIn BytesOut PktsOut Flags\n");
@@ -198,7 +195,7 @@ static int ip6mr_vif_seq_show(struct seq_file *seq, void *v)
198 195
199 seq_printf(seq, 196 seq_printf(seq,
200 "%2td %-10s %8ld %7ld %8ld %7ld %05X\n", 197 "%2td %-10s %8ld %7ld %8ld %7ld %05X\n",
201 vif - vif6_table, 198 vif - net->ipv6.vif6_table,
202 name, vif->bytes_in, vif->pkt_in, 199 name, vif->bytes_in, vif->pkt_in,
203 vif->bytes_out, vif->pkt_out, 200 vif->bytes_out, vif->pkt_out,
204 vif->flags); 201 vif->flags);
@@ -215,8 +212,8 @@ static struct seq_operations ip6mr_vif_seq_ops = {
215 212
216static int ip6mr_vif_open(struct inode *inode, struct file *file) 213static int ip6mr_vif_open(struct inode *inode, struct file *file)
217{ 214{
218 return seq_open_private(file, &ip6mr_vif_seq_ops, 215 return seq_open_net(inode, file, &ip6mr_vif_seq_ops,
219 sizeof(struct ipmr_vif_iter)); 216 sizeof(struct ipmr_vif_iter));
220} 217}
221 218
222static struct file_operations ip6mr_vif_fops = { 219static struct file_operations ip6mr_vif_fops = {
@@ -224,24 +221,27 @@ static struct file_operations ip6mr_vif_fops = {
224 .open = ip6mr_vif_open, 221 .open = ip6mr_vif_open,
225 .read = seq_read, 222 .read = seq_read,
226 .llseek = seq_lseek, 223 .llseek = seq_lseek,
227 .release = seq_release_private, 224 .release = seq_release_net,
228}; 225};
229 226
230static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos) 227static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos)
231{ 228{
232 return (*pos ? ipmr_mfc_seq_idx(seq->private, *pos - 1) 229 struct net *net = seq_file_net(seq);
233 : SEQ_START_TOKEN); 230
231 return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1)
232 : SEQ_START_TOKEN;
234} 233}
235 234
236static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) 235static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
237{ 236{
238 struct mfc6_cache *mfc = v; 237 struct mfc6_cache *mfc = v;
239 struct ipmr_mfc_iter *it = seq->private; 238 struct ipmr_mfc_iter *it = seq->private;
239 struct net *net = seq_file_net(seq);
240 240
241 ++*pos; 241 ++*pos;
242 242
243 if (v == SEQ_START_TOKEN) 243 if (v == SEQ_START_TOKEN)
244 return ipmr_mfc_seq_idx(seq->private, 0); 244 return ipmr_mfc_seq_idx(net, seq->private, 0);
245 245
246 if (mfc->next) 246 if (mfc->next)
247 return mfc->next; 247 return mfc->next;
@@ -249,10 +249,10 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
249 if (it->cache == &mfc_unres_queue) 249 if (it->cache == &mfc_unres_queue)
250 goto end_of_list; 250 goto end_of_list;
251 251
252 BUG_ON(it->cache != mfc6_cache_array); 252 BUG_ON(it->cache != net->ipv6.mfc6_cache_array);
253 253
254 while (++it->ct < ARRAY_SIZE(mfc6_cache_array)) { 254 while (++it->ct < MFC6_LINES) {
255 mfc = mfc6_cache_array[it->ct]; 255 mfc = net->ipv6.mfc6_cache_array[it->ct];
256 if (mfc) 256 if (mfc)
257 return mfc; 257 return mfc;
258 } 258 }
@@ -277,16 +277,18 @@ static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
277static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) 277static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v)
278{ 278{
279 struct ipmr_mfc_iter *it = seq->private; 279 struct ipmr_mfc_iter *it = seq->private;
280 struct net *net = seq_file_net(seq);
280 281
281 if (it->cache == &mfc_unres_queue) 282 if (it->cache == &mfc_unres_queue)
282 spin_unlock_bh(&mfc_unres_lock); 283 spin_unlock_bh(&mfc_unres_lock);
283 else if (it->cache == mfc6_cache_array) 284 else if (it->cache == net->ipv6.mfc6_cache_array)
284 read_unlock(&mrt_lock); 285 read_unlock(&mrt_lock);
285} 286}
286 287
287static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) 288static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
288{ 289{
289 int n; 290 int n;
291 struct net *net = seq_file_net(seq);
290 292
291 if (v == SEQ_START_TOKEN) { 293 if (v == SEQ_START_TOKEN) {
292 seq_puts(seq, 294 seq_puts(seq,
@@ -297,23 +299,28 @@ static int ipmr_mfc_seq_show(struct seq_file *seq, void *v)
297 const struct mfc6_cache *mfc = v; 299 const struct mfc6_cache *mfc = v;
298 const struct ipmr_mfc_iter *it = seq->private; 300 const struct ipmr_mfc_iter *it = seq->private;
299 301
300 seq_printf(seq, 302 seq_printf(seq, "%pI6 %pI6 %-3hd",
301 NIP6_FMT " " NIP6_FMT " %-3d %8ld %8ld %8ld", 303 &mfc->mf6c_mcastgrp, &mfc->mf6c_origin,
302 NIP6(mfc->mf6c_mcastgrp), NIP6(mfc->mf6c_origin), 304 mfc->mf6c_parent);
303 mfc->mf6c_parent,
304 mfc->mfc_un.res.pkt,
305 mfc->mfc_un.res.bytes,
306 mfc->mfc_un.res.wrong_if);
307 305
308 if (it->cache != &mfc_unres_queue) { 306 if (it->cache != &mfc_unres_queue) {
307 seq_printf(seq, " %8lu %8lu %8lu",
308 mfc->mfc_un.res.pkt,
309 mfc->mfc_un.res.bytes,
310 mfc->mfc_un.res.wrong_if);
309 for (n = mfc->mfc_un.res.minvif; 311 for (n = mfc->mfc_un.res.minvif;
310 n < mfc->mfc_un.res.maxvif; n++) { 312 n < mfc->mfc_un.res.maxvif; n++) {
311 if (MIF_EXISTS(n) && 313 if (MIF_EXISTS(net, n) &&
312 mfc->mfc_un.res.ttls[n] < 255) 314 mfc->mfc_un.res.ttls[n] < 255)
313 seq_printf(seq, 315 seq_printf(seq,
314 " %2d:%-3d", 316 " %2d:%-3d",
315 n, mfc->mfc_un.res.ttls[n]); 317 n, mfc->mfc_un.res.ttls[n]);
316 } 318 }
319 } else {
320 /* unresolved mfc_caches don't contain
321 * pkt, bytes and wrong_if values
322 */
323 seq_printf(seq, " %8lu %8lu %8lu", 0ul, 0ul, 0ul);
317 } 324 }
318 seq_putc(seq, '\n'); 325 seq_putc(seq, '\n');
319 } 326 }
@@ -329,8 +336,8 @@ static struct seq_operations ipmr_mfc_seq_ops = {
329 336
330static int ipmr_mfc_open(struct inode *inode, struct file *file) 337static int ipmr_mfc_open(struct inode *inode, struct file *file)
331{ 338{
332 return seq_open_private(file, &ipmr_mfc_seq_ops, 339 return seq_open_net(inode, file, &ipmr_mfc_seq_ops,
333 sizeof(struct ipmr_mfc_iter)); 340 sizeof(struct ipmr_mfc_iter));
334} 341}
335 342
336static struct file_operations ip6mr_mfc_fops = { 343static struct file_operations ip6mr_mfc_fops = {
@@ -338,18 +345,19 @@ static struct file_operations ip6mr_mfc_fops = {
338 .open = ipmr_mfc_open, 345 .open = ipmr_mfc_open,
339 .read = seq_read, 346 .read = seq_read,
340 .llseek = seq_lseek, 347 .llseek = seq_lseek,
341 .release = seq_release_private, 348 .release = seq_release_net,
342}; 349};
343#endif 350#endif
344 351
345#ifdef CONFIG_IPV6_PIMSM_V2 352#ifdef CONFIG_IPV6_PIMSM_V2
346static int reg_vif_num = -1;
347 353
348static int pim6_rcv(struct sk_buff *skb) 354static int pim6_rcv(struct sk_buff *skb)
349{ 355{
350 struct pimreghdr *pim; 356 struct pimreghdr *pim;
351 struct ipv6hdr *encap; 357 struct ipv6hdr *encap;
352 struct net_device *reg_dev = NULL; 358 struct net_device *reg_dev = NULL;
359 struct net *net = dev_net(skb->dev);
360 int reg_vif_num = net->ipv6.mroute_reg_vif_num;
353 361
354 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap))) 362 if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap)))
355 goto drop; 363 goto drop;
@@ -372,7 +380,7 @@ static int pim6_rcv(struct sk_buff *skb)
372 380
373 read_lock(&mrt_lock); 381 read_lock(&mrt_lock);
374 if (reg_vif_num >= 0) 382 if (reg_vif_num >= 0)
375 reg_dev = vif6_table[reg_vif_num].dev; 383 reg_dev = net->ipv6.vif6_table[reg_vif_num].dev;
376 if (reg_dev) 384 if (reg_dev)
377 dev_hold(reg_dev); 385 dev_hold(reg_dev);
378 read_unlock(&mrt_lock); 386 read_unlock(&mrt_lock);
@@ -408,25 +416,32 @@ static struct inet6_protocol pim6_protocol = {
408 416
409static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) 417static int reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
410{ 418{
419 struct net *net = dev_net(dev);
420
411 read_lock(&mrt_lock); 421 read_lock(&mrt_lock);
412 dev->stats.tx_bytes += skb->len; 422 dev->stats.tx_bytes += skb->len;
413 dev->stats.tx_packets++; 423 dev->stats.tx_packets++;
414 ip6mr_cache_report(skb, reg_vif_num, MRT6MSG_WHOLEPKT); 424 ip6mr_cache_report(net, skb, net->ipv6.mroute_reg_vif_num,
425 MRT6MSG_WHOLEPKT);
415 read_unlock(&mrt_lock); 426 read_unlock(&mrt_lock);
416 kfree_skb(skb); 427 kfree_skb(skb);
417 return 0; 428 return 0;
418} 429}
419 430
431static const struct net_device_ops reg_vif_netdev_ops = {
432 .ndo_start_xmit = reg_vif_xmit,
433};
434
420static void reg_vif_setup(struct net_device *dev) 435static void reg_vif_setup(struct net_device *dev)
421{ 436{
422 dev->type = ARPHRD_PIMREG; 437 dev->type = ARPHRD_PIMREG;
423 dev->mtu = 1500 - sizeof(struct ipv6hdr) - 8; 438 dev->mtu = 1500 - sizeof(struct ipv6hdr) - 8;
424 dev->flags = IFF_NOARP; 439 dev->flags = IFF_NOARP;
425 dev->hard_start_xmit = reg_vif_xmit; 440 dev->netdev_ops = &reg_vif_netdev_ops;
426 dev->destructor = free_netdev; 441 dev->destructor = free_netdev;
427} 442}
428 443
429static struct net_device *ip6mr_reg_vif(void) 444static struct net_device *ip6mr_reg_vif(struct net *net)
430{ 445{
431 struct net_device *dev; 446 struct net_device *dev;
432 447
@@ -434,6 +449,8 @@ static struct net_device *ip6mr_reg_vif(void)
434 if (dev == NULL) 449 if (dev == NULL)
435 return NULL; 450 return NULL;
436 451
452 dev_net_set(dev, net);
453
437 if (register_netdevice(dev)) { 454 if (register_netdevice(dev)) {
438 free_netdev(dev); 455 free_netdev(dev);
439 return NULL; 456 return NULL;
@@ -460,14 +477,14 @@ failure:
460 * Delete a VIF entry 477 * Delete a VIF entry
461 */ 478 */
462 479
463static int mif6_delete(int vifi) 480static int mif6_delete(struct net *net, int vifi)
464{ 481{
465 struct mif_device *v; 482 struct mif_device *v;
466 struct net_device *dev; 483 struct net_device *dev;
467 if (vifi < 0 || vifi >= maxvif) 484 if (vifi < 0 || vifi >= net->ipv6.maxvif)
468 return -EADDRNOTAVAIL; 485 return -EADDRNOTAVAIL;
469 486
470 v = &vif6_table[vifi]; 487 v = &net->ipv6.vif6_table[vifi];
471 488
472 write_lock_bh(&mrt_lock); 489 write_lock_bh(&mrt_lock);
473 dev = v->dev; 490 dev = v->dev;
@@ -479,17 +496,17 @@ static int mif6_delete(int vifi)
479 } 496 }
480 497
481#ifdef CONFIG_IPV6_PIMSM_V2 498#ifdef CONFIG_IPV6_PIMSM_V2
482 if (vifi == reg_vif_num) 499 if (vifi == net->ipv6.mroute_reg_vif_num)
483 reg_vif_num = -1; 500 net->ipv6.mroute_reg_vif_num = -1;
484#endif 501#endif
485 502
486 if (vifi + 1 == maxvif) { 503 if (vifi + 1 == net->ipv6.maxvif) {
487 int tmp; 504 int tmp;
488 for (tmp = vifi - 1; tmp >= 0; tmp--) { 505 for (tmp = vifi - 1; tmp >= 0; tmp--) {
489 if (MIF_EXISTS(tmp)) 506 if (MIF_EXISTS(net, tmp))
490 break; 507 break;
491 } 508 }
492 maxvif = tmp + 1; 509 net->ipv6.maxvif = tmp + 1;
493 } 510 }
494 511
495 write_unlock_bh(&mrt_lock); 512 write_unlock_bh(&mrt_lock);
@@ -503,6 +520,12 @@ static int mif6_delete(int vifi)
503 return 0; 520 return 0;
504} 521}
505 522
523static inline void ip6mr_cache_free(struct mfc6_cache *c)
524{
525 release_net(mfc6_net(c));
526 kmem_cache_free(mrt_cachep, c);
527}
528
506/* Destroy an unresolved cache entry, killing queued skbs 529/* Destroy an unresolved cache entry, killing queued skbs
507 and reporting error to netlink readers. 530 and reporting error to netlink readers.
508 */ 531 */
@@ -510,8 +533,9 @@ static int mif6_delete(int vifi)
510static void ip6mr_destroy_unres(struct mfc6_cache *c) 533static void ip6mr_destroy_unres(struct mfc6_cache *c)
511{ 534{
512 struct sk_buff *skb; 535 struct sk_buff *skb;
536 struct net *net = mfc6_net(c);
513 537
514 atomic_dec(&cache_resolve_queue_len); 538 atomic_dec(&net->ipv6.cache_resolve_queue_len);
515 539
516 while((skb = skb_dequeue(&c->mfc_un.unres.unresolved)) != NULL) { 540 while((skb = skb_dequeue(&c->mfc_un.unres.unresolved)) != NULL) {
517 if (ipv6_hdr(skb)->version == 0) { 541 if (ipv6_hdr(skb)->version == 0) {
@@ -520,12 +544,12 @@ static void ip6mr_destroy_unres(struct mfc6_cache *c)
520 nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr)); 544 nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr));
521 skb_trim(skb, nlh->nlmsg_len); 545 skb_trim(skb, nlh->nlmsg_len);
522 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -ETIMEDOUT; 546 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -ETIMEDOUT;
523 rtnl_unicast(skb, &init_net, NETLINK_CB(skb).pid); 547 rtnl_unicast(skb, net, NETLINK_CB(skb).pid);
524 } else 548 } else
525 kfree_skb(skb); 549 kfree_skb(skb);
526 } 550 }
527 551
528 kmem_cache_free(mrt_cachep, c); 552 ip6mr_cache_free(c);
529} 553}
530 554
531 555
@@ -553,7 +577,7 @@ static void ipmr_do_expire_process(unsigned long dummy)
553 ip6mr_destroy_unres(c); 577 ip6mr_destroy_unres(c);
554 } 578 }
555 579
556 if (atomic_read(&cache_resolve_queue_len)) 580 if (mfc_unres_queue != NULL)
557 mod_timer(&ipmr_expire_timer, jiffies + expires); 581 mod_timer(&ipmr_expire_timer, jiffies + expires);
558} 582}
559 583
@@ -564,7 +588,7 @@ static void ipmr_expire_process(unsigned long dummy)
564 return; 588 return;
565 } 589 }
566 590
567 if (atomic_read(&cache_resolve_queue_len)) 591 if (mfc_unres_queue != NULL)
568 ipmr_do_expire_process(dummy); 592 ipmr_do_expire_process(dummy);
569 593
570 spin_unlock(&mfc_unres_lock); 594 spin_unlock(&mfc_unres_lock);
@@ -575,13 +599,15 @@ static void ipmr_expire_process(unsigned long dummy)
575static void ip6mr_update_thresholds(struct mfc6_cache *cache, unsigned char *ttls) 599static void ip6mr_update_thresholds(struct mfc6_cache *cache, unsigned char *ttls)
576{ 600{
577 int vifi; 601 int vifi;
602 struct net *net = mfc6_net(cache);
578 603
579 cache->mfc_un.res.minvif = MAXMIFS; 604 cache->mfc_un.res.minvif = MAXMIFS;
580 cache->mfc_un.res.maxvif = 0; 605 cache->mfc_un.res.maxvif = 0;
581 memset(cache->mfc_un.res.ttls, 255, MAXMIFS); 606 memset(cache->mfc_un.res.ttls, 255, MAXMIFS);
582 607
583 for (vifi = 0; vifi < maxvif; vifi++) { 608 for (vifi = 0; vifi < net->ipv6.maxvif; vifi++) {
584 if (MIF_EXISTS(vifi) && ttls[vifi] && ttls[vifi] < 255) { 609 if (MIF_EXISTS(net, vifi) &&
610 ttls[vifi] && ttls[vifi] < 255) {
585 cache->mfc_un.res.ttls[vifi] = ttls[vifi]; 611 cache->mfc_un.res.ttls[vifi] = ttls[vifi];
586 if (cache->mfc_un.res.minvif > vifi) 612 if (cache->mfc_un.res.minvif > vifi)
587 cache->mfc_un.res.minvif = vifi; 613 cache->mfc_un.res.minvif = vifi;
@@ -591,15 +617,15 @@ static void ip6mr_update_thresholds(struct mfc6_cache *cache, unsigned char *ttl
591 } 617 }
592} 618}
593 619
594static int mif6_add(struct mif6ctl *vifc, int mrtsock) 620static int mif6_add(struct net *net, struct mif6ctl *vifc, int mrtsock)
595{ 621{
596 int vifi = vifc->mif6c_mifi; 622 int vifi = vifc->mif6c_mifi;
597 struct mif_device *v = &vif6_table[vifi]; 623 struct mif_device *v = &net->ipv6.vif6_table[vifi];
598 struct net_device *dev; 624 struct net_device *dev;
599 int err; 625 int err;
600 626
601 /* Is vif busy ? */ 627 /* Is vif busy ? */
602 if (MIF_EXISTS(vifi)) 628 if (MIF_EXISTS(net, vifi))
603 return -EADDRINUSE; 629 return -EADDRINUSE;
604 630
605 switch (vifc->mif6c_flags) { 631 switch (vifc->mif6c_flags) {
@@ -609,9 +635,9 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock)
609 * Special Purpose VIF in PIM 635 * Special Purpose VIF in PIM
610 * All the packets will be sent to the daemon 636 * All the packets will be sent to the daemon
611 */ 637 */
612 if (reg_vif_num >= 0) 638 if (net->ipv6.mroute_reg_vif_num >= 0)
613 return -EADDRINUSE; 639 return -EADDRINUSE;
614 dev = ip6mr_reg_vif(); 640 dev = ip6mr_reg_vif(net);
615 if (!dev) 641 if (!dev)
616 return -ENOBUFS; 642 return -ENOBUFS;
617 err = dev_set_allmulti(dev, 1); 643 err = dev_set_allmulti(dev, 1);
@@ -623,7 +649,7 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock)
623 break; 649 break;
624#endif 650#endif
625 case 0: 651 case 0:
626 dev = dev_get_by_index(&init_net, vifc->mif6c_pifi); 652 dev = dev_get_by_index(net, vifc->mif6c_pifi);
627 if (!dev) 653 if (!dev)
628 return -EADDRNOTAVAIL; 654 return -EADDRNOTAVAIL;
629 err = dev_set_allmulti(dev, 1); 655 err = dev_set_allmulti(dev, 1);
@@ -657,20 +683,22 @@ static int mif6_add(struct mif6ctl *vifc, int mrtsock)
657 v->dev = dev; 683 v->dev = dev;
658#ifdef CONFIG_IPV6_PIMSM_V2 684#ifdef CONFIG_IPV6_PIMSM_V2
659 if (v->flags & MIFF_REGISTER) 685 if (v->flags & MIFF_REGISTER)
660 reg_vif_num = vifi; 686 net->ipv6.mroute_reg_vif_num = vifi;
661#endif 687#endif
662 if (vifi + 1 > maxvif) 688 if (vifi + 1 > net->ipv6.maxvif)
663 maxvif = vifi + 1; 689 net->ipv6.maxvif = vifi + 1;
664 write_unlock_bh(&mrt_lock); 690 write_unlock_bh(&mrt_lock);
665 return 0; 691 return 0;
666} 692}
667 693
668static struct mfc6_cache *ip6mr_cache_find(struct in6_addr *origin, struct in6_addr *mcastgrp) 694static struct mfc6_cache *ip6mr_cache_find(struct net *net,
695 struct in6_addr *origin,
696 struct in6_addr *mcastgrp)
669{ 697{
670 int line = MFC6_HASH(mcastgrp, origin); 698 int line = MFC6_HASH(mcastgrp, origin);
671 struct mfc6_cache *c; 699 struct mfc6_cache *c;
672 700
673 for (c = mfc6_cache_array[line]; c; c = c->next) { 701 for (c = net->ipv6.mfc6_cache_array[line]; c; c = c->next) {
674 if (ipv6_addr_equal(&c->mf6c_origin, origin) && 702 if (ipv6_addr_equal(&c->mf6c_origin, origin) &&
675 ipv6_addr_equal(&c->mf6c_mcastgrp, mcastgrp)) 703 ipv6_addr_equal(&c->mf6c_mcastgrp, mcastgrp))
676 break; 704 break;
@@ -681,24 +709,24 @@ static struct mfc6_cache *ip6mr_cache_find(struct in6_addr *origin, struct in6_a
681/* 709/*
682 * Allocate a multicast cache entry 710 * Allocate a multicast cache entry
683 */ 711 */
684static struct mfc6_cache *ip6mr_cache_alloc(void) 712static struct mfc6_cache *ip6mr_cache_alloc(struct net *net)
685{ 713{
686 struct mfc6_cache *c = kmem_cache_alloc(mrt_cachep, GFP_KERNEL); 714 struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL);
687 if (c == NULL) 715 if (c == NULL)
688 return NULL; 716 return NULL;
689 memset(c, 0, sizeof(*c));
690 c->mfc_un.res.minvif = MAXMIFS; 717 c->mfc_un.res.minvif = MAXMIFS;
718 mfc6_net_set(c, net);
691 return c; 719 return c;
692} 720}
693 721
694static struct mfc6_cache *ip6mr_cache_alloc_unres(void) 722static struct mfc6_cache *ip6mr_cache_alloc_unres(struct net *net)
695{ 723{
696 struct mfc6_cache *c = kmem_cache_alloc(mrt_cachep, GFP_ATOMIC); 724 struct mfc6_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC);
697 if (c == NULL) 725 if (c == NULL)
698 return NULL; 726 return NULL;
699 memset(c, 0, sizeof(*c));
700 skb_queue_head_init(&c->mfc_un.unres.unresolved); 727 skb_queue_head_init(&c->mfc_un.unres.unresolved);
701 c->mfc_un.unres.expires = jiffies + 10 * HZ; 728 c->mfc_un.unres.expires = jiffies + 10 * HZ;
729 mfc6_net_set(c, net);
702 return c; 730 return c;
703} 731}
704 732
@@ -727,7 +755,7 @@ static void ip6mr_cache_resolve(struct mfc6_cache *uc, struct mfc6_cache *c)
727 skb_trim(skb, nlh->nlmsg_len); 755 skb_trim(skb, nlh->nlmsg_len);
728 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -EMSGSIZE; 756 ((struct nlmsgerr *)NLMSG_DATA(nlh))->error = -EMSGSIZE;
729 } 757 }
730 err = rtnl_unicast(skb, &init_net, NETLINK_CB(skb).pid); 758 err = rtnl_unicast(skb, mfc6_net(uc), NETLINK_CB(skb).pid);
731 } else 759 } else
732 ip6_mr_forward(skb, c); 760 ip6_mr_forward(skb, c);
733 } 761 }
@@ -740,7 +768,8 @@ static void ip6mr_cache_resolve(struct mfc6_cache *uc, struct mfc6_cache *c)
740 * Called under mrt_lock. 768 * Called under mrt_lock.
741 */ 769 */
742 770
743static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert) 771static int ip6mr_cache_report(struct net *net, struct sk_buff *pkt, mifi_t mifi,
772 int assert)
744{ 773{
745 struct sk_buff *skb; 774 struct sk_buff *skb;
746 struct mrt6msg *msg; 775 struct mrt6msg *msg;
@@ -776,7 +805,7 @@ static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert)
776 msg = (struct mrt6msg *)skb_transport_header(skb); 805 msg = (struct mrt6msg *)skb_transport_header(skb);
777 msg->im6_mbz = 0; 806 msg->im6_mbz = 0;
778 msg->im6_msgtype = MRT6MSG_WHOLEPKT; 807 msg->im6_msgtype = MRT6MSG_WHOLEPKT;
779 msg->im6_mif = reg_vif_num; 808 msg->im6_mif = net->ipv6.mroute_reg_vif_num;
780 msg->im6_pad = 0; 809 msg->im6_pad = 0;
781 ipv6_addr_copy(&msg->im6_src, &ipv6_hdr(pkt)->saddr); 810 ipv6_addr_copy(&msg->im6_src, &ipv6_hdr(pkt)->saddr);
782 ipv6_addr_copy(&msg->im6_dst, &ipv6_hdr(pkt)->daddr); 811 ipv6_addr_copy(&msg->im6_dst, &ipv6_hdr(pkt)->daddr);
@@ -813,7 +842,7 @@ static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert)
813 skb_pull(skb, sizeof(struct ipv6hdr)); 842 skb_pull(skb, sizeof(struct ipv6hdr));
814 } 843 }
815 844
816 if (mroute6_socket == NULL) { 845 if (net->ipv6.mroute6_sk == NULL) {
817 kfree_skb(skb); 846 kfree_skb(skb);
818 return -EINVAL; 847 return -EINVAL;
819 } 848 }
@@ -821,7 +850,8 @@ static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert)
821 /* 850 /*
822 * Deliver to user space multicast routing algorithms 851 * Deliver to user space multicast routing algorithms
823 */ 852 */
824 if ((ret = sock_queue_rcv_skb(mroute6_socket, skb)) < 0) { 853 ret = sock_queue_rcv_skb(net->ipv6.mroute6_sk, skb);
854 if (ret < 0) {
825 if (net_ratelimit()) 855 if (net_ratelimit())
826 printk(KERN_WARNING "mroute6: pending queue full, dropping entries.\n"); 856 printk(KERN_WARNING "mroute6: pending queue full, dropping entries.\n");
827 kfree_skb(skb); 857 kfree_skb(skb);
@@ -835,14 +865,15 @@ static int ip6mr_cache_report(struct sk_buff *pkt, mifi_t mifi, int assert)
835 */ 865 */
836 866
837static int 867static int
838ip6mr_cache_unresolved(mifi_t mifi, struct sk_buff *skb) 868ip6mr_cache_unresolved(struct net *net, mifi_t mifi, struct sk_buff *skb)
839{ 869{
840 int err; 870 int err;
841 struct mfc6_cache *c; 871 struct mfc6_cache *c;
842 872
843 spin_lock_bh(&mfc_unres_lock); 873 spin_lock_bh(&mfc_unres_lock);
844 for (c = mfc_unres_queue; c; c = c->next) { 874 for (c = mfc_unres_queue; c; c = c->next) {
845 if (ipv6_addr_equal(&c->mf6c_mcastgrp, &ipv6_hdr(skb)->daddr) && 875 if (net_eq(mfc6_net(c), net) &&
876 ipv6_addr_equal(&c->mf6c_mcastgrp, &ipv6_hdr(skb)->daddr) &&
846 ipv6_addr_equal(&c->mf6c_origin, &ipv6_hdr(skb)->saddr)) 877 ipv6_addr_equal(&c->mf6c_origin, &ipv6_hdr(skb)->saddr))
847 break; 878 break;
848 } 879 }
@@ -852,8 +883,8 @@ ip6mr_cache_unresolved(mifi_t mifi, struct sk_buff *skb)
852 * Create a new entry if allowable 883 * Create a new entry if allowable
853 */ 884 */
854 885
855 if (atomic_read(&cache_resolve_queue_len) >= 10 || 886 if (atomic_read(&net->ipv6.cache_resolve_queue_len) >= 10 ||
856 (c = ip6mr_cache_alloc_unres()) == NULL) { 887 (c = ip6mr_cache_alloc_unres(net)) == NULL) {
857 spin_unlock_bh(&mfc_unres_lock); 888 spin_unlock_bh(&mfc_unres_lock);
858 889
859 kfree_skb(skb); 890 kfree_skb(skb);
@@ -870,18 +901,19 @@ ip6mr_cache_unresolved(mifi_t mifi, struct sk_buff *skb)
870 /* 901 /*
871 * Reflect first query at pim6sd 902 * Reflect first query at pim6sd
872 */ 903 */
873 if ((err = ip6mr_cache_report(skb, mifi, MRT6MSG_NOCACHE)) < 0) { 904 err = ip6mr_cache_report(net, skb, mifi, MRT6MSG_NOCACHE);
905 if (err < 0) {
874 /* If the report failed throw the cache entry 906 /* If the report failed throw the cache entry
875 out - Brad Parker 907 out - Brad Parker
876 */ 908 */
877 spin_unlock_bh(&mfc_unres_lock); 909 spin_unlock_bh(&mfc_unres_lock);
878 910
879 kmem_cache_free(mrt_cachep, c); 911 ip6mr_cache_free(c);
880 kfree_skb(skb); 912 kfree_skb(skb);
881 return err; 913 return err;
882 } 914 }
883 915
884 atomic_inc(&cache_resolve_queue_len); 916 atomic_inc(&net->ipv6.cache_resolve_queue_len);
885 c->next = mfc_unres_queue; 917 c->next = mfc_unres_queue;
886 mfc_unres_queue = c; 918 mfc_unres_queue = c;
887 919
@@ -907,21 +939,22 @@ ip6mr_cache_unresolved(mifi_t mifi, struct sk_buff *skb)
907 * MFC6 cache manipulation by user space 939 * MFC6 cache manipulation by user space
908 */ 940 */
909 941
910static int ip6mr_mfc_delete(struct mf6cctl *mfc) 942static int ip6mr_mfc_delete(struct net *net, struct mf6cctl *mfc)
911{ 943{
912 int line; 944 int line;
913 struct mfc6_cache *c, **cp; 945 struct mfc6_cache *c, **cp;
914 946
915 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr); 947 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr);
916 948
917 for (cp = &mfc6_cache_array[line]; (c = *cp) != NULL; cp = &c->next) { 949 for (cp = &net->ipv6.mfc6_cache_array[line];
950 (c = *cp) != NULL; cp = &c->next) {
918 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) && 951 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) &&
919 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) { 952 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) {
920 write_lock_bh(&mrt_lock); 953 write_lock_bh(&mrt_lock);
921 *cp = c->next; 954 *cp = c->next;
922 write_unlock_bh(&mrt_lock); 955 write_unlock_bh(&mrt_lock);
923 956
924 kmem_cache_free(mrt_cachep, c); 957 ip6mr_cache_free(c);
925 return 0; 958 return 0;
926 } 959 }
927 } 960 }
@@ -932,19 +965,17 @@ static int ip6mr_device_event(struct notifier_block *this,
932 unsigned long event, void *ptr) 965 unsigned long event, void *ptr)
933{ 966{
934 struct net_device *dev = ptr; 967 struct net_device *dev = ptr;
968 struct net *net = dev_net(dev);
935 struct mif_device *v; 969 struct mif_device *v;
936 int ct; 970 int ct;
937 971
938 if (!net_eq(dev_net(dev), &init_net))
939 return NOTIFY_DONE;
940
941 if (event != NETDEV_UNREGISTER) 972 if (event != NETDEV_UNREGISTER)
942 return NOTIFY_DONE; 973 return NOTIFY_DONE;
943 974
944 v = &vif6_table[0]; 975 v = &net->ipv6.vif6_table[0];
945 for (ct = 0; ct < maxvif; ct++, v++) { 976 for (ct = 0; ct < net->ipv6.maxvif; ct++, v++) {
946 if (v->dev == dev) 977 if (v->dev == dev)
947 mif6_delete(ct); 978 mif6_delete(net, ct);
948 } 979 }
949 return NOTIFY_DONE; 980 return NOTIFY_DONE;
950} 981}
@@ -957,6 +988,66 @@ static struct notifier_block ip6_mr_notifier = {
957 * Setup for IP multicast routing 988 * Setup for IP multicast routing
958 */ 989 */
959 990
991static int __net_init ip6mr_net_init(struct net *net)
992{
993 int err = 0;
994 net->ipv6.vif6_table = kcalloc(MAXMIFS, sizeof(struct mif_device),
995 GFP_KERNEL);
996 if (!net->ipv6.vif6_table) {
997 err = -ENOMEM;
998 goto fail;
999 }
1000
1001 /* Forwarding cache */
1002 net->ipv6.mfc6_cache_array = kcalloc(MFC6_LINES,
1003 sizeof(struct mfc6_cache *),
1004 GFP_KERNEL);
1005 if (!net->ipv6.mfc6_cache_array) {
1006 err = -ENOMEM;
1007 goto fail_mfc6_cache;
1008 }
1009
1010#ifdef CONFIG_IPV6_PIMSM_V2
1011 net->ipv6.mroute_reg_vif_num = -1;
1012#endif
1013
1014#ifdef CONFIG_PROC_FS
1015 err = -ENOMEM;
1016 if (!proc_net_fops_create(net, "ip6_mr_vif", 0, &ip6mr_vif_fops))
1017 goto proc_vif_fail;
1018 if (!proc_net_fops_create(net, "ip6_mr_cache", 0, &ip6mr_mfc_fops))
1019 goto proc_cache_fail;
1020#endif
1021 return 0;
1022
1023#ifdef CONFIG_PROC_FS
1024proc_cache_fail:
1025 proc_net_remove(net, "ip6_mr_vif");
1026proc_vif_fail:
1027 kfree(net->ipv6.mfc6_cache_array);
1028#endif
1029fail_mfc6_cache:
1030 kfree(net->ipv6.vif6_table);
1031fail:
1032 return err;
1033}
1034
1035static void __net_exit ip6mr_net_exit(struct net *net)
1036{
1037#ifdef CONFIG_PROC_FS
1038 proc_net_remove(net, "ip6_mr_cache");
1039 proc_net_remove(net, "ip6_mr_vif");
1040#endif
1041 mroute_clean_tables(net);
1042 kfree(net->ipv6.mfc6_cache_array);
1043 kfree(net->ipv6.vif6_table);
1044}
1045
1046static struct pernet_operations ip6mr_net_ops = {
1047 .init = ip6mr_net_init,
1048 .exit = ip6mr_net_exit,
1049};
1050
960int __init ip6_mr_init(void) 1051int __init ip6_mr_init(void)
961{ 1052{
962 int err; 1053 int err;
@@ -968,43 +1059,32 @@ int __init ip6_mr_init(void)
968 if (!mrt_cachep) 1059 if (!mrt_cachep)
969 return -ENOMEM; 1060 return -ENOMEM;
970 1061
1062 err = register_pernet_subsys(&ip6mr_net_ops);
1063 if (err)
1064 goto reg_pernet_fail;
1065
971 setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0); 1066 setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
972 err = register_netdevice_notifier(&ip6_mr_notifier); 1067 err = register_netdevice_notifier(&ip6_mr_notifier);
973 if (err) 1068 if (err)
974 goto reg_notif_fail; 1069 goto reg_notif_fail;
975#ifdef CONFIG_PROC_FS
976 err = -ENOMEM;
977 if (!proc_net_fops_create(&init_net, "ip6_mr_vif", 0, &ip6mr_vif_fops))
978 goto proc_vif_fail;
979 if (!proc_net_fops_create(&init_net, "ip6_mr_cache",
980 0, &ip6mr_mfc_fops))
981 goto proc_cache_fail;
982#endif
983 return 0; 1070 return 0;
984#ifdef CONFIG_PROC_FS
985proc_cache_fail:
986 proc_net_remove(&init_net, "ip6_mr_vif");
987proc_vif_fail:
988 unregister_netdevice_notifier(&ip6_mr_notifier);
989#endif
990reg_notif_fail: 1071reg_notif_fail:
991 del_timer(&ipmr_expire_timer); 1072 del_timer(&ipmr_expire_timer);
1073 unregister_pernet_subsys(&ip6mr_net_ops);
1074reg_pernet_fail:
992 kmem_cache_destroy(mrt_cachep); 1075 kmem_cache_destroy(mrt_cachep);
993 return err; 1076 return err;
994} 1077}
995 1078
996void ip6_mr_cleanup(void) 1079void ip6_mr_cleanup(void)
997{ 1080{
998#ifdef CONFIG_PROC_FS
999 proc_net_remove(&init_net, "ip6_mr_cache");
1000 proc_net_remove(&init_net, "ip6_mr_vif");
1001#endif
1002 unregister_netdevice_notifier(&ip6_mr_notifier); 1081 unregister_netdevice_notifier(&ip6_mr_notifier);
1003 del_timer(&ipmr_expire_timer); 1082 del_timer(&ipmr_expire_timer);
1083 unregister_pernet_subsys(&ip6mr_net_ops);
1004 kmem_cache_destroy(mrt_cachep); 1084 kmem_cache_destroy(mrt_cachep);
1005} 1085}
1006 1086
1007static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock) 1087static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
1008{ 1088{
1009 int line; 1089 int line;
1010 struct mfc6_cache *uc, *c, **cp; 1090 struct mfc6_cache *uc, *c, **cp;
@@ -1020,7 +1100,8 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1020 1100
1021 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr); 1101 line = MFC6_HASH(&mfc->mf6cc_mcastgrp.sin6_addr, &mfc->mf6cc_origin.sin6_addr);
1022 1102
1023 for (cp = &mfc6_cache_array[line]; (c = *cp) != NULL; cp = &c->next) { 1103 for (cp = &net->ipv6.mfc6_cache_array[line];
1104 (c = *cp) != NULL; cp = &c->next) {
1024 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) && 1105 if (ipv6_addr_equal(&c->mf6c_origin, &mfc->mf6cc_origin.sin6_addr) &&
1025 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr)) 1106 ipv6_addr_equal(&c->mf6c_mcastgrp, &mfc->mf6cc_mcastgrp.sin6_addr))
1026 break; 1107 break;
@@ -1039,7 +1120,7 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1039 if (!ipv6_addr_is_multicast(&mfc->mf6cc_mcastgrp.sin6_addr)) 1120 if (!ipv6_addr_is_multicast(&mfc->mf6cc_mcastgrp.sin6_addr))
1040 return -EINVAL; 1121 return -EINVAL;
1041 1122
1042 c = ip6mr_cache_alloc(); 1123 c = ip6mr_cache_alloc(net);
1043 if (c == NULL) 1124 if (c == NULL)
1044 return -ENOMEM; 1125 return -ENOMEM;
1045 1126
@@ -1051,8 +1132,8 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1051 c->mfc_flags |= MFC_STATIC; 1132 c->mfc_flags |= MFC_STATIC;
1052 1133
1053 write_lock_bh(&mrt_lock); 1134 write_lock_bh(&mrt_lock);
1054 c->next = mfc6_cache_array[line]; 1135 c->next = net->ipv6.mfc6_cache_array[line];
1055 mfc6_cache_array[line] = c; 1136 net->ipv6.mfc6_cache_array[line] = c;
1056 write_unlock_bh(&mrt_lock); 1137 write_unlock_bh(&mrt_lock);
1057 1138
1058 /* 1139 /*
@@ -1062,19 +1143,21 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1062 spin_lock_bh(&mfc_unres_lock); 1143 spin_lock_bh(&mfc_unres_lock);
1063 for (cp = &mfc_unres_queue; (uc = *cp) != NULL; 1144 for (cp = &mfc_unres_queue; (uc = *cp) != NULL;
1064 cp = &uc->next) { 1145 cp = &uc->next) {
1065 if (ipv6_addr_equal(&uc->mf6c_origin, &c->mf6c_origin) && 1146 if (net_eq(mfc6_net(uc), net) &&
1147 ipv6_addr_equal(&uc->mf6c_origin, &c->mf6c_origin) &&
1066 ipv6_addr_equal(&uc->mf6c_mcastgrp, &c->mf6c_mcastgrp)) { 1148 ipv6_addr_equal(&uc->mf6c_mcastgrp, &c->mf6c_mcastgrp)) {
1067 *cp = uc->next; 1149 *cp = uc->next;
1068 if (atomic_dec_and_test(&cache_resolve_queue_len)) 1150 atomic_dec(&net->ipv6.cache_resolve_queue_len);
1069 del_timer(&ipmr_expire_timer);
1070 break; 1151 break;
1071 } 1152 }
1072 } 1153 }
1154 if (mfc_unres_queue == NULL)
1155 del_timer(&ipmr_expire_timer);
1073 spin_unlock_bh(&mfc_unres_lock); 1156 spin_unlock_bh(&mfc_unres_lock);
1074 1157
1075 if (uc) { 1158 if (uc) {
1076 ip6mr_cache_resolve(uc, c); 1159 ip6mr_cache_resolve(uc, c);
1077 kmem_cache_free(mrt_cachep, uc); 1160 ip6mr_cache_free(uc);
1078 } 1161 }
1079 return 0; 1162 return 0;
1080} 1163}
@@ -1083,25 +1166,25 @@ static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
1083 * Close the multicast socket, and clear the vif tables etc 1166 * Close the multicast socket, and clear the vif tables etc
1084 */ 1167 */
1085 1168
1086static void mroute_clean_tables(struct sock *sk) 1169static void mroute_clean_tables(struct net *net)
1087{ 1170{
1088 int i; 1171 int i;
1089 1172
1090 /* 1173 /*
1091 * Shut down all active vif entries 1174 * Shut down all active vif entries
1092 */ 1175 */
1093 for (i = 0; i < maxvif; i++) { 1176 for (i = 0; i < net->ipv6.maxvif; i++) {
1094 if (!(vif6_table[i].flags & VIFF_STATIC)) 1177 if (!(net->ipv6.vif6_table[i].flags & VIFF_STATIC))
1095 mif6_delete(i); 1178 mif6_delete(net, i);
1096 } 1179 }
1097 1180
1098 /* 1181 /*
1099 * Wipe the cache 1182 * Wipe the cache
1100 */ 1183 */
1101 for (i = 0; i < ARRAY_SIZE(mfc6_cache_array); i++) { 1184 for (i = 0; i < MFC6_LINES; i++) {
1102 struct mfc6_cache *c, **cp; 1185 struct mfc6_cache *c, **cp;
1103 1186
1104 cp = &mfc6_cache_array[i]; 1187 cp = &net->ipv6.mfc6_cache_array[i];
1105 while ((c = *cp) != NULL) { 1188 while ((c = *cp) != NULL) {
1106 if (c->mfc_flags & MFC_STATIC) { 1189 if (c->mfc_flags & MFC_STATIC) {
1107 cp = &c->next; 1190 cp = &c->next;
@@ -1111,22 +1194,22 @@ static void mroute_clean_tables(struct sock *sk)
1111 *cp = c->next; 1194 *cp = c->next;
1112 write_unlock_bh(&mrt_lock); 1195 write_unlock_bh(&mrt_lock);
1113 1196
1114 kmem_cache_free(mrt_cachep, c); 1197 ip6mr_cache_free(c);
1115 } 1198 }
1116 } 1199 }
1117 1200
1118 if (atomic_read(&cache_resolve_queue_len) != 0) { 1201 if (atomic_read(&net->ipv6.cache_resolve_queue_len) != 0) {
1119 struct mfc6_cache *c; 1202 struct mfc6_cache *c, **cp;
1120 1203
1121 spin_lock_bh(&mfc_unres_lock); 1204 spin_lock_bh(&mfc_unres_lock);
1122 while (mfc_unres_queue != NULL) { 1205 cp = &mfc_unres_queue;
1123 c = mfc_unres_queue; 1206 while ((c = *cp) != NULL) {
1124 mfc_unres_queue = c->next; 1207 if (!net_eq(mfc6_net(c), net)) {
1125 spin_unlock_bh(&mfc_unres_lock); 1208 cp = &c->next;
1126 1209 continue;
1210 }
1211 *cp = c->next;
1127 ip6mr_destroy_unres(c); 1212 ip6mr_destroy_unres(c);
1128
1129 spin_lock_bh(&mfc_unres_lock);
1130 } 1213 }
1131 spin_unlock_bh(&mfc_unres_lock); 1214 spin_unlock_bh(&mfc_unres_lock);
1132 } 1215 }
@@ -1135,11 +1218,12 @@ static void mroute_clean_tables(struct sock *sk)
1135static int ip6mr_sk_init(struct sock *sk) 1218static int ip6mr_sk_init(struct sock *sk)
1136{ 1219{
1137 int err = 0; 1220 int err = 0;
1221 struct net *net = sock_net(sk);
1138 1222
1139 rtnl_lock(); 1223 rtnl_lock();
1140 write_lock_bh(&mrt_lock); 1224 write_lock_bh(&mrt_lock);
1141 if (likely(mroute6_socket == NULL)) 1225 if (likely(net->ipv6.mroute6_sk == NULL))
1142 mroute6_socket = sk; 1226 net->ipv6.mroute6_sk = sk;
1143 else 1227 else
1144 err = -EADDRINUSE; 1228 err = -EADDRINUSE;
1145 write_unlock_bh(&mrt_lock); 1229 write_unlock_bh(&mrt_lock);
@@ -1152,14 +1236,15 @@ static int ip6mr_sk_init(struct sock *sk)
1152int ip6mr_sk_done(struct sock *sk) 1236int ip6mr_sk_done(struct sock *sk)
1153{ 1237{
1154 int err = 0; 1238 int err = 0;
1239 struct net *net = sock_net(sk);
1155 1240
1156 rtnl_lock(); 1241 rtnl_lock();
1157 if (sk == mroute6_socket) { 1242 if (sk == net->ipv6.mroute6_sk) {
1158 write_lock_bh(&mrt_lock); 1243 write_lock_bh(&mrt_lock);
1159 mroute6_socket = NULL; 1244 net->ipv6.mroute6_sk = NULL;
1160 write_unlock_bh(&mrt_lock); 1245 write_unlock_bh(&mrt_lock);
1161 1246
1162 mroute_clean_tables(sk); 1247 mroute_clean_tables(net);
1163 } else 1248 } else
1164 err = -EACCES; 1249 err = -EACCES;
1165 rtnl_unlock(); 1250 rtnl_unlock();
@@ -1180,9 +1265,10 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1180 struct mif6ctl vif; 1265 struct mif6ctl vif;
1181 struct mf6cctl mfc; 1266 struct mf6cctl mfc;
1182 mifi_t mifi; 1267 mifi_t mifi;
1268 struct net *net = sock_net(sk);
1183 1269
1184 if (optname != MRT6_INIT) { 1270 if (optname != MRT6_INIT) {
1185 if (sk != mroute6_socket && !capable(CAP_NET_ADMIN)) 1271 if (sk != net->ipv6.mroute6_sk && !capable(CAP_NET_ADMIN))
1186 return -EACCES; 1272 return -EACCES;
1187 } 1273 }
1188 1274
@@ -1207,7 +1293,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1207 if (vif.mif6c_mifi >= MAXMIFS) 1293 if (vif.mif6c_mifi >= MAXMIFS)
1208 return -ENFILE; 1294 return -ENFILE;
1209 rtnl_lock(); 1295 rtnl_lock();
1210 ret = mif6_add(&vif, sk == mroute6_socket); 1296 ret = mif6_add(net, &vif, sk == net->ipv6.mroute6_sk);
1211 rtnl_unlock(); 1297 rtnl_unlock();
1212 return ret; 1298 return ret;
1213 1299
@@ -1217,7 +1303,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1217 if (copy_from_user(&mifi, optval, sizeof(mifi_t))) 1303 if (copy_from_user(&mifi, optval, sizeof(mifi_t)))
1218 return -EFAULT; 1304 return -EFAULT;
1219 rtnl_lock(); 1305 rtnl_lock();
1220 ret = mif6_delete(mifi); 1306 ret = mif6_delete(net, mifi);
1221 rtnl_unlock(); 1307 rtnl_unlock();
1222 return ret; 1308 return ret;
1223 1309
@@ -1233,9 +1319,10 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1233 return -EFAULT; 1319 return -EFAULT;
1234 rtnl_lock(); 1320 rtnl_lock();
1235 if (optname == MRT6_DEL_MFC) 1321 if (optname == MRT6_DEL_MFC)
1236 ret = ip6mr_mfc_delete(&mfc); 1322 ret = ip6mr_mfc_delete(net, &mfc);
1237 else 1323 else
1238 ret = ip6mr_mfc_add(&mfc, sk == mroute6_socket); 1324 ret = ip6mr_mfc_add(net, &mfc,
1325 sk == net->ipv6.mroute6_sk);
1239 rtnl_unlock(); 1326 rtnl_unlock();
1240 return ret; 1327 return ret;
1241 1328
@@ -1247,7 +1334,7 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1247 int v; 1334 int v;
1248 if (get_user(v, (int __user *)optval)) 1335 if (get_user(v, (int __user *)optval))
1249 return -EFAULT; 1336 return -EFAULT;
1250 mroute_do_assert = !!v; 1337 net->ipv6.mroute_do_assert = !!v;
1251 return 0; 1338 return 0;
1252 } 1339 }
1253 1340
@@ -1260,10 +1347,10 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
1260 v = !!v; 1347 v = !!v;
1261 rtnl_lock(); 1348 rtnl_lock();
1262 ret = 0; 1349 ret = 0;
1263 if (v != mroute_do_pim) { 1350 if (v != net->ipv6.mroute_do_pim) {
1264 mroute_do_pim = v; 1351 net->ipv6.mroute_do_pim = v;
1265 mroute_do_assert = v; 1352 net->ipv6.mroute_do_assert = v;
1266 if (mroute_do_pim) 1353 if (net->ipv6.mroute_do_pim)
1267 ret = inet6_add_protocol(&pim6_protocol, 1354 ret = inet6_add_protocol(&pim6_protocol,
1268 IPPROTO_PIM); 1355 IPPROTO_PIM);
1269 else 1356 else
@@ -1295,6 +1382,7 @@ int ip6_mroute_getsockopt(struct sock *sk, int optname, char __user *optval,
1295{ 1382{
1296 int olr; 1383 int olr;
1297 int val; 1384 int val;
1385 struct net *net = sock_net(sk);
1298 1386
1299 switch (optname) { 1387 switch (optname) {
1300 case MRT6_VERSION: 1388 case MRT6_VERSION:
@@ -1302,11 +1390,11 @@ int ip6_mroute_getsockopt(struct sock *sk, int optname, char __user *optval,
1302 break; 1390 break;
1303#ifdef CONFIG_IPV6_PIMSM_V2 1391#ifdef CONFIG_IPV6_PIMSM_V2
1304 case MRT6_PIM: 1392 case MRT6_PIM:
1305 val = mroute_do_pim; 1393 val = net->ipv6.mroute_do_pim;
1306 break; 1394 break;
1307#endif 1395#endif
1308 case MRT6_ASSERT: 1396 case MRT6_ASSERT:
1309 val = mroute_do_assert; 1397 val = net->ipv6.mroute_do_assert;
1310 break; 1398 break;
1311 default: 1399 default:
1312 return -ENOPROTOOPT; 1400 return -ENOPROTOOPT;
@@ -1336,16 +1424,17 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
1336 struct sioc_mif_req6 vr; 1424 struct sioc_mif_req6 vr;
1337 struct mif_device *vif; 1425 struct mif_device *vif;
1338 struct mfc6_cache *c; 1426 struct mfc6_cache *c;
1427 struct net *net = sock_net(sk);
1339 1428
1340 switch (cmd) { 1429 switch (cmd) {
1341 case SIOCGETMIFCNT_IN6: 1430 case SIOCGETMIFCNT_IN6:
1342 if (copy_from_user(&vr, arg, sizeof(vr))) 1431 if (copy_from_user(&vr, arg, sizeof(vr)))
1343 return -EFAULT; 1432 return -EFAULT;
1344 if (vr.mifi >= maxvif) 1433 if (vr.mifi >= net->ipv6.maxvif)
1345 return -EINVAL; 1434 return -EINVAL;
1346 read_lock(&mrt_lock); 1435 read_lock(&mrt_lock);
1347 vif = &vif6_table[vr.mifi]; 1436 vif = &net->ipv6.vif6_table[vr.mifi];
1348 if (MIF_EXISTS(vr.mifi)) { 1437 if (MIF_EXISTS(net, vr.mifi)) {
1349 vr.icount = vif->pkt_in; 1438 vr.icount = vif->pkt_in;
1350 vr.ocount = vif->pkt_out; 1439 vr.ocount = vif->pkt_out;
1351 vr.ibytes = vif->bytes_in; 1440 vr.ibytes = vif->bytes_in;
@@ -1363,7 +1452,7 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg)
1363 return -EFAULT; 1452 return -EFAULT;
1364 1453
1365 read_lock(&mrt_lock); 1454 read_lock(&mrt_lock);
1366 c = ip6mr_cache_find(&sr.src.sin6_addr, &sr.grp.sin6_addr); 1455 c = ip6mr_cache_find(net, &sr.src.sin6_addr, &sr.grp.sin6_addr);
1367 if (c) { 1456 if (c) {
1368 sr.pktcnt = c->mfc_un.res.pkt; 1457 sr.pktcnt = c->mfc_un.res.pkt;
1369 sr.bytecnt = c->mfc_un.res.bytes; 1458 sr.bytecnt = c->mfc_un.res.bytes;
@@ -1396,7 +1485,8 @@ static inline int ip6mr_forward2_finish(struct sk_buff *skb)
1396static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi) 1485static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1397{ 1486{
1398 struct ipv6hdr *ipv6h; 1487 struct ipv6hdr *ipv6h;
1399 struct mif_device *vif = &vif6_table[vifi]; 1488 struct net *net = mfc6_net(c);
1489 struct mif_device *vif = &net->ipv6.vif6_table[vifi];
1400 struct net_device *dev; 1490 struct net_device *dev;
1401 struct dst_entry *dst; 1491 struct dst_entry *dst;
1402 struct flowi fl; 1492 struct flowi fl;
@@ -1410,9 +1500,8 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1410 vif->bytes_out += skb->len; 1500 vif->bytes_out += skb->len;
1411 vif->dev->stats.tx_bytes += skb->len; 1501 vif->dev->stats.tx_bytes += skb->len;
1412 vif->dev->stats.tx_packets++; 1502 vif->dev->stats.tx_packets++;
1413 ip6mr_cache_report(skb, vifi, MRT6MSG_WHOLEPKT); 1503 ip6mr_cache_report(net, skb, vifi, MRT6MSG_WHOLEPKT);
1414 kfree_skb(skb); 1504 goto out_free;
1415 return 0;
1416 } 1505 }
1417#endif 1506#endif
1418 1507
@@ -1425,7 +1514,7 @@ static int ip6mr_forward2(struct sk_buff *skb, struct mfc6_cache *c, int vifi)
1425 } 1514 }
1426 }; 1515 };
1427 1516
1428 dst = ip6_route_output(&init_net, NULL, &fl); 1517 dst = ip6_route_output(net, NULL, &fl);
1429 if (!dst) 1518 if (!dst)
1430 goto out_free; 1519 goto out_free;
1431 1520
@@ -1468,9 +1557,10 @@ out_free:
1468 1557
1469static int ip6mr_find_vif(struct net_device *dev) 1558static int ip6mr_find_vif(struct net_device *dev)
1470{ 1559{
1560 struct net *net = dev_net(dev);
1471 int ct; 1561 int ct;
1472 for (ct = maxvif - 1; ct >= 0; ct--) { 1562 for (ct = net->ipv6.maxvif - 1; ct >= 0; ct--) {
1473 if (vif6_table[ct].dev == dev) 1563 if (net->ipv6.vif6_table[ct].dev == dev)
1474 break; 1564 break;
1475 } 1565 }
1476 return ct; 1566 return ct;
@@ -1480,6 +1570,7 @@ static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache)
1480{ 1570{
1481 int psend = -1; 1571 int psend = -1;
1482 int vif, ct; 1572 int vif, ct;
1573 struct net *net = mfc6_net(cache);
1483 1574
1484 vif = cache->mf6c_parent; 1575 vif = cache->mf6c_parent;
1485 cache->mfc_un.res.pkt++; 1576 cache->mfc_un.res.pkt++;
@@ -1488,29 +1579,30 @@ static int ip6_mr_forward(struct sk_buff *skb, struct mfc6_cache *cache)
1488 /* 1579 /*
1489 * Wrong interface: drop packet and (maybe) send PIM assert. 1580 * Wrong interface: drop packet and (maybe) send PIM assert.
1490 */ 1581 */
1491 if (vif6_table[vif].dev != skb->dev) { 1582 if (net->ipv6.vif6_table[vif].dev != skb->dev) {
1492 int true_vifi; 1583 int true_vifi;
1493 1584
1494 cache->mfc_un.res.wrong_if++; 1585 cache->mfc_un.res.wrong_if++;
1495 true_vifi = ip6mr_find_vif(skb->dev); 1586 true_vifi = ip6mr_find_vif(skb->dev);
1496 1587
1497 if (true_vifi >= 0 && mroute_do_assert && 1588 if (true_vifi >= 0 && net->ipv6.mroute_do_assert &&
1498 /* pimsm uses asserts, when switching from RPT to SPT, 1589 /* pimsm uses asserts, when switching from RPT to SPT,
1499 so that we cannot check that packet arrived on an oif. 1590 so that we cannot check that packet arrived on an oif.
1500 It is bad, but otherwise we would need to move pretty 1591 It is bad, but otherwise we would need to move pretty
1501 large chunk of pimd to kernel. Ough... --ANK 1592 large chunk of pimd to kernel. Ough... --ANK
1502 */ 1593 */
1503 (mroute_do_pim || cache->mfc_un.res.ttls[true_vifi] < 255) && 1594 (net->ipv6.mroute_do_pim ||
1595 cache->mfc_un.res.ttls[true_vifi] < 255) &&
1504 time_after(jiffies, 1596 time_after(jiffies,
1505 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { 1597 cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) {
1506 cache->mfc_un.res.last_assert = jiffies; 1598 cache->mfc_un.res.last_assert = jiffies;
1507 ip6mr_cache_report(skb, true_vifi, MRT6MSG_WRONGMIF); 1599 ip6mr_cache_report(net, skb, true_vifi, MRT6MSG_WRONGMIF);
1508 } 1600 }
1509 goto dont_forward; 1601 goto dont_forward;
1510 } 1602 }
1511 1603
1512 vif6_table[vif].pkt_in++; 1604 net->ipv6.vif6_table[vif].pkt_in++;
1513 vif6_table[vif].bytes_in += skb->len; 1605 net->ipv6.vif6_table[vif].bytes_in += skb->len;
1514 1606
1515 /* 1607 /*
1516 * Forward the frame 1608 * Forward the frame
@@ -1543,9 +1635,11 @@ dont_forward:
1543int ip6_mr_input(struct sk_buff *skb) 1635int ip6_mr_input(struct sk_buff *skb)
1544{ 1636{
1545 struct mfc6_cache *cache; 1637 struct mfc6_cache *cache;
1638 struct net *net = dev_net(skb->dev);
1546 1639
1547 read_lock(&mrt_lock); 1640 read_lock(&mrt_lock);
1548 cache = ip6mr_cache_find(&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr); 1641 cache = ip6mr_cache_find(net,
1642 &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr);
1549 1643
1550 /* 1644 /*
1551 * No usable cache entry 1645 * No usable cache entry
@@ -1555,7 +1649,7 @@ int ip6_mr_input(struct sk_buff *skb)
1555 1649
1556 vif = ip6mr_find_vif(skb->dev); 1650 vif = ip6mr_find_vif(skb->dev);
1557 if (vif >= 0) { 1651 if (vif >= 0) {
1558 int err = ip6mr_cache_unresolved(vif, skb); 1652 int err = ip6mr_cache_unresolved(net, vif, skb);
1559 read_unlock(&mrt_lock); 1653 read_unlock(&mrt_lock);
1560 1654
1561 return err; 1655 return err;
@@ -1578,7 +1672,8 @@ ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm)
1578{ 1672{
1579 int ct; 1673 int ct;
1580 struct rtnexthop *nhp; 1674 struct rtnexthop *nhp;
1581 struct net_device *dev = vif6_table[c->mf6c_parent].dev; 1675 struct net *net = mfc6_net(c);
1676 struct net_device *dev = net->ipv6.vif6_table[c->mf6c_parent].dev;
1582 u8 *b = skb_tail_pointer(skb); 1677 u8 *b = skb_tail_pointer(skb);
1583 struct rtattr *mp_head; 1678 struct rtattr *mp_head;
1584 1679
@@ -1594,7 +1689,7 @@ ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm)
1594 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp))); 1689 nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
1595 nhp->rtnh_flags = 0; 1690 nhp->rtnh_flags = 0;
1596 nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; 1691 nhp->rtnh_hops = c->mfc_un.res.ttls[ct];
1597 nhp->rtnh_ifindex = vif6_table[ct].dev->ifindex; 1692 nhp->rtnh_ifindex = net->ipv6.vif6_table[ct].dev->ifindex;
1598 nhp->rtnh_len = sizeof(*nhp); 1693 nhp->rtnh_len = sizeof(*nhp);
1599 } 1694 }
1600 } 1695 }
@@ -1608,14 +1703,15 @@ rtattr_failure:
1608 return -EMSGSIZE; 1703 return -EMSGSIZE;
1609} 1704}
1610 1705
1611int ip6mr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait) 1706int ip6mr_get_route(struct net *net,
1707 struct sk_buff *skb, struct rtmsg *rtm, int nowait)
1612{ 1708{
1613 int err; 1709 int err;
1614 struct mfc6_cache *cache; 1710 struct mfc6_cache *cache;
1615 struct rt6_info *rt = (struct rt6_info *)skb->dst; 1711 struct rt6_info *rt = (struct rt6_info *)skb->dst;
1616 1712
1617 read_lock(&mrt_lock); 1713 read_lock(&mrt_lock);
1618 cache = ip6mr_cache_find(&rt->rt6i_src.addr, &rt->rt6i_dst.addr); 1714 cache = ip6mr_cache_find(net, &rt->rt6i_src.addr, &rt->rt6i_dst.addr);
1619 1715
1620 if (!cache) { 1716 if (!cache) {
1621 struct sk_buff *skb2; 1717 struct sk_buff *skb2;
@@ -1658,7 +1754,7 @@ int ip6mr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait)
1658 ipv6_addr_copy(&iph->saddr, &rt->rt6i_src.addr); 1754 ipv6_addr_copy(&iph->saddr, &rt->rt6i_src.addr);
1659 ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr); 1755 ipv6_addr_copy(&iph->daddr, &rt->rt6i_dst.addr);
1660 1756
1661 err = ip6mr_cache_unresolved(vif, skb2); 1757 err = ip6mr_cache_unresolved(net, vif, skb2);
1662 read_unlock(&mrt_lock); 1758 read_unlock(&mrt_lock);
1663 1759
1664 return err; 1760 return err;