ip6_fib.h 18 KB

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