diff options
Diffstat (limited to 'net/ipv6/route.c')
-rw-r--r-- | net/ipv6/route.c | 640 |
1 files changed, 421 insertions, 219 deletions
diff --git a/net/ipv6/route.c b/net/ipv6/route.c index e8b241cb60bc..210a079cfc6f 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c | |||
@@ -36,10 +36,12 @@ | |||
36 | #include <linux/route.h> | 36 | #include <linux/route.h> |
37 | #include <linux/netdevice.h> | 37 | #include <linux/netdevice.h> |
38 | #include <linux/in6.h> | 38 | #include <linux/in6.h> |
39 | #include <linux/mroute6.h> | ||
39 | #include <linux/init.h> | 40 | #include <linux/init.h> |
40 | #include <linux/if_arp.h> | 41 | #include <linux/if_arp.h> |
41 | #include <linux/proc_fs.h> | 42 | #include <linux/proc_fs.h> |
42 | #include <linux/seq_file.h> | 43 | #include <linux/seq_file.h> |
44 | #include <linux/nsproxy.h> | ||
43 | #include <net/net_namespace.h> | 45 | #include <net/net_namespace.h> |
44 | #include <net/snmp.h> | 46 | #include <net/snmp.h> |
45 | #include <net/ipv6.h> | 47 | #include <net/ipv6.h> |
@@ -87,14 +89,16 @@ static void ip6_link_failure(struct sk_buff *skb); | |||
87 | static void ip6_rt_update_pmtu(struct dst_entry *dst, u32 mtu); | 89 | static void ip6_rt_update_pmtu(struct dst_entry *dst, u32 mtu); |
88 | 90 | ||
89 | #ifdef CONFIG_IPV6_ROUTE_INFO | 91 | #ifdef CONFIG_IPV6_ROUTE_INFO |
90 | static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixlen, | 92 | static struct rt6_info *rt6_add_route_info(struct net *net, |
93 | struct in6_addr *prefix, int prefixlen, | ||
91 | struct in6_addr *gwaddr, int ifindex, | 94 | struct in6_addr *gwaddr, int ifindex, |
92 | unsigned pref); | 95 | unsigned pref); |
93 | static struct rt6_info *rt6_get_route_info(struct in6_addr *prefix, int prefixlen, | 96 | static struct rt6_info *rt6_get_route_info(struct net *net, |
97 | struct in6_addr *prefix, int prefixlen, | ||
94 | struct in6_addr *gwaddr, int ifindex); | 98 | struct in6_addr *gwaddr, int ifindex); |
95 | #endif | 99 | #endif |
96 | 100 | ||
97 | static struct dst_ops ip6_dst_ops = { | 101 | static struct dst_ops ip6_dst_ops_template = { |
98 | .family = AF_INET6, | 102 | .family = AF_INET6, |
99 | .protocol = __constant_htons(ETH_P_IPV6), | 103 | .protocol = __constant_htons(ETH_P_IPV6), |
100 | .gc = ip6_dst_gc, | 104 | .gc = ip6_dst_gc, |
@@ -124,7 +128,7 @@ static struct dst_ops ip6_dst_blackhole_ops = { | |||
124 | .entries = ATOMIC_INIT(0), | 128 | .entries = ATOMIC_INIT(0), |
125 | }; | 129 | }; |
126 | 130 | ||
127 | struct rt6_info ip6_null_entry = { | 131 | static struct rt6_info ip6_null_entry_template = { |
128 | .u = { | 132 | .u = { |
129 | .dst = { | 133 | .dst = { |
130 | .__refcnt = ATOMIC_INIT(1), | 134 | .__refcnt = ATOMIC_INIT(1), |
@@ -134,8 +138,6 @@ struct rt6_info ip6_null_entry = { | |||
134 | .metrics = { [RTAX_HOPLIMIT - 1] = 255, }, | 138 | .metrics = { [RTAX_HOPLIMIT - 1] = 255, }, |
135 | .input = ip6_pkt_discard, | 139 | .input = ip6_pkt_discard, |
136 | .output = ip6_pkt_discard_out, | 140 | .output = ip6_pkt_discard_out, |
137 | .ops = &ip6_dst_ops, | ||
138 | .path = (struct dst_entry*)&ip6_null_entry, | ||
139 | } | 141 | } |
140 | }, | 142 | }, |
141 | .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP), | 143 | .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP), |
@@ -148,7 +150,7 @@ struct rt6_info ip6_null_entry = { | |||
148 | static int ip6_pkt_prohibit(struct sk_buff *skb); | 150 | static int ip6_pkt_prohibit(struct sk_buff *skb); |
149 | static int ip6_pkt_prohibit_out(struct sk_buff *skb); | 151 | static int ip6_pkt_prohibit_out(struct sk_buff *skb); |
150 | 152 | ||
151 | struct rt6_info ip6_prohibit_entry = { | 153 | struct rt6_info ip6_prohibit_entry_template = { |
152 | .u = { | 154 | .u = { |
153 | .dst = { | 155 | .dst = { |
154 | .__refcnt = ATOMIC_INIT(1), | 156 | .__refcnt = ATOMIC_INIT(1), |
@@ -158,8 +160,6 @@ struct rt6_info ip6_prohibit_entry = { | |||
158 | .metrics = { [RTAX_HOPLIMIT - 1] = 255, }, | 160 | .metrics = { [RTAX_HOPLIMIT - 1] = 255, }, |
159 | .input = ip6_pkt_prohibit, | 161 | .input = ip6_pkt_prohibit, |
160 | .output = ip6_pkt_prohibit_out, | 162 | .output = ip6_pkt_prohibit_out, |
161 | .ops = &ip6_dst_ops, | ||
162 | .path = (struct dst_entry*)&ip6_prohibit_entry, | ||
163 | } | 163 | } |
164 | }, | 164 | }, |
165 | .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP), | 165 | .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP), |
@@ -167,7 +167,7 @@ struct rt6_info ip6_prohibit_entry = { | |||
167 | .rt6i_ref = ATOMIC_INIT(1), | 167 | .rt6i_ref = ATOMIC_INIT(1), |
168 | }; | 168 | }; |
169 | 169 | ||
170 | struct rt6_info ip6_blk_hole_entry = { | 170 | static struct rt6_info ip6_blk_hole_entry_template = { |
171 | .u = { | 171 | .u = { |
172 | .dst = { | 172 | .dst = { |
173 | .__refcnt = ATOMIC_INIT(1), | 173 | .__refcnt = ATOMIC_INIT(1), |
@@ -177,8 +177,6 @@ struct rt6_info ip6_blk_hole_entry = { | |||
177 | .metrics = { [RTAX_HOPLIMIT - 1] = 255, }, | 177 | .metrics = { [RTAX_HOPLIMIT - 1] = 255, }, |
178 | .input = dst_discard, | 178 | .input = dst_discard, |
179 | .output = dst_discard, | 179 | .output = dst_discard, |
180 | .ops = &ip6_dst_ops, | ||
181 | .path = (struct dst_entry*)&ip6_blk_hole_entry, | ||
182 | } | 180 | } |
183 | }, | 181 | }, |
184 | .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP), | 182 | .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP), |
@@ -189,9 +187,9 @@ struct rt6_info ip6_blk_hole_entry = { | |||
189 | #endif | 187 | #endif |
190 | 188 | ||
191 | /* allocate dst with ip6_dst_ops */ | 189 | /* allocate dst with ip6_dst_ops */ |
192 | static __inline__ struct rt6_info *ip6_dst_alloc(void) | 190 | static inline struct rt6_info *ip6_dst_alloc(struct dst_ops *ops) |
193 | { | 191 | { |
194 | return (struct rt6_info *)dst_alloc(&ip6_dst_ops); | 192 | return (struct rt6_info *)dst_alloc(ops); |
195 | } | 193 | } |
196 | 194 | ||
197 | static void ip6_dst_destroy(struct dst_entry *dst) | 195 | static void ip6_dst_destroy(struct dst_entry *dst) |
@@ -211,7 +209,7 @@ static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev, | |||
211 | struct rt6_info *rt = (struct rt6_info *)dst; | 209 | struct rt6_info *rt = (struct rt6_info *)dst; |
212 | struct inet6_dev *idev = rt->rt6i_idev; | 210 | struct inet6_dev *idev = rt->rt6i_idev; |
213 | struct net_device *loopback_dev = | 211 | struct net_device *loopback_dev = |
214 | dev->nd_net->loopback_dev; | 212 | dev_net(dev)->loopback_dev; |
215 | 213 | ||
216 | if (dev != loopback_dev && idev != NULL && idev->dev == dev) { | 214 | if (dev != loopback_dev && idev != NULL && idev->dev == dev) { |
217 | struct inet6_dev *loopback_idev = | 215 | struct inet6_dev *loopback_idev = |
@@ -239,7 +237,8 @@ static inline int rt6_need_strict(struct in6_addr *daddr) | |||
239 | * Route lookup. Any table->tb6_lock is implied. | 237 | * Route lookup. Any table->tb6_lock is implied. |
240 | */ | 238 | */ |
241 | 239 | ||
242 | static __inline__ struct rt6_info *rt6_device_match(struct rt6_info *rt, | 240 | static inline struct rt6_info *rt6_device_match(struct net *net, |
241 | struct rt6_info *rt, | ||
243 | int oif, | 242 | int oif, |
244 | int strict) | 243 | int strict) |
245 | { | 244 | { |
@@ -268,7 +267,7 @@ static __inline__ struct rt6_info *rt6_device_match(struct rt6_info *rt, | |||
268 | return local; | 267 | return local; |
269 | 268 | ||
270 | if (strict) | 269 | if (strict) |
271 | return &ip6_null_entry; | 270 | return net->ipv6.ip6_null_entry; |
272 | } | 271 | } |
273 | return rt; | 272 | return rt; |
274 | } | 273 | } |
@@ -409,9 +408,10 @@ static struct rt6_info *find_rr_leaf(struct fib6_node *fn, | |||
409 | static struct rt6_info *rt6_select(struct fib6_node *fn, int oif, int strict) | 408 | static struct rt6_info *rt6_select(struct fib6_node *fn, int oif, int strict) |
410 | { | 409 | { |
411 | struct rt6_info *match, *rt0; | 410 | struct rt6_info *match, *rt0; |
411 | struct net *net; | ||
412 | 412 | ||
413 | RT6_TRACE("%s(fn->leaf=%p, oif=%d)\n", | 413 | RT6_TRACE("%s(fn->leaf=%p, oif=%d)\n", |
414 | __FUNCTION__, fn->leaf, oif); | 414 | __func__, fn->leaf, oif); |
415 | 415 | ||
416 | rt0 = fn->rr_ptr; | 416 | rt0 = fn->rr_ptr; |
417 | if (!rt0) | 417 | if (!rt0) |
@@ -432,15 +432,17 @@ static struct rt6_info *rt6_select(struct fib6_node *fn, int oif, int strict) | |||
432 | } | 432 | } |
433 | 433 | ||
434 | RT6_TRACE("%s() => %p\n", | 434 | RT6_TRACE("%s() => %p\n", |
435 | __FUNCTION__, match); | 435 | __func__, match); |
436 | 436 | ||
437 | return (match ? match : &ip6_null_entry); | 437 | net = dev_net(rt0->rt6i_dev); |
438 | return (match ? match : net->ipv6.ip6_null_entry); | ||
438 | } | 439 | } |
439 | 440 | ||
440 | #ifdef CONFIG_IPV6_ROUTE_INFO | 441 | #ifdef CONFIG_IPV6_ROUTE_INFO |
441 | int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, | 442 | int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, |
442 | struct in6_addr *gwaddr) | 443 | struct in6_addr *gwaddr) |
443 | { | 444 | { |
445 | struct net *net = dev_net(dev); | ||
444 | struct route_info *rinfo = (struct route_info *) opt; | 446 | struct route_info *rinfo = (struct route_info *) opt; |
445 | struct in6_addr prefix_buf, *prefix; | 447 | struct in6_addr prefix_buf, *prefix; |
446 | unsigned int pref; | 448 | unsigned int pref; |
@@ -488,7 +490,8 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, | |||
488 | prefix = &prefix_buf; | 490 | prefix = &prefix_buf; |
489 | } | 491 | } |
490 | 492 | ||
491 | rt = rt6_get_route_info(prefix, rinfo->prefix_len, gwaddr, dev->ifindex); | 493 | rt = rt6_get_route_info(net, prefix, rinfo->prefix_len, gwaddr, |
494 | dev->ifindex); | ||
492 | 495 | ||
493 | if (rt && !lifetime) { | 496 | if (rt && !lifetime) { |
494 | ip6_del_rt(rt); | 497 | ip6_del_rt(rt); |
@@ -496,7 +499,7 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, | |||
496 | } | 499 | } |
497 | 500 | ||
498 | if (!rt && lifetime) | 501 | if (!rt && lifetime) |
499 | rt = rt6_add_route_info(prefix, rinfo->prefix_len, gwaddr, dev->ifindex, | 502 | rt = rt6_add_route_info(net, prefix, rinfo->prefix_len, gwaddr, dev->ifindex, |
500 | pref); | 503 | pref); |
501 | else if (rt) | 504 | else if (rt) |
502 | rt->rt6i_flags = RTF_ROUTEINFO | | 505 | rt->rt6i_flags = RTF_ROUTEINFO | |
@@ -515,9 +518,9 @@ int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, | |||
515 | } | 518 | } |
516 | #endif | 519 | #endif |
517 | 520 | ||
518 | #define BACKTRACK(saddr) \ | 521 | #define BACKTRACK(__net, saddr) \ |
519 | do { \ | 522 | do { \ |
520 | if (rt == &ip6_null_entry) { \ | 523 | if (rt == __net->ipv6.ip6_null_entry) { \ |
521 | struct fib6_node *pn; \ | 524 | struct fib6_node *pn; \ |
522 | while (1) { \ | 525 | while (1) { \ |
523 | if (fn->fn_flags & RTN_TL_ROOT) \ | 526 | if (fn->fn_flags & RTN_TL_ROOT) \ |
@@ -533,7 +536,8 @@ do { \ | |||
533 | } \ | 536 | } \ |
534 | } while(0) | 537 | } while(0) |
535 | 538 | ||
536 | static struct rt6_info *ip6_pol_route_lookup(struct fib6_table *table, | 539 | static struct rt6_info *ip6_pol_route_lookup(struct net *net, |
540 | struct fib6_table *table, | ||
537 | struct flowi *fl, int flags) | 541 | struct flowi *fl, int flags) |
538 | { | 542 | { |
539 | struct fib6_node *fn; | 543 | struct fib6_node *fn; |
@@ -543,8 +547,8 @@ static struct rt6_info *ip6_pol_route_lookup(struct fib6_table *table, | |||
543 | fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src); | 547 | fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src); |
544 | restart: | 548 | restart: |
545 | rt = fn->leaf; | 549 | rt = fn->leaf; |
546 | rt = rt6_device_match(rt, fl->oif, flags); | 550 | rt = rt6_device_match(net, rt, fl->oif, flags); |
547 | BACKTRACK(&fl->fl6_src); | 551 | BACKTRACK(net, &fl->fl6_src); |
548 | out: | 552 | out: |
549 | dst_use(&rt->u.dst, jiffies); | 553 | dst_use(&rt->u.dst, jiffies); |
550 | read_unlock_bh(&table->tb6_lock); | 554 | read_unlock_bh(&table->tb6_lock); |
@@ -552,8 +556,8 @@ out: | |||
552 | 556 | ||
553 | } | 557 | } |
554 | 558 | ||
555 | struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr, | 559 | struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr, |
556 | int oif, int strict) | 560 | const struct in6_addr *saddr, int oif, int strict) |
557 | { | 561 | { |
558 | struct flowi fl = { | 562 | struct flowi fl = { |
559 | .oif = oif, | 563 | .oif = oif, |
@@ -571,7 +575,7 @@ struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr, | |||
571 | flags |= RT6_LOOKUP_F_HAS_SADDR; | 575 | flags |= RT6_LOOKUP_F_HAS_SADDR; |
572 | } | 576 | } |
573 | 577 | ||
574 | dst = fib6_rule_lookup(&fl, flags, ip6_pol_route_lookup); | 578 | dst = fib6_rule_lookup(net, &fl, flags, ip6_pol_route_lookup); |
575 | if (dst->error == 0) | 579 | if (dst->error == 0) |
576 | return (struct rt6_info *) dst; | 580 | return (struct rt6_info *) dst; |
577 | 581 | ||
@@ -604,7 +608,7 @@ static int __ip6_ins_rt(struct rt6_info *rt, struct nl_info *info) | |||
604 | int ip6_ins_rt(struct rt6_info *rt) | 608 | int ip6_ins_rt(struct rt6_info *rt) |
605 | { | 609 | { |
606 | struct nl_info info = { | 610 | struct nl_info info = { |
607 | .nl_net = &init_net, | 611 | .nl_net = dev_net(rt->rt6i_dev), |
608 | }; | 612 | }; |
609 | return __ip6_ins_rt(rt, &info); | 613 | return __ip6_ins_rt(rt, &info); |
610 | } | 614 | } |
@@ -660,8 +664,8 @@ static struct rt6_info *rt6_alloc_clone(struct rt6_info *ort, struct in6_addr *d | |||
660 | return rt; | 664 | return rt; |
661 | } | 665 | } |
662 | 666 | ||
663 | static struct rt6_info *ip6_pol_route(struct fib6_table *table, int oif, | 667 | static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, int oif, |
664 | struct flowi *fl, int flags) | 668 | struct flowi *fl, int flags) |
665 | { | 669 | { |
666 | struct fib6_node *fn; | 670 | struct fib6_node *fn; |
667 | struct rt6_info *rt, *nrt; | 671 | struct rt6_info *rt, *nrt; |
@@ -680,8 +684,9 @@ restart_2: | |||
680 | 684 | ||
681 | restart: | 685 | restart: |
682 | rt = rt6_select(fn, oif, strict | reachable); | 686 | rt = rt6_select(fn, oif, strict | reachable); |
683 | BACKTRACK(&fl->fl6_src); | 687 | |
684 | if (rt == &ip6_null_entry || | 688 | BACKTRACK(net, &fl->fl6_src); |
689 | if (rt == net->ipv6.ip6_null_entry || | ||
685 | rt->rt6i_flags & RTF_CACHE) | 690 | rt->rt6i_flags & RTF_CACHE) |
686 | goto out; | 691 | goto out; |
687 | 692 | ||
@@ -699,7 +704,7 @@ restart: | |||
699 | } | 704 | } |
700 | 705 | ||
701 | dst_release(&rt->u.dst); | 706 | dst_release(&rt->u.dst); |
702 | rt = nrt ? : &ip6_null_entry; | 707 | rt = nrt ? : net->ipv6.ip6_null_entry; |
703 | 708 | ||
704 | dst_hold(&rt->u.dst); | 709 | dst_hold(&rt->u.dst); |
705 | if (nrt) { | 710 | if (nrt) { |
@@ -732,15 +737,16 @@ out2: | |||
732 | return rt; | 737 | return rt; |
733 | } | 738 | } |
734 | 739 | ||
735 | static struct rt6_info *ip6_pol_route_input(struct fib6_table *table, | 740 | static struct rt6_info *ip6_pol_route_input(struct net *net, struct fib6_table *table, |
736 | struct flowi *fl, int flags) | 741 | struct flowi *fl, int flags) |
737 | { | 742 | { |
738 | return ip6_pol_route(table, fl->iif, fl, flags); | 743 | return ip6_pol_route(net, table, fl->iif, fl, flags); |
739 | } | 744 | } |
740 | 745 | ||
741 | void ip6_route_input(struct sk_buff *skb) | 746 | void ip6_route_input(struct sk_buff *skb) |
742 | { | 747 | { |
743 | struct ipv6hdr *iph = ipv6_hdr(skb); | 748 | struct ipv6hdr *iph = ipv6_hdr(skb); |
749 | struct net *net = dev_net(skb->dev); | ||
744 | int flags = RT6_LOOKUP_F_HAS_SADDR; | 750 | int flags = RT6_LOOKUP_F_HAS_SADDR; |
745 | struct flowi fl = { | 751 | struct flowi fl = { |
746 | .iif = skb->dev->ifindex, | 752 | .iif = skb->dev->ifindex, |
@@ -758,16 +764,17 @@ void ip6_route_input(struct sk_buff *skb) | |||
758 | if (rt6_need_strict(&iph->daddr)) | 764 | if (rt6_need_strict(&iph->daddr)) |
759 | flags |= RT6_LOOKUP_F_IFACE; | 765 | flags |= RT6_LOOKUP_F_IFACE; |
760 | 766 | ||
761 | skb->dst = fib6_rule_lookup(&fl, flags, ip6_pol_route_input); | 767 | skb->dst = fib6_rule_lookup(net, &fl, flags, ip6_pol_route_input); |
762 | } | 768 | } |
763 | 769 | ||
764 | static struct rt6_info *ip6_pol_route_output(struct fib6_table *table, | 770 | static struct rt6_info *ip6_pol_route_output(struct net *net, struct fib6_table *table, |
765 | struct flowi *fl, int flags) | 771 | struct flowi *fl, int flags) |
766 | { | 772 | { |
767 | return ip6_pol_route(table, fl->oif, fl, flags); | 773 | return ip6_pol_route(net, table, fl->oif, fl, flags); |
768 | } | 774 | } |
769 | 775 | ||
770 | struct dst_entry * ip6_route_output(struct sock *sk, struct flowi *fl) | 776 | struct dst_entry * ip6_route_output(struct net *net, struct sock *sk, |
777 | struct flowi *fl) | ||
771 | { | 778 | { |
772 | int flags = 0; | 779 | int flags = 0; |
773 | 780 | ||
@@ -776,8 +783,17 @@ struct dst_entry * ip6_route_output(struct sock *sk, struct flowi *fl) | |||
776 | 783 | ||
777 | if (!ipv6_addr_any(&fl->fl6_src)) | 784 | if (!ipv6_addr_any(&fl->fl6_src)) |
778 | flags |= RT6_LOOKUP_F_HAS_SADDR; | 785 | flags |= RT6_LOOKUP_F_HAS_SADDR; |
786 | else if (sk) { | ||
787 | unsigned int prefs = inet6_sk(sk)->srcprefs; | ||
788 | if (prefs & IPV6_PREFER_SRC_TMP) | ||
789 | flags |= RT6_LOOKUP_F_SRCPREF_TMP; | ||
790 | if (prefs & IPV6_PREFER_SRC_PUBLIC) | ||
791 | flags |= RT6_LOOKUP_F_SRCPREF_PUBLIC; | ||
792 | if (prefs & IPV6_PREFER_SRC_COA) | ||
793 | flags |= RT6_LOOKUP_F_SRCPREF_COA; | ||
794 | } | ||
779 | 795 | ||
780 | return fib6_rule_lookup(fl, flags, ip6_pol_route_output); | 796 | return fib6_rule_lookup(net, fl, flags, ip6_pol_route_output); |
781 | } | 797 | } |
782 | 798 | ||
783 | EXPORT_SYMBOL(ip6_route_output); | 799 | EXPORT_SYMBOL(ip6_route_output); |
@@ -886,12 +902,12 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, u32 mtu) | |||
886 | 902 | ||
887 | static int ipv6_get_mtu(struct net_device *dev); | 903 | static int ipv6_get_mtu(struct net_device *dev); |
888 | 904 | ||
889 | static inline unsigned int ipv6_advmss(unsigned int mtu) | 905 | static inline unsigned int ipv6_advmss(struct net *net, unsigned int mtu) |
890 | { | 906 | { |
891 | mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr); | 907 | mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr); |
892 | 908 | ||
893 | if (mtu < init_net.ipv6.sysctl.ip6_rt_min_advmss) | 909 | if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss) |
894 | mtu = init_net.ipv6.sysctl.ip6_rt_min_advmss; | 910 | mtu = net->ipv6.sysctl.ip6_rt_min_advmss; |
895 | 911 | ||
896 | /* | 912 | /* |
897 | * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and | 913 | * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and |
@@ -904,21 +920,21 @@ static inline unsigned int ipv6_advmss(unsigned int mtu) | |||
904 | return mtu; | 920 | return mtu; |
905 | } | 921 | } |
906 | 922 | ||
907 | static struct dst_entry *ndisc_dst_gc_list; | 923 | static struct dst_entry *icmp6_dst_gc_list; |
908 | static DEFINE_SPINLOCK(ndisc_lock); | 924 | static DEFINE_SPINLOCK(icmp6_dst_lock); |
909 | 925 | ||
910 | struct dst_entry *ndisc_dst_alloc(struct net_device *dev, | 926 | struct dst_entry *icmp6_dst_alloc(struct net_device *dev, |
911 | struct neighbour *neigh, | 927 | struct neighbour *neigh, |
912 | struct in6_addr *addr, | 928 | const struct in6_addr *addr) |
913 | int (*output)(struct sk_buff *)) | ||
914 | { | 929 | { |
915 | struct rt6_info *rt; | 930 | struct rt6_info *rt; |
916 | struct inet6_dev *idev = in6_dev_get(dev); | 931 | struct inet6_dev *idev = in6_dev_get(dev); |
932 | struct net *net = dev_net(dev); | ||
917 | 933 | ||
918 | if (unlikely(idev == NULL)) | 934 | if (unlikely(idev == NULL)) |
919 | return NULL; | 935 | return NULL; |
920 | 936 | ||
921 | rt = ip6_dst_alloc(); | 937 | rt = ip6_dst_alloc(net->ipv6.ip6_dst_ops); |
922 | if (unlikely(rt == NULL)) { | 938 | if (unlikely(rt == NULL)) { |
923 | in6_dev_put(idev); | 939 | in6_dev_put(idev); |
924 | goto out; | 940 | goto out; |
@@ -936,8 +952,8 @@ struct dst_entry *ndisc_dst_alloc(struct net_device *dev, | |||
936 | atomic_set(&rt->u.dst.__refcnt, 1); | 952 | atomic_set(&rt->u.dst.__refcnt, 1); |
937 | rt->u.dst.metrics[RTAX_HOPLIMIT-1] = 255; | 953 | rt->u.dst.metrics[RTAX_HOPLIMIT-1] = 255; |
938 | rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(rt->rt6i_dev); | 954 | rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(rt->rt6i_dev); |
939 | rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&rt->u.dst)); | 955 | rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(net, dst_mtu(&rt->u.dst)); |
940 | rt->u.dst.output = output; | 956 | rt->u.dst.output = ip6_output; |
941 | 957 | ||
942 | #if 0 /* there's no chance to use these for ndisc */ | 958 | #if 0 /* there's no chance to use these for ndisc */ |
943 | rt->u.dst.flags = ipv6_addr_type(addr) & IPV6_ADDR_UNICAST | 959 | rt->u.dst.flags = ipv6_addr_type(addr) & IPV6_ADDR_UNICAST |
@@ -947,18 +963,18 @@ struct dst_entry *ndisc_dst_alloc(struct net_device *dev, | |||
947 | rt->rt6i_dst.plen = 128; | 963 | rt->rt6i_dst.plen = 128; |
948 | #endif | 964 | #endif |
949 | 965 | ||
950 | spin_lock_bh(&ndisc_lock); | 966 | spin_lock_bh(&icmp6_dst_lock); |
951 | rt->u.dst.next = ndisc_dst_gc_list; | 967 | rt->u.dst.next = icmp6_dst_gc_list; |
952 | ndisc_dst_gc_list = &rt->u.dst; | 968 | icmp6_dst_gc_list = &rt->u.dst; |
953 | spin_unlock_bh(&ndisc_lock); | 969 | spin_unlock_bh(&icmp6_dst_lock); |
954 | 970 | ||
955 | fib6_force_start_gc(); | 971 | fib6_force_start_gc(net); |
956 | 972 | ||
957 | out: | 973 | out: |
958 | return &rt->u.dst; | 974 | return &rt->u.dst; |
959 | } | 975 | } |
960 | 976 | ||
961 | int ndisc_dst_gc(int *more) | 977 | int icmp6_dst_gc(int *more) |
962 | { | 978 | { |
963 | struct dst_entry *dst, *next, **pprev; | 979 | struct dst_entry *dst, *next, **pprev; |
964 | int freed; | 980 | int freed; |
@@ -966,8 +982,8 @@ int ndisc_dst_gc(int *more) | |||
966 | next = NULL; | 982 | next = NULL; |
967 | freed = 0; | 983 | freed = 0; |
968 | 984 | ||
969 | spin_lock_bh(&ndisc_lock); | 985 | spin_lock_bh(&icmp6_dst_lock); |
970 | pprev = &ndisc_dst_gc_list; | 986 | pprev = &icmp6_dst_gc_list; |
971 | 987 | ||
972 | while ((dst = *pprev) != NULL) { | 988 | while ((dst = *pprev) != NULL) { |
973 | if (!atomic_read(&dst->__refcnt)) { | 989 | if (!atomic_read(&dst->__refcnt)) { |
@@ -980,30 +996,33 @@ int ndisc_dst_gc(int *more) | |||
980 | } | 996 | } |
981 | } | 997 | } |
982 | 998 | ||
983 | spin_unlock_bh(&ndisc_lock); | 999 | spin_unlock_bh(&icmp6_dst_lock); |
984 | 1000 | ||
985 | return freed; | 1001 | return freed; |
986 | } | 1002 | } |
987 | 1003 | ||
988 | static int ip6_dst_gc(struct dst_ops *ops) | 1004 | static int ip6_dst_gc(struct dst_ops *ops) |
989 | { | 1005 | { |
990 | static unsigned expire = 30*HZ; | ||
991 | static unsigned long last_gc; | ||
992 | unsigned long now = jiffies; | 1006 | unsigned long now = jiffies; |
993 | 1007 | struct net *net = ops->dst_net; | |
994 | if (time_after(last_gc + init_net.ipv6.sysctl.ip6_rt_gc_min_interval, now) && | 1008 | int rt_min_interval = net->ipv6.sysctl.ip6_rt_gc_min_interval; |
995 | atomic_read(&ip6_dst_ops.entries) <= init_net.ipv6.sysctl.ip6_rt_max_size) | 1009 | int rt_max_size = net->ipv6.sysctl.ip6_rt_max_size; |
1010 | int rt_elasticity = net->ipv6.sysctl.ip6_rt_gc_elasticity; | ||
1011 | int rt_gc_timeout = net->ipv6.sysctl.ip6_rt_gc_timeout; | ||
1012 | unsigned long rt_last_gc = net->ipv6.ip6_rt_last_gc; | ||
1013 | |||
1014 | if (time_after(rt_last_gc + rt_min_interval, now) && | ||
1015 | atomic_read(&ops->entries) <= rt_max_size) | ||
996 | goto out; | 1016 | goto out; |
997 | 1017 | ||
998 | expire++; | 1018 | net->ipv6.ip6_rt_gc_expire++; |
999 | fib6_run_gc(expire); | 1019 | fib6_run_gc(net->ipv6.ip6_rt_gc_expire, net); |
1000 | last_gc = now; | 1020 | net->ipv6.ip6_rt_last_gc = now; |
1001 | if (atomic_read(&ip6_dst_ops.entries) < ip6_dst_ops.gc_thresh) | 1021 | if (atomic_read(&ops->entries) < ops->gc_thresh) |
1002 | expire = init_net.ipv6.sysctl.ip6_rt_gc_timeout>>1; | 1022 | net->ipv6.ip6_rt_gc_expire = rt_gc_timeout>>1; |
1003 | |||
1004 | out: | 1023 | out: |
1005 | expire -= expire>>init_net.ipv6.sysctl.ip6_rt_gc_elasticity; | 1024 | net->ipv6.ip6_rt_gc_expire -= net->ipv6.ip6_rt_gc_expire>>rt_elasticity; |
1006 | return (atomic_read(&ip6_dst_ops.entries) > init_net.ipv6.sysctl.ip6_rt_max_size); | 1025 | return (atomic_read(&ops->entries) > rt_max_size); |
1007 | } | 1026 | } |
1008 | 1027 | ||
1009 | /* Clean host part of a prefix. Not necessary in radix tree, | 1028 | /* Clean host part of a prefix. Not necessary in radix tree, |
@@ -1025,15 +1044,17 @@ static int ipv6_get_mtu(struct net_device *dev) | |||
1025 | return mtu; | 1044 | return mtu; |
1026 | } | 1045 | } |
1027 | 1046 | ||
1028 | int ipv6_get_hoplimit(struct net_device *dev) | 1047 | int ip6_dst_hoplimit(struct dst_entry *dst) |
1029 | { | 1048 | { |
1030 | int hoplimit = ipv6_devconf.hop_limit; | 1049 | int hoplimit = dst_metric(dst, RTAX_HOPLIMIT); |
1031 | struct inet6_dev *idev; | 1050 | if (hoplimit < 0) { |
1032 | 1051 | struct net_device *dev = dst->dev; | |
1033 | idev = in6_dev_get(dev); | 1052 | struct inet6_dev *idev = in6_dev_get(dev); |
1034 | if (idev) { | 1053 | if (idev) { |
1035 | hoplimit = idev->cnf.hop_limit; | 1054 | hoplimit = idev->cnf.hop_limit; |
1036 | in6_dev_put(idev); | 1055 | in6_dev_put(idev); |
1056 | } else | ||
1057 | hoplimit = ipv6_devconf.hop_limit; | ||
1037 | } | 1058 | } |
1038 | return hoplimit; | 1059 | return hoplimit; |
1039 | } | 1060 | } |
@@ -1045,6 +1066,7 @@ int ipv6_get_hoplimit(struct net_device *dev) | |||
1045 | int ip6_route_add(struct fib6_config *cfg) | 1066 | int ip6_route_add(struct fib6_config *cfg) |
1046 | { | 1067 | { |
1047 | int err; | 1068 | int err; |
1069 | struct net *net = cfg->fc_nlinfo.nl_net; | ||
1048 | struct rt6_info *rt = NULL; | 1070 | struct rt6_info *rt = NULL; |
1049 | struct net_device *dev = NULL; | 1071 | struct net_device *dev = NULL; |
1050 | struct inet6_dev *idev = NULL; | 1072 | struct inet6_dev *idev = NULL; |
@@ -1059,7 +1081,7 @@ int ip6_route_add(struct fib6_config *cfg) | |||
1059 | #endif | 1081 | #endif |
1060 | if (cfg->fc_ifindex) { | 1082 | if (cfg->fc_ifindex) { |
1061 | err = -ENODEV; | 1083 | err = -ENODEV; |
1062 | dev = dev_get_by_index(&init_net, cfg->fc_ifindex); | 1084 | dev = dev_get_by_index(net, cfg->fc_ifindex); |
1063 | if (!dev) | 1085 | if (!dev) |
1064 | goto out; | 1086 | goto out; |
1065 | idev = in6_dev_get(dev); | 1087 | idev = in6_dev_get(dev); |
@@ -1070,13 +1092,13 @@ int ip6_route_add(struct fib6_config *cfg) | |||
1070 | if (cfg->fc_metric == 0) | 1092 | if (cfg->fc_metric == 0) |
1071 | cfg->fc_metric = IP6_RT_PRIO_USER; | 1093 | cfg->fc_metric = IP6_RT_PRIO_USER; |
1072 | 1094 | ||
1073 | table = fib6_new_table(cfg->fc_table); | 1095 | table = fib6_new_table(net, cfg->fc_table); |
1074 | if (table == NULL) { | 1096 | if (table == NULL) { |
1075 | err = -ENOBUFS; | 1097 | err = -ENOBUFS; |
1076 | goto out; | 1098 | goto out; |
1077 | } | 1099 | } |
1078 | 1100 | ||
1079 | rt = ip6_dst_alloc(); | 1101 | rt = ip6_dst_alloc(net->ipv6.ip6_dst_ops); |
1080 | 1102 | ||
1081 | if (rt == NULL) { | 1103 | if (rt == NULL) { |
1082 | err = -ENOMEM; | 1104 | err = -ENOMEM; |
@@ -1117,12 +1139,12 @@ int ip6_route_add(struct fib6_config *cfg) | |||
1117 | if ((cfg->fc_flags & RTF_REJECT) || | 1139 | if ((cfg->fc_flags & RTF_REJECT) || |
1118 | (dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK))) { | 1140 | (dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK))) { |
1119 | /* hold loopback dev/idev if we haven't done so. */ | 1141 | /* hold loopback dev/idev if we haven't done so. */ |
1120 | if (dev != init_net.loopback_dev) { | 1142 | if (dev != net->loopback_dev) { |
1121 | if (dev) { | 1143 | if (dev) { |
1122 | dev_put(dev); | 1144 | dev_put(dev); |
1123 | in6_dev_put(idev); | 1145 | in6_dev_put(idev); |
1124 | } | 1146 | } |
1125 | dev = init_net.loopback_dev; | 1147 | dev = net->loopback_dev; |
1126 | dev_hold(dev); | 1148 | dev_hold(dev); |
1127 | idev = in6_dev_get(dev); | 1149 | idev = in6_dev_get(dev); |
1128 | if (!idev) { | 1150 | if (!idev) { |
@@ -1159,7 +1181,7 @@ int ip6_route_add(struct fib6_config *cfg) | |||
1159 | if (!(gwa_type&IPV6_ADDR_UNICAST)) | 1181 | if (!(gwa_type&IPV6_ADDR_UNICAST)) |
1160 | goto out; | 1182 | goto out; |
1161 | 1183 | ||
1162 | grt = rt6_lookup(gw_addr, NULL, cfg->fc_ifindex, 1); | 1184 | grt = rt6_lookup(net, gw_addr, NULL, cfg->fc_ifindex, 1); |
1163 | 1185 | ||
1164 | err = -EHOSTUNREACH; | 1186 | err = -EHOSTUNREACH; |
1165 | if (grt == NULL) | 1187 | if (grt == NULL) |
@@ -1226,10 +1248,13 @@ install_route: | |||
1226 | if (!rt->u.dst.metrics[RTAX_MTU-1]) | 1248 | if (!rt->u.dst.metrics[RTAX_MTU-1]) |
1227 | rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(dev); | 1249 | rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(dev); |
1228 | if (!rt->u.dst.metrics[RTAX_ADVMSS-1]) | 1250 | if (!rt->u.dst.metrics[RTAX_ADVMSS-1]) |
1229 | rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&rt->u.dst)); | 1251 | rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(net, dst_mtu(&rt->u.dst)); |
1230 | rt->u.dst.dev = dev; | 1252 | rt->u.dst.dev = dev; |
1231 | rt->rt6i_idev = idev; | 1253 | rt->rt6i_idev = idev; |
1232 | rt->rt6i_table = table; | 1254 | rt->rt6i_table = table; |
1255 | |||
1256 | cfg->fc_nlinfo.nl_net = dev_net(dev); | ||
1257 | |||
1233 | return __ip6_ins_rt(rt, &cfg->fc_nlinfo); | 1258 | return __ip6_ins_rt(rt, &cfg->fc_nlinfo); |
1234 | 1259 | ||
1235 | out: | 1260 | out: |
@@ -1246,8 +1271,9 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info) | |||
1246 | { | 1271 | { |
1247 | int err; | 1272 | int err; |
1248 | struct fib6_table *table; | 1273 | struct fib6_table *table; |
1274 | struct net *net = dev_net(rt->rt6i_dev); | ||
1249 | 1275 | ||
1250 | if (rt == &ip6_null_entry) | 1276 | if (rt == net->ipv6.ip6_null_entry) |
1251 | return -ENOENT; | 1277 | return -ENOENT; |
1252 | 1278 | ||
1253 | table = rt->rt6i_table; | 1279 | table = rt->rt6i_table; |
@@ -1264,7 +1290,7 @@ static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info) | |||
1264 | int ip6_del_rt(struct rt6_info *rt) | 1290 | int ip6_del_rt(struct rt6_info *rt) |
1265 | { | 1291 | { |
1266 | struct nl_info info = { | 1292 | struct nl_info info = { |
1267 | .nl_net = &init_net, | 1293 | .nl_net = dev_net(rt->rt6i_dev), |
1268 | }; | 1294 | }; |
1269 | return __ip6_del_rt(rt, &info); | 1295 | return __ip6_del_rt(rt, &info); |
1270 | } | 1296 | } |
@@ -1276,7 +1302,7 @@ static int ip6_route_del(struct fib6_config *cfg) | |||
1276 | struct rt6_info *rt; | 1302 | struct rt6_info *rt; |
1277 | int err = -ESRCH; | 1303 | int err = -ESRCH; |
1278 | 1304 | ||
1279 | table = fib6_get_table(cfg->fc_table); | 1305 | table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table); |
1280 | if (table == NULL) | 1306 | if (table == NULL) |
1281 | return err; | 1307 | return err; |
1282 | 1308 | ||
@@ -1316,7 +1342,8 @@ struct ip6rd_flowi { | |||
1316 | struct in6_addr gateway; | 1342 | struct in6_addr gateway; |
1317 | }; | 1343 | }; |
1318 | 1344 | ||
1319 | static struct rt6_info *__ip6_route_redirect(struct fib6_table *table, | 1345 | static struct rt6_info *__ip6_route_redirect(struct net *net, |
1346 | struct fib6_table *table, | ||
1320 | struct flowi *fl, | 1347 | struct flowi *fl, |
1321 | int flags) | 1348 | int flags) |
1322 | { | 1349 | { |
@@ -1359,8 +1386,8 @@ restart: | |||
1359 | } | 1386 | } |
1360 | 1387 | ||
1361 | if (!rt) | 1388 | if (!rt) |
1362 | rt = &ip6_null_entry; | 1389 | rt = net->ipv6.ip6_null_entry; |
1363 | BACKTRACK(&fl->fl6_src); | 1390 | BACKTRACK(net, &fl->fl6_src); |
1364 | out: | 1391 | out: |
1365 | dst_hold(&rt->u.dst); | 1392 | dst_hold(&rt->u.dst); |
1366 | 1393 | ||
@@ -1375,6 +1402,7 @@ static struct rt6_info *ip6_route_redirect(struct in6_addr *dest, | |||
1375 | struct net_device *dev) | 1402 | struct net_device *dev) |
1376 | { | 1403 | { |
1377 | int flags = RT6_LOOKUP_F_HAS_SADDR; | 1404 | int flags = RT6_LOOKUP_F_HAS_SADDR; |
1405 | struct net *net = dev_net(dev); | ||
1378 | struct ip6rd_flowi rdfl = { | 1406 | struct ip6rd_flowi rdfl = { |
1379 | .fl = { | 1407 | .fl = { |
1380 | .oif = dev->ifindex, | 1408 | .oif = dev->ifindex, |
@@ -1391,7 +1419,8 @@ static struct rt6_info *ip6_route_redirect(struct in6_addr *dest, | |||
1391 | if (rt6_need_strict(dest)) | 1419 | if (rt6_need_strict(dest)) |
1392 | flags |= RT6_LOOKUP_F_IFACE; | 1420 | flags |= RT6_LOOKUP_F_IFACE; |
1393 | 1421 | ||
1394 | return (struct rt6_info *)fib6_rule_lookup((struct flowi *)&rdfl, flags, __ip6_route_redirect); | 1422 | return (struct rt6_info *)fib6_rule_lookup(net, (struct flowi *)&rdfl, |
1423 | flags, __ip6_route_redirect); | ||
1395 | } | 1424 | } |
1396 | 1425 | ||
1397 | void rt6_redirect(struct in6_addr *dest, struct in6_addr *src, | 1426 | void rt6_redirect(struct in6_addr *dest, struct in6_addr *src, |
@@ -1400,10 +1429,11 @@ void rt6_redirect(struct in6_addr *dest, struct in6_addr *src, | |||
1400 | { | 1429 | { |
1401 | struct rt6_info *rt, *nrt = NULL; | 1430 | struct rt6_info *rt, *nrt = NULL; |
1402 | struct netevent_redirect netevent; | 1431 | struct netevent_redirect netevent; |
1432 | struct net *net = dev_net(neigh->dev); | ||
1403 | 1433 | ||
1404 | rt = ip6_route_redirect(dest, src, saddr, neigh->dev); | 1434 | rt = ip6_route_redirect(dest, src, saddr, neigh->dev); |
1405 | 1435 | ||
1406 | if (rt == &ip6_null_entry) { | 1436 | if (rt == net->ipv6.ip6_null_entry) { |
1407 | if (net_ratelimit()) | 1437 | if (net_ratelimit()) |
1408 | printk(KERN_DEBUG "rt6_redirect: source isn't a valid nexthop " | 1438 | printk(KERN_DEBUG "rt6_redirect: source isn't a valid nexthop " |
1409 | "for redirect target\n"); | 1439 | "for redirect target\n"); |
@@ -1448,7 +1478,8 @@ void rt6_redirect(struct in6_addr *dest, struct in6_addr *src, | |||
1448 | nrt->rt6i_nexthop = neigh_clone(neigh); | 1478 | nrt->rt6i_nexthop = neigh_clone(neigh); |
1449 | /* Reset pmtu, it may be better */ | 1479 | /* Reset pmtu, it may be better */ |
1450 | nrt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(neigh->dev); | 1480 | nrt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(neigh->dev); |
1451 | nrt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&nrt->u.dst)); | 1481 | nrt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dev_net(neigh->dev), |
1482 | dst_mtu(&nrt->u.dst)); | ||
1452 | 1483 | ||
1453 | if (ip6_ins_rt(nrt)) | 1484 | if (ip6_ins_rt(nrt)) |
1454 | goto out; | 1485 | goto out; |
@@ -1476,9 +1507,10 @@ void rt6_pmtu_discovery(struct in6_addr *daddr, struct in6_addr *saddr, | |||
1476 | struct net_device *dev, u32 pmtu) | 1507 | struct net_device *dev, u32 pmtu) |
1477 | { | 1508 | { |
1478 | struct rt6_info *rt, *nrt; | 1509 | struct rt6_info *rt, *nrt; |
1510 | struct net *net = dev_net(dev); | ||
1479 | int allfrag = 0; | 1511 | int allfrag = 0; |
1480 | 1512 | ||
1481 | rt = rt6_lookup(daddr, saddr, dev->ifindex, 0); | 1513 | rt = rt6_lookup(net, daddr, saddr, dev->ifindex, 0); |
1482 | if (rt == NULL) | 1514 | if (rt == NULL) |
1483 | return; | 1515 | return; |
1484 | 1516 | ||
@@ -1511,7 +1543,7 @@ void rt6_pmtu_discovery(struct in6_addr *daddr, struct in6_addr *saddr, | |||
1511 | rt->u.dst.metrics[RTAX_MTU-1] = pmtu; | 1543 | rt->u.dst.metrics[RTAX_MTU-1] = pmtu; |
1512 | if (allfrag) | 1544 | if (allfrag) |
1513 | rt->u.dst.metrics[RTAX_FEATURES-1] |= RTAX_FEATURE_ALLFRAG; | 1545 | rt->u.dst.metrics[RTAX_FEATURES-1] |= RTAX_FEATURE_ALLFRAG; |
1514 | dst_set_expires(&rt->u.dst, init_net.ipv6.sysctl.ip6_rt_mtu_expires); | 1546 | dst_set_expires(&rt->u.dst, net->ipv6.sysctl.ip6_rt_mtu_expires); |
1515 | rt->rt6i_flags |= RTF_MODIFIED|RTF_EXPIRES; | 1547 | rt->rt6i_flags |= RTF_MODIFIED|RTF_EXPIRES; |
1516 | goto out; | 1548 | goto out; |
1517 | } | 1549 | } |
@@ -1537,7 +1569,7 @@ void rt6_pmtu_discovery(struct in6_addr *daddr, struct in6_addr *saddr, | |||
1537 | * which is 10 mins. After 10 mins the decreased pmtu is expired | 1569 | * which is 10 mins. After 10 mins the decreased pmtu is expired |
1538 | * and detecting PMTU increase will be automatically happened. | 1570 | * and detecting PMTU increase will be automatically happened. |
1539 | */ | 1571 | */ |
1540 | dst_set_expires(&nrt->u.dst, init_net.ipv6.sysctl.ip6_rt_mtu_expires); | 1572 | dst_set_expires(&nrt->u.dst, net->ipv6.sysctl.ip6_rt_mtu_expires); |
1541 | nrt->rt6i_flags |= RTF_DYNAMIC|RTF_EXPIRES; | 1573 | nrt->rt6i_flags |= RTF_DYNAMIC|RTF_EXPIRES; |
1542 | 1574 | ||
1543 | ip6_ins_rt(nrt); | 1575 | ip6_ins_rt(nrt); |
@@ -1552,7 +1584,8 @@ out: | |||
1552 | 1584 | ||
1553 | static struct rt6_info * ip6_rt_copy(struct rt6_info *ort) | 1585 | static struct rt6_info * ip6_rt_copy(struct rt6_info *ort) |
1554 | { | 1586 | { |
1555 | struct rt6_info *rt = ip6_dst_alloc(); | 1587 | struct net *net = dev_net(ort->rt6i_dev); |
1588 | struct rt6_info *rt = ip6_dst_alloc(net->ipv6.ip6_dst_ops); | ||
1556 | 1589 | ||
1557 | if (rt) { | 1590 | if (rt) { |
1558 | rt->u.dst.input = ort->u.dst.input; | 1591 | rt->u.dst.input = ort->u.dst.input; |
@@ -1583,14 +1616,15 @@ static struct rt6_info * ip6_rt_copy(struct rt6_info *ort) | |||
1583 | } | 1616 | } |
1584 | 1617 | ||
1585 | #ifdef CONFIG_IPV6_ROUTE_INFO | 1618 | #ifdef CONFIG_IPV6_ROUTE_INFO |
1586 | static struct rt6_info *rt6_get_route_info(struct in6_addr *prefix, int prefixlen, | 1619 | static struct rt6_info *rt6_get_route_info(struct net *net, |
1620 | struct in6_addr *prefix, int prefixlen, | ||
1587 | struct in6_addr *gwaddr, int ifindex) | 1621 | struct in6_addr *gwaddr, int ifindex) |
1588 | { | 1622 | { |
1589 | struct fib6_node *fn; | 1623 | struct fib6_node *fn; |
1590 | struct rt6_info *rt = NULL; | 1624 | struct rt6_info *rt = NULL; |
1591 | struct fib6_table *table; | 1625 | struct fib6_table *table; |
1592 | 1626 | ||
1593 | table = fib6_get_table(RT6_TABLE_INFO); | 1627 | table = fib6_get_table(net, RT6_TABLE_INFO); |
1594 | if (table == NULL) | 1628 | if (table == NULL) |
1595 | return NULL; | 1629 | return NULL; |
1596 | 1630 | ||
@@ -1614,7 +1648,8 @@ out: | |||
1614 | return rt; | 1648 | return rt; |
1615 | } | 1649 | } |
1616 | 1650 | ||
1617 | static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixlen, | 1651 | static struct rt6_info *rt6_add_route_info(struct net *net, |
1652 | struct in6_addr *prefix, int prefixlen, | ||
1618 | struct in6_addr *gwaddr, int ifindex, | 1653 | struct in6_addr *gwaddr, int ifindex, |
1619 | unsigned pref) | 1654 | unsigned pref) |
1620 | { | 1655 | { |
@@ -1625,6 +1660,9 @@ static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixle | |||
1625 | .fc_dst_len = prefixlen, | 1660 | .fc_dst_len = prefixlen, |
1626 | .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_ROUTEINFO | | 1661 | .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_ROUTEINFO | |
1627 | RTF_UP | RTF_PREF(pref), | 1662 | RTF_UP | RTF_PREF(pref), |
1663 | .fc_nlinfo.pid = 0, | ||
1664 | .fc_nlinfo.nlh = NULL, | ||
1665 | .fc_nlinfo.nl_net = net, | ||
1628 | }; | 1666 | }; |
1629 | 1667 | ||
1630 | ipv6_addr_copy(&cfg.fc_dst, prefix); | 1668 | ipv6_addr_copy(&cfg.fc_dst, prefix); |
@@ -1636,7 +1674,7 @@ static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixle | |||
1636 | 1674 | ||
1637 | ip6_route_add(&cfg); | 1675 | ip6_route_add(&cfg); |
1638 | 1676 | ||
1639 | return rt6_get_route_info(prefix, prefixlen, gwaddr, ifindex); | 1677 | return rt6_get_route_info(net, prefix, prefixlen, gwaddr, ifindex); |
1640 | } | 1678 | } |
1641 | #endif | 1679 | #endif |
1642 | 1680 | ||
@@ -1645,7 +1683,7 @@ struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *d | |||
1645 | struct rt6_info *rt; | 1683 | struct rt6_info *rt; |
1646 | struct fib6_table *table; | 1684 | struct fib6_table *table; |
1647 | 1685 | ||
1648 | table = fib6_get_table(RT6_TABLE_DFLT); | 1686 | table = fib6_get_table(dev_net(dev), RT6_TABLE_DFLT); |
1649 | if (table == NULL) | 1687 | if (table == NULL) |
1650 | return NULL; | 1688 | return NULL; |
1651 | 1689 | ||
@@ -1662,8 +1700,6 @@ struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *d | |||
1662 | return rt; | 1700 | return rt; |
1663 | } | 1701 | } |
1664 | 1702 | ||
1665 | EXPORT_SYMBOL(rt6_get_dflt_router); | ||
1666 | |||
1667 | struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr, | 1703 | struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr, |
1668 | struct net_device *dev, | 1704 | struct net_device *dev, |
1669 | unsigned int pref) | 1705 | unsigned int pref) |
@@ -1674,6 +1710,9 @@ struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr, | |||
1674 | .fc_ifindex = dev->ifindex, | 1710 | .fc_ifindex = dev->ifindex, |
1675 | .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT | | 1711 | .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT | |
1676 | RTF_UP | RTF_EXPIRES | RTF_PREF(pref), | 1712 | RTF_UP | RTF_EXPIRES | RTF_PREF(pref), |
1713 | .fc_nlinfo.pid = 0, | ||
1714 | .fc_nlinfo.nlh = NULL, | ||
1715 | .fc_nlinfo.nl_net = dev_net(dev), | ||
1677 | }; | 1716 | }; |
1678 | 1717 | ||
1679 | ipv6_addr_copy(&cfg.fc_gateway, gwaddr); | 1718 | ipv6_addr_copy(&cfg.fc_gateway, gwaddr); |
@@ -1683,13 +1722,13 @@ struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr, | |||
1683 | return rt6_get_dflt_router(gwaddr, dev); | 1722 | return rt6_get_dflt_router(gwaddr, dev); |
1684 | } | 1723 | } |
1685 | 1724 | ||
1686 | void rt6_purge_dflt_routers(void) | 1725 | void rt6_purge_dflt_routers(struct net *net) |
1687 | { | 1726 | { |
1688 | struct rt6_info *rt; | 1727 | struct rt6_info *rt; |
1689 | struct fib6_table *table; | 1728 | struct fib6_table *table; |
1690 | 1729 | ||
1691 | /* NOTE: Keep consistent with rt6_get_dflt_router */ | 1730 | /* NOTE: Keep consistent with rt6_get_dflt_router */ |
1692 | table = fib6_get_table(RT6_TABLE_DFLT); | 1731 | table = fib6_get_table(net, RT6_TABLE_DFLT); |
1693 | if (table == NULL) | 1732 | if (table == NULL) |
1694 | return; | 1733 | return; |
1695 | 1734 | ||
@@ -1706,7 +1745,8 @@ restart: | |||
1706 | read_unlock_bh(&table->tb6_lock); | 1745 | read_unlock_bh(&table->tb6_lock); |
1707 | } | 1746 | } |
1708 | 1747 | ||
1709 | static void rtmsg_to_fib6_config(struct in6_rtmsg *rtmsg, | 1748 | static void rtmsg_to_fib6_config(struct net *net, |
1749 | struct in6_rtmsg *rtmsg, | ||
1710 | struct fib6_config *cfg) | 1750 | struct fib6_config *cfg) |
1711 | { | 1751 | { |
1712 | memset(cfg, 0, sizeof(*cfg)); | 1752 | memset(cfg, 0, sizeof(*cfg)); |
@@ -1719,14 +1759,14 @@ static void rtmsg_to_fib6_config(struct in6_rtmsg *rtmsg, | |||
1719 | cfg->fc_src_len = rtmsg->rtmsg_src_len; | 1759 | cfg->fc_src_len = rtmsg->rtmsg_src_len; |
1720 | cfg->fc_flags = rtmsg->rtmsg_flags; | 1760 | cfg->fc_flags = rtmsg->rtmsg_flags; |
1721 | 1761 | ||
1722 | cfg->fc_nlinfo.nl_net = &init_net; | 1762 | cfg->fc_nlinfo.nl_net = net; |
1723 | 1763 | ||
1724 | ipv6_addr_copy(&cfg->fc_dst, &rtmsg->rtmsg_dst); | 1764 | ipv6_addr_copy(&cfg->fc_dst, &rtmsg->rtmsg_dst); |
1725 | ipv6_addr_copy(&cfg->fc_src, &rtmsg->rtmsg_src); | 1765 | ipv6_addr_copy(&cfg->fc_src, &rtmsg->rtmsg_src); |
1726 | ipv6_addr_copy(&cfg->fc_gateway, &rtmsg->rtmsg_gateway); | 1766 | ipv6_addr_copy(&cfg->fc_gateway, &rtmsg->rtmsg_gateway); |
1727 | } | 1767 | } |
1728 | 1768 | ||
1729 | int ipv6_route_ioctl(unsigned int cmd, void __user *arg) | 1769 | int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg) |
1730 | { | 1770 | { |
1731 | struct fib6_config cfg; | 1771 | struct fib6_config cfg; |
1732 | struct in6_rtmsg rtmsg; | 1772 | struct in6_rtmsg rtmsg; |
@@ -1742,7 +1782,7 @@ int ipv6_route_ioctl(unsigned int cmd, void __user *arg) | |||
1742 | if (err) | 1782 | if (err) |
1743 | return -EFAULT; | 1783 | return -EFAULT; |
1744 | 1784 | ||
1745 | rtmsg_to_fib6_config(&rtmsg, &cfg); | 1785 | rtmsg_to_fib6_config(net, &rtmsg, &cfg); |
1746 | 1786 | ||
1747 | rtnl_lock(); | 1787 | rtnl_lock(); |
1748 | switch (cmd) { | 1788 | switch (cmd) { |
@@ -1821,21 +1861,22 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev, | |||
1821 | const struct in6_addr *addr, | 1861 | const struct in6_addr *addr, |
1822 | int anycast) | 1862 | int anycast) |
1823 | { | 1863 | { |
1824 | struct rt6_info *rt = ip6_dst_alloc(); | 1864 | struct net *net = dev_net(idev->dev); |
1865 | struct rt6_info *rt = ip6_dst_alloc(net->ipv6.ip6_dst_ops); | ||
1825 | 1866 | ||
1826 | if (rt == NULL) | 1867 | if (rt == NULL) |
1827 | return ERR_PTR(-ENOMEM); | 1868 | return ERR_PTR(-ENOMEM); |
1828 | 1869 | ||
1829 | dev_hold(init_net.loopback_dev); | 1870 | dev_hold(net->loopback_dev); |
1830 | in6_dev_hold(idev); | 1871 | in6_dev_hold(idev); |
1831 | 1872 | ||
1832 | rt->u.dst.flags = DST_HOST; | 1873 | rt->u.dst.flags = DST_HOST; |
1833 | rt->u.dst.input = ip6_input; | 1874 | rt->u.dst.input = ip6_input; |
1834 | rt->u.dst.output = ip6_output; | 1875 | rt->u.dst.output = ip6_output; |
1835 | rt->rt6i_dev = init_net.loopback_dev; | 1876 | rt->rt6i_dev = net->loopback_dev; |
1836 | rt->rt6i_idev = idev; | 1877 | rt->rt6i_idev = idev; |
1837 | rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(rt->rt6i_dev); | 1878 | rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(rt->rt6i_dev); |
1838 | rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&rt->u.dst)); | 1879 | rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(net, dst_mtu(&rt->u.dst)); |
1839 | rt->u.dst.metrics[RTAX_HOPLIMIT-1] = -1; | 1880 | rt->u.dst.metrics[RTAX_HOPLIMIT-1] = -1; |
1840 | rt->u.dst.obsolete = -1; | 1881 | rt->u.dst.obsolete = -1; |
1841 | 1882 | ||
@@ -1852,26 +1893,39 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev, | |||
1852 | 1893 | ||
1853 | ipv6_addr_copy(&rt->rt6i_dst.addr, addr); | 1894 | ipv6_addr_copy(&rt->rt6i_dst.addr, addr); |
1854 | rt->rt6i_dst.plen = 128; | 1895 | rt->rt6i_dst.plen = 128; |
1855 | rt->rt6i_table = fib6_get_table(RT6_TABLE_LOCAL); | 1896 | rt->rt6i_table = fib6_get_table(net, RT6_TABLE_LOCAL); |
1856 | 1897 | ||
1857 | atomic_set(&rt->u.dst.__refcnt, 1); | 1898 | atomic_set(&rt->u.dst.__refcnt, 1); |
1858 | 1899 | ||
1859 | return rt; | 1900 | return rt; |
1860 | } | 1901 | } |
1861 | 1902 | ||
1903 | struct arg_dev_net { | ||
1904 | struct net_device *dev; | ||
1905 | struct net *net; | ||
1906 | }; | ||
1907 | |||
1862 | static int fib6_ifdown(struct rt6_info *rt, void *arg) | 1908 | static int fib6_ifdown(struct rt6_info *rt, void *arg) |
1863 | { | 1909 | { |
1864 | if (((void*)rt->rt6i_dev == arg || arg == NULL) && | 1910 | struct net_device *dev = ((struct arg_dev_net *)arg)->dev; |
1865 | rt != &ip6_null_entry) { | 1911 | struct net *net = ((struct arg_dev_net *)arg)->net; |
1912 | |||
1913 | if (((void *)rt->rt6i_dev == dev || dev == NULL) && | ||
1914 | rt != net->ipv6.ip6_null_entry) { | ||
1866 | RT6_TRACE("deleted by ifdown %p\n", rt); | 1915 | RT6_TRACE("deleted by ifdown %p\n", rt); |
1867 | return -1; | 1916 | return -1; |
1868 | } | 1917 | } |
1869 | return 0; | 1918 | return 0; |
1870 | } | 1919 | } |
1871 | 1920 | ||
1872 | void rt6_ifdown(struct net_device *dev) | 1921 | void rt6_ifdown(struct net *net, struct net_device *dev) |
1873 | { | 1922 | { |
1874 | fib6_clean_all(fib6_ifdown, 0, dev); | 1923 | struct arg_dev_net adn = { |
1924 | .dev = dev, | ||
1925 | .net = net, | ||
1926 | }; | ||
1927 | |||
1928 | fib6_clean_all(net, fib6_ifdown, 0, &adn); | ||
1875 | } | 1929 | } |
1876 | 1930 | ||
1877 | struct rt6_mtu_change_arg | 1931 | struct rt6_mtu_change_arg |
@@ -1884,6 +1938,7 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg) | |||
1884 | { | 1938 | { |
1885 | struct rt6_mtu_change_arg *arg = (struct rt6_mtu_change_arg *) p_arg; | 1939 | struct rt6_mtu_change_arg *arg = (struct rt6_mtu_change_arg *) p_arg; |
1886 | struct inet6_dev *idev; | 1940 | struct inet6_dev *idev; |
1941 | struct net *net = dev_net(arg->dev); | ||
1887 | 1942 | ||
1888 | /* In IPv6 pmtu discovery is not optional, | 1943 | /* In IPv6 pmtu discovery is not optional, |
1889 | so that RTAX_MTU lock cannot disable it. | 1944 | so that RTAX_MTU lock cannot disable it. |
@@ -1915,7 +1970,7 @@ static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg) | |||
1915 | (dst_mtu(&rt->u.dst) < arg->mtu && | 1970 | (dst_mtu(&rt->u.dst) < arg->mtu && |
1916 | dst_mtu(&rt->u.dst) == idev->cnf.mtu6))) { | 1971 | dst_mtu(&rt->u.dst) == idev->cnf.mtu6))) { |
1917 | rt->u.dst.metrics[RTAX_MTU-1] = arg->mtu; | 1972 | rt->u.dst.metrics[RTAX_MTU-1] = arg->mtu; |
1918 | rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(arg->mtu); | 1973 | rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(net, arg->mtu); |
1919 | } | 1974 | } |
1920 | return 0; | 1975 | return 0; |
1921 | } | 1976 | } |
@@ -1927,7 +1982,7 @@ void rt6_mtu_change(struct net_device *dev, unsigned mtu) | |||
1927 | .mtu = mtu, | 1982 | .mtu = mtu, |
1928 | }; | 1983 | }; |
1929 | 1984 | ||
1930 | fib6_clean_all(rt6_mtu_change_route, 0, &arg); | 1985 | fib6_clean_all(dev_net(dev), rt6_mtu_change_route, 0, &arg); |
1931 | } | 1986 | } |
1932 | 1987 | ||
1933 | static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = { | 1988 | static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = { |
@@ -1964,7 +2019,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1964 | 2019 | ||
1965 | cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid; | 2020 | cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid; |
1966 | cfg->fc_nlinfo.nlh = nlh; | 2021 | cfg->fc_nlinfo.nlh = nlh; |
1967 | cfg->fc_nlinfo.nl_net = skb->sk->sk_net; | 2022 | cfg->fc_nlinfo.nl_net = sock_net(skb->sk); |
1968 | 2023 | ||
1969 | if (tb[RTA_GATEWAY]) { | 2024 | if (tb[RTA_GATEWAY]) { |
1970 | nla_memcpy(&cfg->fc_gateway, tb[RTA_GATEWAY], 16); | 2025 | nla_memcpy(&cfg->fc_gateway, tb[RTA_GATEWAY], 16); |
@@ -2010,13 +2065,9 @@ errout: | |||
2010 | 2065 | ||
2011 | static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) | 2066 | static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) |
2012 | { | 2067 | { |
2013 | struct net *net = skb->sk->sk_net; | ||
2014 | struct fib6_config cfg; | 2068 | struct fib6_config cfg; |
2015 | int err; | 2069 | int err; |
2016 | 2070 | ||
2017 | if (net != &init_net) | ||
2018 | return -EINVAL; | ||
2019 | |||
2020 | err = rtm_to_fib6_config(skb, nlh, &cfg); | 2071 | err = rtm_to_fib6_config(skb, nlh, &cfg); |
2021 | if (err < 0) | 2072 | if (err < 0) |
2022 | return err; | 2073 | return err; |
@@ -2026,13 +2077,9 @@ static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *a | |||
2026 | 2077 | ||
2027 | static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) | 2078 | static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) |
2028 | { | 2079 | { |
2029 | struct net *net = skb->sk->sk_net; | ||
2030 | struct fib6_config cfg; | 2080 | struct fib6_config cfg; |
2031 | int err; | 2081 | int err; |
2032 | 2082 | ||
2033 | if (net != &init_net) | ||
2034 | return -EINVAL; | ||
2035 | |||
2036 | err = rtm_to_fib6_config(skb, nlh, &cfg); | 2083 | err = rtm_to_fib6_config(skb, nlh, &cfg); |
2037 | if (err < 0) | 2084 | if (err < 0) |
2038 | return err; | 2085 | return err; |
@@ -2058,7 +2105,7 @@ static inline size_t rt6_nlmsg_size(void) | |||
2058 | static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt, | 2105 | static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt, |
2059 | struct in6_addr *dst, struct in6_addr *src, | 2106 | struct in6_addr *dst, struct in6_addr *src, |
2060 | int iif, int type, u32 pid, u32 seq, | 2107 | int iif, int type, u32 pid, u32 seq, |
2061 | int prefix, unsigned int flags) | 2108 | int prefix, int nowait, unsigned int flags) |
2062 | { | 2109 | { |
2063 | struct rtmsg *rtm; | 2110 | struct rtmsg *rtm; |
2064 | struct nlmsghdr *nlh; | 2111 | struct nlmsghdr *nlh; |
@@ -2118,11 +2165,27 @@ static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt, | |||
2118 | } else if (rtm->rtm_src_len) | 2165 | } else if (rtm->rtm_src_len) |
2119 | NLA_PUT(skb, RTA_SRC, 16, &rt->rt6i_src.addr); | 2166 | NLA_PUT(skb, RTA_SRC, 16, &rt->rt6i_src.addr); |
2120 | #endif | 2167 | #endif |
2121 | if (iif) | 2168 | if (iif) { |
2122 | NLA_PUT_U32(skb, RTA_IIF, iif); | 2169 | #ifdef CONFIG_IPV6_MROUTE |
2123 | else if (dst) { | 2170 | if (ipv6_addr_is_multicast(&rt->rt6i_dst.addr)) { |
2171 | int err = ip6mr_get_route(skb, rtm, nowait); | ||
2172 | if (err <= 0) { | ||
2173 | if (!nowait) { | ||
2174 | if (err == 0) | ||
2175 | return 0; | ||
2176 | goto nla_put_failure; | ||
2177 | } else { | ||
2178 | if (err == -EMSGSIZE) | ||
2179 | goto nla_put_failure; | ||
2180 | } | ||
2181 | } | ||
2182 | } else | ||
2183 | #endif | ||
2184 | NLA_PUT_U32(skb, RTA_IIF, iif); | ||
2185 | } else if (dst) { | ||
2124 | struct in6_addr saddr_buf; | 2186 | struct in6_addr saddr_buf; |
2125 | if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0) | 2187 | if (ipv6_dev_get_saddr(ip6_dst_idev(&rt->u.dst)->dev, |
2188 | dst, 0, &saddr_buf) == 0) | ||
2126 | NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf); | 2189 | NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf); |
2127 | } | 2190 | } |
2128 | 2191 | ||
@@ -2162,12 +2225,12 @@ int rt6_dump_route(struct rt6_info *rt, void *p_arg) | |||
2162 | 2225 | ||
2163 | return rt6_fill_node(arg->skb, rt, NULL, NULL, 0, RTM_NEWROUTE, | 2226 | return rt6_fill_node(arg->skb, rt, NULL, NULL, 0, RTM_NEWROUTE, |
2164 | NETLINK_CB(arg->cb->skb).pid, arg->cb->nlh->nlmsg_seq, | 2227 | NETLINK_CB(arg->cb->skb).pid, arg->cb->nlh->nlmsg_seq, |
2165 | prefix, NLM_F_MULTI); | 2228 | prefix, 0, NLM_F_MULTI); |
2166 | } | 2229 | } |
2167 | 2230 | ||
2168 | static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg) | 2231 | static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg) |
2169 | { | 2232 | { |
2170 | struct net *net = in_skb->sk->sk_net; | 2233 | struct net *net = sock_net(in_skb->sk); |
2171 | struct nlattr *tb[RTA_MAX+1]; | 2234 | struct nlattr *tb[RTA_MAX+1]; |
2172 | struct rt6_info *rt; | 2235 | struct rt6_info *rt; |
2173 | struct sk_buff *skb; | 2236 | struct sk_buff *skb; |
@@ -2175,9 +2238,6 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void | |||
2175 | struct flowi fl; | 2238 | struct flowi fl; |
2176 | int err, iif = 0; | 2239 | int err, iif = 0; |
2177 | 2240 | ||
2178 | if (net != &init_net) | ||
2179 | return -EINVAL; | ||
2180 | |||
2181 | err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy); | 2241 | err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy); |
2182 | if (err < 0) | 2242 | if (err < 0) |
2183 | goto errout; | 2243 | goto errout; |
@@ -2207,7 +2267,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void | |||
2207 | 2267 | ||
2208 | if (iif) { | 2268 | if (iif) { |
2209 | struct net_device *dev; | 2269 | struct net_device *dev; |
2210 | dev = __dev_get_by_index(&init_net, iif); | 2270 | dev = __dev_get_by_index(net, iif); |
2211 | if (!dev) { | 2271 | if (!dev) { |
2212 | err = -ENODEV; | 2272 | err = -ENODEV; |
2213 | goto errout; | 2273 | goto errout; |
@@ -2226,18 +2286,18 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void | |||
2226 | skb_reset_mac_header(skb); | 2286 | skb_reset_mac_header(skb); |
2227 | skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr)); | 2287 | skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr)); |
2228 | 2288 | ||
2229 | rt = (struct rt6_info*) ip6_route_output(NULL, &fl); | 2289 | rt = (struct rt6_info*) ip6_route_output(net, NULL, &fl); |
2230 | skb->dst = &rt->u.dst; | 2290 | skb->dst = &rt->u.dst; |
2231 | 2291 | ||
2232 | err = rt6_fill_node(skb, rt, &fl.fl6_dst, &fl.fl6_src, iif, | 2292 | err = rt6_fill_node(skb, rt, &fl.fl6_dst, &fl.fl6_src, iif, |
2233 | RTM_NEWROUTE, NETLINK_CB(in_skb).pid, | 2293 | RTM_NEWROUTE, NETLINK_CB(in_skb).pid, |
2234 | nlh->nlmsg_seq, 0, 0); | 2294 | nlh->nlmsg_seq, 0, 0, 0); |
2235 | if (err < 0) { | 2295 | if (err < 0) { |
2236 | kfree_skb(skb); | 2296 | kfree_skb(skb); |
2237 | goto errout; | 2297 | goto errout; |
2238 | } | 2298 | } |
2239 | 2299 | ||
2240 | err = rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).pid); | 2300 | err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).pid); |
2241 | errout: | 2301 | errout: |
2242 | return err; | 2302 | return err; |
2243 | } | 2303 | } |
@@ -2245,6 +2305,7 @@ errout: | |||
2245 | void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info) | 2305 | void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info) |
2246 | { | 2306 | { |
2247 | struct sk_buff *skb; | 2307 | struct sk_buff *skb; |
2308 | struct net *net = info->nl_net; | ||
2248 | u32 seq; | 2309 | u32 seq; |
2249 | int err; | 2310 | int err; |
2250 | 2311 | ||
@@ -2256,18 +2317,38 @@ void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info) | |||
2256 | goto errout; | 2317 | goto errout; |
2257 | 2318 | ||
2258 | err = rt6_fill_node(skb, rt, NULL, NULL, 0, | 2319 | err = rt6_fill_node(skb, rt, NULL, NULL, 0, |
2259 | event, info->pid, seq, 0, 0); | 2320 | event, info->pid, seq, 0, 0, 0); |
2260 | if (err < 0) { | 2321 | if (err < 0) { |
2261 | /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ | 2322 | /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ |
2262 | WARN_ON(err == -EMSGSIZE); | 2323 | WARN_ON(err == -EMSGSIZE); |
2263 | kfree_skb(skb); | 2324 | kfree_skb(skb); |
2264 | goto errout; | 2325 | goto errout; |
2265 | } | 2326 | } |
2266 | err = rtnl_notify(skb, &init_net, info->pid, | 2327 | err = rtnl_notify(skb, net, info->pid, RTNLGRP_IPV6_ROUTE, |
2267 | RTNLGRP_IPV6_ROUTE, info->nlh, gfp_any()); | 2328 | info->nlh, gfp_any()); |
2268 | errout: | 2329 | errout: |
2269 | if (err < 0) | 2330 | if (err < 0) |
2270 | rtnl_set_sk_err(&init_net, RTNLGRP_IPV6_ROUTE, err); | 2331 | rtnl_set_sk_err(net, RTNLGRP_IPV6_ROUTE, err); |
2332 | } | ||
2333 | |||
2334 | static int ip6_route_dev_notify(struct notifier_block *this, | ||
2335 | unsigned long event, void *data) | ||
2336 | { | ||
2337 | struct net_device *dev = (struct net_device *)data; | ||
2338 | struct net *net = dev_net(dev); | ||
2339 | |||
2340 | if (event == NETDEV_REGISTER && (dev->flags & IFF_LOOPBACK)) { | ||
2341 | net->ipv6.ip6_null_entry->u.dst.dev = dev; | ||
2342 | net->ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(dev); | ||
2343 | #ifdef CONFIG_IPV6_MULTIPLE_TABLES | ||
2344 | net->ipv6.ip6_prohibit_entry->u.dst.dev = dev; | ||
2345 | net->ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(dev); | ||
2346 | net->ipv6.ip6_blk_hole_entry->u.dst.dev = dev; | ||
2347 | net->ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(dev); | ||
2348 | #endif | ||
2349 | } | ||
2350 | |||
2351 | return NOTIFY_OK; | ||
2271 | } | 2352 | } |
2272 | 2353 | ||
2273 | /* | 2354 | /* |
@@ -2316,13 +2397,33 @@ static int rt6_info_route(struct rt6_info *rt, void *p_arg) | |||
2316 | 2397 | ||
2317 | static int ipv6_route_show(struct seq_file *m, void *v) | 2398 | static int ipv6_route_show(struct seq_file *m, void *v) |
2318 | { | 2399 | { |
2319 | fib6_clean_all(rt6_info_route, 0, m); | 2400 | struct net *net = (struct net *)m->private; |
2401 | fib6_clean_all(net, rt6_info_route, 0, m); | ||
2320 | return 0; | 2402 | return 0; |
2321 | } | 2403 | } |
2322 | 2404 | ||
2323 | static int ipv6_route_open(struct inode *inode, struct file *file) | 2405 | static int ipv6_route_open(struct inode *inode, struct file *file) |
2324 | { | 2406 | { |
2325 | return single_open(file, ipv6_route_show, NULL); | 2407 | int err; |
2408 | struct net *net = get_proc_net(inode); | ||
2409 | if (!net) | ||
2410 | return -ENXIO; | ||
2411 | |||
2412 | err = single_open(file, ipv6_route_show, net); | ||
2413 | if (err < 0) { | ||
2414 | put_net(net); | ||
2415 | return err; | ||
2416 | } | ||
2417 | |||
2418 | return 0; | ||
2419 | } | ||
2420 | |||
2421 | static int ipv6_route_release(struct inode *inode, struct file *file) | ||
2422 | { | ||
2423 | struct seq_file *seq = file->private_data; | ||
2424 | struct net *net = seq->private; | ||
2425 | put_net(net); | ||
2426 | return single_release(inode, file); | ||
2326 | } | 2427 | } |
2327 | 2428 | ||
2328 | static const struct file_operations ipv6_route_proc_fops = { | 2429 | static const struct file_operations ipv6_route_proc_fops = { |
@@ -2330,24 +2431,46 @@ static const struct file_operations ipv6_route_proc_fops = { | |||
2330 | .open = ipv6_route_open, | 2431 | .open = ipv6_route_open, |
2331 | .read = seq_read, | 2432 | .read = seq_read, |
2332 | .llseek = seq_lseek, | 2433 | .llseek = seq_lseek, |
2333 | .release = single_release, | 2434 | .release = ipv6_route_release, |
2334 | }; | 2435 | }; |
2335 | 2436 | ||
2336 | static int rt6_stats_seq_show(struct seq_file *seq, void *v) | 2437 | static int rt6_stats_seq_show(struct seq_file *seq, void *v) |
2337 | { | 2438 | { |
2439 | struct net *net = (struct net *)seq->private; | ||
2338 | seq_printf(seq, "%04x %04x %04x %04x %04x %04x %04x\n", | 2440 | seq_printf(seq, "%04x %04x %04x %04x %04x %04x %04x\n", |
2339 | rt6_stats.fib_nodes, rt6_stats.fib_route_nodes, | 2441 | net->ipv6.rt6_stats->fib_nodes, |
2340 | rt6_stats.fib_rt_alloc, rt6_stats.fib_rt_entries, | 2442 | net->ipv6.rt6_stats->fib_route_nodes, |
2341 | rt6_stats.fib_rt_cache, | 2443 | net->ipv6.rt6_stats->fib_rt_alloc, |
2342 | atomic_read(&ip6_dst_ops.entries), | 2444 | net->ipv6.rt6_stats->fib_rt_entries, |
2343 | rt6_stats.fib_discarded_routes); | 2445 | net->ipv6.rt6_stats->fib_rt_cache, |
2446 | atomic_read(&net->ipv6.ip6_dst_ops->entries), | ||
2447 | net->ipv6.rt6_stats->fib_discarded_routes); | ||
2344 | 2448 | ||
2345 | return 0; | 2449 | return 0; |
2346 | } | 2450 | } |
2347 | 2451 | ||
2348 | static int rt6_stats_seq_open(struct inode *inode, struct file *file) | 2452 | static int rt6_stats_seq_open(struct inode *inode, struct file *file) |
2349 | { | 2453 | { |
2350 | return single_open(file, rt6_stats_seq_show, NULL); | 2454 | int err; |
2455 | struct net *net = get_proc_net(inode); | ||
2456 | if (!net) | ||
2457 | return -ENXIO; | ||
2458 | |||
2459 | err = single_open(file, rt6_stats_seq_show, net); | ||
2460 | if (err < 0) { | ||
2461 | put_net(net); | ||
2462 | return err; | ||
2463 | } | ||
2464 | |||
2465 | return 0; | ||
2466 | } | ||
2467 | |||
2468 | static int rt6_stats_seq_release(struct inode *inode, struct file *file) | ||
2469 | { | ||
2470 | struct seq_file *seq = file->private_data; | ||
2471 | struct net *net = (struct net *)seq->private; | ||
2472 | put_net(net); | ||
2473 | return single_release(inode, file); | ||
2351 | } | 2474 | } |
2352 | 2475 | ||
2353 | static const struct file_operations rt6_stats_seq_fops = { | 2476 | static const struct file_operations rt6_stats_seq_fops = { |
@@ -2355,42 +2478,8 @@ static const struct file_operations rt6_stats_seq_fops = { | |||
2355 | .open = rt6_stats_seq_open, | 2478 | .open = rt6_stats_seq_open, |
2356 | .read = seq_read, | 2479 | .read = seq_read, |
2357 | .llseek = seq_lseek, | 2480 | .llseek = seq_lseek, |
2358 | .release = single_release, | 2481 | .release = rt6_stats_seq_release, |
2359 | }; | 2482 | }; |
2360 | |||
2361 | static int ipv6_route_proc_init(struct net *net) | ||
2362 | { | ||
2363 | int ret = -ENOMEM; | ||
2364 | if (!proc_net_fops_create(net, "ipv6_route", | ||
2365 | 0, &ipv6_route_proc_fops)) | ||
2366 | goto out; | ||
2367 | |||
2368 | if (!proc_net_fops_create(net, "rt6_stats", | ||
2369 | S_IRUGO, &rt6_stats_seq_fops)) | ||
2370 | goto out_ipv6_route; | ||
2371 | |||
2372 | ret = 0; | ||
2373 | out: | ||
2374 | return ret; | ||
2375 | out_ipv6_route: | ||
2376 | proc_net_remove(net, "ipv6_route"); | ||
2377 | goto out; | ||
2378 | } | ||
2379 | |||
2380 | static void ipv6_route_proc_fini(struct net *net) | ||
2381 | { | ||
2382 | proc_net_remove(net, "ipv6_route"); | ||
2383 | proc_net_remove(net, "rt6_stats"); | ||
2384 | } | ||
2385 | #else | ||
2386 | static inline int ipv6_route_proc_init(struct net *net) | ||
2387 | { | ||
2388 | return 0; | ||
2389 | } | ||
2390 | static inline void ipv6_route_proc_fini(struct net *net) | ||
2391 | { | ||
2392 | return ; | ||
2393 | } | ||
2394 | #endif /* CONFIG_PROC_FS */ | 2483 | #endif /* CONFIG_PROC_FS */ |
2395 | 2484 | ||
2396 | #ifdef CONFIG_SYSCTL | 2485 | #ifdef CONFIG_SYSCTL |
@@ -2399,10 +2488,11 @@ static | |||
2399 | int ipv6_sysctl_rtcache_flush(ctl_table *ctl, int write, struct file * filp, | 2488 | int ipv6_sysctl_rtcache_flush(ctl_table *ctl, int write, struct file * filp, |
2400 | void __user *buffer, size_t *lenp, loff_t *ppos) | 2489 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2401 | { | 2490 | { |
2402 | int delay = init_net.ipv6.sysctl.flush_delay; | 2491 | struct net *net = current->nsproxy->net_ns; |
2492 | int delay = net->ipv6.sysctl.flush_delay; | ||
2403 | if (write) { | 2493 | if (write) { |
2404 | proc_dointvec(ctl, write, filp, buffer, lenp, ppos); | 2494 | proc_dointvec(ctl, write, filp, buffer, lenp, ppos); |
2405 | fib6_run_gc(delay <= 0 ? ~0UL : (unsigned long)delay); | 2495 | fib6_run_gc(delay <= 0 ? ~0UL : (unsigned long)delay, net); |
2406 | return 0; | 2496 | return 0; |
2407 | } else | 2497 | } else |
2408 | return -EINVAL; | 2498 | return -EINVAL; |
@@ -2419,7 +2509,7 @@ ctl_table ipv6_route_table_template[] = { | |||
2419 | { | 2509 | { |
2420 | .ctl_name = NET_IPV6_ROUTE_GC_THRESH, | 2510 | .ctl_name = NET_IPV6_ROUTE_GC_THRESH, |
2421 | .procname = "gc_thresh", | 2511 | .procname = "gc_thresh", |
2422 | .data = &ip6_dst_ops.gc_thresh, | 2512 | .data = &ip6_dst_ops_template.gc_thresh, |
2423 | .maxlen = sizeof(int), | 2513 | .maxlen = sizeof(int), |
2424 | .mode = 0644, | 2514 | .mode = 0644, |
2425 | .proc_handler = &proc_dointvec, | 2515 | .proc_handler = &proc_dointvec, |
@@ -2505,33 +2595,143 @@ struct ctl_table *ipv6_route_sysctl_init(struct net *net) | |||
2505 | table = kmemdup(ipv6_route_table_template, | 2595 | table = kmemdup(ipv6_route_table_template, |
2506 | sizeof(ipv6_route_table_template), | 2596 | sizeof(ipv6_route_table_template), |
2507 | GFP_KERNEL); | 2597 | GFP_KERNEL); |
2598 | |||
2599 | if (table) { | ||
2600 | table[0].data = &net->ipv6.sysctl.flush_delay; | ||
2601 | table[1].data = &net->ipv6.ip6_dst_ops->gc_thresh; | ||
2602 | table[2].data = &net->ipv6.sysctl.ip6_rt_max_size; | ||
2603 | table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; | ||
2604 | table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout; | ||
2605 | table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval; | ||
2606 | table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity; | ||
2607 | table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires; | ||
2608 | table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; | ||
2609 | } | ||
2610 | |||
2508 | return table; | 2611 | return table; |
2509 | } | 2612 | } |
2510 | #endif | 2613 | #endif |
2511 | 2614 | ||
2615 | static int ip6_route_net_init(struct net *net) | ||
2616 | { | ||
2617 | int ret = 0; | ||
2618 | |||
2619 | ret = -ENOMEM; | ||
2620 | net->ipv6.ip6_dst_ops = kmemdup(&ip6_dst_ops_template, | ||
2621 | sizeof(*net->ipv6.ip6_dst_ops), | ||
2622 | GFP_KERNEL); | ||
2623 | if (!net->ipv6.ip6_dst_ops) | ||
2624 | goto out; | ||
2625 | net->ipv6.ip6_dst_ops->dst_net = hold_net(net); | ||
2626 | |||
2627 | net->ipv6.ip6_null_entry = kmemdup(&ip6_null_entry_template, | ||
2628 | sizeof(*net->ipv6.ip6_null_entry), | ||
2629 | GFP_KERNEL); | ||
2630 | if (!net->ipv6.ip6_null_entry) | ||
2631 | goto out_ip6_dst_ops; | ||
2632 | net->ipv6.ip6_null_entry->u.dst.path = | ||
2633 | (struct dst_entry *)net->ipv6.ip6_null_entry; | ||
2634 | net->ipv6.ip6_null_entry->u.dst.ops = net->ipv6.ip6_dst_ops; | ||
2635 | |||
2636 | #ifdef CONFIG_IPV6_MULTIPLE_TABLES | ||
2637 | net->ipv6.ip6_prohibit_entry = kmemdup(&ip6_prohibit_entry_template, | ||
2638 | sizeof(*net->ipv6.ip6_prohibit_entry), | ||
2639 | GFP_KERNEL); | ||
2640 | if (!net->ipv6.ip6_prohibit_entry) { | ||
2641 | kfree(net->ipv6.ip6_null_entry); | ||
2642 | goto out; | ||
2643 | } | ||
2644 | net->ipv6.ip6_prohibit_entry->u.dst.path = | ||
2645 | (struct dst_entry *)net->ipv6.ip6_prohibit_entry; | ||
2646 | net->ipv6.ip6_prohibit_entry->u.dst.ops = net->ipv6.ip6_dst_ops; | ||
2647 | |||
2648 | net->ipv6.ip6_blk_hole_entry = kmemdup(&ip6_blk_hole_entry_template, | ||
2649 | sizeof(*net->ipv6.ip6_blk_hole_entry), | ||
2650 | GFP_KERNEL); | ||
2651 | if (!net->ipv6.ip6_blk_hole_entry) { | ||
2652 | kfree(net->ipv6.ip6_null_entry); | ||
2653 | kfree(net->ipv6.ip6_prohibit_entry); | ||
2654 | goto out; | ||
2655 | } | ||
2656 | net->ipv6.ip6_blk_hole_entry->u.dst.path = | ||
2657 | (struct dst_entry *)net->ipv6.ip6_blk_hole_entry; | ||
2658 | net->ipv6.ip6_blk_hole_entry->u.dst.ops = net->ipv6.ip6_dst_ops; | ||
2659 | #endif | ||
2660 | |||
2661 | #ifdef CONFIG_PROC_FS | ||
2662 | proc_net_fops_create(net, "ipv6_route", 0, &ipv6_route_proc_fops); | ||
2663 | proc_net_fops_create(net, "rt6_stats", S_IRUGO, &rt6_stats_seq_fops); | ||
2664 | #endif | ||
2665 | net->ipv6.ip6_rt_gc_expire = 30*HZ; | ||
2666 | |||
2667 | ret = 0; | ||
2668 | out: | ||
2669 | return ret; | ||
2670 | |||
2671 | out_ip6_dst_ops: | ||
2672 | release_net(net->ipv6.ip6_dst_ops->dst_net); | ||
2673 | kfree(net->ipv6.ip6_dst_ops); | ||
2674 | goto out; | ||
2675 | } | ||
2676 | |||
2677 | static void ip6_route_net_exit(struct net *net) | ||
2678 | { | ||
2679 | #ifdef CONFIG_PROC_FS | ||
2680 | proc_net_remove(net, "ipv6_route"); | ||
2681 | proc_net_remove(net, "rt6_stats"); | ||
2682 | #endif | ||
2683 | kfree(net->ipv6.ip6_null_entry); | ||
2684 | #ifdef CONFIG_IPV6_MULTIPLE_TABLES | ||
2685 | kfree(net->ipv6.ip6_prohibit_entry); | ||
2686 | kfree(net->ipv6.ip6_blk_hole_entry); | ||
2687 | #endif | ||
2688 | release_net(net->ipv6.ip6_dst_ops->dst_net); | ||
2689 | kfree(net->ipv6.ip6_dst_ops); | ||
2690 | } | ||
2691 | |||
2692 | static struct pernet_operations ip6_route_net_ops = { | ||
2693 | .init = ip6_route_net_init, | ||
2694 | .exit = ip6_route_net_exit, | ||
2695 | }; | ||
2696 | |||
2697 | static struct notifier_block ip6_route_dev_notifier = { | ||
2698 | .notifier_call = ip6_route_dev_notify, | ||
2699 | .priority = 0, | ||
2700 | }; | ||
2701 | |||
2512 | int __init ip6_route_init(void) | 2702 | int __init ip6_route_init(void) |
2513 | { | 2703 | { |
2514 | int ret; | 2704 | int ret; |
2515 | 2705 | ||
2516 | ip6_dst_ops.kmem_cachep = | 2706 | ret = -ENOMEM; |
2707 | ip6_dst_ops_template.kmem_cachep = | ||
2517 | kmem_cache_create("ip6_dst_cache", sizeof(struct rt6_info), 0, | 2708 | kmem_cache_create("ip6_dst_cache", sizeof(struct rt6_info), 0, |
2518 | SLAB_HWCACHE_ALIGN, NULL); | 2709 | SLAB_HWCACHE_ALIGN, NULL); |
2519 | if (!ip6_dst_ops.kmem_cachep) | 2710 | if (!ip6_dst_ops_template.kmem_cachep) |
2520 | return -ENOMEM; | 2711 | goto out;; |
2521 | |||
2522 | ip6_dst_blackhole_ops.kmem_cachep = ip6_dst_ops.kmem_cachep; | ||
2523 | 2712 | ||
2524 | ret = fib6_init(); | 2713 | ret = register_pernet_subsys(&ip6_route_net_ops); |
2525 | if (ret) | 2714 | if (ret) |
2526 | goto out_kmem_cache; | 2715 | goto out_kmem_cache; |
2527 | 2716 | ||
2528 | ret = ipv6_route_proc_init(&init_net); | 2717 | /* Registering of the loopback is done before this portion of code, |
2718 | * the loopback reference in rt6_info will not be taken, do it | ||
2719 | * manually for init_net */ | ||
2720 | init_net.ipv6.ip6_null_entry->u.dst.dev = init_net.loopback_dev; | ||
2721 | init_net.ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); | ||
2722 | #ifdef CONFIG_IPV6_MULTIPLE_TABLES | ||
2723 | init_net.ipv6.ip6_prohibit_entry->u.dst.dev = init_net.loopback_dev; | ||
2724 | init_net.ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); | ||
2725 | init_net.ipv6.ip6_blk_hole_entry->u.dst.dev = init_net.loopback_dev; | ||
2726 | init_net.ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); | ||
2727 | #endif | ||
2728 | ret = fib6_init(); | ||
2529 | if (ret) | 2729 | if (ret) |
2530 | goto out_fib6_init; | 2730 | goto out_register_subsys; |
2531 | 2731 | ||
2532 | ret = xfrm6_init(); | 2732 | ret = xfrm6_init(); |
2533 | if (ret) | 2733 | if (ret) |
2534 | goto out_proc_init; | 2734 | goto out_fib6_init; |
2535 | 2735 | ||
2536 | ret = fib6_rules_init(); | 2736 | ret = fib6_rules_init(); |
2537 | if (ret) | 2737 | if (ret) |
@@ -2543,7 +2743,10 @@ int __init ip6_route_init(void) | |||
2543 | __rtnl_register(PF_INET6, RTM_GETROUTE, inet6_rtm_getroute, NULL)) | 2743 | __rtnl_register(PF_INET6, RTM_GETROUTE, inet6_rtm_getroute, NULL)) |
2544 | goto fib6_rules_init; | 2744 | goto fib6_rules_init; |
2545 | 2745 | ||
2546 | ret = 0; | 2746 | ret = register_netdevice_notifier(&ip6_route_dev_notifier); |
2747 | if (ret) | ||
2748 | goto fib6_rules_init; | ||
2749 | |||
2547 | out: | 2750 | out: |
2548 | return ret; | 2751 | return ret; |
2549 | 2752 | ||
@@ -2551,22 +2754,21 @@ fib6_rules_init: | |||
2551 | fib6_rules_cleanup(); | 2754 | fib6_rules_cleanup(); |
2552 | xfrm6_init: | 2755 | xfrm6_init: |
2553 | xfrm6_fini(); | 2756 | xfrm6_fini(); |
2554 | out_proc_init: | ||
2555 | ipv6_route_proc_fini(&init_net); | ||
2556 | out_fib6_init: | 2757 | out_fib6_init: |
2557 | rt6_ifdown(NULL); | ||
2558 | fib6_gc_cleanup(); | 2758 | fib6_gc_cleanup(); |
2759 | out_register_subsys: | ||
2760 | unregister_pernet_subsys(&ip6_route_net_ops); | ||
2559 | out_kmem_cache: | 2761 | out_kmem_cache: |
2560 | kmem_cache_destroy(ip6_dst_ops.kmem_cachep); | 2762 | kmem_cache_destroy(ip6_dst_ops_template.kmem_cachep); |
2561 | goto out; | 2763 | goto out; |
2562 | } | 2764 | } |
2563 | 2765 | ||
2564 | void ip6_route_cleanup(void) | 2766 | void ip6_route_cleanup(void) |
2565 | { | 2767 | { |
2768 | unregister_netdevice_notifier(&ip6_route_dev_notifier); | ||
2566 | fib6_rules_cleanup(); | 2769 | fib6_rules_cleanup(); |
2567 | ipv6_route_proc_fini(&init_net); | ||
2568 | xfrm6_fini(); | 2770 | xfrm6_fini(); |
2569 | rt6_ifdown(NULL); | ||
2570 | fib6_gc_cleanup(); | 2771 | fib6_gc_cleanup(); |
2571 | kmem_cache_destroy(ip6_dst_ops.kmem_cachep); | 2772 | unregister_pernet_subsys(&ip6_route_net_ops); |
2773 | kmem_cache_destroy(ip6_dst_ops_template.kmem_cachep); | ||
2572 | } | 2774 | } |