2 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * $Id: route.c,v 1.56 2001/10/31 21:55:55 davem Exp $
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
18 * YOSHIFUJI Hideaki @USAGI
19 * reworked default router selection.
20 * - respect outgoing interface
21 * - select from (probably) reachable routers (i.e.
22 * routers in REACHABLE, STALE, DELAY or PROBE states).
23 * - always select the same router if it is (probably)
24 * reachable. otherwise, round-robin the list.
26 * Fixed routing subtrees.
29 #include <linux/capability.h>
30 #include <linux/errno.h>
31 #include <linux/types.h>
32 #include <linux/times.h>
33 #include <linux/socket.h>
34 #include <linux/sockios.h>
35 #include <linux/net.h>
36 #include <linux/route.h>
37 #include <linux/netdevice.h>
38 #include <linux/in6.h>
39 #include <linux/init.h>
40 #include <linux/if_arp.h>
43 #include <linux/proc_fs.h>
44 #include <linux/seq_file.h>
47 #include <net/net_namespace.h>
50 #include <net/ip6_fib.h>
51 #include <net/ip6_route.h>
52 #include <net/ndisc.h>
53 #include <net/addrconf.h>
55 #include <linux/rtnetlink.h>
58 #include <net/netevent.h>
59 #include <net/netlink.h>
61 #include <asm/uaccess.h>
64 #include <linux/sysctl.h>
67 /* Set to 3 to get tracing. */
71 #define RDBG(x) printk x
72 #define RT6_TRACE(x...) printk(KERN_DEBUG x)
75 #define RT6_TRACE(x...) do { ; } while (0)
78 #define CLONE_OFFLINK_ROUTE 0
80 static int ip6_rt_max_size = 4096;
81 static int ip6_rt_gc_min_interval = HZ / 2;
82 static int ip6_rt_gc_timeout = 60*HZ;
83 int ip6_rt_gc_interval = 30*HZ;
84 static int ip6_rt_gc_elasticity = 9;
85 static int ip6_rt_mtu_expires = 10*60*HZ;
86 static int ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40;
88 static struct rt6_info * ip6_rt_copy(struct rt6_info *ort);
89 static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie);
90 static struct dst_entry *ip6_negative_advice(struct dst_entry *);
91 static void ip6_dst_destroy(struct dst_entry *);
92 static void ip6_dst_ifdown(struct dst_entry *,
93 struct net_device *dev, int how);
94 static int ip6_dst_gc(void);
96 static int ip6_pkt_discard(struct sk_buff *skb);
97 static int ip6_pkt_discard_out(struct sk_buff *skb);
98 static void ip6_link_failure(struct sk_buff *skb);
99 static void ip6_rt_update_pmtu(struct dst_entry *dst, u32 mtu);
101 #ifdef CONFIG_IPV6_ROUTE_INFO
102 static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixlen,
103 struct in6_addr *gwaddr, int ifindex,
105 static struct rt6_info *rt6_get_route_info(struct in6_addr *prefix, int prefixlen,
106 struct in6_addr *gwaddr, int ifindex);
109 static struct dst_ops ip6_dst_ops = {
111 .protocol = __constant_htons(ETH_P_IPV6),
114 .check = ip6_dst_check,
115 .destroy = ip6_dst_destroy,
116 .ifdown = ip6_dst_ifdown,
117 .negative_advice = ip6_negative_advice,
118 .link_failure = ip6_link_failure,
119 .update_pmtu = ip6_rt_update_pmtu,
120 .entry_size = sizeof(struct rt6_info),
123 static void ip6_rt_blackhole_update_pmtu(struct dst_entry *dst, u32 mtu)
127 static struct dst_ops ip6_dst_blackhole_ops = {
129 .protocol = __constant_htons(ETH_P_IPV6),
130 .destroy = ip6_dst_destroy,
131 .check = ip6_dst_check,
132 .update_pmtu = ip6_rt_blackhole_update_pmtu,
133 .entry_size = sizeof(struct rt6_info),
136 struct rt6_info ip6_null_entry = {
139 .__refcnt = ATOMIC_INIT(1),
141 .dev = &loopback_dev,
143 .error = -ENETUNREACH,
144 .metrics = { [RTAX_HOPLIMIT - 1] = 255, },
145 .input = ip6_pkt_discard,
146 .output = ip6_pkt_discard_out,
148 .path = (struct dst_entry*)&ip6_null_entry,
151 .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP),
152 .rt6i_metric = ~(u32) 0,
153 .rt6i_ref = ATOMIC_INIT(1),
156 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
158 static int ip6_pkt_prohibit(struct sk_buff *skb);
159 static int ip6_pkt_prohibit_out(struct sk_buff *skb);
160 static int ip6_pkt_blk_hole(struct sk_buff *skb);
162 struct rt6_info ip6_prohibit_entry = {
165 .__refcnt = ATOMIC_INIT(1),
167 .dev = &loopback_dev,
170 .metrics = { [RTAX_HOPLIMIT - 1] = 255, },
171 .input = ip6_pkt_prohibit,
172 .output = ip6_pkt_prohibit_out,
174 .path = (struct dst_entry*)&ip6_prohibit_entry,
177 .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP),
178 .rt6i_metric = ~(u32) 0,
179 .rt6i_ref = ATOMIC_INIT(1),
182 struct rt6_info ip6_blk_hole_entry = {
185 .__refcnt = ATOMIC_INIT(1),
187 .dev = &loopback_dev,
190 .metrics = { [RTAX_HOPLIMIT - 1] = 255, },
191 .input = ip6_pkt_blk_hole,
192 .output = ip6_pkt_blk_hole,
194 .path = (struct dst_entry*)&ip6_blk_hole_entry,
197 .rt6i_flags = (RTF_REJECT | RTF_NONEXTHOP),
198 .rt6i_metric = ~(u32) 0,
199 .rt6i_ref = ATOMIC_INIT(1),
204 /* allocate dst with ip6_dst_ops */
205 static __inline__ struct rt6_info *ip6_dst_alloc(void)
207 return (struct rt6_info *)dst_alloc(&ip6_dst_ops);
210 static void ip6_dst_destroy(struct dst_entry *dst)
212 struct rt6_info *rt = (struct rt6_info *)dst;
213 struct inet6_dev *idev = rt->rt6i_idev;
216 rt->rt6i_idev = NULL;
221 static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
224 struct rt6_info *rt = (struct rt6_info *)dst;
225 struct inet6_dev *idev = rt->rt6i_idev;
227 if (dev != &loopback_dev && idev != NULL && idev->dev == dev) {
228 struct inet6_dev *loopback_idev = in6_dev_get(&loopback_dev);
229 if (loopback_idev != NULL) {
230 rt->rt6i_idev = loopback_idev;
236 static __inline__ int rt6_check_expired(const struct rt6_info *rt)
238 return (rt->rt6i_flags & RTF_EXPIRES &&
239 time_after(jiffies, rt->rt6i_expires));
242 static inline int rt6_need_strict(struct in6_addr *daddr)
244 return (ipv6_addr_type(daddr) &
245 (IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL));
249 * Route lookup. Any table->tb6_lock is implied.
252 static __inline__ struct rt6_info *rt6_device_match(struct rt6_info *rt,
256 struct rt6_info *local = NULL;
257 struct rt6_info *sprt;
260 for (sprt = rt; sprt; sprt = sprt->u.dst.rt6_next) {
261 struct net_device *dev = sprt->rt6i_dev;
262 if (dev->ifindex == oif)
264 if (dev->flags & IFF_LOOPBACK) {
265 if (sprt->rt6i_idev == NULL ||
266 sprt->rt6i_idev->dev->ifindex != oif) {
269 if (local && (!oif ||
270 local->rt6i_idev->dev->ifindex == oif))
281 return &ip6_null_entry;
286 #ifdef CONFIG_IPV6_ROUTER_PREF
287 static void rt6_probe(struct rt6_info *rt)
289 struct neighbour *neigh = rt ? rt->rt6i_nexthop : NULL;
291 * Okay, this does not seem to be appropriate
292 * for now, however, we need to check if it
293 * is really so; aka Router Reachability Probing.
295 * Router Reachability Probe MUST be rate-limited
296 * to no more than one per minute.
298 if (!neigh || (neigh->nud_state & NUD_VALID))
300 read_lock_bh(&neigh->lock);
301 if (!(neigh->nud_state & NUD_VALID) &&
302 time_after(jiffies, neigh->updated + rt->rt6i_idev->cnf.rtr_probe_interval)) {
303 struct in6_addr mcaddr;
304 struct in6_addr *target;
306 neigh->updated = jiffies;
307 read_unlock_bh(&neigh->lock);
309 target = (struct in6_addr *)&neigh->primary_key;
310 addrconf_addr_solict_mult(target, &mcaddr);
311 ndisc_send_ns(rt->rt6i_dev, NULL, target, &mcaddr, NULL);
313 read_unlock_bh(&neigh->lock);
316 static inline void rt6_probe(struct rt6_info *rt)
323 * Default Router Selection (RFC 2461 6.3.6)
325 static inline int rt6_check_dev(struct rt6_info *rt, int oif)
327 struct net_device *dev = rt->rt6i_dev;
328 if (!oif || dev->ifindex == oif)
330 if ((dev->flags & IFF_LOOPBACK) &&
331 rt->rt6i_idev && rt->rt6i_idev->dev->ifindex == oif)
336 static inline int rt6_check_neigh(struct rt6_info *rt)
338 struct neighbour *neigh = rt->rt6i_nexthop;
340 if (rt->rt6i_flags & RTF_NONEXTHOP ||
341 !(rt->rt6i_flags & RTF_GATEWAY))
344 read_lock_bh(&neigh->lock);
345 if (neigh->nud_state & NUD_VALID)
347 else if (!(neigh->nud_state & NUD_FAILED))
349 read_unlock_bh(&neigh->lock);
354 static int rt6_score_route(struct rt6_info *rt, int oif,
359 m = rt6_check_dev(rt, oif);
360 if (!m && (strict & RT6_LOOKUP_F_IFACE))
362 #ifdef CONFIG_IPV6_ROUTER_PREF
363 m |= IPV6_DECODE_PREF(IPV6_EXTRACT_PREF(rt->rt6i_flags)) << 2;
365 n = rt6_check_neigh(rt);
366 if (!n && (strict & RT6_LOOKUP_F_REACHABLE))
371 static struct rt6_info *find_match(struct rt6_info *rt, int oif, int strict,
372 int *mpri, struct rt6_info *match)
376 if (rt6_check_expired(rt))
379 m = rt6_score_route(rt, oif, strict);
384 if (strict & RT6_LOOKUP_F_REACHABLE)
388 } else if (strict & RT6_LOOKUP_F_REACHABLE) {
396 static struct rt6_info *find_rr_leaf(struct fib6_node *fn,
397 struct rt6_info *rr_head,
398 u32 metric, int oif, int strict)
400 struct rt6_info *rt, *match;
404 for (rt = rr_head; rt && rt->rt6i_metric == metric;
405 rt = rt->u.dst.rt6_next)
406 match = find_match(rt, oif, strict, &mpri, match);
407 for (rt = fn->leaf; rt && rt != rr_head && rt->rt6i_metric == metric;
408 rt = rt->u.dst.rt6_next)
409 match = find_match(rt, oif, strict, &mpri, match);
414 static struct rt6_info *rt6_select(struct fib6_node *fn, int oif, int strict)
416 struct rt6_info *match, *rt0;
418 RT6_TRACE("%s(fn->leaf=%p, oif=%d)\n",
419 __FUNCTION__, fn->leaf, oif);
423 fn->rr_ptr = rt0 = fn->leaf;
425 match = find_rr_leaf(fn, rt0, rt0->rt6i_metric, oif, strict);
428 (strict & RT6_LOOKUP_F_REACHABLE)) {
429 struct rt6_info *next = rt0->u.dst.rt6_next;
431 /* no entries matched; do round-robin */
432 if (!next || next->rt6i_metric != rt0->rt6i_metric)
439 RT6_TRACE("%s() => %p\n",
440 __FUNCTION__, match);
442 return (match ? match : &ip6_null_entry);
445 #ifdef CONFIG_IPV6_ROUTE_INFO
446 int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
447 struct in6_addr *gwaddr)
449 struct route_info *rinfo = (struct route_info *) opt;
450 struct in6_addr prefix_buf, *prefix;
455 if (len < sizeof(struct route_info)) {
459 /* Sanity check for prefix_len and length */
460 if (rinfo->length > 3) {
462 } else if (rinfo->prefix_len > 128) {
464 } else if (rinfo->prefix_len > 64) {
465 if (rinfo->length < 2) {
468 } else if (rinfo->prefix_len > 0) {
469 if (rinfo->length < 1) {
474 pref = rinfo->route_pref;
475 if (pref == ICMPV6_ROUTER_PREF_INVALID)
476 pref = ICMPV6_ROUTER_PREF_MEDIUM;
478 lifetime = ntohl(rinfo->lifetime);
479 if (lifetime == 0xffffffff) {
481 } else if (lifetime > 0x7fffffff/HZ) {
482 /* Avoid arithmetic overflow */
483 lifetime = 0x7fffffff/HZ - 1;
486 if (rinfo->length == 3)
487 prefix = (struct in6_addr *)rinfo->prefix;
489 /* this function is safe */
490 ipv6_addr_prefix(&prefix_buf,
491 (struct in6_addr *)rinfo->prefix,
493 prefix = &prefix_buf;
496 rt = rt6_get_route_info(prefix, rinfo->prefix_len, gwaddr, dev->ifindex);
498 if (rt && !lifetime) {
504 rt = rt6_add_route_info(prefix, rinfo->prefix_len, gwaddr, dev->ifindex,
507 rt->rt6i_flags = RTF_ROUTEINFO |
508 (rt->rt6i_flags & ~RTF_PREF_MASK) | RTF_PREF(pref);
511 if (lifetime == 0xffffffff) {
512 rt->rt6i_flags &= ~RTF_EXPIRES;
514 rt->rt6i_expires = jiffies + HZ * lifetime;
515 rt->rt6i_flags |= RTF_EXPIRES;
517 dst_release(&rt->u.dst);
523 #define BACKTRACK(saddr) \
525 if (rt == &ip6_null_entry) { \
526 struct fib6_node *pn; \
528 if (fn->fn_flags & RTN_TL_ROOT) \
531 if (FIB6_SUBTREE(pn) && FIB6_SUBTREE(pn) != fn) \
532 fn = fib6_lookup(FIB6_SUBTREE(pn), NULL, saddr); \
535 if (fn->fn_flags & RTN_RTINFO) \
541 static struct rt6_info *ip6_pol_route_lookup(struct fib6_table *table,
542 struct flowi *fl, int flags)
544 struct fib6_node *fn;
547 read_lock_bh(&table->tb6_lock);
548 fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src);
551 rt = rt6_device_match(rt, fl->oif, flags);
552 BACKTRACK(&fl->fl6_src);
554 dst_hold(&rt->u.dst);
555 read_unlock_bh(&table->tb6_lock);
557 rt->u.dst.lastuse = jiffies;
564 struct rt6_info *rt6_lookup(struct in6_addr *daddr, struct in6_addr *saddr,
575 struct dst_entry *dst;
576 int flags = strict ? RT6_LOOKUP_F_IFACE : 0;
579 memcpy(&fl.fl6_src, saddr, sizeof(*saddr));
580 flags |= RT6_LOOKUP_F_HAS_SADDR;
583 dst = fib6_rule_lookup(&fl, flags, ip6_pol_route_lookup);
585 return (struct rt6_info *) dst;
592 EXPORT_SYMBOL(rt6_lookup);
594 /* ip6_ins_rt is called with FREE table->tb6_lock.
595 It takes new route entry, the addition fails by any reason the
596 route is freed. In any case, if caller does not hold it, it may
600 static int __ip6_ins_rt(struct rt6_info *rt, struct nl_info *info)
603 struct fib6_table *table;
605 table = rt->rt6i_table;
606 write_lock_bh(&table->tb6_lock);
607 err = fib6_add(&table->tb6_root, rt, info);
608 write_unlock_bh(&table->tb6_lock);
613 int ip6_ins_rt(struct rt6_info *rt)
615 return __ip6_ins_rt(rt, NULL);
618 static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort, struct in6_addr *daddr,
619 struct in6_addr *saddr)
627 rt = ip6_rt_copy(ort);
630 if (!(rt->rt6i_flags&RTF_GATEWAY)) {
631 if (rt->rt6i_dst.plen != 128 &&
632 ipv6_addr_equal(&rt->rt6i_dst.addr, daddr))
633 rt->rt6i_flags |= RTF_ANYCAST;
634 ipv6_addr_copy(&rt->rt6i_gateway, daddr);
637 ipv6_addr_copy(&rt->rt6i_dst.addr, daddr);
638 rt->rt6i_dst.plen = 128;
639 rt->rt6i_flags |= RTF_CACHE;
640 rt->u.dst.flags |= DST_HOST;
642 #ifdef CONFIG_IPV6_SUBTREES
643 if (rt->rt6i_src.plen && saddr) {
644 ipv6_addr_copy(&rt->rt6i_src.addr, saddr);
645 rt->rt6i_src.plen = 128;
649 rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_gateway);
656 static struct rt6_info *rt6_alloc_clone(struct rt6_info *ort, struct in6_addr *daddr)
658 struct rt6_info *rt = ip6_rt_copy(ort);
660 ipv6_addr_copy(&rt->rt6i_dst.addr, daddr);
661 rt->rt6i_dst.plen = 128;
662 rt->rt6i_flags |= RTF_CACHE;
663 rt->u.dst.flags |= DST_HOST;
664 rt->rt6i_nexthop = neigh_clone(ort->rt6i_nexthop);
669 static struct rt6_info *ip6_pol_route_input(struct fib6_table *table,
670 struct flowi *fl, int flags)
672 struct fib6_node *fn;
673 struct rt6_info *rt, *nrt;
677 int reachable = ipv6_devconf.forwarding ? 0 : RT6_LOOKUP_F_REACHABLE;
679 strict |= flags & RT6_LOOKUP_F_IFACE;
682 read_lock_bh(&table->tb6_lock);
685 fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src);
688 rt = rt6_select(fn, fl->iif, strict | reachable);
689 BACKTRACK(&fl->fl6_src);
690 if (rt == &ip6_null_entry ||
691 rt->rt6i_flags & RTF_CACHE)
694 dst_hold(&rt->u.dst);
695 read_unlock_bh(&table->tb6_lock);
697 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP))
698 nrt = rt6_alloc_cow(rt, &fl->fl6_dst, &fl->fl6_src);
700 #if CLONE_OFFLINK_ROUTE
701 nrt = rt6_alloc_clone(rt, &fl->fl6_dst);
707 dst_release(&rt->u.dst);
708 rt = nrt ? : &ip6_null_entry;
710 dst_hold(&rt->u.dst);
712 err = ip6_ins_rt(nrt);
721 * Race condition! In the gap, when table->tb6_lock was
722 * released someone could insert this route. Relookup.
724 dst_release(&rt->u.dst);
732 dst_hold(&rt->u.dst);
733 read_unlock_bh(&table->tb6_lock);
735 rt->u.dst.lastuse = jiffies;
741 void ip6_route_input(struct sk_buff *skb)
743 struct ipv6hdr *iph = ipv6_hdr(skb);
744 int flags = RT6_LOOKUP_F_HAS_SADDR;
746 .iif = skb->dev->ifindex,
751 .flowlabel = (* (__be32 *) iph)&IPV6_FLOWINFO_MASK,
755 .proto = iph->nexthdr,
758 if (rt6_need_strict(&iph->daddr))
759 flags |= RT6_LOOKUP_F_IFACE;
761 skb->dst = fib6_rule_lookup(&fl, flags, ip6_pol_route_input);
764 static struct rt6_info *ip6_pol_route_output(struct fib6_table *table,
765 struct flowi *fl, int flags)
767 struct fib6_node *fn;
768 struct rt6_info *rt, *nrt;
772 int reachable = ipv6_devconf.forwarding ? 0 : RT6_LOOKUP_F_REACHABLE;
774 strict |= flags & RT6_LOOKUP_F_IFACE;
777 read_lock_bh(&table->tb6_lock);
780 fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src);
783 rt = rt6_select(fn, fl->oif, strict | reachable);
784 BACKTRACK(&fl->fl6_src);
785 if (rt == &ip6_null_entry ||
786 rt->rt6i_flags & RTF_CACHE)
789 dst_hold(&rt->u.dst);
790 read_unlock_bh(&table->tb6_lock);
792 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP))
793 nrt = rt6_alloc_cow(rt, &fl->fl6_dst, &fl->fl6_src);
795 #if CLONE_OFFLINK_ROUTE
796 nrt = rt6_alloc_clone(rt, &fl->fl6_dst);
802 dst_release(&rt->u.dst);
803 rt = nrt ? : &ip6_null_entry;
805 dst_hold(&rt->u.dst);
807 err = ip6_ins_rt(nrt);
816 * Race condition! In the gap, when table->tb6_lock was
817 * released someone could insert this route. Relookup.
819 dst_release(&rt->u.dst);
827 dst_hold(&rt->u.dst);
828 read_unlock_bh(&table->tb6_lock);
830 rt->u.dst.lastuse = jiffies;
835 struct dst_entry * ip6_route_output(struct sock *sk, struct flowi *fl)
839 if (rt6_need_strict(&fl->fl6_dst))
840 flags |= RT6_LOOKUP_F_IFACE;
842 if (!ipv6_addr_any(&fl->fl6_src))
843 flags |= RT6_LOOKUP_F_HAS_SADDR;
845 return fib6_rule_lookup(fl, flags, ip6_pol_route_output);
848 EXPORT_SYMBOL(ip6_route_output);
850 static int ip6_blackhole_output(struct sk_buff *skb)
856 int ip6_dst_blackhole(struct sock *sk, struct dst_entry **dstp, struct flowi *fl)
858 struct rt6_info *ort = (struct rt6_info *) *dstp;
859 struct rt6_info *rt = (struct rt6_info *)
860 dst_alloc(&ip6_dst_blackhole_ops);
861 struct dst_entry *new = NULL;
866 atomic_set(&new->__refcnt, 1);
868 new->input = ip6_blackhole_output;
869 new->output = ip6_blackhole_output;
871 memcpy(new->metrics, ort->u.dst.metrics, RTAX_MAX*sizeof(u32));
872 new->dev = ort->u.dst.dev;
875 rt->rt6i_idev = ort->rt6i_idev;
877 in6_dev_hold(rt->rt6i_idev);
878 rt->rt6i_expires = 0;
880 ipv6_addr_copy(&rt->rt6i_gateway, &ort->rt6i_gateway);
881 rt->rt6i_flags = ort->rt6i_flags & ~RTF_EXPIRES;
884 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key));
885 #ifdef CONFIG_IPV6_SUBTREES
886 memcpy(&rt->rt6i_src, &ort->rt6i_src, sizeof(struct rt6key));
894 return (new ? 0 : -ENOMEM);
896 EXPORT_SYMBOL_GPL(ip6_dst_blackhole);
899 * Destination cache support functions
902 static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie)
906 rt = (struct rt6_info *) dst;
908 if (rt && rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie))
914 static struct dst_entry *ip6_negative_advice(struct dst_entry *dst)
916 struct rt6_info *rt = (struct rt6_info *) dst;
919 if (rt->rt6i_flags & RTF_CACHE)
927 static void ip6_link_failure(struct sk_buff *skb)
931 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_ADDR_UNREACH, 0, skb->dev);
933 rt = (struct rt6_info *) skb->dst;
935 if (rt->rt6i_flags&RTF_CACHE) {
936 dst_set_expires(&rt->u.dst, 0);
937 rt->rt6i_flags |= RTF_EXPIRES;
938 } else if (rt->rt6i_node && (rt->rt6i_flags & RTF_DEFAULT))
939 rt->rt6i_node->fn_sernum = -1;
943 static void ip6_rt_update_pmtu(struct dst_entry *dst, u32 mtu)
945 struct rt6_info *rt6 = (struct rt6_info*)dst;
947 if (mtu < dst_mtu(dst) && rt6->rt6i_dst.plen == 128) {
948 rt6->rt6i_flags |= RTF_MODIFIED;
949 if (mtu < IPV6_MIN_MTU) {
951 dst->metrics[RTAX_FEATURES-1] |= RTAX_FEATURE_ALLFRAG;
953 dst->metrics[RTAX_MTU-1] = mtu;
954 call_netevent_notifiers(NETEVENT_PMTU_UPDATE, dst);
958 static int ipv6_get_mtu(struct net_device *dev);
960 static inline unsigned int ipv6_advmss(unsigned int mtu)
962 mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr);
964 if (mtu < ip6_rt_min_advmss)
965 mtu = ip6_rt_min_advmss;
968 * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and
969 * corresponding MSS is IPV6_MAXPLEN - tcp_header_size.
970 * IPV6_MAXPLEN is also valid and means: "any MSS,
971 * rely only on pmtu discovery"
973 if (mtu > IPV6_MAXPLEN - sizeof(struct tcphdr))
978 static struct dst_entry *ndisc_dst_gc_list;
979 static DEFINE_SPINLOCK(ndisc_lock);
981 struct dst_entry *ndisc_dst_alloc(struct net_device *dev,
982 struct neighbour *neigh,
983 struct in6_addr *addr,
984 int (*output)(struct sk_buff *))
987 struct inet6_dev *idev = in6_dev_get(dev);
989 if (unlikely(idev == NULL))
992 rt = ip6_dst_alloc();
993 if (unlikely(rt == NULL)) {
1002 neigh = ndisc_get_neigh(dev, addr);
1005 rt->rt6i_idev = idev;
1006 rt->rt6i_nexthop = neigh;
1007 atomic_set(&rt->u.dst.__refcnt, 1);
1008 rt->u.dst.metrics[RTAX_HOPLIMIT-1] = 255;
1009 rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(rt->rt6i_dev);
1010 rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&rt->u.dst));
1011 rt->u.dst.output = output;
1013 #if 0 /* there's no chance to use these for ndisc */
1014 rt->u.dst.flags = ipv6_addr_type(addr) & IPV6_ADDR_UNICAST
1017 ipv6_addr_copy(&rt->rt6i_dst.addr, addr);
1018 rt->rt6i_dst.plen = 128;
1021 spin_lock_bh(&ndisc_lock);
1022 rt->u.dst.next = ndisc_dst_gc_list;
1023 ndisc_dst_gc_list = &rt->u.dst;
1024 spin_unlock_bh(&ndisc_lock);
1026 fib6_force_start_gc();
1032 int ndisc_dst_gc(int *more)
1034 struct dst_entry *dst, *next, **pprev;
1040 spin_lock_bh(&ndisc_lock);
1041 pprev = &ndisc_dst_gc_list;
1043 while ((dst = *pprev) != NULL) {
1044 if (!atomic_read(&dst->__refcnt)) {
1054 spin_unlock_bh(&ndisc_lock);
1059 static int ip6_dst_gc(void)
1061 static unsigned expire = 30*HZ;
1062 static unsigned long last_gc;
1063 unsigned long now = jiffies;
1065 if (time_after(last_gc + ip6_rt_gc_min_interval, now) &&
1066 atomic_read(&ip6_dst_ops.entries) <= ip6_rt_max_size)
1070 fib6_run_gc(expire);
1072 if (atomic_read(&ip6_dst_ops.entries) < ip6_dst_ops.gc_thresh)
1073 expire = ip6_rt_gc_timeout>>1;
1076 expire -= expire>>ip6_rt_gc_elasticity;
1077 return (atomic_read(&ip6_dst_ops.entries) > ip6_rt_max_size);
1080 /* Clean host part of a prefix. Not necessary in radix tree,
1081 but results in cleaner routing tables.
1083 Remove it only when all the things will work!
1086 static int ipv6_get_mtu(struct net_device *dev)
1088 int mtu = IPV6_MIN_MTU;
1089 struct inet6_dev *idev;
1091 idev = in6_dev_get(dev);
1093 mtu = idev->cnf.mtu6;
1099 int ipv6_get_hoplimit(struct net_device *dev)
1101 int hoplimit = ipv6_devconf.hop_limit;
1102 struct inet6_dev *idev;
1104 idev = in6_dev_get(dev);
1106 hoplimit = idev->cnf.hop_limit;
1116 int ip6_route_add(struct fib6_config *cfg)
1119 struct rt6_info *rt = NULL;
1120 struct net_device *dev = NULL;
1121 struct inet6_dev *idev = NULL;
1122 struct fib6_table *table;
1125 if (cfg->fc_dst_len > 128 || cfg->fc_src_len > 128)
1127 #ifndef CONFIG_IPV6_SUBTREES
1128 if (cfg->fc_src_len)
1131 if (cfg->fc_ifindex) {
1133 dev = dev_get_by_index(&init_net, cfg->fc_ifindex);
1136 idev = in6_dev_get(dev);
1141 if (cfg->fc_metric == 0)
1142 cfg->fc_metric = IP6_RT_PRIO_USER;
1144 table = fib6_new_table(cfg->fc_table);
1145 if (table == NULL) {
1150 rt = ip6_dst_alloc();
1157 rt->u.dst.obsolete = -1;
1158 rt->rt6i_expires = jiffies + clock_t_to_jiffies(cfg->fc_expires);
1160 if (cfg->fc_protocol == RTPROT_UNSPEC)
1161 cfg->fc_protocol = RTPROT_BOOT;
1162 rt->rt6i_protocol = cfg->fc_protocol;
1164 addr_type = ipv6_addr_type(&cfg->fc_dst);
1166 if (addr_type & IPV6_ADDR_MULTICAST)
1167 rt->u.dst.input = ip6_mc_input;
1169 rt->u.dst.input = ip6_forward;
1171 rt->u.dst.output = ip6_output;
1173 ipv6_addr_prefix(&rt->rt6i_dst.addr, &cfg->fc_dst, cfg->fc_dst_len);
1174 rt->rt6i_dst.plen = cfg->fc_dst_len;
1175 if (rt->rt6i_dst.plen == 128)
1176 rt->u.dst.flags = DST_HOST;
1178 #ifdef CONFIG_IPV6_SUBTREES
1179 ipv6_addr_prefix(&rt->rt6i_src.addr, &cfg->fc_src, cfg->fc_src_len);
1180 rt->rt6i_src.plen = cfg->fc_src_len;
1183 rt->rt6i_metric = cfg->fc_metric;
1185 /* We cannot add true routes via loopback here,
1186 they would result in kernel looping; promote them to reject routes
1188 if ((cfg->fc_flags & RTF_REJECT) ||
1189 (dev && (dev->flags&IFF_LOOPBACK) && !(addr_type&IPV6_ADDR_LOOPBACK))) {
1190 /* hold loopback dev/idev if we haven't done so. */
1191 if (dev != &loopback_dev) {
1196 dev = &loopback_dev;
1198 idev = in6_dev_get(dev);
1204 rt->u.dst.output = ip6_pkt_discard_out;
1205 rt->u.dst.input = ip6_pkt_discard;
1206 rt->u.dst.error = -ENETUNREACH;
1207 rt->rt6i_flags = RTF_REJECT|RTF_NONEXTHOP;
1211 if (cfg->fc_flags & RTF_GATEWAY) {
1212 struct in6_addr *gw_addr;
1215 gw_addr = &cfg->fc_gateway;
1216 ipv6_addr_copy(&rt->rt6i_gateway, gw_addr);
1217 gwa_type = ipv6_addr_type(gw_addr);
1219 if (gwa_type != (IPV6_ADDR_LINKLOCAL|IPV6_ADDR_UNICAST)) {
1220 struct rt6_info *grt;
1222 /* IPv6 strictly inhibits using not link-local
1223 addresses as nexthop address.
1224 Otherwise, router will not able to send redirects.
1225 It is very good, but in some (rare!) circumstances
1226 (SIT, PtP, NBMA NOARP links) it is handy to allow
1227 some exceptions. --ANK
1230 if (!(gwa_type&IPV6_ADDR_UNICAST))
1233 grt = rt6_lookup(gw_addr, NULL, cfg->fc_ifindex, 1);
1235 err = -EHOSTUNREACH;
1239 if (dev != grt->rt6i_dev) {
1240 dst_release(&grt->u.dst);
1244 dev = grt->rt6i_dev;
1245 idev = grt->rt6i_idev;
1247 in6_dev_hold(grt->rt6i_idev);
1249 if (!(grt->rt6i_flags&RTF_GATEWAY))
1251 dst_release(&grt->u.dst);
1257 if (dev == NULL || (dev->flags&IFF_LOOPBACK))
1265 if (cfg->fc_flags & (RTF_GATEWAY | RTF_NONEXTHOP)) {
1266 rt->rt6i_nexthop = __neigh_lookup_errno(&nd_tbl, &rt->rt6i_gateway, dev);
1267 if (IS_ERR(rt->rt6i_nexthop)) {
1268 err = PTR_ERR(rt->rt6i_nexthop);
1269 rt->rt6i_nexthop = NULL;
1274 rt->rt6i_flags = cfg->fc_flags;
1281 nla_for_each_attr(nla, cfg->fc_mx, cfg->fc_mx_len, remaining) {
1282 int type = nla_type(nla);
1285 if (type > RTAX_MAX) {
1290 rt->u.dst.metrics[type - 1] = nla_get_u32(nla);
1295 if (rt->u.dst.metrics[RTAX_HOPLIMIT-1] == 0)
1296 rt->u.dst.metrics[RTAX_HOPLIMIT-1] = -1;
1297 if (!rt->u.dst.metrics[RTAX_MTU-1])
1298 rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(dev);
1299 if (!rt->u.dst.metrics[RTAX_ADVMSS-1])
1300 rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&rt->u.dst));
1301 rt->u.dst.dev = dev;
1302 rt->rt6i_idev = idev;
1303 rt->rt6i_table = table;
1304 return __ip6_ins_rt(rt, &cfg->fc_nlinfo);
1312 dst_free(&rt->u.dst);
1316 static int __ip6_del_rt(struct rt6_info *rt, struct nl_info *info)
1319 struct fib6_table *table;
1321 if (rt == &ip6_null_entry)
1324 table = rt->rt6i_table;
1325 write_lock_bh(&table->tb6_lock);
1327 err = fib6_del(rt, info);
1328 dst_release(&rt->u.dst);
1330 write_unlock_bh(&table->tb6_lock);
1335 int ip6_del_rt(struct rt6_info *rt)
1337 return __ip6_del_rt(rt, NULL);
1340 static int ip6_route_del(struct fib6_config *cfg)
1342 struct fib6_table *table;
1343 struct fib6_node *fn;
1344 struct rt6_info *rt;
1347 table = fib6_get_table(cfg->fc_table);
1351 read_lock_bh(&table->tb6_lock);
1353 fn = fib6_locate(&table->tb6_root,
1354 &cfg->fc_dst, cfg->fc_dst_len,
1355 &cfg->fc_src, cfg->fc_src_len);
1358 for (rt = fn->leaf; rt; rt = rt->u.dst.rt6_next) {
1359 if (cfg->fc_ifindex &&
1360 (rt->rt6i_dev == NULL ||
1361 rt->rt6i_dev->ifindex != cfg->fc_ifindex))
1363 if (cfg->fc_flags & RTF_GATEWAY &&
1364 !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway))
1366 if (cfg->fc_metric && cfg->fc_metric != rt->rt6i_metric)
1368 dst_hold(&rt->u.dst);
1369 read_unlock_bh(&table->tb6_lock);
1371 return __ip6_del_rt(rt, &cfg->fc_nlinfo);
1374 read_unlock_bh(&table->tb6_lock);
1382 struct ip6rd_flowi {
1384 struct in6_addr gateway;
1387 static struct rt6_info *__ip6_route_redirect(struct fib6_table *table,
1391 struct ip6rd_flowi *rdfl = (struct ip6rd_flowi *)fl;
1392 struct rt6_info *rt;
1393 struct fib6_node *fn;
1396 * Get the "current" route for this destination and
1397 * check if the redirect has come from approriate router.
1399 * RFC 2461 specifies that redirects should only be
1400 * accepted if they come from the nexthop to the target.
1401 * Due to the way the routes are chosen, this notion
1402 * is a bit fuzzy and one might need to check all possible
1406 read_lock_bh(&table->tb6_lock);
1407 fn = fib6_lookup(&table->tb6_root, &fl->fl6_dst, &fl->fl6_src);
1409 for (rt = fn->leaf; rt; rt = rt->u.dst.rt6_next) {
1411 * Current route is on-link; redirect is always invalid.
1413 * Seems, previous statement is not true. It could
1414 * be node, which looks for us as on-link (f.e. proxy ndisc)
1415 * But then router serving it might decide, that we should
1416 * know truth 8)8) --ANK (980726).
1418 if (rt6_check_expired(rt))
1420 if (!(rt->rt6i_flags & RTF_GATEWAY))
1422 if (fl->oif != rt->rt6i_dev->ifindex)
1424 if (!ipv6_addr_equal(&rdfl->gateway, &rt->rt6i_gateway))
1430 rt = &ip6_null_entry;
1431 BACKTRACK(&fl->fl6_src);
1433 dst_hold(&rt->u.dst);
1435 read_unlock_bh(&table->tb6_lock);
1440 static struct rt6_info *ip6_route_redirect(struct in6_addr *dest,
1441 struct in6_addr *src,
1442 struct in6_addr *gateway,
1443 struct net_device *dev)
1445 int flags = RT6_LOOKUP_F_HAS_SADDR;
1446 struct ip6rd_flowi rdfl = {
1448 .oif = dev->ifindex,
1456 .gateway = *gateway,
1459 if (rt6_need_strict(dest))
1460 flags |= RT6_LOOKUP_F_IFACE;
1462 return (struct rt6_info *)fib6_rule_lookup((struct flowi *)&rdfl, flags, __ip6_route_redirect);
1465 void rt6_redirect(struct in6_addr *dest, struct in6_addr *src,
1466 struct in6_addr *saddr,
1467 struct neighbour *neigh, u8 *lladdr, int on_link)
1469 struct rt6_info *rt, *nrt = NULL;
1470 struct netevent_redirect netevent;
1472 rt = ip6_route_redirect(dest, src, saddr, neigh->dev);
1474 if (rt == &ip6_null_entry) {
1475 if (net_ratelimit())
1476 printk(KERN_DEBUG "rt6_redirect: source isn't a valid nexthop "
1477 "for redirect target\n");
1482 * We have finally decided to accept it.
1485 neigh_update(neigh, lladdr, NUD_STALE,
1486 NEIGH_UPDATE_F_WEAK_OVERRIDE|
1487 NEIGH_UPDATE_F_OVERRIDE|
1488 (on_link ? 0 : (NEIGH_UPDATE_F_OVERRIDE_ISROUTER|
1489 NEIGH_UPDATE_F_ISROUTER))
1493 * Redirect received -> path was valid.
1494 * Look, redirects are sent only in response to data packets,
1495 * so that this nexthop apparently is reachable. --ANK
1497 dst_confirm(&rt->u.dst);
1499 /* Duplicate redirect: silently ignore. */
1500 if (neigh == rt->u.dst.neighbour)
1503 nrt = ip6_rt_copy(rt);
1507 nrt->rt6i_flags = RTF_GATEWAY|RTF_UP|RTF_DYNAMIC|RTF_CACHE;
1509 nrt->rt6i_flags &= ~RTF_GATEWAY;
1511 ipv6_addr_copy(&nrt->rt6i_dst.addr, dest);
1512 nrt->rt6i_dst.plen = 128;
1513 nrt->u.dst.flags |= DST_HOST;
1515 ipv6_addr_copy(&nrt->rt6i_gateway, (struct in6_addr*)neigh->primary_key);
1516 nrt->rt6i_nexthop = neigh_clone(neigh);
1517 /* Reset pmtu, it may be better */
1518 nrt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(neigh->dev);
1519 nrt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&nrt->u.dst));
1521 if (ip6_ins_rt(nrt))
1524 netevent.old = &rt->u.dst;
1525 netevent.new = &nrt->u.dst;
1526 call_netevent_notifiers(NETEVENT_REDIRECT, &netevent);
1528 if (rt->rt6i_flags&RTF_CACHE) {
1534 dst_release(&rt->u.dst);
1539 * Handle ICMP "packet too big" messages
1540 * i.e. Path MTU discovery
1543 void rt6_pmtu_discovery(struct in6_addr *daddr, struct in6_addr *saddr,
1544 struct net_device *dev, u32 pmtu)
1546 struct rt6_info *rt, *nrt;
1549 rt = rt6_lookup(daddr, saddr, dev->ifindex, 0);
1553 if (pmtu >= dst_mtu(&rt->u.dst))
1556 if (pmtu < IPV6_MIN_MTU) {
1558 * According to RFC2460, PMTU is set to the IPv6 Minimum Link
1559 * MTU (1280) and a fragment header should always be included
1560 * after a node receiving Too Big message reporting PMTU is
1561 * less than the IPv6 Minimum Link MTU.
1563 pmtu = IPV6_MIN_MTU;
1567 /* New mtu received -> path was valid.
1568 They are sent only in response to data packets,
1569 so that this nexthop apparently is reachable. --ANK
1571 dst_confirm(&rt->u.dst);
1573 /* Host route. If it is static, it would be better
1574 not to override it, but add new one, so that
1575 when cache entry will expire old pmtu
1576 would return automatically.
1578 if (rt->rt6i_flags & RTF_CACHE) {
1579 rt->u.dst.metrics[RTAX_MTU-1] = pmtu;
1581 rt->u.dst.metrics[RTAX_FEATURES-1] |= RTAX_FEATURE_ALLFRAG;
1582 dst_set_expires(&rt->u.dst, ip6_rt_mtu_expires);
1583 rt->rt6i_flags |= RTF_MODIFIED|RTF_EXPIRES;
1588 Two cases are possible:
1589 1. It is connected route. Action: COW
1590 2. It is gatewayed route or NONEXTHOP route. Action: clone it.
1592 if (!rt->rt6i_nexthop && !(rt->rt6i_flags & RTF_NONEXTHOP))
1593 nrt = rt6_alloc_cow(rt, daddr, saddr);
1595 nrt = rt6_alloc_clone(rt, daddr);
1598 nrt->u.dst.metrics[RTAX_MTU-1] = pmtu;
1600 nrt->u.dst.metrics[RTAX_FEATURES-1] |= RTAX_FEATURE_ALLFRAG;
1602 /* According to RFC 1981, detecting PMTU increase shouldn't be
1603 * happened within 5 mins, the recommended timer is 10 mins.
1604 * Here this route expiration time is set to ip6_rt_mtu_expires
1605 * which is 10 mins. After 10 mins the decreased pmtu is expired
1606 * and detecting PMTU increase will be automatically happened.
1608 dst_set_expires(&nrt->u.dst, ip6_rt_mtu_expires);
1609 nrt->rt6i_flags |= RTF_DYNAMIC|RTF_EXPIRES;
1614 dst_release(&rt->u.dst);
1618 * Misc support functions
1621 static struct rt6_info * ip6_rt_copy(struct rt6_info *ort)
1623 struct rt6_info *rt = ip6_dst_alloc();
1626 rt->u.dst.input = ort->u.dst.input;
1627 rt->u.dst.output = ort->u.dst.output;
1629 memcpy(rt->u.dst.metrics, ort->u.dst.metrics, RTAX_MAX*sizeof(u32));
1630 rt->u.dst.error = ort->u.dst.error;
1631 rt->u.dst.dev = ort->u.dst.dev;
1633 dev_hold(rt->u.dst.dev);
1634 rt->rt6i_idev = ort->rt6i_idev;
1636 in6_dev_hold(rt->rt6i_idev);
1637 rt->u.dst.lastuse = jiffies;
1638 rt->rt6i_expires = 0;
1640 ipv6_addr_copy(&rt->rt6i_gateway, &ort->rt6i_gateway);
1641 rt->rt6i_flags = ort->rt6i_flags & ~RTF_EXPIRES;
1642 rt->rt6i_metric = 0;
1644 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key));
1645 #ifdef CONFIG_IPV6_SUBTREES
1646 memcpy(&rt->rt6i_src, &ort->rt6i_src, sizeof(struct rt6key));
1648 rt->rt6i_table = ort->rt6i_table;
1653 #ifdef CONFIG_IPV6_ROUTE_INFO
1654 static struct rt6_info *rt6_get_route_info(struct in6_addr *prefix, int prefixlen,
1655 struct in6_addr *gwaddr, int ifindex)
1657 struct fib6_node *fn;
1658 struct rt6_info *rt = NULL;
1659 struct fib6_table *table;
1661 table = fib6_get_table(RT6_TABLE_INFO);
1665 write_lock_bh(&table->tb6_lock);
1666 fn = fib6_locate(&table->tb6_root, prefix ,prefixlen, NULL, 0);
1670 for (rt = fn->leaf; rt; rt = rt->u.dst.rt6_next) {
1671 if (rt->rt6i_dev->ifindex != ifindex)
1673 if ((rt->rt6i_flags & (RTF_ROUTEINFO|RTF_GATEWAY)) != (RTF_ROUTEINFO|RTF_GATEWAY))
1675 if (!ipv6_addr_equal(&rt->rt6i_gateway, gwaddr))
1677 dst_hold(&rt->u.dst);
1681 write_unlock_bh(&table->tb6_lock);
1685 static struct rt6_info *rt6_add_route_info(struct in6_addr *prefix, int prefixlen,
1686 struct in6_addr *gwaddr, int ifindex,
1689 struct fib6_config cfg = {
1690 .fc_table = RT6_TABLE_INFO,
1692 .fc_ifindex = ifindex,
1693 .fc_dst_len = prefixlen,
1694 .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_ROUTEINFO |
1695 RTF_UP | RTF_PREF(pref),
1698 ipv6_addr_copy(&cfg.fc_dst, prefix);
1699 ipv6_addr_copy(&cfg.fc_gateway, gwaddr);
1701 /* We should treat it as a default route if prefix length is 0. */
1703 cfg.fc_flags |= RTF_DEFAULT;
1705 ip6_route_add(&cfg);
1707 return rt6_get_route_info(prefix, prefixlen, gwaddr, ifindex);
1711 struct rt6_info *rt6_get_dflt_router(struct in6_addr *addr, struct net_device *dev)
1713 struct rt6_info *rt;
1714 struct fib6_table *table;
1716 table = fib6_get_table(RT6_TABLE_DFLT);
1720 write_lock_bh(&table->tb6_lock);
1721 for (rt = table->tb6_root.leaf; rt; rt=rt->u.dst.rt6_next) {
1722 if (dev == rt->rt6i_dev &&
1723 ((rt->rt6i_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) &&
1724 ipv6_addr_equal(&rt->rt6i_gateway, addr))
1728 dst_hold(&rt->u.dst);
1729 write_unlock_bh(&table->tb6_lock);
1733 struct rt6_info *rt6_add_dflt_router(struct in6_addr *gwaddr,
1734 struct net_device *dev,
1737 struct fib6_config cfg = {
1738 .fc_table = RT6_TABLE_DFLT,
1740 .fc_ifindex = dev->ifindex,
1741 .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT |
1742 RTF_UP | RTF_EXPIRES | RTF_PREF(pref),
1745 ipv6_addr_copy(&cfg.fc_gateway, gwaddr);
1747 ip6_route_add(&cfg);
1749 return rt6_get_dflt_router(gwaddr, dev);
1752 void rt6_purge_dflt_routers(void)
1754 struct rt6_info *rt;
1755 struct fib6_table *table;
1757 /* NOTE: Keep consistent with rt6_get_dflt_router */
1758 table = fib6_get_table(RT6_TABLE_DFLT);
1763 read_lock_bh(&table->tb6_lock);
1764 for (rt = table->tb6_root.leaf; rt; rt = rt->u.dst.rt6_next) {
1765 if (rt->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) {
1766 dst_hold(&rt->u.dst);
1767 read_unlock_bh(&table->tb6_lock);
1772 read_unlock_bh(&table->tb6_lock);
1775 static void rtmsg_to_fib6_config(struct in6_rtmsg *rtmsg,
1776 struct fib6_config *cfg)
1778 memset(cfg, 0, sizeof(*cfg));
1780 cfg->fc_table = RT6_TABLE_MAIN;
1781 cfg->fc_ifindex = rtmsg->rtmsg_ifindex;
1782 cfg->fc_metric = rtmsg->rtmsg_metric;
1783 cfg->fc_expires = rtmsg->rtmsg_info;
1784 cfg->fc_dst_len = rtmsg->rtmsg_dst_len;
1785 cfg->fc_src_len = rtmsg->rtmsg_src_len;
1786 cfg->fc_flags = rtmsg->rtmsg_flags;
1788 ipv6_addr_copy(&cfg->fc_dst, &rtmsg->rtmsg_dst);
1789 ipv6_addr_copy(&cfg->fc_src, &rtmsg->rtmsg_src);
1790 ipv6_addr_copy(&cfg->fc_gateway, &rtmsg->rtmsg_gateway);
1793 int ipv6_route_ioctl(unsigned int cmd, void __user *arg)
1795 struct fib6_config cfg;
1796 struct in6_rtmsg rtmsg;
1800 case SIOCADDRT: /* Add a route */
1801 case SIOCDELRT: /* Delete a route */
1802 if (!capable(CAP_NET_ADMIN))
1804 err = copy_from_user(&rtmsg, arg,
1805 sizeof(struct in6_rtmsg));
1809 rtmsg_to_fib6_config(&rtmsg, &cfg);
1814 err = ip6_route_add(&cfg);
1817 err = ip6_route_del(&cfg);
1831 * Drop the packet on the floor
1834 static inline int ip6_pkt_drop(struct sk_buff *skb, int code,
1835 int ipstats_mib_noroutes)
1838 switch (ipstats_mib_noroutes) {
1839 case IPSTATS_MIB_INNOROUTES:
1840 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr);
1841 if (type == IPV6_ADDR_ANY || type == IPV6_ADDR_RESERVED) {
1842 IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INADDRERRORS);
1846 case IPSTATS_MIB_OUTNOROUTES:
1847 IP6_INC_STATS(ip6_dst_idev(skb->dst), ipstats_mib_noroutes);
1850 icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0, skb->dev);
1855 static int ip6_pkt_discard(struct sk_buff *skb)
1857 return ip6_pkt_drop(skb, ICMPV6_NOROUTE, IPSTATS_MIB_INNOROUTES);
1860 static int ip6_pkt_discard_out(struct sk_buff *skb)
1862 skb->dev = skb->dst->dev;
1863 return ip6_pkt_drop(skb, ICMPV6_NOROUTE, IPSTATS_MIB_OUTNOROUTES);
1866 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
1868 static int ip6_pkt_prohibit(struct sk_buff *skb)
1870 return ip6_pkt_drop(skb, ICMPV6_ADM_PROHIBITED, IPSTATS_MIB_INNOROUTES);
1873 static int ip6_pkt_prohibit_out(struct sk_buff *skb)
1875 skb->dev = skb->dst->dev;
1876 return ip6_pkt_drop(skb, ICMPV6_ADM_PROHIBITED, IPSTATS_MIB_OUTNOROUTES);
1879 static int ip6_pkt_blk_hole(struct sk_buff *skb)
1888 * Allocate a dst for local (unicast / anycast) address.
1891 struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
1892 const struct in6_addr *addr,
1895 struct rt6_info *rt = ip6_dst_alloc();
1898 return ERR_PTR(-ENOMEM);
1900 dev_hold(&loopback_dev);
1903 rt->u.dst.flags = DST_HOST;
1904 rt->u.dst.input = ip6_input;
1905 rt->u.dst.output = ip6_output;
1906 rt->rt6i_dev = &loopback_dev;
1907 rt->rt6i_idev = idev;
1908 rt->u.dst.metrics[RTAX_MTU-1] = ipv6_get_mtu(rt->rt6i_dev);
1909 rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(dst_mtu(&rt->u.dst));
1910 rt->u.dst.metrics[RTAX_HOPLIMIT-1] = -1;
1911 rt->u.dst.obsolete = -1;
1913 rt->rt6i_flags = RTF_UP | RTF_NONEXTHOP;
1915 rt->rt6i_flags |= RTF_ANYCAST;
1917 rt->rt6i_flags |= RTF_LOCAL;
1918 rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_gateway);
1919 if (rt->rt6i_nexthop == NULL) {
1920 dst_free(&rt->u.dst);
1921 return ERR_PTR(-ENOMEM);
1924 ipv6_addr_copy(&rt->rt6i_dst.addr, addr);
1925 rt->rt6i_dst.plen = 128;
1926 rt->rt6i_table = fib6_get_table(RT6_TABLE_LOCAL);
1928 atomic_set(&rt->u.dst.__refcnt, 1);
1933 static int fib6_ifdown(struct rt6_info *rt, void *arg)
1935 if (((void*)rt->rt6i_dev == arg || arg == NULL) &&
1936 rt != &ip6_null_entry) {
1937 RT6_TRACE("deleted by ifdown %p\n", rt);
1943 void rt6_ifdown(struct net_device *dev)
1945 fib6_clean_all(fib6_ifdown, 0, dev);
1948 struct rt6_mtu_change_arg
1950 struct net_device *dev;
1954 static int rt6_mtu_change_route(struct rt6_info *rt, void *p_arg)
1956 struct rt6_mtu_change_arg *arg = (struct rt6_mtu_change_arg *) p_arg;
1957 struct inet6_dev *idev;
1959 /* In IPv6 pmtu discovery is not optional,
1960 so that RTAX_MTU lock cannot disable it.
1961 We still use this lock to block changes
1962 caused by addrconf/ndisc.
1965 idev = __in6_dev_get(arg->dev);
1969 /* For administrative MTU increase, there is no way to discover
1970 IPv6 PMTU increase, so PMTU increase should be updated here.
1971 Since RFC 1981 doesn't include administrative MTU increase
1972 update PMTU increase is a MUST. (i.e. jumbo frame)
1975 If new MTU is less than route PMTU, this new MTU will be the
1976 lowest MTU in the path, update the route PMTU to reflect PMTU
1977 decreases; if new MTU is greater than route PMTU, and the
1978 old MTU is the lowest MTU in the path, update the route PMTU
1979 to reflect the increase. In this case if the other nodes' MTU
1980 also have the lowest MTU, TOO BIG MESSAGE will be lead to
1983 if (rt->rt6i_dev == arg->dev &&
1984 !dst_metric_locked(&rt->u.dst, RTAX_MTU) &&
1985 (dst_mtu(&rt->u.dst) > arg->mtu ||
1986 (dst_mtu(&rt->u.dst) < arg->mtu &&
1987 dst_mtu(&rt->u.dst) == idev->cnf.mtu6))) {
1988 rt->u.dst.metrics[RTAX_MTU-1] = arg->mtu;
1989 rt->u.dst.metrics[RTAX_ADVMSS-1] = ipv6_advmss(arg->mtu);
1994 void rt6_mtu_change(struct net_device *dev, unsigned mtu)
1996 struct rt6_mtu_change_arg arg = {
2001 fib6_clean_all(rt6_mtu_change_route, 0, &arg);
2004 static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
2005 [RTA_GATEWAY] = { .len = sizeof(struct in6_addr) },
2006 [RTA_OIF] = { .type = NLA_U32 },
2007 [RTA_IIF] = { .type = NLA_U32 },
2008 [RTA_PRIORITY] = { .type = NLA_U32 },
2009 [RTA_METRICS] = { .type = NLA_NESTED },
2012 static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
2013 struct fib6_config *cfg)
2016 struct nlattr *tb[RTA_MAX+1];
2019 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
2024 rtm = nlmsg_data(nlh);
2025 memset(cfg, 0, sizeof(*cfg));
2027 cfg->fc_table = rtm->rtm_table;
2028 cfg->fc_dst_len = rtm->rtm_dst_len;
2029 cfg->fc_src_len = rtm->rtm_src_len;
2030 cfg->fc_flags = RTF_UP;
2031 cfg->fc_protocol = rtm->rtm_protocol;
2033 if (rtm->rtm_type == RTN_UNREACHABLE)
2034 cfg->fc_flags |= RTF_REJECT;
2036 cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid;
2037 cfg->fc_nlinfo.nlh = nlh;
2039 if (tb[RTA_GATEWAY]) {
2040 nla_memcpy(&cfg->fc_gateway, tb[RTA_GATEWAY], 16);
2041 cfg->fc_flags |= RTF_GATEWAY;
2045 int plen = (rtm->rtm_dst_len + 7) >> 3;
2047 if (nla_len(tb[RTA_DST]) < plen)
2050 nla_memcpy(&cfg->fc_dst, tb[RTA_DST], plen);
2054 int plen = (rtm->rtm_src_len + 7) >> 3;
2056 if (nla_len(tb[RTA_SRC]) < plen)
2059 nla_memcpy(&cfg->fc_src, tb[RTA_SRC], plen);
2063 cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]);
2065 if (tb[RTA_PRIORITY])
2066 cfg->fc_metric = nla_get_u32(tb[RTA_PRIORITY]);
2068 if (tb[RTA_METRICS]) {
2069 cfg->fc_mx = nla_data(tb[RTA_METRICS]);
2070 cfg->fc_mx_len = nla_len(tb[RTA_METRICS]);
2074 cfg->fc_table = nla_get_u32(tb[RTA_TABLE]);
2081 static int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
2083 struct fib6_config cfg;
2086 err = rtm_to_fib6_config(skb, nlh, &cfg);
2090 return ip6_route_del(&cfg);
2093 static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
2095 struct fib6_config cfg;
2098 err = rtm_to_fib6_config(skb, nlh, &cfg);
2102 return ip6_route_add(&cfg);
2105 static inline size_t rt6_nlmsg_size(void)
2107 return NLMSG_ALIGN(sizeof(struct rtmsg))
2108 + nla_total_size(16) /* RTA_SRC */
2109 + nla_total_size(16) /* RTA_DST */
2110 + nla_total_size(16) /* RTA_GATEWAY */
2111 + nla_total_size(16) /* RTA_PREFSRC */
2112 + nla_total_size(4) /* RTA_TABLE */
2113 + nla_total_size(4) /* RTA_IIF */
2114 + nla_total_size(4) /* RTA_OIF */
2115 + nla_total_size(4) /* RTA_PRIORITY */
2116 + RTAX_MAX * nla_total_size(4) /* RTA_METRICS */
2117 + nla_total_size(sizeof(struct rta_cacheinfo));
2120 static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt,
2121 struct in6_addr *dst, struct in6_addr *src,
2122 int iif, int type, u32 pid, u32 seq,
2123 int prefix, unsigned int flags)
2126 struct nlmsghdr *nlh;
2130 if (prefix) { /* user wants prefix routes only */
2131 if (!(rt->rt6i_flags & RTF_PREFIX_RT)) {
2132 /* success since this is not a prefix route */
2137 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*rtm), flags);
2141 rtm = nlmsg_data(nlh);
2142 rtm->rtm_family = AF_INET6;
2143 rtm->rtm_dst_len = rt->rt6i_dst.plen;
2144 rtm->rtm_src_len = rt->rt6i_src.plen;
2147 table = rt->rt6i_table->tb6_id;
2149 table = RT6_TABLE_UNSPEC;
2150 rtm->rtm_table = table;
2151 NLA_PUT_U32(skb, RTA_TABLE, table);
2152 if (rt->rt6i_flags&RTF_REJECT)
2153 rtm->rtm_type = RTN_UNREACHABLE;
2154 else if (rt->rt6i_dev && (rt->rt6i_dev->flags&IFF_LOOPBACK))
2155 rtm->rtm_type = RTN_LOCAL;
2157 rtm->rtm_type = RTN_UNICAST;
2159 rtm->rtm_scope = RT_SCOPE_UNIVERSE;
2160 rtm->rtm_protocol = rt->rt6i_protocol;
2161 if (rt->rt6i_flags&RTF_DYNAMIC)
2162 rtm->rtm_protocol = RTPROT_REDIRECT;
2163 else if (rt->rt6i_flags & RTF_ADDRCONF)
2164 rtm->rtm_protocol = RTPROT_KERNEL;
2165 else if (rt->rt6i_flags&RTF_DEFAULT)
2166 rtm->rtm_protocol = RTPROT_RA;
2168 if (rt->rt6i_flags&RTF_CACHE)
2169 rtm->rtm_flags |= RTM_F_CLONED;
2172 NLA_PUT(skb, RTA_DST, 16, dst);
2173 rtm->rtm_dst_len = 128;
2174 } else if (rtm->rtm_dst_len)
2175 NLA_PUT(skb, RTA_DST, 16, &rt->rt6i_dst.addr);
2176 #ifdef CONFIG_IPV6_SUBTREES
2178 NLA_PUT(skb, RTA_SRC, 16, src);
2179 rtm->rtm_src_len = 128;
2180 } else if (rtm->rtm_src_len)
2181 NLA_PUT(skb, RTA_SRC, 16, &rt->rt6i_src.addr);
2184 NLA_PUT_U32(skb, RTA_IIF, iif);
2186 struct in6_addr saddr_buf;
2187 if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0)
2188 NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
2191 if (rtnetlink_put_metrics(skb, rt->u.dst.metrics) < 0)
2192 goto nla_put_failure;
2194 if (rt->u.dst.neighbour)
2195 NLA_PUT(skb, RTA_GATEWAY, 16, &rt->u.dst.neighbour->primary_key);
2198 NLA_PUT_U32(skb, RTA_OIF, rt->rt6i_dev->ifindex);
2200 NLA_PUT_U32(skb, RTA_PRIORITY, rt->rt6i_metric);
2202 expires = rt->rt6i_expires ? rt->rt6i_expires - jiffies : 0;
2203 if (rtnl_put_cacheinfo(skb, &rt->u.dst, 0, 0, 0,
2204 expires, rt->u.dst.error) < 0)
2205 goto nla_put_failure;
2207 return nlmsg_end(skb, nlh);
2210 nlmsg_cancel(skb, nlh);
2214 int rt6_dump_route(struct rt6_info *rt, void *p_arg)
2216 struct rt6_rtnl_dump_arg *arg = (struct rt6_rtnl_dump_arg *) p_arg;
2219 if (nlmsg_len(arg->cb->nlh) >= sizeof(struct rtmsg)) {
2220 struct rtmsg *rtm = nlmsg_data(arg->cb->nlh);
2221 prefix = (rtm->rtm_flags & RTM_F_PREFIX) != 0;
2225 return rt6_fill_node(arg->skb, rt, NULL, NULL, 0, RTM_NEWROUTE,
2226 NETLINK_CB(arg->cb->skb).pid, arg->cb->nlh->nlmsg_seq,
2227 prefix, NLM_F_MULTI);
2230 static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void *arg)
2232 struct nlattr *tb[RTA_MAX+1];
2233 struct rt6_info *rt;
2234 struct sk_buff *skb;
2239 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
2244 memset(&fl, 0, sizeof(fl));
2247 if (nla_len(tb[RTA_SRC]) < sizeof(struct in6_addr))
2250 ipv6_addr_copy(&fl.fl6_src, nla_data(tb[RTA_SRC]));
2254 if (nla_len(tb[RTA_DST]) < sizeof(struct in6_addr))
2257 ipv6_addr_copy(&fl.fl6_dst, nla_data(tb[RTA_DST]));
2261 iif = nla_get_u32(tb[RTA_IIF]);
2264 fl.oif = nla_get_u32(tb[RTA_OIF]);
2267 struct net_device *dev;
2268 dev = __dev_get_by_index(&init_net, iif);
2275 skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
2281 /* Reserve room for dummy headers, this skb can pass
2282 through good chunk of routing engine.
2284 skb_reset_mac_header(skb);
2285 skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr));
2287 rt = (struct rt6_info*) ip6_route_output(NULL, &fl);
2288 skb->dst = &rt->u.dst;
2290 err = rt6_fill_node(skb, rt, &fl.fl6_dst, &fl.fl6_src, iif,
2291 RTM_NEWROUTE, NETLINK_CB(in_skb).pid,
2292 nlh->nlmsg_seq, 0, 0);
2298 err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
2303 void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info)
2305 struct sk_buff *skb;
2306 u32 pid = 0, seq = 0;
2307 struct nlmsghdr *nlh = NULL;
2314 seq = nlh->nlmsg_seq;
2317 skb = nlmsg_new(rt6_nlmsg_size(), gfp_any());
2321 err = rt6_fill_node(skb, rt, NULL, NULL, 0, event, pid, seq, 0, 0);
2323 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */
2324 WARN_ON(err == -EMSGSIZE);
2328 err = rtnl_notify(skb, pid, RTNLGRP_IPV6_ROUTE, nlh, gfp_any());
2331 rtnl_set_sk_err(RTNLGRP_IPV6_ROUTE, err);
2338 #ifdef CONFIG_PROC_FS
2340 #define RT6_INFO_LEN (32 + 4 + 32 + 4 + 32 + 40 + 5 + 1)
2351 static int rt6_info_route(struct rt6_info *rt, void *p_arg)
2353 struct rt6_proc_arg *arg = (struct rt6_proc_arg *) p_arg;
2355 if (arg->skip < arg->offset / RT6_INFO_LEN) {
2360 if (arg->len >= arg->length)
2363 arg->len += sprintf(arg->buffer + arg->len,
2364 NIP6_SEQFMT " %02x ",
2365 NIP6(rt->rt6i_dst.addr),
2368 #ifdef CONFIG_IPV6_SUBTREES
2369 arg->len += sprintf(arg->buffer + arg->len,
2370 NIP6_SEQFMT " %02x ",
2371 NIP6(rt->rt6i_src.addr),
2374 arg->len += sprintf(arg->buffer + arg->len,
2375 "00000000000000000000000000000000 00 ");
2378 if (rt->rt6i_nexthop) {
2379 arg->len += sprintf(arg->buffer + arg->len,
2381 NIP6(*((struct in6_addr *)rt->rt6i_nexthop->primary_key)));
2383 arg->len += sprintf(arg->buffer + arg->len,
2384 "00000000000000000000000000000000");
2386 arg->len += sprintf(arg->buffer + arg->len,
2387 " %08x %08x %08x %08x %8s\n",
2388 rt->rt6i_metric, atomic_read(&rt->u.dst.__refcnt),
2389 rt->u.dst.__use, rt->rt6i_flags,
2390 rt->rt6i_dev ? rt->rt6i_dev->name : "");
2394 static int rt6_proc_info(char *buffer, char **start, off_t offset, int length)
2396 struct rt6_proc_arg arg = {
2402 fib6_clean_all(rt6_info_route, 0, &arg);
2406 *start += offset % RT6_INFO_LEN;
2408 arg.len -= offset % RT6_INFO_LEN;
2410 if (arg.len > length)
2418 static int rt6_stats_seq_show(struct seq_file *seq, void *v)
2420 seq_printf(seq, "%04x %04x %04x %04x %04x %04x %04x\n",
2421 rt6_stats.fib_nodes, rt6_stats.fib_route_nodes,
2422 rt6_stats.fib_rt_alloc, rt6_stats.fib_rt_entries,
2423 rt6_stats.fib_rt_cache,
2424 atomic_read(&ip6_dst_ops.entries),
2425 rt6_stats.fib_discarded_routes);
2430 static int rt6_stats_seq_open(struct inode *inode, struct file *file)
2432 return single_open(file, rt6_stats_seq_show, NULL);
2435 static const struct file_operations rt6_stats_seq_fops = {
2436 .owner = THIS_MODULE,
2437 .open = rt6_stats_seq_open,
2439 .llseek = seq_lseek,
2440 .release = single_release,
2442 #endif /* CONFIG_PROC_FS */
2444 #ifdef CONFIG_SYSCTL
2446 static int flush_delay;
2449 int ipv6_sysctl_rtcache_flush(ctl_table *ctl, int write, struct file * filp,
2450 void __user *buffer, size_t *lenp, loff_t *ppos)
2453 proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
2454 fib6_run_gc(flush_delay <= 0 ? ~0UL : (unsigned long)flush_delay);
2460 ctl_table ipv6_route_table[] = {
2462 .ctl_name = NET_IPV6_ROUTE_FLUSH,
2463 .procname = "flush",
2464 .data = &flush_delay,
2465 .maxlen = sizeof(int),
2467 .proc_handler = &ipv6_sysctl_rtcache_flush
2470 .ctl_name = NET_IPV6_ROUTE_GC_THRESH,
2471 .procname = "gc_thresh",
2472 .data = &ip6_dst_ops.gc_thresh,
2473 .maxlen = sizeof(int),
2475 .proc_handler = &proc_dointvec,
2478 .ctl_name = NET_IPV6_ROUTE_MAX_SIZE,
2479 .procname = "max_size",
2480 .data = &ip6_rt_max_size,
2481 .maxlen = sizeof(int),
2483 .proc_handler = &proc_dointvec,
2486 .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL,
2487 .procname = "gc_min_interval",
2488 .data = &ip6_rt_gc_min_interval,
2489 .maxlen = sizeof(int),
2491 .proc_handler = &proc_dointvec_jiffies,
2492 .strategy = &sysctl_jiffies,
2495 .ctl_name = NET_IPV6_ROUTE_GC_TIMEOUT,
2496 .procname = "gc_timeout",
2497 .data = &ip6_rt_gc_timeout,
2498 .maxlen = sizeof(int),
2500 .proc_handler = &proc_dointvec_jiffies,
2501 .strategy = &sysctl_jiffies,
2504 .ctl_name = NET_IPV6_ROUTE_GC_INTERVAL,
2505 .procname = "gc_interval",
2506 .data = &ip6_rt_gc_interval,
2507 .maxlen = sizeof(int),
2509 .proc_handler = &proc_dointvec_jiffies,
2510 .strategy = &sysctl_jiffies,
2513 .ctl_name = NET_IPV6_ROUTE_GC_ELASTICITY,
2514 .procname = "gc_elasticity",
2515 .data = &ip6_rt_gc_elasticity,
2516 .maxlen = sizeof(int),
2518 .proc_handler = &proc_dointvec_jiffies,
2519 .strategy = &sysctl_jiffies,
2522 .ctl_name = NET_IPV6_ROUTE_MTU_EXPIRES,
2523 .procname = "mtu_expires",
2524 .data = &ip6_rt_mtu_expires,
2525 .maxlen = sizeof(int),
2527 .proc_handler = &proc_dointvec_jiffies,
2528 .strategy = &sysctl_jiffies,
2531 .ctl_name = NET_IPV6_ROUTE_MIN_ADVMSS,
2532 .procname = "min_adv_mss",
2533 .data = &ip6_rt_min_advmss,
2534 .maxlen = sizeof(int),
2536 .proc_handler = &proc_dointvec_jiffies,
2537 .strategy = &sysctl_jiffies,
2540 .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL_MS,
2541 .procname = "gc_min_interval_ms",
2542 .data = &ip6_rt_gc_min_interval,
2543 .maxlen = sizeof(int),
2545 .proc_handler = &proc_dointvec_ms_jiffies,
2546 .strategy = &sysctl_ms_jiffies,
2553 void __init ip6_route_init(void)
2555 #ifdef CONFIG_PROC_FS
2556 struct proc_dir_entry *p;
2558 ip6_dst_ops.kmem_cachep =
2559 kmem_cache_create("ip6_dst_cache", sizeof(struct rt6_info), 0,
2560 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
2561 ip6_dst_blackhole_ops.kmem_cachep = ip6_dst_ops.kmem_cachep;
2564 #ifdef CONFIG_PROC_FS
2565 p = proc_net_create(&init_net, "ipv6_route", 0, rt6_proc_info);
2567 p->owner = THIS_MODULE;
2569 proc_net_fops_create(&init_net, "rt6_stats", S_IRUGO, &rt6_stats_seq_fops);
2574 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
2578 __rtnl_register(PF_INET6, RTM_NEWROUTE, inet6_rtm_newroute, NULL);
2579 __rtnl_register(PF_INET6, RTM_DELROUTE, inet6_rtm_delroute, NULL);
2580 __rtnl_register(PF_INET6, RTM_GETROUTE, inet6_rtm_getroute, NULL);
2583 void ip6_route_cleanup(void)
2585 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
2586 fib6_rules_cleanup();
2588 #ifdef CONFIG_PROC_FS
2589 proc_net_remove(&init_net, "ipv6_route");
2590 proc_net_remove(&init_net, "rt6_stats");
2597 kmem_cache_destroy(ip6_dst_ops.kmem_cachep);