blob: 1f8dc9d12abb7b14a1f5041949a6ad0574194244 [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
97/*
98 * routing information
99 *
100 */
101
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000102struct rt6key {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 struct in6_addr addr;
104 int plen;
105};
106
Thomas Grafc71099a2006-08-04 23:20:06 -0700107struct fib6_table;
108
Wei Wang35732d02017-10-06 12:05:57 -0700109struct rt6_exception_bucket {
110 struct hlist_head chain;
111 int depth;
112};
113
114struct rt6_exception {
115 struct hlist_node hlist;
116 struct rt6_info *rt6i;
117 unsigned long stamp;
118 struct rcu_head rcu;
119};
120
121#define FIB6_EXCEPTION_BUCKET_SIZE_SHIFT 10
122#define FIB6_EXCEPTION_BUCKET_SIZE (1 << FIB6_EXCEPTION_BUCKET_SIZE_SHIFT)
123#define FIB6_MAX_DEPTH 5
124
David Ahern5e670d82018-04-17 17:33:14 -0700125struct fib6_nh {
126 struct in6_addr nh_gw;
127 struct net_device *nh_dev;
128 struct lwtunnel_state *nh_lwtstate;
129
130 unsigned int nh_flags;
131 atomic_t nh_upper_bound;
132 int nh_weight;
133};
134
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000135struct rt6_info {
Changli Gaod8d1f302010-06-10 23:31:35 -0700136 struct dst_entry dst;
David Miller071fb372017-11-28 15:40:15 -0500137 struct rt6_info __rcu *rt6_next;
David Miller3a2232e2017-11-28 15:40:40 -0500138 struct rt6_info *from;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000140 /*
141 * Tail elements of dst_entry (__refcnt etc.)
142 * and these elements (rarely used in hot path) are in
143 * the same cache line.
144 */
145 struct fib6_table *rt6i_table;
Wei Wang4e587ea2017-08-25 15:03:10 -0700146 struct fib6_node __rcu *rt6i_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 struct in6_addr rt6i_gateway;
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000149
Nicolas Dichtel51ebd312012-10-22 03:42:09 +0000150 /* Multipath routes:
151 * siblings is a list of rt6_info that have the the same metric/weight,
152 * destination, but not the same gateway. nsiblings is just a cache
153 * to speed up lookup.
154 */
155 struct list_head rt6i_siblings;
156 unsigned int rt6i_nsiblings;
157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 atomic_t rt6i_ref;
Herbert Xub4ce9272007-11-13 21:33:32 -0800159
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000160 /* These are in a separate cache line. */
161 struct rt6key rt6i_dst ____cacheline_aligned_in_smp;
162 u32 rt6i_flags;
163 struct rt6key rt6i_src;
Daniel Walterc3968a82011-04-13 21:10:57 +0000164 struct rt6key rt6i_prefsrc;
Herbert Xub4ce9272007-11-13 21:33:32 -0800165
Martin KaFai Lau8d0b94a2015-05-22 20:56:04 -0700166 struct list_head rt6i_uncached;
167 struct uncached_list *rt6i_uncached_list;
168
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000169 struct inet6_dev *rt6i_idev;
Martin KaFai Laud52d3992015-05-22 20:56:06 -0700170 struct rt6_info * __percpu *rt6i_pcpu;
Wei Wang35732d02017-10-06 12:05:57 -0700171 struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
Noriaki TAKAMIYAa47ed4c2007-09-06 03:31:25 -0700172
Hannes Frederic Sowa705f1c82014-09-28 00:46:06 +0200173 u32 rt6i_metric;
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000174 /* more non-fragment space at head required */
175 unsigned short rt6i_nfheader_len;
YOSHIFUJI Hideaki / 吉藤英明bd2c77a2010-03-31 22:24:22 +0000176 u8 rt6i_protocol;
David Aherne8478e82018-04-17 17:33:13 -0700177 u8 fib6_type;
Wei Wang35732d02017-10-06 12:05:57 -0700178 u8 exception_bucket_flushed:1,
Ido Schimmela2c554d2018-01-07 12:45:11 +0200179 should_flush:1,
180 unused:6;
David Ahern5e670d82018-04-17 17:33:14 -0700181
David Ahernd4ead6b2018-04-17 17:33:16 -0700182 struct dst_metrics *fib6_metrics;
183#define fib6_pmtu fib6_metrics->metrics[RTAX_MTU-1]
David Ahern5e670d82018-04-17 17:33:14 -0700184 struct fib6_nh fib6_nh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185};
186
Wei Wang66f5d6c2017-10-06 12:06:10 -0700187#define for_each_fib6_node_rt_rcu(fn) \
188 for (rt = rcu_dereference((fn)->leaf); rt; \
David Miller071fb372017-11-28 15:40:15 -0500189 rt = rcu_dereference(rt->rt6_next))
Wei Wang66f5d6c2017-10-06 12:06:10 -0700190
191#define for_each_fib6_walker_rt(w) \
192 for (rt = (w)->leaf; rt; \
David Miller071fb372017-11-28 15:40:15 -0500193 rt = rcu_dereference_protected(rt->rt6_next, 1))
Wei Wang66f5d6c2017-10-06 12:06:10 -0700194
YOSHIFUJI Hideaki7a3025b2006-10-13 16:17:25 +0900195static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
196{
197 return ((struct rt6_info *)dst)->rt6i_idev;
198}
199
Gao feng1716a962012-04-06 00:13:10 +0000200static inline void rt6_clean_expires(struct rt6_info *rt)
201{
Gao feng1716a962012-04-06 00:13:10 +0000202 rt->rt6i_flags &= ~RTF_EXPIRES;
Hannes Frederic Sowa01ba16d2013-10-24 10:14:27 +0200203 rt->dst.expires = 0;
Gao feng1716a962012-04-06 00:13:10 +0000204}
205
206static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires)
207{
Gao feng1716a962012-04-06 00:13:10 +0000208 rt->dst.expires = expires;
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000209 rt->rt6i_flags |= RTF_EXPIRES;
Gao feng1716a962012-04-06 00:13:10 +0000210}
211
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000212static inline void rt6_update_expires(struct rt6_info *rt0, int timeout)
Gao feng1716a962012-04-06 00:13:10 +0000213{
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000214 struct rt6_info *rt;
Gao feng1716a962012-04-06 00:13:10 +0000215
David Miller3a2232e2017-11-28 15:40:40 -0500216 for (rt = rt0; rt && !(rt->rt6i_flags & RTF_EXPIRES); rt = rt->from);
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000217 if (rt && rt != rt0)
218 rt0->dst.expires = rt->dst.expires;
YOSHIFUJI Hideaki / 吉藤英明ecd98832013-02-20 00:29:08 +0000219 dst_set_expires(&rt0->dst, timeout);
220 rt0->rt6i_flags |= RTF_EXPIRES;
Gao feng1716a962012-04-06 00:13:10 +0000221}
222
Wei Wangc5cff852017-08-21 09:47:10 -0700223/* Function to safely get fn->sernum for passed in rt
224 * and store result in passed in cookie.
225 * Return true if we can get cookie safely
226 * Return false if not
227 */
228static inline bool rt6_get_cookie_safe(const struct rt6_info *rt,
229 u32 *cookie)
230{
231 struct fib6_node *fn;
232 bool status = false;
233
234 rcu_read_lock();
235 fn = rcu_dereference(rt->rt6i_node);
236
237 if (fn) {
238 *cookie = fn->fn_sernum;
Wei Wangbbd63f02017-10-06 12:06:07 -0700239 /* pairs with smp_wmb() in fib6_update_sernum_upto_root() */
240 smp_rmb();
Wei Wangc5cff852017-08-21 09:47:10 -0700241 status = true;
242 }
243
244 rcu_read_unlock();
245 return status;
246}
247
Martin KaFai Laub197df42015-05-22 20:56:01 -0700248static inline u32 rt6_get_cookie(const struct rt6_info *rt)
249{
Wei Wangc5cff852017-08-21 09:47:10 -0700250 u32 cookie = 0;
251
Martin KaFai Lau02bcf4e2015-11-11 11:51:08 -0800252 if (rt->rt6i_flags & RTF_PCPU ||
David Miller3a2232e2017-11-28 15:40:40 -0500253 (unlikely(!list_empty(&rt->rt6i_uncached)) && rt->from))
254 rt = rt->from;
Martin KaFai Lau3da59bd2015-05-22 20:56:03 -0700255
Wei Wangc5cff852017-08-21 09:47:10 -0700256 rt6_get_cookie_safe(rt, &cookie);
257
258 return cookie;
Martin KaFai Laub197df42015-05-22 20:56:01 -0700259}
260
Amerigo Wang94e187c2012-10-29 00:13:19 +0000261static inline void ip6_rt_put(struct rt6_info *rt)
262{
263 /* dst_release() accepts a NULL parameter.
264 * We rely on dst being first structure in struct rt6_info
265 */
266 BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
267 dst_release(&rt->dst);
268}
269
Ido Schimmela460aa82017-08-03 13:28:25 +0200270void rt6_free_pcpu(struct rt6_info *non_pcpu_rt);
271
272static inline void rt6_hold(struct rt6_info *rt)
273{
274 atomic_inc(&rt->rt6i_ref);
275}
276
277static inline void rt6_release(struct rt6_info *rt)
278{
279 if (atomic_dec_and_test(&rt->rt6i_ref)) {
280 rt6_free_pcpu(rt);
281 dst_dev_put(&rt->dst);
282 dst_release(&rt->dst);
283 }
284}
285
Hannes Frederic Sowa94b2cfe2014-10-06 19:58:34 +0200286enum fib6_walk_state {
287#ifdef CONFIG_IPV6_SUBTREES
288 FWS_S,
289#endif
290 FWS_L,
291 FWS_R,
292 FWS_C,
293 FWS_U
294};
295
296struct fib6_walker {
Alexey Dobriyanbbef49d2010-02-18 08:13:30 +0000297 struct list_head lh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 struct fib6_node *root, *node;
299 struct rt6_info *leaf;
Hannes Frederic Sowa94b2cfe2014-10-06 19:58:34 +0200300 enum fib6_walk_state state;
Patrick McHardy2bec5a32010-02-08 05:19:03 +0000301 unsigned int skip;
302 unsigned int count;
Hannes Frederic Sowa94b2cfe2014-10-06 19:58:34 +0200303 int (*func)(struct fib6_walker *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 void *args;
305};
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307struct rt6_statistics {
Wei Wang81eb8442017-10-06 12:06:11 -0700308 __u32 fib_nodes; /* all fib6 nodes */
309 __u32 fib_route_nodes; /* intermediate nodes */
310 __u32 fib_rt_entries; /* rt entries in fib table */
311 __u32 fib_rt_cache; /* cached rt entries in exception table */
312 __u32 fib_discarded_routes; /* total number of routes delete */
313
314 /* The following stats are not protected by any lock */
315 atomic_t fib_rt_alloc; /* total number of routes alloced */
316 atomic_t fib_rt_uncache; /* rt entries in uncached list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317};
318
319#define RTN_TL_ROOT 0x0001
320#define RTN_ROOT 0x0002 /* tree root node */
321#define RTN_RTINFO 0x0004 /* node with valid routing info */
322
323/*
324 * priority levels (or metrics)
325 *
326 */
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Thomas Grafc71099a2006-08-04 23:20:06 -0700329struct fib6_table {
330 struct hlist_node tb6_hlist;
331 u32 tb6_id;
Wei Wang66f5d6c2017-10-06 12:06:10 -0700332 spinlock_t tb6_lock;
Thomas Grafc71099a2006-08-04 23:20:06 -0700333 struct fib6_node tb6_root;
David S. Miller8e773272012-06-11 00:01:52 -0700334 struct inet_peer_base tb6_peers;
David Ahern830218c2016-10-24 10:52:35 -0700335 unsigned int flags;
Ido Schimmele1ee0a52017-08-03 13:28:19 +0200336 unsigned int fib_seq;
David Ahern830218c2016-10-24 10:52:35 -0700337#define RT6_TABLE_HAS_DFLT_ROUTER BIT(0)
Thomas Grafc71099a2006-08-04 23:20:06 -0700338};
339
340#define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
341#define RT6_TABLE_MAIN RT_TABLE_MAIN
Thomas Grafc71099a2006-08-04 23:20:06 -0700342#define RT6_TABLE_DFLT RT6_TABLE_MAIN
343#define RT6_TABLE_INFO RT6_TABLE_MAIN
344#define RT6_TABLE_PREFIX RT6_TABLE_MAIN
345
346#ifdef CONFIG_IPV6_MULTIPLE_TABLES
347#define FIB6_TABLE_MIN 1
348#define FIB6_TABLE_MAX RT_TABLE_MAX
Thomas Graf101367c2006-08-04 03:39:02 -0700349#define RT6_TABLE_LOCAL RT_TABLE_LOCAL
Thomas Grafc71099a2006-08-04 23:20:06 -0700350#else
351#define FIB6_TABLE_MIN RT_TABLE_MAIN
352#define FIB6_TABLE_MAX FIB6_TABLE_MIN
Thomas Graf101367c2006-08-04 03:39:02 -0700353#define RT6_TABLE_LOCAL RT6_TABLE_MAIN
Thomas Grafc71099a2006-08-04 23:20:06 -0700354#endif
355
Daniel Lezcano8ed67782008-03-04 13:48:30 -0800356typedef struct rt6_info *(*pol_lookup_t)(struct net *,
357 struct fib6_table *,
David Ahernb75cc8f2018-03-02 08:32:17 -0800358 struct flowi6 *,
359 const struct sk_buff *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Ido Schimmeldf77fe42017-08-03 13:28:17 +0200361struct fib6_entry_notifier_info {
362 struct fib_notifier_info info; /* must be first */
363 struct rt6_info *rt;
364};
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366/*
367 * exported functions
368 */
369
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700370struct fib6_table *fib6_get_table(struct net *net, u32 id);
371struct fib6_table *fib6_new_table(struct net *net, u32 id);
372struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
David Ahernb75cc8f2018-03-02 08:32:17 -0800373 const struct sk_buff *skb,
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700374 int flags, pol_lookup_t lookup);
Thomas Grafc71099a2006-08-04 23:20:06 -0700375
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700376struct fib6_node *fib6_lookup(struct fib6_node *root,
377 const struct in6_addr *daddr,
378 const struct in6_addr *saddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700380struct fib6_node *fib6_locate(struct fib6_node *root,
381 const struct in6_addr *daddr, int dst_len,
Wei Wang38fbeee2017-10-06 12:06:02 -0700382 const struct in6_addr *saddr, int src_len,
383 bool exact_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700385void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
Li RongQing0c3584d2013-12-27 16:32:38 +0800386 void *arg);
Thomas Grafc71099a2006-08-04 23:20:06 -0700387
Florian Westphale715b6d2015-01-05 23:57:44 +0100388int fib6_add(struct fib6_node *root, struct rt6_info *rt,
David Ahernd4ead6b2018-04-17 17:33:16 -0700389 struct nl_info *info, struct netlink_ext_ack *extack);
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700390int fib6_del(struct rt6_info *rt, struct nl_info *info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Roopa Prabhu37a1d362015-09-13 10:18:33 -0700392void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info,
393 unsigned int flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700395void fib6_run_gc(unsigned long expires, struct net *net, bool force);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700397void fib6_gc_cleanup(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700399int fib6_init(void);
Thomas Graf101367c2006-08-04 03:39:02 -0700400
Hannes Frederic Sowa8d2ca1d2013-09-21 16:55:59 +0200401int ipv6_route_open(struct inode *inode, struct file *file);
402
Ido Schimmel16ab6d72017-08-03 13:28:16 +0200403int call_fib6_notifier(struct notifier_block *nb, struct net *net,
404 enum fib_event_type event_type,
405 struct fib_notifier_info *info);
406int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
407 struct fib_notifier_info *info);
408
409int __net_init fib6_notifier_init(struct net *net);
410void __net_exit fib6_notifier_exit(struct net *net);
411
Ido Schimmele1ee0a52017-08-03 13:28:19 +0200412unsigned int fib6_tables_seq_read(struct net *net);
413int fib6_tables_dump(struct net *net, struct notifier_block *nb);
414
David Ahern7aef6852018-04-17 17:33:10 -0700415void fib6_update_sernum(struct net *net, struct rt6_info *rt);
Ido Schimmel4a8e56e2018-01-07 12:45:13 +0200416void fib6_update_sernum_upto_root(struct net *net, struct rt6_info *rt);
Wei Wang180ca442017-10-06 12:05:56 -0700417
David Ahernd4ead6b2018-04-17 17:33:16 -0700418void fib6_metric_set(struct rt6_info *f6i, int metric, u32 val);
419static inline bool fib6_metric_locked(struct rt6_info *f6i, int metric)
420{
421 return !!(f6i->fib6_metrics->metrics[RTAX_LOCK - 1] & (1 << metric));
422}
423
Daniel Lezcano7e5449c2007-12-08 00:14:54 -0800424#ifdef CONFIG_IPV6_MULTIPLE_TABLES
Joe Perches5c3a0fd2013-09-21 10:22:42 -0700425int fib6_rules_init(void);
426void fib6_rules_cleanup(void);
Ido Schimmele3ea9732017-08-03 13:28:15 +0200427bool fib6_rule_default(const struct fib_rule *rule);
Ido Schimmeldcb18f72017-08-03 13:28:18 +0200428int fib6_rules_dump(struct net *net, struct notifier_block *nb);
429unsigned int fib6_rules_seq_read(struct net *net);
Roopa Prabhu5e5d6fe2018-02-28 22:43:22 -0500430
431static inline bool fib6_rules_early_flow_dissect(struct net *net,
432 struct sk_buff *skb,
433 struct flowi6 *fl6,
434 struct flow_keys *flkeys)
435{
436 unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
437
438 if (!net->ipv6.fib6_rules_require_fldissect)
439 return false;
440
441 skb_flow_dissect_flow_keys(skb, flkeys, flag);
442 fl6->fl6_sport = flkeys->ports.src;
443 fl6->fl6_dport = flkeys->ports.dst;
444 fl6->flowi6_proto = flkeys->basic.ip_proto;
445
446 return true;
447}
Daniel Lezcano7e5449c2007-12-08 00:14:54 -0800448#else
449static inline int fib6_rules_init(void)
450{
451 return 0;
452}
453static inline void fib6_rules_cleanup(void)
454{
455 return ;
456}
Ido Schimmele3ea9732017-08-03 13:28:15 +0200457static inline bool fib6_rule_default(const struct fib_rule *rule)
458{
459 return true;
460}
Ido Schimmeldcb18f72017-08-03 13:28:18 +0200461static inline int fib6_rules_dump(struct net *net, struct notifier_block *nb)
462{
463 return 0;
464}
465static inline unsigned int fib6_rules_seq_read(struct net *net)
466{
467 return 0;
468}
Roopa Prabhu5e5d6fe2018-02-28 22:43:22 -0500469static inline bool fib6_rules_early_flow_dissect(struct net *net,
470 struct sk_buff *skb,
471 struct flowi6 *fl6,
472 struct flow_keys *flkeys)
473{
474 return false;
475}
Daniel Lezcano7e5449c2007-12-08 00:14:54 -0800476#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#endif