2 * Linux INET6 implementation
3 * Forwarding Information Database
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 * Yuji SEKIYA @USAGI: Support default route on router node;
15 * remove ip6_null_entry from the top of
17 * Ville Nuorvala: Fixed routing subtrees.
20 #define pr_fmt(fmt) "IPv6: " fmt
22 #include <linux/errno.h>
23 #include <linux/types.h>
24 #include <linux/net.h>
25 #include <linux/route.h>
26 #include <linux/netdevice.h>
27 #include <linux/in6.h>
28 #include <linux/init.h>
29 #include <linux/list.h>
30 #include <linux/slab.h>
33 #include <net/ndisc.h>
34 #include <net/addrconf.h>
36 #include <net/ip6_fib.h>
37 #include <net/ip6_route.h>
42 #define RT6_TRACE(x...) pr_debug(x)
44 #define RT6_TRACE(x...) do { ; } while (0)
47 static struct kmem_cache
*fib6_node_kmem __read_mostly
;
49 enum fib_walk_state_t
{
50 #ifdef CONFIG_IPV6_SUBTREES
59 struct fib6_cleaner_t
{
60 struct fib6_walker_t w
;
62 int (*func
)(struct rt6_info
*, void *arg
);
66 static DEFINE_RWLOCK(fib6_walker_lock
);
68 #ifdef CONFIG_IPV6_SUBTREES
69 #define FWS_INIT FWS_S
71 #define FWS_INIT FWS_L
74 static void fib6_prune_clones(struct net
*net
, struct fib6_node
*fn
);
75 static struct rt6_info
*fib6_find_prefix(struct net
*net
, struct fib6_node
*fn
);
76 static struct fib6_node
*fib6_repair_tree(struct net
*net
, struct fib6_node
*fn
);
77 static int fib6_walk(struct fib6_walker_t
*w
);
78 static int fib6_walk_continue(struct fib6_walker_t
*w
);
81 * A routing update causes an increase of the serial number on the
82 * affected subtree. This allows for cached routes to be asynchronously
83 * tested when modifications are made to the destination cache as a
84 * result of redirects, path MTU changes, etc.
87 static __u32 rt_sernum
;
89 static void fib6_gc_timer_cb(unsigned long arg
);
91 static LIST_HEAD(fib6_walkers
);
92 #define FOR_WALKERS(w) list_for_each_entry(w, &fib6_walkers, lh)
94 static inline void fib6_walker_link(struct fib6_walker_t
*w
)
96 write_lock_bh(&fib6_walker_lock
);
97 list_add(&w
->lh
, &fib6_walkers
);
98 write_unlock_bh(&fib6_walker_lock
);
101 static inline void fib6_walker_unlink(struct fib6_walker_t
*w
)
103 write_lock_bh(&fib6_walker_lock
);
105 write_unlock_bh(&fib6_walker_lock
);
107 static __inline__ u32
fib6_new_sernum(void)
116 * Auxiliary address test functions for the radix tree.
118 * These assume a 32bit processor (although it will work on
125 #if defined(__LITTLE_ENDIAN)
126 # define BITOP_BE32_SWIZZLE (0x1F & ~7)
128 # define BITOP_BE32_SWIZZLE 0
131 static __inline__ __be32
addr_bit_set(const void *token
, int fn_bit
)
133 const __be32
*addr
= token
;
136 * 1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)
137 * is optimized version of
138 * htonl(1 << ((~fn_bit)&0x1F))
139 * See include/asm-generic/bitops/le.h.
141 return (__force __be32
)(1 << ((~fn_bit
^ BITOP_BE32_SWIZZLE
) & 0x1f)) &
145 static __inline__
struct fib6_node
*node_alloc(void)
147 struct fib6_node
*fn
;
149 fn
= kmem_cache_zalloc(fib6_node_kmem
, GFP_ATOMIC
);
154 static __inline__
void node_free(struct fib6_node
*fn
)
156 kmem_cache_free(fib6_node_kmem
, fn
);
159 static __inline__
void rt6_release(struct rt6_info
*rt
)
161 if (atomic_dec_and_test(&rt
->rt6i_ref
))
165 static void fib6_link_table(struct net
*net
, struct fib6_table
*tb
)
170 * Initialize table lock at a single place to give lockdep a key,
171 * tables aren't visible prior to being linked to the list.
173 rwlock_init(&tb
->tb6_lock
);
175 h
= tb
->tb6_id
& (FIB6_TABLE_HASHSZ
- 1);
178 * No protection necessary, this is the only list mutatation
179 * operation, tables never disappear once they exist.
181 hlist_add_head_rcu(&tb
->tb6_hlist
, &net
->ipv6
.fib_table_hash
[h
]);
184 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
186 static struct fib6_table
*fib6_alloc_table(struct net
*net
, u32 id
)
188 struct fib6_table
*table
;
190 table
= kzalloc(sizeof(*table
), GFP_ATOMIC
);
193 table
->tb6_root
.leaf
= net
->ipv6
.ip6_null_entry
;
194 table
->tb6_root
.fn_flags
= RTN_ROOT
| RTN_TL_ROOT
| RTN_RTINFO
;
195 inet_peer_base_init(&table
->tb6_peers
);
201 struct fib6_table
*fib6_new_table(struct net
*net
, u32 id
)
203 struct fib6_table
*tb
;
207 tb
= fib6_get_table(net
, id
);
211 tb
= fib6_alloc_table(net
, id
);
213 fib6_link_table(net
, tb
);
218 struct fib6_table
*fib6_get_table(struct net
*net
, u32 id
)
220 struct fib6_table
*tb
;
221 struct hlist_head
*head
;
226 h
= id
& (FIB6_TABLE_HASHSZ
- 1);
228 head
= &net
->ipv6
.fib_table_hash
[h
];
229 hlist_for_each_entry_rcu(tb
, head
, tb6_hlist
) {
230 if (tb
->tb6_id
== id
) {
240 static void __net_init
fib6_tables_init(struct net
*net
)
242 fib6_link_table(net
, net
->ipv6
.fib6_main_tbl
);
243 fib6_link_table(net
, net
->ipv6
.fib6_local_tbl
);
247 struct fib6_table
*fib6_new_table(struct net
*net
, u32 id
)
249 return fib6_get_table(net
, id
);
252 struct fib6_table
*fib6_get_table(struct net
*net
, u32 id
)
254 return net
->ipv6
.fib6_main_tbl
;
257 struct dst_entry
*fib6_rule_lookup(struct net
*net
, struct flowi6
*fl6
,
258 int flags
, pol_lookup_t lookup
)
260 return (struct dst_entry
*) lookup(net
, net
->ipv6
.fib6_main_tbl
, fl6
, flags
);
263 static void __net_init
fib6_tables_init(struct net
*net
)
265 fib6_link_table(net
, net
->ipv6
.fib6_main_tbl
);
270 static int fib6_dump_node(struct fib6_walker_t
*w
)
275 for (rt
= w
->leaf
; rt
; rt
= rt
->dst
.rt6_next
) {
276 res
= rt6_dump_route(rt
, w
->args
);
278 /* Frame is full, suspend walking */
288 static void fib6_dump_end(struct netlink_callback
*cb
)
290 struct fib6_walker_t
*w
= (void *)cb
->args
[2];
295 fib6_walker_unlink(w
);
300 cb
->done
= (void *)cb
->args
[3];
304 static int fib6_dump_done(struct netlink_callback
*cb
)
307 return cb
->done
? cb
->done(cb
) : 0;
310 static int fib6_dump_table(struct fib6_table
*table
, struct sk_buff
*skb
,
311 struct netlink_callback
*cb
)
313 struct fib6_walker_t
*w
;
316 w
= (void *)cb
->args
[2];
317 w
->root
= &table
->tb6_root
;
319 if (cb
->args
[4] == 0) {
323 read_lock_bh(&table
->tb6_lock
);
325 read_unlock_bh(&table
->tb6_lock
);
328 cb
->args
[5] = w
->root
->fn_sernum
;
331 if (cb
->args
[5] != w
->root
->fn_sernum
) {
332 /* Begin at the root if the tree changed */
333 cb
->args
[5] = w
->root
->fn_sernum
;
340 read_lock_bh(&table
->tb6_lock
);
341 res
= fib6_walk_continue(w
);
342 read_unlock_bh(&table
->tb6_lock
);
344 fib6_walker_unlink(w
);
352 static int inet6_dump_fib(struct sk_buff
*skb
, struct netlink_callback
*cb
)
354 struct net
*net
= sock_net(skb
->sk
);
356 unsigned int e
= 0, s_e
;
357 struct rt6_rtnl_dump_arg arg
;
358 struct fib6_walker_t
*w
;
359 struct fib6_table
*tb
;
360 struct hlist_head
*head
;
366 w
= (void *)cb
->args
[2];
370 * 1. hook callback destructor.
372 cb
->args
[3] = (long)cb
->done
;
373 cb
->done
= fib6_dump_done
;
376 * 2. allocate and initialize walker.
378 w
= kzalloc(sizeof(*w
), GFP_ATOMIC
);
381 w
->func
= fib6_dump_node
;
382 cb
->args
[2] = (long)w
;
391 for (h
= s_h
; h
< FIB6_TABLE_HASHSZ
; h
++, s_e
= 0) {
393 head
= &net
->ipv6
.fib_table_hash
[h
];
394 hlist_for_each_entry_rcu(tb
, head
, tb6_hlist
) {
397 res
= fib6_dump_table(tb
, skb
, cb
);
409 res
= res
< 0 ? res
: skb
->len
;
418 * return the appropriate node for a routing tree "add" operation
419 * by either creating and inserting or by returning an existing
423 static struct fib6_node
*fib6_add_1(struct fib6_node
*root
,
424 struct in6_addr
*addr
, int plen
,
425 int offset
, int allow_create
,
426 int replace_required
)
428 struct fib6_node
*fn
, *in
, *ln
;
429 struct fib6_node
*pn
= NULL
;
433 __u32 sernum
= fib6_new_sernum();
435 RT6_TRACE("fib6_add_1\n");
437 /* insert node in tree */
442 key
= (struct rt6key
*)((u8
*)fn
->leaf
+ offset
);
447 if (plen
< fn
->fn_bit
||
448 !ipv6_prefix_equal(&key
->addr
, addr
, fn
->fn_bit
)) {
450 if (replace_required
) {
451 pr_warn("Can't replace route, no match found\n");
452 return ERR_PTR(-ENOENT
);
454 pr_warn("NLM_F_CREATE should be set when creating new route\n");
463 if (plen
== fn
->fn_bit
) {
464 /* clean up an intermediate node */
465 if (!(fn
->fn_flags
& RTN_RTINFO
)) {
466 rt6_release(fn
->leaf
);
470 fn
->fn_sernum
= sernum
;
476 * We have more bits to go
479 /* Try to walk down on tree. */
480 fn
->fn_sernum
= sernum
;
481 dir
= addr_bit_set(addr
, fn
->fn_bit
);
483 fn
= dir
? fn
->right
: fn
->left
;
487 /* We should not create new node because
488 * NLM_F_REPLACE was specified without NLM_F_CREATE
489 * I assume it is safe to require NLM_F_CREATE when
490 * REPLACE flag is used! Later we may want to remove the
491 * check for replace_required, because according
492 * to netlink specification, NLM_F_CREATE
493 * MUST be specified if new route is created.
494 * That would keep IPv6 consistent with IPv4
496 if (replace_required
) {
497 pr_warn("Can't replace route, no match found\n");
498 return ERR_PTR(-ENOENT
);
500 pr_warn("NLM_F_CREATE should be set when creating new route\n");
503 * We walked to the bottom of tree.
504 * Create new leaf node without children.
510 return ERR_PTR(-ENOMEM
);
514 ln
->fn_sernum
= sernum
;
526 * split since we don't have a common prefix anymore or
527 * we have a less significant route.
528 * we've to insert an intermediate node on the list
529 * this new node will point to the one we need to create
535 /* find 1st bit in difference between the 2 addrs.
537 See comment in __ipv6_addr_diff: bit may be an invalid value,
538 but if it is >= plen, the value is ignored in any case.
541 bit
= __ipv6_addr_diff(addr
, &key
->addr
, sizeof(*addr
));
546 * (new leaf node)[ln] (old node)[fn]
557 return ERR_PTR(-ENOMEM
);
561 * new intermediate node.
563 * be off since that an address that chooses one of
564 * the branches would not match less specific routes
565 * in the other branch
572 atomic_inc(&in
->leaf
->rt6i_ref
);
574 in
->fn_sernum
= sernum
;
576 /* update parent pointer */
587 ln
->fn_sernum
= sernum
;
589 if (addr_bit_set(addr
, bit
)) {
596 } else { /* plen <= bit */
599 * (new leaf node)[ln]
601 * (old node)[fn] NULL
607 return ERR_PTR(-ENOMEM
);
613 ln
->fn_sernum
= sernum
;
620 if (addr_bit_set(&key
->addr
, plen
))
630 static inline bool rt6_qualify_for_ecmp(struct rt6_info
*rt
)
632 return (rt
->rt6i_flags
& (RTF_GATEWAY
|RTF_ADDRCONF
|RTF_DYNAMIC
)) ==
636 static int fib6_commit_metrics(struct dst_entry
*dst
,
637 struct nlattr
*mx
, int mx_len
)
643 if (dst
->flags
& DST_HOST
) {
644 mp
= dst_metrics_write_ptr(dst
);
646 mp
= kzalloc(sizeof(u32
) * RTAX_MAX
, GFP_ATOMIC
);
649 dst_init_metrics(dst
, mp
, 0);
652 nla_for_each_attr(nla
, mx
, mx_len
, remaining
) {
653 int type
= nla_type(nla
);
659 mp
[type
- 1] = nla_get_u32(nla
);
666 * Insert routing information in a node.
669 static int fib6_add_rt2node(struct fib6_node
*fn
, struct rt6_info
*rt
,
670 struct nl_info
*info
, struct nlattr
*mx
, int mx_len
)
672 struct rt6_info
*iter
= NULL
;
673 struct rt6_info
**ins
;
674 int replace
= (info
->nlh
&&
675 (info
->nlh
->nlmsg_flags
& NLM_F_REPLACE
));
676 int add
= (!info
->nlh
||
677 (info
->nlh
->nlmsg_flags
& NLM_F_CREATE
));
679 bool rt_can_ecmp
= rt6_qualify_for_ecmp(rt
);
684 for (iter
= fn
->leaf
; iter
; iter
= iter
->dst
.rt6_next
) {
686 * Search for duplicates
689 if (iter
->rt6i_metric
== rt
->rt6i_metric
) {
691 * Same priority level
694 (info
->nlh
->nlmsg_flags
& NLM_F_EXCL
))
701 if (iter
->dst
.dev
== rt
->dst
.dev
&&
702 iter
->rt6i_idev
== rt
->rt6i_idev
&&
703 ipv6_addr_equal(&iter
->rt6i_gateway
,
704 &rt
->rt6i_gateway
)) {
705 if (rt
->rt6i_nsiblings
)
706 rt
->rt6i_nsiblings
= 0;
707 if (!(iter
->rt6i_flags
& RTF_EXPIRES
))
709 if (!(rt
->rt6i_flags
& RTF_EXPIRES
))
710 rt6_clean_expires(iter
);
712 rt6_set_expires(iter
, rt
->dst
.expires
);
715 /* If we have the same destination and the same metric,
716 * but not the same gateway, then the route we try to
717 * add is sibling to this route, increment our counter
718 * of siblings, and later we will add our route to the
720 * Only static routes (which don't have flag
721 * RTF_EXPIRES) are used for ECMPv6.
723 * To avoid long list, we only had siblings if the
724 * route have a gateway.
727 rt6_qualify_for_ecmp(iter
))
728 rt
->rt6i_nsiblings
++;
731 if (iter
->rt6i_metric
> rt
->rt6i_metric
)
734 ins
= &iter
->dst
.rt6_next
;
737 /* Reset round-robin state, if necessary */
738 if (ins
== &fn
->leaf
)
741 /* Link this route to others same route. */
742 if (rt
->rt6i_nsiblings
) {
743 unsigned int rt6i_nsiblings
;
744 struct rt6_info
*sibling
, *temp_sibling
;
746 /* Find the first route that have the same metric */
749 if (sibling
->rt6i_metric
== rt
->rt6i_metric
&&
750 rt6_qualify_for_ecmp(sibling
)) {
751 list_add_tail(&rt
->rt6i_siblings
,
752 &sibling
->rt6i_siblings
);
755 sibling
= sibling
->dst
.rt6_next
;
757 /* For each sibling in the list, increment the counter of
758 * siblings. BUG() if counters does not match, list of siblings
762 list_for_each_entry_safe(sibling
, temp_sibling
,
763 &rt
->rt6i_siblings
, rt6i_siblings
) {
764 sibling
->rt6i_nsiblings
++;
765 BUG_ON(sibling
->rt6i_nsiblings
!= rt
->rt6i_nsiblings
);
768 BUG_ON(rt6i_nsiblings
!= rt
->rt6i_nsiblings
);
776 pr_warn("NLM_F_CREATE should be set when creating new route\n");
780 err
= fib6_commit_metrics(&rt
->dst
, mx
, mx_len
);
784 rt
->dst
.rt6_next
= iter
;
787 atomic_inc(&rt
->rt6i_ref
);
788 inet6_rt_notify(RTM_NEWROUTE
, rt
, info
);
789 info
->nl_net
->ipv6
.rt6_stats
->fib_rt_entries
++;
791 if (!(fn
->fn_flags
& RTN_RTINFO
)) {
792 info
->nl_net
->ipv6
.rt6_stats
->fib_route_nodes
++;
793 fn
->fn_flags
|= RTN_RTINFO
;
800 pr_warn("NLM_F_REPLACE set, but no existing node found!\n");
804 err
= fib6_commit_metrics(&rt
->dst
, mx
, mx_len
);
810 rt
->dst
.rt6_next
= iter
->dst
.rt6_next
;
811 atomic_inc(&rt
->rt6i_ref
);
812 inet6_rt_notify(RTM_NEWROUTE
, rt
, info
);
814 if (!(fn
->fn_flags
& RTN_RTINFO
)) {
815 info
->nl_net
->ipv6
.rt6_stats
->fib_route_nodes
++;
816 fn
->fn_flags
|= RTN_RTINFO
;
823 static __inline__
void fib6_start_gc(struct net
*net
, struct rt6_info
*rt
)
825 if (!timer_pending(&net
->ipv6
.ip6_fib_timer
) &&
826 (rt
->rt6i_flags
& (RTF_EXPIRES
| RTF_CACHE
)))
827 mod_timer(&net
->ipv6
.ip6_fib_timer
,
828 jiffies
+ net
->ipv6
.sysctl
.ip6_rt_gc_interval
);
831 void fib6_force_start_gc(struct net
*net
)
833 if (!timer_pending(&net
->ipv6
.ip6_fib_timer
))
834 mod_timer(&net
->ipv6
.ip6_fib_timer
,
835 jiffies
+ net
->ipv6
.sysctl
.ip6_rt_gc_interval
);
839 * Add routing information to the routing tree.
840 * <destination addr>/<source addr>
841 * with source addr info in sub-trees
844 int fib6_add(struct fib6_node
*root
, struct rt6_info
*rt
, struct nl_info
*info
,
845 struct nlattr
*mx
, int mx_len
)
847 struct fib6_node
*fn
, *pn
= NULL
;
849 int allow_create
= 1;
850 int replace_required
= 0;
853 if (!(info
->nlh
->nlmsg_flags
& NLM_F_CREATE
))
855 if (info
->nlh
->nlmsg_flags
& NLM_F_REPLACE
)
856 replace_required
= 1;
858 if (!allow_create
&& !replace_required
)
859 pr_warn("RTM_NEWROUTE with no NLM_F_CREATE or NLM_F_REPLACE\n");
861 fn
= fib6_add_1(root
, &rt
->rt6i_dst
.addr
, rt
->rt6i_dst
.plen
,
862 offsetof(struct rt6_info
, rt6i_dst
), allow_create
,
872 #ifdef CONFIG_IPV6_SUBTREES
873 if (rt
->rt6i_src
.plen
) {
874 struct fib6_node
*sn
;
877 struct fib6_node
*sfn
;
889 /* Create subtree root node */
894 sfn
->leaf
= info
->nl_net
->ipv6
.ip6_null_entry
;
895 atomic_inc(&info
->nl_net
->ipv6
.ip6_null_entry
->rt6i_ref
);
896 sfn
->fn_flags
= RTN_ROOT
;
897 sfn
->fn_sernum
= fib6_new_sernum();
899 /* Now add the first leaf node to new subtree */
901 sn
= fib6_add_1(sfn
, &rt
->rt6i_src
.addr
,
903 offsetof(struct rt6_info
, rt6i_src
),
904 allow_create
, replace_required
);
907 /* If it is failed, discard just allocated
908 root, and then (in st_failure) stale node
916 /* Now link new subtree to main tree */
920 sn
= fib6_add_1(fn
->subtree
, &rt
->rt6i_src
.addr
,
922 offsetof(struct rt6_info
, rt6i_src
),
923 allow_create
, replace_required
);
933 atomic_inc(&rt
->rt6i_ref
);
939 err
= fib6_add_rt2node(fn
, rt
, info
, mx
, mx_len
);
941 fib6_start_gc(info
->nl_net
, rt
);
942 if (!(rt
->rt6i_flags
& RTF_CACHE
))
943 fib6_prune_clones(info
->nl_net
, pn
);
948 #ifdef CONFIG_IPV6_SUBTREES
950 * If fib6_add_1 has cleared the old leaf pointer in the
951 * super-tree leaf node we have to find a new one for it.
953 if (pn
!= fn
&& pn
->leaf
== rt
) {
955 atomic_dec(&rt
->rt6i_ref
);
957 if (pn
!= fn
&& !pn
->leaf
&& !(pn
->fn_flags
& RTN_RTINFO
)) {
958 pn
->leaf
= fib6_find_prefix(info
->nl_net
, pn
);
961 WARN_ON(pn
->leaf
== NULL
);
962 pn
->leaf
= info
->nl_net
->ipv6
.ip6_null_entry
;
965 atomic_inc(&pn
->leaf
->rt6i_ref
);
972 #ifdef CONFIG_IPV6_SUBTREES
973 /* Subtree creation failed, probably main tree node
974 is orphan. If it is, shoot it.
977 if (fn
&& !(fn
->fn_flags
& (RTN_RTINFO
|RTN_ROOT
)))
978 fib6_repair_tree(info
->nl_net
, fn
);
985 * Routing tree lookup
990 int offset
; /* key offset on rt6_info */
991 const struct in6_addr
*addr
; /* search key */
994 static struct fib6_node
*fib6_lookup_1(struct fib6_node
*root
,
995 struct lookup_args
*args
)
997 struct fib6_node
*fn
;
1000 if (unlikely(args
->offset
== 0))
1010 struct fib6_node
*next
;
1012 dir
= addr_bit_set(args
->addr
, fn
->fn_bit
);
1014 next
= dir
? fn
->right
: fn
->left
;
1024 if (FIB6_SUBTREE(fn
) || fn
->fn_flags
& RTN_RTINFO
) {
1027 key
= (struct rt6key
*) ((u8
*) fn
->leaf
+
1030 if (ipv6_prefix_equal(&key
->addr
, args
->addr
, key
->plen
)) {
1031 #ifdef CONFIG_IPV6_SUBTREES
1033 struct fib6_node
*sfn
;
1034 sfn
= fib6_lookup_1(fn
->subtree
,
1041 if (fn
->fn_flags
& RTN_RTINFO
)
1045 #ifdef CONFIG_IPV6_SUBTREES
1048 if (fn
->fn_flags
& RTN_ROOT
)
1057 struct fib6_node
*fib6_lookup(struct fib6_node
*root
, const struct in6_addr
*daddr
,
1058 const struct in6_addr
*saddr
)
1060 struct fib6_node
*fn
;
1061 struct lookup_args args
[] = {
1063 .offset
= offsetof(struct rt6_info
, rt6i_dst
),
1066 #ifdef CONFIG_IPV6_SUBTREES
1068 .offset
= offsetof(struct rt6_info
, rt6i_src
),
1073 .offset
= 0, /* sentinel */
1077 fn
= fib6_lookup_1(root
, daddr
? args
: args
+ 1);
1078 if (!fn
|| fn
->fn_flags
& RTN_TL_ROOT
)
1085 * Get node with specified destination prefix (and source prefix,
1086 * if subtrees are used)
1090 static struct fib6_node
*fib6_locate_1(struct fib6_node
*root
,
1091 const struct in6_addr
*addr
,
1092 int plen
, int offset
)
1094 struct fib6_node
*fn
;
1096 for (fn
= root
; fn
; ) {
1097 struct rt6key
*key
= (struct rt6key
*)((u8
*)fn
->leaf
+ offset
);
1102 if (plen
< fn
->fn_bit
||
1103 !ipv6_prefix_equal(&key
->addr
, addr
, fn
->fn_bit
))
1106 if (plen
== fn
->fn_bit
)
1110 * We have more bits to go
1112 if (addr_bit_set(addr
, fn
->fn_bit
))
1120 struct fib6_node
*fib6_locate(struct fib6_node
*root
,
1121 const struct in6_addr
*daddr
, int dst_len
,
1122 const struct in6_addr
*saddr
, int src_len
)
1124 struct fib6_node
*fn
;
1126 fn
= fib6_locate_1(root
, daddr
, dst_len
,
1127 offsetof(struct rt6_info
, rt6i_dst
));
1129 #ifdef CONFIG_IPV6_SUBTREES
1131 WARN_ON(saddr
== NULL
);
1132 if (fn
&& fn
->subtree
)
1133 fn
= fib6_locate_1(fn
->subtree
, saddr
, src_len
,
1134 offsetof(struct rt6_info
, rt6i_src
));
1138 if (fn
&& fn
->fn_flags
& RTN_RTINFO
)
1150 static struct rt6_info
*fib6_find_prefix(struct net
*net
, struct fib6_node
*fn
)
1152 if (fn
->fn_flags
& RTN_ROOT
)
1153 return net
->ipv6
.ip6_null_entry
;
1157 return fn
->left
->leaf
;
1159 return fn
->right
->leaf
;
1161 fn
= FIB6_SUBTREE(fn
);
1167 * Called to trim the tree of intermediate nodes when possible. "fn"
1168 * is the node we want to try and remove.
1171 static struct fib6_node
*fib6_repair_tree(struct net
*net
,
1172 struct fib6_node
*fn
)
1176 struct fib6_node
*child
, *pn
;
1177 struct fib6_walker_t
*w
;
1181 RT6_TRACE("fixing tree: plen=%d iter=%d\n", fn
->fn_bit
, iter
);
1184 WARN_ON(fn
->fn_flags
& RTN_RTINFO
);
1185 WARN_ON(fn
->fn_flags
& RTN_TL_ROOT
);
1186 WARN_ON(fn
->leaf
!= NULL
);
1191 child
= fn
->right
, children
|= 1;
1193 child
= fn
->left
, children
|= 2;
1195 if (children
== 3 || FIB6_SUBTREE(fn
)
1196 #ifdef CONFIG_IPV6_SUBTREES
1197 /* Subtree root (i.e. fn) may have one child */
1198 || (children
&& fn
->fn_flags
& RTN_ROOT
)
1201 fn
->leaf
= fib6_find_prefix(net
, fn
);
1205 fn
->leaf
= net
->ipv6
.ip6_null_entry
;
1208 atomic_inc(&fn
->leaf
->rt6i_ref
);
1213 #ifdef CONFIG_IPV6_SUBTREES
1214 if (FIB6_SUBTREE(pn
) == fn
) {
1215 WARN_ON(!(fn
->fn_flags
& RTN_ROOT
));
1216 FIB6_SUBTREE(pn
) = NULL
;
1219 WARN_ON(fn
->fn_flags
& RTN_ROOT
);
1221 if (pn
->right
== fn
)
1223 else if (pn
->left
== fn
)
1232 #ifdef CONFIG_IPV6_SUBTREES
1236 read_lock(&fib6_walker_lock
);
1239 if (w
->root
== fn
) {
1240 w
->root
= w
->node
= NULL
;
1241 RT6_TRACE("W %p adjusted by delroot 1\n", w
);
1242 } else if (w
->node
== fn
) {
1243 RT6_TRACE("W %p adjusted by delnode 1, s=%d/%d\n", w
, w
->state
, nstate
);
1248 if (w
->root
== fn
) {
1250 RT6_TRACE("W %p adjusted by delroot 2\n", w
);
1252 if (w
->node
== fn
) {
1255 RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w
, w
->state
);
1256 w
->state
= w
->state
>= FWS_R
? FWS_U
: FWS_INIT
;
1258 RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w
, w
->state
);
1259 w
->state
= w
->state
>= FWS_C
? FWS_U
: FWS_INIT
;
1264 read_unlock(&fib6_walker_lock
);
1267 if (pn
->fn_flags
& RTN_RTINFO
|| FIB6_SUBTREE(pn
))
1270 rt6_release(pn
->leaf
);
1276 static void fib6_del_route(struct fib6_node
*fn
, struct rt6_info
**rtp
,
1277 struct nl_info
*info
)
1279 struct fib6_walker_t
*w
;
1280 struct rt6_info
*rt
= *rtp
;
1281 struct net
*net
= info
->nl_net
;
1283 RT6_TRACE("fib6_del_route\n");
1286 *rtp
= rt
->dst
.rt6_next
;
1287 rt
->rt6i_node
= NULL
;
1288 net
->ipv6
.rt6_stats
->fib_rt_entries
--;
1289 net
->ipv6
.rt6_stats
->fib_discarded_routes
++;
1291 /* Reset round-robin state, if necessary */
1292 if (fn
->rr_ptr
== rt
)
1295 /* Remove this entry from other siblings */
1296 if (rt
->rt6i_nsiblings
) {
1297 struct rt6_info
*sibling
, *next_sibling
;
1299 list_for_each_entry_safe(sibling
, next_sibling
,
1300 &rt
->rt6i_siblings
, rt6i_siblings
)
1301 sibling
->rt6i_nsiblings
--;
1302 rt
->rt6i_nsiblings
= 0;
1303 list_del_init(&rt
->rt6i_siblings
);
1306 /* Adjust walkers */
1307 read_lock(&fib6_walker_lock
);
1309 if (w
->state
== FWS_C
&& w
->leaf
== rt
) {
1310 RT6_TRACE("walker %p adjusted by delroute\n", w
);
1311 w
->leaf
= rt
->dst
.rt6_next
;
1316 read_unlock(&fib6_walker_lock
);
1318 rt
->dst
.rt6_next
= NULL
;
1320 /* If it was last route, expunge its radix tree node */
1322 fn
->fn_flags
&= ~RTN_RTINFO
;
1323 net
->ipv6
.rt6_stats
->fib_route_nodes
--;
1324 fn
= fib6_repair_tree(net
, fn
);
1327 if (atomic_read(&rt
->rt6i_ref
) != 1) {
1328 /* This route is used as dummy address holder in some split
1329 * nodes. It is not leaked, but it still holds other resources,
1330 * which must be released in time. So, scan ascendant nodes
1331 * and replace dummy references to this route with references
1332 * to still alive ones.
1335 if (!(fn
->fn_flags
& RTN_RTINFO
) && fn
->leaf
== rt
) {
1336 fn
->leaf
= fib6_find_prefix(net
, fn
);
1337 atomic_inc(&fn
->leaf
->rt6i_ref
);
1342 /* No more references are possible at this point. */
1343 BUG_ON(atomic_read(&rt
->rt6i_ref
) != 1);
1346 inet6_rt_notify(RTM_DELROUTE
, rt
, info
);
1350 int fib6_del(struct rt6_info
*rt
, struct nl_info
*info
)
1352 struct net
*net
= info
->nl_net
;
1353 struct fib6_node
*fn
= rt
->rt6i_node
;
1354 struct rt6_info
**rtp
;
1357 if (rt
->dst
.obsolete
> 0) {
1358 WARN_ON(fn
!= NULL
);
1362 if (!fn
|| rt
== net
->ipv6
.ip6_null_entry
)
1365 WARN_ON(!(fn
->fn_flags
& RTN_RTINFO
));
1367 if (!(rt
->rt6i_flags
& RTF_CACHE
)) {
1368 struct fib6_node
*pn
= fn
;
1369 #ifdef CONFIG_IPV6_SUBTREES
1370 /* clones of this route might be in another subtree */
1371 if (rt
->rt6i_src
.plen
) {
1372 while (!(pn
->fn_flags
& RTN_ROOT
))
1377 fib6_prune_clones(info
->nl_net
, pn
);
1381 * Walk the leaf entries looking for ourself
1384 for (rtp
= &fn
->leaf
; *rtp
; rtp
= &(*rtp
)->dst
.rt6_next
) {
1386 fib6_del_route(fn
, rtp
, info
);
1394 * Tree traversal function.
1396 * Certainly, it is not interrupt safe.
1397 * However, it is internally reenterable wrt itself and fib6_add/fib6_del.
1398 * It means, that we can modify tree during walking
1399 * and use this function for garbage collection, clone pruning,
1400 * cleaning tree when a device goes down etc. etc.
1402 * It guarantees that every node will be traversed,
1403 * and that it will be traversed only once.
1405 * Callback function w->func may return:
1406 * 0 -> continue walking.
1407 * positive value -> walking is suspended (used by tree dumps,
1408 * and probably by gc, if it will be split to several slices)
1409 * negative value -> terminate walking.
1411 * The function itself returns:
1412 * 0 -> walk is complete.
1413 * >0 -> walk is incomplete (i.e. suspended)
1414 * <0 -> walk is terminated by an error.
1417 static int fib6_walk_continue(struct fib6_walker_t
*w
)
1419 struct fib6_node
*fn
, *pn
;
1426 if (w
->prune
&& fn
!= w
->root
&&
1427 fn
->fn_flags
& RTN_RTINFO
&& w
->state
< FWS_C
) {
1432 #ifdef CONFIG_IPV6_SUBTREES
1434 if (FIB6_SUBTREE(fn
)) {
1435 w
->node
= FIB6_SUBTREE(fn
);
1443 w
->state
= FWS_INIT
;
1449 w
->node
= fn
->right
;
1450 w
->state
= FWS_INIT
;
1456 if (w
->leaf
&& fn
->fn_flags
& RTN_RTINFO
) {
1478 #ifdef CONFIG_IPV6_SUBTREES
1479 if (FIB6_SUBTREE(pn
) == fn
) {
1480 WARN_ON(!(fn
->fn_flags
& RTN_ROOT
));
1485 if (pn
->left
== fn
) {
1489 if (pn
->right
== fn
) {
1491 w
->leaf
= w
->node
->leaf
;
1501 static int fib6_walk(struct fib6_walker_t
*w
)
1505 w
->state
= FWS_INIT
;
1508 fib6_walker_link(w
);
1509 res
= fib6_walk_continue(w
);
1511 fib6_walker_unlink(w
);
1515 static int fib6_clean_node(struct fib6_walker_t
*w
)
1518 struct rt6_info
*rt
;
1519 struct fib6_cleaner_t
*c
= container_of(w
, struct fib6_cleaner_t
, w
);
1520 struct nl_info info
= {
1524 for (rt
= w
->leaf
; rt
; rt
= rt
->dst
.rt6_next
) {
1525 res
= c
->func(rt
, c
->arg
);
1528 res
= fib6_del(rt
, &info
);
1531 pr_debug("%s: del failed: rt=%p@%p err=%d\n",
1532 __func__
, rt
, rt
->rt6i_node
, res
);
1545 * Convenient frontend to tree walker.
1547 * func is called on each route.
1548 * It may return -1 -> delete this route.
1549 * 0 -> continue walking
1551 * prune==1 -> only immediate children of node (certainly,
1552 * ignoring pure split nodes) will be scanned.
1555 static void fib6_clean_tree(struct net
*net
, struct fib6_node
*root
,
1556 int (*func
)(struct rt6_info
*, void *arg
),
1557 int prune
, void *arg
)
1559 struct fib6_cleaner_t c
;
1562 c
.w
.func
= fib6_clean_node
;
1573 void fib6_clean_all(struct net
*net
, int (*func
)(struct rt6_info
*, void *arg
),
1576 struct fib6_table
*table
;
1577 struct hlist_head
*head
;
1581 for (h
= 0; h
< FIB6_TABLE_HASHSZ
; h
++) {
1582 head
= &net
->ipv6
.fib_table_hash
[h
];
1583 hlist_for_each_entry_rcu(table
, head
, tb6_hlist
) {
1584 write_lock_bh(&table
->tb6_lock
);
1585 fib6_clean_tree(net
, &table
->tb6_root
,
1587 write_unlock_bh(&table
->tb6_lock
);
1593 static int fib6_prune_clone(struct rt6_info
*rt
, void *arg
)
1595 if (rt
->rt6i_flags
& RTF_CACHE
) {
1596 RT6_TRACE("pruning clone %p\n", rt
);
1603 static void fib6_prune_clones(struct net
*net
, struct fib6_node
*fn
)
1605 fib6_clean_tree(net
, fn
, fib6_prune_clone
, 1, NULL
);
1609 * Garbage collection
1612 static struct fib6_gc_args
1618 static int fib6_age(struct rt6_info
*rt
, void *arg
)
1620 unsigned long now
= jiffies
;
1623 * check addrconf expiration here.
1624 * Routes are expired even if they are in use.
1626 * Also age clones. Note, that clones are aged out
1627 * only if they are not in use now.
1630 if (rt
->rt6i_flags
& RTF_EXPIRES
&& rt
->dst
.expires
) {
1631 if (time_after(now
, rt
->dst
.expires
)) {
1632 RT6_TRACE("expiring %p\n", rt
);
1636 } else if (rt
->rt6i_flags
& RTF_CACHE
) {
1637 if (atomic_read(&rt
->dst
.__refcnt
) == 0 &&
1638 time_after_eq(now
, rt
->dst
.lastuse
+ gc_args
.timeout
)) {
1639 RT6_TRACE("aging clone %p\n", rt
);
1641 } else if (rt
->rt6i_flags
& RTF_GATEWAY
) {
1642 struct neighbour
*neigh
;
1643 __u8 neigh_flags
= 0;
1645 neigh
= dst_neigh_lookup(&rt
->dst
, &rt
->rt6i_gateway
);
1647 neigh_flags
= neigh
->flags
;
1648 neigh_release(neigh
);
1650 if (!(neigh_flags
& NTF_ROUTER
)) {
1651 RT6_TRACE("purging route %p via non-router but gateway\n",
1662 static DEFINE_SPINLOCK(fib6_gc_lock
);
1664 void fib6_run_gc(unsigned long expires
, struct net
*net
, bool force
)
1669 spin_lock_bh(&fib6_gc_lock
);
1670 } else if (!spin_trylock_bh(&fib6_gc_lock
)) {
1671 mod_timer(&net
->ipv6
.ip6_fib_timer
, jiffies
+ HZ
);
1674 gc_args
.timeout
= expires
? (int)expires
:
1675 net
->ipv6
.sysctl
.ip6_rt_gc_interval
;
1677 gc_args
.more
= icmp6_dst_gc();
1679 fib6_clean_all(net
, fib6_age
, NULL
);
1681 net
->ipv6
.ip6_rt_last_gc
= now
;
1684 mod_timer(&net
->ipv6
.ip6_fib_timer
,
1686 + net
->ipv6
.sysctl
.ip6_rt_gc_interval
));
1688 del_timer(&net
->ipv6
.ip6_fib_timer
);
1689 spin_unlock_bh(&fib6_gc_lock
);
1692 static void fib6_gc_timer_cb(unsigned long arg
)
1694 fib6_run_gc(0, (struct net
*)arg
, true);
1697 static int __net_init
fib6_net_init(struct net
*net
)
1699 size_t size
= sizeof(struct hlist_head
) * FIB6_TABLE_HASHSZ
;
1701 setup_timer(&net
->ipv6
.ip6_fib_timer
, fib6_gc_timer_cb
, (unsigned long)net
);
1703 net
->ipv6
.rt6_stats
= kzalloc(sizeof(*net
->ipv6
.rt6_stats
), GFP_KERNEL
);
1704 if (!net
->ipv6
.rt6_stats
)
1707 /* Avoid false sharing : Use at least a full cache line */
1708 size
= max_t(size_t, size
, L1_CACHE_BYTES
);
1710 net
->ipv6
.fib_table_hash
= kzalloc(size
, GFP_KERNEL
);
1711 if (!net
->ipv6
.fib_table_hash
)
1714 net
->ipv6
.fib6_main_tbl
= kzalloc(sizeof(*net
->ipv6
.fib6_main_tbl
),
1716 if (!net
->ipv6
.fib6_main_tbl
)
1717 goto out_fib_table_hash
;
1719 net
->ipv6
.fib6_main_tbl
->tb6_id
= RT6_TABLE_MAIN
;
1720 net
->ipv6
.fib6_main_tbl
->tb6_root
.leaf
= net
->ipv6
.ip6_null_entry
;
1721 net
->ipv6
.fib6_main_tbl
->tb6_root
.fn_flags
=
1722 RTN_ROOT
| RTN_TL_ROOT
| RTN_RTINFO
;
1723 inet_peer_base_init(&net
->ipv6
.fib6_main_tbl
->tb6_peers
);
1725 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
1726 net
->ipv6
.fib6_local_tbl
= kzalloc(sizeof(*net
->ipv6
.fib6_local_tbl
),
1728 if (!net
->ipv6
.fib6_local_tbl
)
1729 goto out_fib6_main_tbl
;
1730 net
->ipv6
.fib6_local_tbl
->tb6_id
= RT6_TABLE_LOCAL
;
1731 net
->ipv6
.fib6_local_tbl
->tb6_root
.leaf
= net
->ipv6
.ip6_null_entry
;
1732 net
->ipv6
.fib6_local_tbl
->tb6_root
.fn_flags
=
1733 RTN_ROOT
| RTN_TL_ROOT
| RTN_RTINFO
;
1734 inet_peer_base_init(&net
->ipv6
.fib6_local_tbl
->tb6_peers
);
1736 fib6_tables_init(net
);
1740 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
1742 kfree(net
->ipv6
.fib6_main_tbl
);
1745 kfree(net
->ipv6
.fib_table_hash
);
1747 kfree(net
->ipv6
.rt6_stats
);
1752 static void fib6_net_exit(struct net
*net
)
1754 rt6_ifdown(net
, NULL
);
1755 del_timer_sync(&net
->ipv6
.ip6_fib_timer
);
1757 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
1758 inetpeer_invalidate_tree(&net
->ipv6
.fib6_local_tbl
->tb6_peers
);
1759 kfree(net
->ipv6
.fib6_local_tbl
);
1761 inetpeer_invalidate_tree(&net
->ipv6
.fib6_main_tbl
->tb6_peers
);
1762 kfree(net
->ipv6
.fib6_main_tbl
);
1763 kfree(net
->ipv6
.fib_table_hash
);
1764 kfree(net
->ipv6
.rt6_stats
);
1767 static struct pernet_operations fib6_net_ops
= {
1768 .init
= fib6_net_init
,
1769 .exit
= fib6_net_exit
,
1772 int __init
fib6_init(void)
1776 fib6_node_kmem
= kmem_cache_create("fib6_nodes",
1777 sizeof(struct fib6_node
),
1778 0, SLAB_HWCACHE_ALIGN
,
1780 if (!fib6_node_kmem
)
1783 ret
= register_pernet_subsys(&fib6_net_ops
);
1785 goto out_kmem_cache_create
;
1787 ret
= __rtnl_register(PF_INET6
, RTM_GETROUTE
, NULL
, inet6_dump_fib
,
1790 goto out_unregister_subsys
;
1794 out_unregister_subsys
:
1795 unregister_pernet_subsys(&fib6_net_ops
);
1796 out_kmem_cache_create
:
1797 kmem_cache_destroy(fib6_node_kmem
);
1801 void fib6_gc_cleanup(void)
1803 unregister_pernet_subsys(&fib6_net_ops
);
1804 kmem_cache_destroy(fib6_node_kmem
);
1807 #ifdef CONFIG_PROC_FS
1809 struct ipv6_route_iter
{
1810 struct seq_net_private p
;
1811 struct fib6_walker_t w
;
1813 struct fib6_table
*tbl
;
1817 static int ipv6_route_seq_show(struct seq_file
*seq
, void *v
)
1819 struct rt6_info
*rt
= v
;
1820 struct ipv6_route_iter
*iter
= seq
->private;
1822 seq_printf(seq
, "%pi6 %02x ", &rt
->rt6i_dst
.addr
, rt
->rt6i_dst
.plen
);
1824 #ifdef CONFIG_IPV6_SUBTREES
1825 seq_printf(seq
, "%pi6 %02x ", &rt
->rt6i_src
.addr
, rt
->rt6i_src
.plen
);
1827 seq_puts(seq
, "00000000000000000000000000000000 00 ");
1829 if (rt
->rt6i_flags
& RTF_GATEWAY
)
1830 seq_printf(seq
, "%pi6", &rt
->rt6i_gateway
);
1832 seq_puts(seq
, "00000000000000000000000000000000");
1834 seq_printf(seq
, " %08x %08x %08x %08x %8s\n",
1835 rt
->rt6i_metric
, atomic_read(&rt
->dst
.__refcnt
),
1836 rt
->dst
.__use
, rt
->rt6i_flags
,
1837 rt
->dst
.dev
? rt
->dst
.dev
->name
: "");
1838 iter
->w
.leaf
= NULL
;
1842 static int ipv6_route_yield(struct fib6_walker_t
*w
)
1844 struct ipv6_route_iter
*iter
= w
->args
;
1850 iter
->w
.leaf
= iter
->w
.leaf
->dst
.rt6_next
;
1852 if (!iter
->skip
&& iter
->w
.leaf
)
1854 } while (iter
->w
.leaf
);
1859 static void ipv6_route_seq_setup_walk(struct ipv6_route_iter
*iter
)
1861 memset(&iter
->w
, 0, sizeof(iter
->w
));
1862 iter
->w
.func
= ipv6_route_yield
;
1863 iter
->w
.root
= &iter
->tbl
->tb6_root
;
1864 iter
->w
.state
= FWS_INIT
;
1865 iter
->w
.node
= iter
->w
.root
;
1866 iter
->w
.args
= iter
;
1867 iter
->sernum
= iter
->w
.root
->fn_sernum
;
1868 INIT_LIST_HEAD(&iter
->w
.lh
);
1869 fib6_walker_link(&iter
->w
);
1872 static struct fib6_table
*ipv6_route_seq_next_table(struct fib6_table
*tbl
,
1876 struct hlist_node
*node
;
1879 h
= (tbl
->tb6_id
& (FIB6_TABLE_HASHSZ
- 1)) + 1;
1880 node
= rcu_dereference_bh(hlist_next_rcu(&tbl
->tb6_hlist
));
1886 while (!node
&& h
< FIB6_TABLE_HASHSZ
) {
1887 node
= rcu_dereference_bh(
1888 hlist_first_rcu(&net
->ipv6
.fib_table_hash
[h
++]));
1890 return hlist_entry_safe(node
, struct fib6_table
, tb6_hlist
);
1893 static void ipv6_route_check_sernum(struct ipv6_route_iter
*iter
)
1895 if (iter
->sernum
!= iter
->w
.root
->fn_sernum
) {
1896 iter
->sernum
= iter
->w
.root
->fn_sernum
;
1897 iter
->w
.state
= FWS_INIT
;
1898 iter
->w
.node
= iter
->w
.root
;
1899 WARN_ON(iter
->w
.skip
);
1900 iter
->w
.skip
= iter
->w
.count
;
1904 static void *ipv6_route_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1908 struct net
*net
= seq_file_net(seq
);
1909 struct ipv6_route_iter
*iter
= seq
->private;
1914 n
= ((struct rt6_info
*)v
)->dst
.rt6_next
;
1921 ipv6_route_check_sernum(iter
);
1922 read_lock(&iter
->tbl
->tb6_lock
);
1923 r
= fib6_walk_continue(&iter
->w
);
1924 read_unlock(&iter
->tbl
->tb6_lock
);
1928 return iter
->w
.leaf
;
1930 fib6_walker_unlink(&iter
->w
);
1933 fib6_walker_unlink(&iter
->w
);
1935 iter
->tbl
= ipv6_route_seq_next_table(iter
->tbl
, net
);
1939 ipv6_route_seq_setup_walk(iter
);
1943 static void *ipv6_route_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1946 struct net
*net
= seq_file_net(seq
);
1947 struct ipv6_route_iter
*iter
= seq
->private;
1950 iter
->tbl
= ipv6_route_seq_next_table(NULL
, net
);
1954 ipv6_route_seq_setup_walk(iter
);
1955 return ipv6_route_seq_next(seq
, NULL
, pos
);
1961 static bool ipv6_route_iter_active(struct ipv6_route_iter
*iter
)
1963 struct fib6_walker_t
*w
= &iter
->w
;
1964 return w
->node
&& !(w
->state
== FWS_U
&& w
->node
== w
->root
);
1967 static void ipv6_route_seq_stop(struct seq_file
*seq
, void *v
)
1970 struct ipv6_route_iter
*iter
= seq
->private;
1972 if (ipv6_route_iter_active(iter
))
1973 fib6_walker_unlink(&iter
->w
);
1975 rcu_read_unlock_bh();
1978 static const struct seq_operations ipv6_route_seq_ops
= {
1979 .start
= ipv6_route_seq_start
,
1980 .next
= ipv6_route_seq_next
,
1981 .stop
= ipv6_route_seq_stop
,
1982 .show
= ipv6_route_seq_show
1985 int ipv6_route_open(struct inode
*inode
, struct file
*file
)
1987 return seq_open_net(inode
, file
, &ipv6_route_seq_ops
,
1988 sizeof(struct ipv6_route_iter
));
1991 #endif /* CONFIG_PROC_FS */