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