ip_fib.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. #ifdef CONFIG_IP_MULTIPLE_TABLES
  150. struct fib_rule;
  151. #endif
  152. struct fib_table;
  153. struct fib_result {
  154. __be32 prefix;
  155. unsigned char prefixlen;
  156. unsigned char nh_sel;
  157. unsigned char type;
  158. unsigned char scope;
  159. u32 tclassid;
  160. dscp_t dscp;
  161. struct fib_nh_common *nhc;
  162. struct fib_info *fi;
  163. struct fib_table *table;
  164. struct hlist_head *fa_head;
  165. };
  166. struct fib_result_nl {
  167. __be32 fl_addr; /* To be looked up*/
  168. u32 fl_mark;
  169. unsigned char fl_tos;
  170. unsigned char fl_scope;
  171. unsigned char tb_id_in;
  172. unsigned char tb_id; /* Results */
  173. unsigned char prefixlen;
  174. unsigned char nh_sel;
  175. unsigned char type;
  176. unsigned char scope;
  177. int err;
  178. };
  179. #ifdef CONFIG_IP_MULTIPLE_TABLES
  180. #define FIB_TABLE_HASHSZ 256
  181. #else
  182. #define FIB_TABLE_HASHSZ 2
  183. #endif
  184. __be32 fib_info_update_nhc_saddr(struct net *net, struct fib_nh_common *nhc,
  185. unsigned char scope);
  186. __be32 fib_result_prefsrc(struct net *net, struct fib_result *res);
  187. #define FIB_RES_NHC(res) ((res).nhc)
  188. #define FIB_RES_DEV(res) (FIB_RES_NHC(res)->nhc_dev)
  189. #define FIB_RES_OIF(res) (FIB_RES_NHC(res)->nhc_oif)
  190. struct fib_rt_info {
  191. struct fib_info *fi;
  192. u32 tb_id;
  193. __be32 dst;
  194. int dst_len;
  195. dscp_t dscp;
  196. u8 type;
  197. u8 offload:1,
  198. trap:1,
  199. offload_failed:1,
  200. unused:5;
  201. };
  202. struct fib_entry_notifier_info {
  203. struct fib_notifier_info info; /* must be first */
  204. u32 dst;
  205. int dst_len;
  206. struct fib_info *fi;
  207. dscp_t dscp;
  208. u8 type;
  209. u32 tb_id;
  210. };
  211. struct fib_nh_notifier_info {
  212. struct fib_notifier_info info; /* must be first */
  213. struct fib_nh *fib_nh;
  214. };
  215. int call_fib4_notifier(struct notifier_block *nb,
  216. enum fib_event_type event_type,
  217. struct fib_notifier_info *info);
  218. int call_fib4_notifiers(struct net *net, enum fib_event_type event_type,
  219. struct fib_notifier_info *info);
  220. int __net_init fib4_notifier_init(struct net *net);
  221. void __net_exit fib4_notifier_exit(struct net *net);
  222. void fib_info_notify_update(struct net *net, struct nl_info *info);
  223. int fib_notify(struct net *net, struct notifier_block *nb,
  224. struct netlink_ext_ack *extack);
  225. struct fib_table {
  226. struct hlist_node tb_hlist;
  227. u32 tb_id;
  228. int tb_num_default;
  229. struct rcu_head rcu;
  230. unsigned long *tb_data;
  231. unsigned long __data[];
  232. };
  233. struct fib_dump_filter {
  234. u32 table_id;
  235. /* filter_set is an optimization that an entry is set */
  236. bool filter_set;
  237. bool dump_routes;
  238. bool dump_exceptions;
  239. bool rtnl_held;
  240. unsigned char protocol;
  241. unsigned char rt_type;
  242. unsigned int flags;
  243. struct net_device *dev;
  244. };
  245. int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
  246. struct fib_result *res, int fib_flags);
  247. int fib_table_insert(struct net *, struct fib_table *, struct fib_config *,
  248. struct netlink_ext_ack *extack);
  249. int fib_table_delete(struct net *, struct fib_table *, struct fib_config *,
  250. struct netlink_ext_ack *extack);
  251. int fib_table_dump(struct fib_table *table, struct sk_buff *skb,
  252. struct netlink_callback *cb, struct fib_dump_filter *filter);
  253. int fib_table_flush(struct net *net, struct fib_table *table, bool flush_all);
  254. struct fib_table *fib_trie_unmerge(struct fib_table *main_tb);
  255. void fib_table_flush_external(struct fib_table *table);
  256. void fib_free_table(struct fib_table *tb);
  257. #ifndef CONFIG_IP_MULTIPLE_TABLES
  258. #define TABLE_LOCAL_INDEX (RT_TABLE_LOCAL & (FIB_TABLE_HASHSZ - 1))
  259. #define TABLE_MAIN_INDEX (RT_TABLE_MAIN & (FIB_TABLE_HASHSZ - 1))
  260. static inline struct fib_table *fib_get_table(struct net *net, u32 id)
  261. {
  262. struct hlist_node *tb_hlist;
  263. struct hlist_head *ptr;
  264. ptr = id == RT_TABLE_LOCAL ?
  265. &net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX] :
  266. &net->ipv4.fib_table_hash[TABLE_MAIN_INDEX];
  267. tb_hlist = rcu_dereference_rtnl(hlist_first_rcu(ptr));
  268. return hlist_entry(tb_hlist, struct fib_table, tb_hlist);
  269. }
  270. static inline struct fib_table *fib_new_table(struct net *net, u32 id)
  271. {
  272. return fib_get_table(net, id);
  273. }
  274. static inline int fib_lookup(struct net *net, const struct flowi4 *flp,
  275. struct fib_result *res, unsigned int flags)
  276. {
  277. struct fib_table *tb;
  278. int err = -ENETUNREACH;
  279. rcu_read_lock();
  280. tb = fib_get_table(net, RT_TABLE_MAIN);
  281. if (tb)
  282. err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF);
  283. if (err == -EAGAIN)
  284. err = -ENETUNREACH;
  285. rcu_read_unlock();
  286. return err;
  287. }
  288. static inline bool fib4_has_custom_rules(const struct net *net)
  289. {
  290. return false;
  291. }
  292. static inline bool fib4_rule_default(const struct fib_rule *rule)
  293. {
  294. return true;
  295. }
  296. static inline int fib4_rules_dump(struct net *net, struct notifier_block *nb,
  297. struct netlink_ext_ack *extack)
  298. {
  299. return 0;
  300. }
  301. static inline unsigned int fib4_rules_seq_read(struct net *net)
  302. {
  303. return 0;
  304. }
  305. static inline bool fib4_rules_early_flow_dissect(struct net *net,
  306. struct sk_buff *skb,
  307. struct flowi4 *fl4,
  308. struct flow_keys *flkeys)
  309. {
  310. return false;
  311. }
  312. #else /* CONFIG_IP_MULTIPLE_TABLES */
  313. int __net_init fib4_rules_init(struct net *net);
  314. void __net_exit fib4_rules_exit(struct net *net);
  315. struct fib_table *fib_new_table(struct net *net, u32 id);
  316. struct fib_table *fib_get_table(struct net *net, u32 id);
  317. int __fib_lookup(struct net *net, struct flowi4 *flp,
  318. struct fib_result *res, unsigned int flags);
  319. static inline int fib_lookup(struct net *net, struct flowi4 *flp,
  320. struct fib_result *res, unsigned int flags)
  321. {
  322. struct fib_table *tb;
  323. int err = -ENETUNREACH;
  324. flags |= FIB_LOOKUP_NOREF;
  325. if (net->ipv4.fib_has_custom_rules)
  326. return __fib_lookup(net, flp, res, flags);
  327. rcu_read_lock();
  328. res->tclassid = 0;
  329. tb = rcu_dereference_rtnl(net->ipv4.fib_main);
  330. if (tb)
  331. err = fib_table_lookup(tb, flp, res, flags);
  332. if (!err)
  333. goto out;
  334. tb = rcu_dereference_rtnl(net->ipv4.fib_default);
  335. if (tb)
  336. err = fib_table_lookup(tb, flp, res, flags);
  337. out:
  338. if (err == -EAGAIN)
  339. err = -ENETUNREACH;
  340. rcu_read_unlock();
  341. return err;
  342. }
  343. static inline bool fib4_has_custom_rules(const struct net *net)
  344. {
  345. return net->ipv4.fib_has_custom_rules;
  346. }
  347. bool fib4_rule_default(const struct fib_rule *rule);
  348. int fib4_rules_dump(struct net *net, struct notifier_block *nb,
  349. struct netlink_ext_ack *extack);
  350. unsigned int fib4_rules_seq_read(struct net *net);
  351. static inline bool fib4_rules_early_flow_dissect(struct net *net,
  352. struct sk_buff *skb,
  353. struct flowi4 *fl4,
  354. struct flow_keys *flkeys)
  355. {
  356. unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
  357. if (!net->ipv4.fib_rules_require_fldissect)
  358. return false;
  359. memset(flkeys, 0, sizeof(*flkeys));
  360. __skb_flow_dissect(net, skb, &flow_keys_dissector,
  361. flkeys, NULL, 0, 0, 0, flag);
  362. fl4->fl4_sport = flkeys->ports.src;
  363. fl4->fl4_dport = flkeys->ports.dst;
  364. fl4->flowi4_proto = flkeys->basic.ip_proto;
  365. return true;
  366. }
  367. #endif /* CONFIG_IP_MULTIPLE_TABLES */
  368. static inline bool fib_dscp_masked_match(dscp_t dscp, const struct flowi4 *fl4)
  369. {
  370. return dscp == inet_dsfield_to_dscp(RT_TOS(fl4->flowi4_tos));
  371. }
  372. /* Exported by fib_frontend.c */
  373. extern const struct nla_policy rtm_ipv4_policy[];
  374. void ip_fib_init(void);
  375. int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla,
  376. struct netlink_ext_ack *extack);
  377. __be32 fib_compute_spec_dst(struct sk_buff *skb);
  378. bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev);
  379. int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
  380. u8 tos, int oif, struct net_device *dev,
  381. struct in_device *idev, u32 *itag);
  382. #ifdef CONFIG_IP_ROUTE_CLASSID
  383. static inline int fib_num_tclassid_users(struct net *net)
  384. {
  385. return atomic_read(&net->ipv4.fib_num_tclassid_users);
  386. }
  387. #else
  388. static inline int fib_num_tclassid_users(struct net *net)
  389. {
  390. return 0;
  391. }
  392. #endif
  393. int fib_unmerge(struct net *net);
  394. static inline bool nhc_l3mdev_matches_dev(const struct fib_nh_common *nhc,
  395. const struct net_device *dev)
  396. {
  397. if (nhc->nhc_dev == dev ||
  398. l3mdev_master_ifindex_rcu(nhc->nhc_dev) == dev->ifindex)
  399. return true;
  400. return false;
  401. }
  402. /* Exported by fib_semantics.c */
  403. int ip_fib_check_default(__be32 gw, struct net_device *dev);
  404. int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force);
  405. int fib_sync_down_addr(struct net_device *dev, __be32 local);
  406. int fib_sync_up(struct net_device *dev, unsigned char nh_flags);
  407. void fib_sync_mtu(struct net_device *dev, u32 orig_mtu);
  408. void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig);
  409. /* Fields used for sysctl_fib_multipath_hash_fields.
  410. * Common to IPv4 and IPv6.
  411. *
  412. * Add new fields at the end. This is user API.
  413. */
  414. #define FIB_MULTIPATH_HASH_FIELD_SRC_IP BIT(0)
  415. #define FIB_MULTIPATH_HASH_FIELD_DST_IP BIT(1)
  416. #define FIB_MULTIPATH_HASH_FIELD_IP_PROTO BIT(2)
  417. #define FIB_MULTIPATH_HASH_FIELD_FLOWLABEL BIT(3)
  418. #define FIB_MULTIPATH_HASH_FIELD_SRC_PORT BIT(4)
  419. #define FIB_MULTIPATH_HASH_FIELD_DST_PORT BIT(5)
  420. #define FIB_MULTIPATH_HASH_FIELD_INNER_SRC_IP BIT(6)
  421. #define FIB_MULTIPATH_HASH_FIELD_INNER_DST_IP BIT(7)
  422. #define FIB_MULTIPATH_HASH_FIELD_INNER_IP_PROTO BIT(8)
  423. #define FIB_MULTIPATH_HASH_FIELD_INNER_FLOWLABEL BIT(9)
  424. #define FIB_MULTIPATH_HASH_FIELD_INNER_SRC_PORT BIT(10)
  425. #define FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT BIT(11)
  426. #define FIB_MULTIPATH_HASH_FIELD_OUTER_MASK \
  427. (FIB_MULTIPATH_HASH_FIELD_SRC_IP | \
  428. FIB_MULTIPATH_HASH_FIELD_DST_IP | \
  429. FIB_MULTIPATH_HASH_FIELD_IP_PROTO | \
  430. FIB_MULTIPATH_HASH_FIELD_FLOWLABEL | \
  431. FIB_MULTIPATH_HASH_FIELD_SRC_PORT | \
  432. FIB_MULTIPATH_HASH_FIELD_DST_PORT)
  433. #define FIB_MULTIPATH_HASH_FIELD_INNER_MASK \
  434. (FIB_MULTIPATH_HASH_FIELD_INNER_SRC_IP | \
  435. FIB_MULTIPATH_HASH_FIELD_INNER_DST_IP | \
  436. FIB_MULTIPATH_HASH_FIELD_INNER_IP_PROTO | \
  437. FIB_MULTIPATH_HASH_FIELD_INNER_FLOWLABEL | \
  438. FIB_MULTIPATH_HASH_FIELD_INNER_SRC_PORT | \
  439. FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT)
  440. #define FIB_MULTIPATH_HASH_FIELD_ALL_MASK \
  441. (FIB_MULTIPATH_HASH_FIELD_OUTER_MASK | \
  442. FIB_MULTIPATH_HASH_FIELD_INNER_MASK)
  443. #define FIB_MULTIPATH_HASH_FIELD_DEFAULT_MASK \
  444. (FIB_MULTIPATH_HASH_FIELD_SRC_IP | \
  445. FIB_MULTIPATH_HASH_FIELD_DST_IP | \
  446. FIB_MULTIPATH_HASH_FIELD_IP_PROTO)
  447. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  448. int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
  449. const struct sk_buff *skb, struct flow_keys *flkeys);
  450. static void
  451. fib_multipath_hash_construct_key(siphash_key_t *key, u32 mp_seed)
  452. {
  453. u64 mp_seed_64 = mp_seed;
  454. key->key[0] = (mp_seed_64 << 32) | mp_seed_64;
  455. key->key[1] = key->key[0];
  456. }
  457. static inline u32 fib_multipath_hash_from_keys(const struct net *net,
  458. struct flow_keys *keys)
  459. {
  460. siphash_aligned_key_t hash_key;
  461. u32 mp_seed;
  462. mp_seed = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed).mp_seed;
  463. fib_multipath_hash_construct_key(&hash_key, mp_seed);
  464. return flow_hash_from_keys_seed(keys, &hash_key);
  465. }
  466. #else
  467. static inline u32 fib_multipath_hash_from_keys(const struct net *net,
  468. struct flow_keys *keys)
  469. {
  470. return flow_hash_from_keys(keys);
  471. }
  472. #endif
  473. int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope,
  474. struct netlink_ext_ack *extack);
  475. void fib_select_multipath(struct fib_result *res, int hash);
  476. void fib_select_path(struct net *net, struct fib_result *res,
  477. struct flowi4 *fl4, const struct sk_buff *skb);
  478. int fib_nh_init(struct net *net, struct fib_nh *fib_nh,
  479. struct fib_config *cfg, int nh_weight,
  480. struct netlink_ext_ack *extack);
  481. void fib_nh_release(struct net *net, struct fib_nh *fib_nh);
  482. int fib_nh_common_init(struct net *net, struct fib_nh_common *nhc,
  483. struct nlattr *fc_encap, u16 fc_encap_type,
  484. void *cfg, gfp_t gfp_flags,
  485. struct netlink_ext_ack *extack);
  486. void fib_nh_common_release(struct fib_nh_common *nhc);
  487. /* Exported by fib_trie.c */
  488. void fib_alias_hw_flags_set(struct net *net, const struct fib_rt_info *fri);
  489. void fib_trie_init(void);
  490. struct fib_table *fib_trie_table(u32 id, struct fib_table *alias);
  491. bool fib_lookup_good_nhc(const struct fib_nh_common *nhc, int fib_flags,
  492. const struct flowi4 *flp);
  493. static inline void fib_combine_itag(u32 *itag, const struct fib_result *res)
  494. {
  495. #ifdef CONFIG_IP_ROUTE_CLASSID
  496. struct fib_nh_common *nhc = res->nhc;
  497. #ifdef CONFIG_IP_MULTIPLE_TABLES
  498. u32 rtag;
  499. #endif
  500. if (nhc->nhc_family == AF_INET) {
  501. struct fib_nh *nh;
  502. nh = container_of(nhc, struct fib_nh, nh_common);
  503. *itag = nh->nh_tclassid << 16;
  504. } else {
  505. *itag = 0;
  506. }
  507. #ifdef CONFIG_IP_MULTIPLE_TABLES
  508. rtag = res->tclassid;
  509. if (*itag == 0)
  510. *itag = (rtag<<16);
  511. *itag |= (rtag>>16);
  512. #endif
  513. #endif
  514. }
  515. void fib_flush(struct net *net);
  516. void free_fib_info(struct fib_info *fi);
  517. static inline void fib_info_hold(struct fib_info *fi)
  518. {
  519. refcount_inc(&fi->fib_clntref);
  520. }
  521. static inline void fib_info_put(struct fib_info *fi)
  522. {
  523. if (refcount_dec_and_test(&fi->fib_clntref))
  524. free_fib_info(fi);
  525. }
  526. #ifdef CONFIG_PROC_FS
  527. int __net_init fib_proc_init(struct net *net);
  528. void __net_exit fib_proc_exit(struct net *net);
  529. #else
  530. static inline int fib_proc_init(struct net *net)
  531. {
  532. return 0;
  533. }
  534. static inline void fib_proc_exit(struct net *net)
  535. {
  536. }
  537. #endif
  538. u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr);
  539. int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
  540. struct fib_dump_filter *filter,
  541. struct netlink_callback *cb);
  542. int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh,
  543. u8 rt_family, unsigned char *flags, bool skip_oif);
  544. int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh,
  545. int nh_weight, u8 rt_family, u32 nh_tclassid);
  546. #endif /* _NET_FIB_H */