2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * Definitions for the Forwarding Information Base.
8 * Authors: A.N.Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
20 #include <linux/seq_file.h>
21 #include <net/fib_rules.h>
38 struct rtnexthop
*fc_mp
;
44 struct nl_info fc_nlinfo
;
50 struct net_device
*nh_dev
;
51 struct hlist_node nh_hash
;
52 struct fib_info
*nh_parent
;
54 unsigned char nh_scope
;
55 #ifdef CONFIG_IP_ROUTE_MULTIPATH
59 #ifdef CONFIG_NET_CLS_ROUTE
67 * This structure contains data shared by many of routes.
71 struct hlist_node fib_hash
;
72 struct hlist_node fib_lhash
;
80 u32 fib_metrics
[RTAX_MAX
];
81 #define fib_mtu fib_metrics[RTAX_MTU-1]
82 #define fib_window fib_metrics[RTAX_WINDOW-1]
83 #define fib_rtt fib_metrics[RTAX_RTT-1]
84 #define fib_advmss fib_metrics[RTAX_ADVMSS-1]
86 #ifdef CONFIG_IP_ROUTE_MULTIPATH
89 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
92 struct fib_nh fib_nh
[0];
93 #define fib_dev fib_nh[0].nh_dev
97 #ifdef CONFIG_IP_MULTIPLE_TABLES
102 unsigned char prefixlen
;
103 unsigned char nh_sel
;
106 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
111 #ifdef CONFIG_IP_MULTIPLE_TABLES
116 struct fib_result_nl
{
117 __be32 fl_addr
; /* To be looked up*/
119 unsigned char fl_tos
;
120 unsigned char fl_scope
;
121 unsigned char tb_id_in
;
123 unsigned char tb_id
; /* Results */
124 unsigned char prefixlen
;
125 unsigned char nh_sel
;
131 #ifdef CONFIG_IP_ROUTE_MULTIPATH
133 #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
134 #define FIB_RES_RESET(res) ((res).nh_sel = 0)
136 #else /* CONFIG_IP_ROUTE_MULTIPATH */
138 #define FIB_RES_NH(res) ((res).fi->fib_nh[0])
139 #define FIB_RES_RESET(res)
141 #endif /* CONFIG_IP_ROUTE_MULTIPATH */
143 #define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res))
144 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
145 #define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
146 #define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif)
148 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
149 #define FIB_RES_NETWORK(res) ((res).network)
150 #define FIB_RES_NETMASK(res) ((res).netmask)
151 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
152 #define FIB_RES_NETWORK(res) (0)
153 #define FIB_RES_NETMASK(res) (0)
154 #endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */
157 struct hlist_node tb_hlist
;
160 int (*tb_lookup
)(struct fib_table
*tb
, const struct flowi
*flp
, struct fib_result
*res
);
161 int (*tb_insert
)(struct fib_table
*, struct fib_config
*);
162 int (*tb_delete
)(struct fib_table
*, struct fib_config
*);
163 int (*tb_dump
)(struct fib_table
*table
, struct sk_buff
*skb
,
164 struct netlink_callback
*cb
);
165 int (*tb_flush
)(struct fib_table
*table
);
166 void (*tb_select_default
)(struct fib_table
*table
,
167 const struct flowi
*flp
, struct fib_result
*res
);
169 unsigned char tb_data
[0];
172 #ifndef CONFIG_IP_MULTIPLE_TABLES
174 extern struct fib_table
*ip_fib_local_table
;
175 extern struct fib_table
*ip_fib_main_table
;
177 static inline struct fib_table
*fib_get_table(u32 id
)
179 if (id
!= RT_TABLE_LOCAL
)
180 return ip_fib_main_table
;
181 return ip_fib_local_table
;
184 static inline struct fib_table
*fib_new_table(u32 id
)
186 return fib_get_table(id
);
189 static inline int fib_lookup(const struct flowi
*flp
, struct fib_result
*res
)
191 if (ip_fib_local_table
->tb_lookup(ip_fib_local_table
, flp
, res
) &&
192 ip_fib_main_table
->tb_lookup(ip_fib_main_table
, flp
, res
))
197 static inline void fib_select_default(const struct flowi
*flp
, struct fib_result
*res
)
199 if (FIB_RES_GW(*res
) && FIB_RES_NH(*res
).nh_scope
== RT_SCOPE_LINK
)
200 ip_fib_main_table
->tb_select_default(ip_fib_main_table
, flp
, res
);
203 #else /* CONFIG_IP_MULTIPLE_TABLES */
204 #define ip_fib_local_table fib_get_table(RT_TABLE_LOCAL)
205 #define ip_fib_main_table fib_get_table(RT_TABLE_MAIN)
207 extern int fib_lookup(struct flowi
*flp
, struct fib_result
*res
);
209 extern struct fib_table
*fib_new_table(u32 id
);
210 extern struct fib_table
*fib_get_table(u32 id
);
211 extern void fib_select_default(const struct flowi
*flp
, struct fib_result
*res
);
213 #endif /* CONFIG_IP_MULTIPLE_TABLES */
215 /* Exported by fib_frontend.c */
216 extern struct nla_policy rtm_ipv4_policy
[];
217 extern void ip_fib_init(void);
218 extern int inet_rtm_delroute(struct sk_buff
*skb
, struct nlmsghdr
* nlh
, void *arg
);
219 extern int inet_rtm_newroute(struct sk_buff
*skb
, struct nlmsghdr
* nlh
, void *arg
);
220 extern int inet_rtm_getroute(struct sk_buff
*skb
, struct nlmsghdr
* nlh
, void *arg
);
221 extern int inet_dump_fib(struct sk_buff
*skb
, struct netlink_callback
*cb
);
222 extern int fib_validate_source(__be32 src
, __be32 dst
, u8 tos
, int oif
,
223 struct net_device
*dev
, __be32
*spec_dst
, u32
*itag
);
224 extern void fib_select_multipath(const struct flowi
*flp
, struct fib_result
*res
);
228 /* Exported by fib_semantics.c */
229 extern int ip_fib_check_default(__be32 gw
, struct net_device
*dev
);
230 extern int fib_sync_down(__be32 local
, struct net_device
*dev
, int force
);
231 extern int fib_sync_up(struct net_device
*dev
);
232 extern __be32
__fib_res_prefsrc(struct fib_result
*res
);
234 /* Exported by fib_hash.c */
235 extern struct fib_table
*fib_hash_init(u32 id
);
237 #ifdef CONFIG_IP_MULTIPLE_TABLES
238 extern int fib4_rules_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
);
240 extern void __init
fib4_rules_init(void);
242 #ifdef CONFIG_NET_CLS_ROUTE
243 extern u32
fib_rules_tclass(struct fib_result
*res
);
248 static inline void fib_combine_itag(u32
*itag
, struct fib_result
*res
)
250 #ifdef CONFIG_NET_CLS_ROUTE
251 #ifdef CONFIG_IP_MULTIPLE_TABLES
254 *itag
= FIB_RES_NH(*res
).nh_tclassid
<<16;
255 #ifdef CONFIG_IP_MULTIPLE_TABLES
256 rtag
= fib_rules_tclass(res
);
264 extern void free_fib_info(struct fib_info
*fi
);
266 static inline void fib_info_put(struct fib_info
*fi
)
268 if (atomic_dec_and_test(&fi
->fib_clntref
))
272 static inline void fib_res_put(struct fib_result
*res
)
275 fib_info_put(res
->fi
);
276 #ifdef CONFIG_IP_MULTIPLE_TABLES
278 fib_rule_put(res
->r
);
282 #ifdef CONFIG_PROC_FS
283 extern int fib_proc_init(void);
284 extern void fib_proc_exit(void);
287 #endif /* _NET_FIB_H */