blob: 0e79c3408569a94be3e85badb3cea9fb33dcc9ae [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Linux INET6 implementation
3 *
4 * Authors:
5 * Pedro Roque <roque@di.fc.ul.pt>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#ifndef _IP6_FIB_H
14#define _IP6_FIB_H
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/ipv6_route.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/rtnetlink.h>
18#include <linux/spinlock.h>
Ido Schimmel16ab6d72017-08-03 13:28:16 +020019#include <linux/notifier.h>
Thomas Graf86872cb2006-08-22 00:01:08 -070020#include <net/dst.h>
21#include <net/flow.h>
22#include <net/netlink.h>
David S. Millerb3419362010-11-30 12:27:11 -080023#include <net/inetpeer.h>
Ido Schimmel16ab6d72017-08-03 13:28:16 +020024#include <net/fib_notifier.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Neil Hormana33bc5c2009-07-30 18:52:15 -070026#ifdef CONFIG_IPV6_MULTIPLE_TABLES
27#define FIB6_TABLE_HASHSZ 256
28#else
29#define FIB6_TABLE_HASHSZ 1
30#endif
31
Wei Wangc757faa2017-10-06 12:06:01 -070032#define RT6_DEBUG 2
33
34#if RT6_DEBUG >= 3
35#define RT6_TRACE(x...) pr_debug(x)
36#else
37#define RT6_TRACE(x...) do { ; } while (0)
38#endif
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040struct rt6_info;
41
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000042struct fib6_config {
Thomas Graf86872cb2006-08-22 00:01:08 -070043 u32 fc_table;
44 u32 fc_metric;
45 int fc_dst_len;
46 int fc_src_len;
47 int fc_ifindex;
48 u32 fc_flags;
49 u32 fc_protocol;
David Ahern0ae81332017-02-02 12:37:08 -080050 u16 fc_type; /* only 8 bits are used */
51 u16 fc_delete_all_nh : 1,
52 __unused : 15;
Thomas Graf86872cb2006-08-22 00:01:08 -070053
54 struct in6_addr fc_dst;
55 struct in6_addr fc_src;
Daniel Walterc3968a82011-04-13 21:10:57 +000056 struct in6_addr fc_prefsrc;
Thomas Graf86872cb2006-08-22 00:01:08 -070057 struct in6_addr fc_gateway;
58
59 unsigned long fc_expires;
60 struct nlattr *fc_mx;
61 int fc_mx_len;
Nicolas Dichtel51ebd312012-10-22 03:42:09 +000062 int fc_mp_len;
63 struct nlattr *fc_mp;
Thomas Graf86872cb2006-08-22 00:01:08 -070064
65 struct nl_info fc_nlinfo;
Roopa Prabhu19e42e42015-07-21 10:43:48 +020066 struct nlattr *fc_encap;
67 u16 fc_encap_type;
Thomas Graf86872cb2006-08-22 00:01:08 -070068};
69
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000070struct fib6_node {
Wei Wang66f5d6c2017-10-06 12:06:10 -070071 struct fib6_node __rcu *parent;
72 struct fib6_node __rcu *left;
73 struct fib6_node __rcu *right;
Kim Nordlund8bce65b2006-12-13 16:38:29 -080074#ifdef CONFIG_IPV6_SUBTREES
Wei Wang66f5d6c2017-10-06 12:06:10 -070075 struct fib6_node __rcu *subtree;
Kim Nordlund8bce65b2006-12-13 16:38:29 -080076#endif
Wei Wang66f5d6c2017-10-06 12:06:10 -070077 struct rt6_info __rcu *leaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 __u16 fn_bit; /* bit key */
80 __u16 fn_flags;
Hannes Frederic Sowa42b18702014-10-06 19:58:35 +020081 int fn_sernum;
Wei Wang66f5d6c2017-10-06 12:06:10 -070082 struct rt6_info __rcu *rr_ptr;
Wei Wangc5cff852017-08-21 09:47:10 -070083 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084};
85
Wei Wangc757faa2017-10-06 12:06:01 -070086struct fib6_gc_args {
87 int timeout;
88 int more;
89};
90
YOSHIFUJI Hideaki7fc33162006-08-23 17:22:24 -070091#ifndef CONFIG_IPV6_SUBTREES
92#define FIB6_SUBTREE(fn) NULL
93#else
Wei Wang66f5d6c2017-10-06 12:06:10 -070094#define FIB6_SUBTREE(fn) (rcu_dereference_protected((fn)->subtree, 1))
YOSHIFUJI Hideaki7fc33162006-08-23 17:22:24 -070095#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Florian Westphale715b6d2015-01-05 23:57:44 +010097struct mx6_config {
98 const u32 *mx;
99 DECLARE_BITMAP(mx_valid, RTAX_MAX);
100};
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/*
103 * routing information
104 *
105 */
106
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000107struct rt6key {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 struct in6_addr addr;
109 int plen;
110};
111
Thomas Grafc71099a2006-08-04 23:20:06 -0700112struct fib6_table;
113
Wei Wang35732d02017-10-06 12:05:57 -0700114struct rt6_exception_bucket {
115 struct hlist_head chain;
116 int depth;
117};
118
119struct rt6_exception {
120 struct hlist_node hlist;
121 struct rt6_info *rt6i;
122 unsigned long stamp;
123 struct rcu_head rcu;
124};
125
126#define FIB6_EXCEPTION_BUCKET_SIZE_SHIFT 10
127#define FIB6_EXCEPTION_BUCKET_SIZE (1 << FIB6_EXCEPTION_BUCKET_SIZE_SHIFT)
128#define FIB6_MAX_DEPTH 5
129
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000130struct rt6_info {
Changli Gaod8d1f302010-06-10 23:31:35 -0700131 struct dst_entry dst;
David Miller071fb372017-11-28 15:40:15 -0500132 struct rt6_info __rcu *rt6_next;
David Miller3a2232e2017-11-28 15:40:40 -0500133 struct rt6_info *from;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000135 /*
136 * Tail elements of dst_entry (__refcnt etc.)
137 * and these elements (rarely used in hot path) are in
138 * the same cache line.
139 */
140 struct fib6_table *rt6i_table;
Wei Wang4e587ea2017-08-25 15:03:10 -0700141 struct fib6_node __rcu *rt6i_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 struct in6_addr rt6i_gateway;
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000144
Nicolas Dichtel51ebd312012-10-22 03:42:09 +0000145 /* Multipath routes:
146 * siblings is a list of rt6_info that have the the same metric/weight,
147 * destination, but not the same gateway. nsiblings is just a cache
148 * to speed up lookup.
149 */
150 struct list_head rt6i_siblings;
151 unsigned int rt6i_nsiblings;
Ido Schimmeld7dedee2018-01-09 16:40:25 +0200152 atomic_t rt6i_nh_upper_bound;
Nicolas Dichtel51ebd312012-10-22 03:42:09 +0000153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 atomic_t rt6i_ref;
Herbert Xub4ce9272007-11-13 21:33:32 -0800155
Ido Schimmelfe400792017-08-15 09:09:49 +0200156 unsigned int rt6i_nh_flags;
157
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000158 /* These are in a separate cache line. */
159 struct rt6key rt6i_dst ____cacheline_aligned_in_smp;
160 u32 rt6i_flags;
161 struct rt6key rt6i_src;
Daniel Walterc3968a82011-04-13 21:10:57 +0000162 struct rt6key rt6i_prefsrc;
Herbert Xub4ce9272007-11-13 21:33:32 -0800163
Martin KaFai Lau8d0b94a2015-05-22 20:56:04 -0700164 struct list_head rt6i_uncached;
165 struct uncached_list *rt6i_uncached_list;
166
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000167 struct inet6_dev *rt6i_idev;
Martin KaFai Laud52d3992015-05-22 20:56:06 -0700168 struct rt6_info * __percpu *rt6i_pcpu;
Wei Wang35732d02017-10-06 12:05:57 -0700169 struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
Noriaki TAKAMIYAa47ed4c2007-09-06 03:31:25 -0700170
Hannes Frederic Sowa705f1c82014-09-28 00:46:06 +0200171 u32 rt6i_metric;
Martin KaFai Lau4b32b5a2015-04-28 13:03:06 -0700172 u32 rt6i_pmtu;
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000173 /* more non-fragment space at head required */
Ido Schimmel398958a2018-01-09 16:40:28 +0200174 int rt6i_nh_weight;
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000175 unsigned short rt6i_nfheader_len;
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000176 u8 rt6i_protocol;
Wei Wang35732d02017-10-06 12:05:57 -0700177 u8 exception_bucket_flushed:1,
Ido Schimmela2c554d2018-01-07 12:45:11 +0200178 should_flush:1,
179 unused:6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180};
181
Wei Wang66f5d6c2017-10-06 12:06:10 -0700182#define for_each_fib6_node_rt_rcu(fn) \
183 for (rt = rcu_dereference((fn)->leaf); rt; \
David Miller071fb372017-11-28 15:40:15 -0500184 rt = rcu_dereference(rt->rt6_next))
Wei Wang66f5d6c2017-10-06 12:06:10 -0700185
186#define for_each_fib6_walker_rt(w) \
187 for (rt = (w)->leaf; rt; \
David Miller071fb372017-11-28 15:40:15 -0500188 rt = rcu_dereference_protected(rt->rt6_next, 1))
Wei Wang66f5d6c2017-10-06 12:06:10 -0700189
YOSHIFUJI Hideaki7a3025b2006-10-13 16:17:25 +0900190static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
191{
192 return ((struct rt6_info *)dst)->rt6i_idev;
193}
194
Gao feng1716a962012-04-06 00:13:10 +0000195static inline void rt6_clean_expires(struct rt6_info *rt)
196{
Gao feng1716a962012-04-06 00:13:10 +0000197 rt->rt6i_flags &= ~RTF_EXPIRES;
Hannes Frederic Sowa01ba16d2013-10-24 10:14:27 +0200198 rt->dst.expires = 0;
Gao feng1716a962012-04-06 00:13:10 +0000199}
200
201static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires)
202{
Gao feng1716a962012-04-06 00:13:10 +0000203 rt->dst.expires = expires;
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000204 rt->rt6i_flags |= RTF_EXPIRES;
Gao feng1716a962012-04-06 00:13:10 +0000205}
206
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000207static inline void rt6_update_expires(struct rt6_info *rt0, int timeout)
Gao feng1716a962012-04-06 00:13:10 +0000208{
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000209 struct rt6_info *rt;
Gao feng1716a962012-04-06 00:13:10 +0000210
David Miller3a2232e2017-11-28 15:40:40 -0500211 for (rt = rt0; rt && !(rt->rt6i_flags & RTF_EXPIRES); rt = rt->from);
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000212 if (rt && rt != rt0)
213 rt0->dst.expires = rt->dst.expires;
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000214 dst_set_expires(&rt0->dst, timeout);
215 rt0->rt6i_flags |= RTF_EXPIRES;
Gao feng1716a962012-04-06 00:13:10 +0000216}
217
Wei Wangc5cff852017-08-21 09:47:10 -0700218/* Function to safely get fn->sernum for passed in rt
219 * and store result in passed in cookie.
220 * Return true if we can get cookie safely
221 * Return false if not
222 */
223static inline bool rt6_get_cookie_safe(const struct rt6_info *rt,
224 u32 *cookie)
225{
226 struct fib6_node *fn;
227 bool status = false;
228
229 rcu_read_lock();
230 fn = rcu_dereference(rt->rt6i_node);
231
232 if (fn) {
233 *cookie = fn->fn_sernum;
Wei Wangbbd63f02017-10-06 12:06:07 -0700234 /* pairs with smp_wmb() in fib6_update_sernum_upto_root() */
235 smp_rmb();
Wei Wangc5cff852017-08-21 09:47:10 -0700236 status = true;
237 }
238
239 rcu_read_unlock();
240 return status;
241}
242
Martin KaFai Laub197df42015-05-22 20:56:01 -0700243static inline u32 rt6_get_cookie(const struct rt6_info *rt)
244{
Wei Wangc5cff852017-08-21 09:47:10 -0700245 u32 cookie = 0;
246
Martin KaFai Lau02bcf4e2015-11-11 11:51:08 -0800247 if (rt->rt6i_flags & RTF_PCPU ||
David Miller3a2232e2017-11-28 15:40:40 -0500248 (unlikely(!list_empty(&rt->rt6i_uncached)) && rt->from))
249 rt = rt->from;
Martin KaFai Lau3da59bd2015-05-22 20:56:03 -0700250
Wei Wangc5cff852017-08-21 09:47:10 -0700251 rt6_get_cookie_safe(rt, &cookie);
252
253 return cookie;
Martin KaFai Laub197df42015-05-22 20:56:01 -0700254}
255
Amerigo Wang94e187c2012-10-29 00:13:19 +0000256static inline void ip6_rt_put(struct rt6_info *rt)
257{
258 /* dst_release() accepts a NULL parameter.
259 * We rely on dst being first structure in struct rt6_info
260 */
261 BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
262 dst_release(&rt->dst);
263}
264
Ido Schimmela460aa82017-08-03 13:28:25 +0200265void rt6_free_pcpu(struct rt6_info *non_pcpu_rt);
266
267static inline void rt6_hold(struct rt6_info *rt)
268{
269 atomic_inc(&rt->rt6i_ref);
270}
271
272static inline void rt6_release(struct rt6_info *rt)
273{
274 if (atomic_dec_and_test(&rt->rt6i_ref)) {
275 rt6_free_pcpu(rt);
276 dst_dev_put(&rt->dst);
277 dst_release(&rt->dst);
278 }
279}
280
Hannes Frederic Sowa94b2cfe2014-10-06 19:58:34 +0200281enum fib6_walk_state {
282#ifdef CONFIG_IPV6_SUBTREES
283 FWS_S,
284#endif
285 FWS_L,
286 FWS_R,
287 FWS_C,
288 FWS_U
289};
290
291struct fib6_walker {
Alexey Dobriyanbbef49d2010-02-18 08:13:30 +0000292 struct list_head lh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct fib6_node *root, *node;
294 struct rt6_info *leaf;
Hannes Frederic Sowa94b2cfe2014-10-06 19:58:34 +0200295 enum fib6_walk_state state;
Patrick McHardy2bec5a32010-02-08 05:19:03 +0000296 unsigned int skip;
297 unsigned int count;
Hannes Frederic Sowa94b2cfe2014-10-06 19:58:34 +0200298 int (*func)(struct fib6_walker *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 void *args;
300};
301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302struct rt6_statistics {
Wei Wang81eb8442017-10-06 12:06:11 -0700303 __u32 fib_nodes; /* all fib6 nodes */
304 __u32 fib_route_nodes; /* intermediate nodes */
305 __u32 fib_rt_entries; /* rt entries in fib table */
306 __u32 fib_rt_cache; /* cached rt entries in exception table */
307 __u32 fib_discarded_routes; /* total number of routes delete */
308
309 /* The following stats are not protected by any lock */
310 atomic_t fib_rt_alloc; /* total number of routes alloced */
311 atomic_t fib_rt_uncache; /* rt entries in uncached list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312};
313
314#define RTN_TL_ROOT 0x0001
315#define RTN_ROOT 0x0002 /* tree root node */
316#define RTN_RTINFO 0x0004 /* node with valid routing info */
317
318/*
319 * priority levels (or metrics)
320 *
321 */
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Thomas Grafc71099a2006-08-04 23:20:06 -0700324struct fib6_table {
325 struct hlist_node tb6_hlist;
326 u32 tb6_id;
Wei Wang66f5d6c2017-10-06 12:06:10 -0700327 spinlock_t tb6_lock;
Thomas Grafc71099a2006-08-04 23:20:06 -0700328 struct fib6_node tb6_root;
David S. Miller8e773272012-06-11 00:01:52 -0700329 struct inet_peer_base tb6_peers;
David Ahern830218c2016-10-24 10:52:35 -0700330 unsigned int flags;
Ido Schimmele1ee0a52017-08-03 13:28:19 +0200331 unsigned int fib_seq;
David Ahern830218c2016-10-24 10:52:35 -0700332#define RT6_TABLE_HAS_DFLT_ROUTER BIT(0)
Thomas Grafc71099a2006-08-04 23:20:06 -0700333};
334
335#define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
336#define RT6_TABLE_MAIN RT_TABLE_MAIN
Thomas Grafc71099a2006-08-04 23:20:06 -0700337#define RT6_TABLE_DFLT RT6_TABLE_MAIN
338#define RT6_TABLE_INFO RT6_TABLE_MAIN
339#define RT6_TABLE_PREFIX RT6_TABLE_MAIN
340
341#ifdef CONFIG_IPV6_MULTIPLE_TABLES
342#define FIB6_TABLE_MIN 1
343#define FIB6_TABLE_MAX RT_TABLE_MAX
Thomas Graf101367c2006-08-04 03:39:02 -0700344#define RT6_TABLE_LOCAL RT_TABLE_LOCAL
Thomas Grafc71099a2006-08-04 23:20:06 -0700345#else
346#define FIB6_TABLE_MIN RT_TABLE_MAIN
347#define FIB6_TABLE_MAX FIB6_TABLE_MIN
Thomas Graf101367c2006-08-04 03:39:02 -0700348#define RT6_TABLE_LOCAL RT6_TABLE_MAIN
Thomas Grafc71099a2006-08-04 23:20:06 -0700349#endif
350
Daniel Lezcano8ed67782008-03-04 13:48:30 -0800351typedef struct rt6_info *(*pol_lookup_t)(struct net *,
352 struct fib6_table *,
David Ahernb75cc8f2018-03-02 08:32:17 -0800353 struct flowi6 *,
354 const struct sk_buff *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Ido Schimmeldf77fe42017-08-03 13:28:17 +0200356struct fib6_entry_notifier_info {
357 struct fib_notifier_info info; /* must be first */
358 struct rt6_info *rt;
359};
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361/*
362 * exported functions
363 */
364
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700365struct fib6_table *fib6_get_table(struct net *net, u32 id);
366struct fib6_table *fib6_new_table(struct net *net, u32 id);
367struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
David Ahernb75cc8f2018-03-02 08:32:17 -0800368 const struct sk_buff *skb,
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700369 int flags, pol_lookup_t lookup);
Thomas Grafc71099a2006-08-04 23:20:06 -0700370
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700371struct fib6_node *fib6_lookup(struct fib6_node *root,
372 const struct in6_addr *daddr,
373 const struct in6_addr *saddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700375struct fib6_node *fib6_locate(struct fib6_node *root,
376 const struct in6_addr *daddr, int dst_len,
Wei Wang38fbeee2017-10-06 12:06:02 -0700377 const struct in6_addr *saddr, int src_len,
378 bool exact_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700380void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
Li RongQing0c3584d2013-12-27 16:32:38 +0800381 void *arg);
Thomas Grafc71099a2006-08-04 23:20:06 -0700382
Florian Westphale715b6d2015-01-05 23:57:44 +0100383int fib6_add(struct fib6_node *root, struct rt6_info *rt,
David Ahern333c4302017-05-21 10:12:04 -0600384 struct nl_info *info, struct mx6_config *mxc,
385 struct netlink_ext_ack *extack);
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700386int fib6_del(struct rt6_info *rt, struct nl_info *info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Roopa Prabhu37a1d362015-09-13 10:18:33 -0700388void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info,
389 unsigned int flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700391void fib6_run_gc(unsigned long expires, struct net *net, bool force);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700393void fib6_gc_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700395int fib6_init(void);
Thomas Graf101367c2006-08-04 03:39:02 -0700396
Christoph Hellwigc3506372018-04-10 19:42:55 +0200397struct ipv6_route_iter {
398 struct seq_net_private p;
399 struct fib6_walker w;
400 loff_t skip;
401 struct fib6_table *tbl;
402 int sernum;
403};
404
405extern const struct seq_operations ipv6_route_seq_ops;
Hannes Frederic Sowa8d2ca1d2013-09-21 16:55:59 +0200406
Ido Schimmel16ab6d72017-08-03 13:28:16 +0200407int call_fib6_notifier(struct notifier_block *nb, struct net *net,
408 enum fib_event_type event_type,
409 struct fib_notifier_info *info);
410int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
411 struct fib_notifier_info *info);
412
413int __net_init fib6_notifier_init(struct net *net);
414void __net_exit fib6_notifier_exit(struct net *net);
415
Ido Schimmele1ee0a52017-08-03 13:28:19 +0200416unsigned int fib6_tables_seq_read(struct net *net);
417int fib6_tables_dump(struct net *net, struct notifier_block *nb);
418
Wei Wang180ca442017-10-06 12:05:56 -0700419void fib6_update_sernum(struct rt6_info *rt);
Ido Schimmel4a8e56e2018-01-07 12:45:13 +0200420void fib6_update_sernum_upto_root(struct net *net, struct rt6_info *rt);
Wei Wang180ca442017-10-06 12:05:56 -0700421
Daniel Lezcano7e5449c2007-12-08 00:14:54 -0800422#ifdef CONFIG_IPV6_MULTIPLE_TABLES
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700423int fib6_rules_init(void);
424void fib6_rules_cleanup(void);
Ido Schimmele3ea9732017-08-03 13:28:15 +0200425bool fib6_rule_default(const struct fib_rule *rule);
Ido Schimmeldcb18f72017-08-03 13:28:18 +0200426int fib6_rules_dump(struct net *net, struct notifier_block *nb);
427unsigned int fib6_rules_seq_read(struct net *net);
Roopa Prabhu5e5d6fe2018-02-28 22:43:22 -0500428
429static inline bool fib6_rules_early_flow_dissect(struct net *net,
430 struct sk_buff *skb,
431 struct flowi6 *fl6,
432 struct flow_keys *flkeys)
433{
434 unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
435
436 if (!net->ipv6.fib6_rules_require_fldissect)
437 return false;
438
439 skb_flow_dissect_flow_keys(skb, flkeys, flag);
440 fl6->fl6_sport = flkeys->ports.src;
441 fl6->fl6_dport = flkeys->ports.dst;
442 fl6->flowi6_proto = flkeys->basic.ip_proto;
443
444 return true;
445}
Daniel Lezcano7e5449c2007-12-08 00:14:54 -0800446#else
447static inline int fib6_rules_init(void)
448{
449 return 0;
450}
451static inline void fib6_rules_cleanup(void)
452{
453 return ;
454}
Ido Schimmele3ea9732017-08-03 13:28:15 +0200455static inline bool fib6_rule_default(const struct fib_rule *rule)
456{
457 return true;
458}
Ido Schimmeldcb18f72017-08-03 13:28:18 +0200459static inline int fib6_rules_dump(struct net *net, struct notifier_block *nb)
460{
461 return 0;
462}
463static inline unsigned int fib6_rules_seq_read(struct net *net)
464{
465 return 0;
466}
Roopa Prabhu5e5d6fe2018-02-28 22:43:22 -0500467static inline bool fib6_rules_early_flow_dissect(struct net *net,
468 struct sk_buff *skb,
469 struct flowi6 *fl6,
470 struct flow_keys *flkeys)
471{
472 return false;
473}
Daniel Lezcano7e5449c2007-12-08 00:14:54 -0800474#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475#endif