xref: /linux-6.15/include/net/ip_fib.h (revision 982acb97)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * INET		An implementation of the TCP/IP protocol suite for the LINUX
31da177e4SLinus Torvalds  *		operating system.  INET  is implemented using the  BSD Socket
41da177e4SLinus Torvalds  *		interface as the means of communication with the user level.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *		Definitions for the Forwarding Information Base.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Authors:	A.N.Kuznetsov, <[email protected]>
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  *		This program is free software; you can redistribute it and/or
111da177e4SLinus Torvalds  *		modify it under the terms of the GNU General Public License
121da177e4SLinus Torvalds  *		as published by the Free Software Foundation; either version
131da177e4SLinus Torvalds  *		2 of the License, or (at your option) any later version.
141da177e4SLinus Torvalds  */
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds #ifndef _NET_IP_FIB_H
171da177e4SLinus Torvalds #define _NET_IP_FIB_H
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #include <net/flow.h>
201da177e4SLinus Torvalds #include <linux/seq_file.h>
214895c771SDavid S. Miller #include <linux/rcupdate.h>
22e1ef4bf2SThomas Graf #include <net/fib_rules.h>
238e773277SDavid S. Miller #include <net/inetpeer.h>
24d26b3a7cSEric Dumazet #include <linux/percpu.h>
25b90eb754SJiri Pirko #include <linux/notifier.h>
261da177e4SLinus Torvalds 
274e902c57SThomas Graf struct fib_config {
284e902c57SThomas Graf 	u8			fc_dst_len;
294e902c57SThomas Graf 	u8			fc_tos;
304e902c57SThomas Graf 	u8			fc_protocol;
314e902c57SThomas Graf 	u8			fc_scope;
324e902c57SThomas Graf 	u8			fc_type;
33b52f070cSThomas Graf 	/* 3 bytes unused */
344e902c57SThomas Graf 	u32			fc_table;
356d85c10aSAl Viro 	__be32			fc_dst;
366d85c10aSAl Viro 	__be32			fc_gw;
374e902c57SThomas Graf 	int			fc_oif;
384e902c57SThomas Graf 	u32			fc_flags;
394e902c57SThomas Graf 	u32			fc_priority;
406d85c10aSAl Viro 	__be32			fc_prefsrc;
414e902c57SThomas Graf 	struct nlattr		*fc_mx;
424e902c57SThomas Graf 	struct rtnexthop	*fc_mp;
434e902c57SThomas Graf 	int			fc_mx_len;
444e902c57SThomas Graf 	int			fc_mp_len;
454e902c57SThomas Graf 	u32			fc_flow;
464e902c57SThomas Graf 	u32			fc_nlflags;
474e902c57SThomas Graf 	struct nl_info		fc_nlinfo;
48571e7226SRoopa Prabhu 	struct nlattr		*fc_encap;
49571e7226SRoopa Prabhu 	u16			fc_encap_type;
501da177e4SLinus Torvalds };
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds struct fib_info;
53f2bb4bedSDavid S. Miller struct rtable;
541da177e4SLinus Torvalds 
554895c771SDavid S. Miller struct fib_nh_exception {
564895c771SDavid S. Miller 	struct fib_nh_exception __rcu	*fnhe_next;
575aad1de5STimo Teräs 	int				fnhe_genid;
584895c771SDavid S. Miller 	__be32				fnhe_daddr;
594895c771SDavid S. Miller 	u32				fnhe_pmtu;
60aee06da6SJulian Anastasov 	__be32				fnhe_gw;
614895c771SDavid S. Miller 	unsigned long			fnhe_expires;
622ffae99dSTimo Teräs 	struct rtable __rcu		*fnhe_rth_input;
632ffae99dSTimo Teräs 	struct rtable __rcu		*fnhe_rth_output;
644895c771SDavid S. Miller 	unsigned long			fnhe_stamp;
65deed49dfSXin Long 	struct rcu_head			rcu;
664895c771SDavid S. Miller };
674895c771SDavid S. Miller 
684895c771SDavid S. Miller struct fnhe_hash_bucket {
694895c771SDavid S. Miller 	struct fib_nh_exception __rcu	*chain;
704895c771SDavid S. Miller };
714895c771SDavid S. Miller 
72d546c621SEric Dumazet #define FNHE_HASH_SHIFT		11
73d546c621SEric Dumazet #define FNHE_HASH_SIZE		(1 << FNHE_HASH_SHIFT)
744895c771SDavid S. Miller #define FNHE_RECLAIM_DEPTH	5
754895c771SDavid S. Miller 
761da177e4SLinus Torvalds struct fib_nh {
771da177e4SLinus Torvalds 	struct net_device	*nh_dev;
781da177e4SLinus Torvalds 	struct hlist_node	nh_hash;
791da177e4SLinus Torvalds 	struct fib_info		*nh_parent;
8095c96174SEric Dumazet 	unsigned int		nh_flags;
811da177e4SLinus Torvalds 	unsigned char		nh_scope;
821da177e4SLinus Torvalds #ifdef CONFIG_IP_ROUTE_MULTIPATH
831da177e4SLinus Torvalds 	int			nh_weight;
840e884c78SPeter Nørlund 	atomic_t		nh_upper_bound;
851da177e4SLinus Torvalds #endif
86c7066f70SPatrick McHardy #ifdef CONFIG_IP_ROUTE_CLASSID
871da177e4SLinus Torvalds 	__u32			nh_tclassid;
881da177e4SLinus Torvalds #endif
891da177e4SLinus Torvalds 	int			nh_oif;
90ed49e3caSAl Viro 	__be32			nh_gw;
911fc050a1SDavid S. Miller 	__be32			nh_saddr;
92436c3b66SDavid S. Miller 	int			nh_saddr_genid;
93d26b3a7cSEric Dumazet 	struct rtable __rcu * __percpu *nh_pcpu_rth_output;
9454764bb6SEric Dumazet 	struct rtable __rcu	*nh_rth_input;
95caa41527SEric Dumazet 	struct fnhe_hash_bucket	__rcu *nh_exceptions;
96571e7226SRoopa Prabhu 	struct lwtunnel_state	*nh_lwtstate;
971da177e4SLinus Torvalds };
981da177e4SLinus Torvalds 
991da177e4SLinus Torvalds /*
1001da177e4SLinus Torvalds  * This structure contains data shared by many of routes.
1011da177e4SLinus Torvalds  */
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds struct fib_info {
1041da177e4SLinus Torvalds 	struct hlist_node	fib_hash;
1051da177e4SLinus Torvalds 	struct hlist_node	fib_lhash;
1067462bd74SDenis V. Lunev 	struct net		*fib_net;
1071da177e4SLinus Torvalds 	int			fib_treeref;
1081da177e4SLinus Torvalds 	atomic_t		fib_clntref;
10995c96174SEric Dumazet 	unsigned int		fib_flags;
11037e826c5SDavid S. Miller 	unsigned char		fib_dead;
11137e826c5SDavid S. Miller 	unsigned char		fib_protocol;
11237e826c5SDavid S. Miller 	unsigned char		fib_scope;
113f4ef85bbSEric Dumazet 	unsigned char		fib_type;
114b83738aeSAl Viro 	__be32			fib_prefsrc;
1155a56a0b3SMark Tomlinson 	u32			fib_tb_id;
1161da177e4SLinus Torvalds 	u32			fib_priority;
1179c150e82SDavid S. Miller 	u32			*fib_metrics;
1181da177e4SLinus Torvalds #define fib_mtu fib_metrics[RTAX_MTU-1]
1191da177e4SLinus Torvalds #define fib_window fib_metrics[RTAX_WINDOW-1]
1201da177e4SLinus Torvalds #define fib_rtt fib_metrics[RTAX_RTT-1]
1211da177e4SLinus Torvalds #define fib_advmss fib_metrics[RTAX_ADVMSS-1]
1221da177e4SLinus Torvalds 	int			fib_nhs;
1231da177e4SLinus Torvalds #ifdef CONFIG_IP_ROUTE_MULTIPATH
1240e884c78SPeter Nørlund 	int			fib_weight;
1251da177e4SLinus Torvalds #endif
126c9850187SJiri Pirko 	unsigned int		fib_offload_cnt;
127ebc0ffaeSEric Dumazet 	struct rcu_head		rcu;
1281da177e4SLinus Torvalds 	struct fib_nh		fib_nh[0];
1291da177e4SLinus Torvalds #define fib_dev		fib_nh[0].nh_dev
1301da177e4SLinus Torvalds };
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES
1341da177e4SLinus Torvalds struct fib_rule;
1351da177e4SLinus Torvalds #endif
1361da177e4SLinus Torvalds 
1375b470441SDavid S. Miller struct fib_table;
1381da177e4SLinus Torvalds struct fib_result {
1391da177e4SLinus Torvalds 	unsigned char	prefixlen;
1401da177e4SLinus Torvalds 	unsigned char	nh_sel;
1411da177e4SLinus Torvalds 	unsigned char	type;
1421da177e4SLinus Torvalds 	unsigned char	scope;
14385b91b03SDavid S. Miller 	u32		tclassid;
1441da177e4SLinus Torvalds 	struct fib_info *fi;
1455b470441SDavid S. Miller 	struct fib_table *table;
14656315f9eSAlexander Duyck 	struct hlist_head *fa_head;
1471da177e4SLinus Torvalds };
1481da177e4SLinus Torvalds 
149246955feSRobert Olsson struct fib_result_nl {
15080e856e1SAl Viro 	__be32		fl_addr;   /* To be looked up*/
1515f300893SThomas Graf 	u32		fl_mark;
152246955feSRobert Olsson 	unsigned char	fl_tos;
153246955feSRobert Olsson 	unsigned char   fl_scope;
154246955feSRobert Olsson 	unsigned char   tb_id_in;
155246955feSRobert Olsson 
156246955feSRobert Olsson 	unsigned char   tb_id;      /* Results */
157246955feSRobert Olsson 	unsigned char	prefixlen;
158246955feSRobert Olsson 	unsigned char	nh_sel;
159246955feSRobert Olsson 	unsigned char	type;
160246955feSRobert Olsson 	unsigned char	scope;
161246955feSRobert Olsson 	int             err;
162246955feSRobert Olsson };
1631da177e4SLinus Torvalds 
1641da177e4SLinus Torvalds #ifdef CONFIG_IP_ROUTE_MULTIPATH
1651da177e4SLinus Torvalds #define FIB_RES_NH(res)		((res).fi->fib_nh[(res).nh_sel])
1661da177e4SLinus Torvalds #else /* CONFIG_IP_ROUTE_MULTIPATH */
1671da177e4SLinus Torvalds #define FIB_RES_NH(res)		((res).fi->fib_nh[0])
1681da177e4SLinus Torvalds #endif /* CONFIG_IP_ROUTE_MULTIPATH */
1691da177e4SLinus Torvalds 
1705b9e12dbSDenis V. Lunev #ifdef CONFIG_IP_MULTIPLE_TABLES
1715b9e12dbSDenis V. Lunev #define FIB_TABLE_HASHSZ 256
1725b9e12dbSDenis V. Lunev #else
1735b9e12dbSDenis V. Lunev #define FIB_TABLE_HASHSZ 2
1745b9e12dbSDenis V. Lunev #endif
1755b9e12dbSDenis V. Lunev 
1765c3a0fd7SJoe Perches __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
177436c3b66SDavid S. Miller 
178c9850187SJiri Pirko static inline void fib_info_offload_inc(struct fib_info *fi)
179c9850187SJiri Pirko {
180c9850187SJiri Pirko 	fi->fib_offload_cnt++;
181c9850187SJiri Pirko 	fi->fib_flags |= RTNH_F_OFFLOAD;
182c9850187SJiri Pirko }
183c9850187SJiri Pirko 
184c9850187SJiri Pirko static inline void fib_info_offload_dec(struct fib_info *fi)
185c9850187SJiri Pirko {
186c9850187SJiri Pirko 	if (--fi->fib_offload_cnt == 0)
187c9850187SJiri Pirko 		fi->fib_flags &= ~RTNH_F_OFFLOAD;
188c9850187SJiri Pirko }
189c9850187SJiri Pirko 
190436c3b66SDavid S. Miller #define FIB_RES_SADDR(net, res)				\
191436c3b66SDavid S. Miller 	((FIB_RES_NH(res).nh_saddr_genid ==		\
192436c3b66SDavid S. Miller 	  atomic_read(&(net)->ipv4.dev_addr_genid)) ?	\
193436c3b66SDavid S. Miller 	 FIB_RES_NH(res).nh_saddr :			\
194436c3b66SDavid S. Miller 	 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
1951da177e4SLinus Torvalds #define FIB_RES_GW(res)			(FIB_RES_NH(res).nh_gw)
1961da177e4SLinus Torvalds #define FIB_RES_DEV(res)		(FIB_RES_NH(res).nh_dev)
1971da177e4SLinus Torvalds #define FIB_RES_OIF(res)		(FIB_RES_NH(res).nh_oif)
1981da177e4SLinus Torvalds 
199436c3b66SDavid S. Miller #define FIB_RES_PREFSRC(net, res)	((res).fi->fib_prefsrc ? : \
200436c3b66SDavid S. Miller 					 FIB_RES_SADDR(net, res))
2011fc050a1SDavid S. Miller 
202b90eb754SJiri Pirko struct fib_notifier_info {
203b90eb754SJiri Pirko 	struct net *net;
204b90eb754SJiri Pirko };
205b90eb754SJiri Pirko 
206b90eb754SJiri Pirko struct fib_entry_notifier_info {
207b90eb754SJiri Pirko 	struct fib_notifier_info info; /* must be first */
208b90eb754SJiri Pirko 	u32 dst;
209b90eb754SJiri Pirko 	int dst_len;
210b90eb754SJiri Pirko 	struct fib_info *fi;
211b90eb754SJiri Pirko 	u8 tos;
212b90eb754SJiri Pirko 	u8 type;
213b90eb754SJiri Pirko 	u32 tb_id;
214b90eb754SJiri Pirko 	u32 nlflags;
215b90eb754SJiri Pirko };
216b90eb754SJiri Pirko 
217*982acb97SIdo Schimmel struct fib_nh_notifier_info {
218*982acb97SIdo Schimmel 	struct fib_notifier_info info; /* must be first */
219*982acb97SIdo Schimmel 	struct fib_nh *fib_nh;
220*982acb97SIdo Schimmel };
221*982acb97SIdo Schimmel 
222b90eb754SJiri Pirko enum fib_event_type {
223b90eb754SJiri Pirko 	FIB_EVENT_ENTRY_ADD,
224b90eb754SJiri Pirko 	FIB_EVENT_ENTRY_DEL,
225b90eb754SJiri Pirko 	FIB_EVENT_RULE_ADD,
226b90eb754SJiri Pirko 	FIB_EVENT_RULE_DEL,
227*982acb97SIdo Schimmel 	FIB_EVENT_NH_ADD,
228*982acb97SIdo Schimmel 	FIB_EVENT_NH_DEL,
229b90eb754SJiri Pirko };
230b90eb754SJiri Pirko 
231c3852ef7SIdo Schimmel int register_fib_notifier(struct notifier_block *nb,
232c3852ef7SIdo Schimmel 			  void (*cb)(struct notifier_block *nb));
233b90eb754SJiri Pirko int unregister_fib_notifier(struct notifier_block *nb);
234b90eb754SJiri Pirko int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
235b90eb754SJiri Pirko 		       struct fib_notifier_info *info);
236b90eb754SJiri Pirko 
2371da177e4SLinus Torvalds struct fib_table {
2381af5a8c4SPatrick McHardy 	struct hlist_node	tb_hlist;
2392dfe55b4SPatrick McHardy 	u32			tb_id;
24021d8c49eSDavid S. Miller 	int			tb_num_default;
241a7e53531SAlexander Duyck 	struct rcu_head		rcu;
2420ddcf43dSAlexander Duyck 	unsigned long 		*tb_data;
2430ddcf43dSAlexander Duyck 	unsigned long		__data[0];
2441da177e4SLinus Torvalds };
2451da177e4SLinus Torvalds 
2465c3a0fd7SJoe Perches int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
247ebc0ffaeSEric Dumazet 		     struct fib_result *res, int fib_flags);
248b90eb754SJiri Pirko int fib_table_insert(struct net *, struct fib_table *, struct fib_config *);
249b90eb754SJiri Pirko int fib_table_delete(struct net *, struct fib_table *, struct fib_config *);
2505c3a0fd7SJoe Perches int fib_table_dump(struct fib_table *table, struct sk_buff *skb,
25116c6cf8bSStephen Hemminger 		   struct netlink_callback *cb);
252b90eb754SJiri Pirko int fib_table_flush(struct net *net, struct fib_table *table);
2530ddcf43dSAlexander Duyck struct fib_table *fib_trie_unmerge(struct fib_table *main_tb);
2543b709334SAlexander Duyck void fib_table_flush_external(struct fib_table *table);
2555c3a0fd7SJoe Perches void fib_free_table(struct fib_table *tb);
2564aa2c466SPavel Emelyanov 
2571da177e4SLinus Torvalds #ifndef CONFIG_IP_MULTIPLE_TABLES
2581da177e4SLinus Torvalds 
259a5a519b2SAlexander Duyck #define TABLE_LOCAL_INDEX	(RT_TABLE_LOCAL & (FIB_TABLE_HASHSZ - 1))
260a5a519b2SAlexander Duyck #define TABLE_MAIN_INDEX	(RT_TABLE_MAIN  & (FIB_TABLE_HASHSZ - 1))
2611da177e4SLinus Torvalds 
2628ad4942cSDenis V. Lunev static inline struct fib_table *fib_get_table(struct net *net, u32 id)
2631da177e4SLinus Torvalds {
264a7e53531SAlexander Duyck 	struct hlist_node *tb_hlist;
26593456b6dSDenis V. Lunev 	struct hlist_head *ptr;
26693456b6dSDenis V. Lunev 
26793456b6dSDenis V. Lunev 	ptr = id == RT_TABLE_LOCAL ?
268e4aef8aeSDenis V. Lunev 		&net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX] :
269e4aef8aeSDenis V. Lunev 		&net->ipv4.fib_table_hash[TABLE_MAIN_INDEX];
270a7e53531SAlexander Duyck 
271a7e53531SAlexander Duyck 	tb_hlist = rcu_dereference_rtnl(hlist_first_rcu(ptr));
272a7e53531SAlexander Duyck 
273a7e53531SAlexander Duyck 	return hlist_entry(tb_hlist, struct fib_table, tb_hlist);
2741da177e4SLinus Torvalds }
2751da177e4SLinus Torvalds 
2768ad4942cSDenis V. Lunev static inline struct fib_table *fib_new_table(struct net *net, u32 id)
2771da177e4SLinus Torvalds {
2788ad4942cSDenis V. Lunev 	return fib_get_table(net, id);
2791da177e4SLinus Torvalds }
2801da177e4SLinus Torvalds 
28122bd5b9bSDavid S. Miller static inline int fib_lookup(struct net *net, const struct flowi4 *flp,
2820eeb075fSAndy Gospodarek 			     struct fib_result *res, unsigned int flags)
2831da177e4SLinus Torvalds {
284a7e53531SAlexander Duyck 	struct fib_table *tb;
2850ddcf43dSAlexander Duyck 	int err = -ENETUNREACH;
28693456b6dSDenis V. Lunev 
287345e9b54SAlexander Duyck 	rcu_read_lock();
28893456b6dSDenis V. Lunev 
289a7e53531SAlexander Duyck 	tb = fib_get_table(net, RT_TABLE_MAIN);
2900315e382SNikola Forró 	if (tb)
2910315e382SNikola Forró 		err = fib_table_lookup(tb, flp, res, flags | FIB_LOOKUP_NOREF);
2920315e382SNikola Forró 
2930315e382SNikola Forró 	if (err == -EAGAIN)
2940315e382SNikola Forró 		err = -ENETUNREACH;
295345e9b54SAlexander Duyck 
296345e9b54SAlexander Duyck 	rcu_read_unlock();
297345e9b54SAlexander Duyck 
298345e9b54SAlexander Duyck 	return err;
2991da177e4SLinus Torvalds }
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds #else /* CONFIG_IP_MULTIPLE_TABLES */
3025c3a0fd7SJoe Perches int __net_init fib4_rules_init(struct net *net);
3035c3a0fd7SJoe Perches void __net_exit fib4_rules_exit(struct net *net);
304c3e9a353SPavel Emelyanov 
3055c3a0fd7SJoe Perches struct fib_table *fib_new_table(struct net *net, u32 id);
3065c3a0fd7SJoe Perches struct fib_table *fib_get_table(struct net *net, u32 id);
3071da177e4SLinus Torvalds 
3080eeb075fSAndy Gospodarek int __fib_lookup(struct net *net, struct flowi4 *flp,
3090eeb075fSAndy Gospodarek 		 struct fib_result *res, unsigned int flags);
310f4530fa5SDavid S. Miller 
311f4530fa5SDavid S. Miller static inline int fib_lookup(struct net *net, struct flowi4 *flp,
3120eeb075fSAndy Gospodarek 			     struct fib_result *res, unsigned int flags)
313f4530fa5SDavid S. Miller {
314a7e53531SAlexander Duyck 	struct fib_table *tb;
3150315e382SNikola Forró 	int err = -ENETUNREACH;
316a7e53531SAlexander Duyck 
3170eeb075fSAndy Gospodarek 	flags |= FIB_LOOKUP_NOREF;
318a7e53531SAlexander Duyck 	if (net->ipv4.fib_has_custom_rules)
3190eeb075fSAndy Gospodarek 		return __fib_lookup(net, flp, res, flags);
320345e9b54SAlexander Duyck 
321345e9b54SAlexander Duyck 	rcu_read_lock();
322345e9b54SAlexander Duyck 
32385b91b03SDavid S. Miller 	res->tclassid = 0;
324a7e53531SAlexander Duyck 
325a7e53531SAlexander Duyck 	tb = rcu_dereference_rtnl(net->ipv4.fib_main);
3260315e382SNikola Forró 	if (tb)
3270315e382SNikola Forró 		err = fib_table_lookup(tb, flp, res, flags);
3280315e382SNikola Forró 
3290315e382SNikola Forró 	if (!err)
3300315e382SNikola Forró 		goto out;
331a7e53531SAlexander Duyck 
332a7e53531SAlexander Duyck 	tb = rcu_dereference_rtnl(net->ipv4.fib_default);
3330315e382SNikola Forró 	if (tb)
3340315e382SNikola Forró 		err = fib_table_lookup(tb, flp, res, flags);
3350315e382SNikola Forró 
3360315e382SNikola Forró out:
3370315e382SNikola Forró 	if (err == -EAGAIN)
3380315e382SNikola Forró 		err = -ENETUNREACH;
339345e9b54SAlexander Duyck 
340345e9b54SAlexander Duyck 	rcu_read_unlock();
341345e9b54SAlexander Duyck 
342345e9b54SAlexander Duyck 	return err;
343f4530fa5SDavid S. Miller }
344f4530fa5SDavid S. Miller 
3451da177e4SLinus Torvalds #endif /* CONFIG_IP_MULTIPLE_TABLES */
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds /* Exported by fib_frontend.c */
348ef7c79edSPatrick McHardy extern const struct nla_policy rtm_ipv4_policy[];
3495c3a0fd7SJoe Perches void ip_fib_init(void);
3505c3a0fd7SJoe Perches __be32 fib_compute_spec_dst(struct sk_buff *skb);
3515c3a0fd7SJoe Perches int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
3525c04c819SMichael Smith 			u8 tos, int oif, struct net_device *dev,
3539e56e380SDavid S. Miller 			struct in_device *idev, u32 *itag);
3547a9bc9b8SDavid S. Miller #ifdef CONFIG_IP_ROUTE_CLASSID
355f4530fa5SDavid S. Miller static inline int fib_num_tclassid_users(struct net *net)
356f4530fa5SDavid S. Miller {
357f4530fa5SDavid S. Miller 	return net->ipv4.fib_num_tclassid_users;
358f4530fa5SDavid S. Miller }
3597a9bc9b8SDavid S. Miller #else
360f4530fa5SDavid S. Miller static inline int fib_num_tclassid_users(struct net *net)
361f4530fa5SDavid S. Miller {
362f4530fa5SDavid S. Miller 	return 0;
363f4530fa5SDavid S. Miller }
3647a9bc9b8SDavid S. Miller #endif
3650ddcf43dSAlexander Duyck int fib_unmerge(struct net *net);
36614c85021SArnaldo Carvalho de Melo 
3671da177e4SLinus Torvalds /* Exported by fib_semantics.c */
3685c3a0fd7SJoe Perches int ip_fib_check_default(__be32 gw, struct net_device *dev);
3694f823defSJulian Anastasov int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force);
3705a56a0b3SMark Tomlinson int fib_sync_down_addr(struct net_device *dev, __be32 local);
3718a3d0316SAndy Gospodarek int fib_sync_up(struct net_device *dev, unsigned int nh_flags);
3720e884c78SPeter Nørlund 
3730e884c78SPeter Nørlund extern u32 fib_multipath_secret __read_mostly;
3740e884c78SPeter Nørlund 
3750e884c78SPeter Nørlund static inline int fib_multipath_hash(__be32 saddr, __be32 daddr)
3760e884c78SPeter Nørlund {
3770797cbd8SLance Richardson 	return jhash_2words((__force u32)saddr, (__force u32)daddr,
3780797cbd8SLance Richardson 			    fib_multipath_secret) >> 1;
3790e884c78SPeter Nørlund }
3800e884c78SPeter Nørlund 
3810e884c78SPeter Nørlund void fib_select_multipath(struct fib_result *res, int hash);
3823ce58d84SDavid Ahern void fib_select_path(struct net *net, struct fib_result *res,
3833ce58d84SDavid Ahern 		     struct flowi4 *fl4, int mp_hash);
3841da177e4SLinus Torvalds 
3855348ba85SDavid S. Miller /* Exported by fib_trie.c */
3865c3a0fd7SJoe Perches void fib_trie_init(void);
3870ddcf43dSAlexander Duyck struct fib_table *fib_trie_table(u32 id, struct fib_table *alias);
3881da177e4SLinus Torvalds 
389b6bf3ca0SDavid S. Miller static inline void fib_combine_itag(u32 *itag, const struct fib_result *res)
3901da177e4SLinus Torvalds {
391c7066f70SPatrick McHardy #ifdef CONFIG_IP_ROUTE_CLASSID
3921da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES
3931da177e4SLinus Torvalds 	u32 rtag;
3941da177e4SLinus Torvalds #endif
3951da177e4SLinus Torvalds 	*itag = FIB_RES_NH(*res).nh_tclassid<<16;
3961da177e4SLinus Torvalds #ifdef CONFIG_IP_MULTIPLE_TABLES
39785b91b03SDavid S. Miller 	rtag = res->tclassid;
3981da177e4SLinus Torvalds 	if (*itag == 0)
3991da177e4SLinus Torvalds 		*itag = (rtag<<16);
4001da177e4SLinus Torvalds 	*itag |= (rtag>>16);
4011da177e4SLinus Torvalds #endif
4021da177e4SLinus Torvalds #endif
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds 
4055c3a0fd7SJoe Perches void free_fib_info(struct fib_info *fi);
4061da177e4SLinus Torvalds 
4071c677b3dSIdo Schimmel static inline void fib_info_hold(struct fib_info *fi)
4081c677b3dSIdo Schimmel {
4091c677b3dSIdo Schimmel 	atomic_inc(&fi->fib_clntref);
4101c677b3dSIdo Schimmel }
4111c677b3dSIdo Schimmel 
4121da177e4SLinus Torvalds static inline void fib_info_put(struct fib_info *fi)
4131da177e4SLinus Torvalds {
4141da177e4SLinus Torvalds 	if (atomic_dec_and_test(&fi->fib_clntref))
4151da177e4SLinus Torvalds 		free_fib_info(fi);
4161da177e4SLinus Torvalds }
4171da177e4SLinus Torvalds 
41820380731SArnaldo Carvalho de Melo #ifdef CONFIG_PROC_FS
4195c3a0fd7SJoe Perches int __net_init fib_proc_init(struct net *net);
4205c3a0fd7SJoe Perches void __net_exit fib_proc_exit(struct net *net);
421cc8274f5SLi Zefan #else
422cc8274f5SLi Zefan static inline int fib_proc_init(struct net *net)
423cc8274f5SLi Zefan {
424cc8274f5SLi Zefan 	return 0;
425cc8274f5SLi Zefan }
426cc8274f5SLi Zefan static inline void fib_proc_exit(struct net *net)
427cc8274f5SLi Zefan {
428cc8274f5SLi Zefan }
42920380731SArnaldo Carvalho de Melo #endif
43020380731SArnaldo Carvalho de Melo 
4311da177e4SLinus Torvalds #endif  /* _NET_FIB_H */
432