ip_fib.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * INET An implementation of the TCP/IP protocol suite for the LINUX
  4. * operating system. INET is implemented using the BSD Socket
  5. * interface as the means of communication with the user level.
  6. *
  7. * Definitions for the Forwarding Information Base.
  8. *
  9. * Authors: A.N.Kuznetsov, <kuznet@ms2.inr.ac.ru>
  10. */
  11. #ifndef _NET_IP_FIB_H
  12. #define _NET_IP_FIB_H
  13. #include <net/flow.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/rcupdate.h>
  16. #include <net/fib_notifier.h>
  17. #include <net/fib_rules.h>
  18. #include <net/inet_dscp.h>
  19. #include <net/inetpeer.h>
  20. #include <linux/percpu.h>
  21. #include <linux/notifier.h>
  22. #include <linux/refcount.h>
  23. #include <linux/ip.h>
  24. #include <linux/in_route.h>
  25. struct fib_config {
  26. u8 fc_dst_len;
  27. dscp_t fc_dscp;
  28. u8 fc_protocol;
  29. u8 fc_scope;
  30. u8 fc_type;
  31. u8 fc_gw_family;
  32. /* 2 bytes unused */
  33. u32 fc_table;
  34. __be32 fc_dst;
  35. union {
  36. __be32 fc_gw4;
  37. struct in6_addr fc_gw6;
  38. };
  39. int fc_oif;
  40. u32 fc_flags;
  41. u32 fc_priority;
  42. __be32 fc_prefsrc;
  43. u32 fc_nh_id;
  44. struct nlattr *fc_mx;
  45. struct rtnexthop *fc_mp;
  46. int fc_mx_len;
  47. int fc_mp_len;
  48. u32 fc_flow;
  49. u32 fc_nlflags;
  50. struct nl_info fc_nlinfo;
  51. struct nlattr *fc_encap;
  52. u16 fc_encap_type;
  53. };
  54. struct fib_info;
  55. struct rtable;
  56. struct fib_nh_exception {
  57. struct fib_nh_exception __rcu *fnhe_next;
  58. int fnhe_genid;
  59. __be32 fnhe_daddr;
  60. u32 fnhe_pmtu;
  61. bool fnhe_mtu_locked;
  62. __be32 fnhe_gw;
  63. unsigned long fnhe_expires;
  64. struct rtable __rcu *fnhe_rth_input;
  65. struct rtable __rcu *fnhe_rth_output;
  66. unsigned long fnhe_stamp;
  67. struct rcu_head rcu;
  68. };
  69. struct fnhe_hash_bucket {
  70. struct fib_nh_exception __rcu *chain;
  71. };
  72. #define FNHE_HASH_SHIFT 11
  73. #define FNHE_HASH_SIZE (1 << FNHE_HASH_SHIFT)
  74. #define FNHE_RECLAIM_DEPTH 5
  75. struct fib_nh_common {
  76. struct net_device *nhc_dev;
  77. netdevice_tracker nhc_dev_tracker;
  78. int nhc_oif;
  79. unsigned char nhc_scope;
  80. u8 nhc_family;
  81. u8 nhc_gw_family;
  82. unsigned char nhc_flags;
  83. struct lwtunnel_state *nhc_lwtstate;
  84. union {
  85. __be32 ipv4;
  86. struct in6_addr ipv6;
  87. } nhc_gw;
  88. int nhc_weight;
  89. atomic_t nhc_upper_bound;
  90. /* v4 specific, but allows fib6_nh with v4 routes */
  91. struct rtable __rcu * __percpu *nhc_pcpu_rth_output;
  92. struct rtable __rcu *nhc_rth_input;
  93. struct fnhe_hash_bucket __rcu *nhc_exceptions;
  94. };
  95. struct fib_nh {
  96. struct fib_nh_common nh_common;
  97. struct hlist_node nh_hash;
  98. struct fib_info *nh_parent;
  99. #ifdef CONFIG_IP_ROUTE_CLASSID
  100. __u32 nh_tclassid;
  101. #endif
  102. __be32 nh_saddr;
  103. int nh_saddr_genid;
  104. #define fib_nh_family nh_common.nhc_family
  105. #define fib_nh_dev nh_common.nhc_dev
  106. #define fib_nh_dev_tracker nh_common.nhc_dev_tracker
  107. #define fib_nh_oif nh_common.nhc_oif
  108. #define fib_nh_flags nh_common.nhc_flags
  109. #define fib_nh_lws nh_common.nhc_lwtstate
  110. #define fib_nh_scope nh_common.nhc_scope
  111. #define fib_nh_gw_family nh_common.nhc_gw_family
  112. #define fib_nh_gw4 nh_common.nhc_gw.ipv4
  113. #define fib_nh_gw6 nh_common.nhc_gw.ipv6
  114. #define fib_nh_weight nh_common.nhc_weight
  115. #define fib_nh_upper_bound nh_common.nhc_upper_bound
  116. };
  117. /*
  118. * This structure contains data shared by many of routes.
  119. */
  120. struct nexthop;
  121. struct fib_info {
  122. struct hlist_node fib_hash;
  123. struct hlist_node fib_lhash;
  124. struct list_head nh_list;
  125. struct net *fib_net;
  126. refcount_t fib_treeref;
  127. refcount_t fib_clntref;
  128. unsigned int fib_flags;
  129. unsigned char fib_dead;
  130. unsigned char fib_protocol;
  131. unsigned char fib_scope;
  132. unsigned char fib_type;
  133. __be32 fib_prefsrc;
  134. u32 fib_tb_id;
  135. u32 fib_priority;
  136. struct dst_metrics *fib_metrics;
  137. #define fib_mtu fib_metrics->metrics[RTAX_MTU-1]
  138. #define fib_window fib_metrics->metrics[RTAX_WINDOW-1]
  139. #define fib_rtt fib_metrics->metrics[RTAX_RTT-1]
  140. #define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1]
  141. int fib_nhs;
  142. bool fib_nh_is_v6;
  143. bool nh_updated;
  144. bool pfsrc_removed;
  145. struct nexthop *nh;
  146. struct rcu_head rcu;
  147. struct fib_nh fib_nh[] __counted_by(fib_nhs);
  148. };
  149. int __net_init fib4_semantics_init(struct net *net);
  150. void __net_exit fib4_semantics_exit(struct net *net);
  151. #ifdef CONFIG_IP_MULTIPLE_TABLES
  152. struct fib_rule;
  153. #endif
  154. struct fib_table;
  155. struct fib_result {
  156. __be32 prefix;
  157. unsigned char prefixlen;
  158. unsigned char nh_sel;
  159. unsigned char type;
  160. unsigned char scope;
  161. u32 tclassid;
  162. dscp_t dscp;
  163. struct fib_nh_common *nhc;
  164. struct fib_info *fi;
  165. struct fib_table *table;
  166. struct hlist_head *fa_head;
  167. };
  168. struct fib_result_nl {
  169. __be32 fl_addr; /* To be looked up*/
  170. u32 fl_mark;
  171. unsigned char fl_tos;
  172. unsigned char fl_scope;
  173. unsigned char tb_id_in;
  174. unsigned char tb_id; /* Results */
  175. unsigned char prefixlen;
  176. unsigned char nh_sel;
  177. unsigned char type;
  178. unsigned char scope;
  179. int err;
  180. };
  181. #ifdef CONFIG_IP_MULTIPLE_TABLES
  182. #define FIB_TABLE_HASHSZ 256
  183. #else
  184. #define FIB_TABLE_HASHSZ 2
  185. #endif
  186. __be32 fib_info_update_nhc_saddr(struct net *net, struct fib_nh_common *nhc,
  187. unsigned char scope);
  188. __be32 fib_result_prefsrc(struct net *net, struct fib_result *res);
  189. #define FIB_RES_NHC(res) ((res).nhc)
  190. #define FIB_RES_DEV(res) (FIB_RES_NHC(res)->nhc_dev)
  191. #define FIB_RES_OIF(res) (FIB_RES_NHC(res)->nhc_oif)
  192. struct fib_rt_info {
  193. struct fib_info *fi;
  194. u32 tb_id;
  195. __be32 dst;
  196. int dst_len;
  197. dscp_t dscp;
  198. u8 type;
  199. u8 offload:1,
  200. trap:1,
  201. offload_failed:1,
  202. unused:5;
  203. };
  204. struct fib_entry_notifier_info {
  205. struct fib_notifier_info info; /* must be first */
  206. u32 dst;
  207. int dst_len;
  208. struct fib_info *fi;
  209. dscp_t dscp;
  210. u8 type;
  211. u32 tb_id;
  212. };
  213. struct fib_nh_notifier_info {
  214. struct fib_notifier_info info; /* must be first */
  215. struct fib_nh *fib_nh;
  216. };
  217. int call_fib4_notifier(struct notifier_block *nb,
  218. enum fib_event_type event_type,
  219. struct fib_notifier_info *info);
  220. int call_fib4_notifiers(struct net *net, enum fib_event_type event_type,
  221. struct fib_notifier_info *info);
  222. int __net_init fib4_notifier_init(struct net *net);
  223. void __net_exit fib4_notifier_exit(struct net *net);
  224. void fib_info_notify_update(struct net *net, struct nl_info *info);
  225. int fib_notify(struct net *net, struct notifier_block *nb,
  226. struct netlink_ext_ack *extack);
  227. struct fib_table {
  228. struct hlist_node tb_hlist;
  229. u32 tb_id;
  230. int tb_num_default;
  231. struct rcu_head rcu;
  232. unsigned long *tb_data;
  233. unsigned long __data[];
  234. };
  235. struct fib_dump_filter {
  236. u32 table_id;
  237. /* filter_set is an optimization that an entry is set */
  238. bool filter_set;
  239. bool dump_routes;
  240. bool dump_exceptions;
  241. bool rtnl_held;
  242. unsigned char protocol;
  243. unsigned char rt_type;
  244. unsigned int flags;
  245. struct net_device *dev;
  246. };
  247. int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
  248. struct fib_result *res, int fib_flags);
  249. int fib_table_insert(struct net *, struct fib_table *, struct fib_config *,
  250. struct netlink_ext_ack *extack);
  251. int fib_table_delete(struct net *, struct fib_table *, struct fib_config *,
  252. struct netlink_ext_ack *extack);
  253. int fib_table_dump(struct fib_table *table, struct sk_buff *skb,
  254. struct netlink_callback *cb, struct fib_dump_filter *filter);
  255. int fib_table_flush(struct net *net, struct fib_table *table, bool flush_all);
  256. struct fib_table *fib_trie_unmerge(struct fib_table *main_tb);
  257. void fib_table_flush_external(struct fib_table *table);
  258. void fib_free_table(struct fib_table *tb);
  259. #ifndef CONFIG_IP_MULTIPLE_TABLES
  260. #define TABLE_LOCAL_INDEX (RT_TABLE_LOCAL & (FIB_TABLE_HASHSZ - 1))
  261. #define TABLE_MAIN_INDEX (RT_TABLE_MAIN & (FIB_TABLE_HASHSZ - 1))
  262. static inline struct fib_table *fib_get_table(struct net *net, u32 id)
  263. {
  264. struct hlist_node *tb_hlist;
  265. struct hlist_head *ptr;
  266. ptr = id == RT_TABLE_LOCAL ?
  267. &net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX] :
  268. &net->ipv4.fib_table_hash[TABLE_MAIN_INDEX];
  269. tb_hlist = rcu_dereference_rtnl(hlist_first_rcu(ptr));
  270. return hlist_entry(tb_hlist, struct fib_table, tb_hlist);
  271. }
  272. static inline struct fib_table *fib_new_table(struct net *net, u32 id)
  273. {
  274. return fib_get_table(net, id);
  275. }
  276. static inline int fib_lookup(struct net *net, const struct flowi4 *flp,
  277. struct fib_result *res, unsigned int flags)
  278. {
  279. struct fib_table *tb;
  280. int err = -ENETUNREACH;
  281. rcu_read_lock();
  282. tb = fib_get_table(net, RT_TABLE_MAIN);
  283. if (tb)
  284. err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF);
  285. if (err == -EAGAIN)
  286. err = -ENETUNREACH;
  287. rcu_read_unlock();
  288. return err;
  289. }
  290. static inline bool fib4_has_custom_rules(const struct net *net)
  291. {
  292. return false;
  293. }
  294. static inline bool fib4_rule_default(const struct fib_rule *rule)
  295. {
  296. return true;
  297. }
  298. static inline int fib4_rules_dump(struct net *net, struct notifier_block *nb,
  299. struct netlink_ext_ack *extack)
  300. {
  301. return 0;
  302. }
  303. static inline unsigned int fib4_rules_seq_read(const struct net *net)
  304. {
  305. return 0;
  306. }
  307. static inline bool fib4_rules_early_flow_dissect(struct net *net,
  308. struct sk_buff *skb,
  309. struct flowi4 *fl4,
  310. struct flow_keys *flkeys)
  311. {
  312. return false;
  313. }
  314. #else /* CONFIG_IP_MULTIPLE_TABLES */
  315. int __net_init fib4_rules_init(struct net *net);
  316. void __net_exit fib4_rules_exit(struct net *net);
  317. struct fib_table *fib_new_table(struct net *net, u32 id);
  318. struct fib_table *fib_get_table(struct net *net, u32 id);
  319. int __fib_lookup(struct net *net, struct flowi4 *flp,
  320. struct fib_result *res, unsigned int flags);
  321. static inline int fib_lookup(struct net *net, struct flowi4 *flp,
  322. struct fib_result *res, unsigned int flags)
  323. {
  324. struct fib_table *tb;
  325. int err = -ENETUNREACH;
  326. flags |= FIB_LOOKUP_NOREF;
  327. if (net->ipv4.fib_has_custom_rules)
  328. return __fib_lookup(net, flp, res, flags);
  329. rcu_read_lock();
  330. res->tclassid = 0;
  331. tb = rcu_dereference_rtnl(net->ipv4.fib_main);
  332. if (tb)
  333. err = fib_table_lookup(tb, flp, res, flags);
  334. if (!err)
  335. goto out;
  336. tb = rcu_dereference_rtnl(net->ipv4.fib_default);
  337. if (tb)
  338. err = fib_table_lookup(tb, flp, res, flags);
  339. out:
  340. if (err == -EAGAIN)
  341. err = -ENETUNREACH;
  342. rcu_read_unlock();
  343. return err;
  344. }
  345. static inline bool fib4_has_custom_rules(const struct net *net)
  346. {
  347. return net->ipv4.fib_has_custom_rules;
  348. }
  349. bool fib4_rule_default(const struct fib_rule *rule);
  350. int fib4_rules_dump(struct net *net, struct notifier_block *nb,
  351. struct netlink_ext_ack *extack);
  352. unsigned int fib4_rules_seq_read(const struct net *net);
  353. static inline bool fib4_rules_early_flow_dissect(struct net *net,
  354. struct sk_buff *skb,
  355. struct flowi4 *fl4,
  356. struct flow_keys *flkeys)
  357. {
  358. unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
  359. if (!net->ipv4.fib_rules_require_fldissect)
  360. return false;
  361. memset(flkeys, 0, sizeof(*flkeys));
  362. __skb_flow_dissect(net, skb, &flow_keys_dissector,
  363. flkeys, NULL, 0, 0, 0, flag);
  364. fl4->fl4_sport = flkeys->ports.src;
  365. fl4->fl4_dport = flkeys->ports.dst;
  366. fl4->flowi4_proto = flkeys->basic.ip_proto;
  367. return true;
  368. }
  369. #endif /* CONFIG_IP_MULTIPLE_TABLES */
  370. static inline bool fib_dscp_masked_match(dscp_t dscp, const struct flowi4 *fl4)
  371. {
  372. return dscp == (fl4->flowi4_dscp & INET_DSCP_LEGACY_TOS_MASK);
  373. }
  374. /* Exported by fib_frontend.c */
  375. extern const struct nla_policy rtm_ipv4_policy[];
  376. void ip_fib_init(void);
  377. int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla,
  378. struct netlink_ext_ack *extack);
  379. __be32 fib_compute_spec_dst(struct sk_buff *skb);
  380. bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev);
  381. int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
  382. dscp_t dscp, int oif, struct net_device *dev,
  383. struct in_device *idev, u32 *itag);
  384. static inline enum skb_drop_reason
  385. fib_validate_source_reason(struct sk_buff *skb, __be32 src, __be32 dst,
  386. dscp_t dscp, int oif, struct net_device *dev,
  387. struct in_device *idev, u32 *itag)
  388. {
  389. int err = fib_validate_source(skb, src, dst, dscp, oif, dev, idev,
  390. itag);
  391. if (err < 0)
  392. return -err;
  393. return SKB_NOT_DROPPED_YET;
  394. }
  395. #ifdef CONFIG_IP_ROUTE_CLASSID
  396. static inline int fib_num_tclassid_users(struct net *net)
  397. {
  398. return atomic_read(&net->ipv4.fib_num_tclassid_users);
  399. }
  400. #else
  401. static inline int fib_num_tclassid_users(struct net *net)
  402. {
  403. return 0;
  404. }
  405. #endif
  406. int fib_unmerge(struct net *net);
  407. static inline bool nhc_l3mdev_matches_dev(const struct fib_nh_common *nhc,
  408. const struct net_device *dev)
  409. {
  410. if (nhc->nhc_dev == dev ||
  411. l3mdev_master_ifindex_rcu(nhc->nhc_dev) == dev->ifindex)
  412. return true;
  413. return false;
  414. }
  415. /* Exported by fib_semantics.c */
  416. int ip_fib_check_default(__be32 gw, struct net_device *dev);
  417. int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force);
  418. int fib_sync_down_addr(struct net_device *dev, __be32 local);
  419. int fib_sync_up(struct net_device *dev, unsigned char nh_flags);
  420. void fib_sync_mtu(struct net_device *dev, u32 orig_mtu);
  421. void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig);
  422. /* Fields used for sysctl_fib_multipath_hash_fields.
  423. * Common to IPv4 and IPv6.
  424. *
  425. * Add new fields at the end. This is user API.
  426. */
  427. #define FIB_MULTIPATH_HASH_FIELD_SRC_IP BIT(0)
  428. #define FIB_MULTIPATH_HASH_FIELD_DST_IP BIT(1)
  429. #define FIB_MULTIPATH_HASH_FIELD_IP_PROTO BIT(2)
  430. #define FIB_MULTIPATH_HASH_FIELD_FLOWLABEL BIT(3)
  431. #define FIB_MULTIPATH_HASH_FIELD_SRC_PORT BIT(4)
  432. #define FIB_MULTIPATH_HASH_FIELD_DST_PORT BIT(5)
  433. #define FIB_MULTIPATH_HASH_FIELD_INNER_SRC_IP BIT(6)
  434. #define FIB_MULTIPATH_HASH_FIELD_INNER_DST_IP BIT(7)
  435. #define FIB_MULTIPATH_HASH_FIELD_INNER_IP_PROTO BIT(8)
  436. #define FIB_MULTIPATH_HASH_FIELD_INNER_FLOWLABEL BIT(9)
  437. #define FIB_MULTIPATH_HASH_FIELD_INNER_SRC_PORT BIT(10)
  438. #define FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT BIT(11)
  439. #define FIB_MULTIPATH_HASH_FIELD_OUTER_MASK \
  440. (FIB_MULTIPATH_HASH_FIELD_SRC_IP | \
  441. FIB_MULTIPATH_HASH_FIELD_DST_IP | \
  442. FIB_MULTIPATH_HASH_FIELD_IP_PROTO | \
  443. FIB_MULTIPATH_HASH_FIELD_FLOWLABEL | \
  444. FIB_MULTIPATH_HASH_FIELD_SRC_PORT | \
  445. FIB_MULTIPATH_HASH_FIELD_DST_PORT)
  446. #define FIB_MULTIPATH_HASH_FIELD_INNER_MASK \
  447. (FIB_MULTIPATH_HASH_FIELD_INNER_SRC_IP | \
  448. FIB_MULTIPATH_HASH_FIELD_INNER_DST_IP | \
  449. FIB_MULTIPATH_HASH_FIELD_INNER_IP_PROTO | \
  450. FIB_MULTIPATH_HASH_FIELD_INNER_FLOWLABEL | \
  451. FIB_MULTIPATH_HASH_FIELD_INNER_SRC_PORT | \
  452. FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT)
  453. #define FIB_MULTIPATH_HASH_FIELD_ALL_MASK \
  454. (FIB_MULTIPATH_HASH_FIELD_OUTER_MASK | \
  455. FIB_MULTIPATH_HASH_FIELD_INNER_MASK)
  456. #define FIB_MULTIPATH_HASH_FIELD_DEFAULT_MASK \
  457. (FIB_MULTIPATH_HASH_FIELD_SRC_IP | \
  458. FIB_MULTIPATH_HASH_FIELD_DST_IP | \
  459. FIB_MULTIPATH_HASH_FIELD_IP_PROTO)
  460. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  461. int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
  462. const struct sk_buff *skb, struct flow_keys *flkeys);
  463. static void
  464. fib_multipath_hash_construct_key(siphash_key_t *key, u32 mp_seed)
  465. {
  466. u64 mp_seed_64 = mp_seed;
  467. key->key[0] = (mp_seed_64 << 32) | mp_seed_64;
  468. key->key[1] = key->key[0];
  469. }
  470. static inline u32 fib_multipath_hash_from_keys(const struct net *net,
  471. struct flow_keys *keys)
  472. {
  473. siphash_aligned_key_t hash_key;
  474. u32 mp_seed;
  475. mp_seed = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.mp_seed);
  476. fib_multipath_hash_construct_key(&hash_key, mp_seed);
  477. return flow_hash_from_keys_seed(keys, &hash_key);
  478. }
  479. #else
  480. static inline u32 fib_multipath_hash_from_keys(const struct net *net,
  481. struct flow_keys *keys)
  482. {
  483. return flow_hash_from_keys(keys);
  484. }
  485. #endif
  486. int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope,
  487. struct netlink_ext_ack *extack);
  488. void fib_select_multipath(struct fib_result *res, int hash,
  489. const struct flowi4 *fl4);
  490. void fib_select_path(struct net *net, struct fib_result *res,
  491. struct flowi4 *fl4, const struct sk_buff *skb);
  492. int fib_nh_init(struct net *net, struct fib_nh *fib_nh,
  493. struct fib_config *cfg, int nh_weight,
  494. struct netlink_ext_ack *extack);
  495. void fib_nh_release(struct net *net, struct fib_nh *fib_nh);
  496. int fib_nh_common_init(struct net *net, struct fib_nh_common *nhc,
  497. struct nlattr *fc_encap, u16 fc_encap_type,
  498. void *cfg, gfp_t gfp_flags,
  499. struct netlink_ext_ack *extack);
  500. void fib_nh_common_release(struct fib_nh_common *nhc);
  501. /* Exported by fib_trie.c */
  502. void fib_alias_hw_flags_set(struct net *net, const struct fib_rt_info *fri);
  503. void fib_trie_init(void);
  504. struct fib_table *fib_trie_table(u32 id, struct fib_table *alias);
  505. bool fib_lookup_good_nhc(const struct fib_nh_common *nhc, int fib_flags,
  506. const struct flowi4 *flp);
  507. static inline void fib_combine_itag(u32 *itag, const struct fib_result *res)
  508. {
  509. #ifdef CONFIG_IP_ROUTE_CLASSID
  510. struct fib_nh_common *nhc = res->nhc;
  511. #ifdef CONFIG_IP_MULTIPLE_TABLES
  512. u32 rtag;
  513. #endif
  514. if (nhc->nhc_family == AF_INET) {
  515. struct fib_nh *nh;
  516. nh = container_of(nhc, struct fib_nh, nh_common);
  517. *itag = nh->nh_tclassid << 16;
  518. } else {
  519. *itag = 0;
  520. }
  521. #ifdef CONFIG_IP_MULTIPLE_TABLES
  522. rtag = res->tclassid;
  523. if (*itag == 0)
  524. *itag = (rtag<<16);
  525. *itag |= (rtag>>16);
  526. #endif
  527. #endif
  528. }
  529. void fib_flush(struct net *net);
  530. void free_fib_info(struct fib_info *fi);
  531. static inline void fib_info_hold(struct fib_info *fi)
  532. {
  533. refcount_inc(&fi->fib_clntref);
  534. }
  535. static inline void fib_info_put(struct fib_info *fi)
  536. {
  537. if (refcount_dec_and_test(&fi->fib_clntref))
  538. free_fib_info(fi);
  539. }
  540. #ifdef CONFIG_PROC_FS
  541. int __net_init fib_proc_init(struct net *net);
  542. void __net_exit fib_proc_exit(struct net *net);
  543. #else
  544. static inline int fib_proc_init(struct net *net)
  545. {
  546. return 0;
  547. }
  548. static inline void fib_proc_exit(struct net *net)
  549. {
  550. }
  551. #endif
  552. u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr);
  553. int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
  554. struct fib_dump_filter *filter,
  555. struct netlink_callback *cb);
  556. int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh,
  557. u8 rt_family, unsigned char *flags, bool skip_oif);
  558. int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh,
  559. int nh_weight, u8 rt_family, u32 nh_tclassid);
  560. #endif /* _NET_FIB_H */