• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *	Linux INET6 implementation
4  *
5  *	Authors:
6  *	Pedro Roque		<roque@di.fc.ul.pt>
7  */
8 
9 #ifndef _IP6_FIB_H
10 #define _IP6_FIB_H
11 
12 #include <linux/ipv6_route.h>
13 #include <linux/rtnetlink.h>
14 #include <linux/spinlock.h>
15 #include <linux/notifier.h>
16 #include <linux/android_kabi.h>
17 #include <net/dst.h>
18 #include <net/flow.h>
19 #include <net/ip_fib.h>
20 #include <net/netlink.h>
21 #include <net/inetpeer.h>
22 #include <net/fib_notifier.h>
23 #include <linux/indirect_call_wrapper.h>
24 #include <uapi/linux/bpf.h>
25 
26 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
27 #define FIB6_TABLE_HASHSZ 256
28 #else
29 #define FIB6_TABLE_HASHSZ 1
30 #endif
31 
32 #define RT6_DEBUG 2
33 
34 struct rt6_info;
35 struct fib6_info;
36 
37 struct fib6_config {
38 	u32		fc_table;
39 	u32		fc_metric;
40 	int		fc_dst_len;
41 	int		fc_src_len;
42 	int		fc_ifindex;
43 	u32		fc_flags;
44 	u32		fc_protocol;
45 	u16		fc_type;        /* only 8 bits are used */
46 	u16		fc_delete_all_nh : 1,
47 			fc_ignore_dev_down:1,
48 			__unused : 14;
49 	u32		fc_nh_id;
50 
51 	struct in6_addr	fc_dst;
52 	struct in6_addr	fc_src;
53 	struct in6_addr	fc_prefsrc;
54 	struct in6_addr	fc_gateway;
55 
56 	unsigned long	fc_expires;
57 	struct nlattr	*fc_mx;
58 	int		fc_mx_len;
59 	int		fc_mp_len;
60 	struct nlattr	*fc_mp;
61 
62 	struct nl_info	fc_nlinfo;
63 	struct nlattr	*fc_encap;
64 	u16		fc_encap_type;
65 	bool		fc_is_fdb;
66 
67 	ANDROID_KABI_RESERVE(1);
68 };
69 
70 struct fib6_node {
71 	struct fib6_node __rcu	*parent;
72 	struct fib6_node __rcu	*left;
73 	struct fib6_node __rcu	*right;
74 #ifdef CONFIG_IPV6_SUBTREES
75 	struct fib6_node __rcu	*subtree;
76 #endif
77 	struct fib6_info __rcu	*leaf;
78 
79 	__u16			fn_bit;		/* bit key */
80 	__u16			fn_flags;
81 	int			fn_sernum;
82 	struct fib6_info __rcu	*rr_ptr;
83 	struct rcu_head		rcu;
84 
85 	ANDROID_KABI_RESERVE(1);
86 };
87 
88 struct fib6_gc_args {
89 	int			timeout;
90 	int			more;
91 };
92 
93 #ifndef CONFIG_IPV6_SUBTREES
94 #define FIB6_SUBTREE(fn)	NULL
95 
fib6_routes_require_src(const struct net * net)96 static inline bool fib6_routes_require_src(const struct net *net)
97 {
98 	return false;
99 }
100 
fib6_routes_require_src_inc(struct net * net)101 static inline void fib6_routes_require_src_inc(struct net *net) {}
fib6_routes_require_src_dec(struct net * net)102 static inline void fib6_routes_require_src_dec(struct net *net) {}
103 
104 #else
105 
fib6_routes_require_src(const struct net * net)106 static inline bool fib6_routes_require_src(const struct net *net)
107 {
108 	return net->ipv6.fib6_routes_require_src > 0;
109 }
110 
fib6_routes_require_src_inc(struct net * net)111 static inline void fib6_routes_require_src_inc(struct net *net)
112 {
113 	net->ipv6.fib6_routes_require_src++;
114 }
115 
fib6_routes_require_src_dec(struct net * net)116 static inline void fib6_routes_require_src_dec(struct net *net)
117 {
118 	net->ipv6.fib6_routes_require_src--;
119 }
120 
121 #define FIB6_SUBTREE(fn)	(rcu_dereference_protected((fn)->subtree, 1))
122 #endif
123 
124 /*
125  *	routing information
126  *
127  */
128 
129 struct rt6key {
130 	struct in6_addr	addr;
131 	int		plen;
132 };
133 
134 struct fib6_table;
135 
136 struct rt6_exception_bucket {
137 	struct hlist_head	chain;
138 	int			depth;
139 };
140 
141 struct rt6_exception {
142 	struct hlist_node	hlist;
143 	struct rt6_info		*rt6i;
144 	unsigned long		stamp;
145 	struct rcu_head		rcu;
146 };
147 
148 #define FIB6_EXCEPTION_BUCKET_SIZE_SHIFT 10
149 #define FIB6_EXCEPTION_BUCKET_SIZE (1 << FIB6_EXCEPTION_BUCKET_SIZE_SHIFT)
150 #define FIB6_MAX_DEPTH 5
151 
152 struct fib6_nh {
153 	struct fib_nh_common	nh_common;
154 
155 #ifdef CONFIG_IPV6_ROUTER_PREF
156 	unsigned long		last_probe;
157 #endif
158 
159 	struct rt6_info * __percpu *rt6i_pcpu;
160 	struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
161 };
162 
163 struct fib6_info {
164 	struct fib6_table		*fib6_table;
165 	struct fib6_info __rcu		*fib6_next;
166 	struct fib6_node __rcu		*fib6_node;
167 
168 	/* Multipath routes:
169 	 * siblings is a list of fib6_info that have the same metric/weight,
170 	 * destination, but not the same gateway. nsiblings is just a cache
171 	 * to speed up lookup.
172 	 */
173 	union {
174 		struct list_head	fib6_siblings;
175 		struct list_head	nh_list;
176 	};
177 	unsigned int			fib6_nsiblings;
178 
179 	refcount_t			fib6_ref;
180 	unsigned long			expires;
181 
182 	struct hlist_node		gc_link;
183 
184 	struct dst_metrics		*fib6_metrics;
185 #define fib6_pmtu		fib6_metrics->metrics[RTAX_MTU-1]
186 
187 	struct rt6key			fib6_dst;
188 	u32				fib6_flags;
189 	struct rt6key			fib6_src;
190 	struct rt6key			fib6_prefsrc;
191 
192 	u32				fib6_metric;
193 	u8				fib6_protocol;
194 	u8				fib6_type;
195 
196 	u8				offload;
197 	u8				trap;
198 	u8				offload_failed;
199 
200 	u8				should_flush:1,
201 					dst_nocount:1,
202 					dst_nopolicy:1,
203 					fib6_destroying:1,
204 					unused:4;
205 
206 	struct rcu_head			rcu;
207 	struct nexthop			*nh;
208 
209 	ANDROID_KABI_RESERVE(1);
210 
211 	struct fib6_nh			fib6_nh[];
212 };
213 
214 struct rt6_info {
215 	struct dst_entry		dst;
216 	struct fib6_info __rcu		*from;
217 	int				sernum;
218 
219 	struct rt6key			rt6i_dst;
220 	struct rt6key			rt6i_src;
221 	struct in6_addr			rt6i_gateway;
222 	struct inet6_dev		*rt6i_idev;
223 	u32				rt6i_flags;
224 
225 	/* more non-fragment space at head required */
226 	unsigned short			rt6i_nfheader_len;
227 
228 	ANDROID_KABI_RESERVE(1);
229 };
230 
231 struct fib6_result {
232 	struct fib6_nh		*nh;
233 	struct fib6_info	*f6i;
234 	u32			fib6_flags;
235 	u8			fib6_type;
236 	struct rt6_info		*rt6;
237 };
238 
239 #define for_each_fib6_node_rt_rcu(fn)					\
240 	for (rt = rcu_dereference((fn)->leaf); rt;			\
241 	     rt = rcu_dereference(rt->fib6_next))
242 
243 #define for_each_fib6_walker_rt(w)					\
244 	for (rt = (w)->leaf; rt;					\
245 	     rt = rcu_dereference_protected(rt->fib6_next, 1))
246 
247 #define dst_rt6_info(_ptr) container_of_const(_ptr, struct rt6_info, dst)
248 
ip6_dst_idev(const struct dst_entry * dst)249 static inline struct inet6_dev *ip6_dst_idev(const struct dst_entry *dst)
250 {
251 	return dst_rt6_info(dst)->rt6i_idev;
252 }
253 
fib6_requires_src(const struct fib6_info * rt)254 static inline bool fib6_requires_src(const struct fib6_info *rt)
255 {
256 	return rt->fib6_src.plen > 0;
257 }
258 
259 /* The callers should hold f6i->fib6_table->tb6_lock if a route has ever
260  * been added to a table before.
261  */
fib6_clean_expires(struct fib6_info * f6i)262 static inline void fib6_clean_expires(struct fib6_info *f6i)
263 {
264 	f6i->fib6_flags &= ~RTF_EXPIRES;
265 	f6i->expires = 0;
266 }
267 
268 /* The callers should hold f6i->fib6_table->tb6_lock if a route has ever
269  * been added to a table before.
270  */
fib6_set_expires(struct fib6_info * f6i,unsigned long expires)271 static inline void fib6_set_expires(struct fib6_info *f6i,
272 				    unsigned long expires)
273 {
274 	f6i->expires = expires;
275 	f6i->fib6_flags |= RTF_EXPIRES;
276 }
277 
fib6_check_expired(const struct fib6_info * f6i)278 static inline bool fib6_check_expired(const struct fib6_info *f6i)
279 {
280 	if (f6i->fib6_flags & RTF_EXPIRES)
281 		return time_after(jiffies, f6i->expires);
282 	return false;
283 }
284 
285 /* Function to safely get fn->fn_sernum for passed in rt
286  * and store result in passed in cookie.
287  * Return true if we can get cookie safely
288  * Return false if not
289  */
fib6_get_cookie_safe(const struct fib6_info * f6i,u32 * cookie)290 static inline bool fib6_get_cookie_safe(const struct fib6_info *f6i,
291 					u32 *cookie)
292 {
293 	struct fib6_node *fn;
294 	bool status = false;
295 
296 	fn = rcu_dereference(f6i->fib6_node);
297 
298 	if (fn) {
299 		*cookie = READ_ONCE(fn->fn_sernum);
300 		/* pairs with smp_wmb() in __fib6_update_sernum_upto_root() */
301 		smp_rmb();
302 		status = true;
303 	}
304 
305 	return status;
306 }
307 
rt6_get_cookie(const struct rt6_info * rt)308 static inline u32 rt6_get_cookie(const struct rt6_info *rt)
309 {
310 	struct fib6_info *from;
311 	u32 cookie = 0;
312 
313 	if (rt->sernum)
314 		return rt->sernum;
315 
316 	rcu_read_lock();
317 
318 	from = rcu_dereference(rt->from);
319 	if (from)
320 		fib6_get_cookie_safe(from, &cookie);
321 
322 	rcu_read_unlock();
323 
324 	return cookie;
325 }
326 
ip6_rt_put(struct rt6_info * rt)327 static inline void ip6_rt_put(struct rt6_info *rt)
328 {
329 	/* dst_release() accepts a NULL parameter.
330 	 * We rely on dst being first structure in struct rt6_info
331 	 */
332 	BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
333 	dst_release(&rt->dst);
334 }
335 
336 struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh);
337 void fib6_info_destroy_rcu(struct rcu_head *head);
338 
fib6_info_hold(struct fib6_info * f6i)339 static inline void fib6_info_hold(struct fib6_info *f6i)
340 {
341 	refcount_inc(&f6i->fib6_ref);
342 }
343 
fib6_info_hold_safe(struct fib6_info * f6i)344 static inline bool fib6_info_hold_safe(struct fib6_info *f6i)
345 {
346 	return refcount_inc_not_zero(&f6i->fib6_ref);
347 }
348 
fib6_info_release(struct fib6_info * f6i)349 static inline void fib6_info_release(struct fib6_info *f6i)
350 {
351 	if (f6i && refcount_dec_and_test(&f6i->fib6_ref)) {
352 		DEBUG_NET_WARN_ON_ONCE(!hlist_unhashed(&f6i->gc_link));
353 		call_rcu_hurry(&f6i->rcu, fib6_info_destroy_rcu);
354 	}
355 }
356 
357 enum fib6_walk_state {
358 #ifdef CONFIG_IPV6_SUBTREES
359 	FWS_S,
360 #endif
361 	FWS_L,
362 	FWS_R,
363 	FWS_C,
364 	FWS_U
365 };
366 
367 struct fib6_walker {
368 	struct list_head lh;
369 	struct fib6_node *root, *node;
370 	struct fib6_info *leaf;
371 	enum fib6_walk_state state;
372 	unsigned int skip;
373 	unsigned int count;
374 	unsigned int skip_in_node;
375 	int (*func)(struct fib6_walker *);
376 	void *args;
377 };
378 
379 struct rt6_statistics {
380 	__u32		fib_nodes;		/* all fib6 nodes */
381 	__u32		fib_route_nodes;	/* intermediate nodes */
382 	__u32		fib_rt_entries;		/* rt entries in fib table */
383 	__u32		fib_rt_cache;		/* cached rt entries in exception table */
384 	__u32		fib_discarded_routes;	/* total number of routes delete */
385 
386 	/* The following stat is not protected by any lock */
387 	atomic_t	fib_rt_alloc;		/* total number of routes alloced */
388 };
389 
390 #define RTN_TL_ROOT	0x0001
391 #define RTN_ROOT	0x0002		/* tree root node		*/
392 #define RTN_RTINFO	0x0004		/* node with valid routing info	*/
393 
394 /*
395  *	priority levels (or metrics)
396  *
397  */
398 
399 
400 struct fib6_table {
401 	struct hlist_node	tb6_hlist;
402 	u32			tb6_id;
403 	spinlock_t		tb6_lock;
404 	struct fib6_node	tb6_root;
405 	struct inet_peer_base	tb6_peers;
406 	unsigned int		flags;
407 	unsigned int		fib_seq;
408 	struct hlist_head       tb6_gc_hlist;	/* GC candidates */
409 #define RT6_TABLE_HAS_DFLT_ROUTER	BIT(0)
410 };
411 
412 #define RT6_TABLE_UNSPEC	RT_TABLE_UNSPEC
413 #define RT6_TABLE_MAIN		RT_TABLE_MAIN
414 #define RT6_TABLE_DFLT		RT6_TABLE_MAIN
415 #define RT6_TABLE_INFO		RT6_TABLE_MAIN
416 #define RT6_TABLE_PREFIX	RT6_TABLE_MAIN
417 
418 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
419 #define FIB6_TABLE_MIN		1
420 #define FIB6_TABLE_MAX		RT_TABLE_MAX
421 #define RT6_TABLE_LOCAL		RT_TABLE_LOCAL
422 #else
423 #define FIB6_TABLE_MIN		RT_TABLE_MAIN
424 #define FIB6_TABLE_MAX		FIB6_TABLE_MIN
425 #define RT6_TABLE_LOCAL		RT6_TABLE_MAIN
426 #endif
427 
428 typedef struct rt6_info *(*pol_lookup_t)(struct net *,
429 					 struct fib6_table *,
430 					 struct flowi6 *,
431 					 const struct sk_buff *, int);
432 
433 struct fib6_entry_notifier_info {
434 	struct fib_notifier_info info; /* must be first */
435 	struct fib6_info *rt;
436 	unsigned int nsiblings;
437 };
438 
439 /*
440  *	exported functions
441  */
442 
443 struct fib6_table *fib6_get_table(struct net *net, u32 id);
444 struct fib6_table *fib6_new_table(struct net *net, u32 id);
445 struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
446 				   const struct sk_buff *skb,
447 				   int flags, pol_lookup_t lookup);
448 
449 /* called with rcu lock held; can return error pointer
450  * caller needs to select path
451  */
452 int fib6_lookup(struct net *net, int oif, struct flowi6 *fl6,
453 		struct fib6_result *res, int flags);
454 
455 /* called with rcu lock held; caller needs to select path */
456 int fib6_table_lookup(struct net *net, struct fib6_table *table,
457 		      int oif, struct flowi6 *fl6, struct fib6_result *res,
458 		      int strict);
459 
460 void fib6_select_path(const struct net *net, struct fib6_result *res,
461 		      struct flowi6 *fl6, int oif, bool have_oif_match,
462 		      const struct sk_buff *skb, int strict);
463 struct fib6_node *fib6_node_lookup(struct fib6_node *root,
464 				   const struct in6_addr *daddr,
465 				   const struct in6_addr *saddr);
466 
467 struct fib6_node *fib6_locate(struct fib6_node *root,
468 			      const struct in6_addr *daddr, int dst_len,
469 			      const struct in6_addr *saddr, int src_len,
470 			      bool exact_match);
471 
472 void fib6_clean_all(struct net *net, int (*func)(struct fib6_info *, void *arg),
473 		    void *arg);
474 void fib6_clean_all_skip_notify(struct net *net,
475 				int (*func)(struct fib6_info *, void *arg),
476 				void *arg);
477 
478 int fib6_add(struct fib6_node *root, struct fib6_info *rt,
479 	     struct nl_info *info, struct netlink_ext_ack *extack);
480 int fib6_del(struct fib6_info *rt, struct nl_info *info);
481 
482 static inline
rt6_get_prefsrc(const struct rt6_info * rt,struct in6_addr * addr)483 void rt6_get_prefsrc(const struct rt6_info *rt, struct in6_addr *addr)
484 {
485 	const struct fib6_info *from;
486 
487 	rcu_read_lock();
488 
489 	from = rcu_dereference(rt->from);
490 	if (from)
491 		*addr = from->fib6_prefsrc.addr;
492 	else
493 		*addr = in6addr_any;
494 
495 	rcu_read_unlock();
496 }
497 
498 int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
499 		 struct fib6_config *cfg, gfp_t gfp_flags,
500 		 struct netlink_ext_ack *extack);
501 void fib6_nh_release(struct fib6_nh *fib6_nh);
502 void fib6_nh_release_dsts(struct fib6_nh *fib6_nh);
503 
504 int call_fib6_entry_notifiers(struct net *net,
505 			      enum fib_event_type event_type,
506 			      struct fib6_info *rt,
507 			      struct netlink_ext_ack *extack);
508 int call_fib6_multipath_entry_notifiers(struct net *net,
509 					enum fib_event_type event_type,
510 					struct fib6_info *rt,
511 					unsigned int nsiblings,
512 					struct netlink_ext_ack *extack);
513 int call_fib6_entry_notifiers_replace(struct net *net, struct fib6_info *rt);
514 void fib6_rt_update(struct net *net, struct fib6_info *rt,
515 		    struct nl_info *info);
516 void inet6_rt_notify(int event, struct fib6_info *rt, struct nl_info *info,
517 		     unsigned int flags);
518 
519 void fib6_run_gc(unsigned long expires, struct net *net, bool force);
520 
521 void fib6_gc_cleanup(void);
522 
523 int fib6_init(void);
524 
525 /* Add the route to the gc list if it is not already there
526  *
527  * The callers should hold f6i->fib6_table->tb6_lock.
528  */
fib6_add_gc_list(struct fib6_info * f6i)529 static inline void fib6_add_gc_list(struct fib6_info *f6i)
530 {
531 	/* If fib6_node is null, the f6i is not in (or removed from) the
532 	 * table.
533 	 *
534 	 * There is a gap between finding the f6i from the table and
535 	 * calling this function without the protection of the tb6_lock.
536 	 * This check makes sure the f6i is not added to the gc list when
537 	 * it is not on the table.
538 	 */
539 	if (!rcu_dereference_protected(f6i->fib6_node,
540 				       lockdep_is_held(&f6i->fib6_table->tb6_lock)))
541 		return;
542 
543 	if (hlist_unhashed(&f6i->gc_link))
544 		hlist_add_head(&f6i->gc_link, &f6i->fib6_table->tb6_gc_hlist);
545 }
546 
547 /* Remove the route from the gc list if it is on the list.
548  *
549  * The callers should hold f6i->fib6_table->tb6_lock.
550  */
fib6_remove_gc_list(struct fib6_info * f6i)551 static inline void fib6_remove_gc_list(struct fib6_info *f6i)
552 {
553 	if (!hlist_unhashed(&f6i->gc_link))
554 		hlist_del_init(&f6i->gc_link);
555 }
556 
557 struct ipv6_route_iter {
558 	struct seq_net_private p;
559 	struct fib6_walker w;
560 	loff_t skip;
561 	struct fib6_table *tbl;
562 	int sernum;
563 };
564 
565 extern const struct seq_operations ipv6_route_seq_ops;
566 
567 int call_fib6_notifier(struct notifier_block *nb,
568 		       enum fib_event_type event_type,
569 		       struct fib_notifier_info *info);
570 int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
571 			struct fib_notifier_info *info);
572 
573 int __net_init fib6_notifier_init(struct net *net);
574 void __net_exit fib6_notifier_exit(struct net *net);
575 
576 unsigned int fib6_tables_seq_read(struct net *net);
577 int fib6_tables_dump(struct net *net, struct notifier_block *nb,
578 		     struct netlink_ext_ack *extack);
579 
580 void fib6_update_sernum(struct net *net, struct fib6_info *rt);
581 void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt);
582 void fib6_update_sernum_stub(struct net *net, struct fib6_info *f6i);
583 
584 void fib6_metric_set(struct fib6_info *f6i, int metric, u32 val);
fib6_metric_locked(struct fib6_info * f6i,int metric)585 static inline bool fib6_metric_locked(struct fib6_info *f6i, int metric)
586 {
587 	return !!(f6i->fib6_metrics->metrics[RTAX_LOCK - 1] & (1 << metric));
588 }
589 void fib6_info_hw_flags_set(struct net *net, struct fib6_info *f6i,
590 			    bool offload, bool trap, bool offload_failed);
591 
592 #if IS_BUILTIN(CONFIG_IPV6) && defined(CONFIG_BPF_SYSCALL)
593 struct bpf_iter__ipv6_route {
594 	__bpf_md_ptr(struct bpf_iter_meta *, meta);
595 	__bpf_md_ptr(struct fib6_info *, rt);
596 };
597 #endif
598 
599 INDIRECT_CALLABLE_DECLARE(struct rt6_info *ip6_pol_route_output(struct net *net,
600 					     struct fib6_table *table,
601 					     struct flowi6 *fl6,
602 					     const struct sk_buff *skb,
603 					     int flags));
604 INDIRECT_CALLABLE_DECLARE(struct rt6_info *ip6_pol_route_input(struct net *net,
605 					     struct fib6_table *table,
606 					     struct flowi6 *fl6,
607 					     const struct sk_buff *skb,
608 					     int flags));
609 INDIRECT_CALLABLE_DECLARE(struct rt6_info *__ip6_route_redirect(struct net *net,
610 					     struct fib6_table *table,
611 					     struct flowi6 *fl6,
612 					     const struct sk_buff *skb,
613 					     int flags));
614 INDIRECT_CALLABLE_DECLARE(struct rt6_info *ip6_pol_route_lookup(struct net *net,
615 					     struct fib6_table *table,
616 					     struct flowi6 *fl6,
617 					     const struct sk_buff *skb,
618 					     int flags));
pol_lookup_func(pol_lookup_t lookup,struct net * net,struct fib6_table * table,struct flowi6 * fl6,const struct sk_buff * skb,int flags)619 static inline struct rt6_info *pol_lookup_func(pol_lookup_t lookup,
620 						struct net *net,
621 						struct fib6_table *table,
622 						struct flowi6 *fl6,
623 						const struct sk_buff *skb,
624 						int flags)
625 {
626 	return INDIRECT_CALL_4(lookup,
627 			       ip6_pol_route_output,
628 			       ip6_pol_route_input,
629 			       ip6_pol_route_lookup,
630 			       __ip6_route_redirect,
631 			       net, table, fl6, skb, flags);
632 }
633 
634 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
fib6_has_custom_rules(const struct net * net)635 static inline bool fib6_has_custom_rules(const struct net *net)
636 {
637 	return net->ipv6.fib6_has_custom_rules;
638 }
639 
640 int fib6_rules_init(void);
641 void fib6_rules_cleanup(void);
642 bool fib6_rule_default(const struct fib_rule *rule);
643 int fib6_rules_dump(struct net *net, struct notifier_block *nb,
644 		    struct netlink_ext_ack *extack);
645 unsigned int fib6_rules_seq_read(struct net *net);
646 
fib6_rules_early_flow_dissect(struct net * net,struct sk_buff * skb,struct flowi6 * fl6,struct flow_keys * flkeys)647 static inline bool fib6_rules_early_flow_dissect(struct net *net,
648 						 struct sk_buff *skb,
649 						 struct flowi6 *fl6,
650 						 struct flow_keys *flkeys)
651 {
652 	unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
653 
654 	if (!net->ipv6.fib6_rules_require_fldissect)
655 		return false;
656 
657 	memset(flkeys, 0, sizeof(*flkeys));
658 	__skb_flow_dissect(net, skb, &flow_keys_dissector,
659 			   flkeys, NULL, 0, 0, 0, flag);
660 
661 	fl6->fl6_sport = flkeys->ports.src;
662 	fl6->fl6_dport = flkeys->ports.dst;
663 	fl6->flowi6_proto = flkeys->basic.ip_proto;
664 
665 	return true;
666 }
667 #else
fib6_has_custom_rules(const struct net * net)668 static inline bool fib6_has_custom_rules(const struct net *net)
669 {
670 	return false;
671 }
fib6_rules_init(void)672 static inline int               fib6_rules_init(void)
673 {
674 	return 0;
675 }
fib6_rules_cleanup(void)676 static inline void              fib6_rules_cleanup(void)
677 {
678 	return ;
679 }
fib6_rule_default(const struct fib_rule * rule)680 static inline bool fib6_rule_default(const struct fib_rule *rule)
681 {
682 	return true;
683 }
fib6_rules_dump(struct net * net,struct notifier_block * nb,struct netlink_ext_ack * extack)684 static inline int fib6_rules_dump(struct net *net, struct notifier_block *nb,
685 				  struct netlink_ext_ack *extack)
686 {
687 	return 0;
688 }
fib6_rules_seq_read(struct net * net)689 static inline unsigned int fib6_rules_seq_read(struct net *net)
690 {
691 	return 0;
692 }
fib6_rules_early_flow_dissect(struct net * net,struct sk_buff * skb,struct flowi6 * fl6,struct flow_keys * flkeys)693 static inline bool fib6_rules_early_flow_dissect(struct net *net,
694 						 struct sk_buff *skb,
695 						 struct flowi6 *fl6,
696 						 struct flow_keys *flkeys)
697 {
698 	return false;
699 }
700 #endif
701 #endif
702