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.
19 #include <linux/config.h>
21 #include <linux/seq_file.h>
23 /* WARNING: The ordering of these elements must match ordering
24 * of RTA_* rtnetlink attribute numbers.
34 struct rtattr *rta_mx;
35 struct rtattr *rta_mp;
36 unsigned char *rta_protoinfo;
38 struct rta_cacheinfo *rta_ci;
39 struct rta_session *rta_sess;
46 struct net_device *nh_dev;
47 struct hlist_node nh_hash;
48 struct fib_info *nh_parent;
50 unsigned char nh_scope;
51 #ifdef CONFIG_IP_ROUTE_MULTIPATH
55 #ifdef CONFIG_NET_CLS_ROUTE
63 * This structure contains data shared by many of routes.
67 struct hlist_node fib_hash;
68 struct hlist_node fib_lhash;
76 u32 fib_metrics[RTAX_MAX];
77 #define fib_mtu fib_metrics[RTAX_MTU-1]
78 #define fib_window fib_metrics[RTAX_WINDOW-1]
79 #define fib_rtt fib_metrics[RTAX_RTT-1]
80 #define fib_advmss fib_metrics[RTAX_ADVMSS-1]
82 #ifdef CONFIG_IP_ROUTE_MULTIPATH
85 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
88 struct fib_nh fib_nh[0];
89 #define fib_dev fib_nh[0].nh_dev
93 #ifdef CONFIG_IP_MULTIPLE_TABLES
98 unsigned char prefixlen;
102 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
107 #ifdef CONFIG_IP_MULTIPLE_TABLES
112 struct fib_result_nl {
113 u32 fl_addr; /* To be looked up*/
115 unsigned char fl_tos;
116 unsigned char fl_scope;
117 unsigned char tb_id_in;
119 unsigned char tb_id; /* Results */
120 unsigned char prefixlen;
121 unsigned char nh_sel;
127 #ifdef CONFIG_IP_ROUTE_MULTIPATH
129 #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
130 #define FIB_RES_RESET(res) ((res).nh_sel = 0)
132 #else /* CONFIG_IP_ROUTE_MULTIPATH */
134 #define FIB_RES_NH(res) ((res).fi->fib_nh[0])
135 #define FIB_RES_RESET(res)
137 #endif /* CONFIG_IP_ROUTE_MULTIPATH */
139 #define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res))
140 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
141 #define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
142 #define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif)
144 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
145 #define FIB_RES_NETWORK(res) ((res).network)
146 #define FIB_RES_NETMASK(res) ((res).netmask)
147 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
148 #define FIB_RES_NETWORK(res) (0)
149 #define FIB_RES_NETMASK(res) (0)
150 #endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */
155 int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
156 int (*tb_insert)(struct fib_table *table, struct rtmsg *r,
157 struct kern_rta *rta, struct nlmsghdr *n,
158 struct netlink_skb_parms *req);
159 int (*tb_delete)(struct fib_table *table, struct rtmsg *r,
160 struct kern_rta *rta, struct nlmsghdr *n,
161 struct netlink_skb_parms *req);
162 int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
163 struct netlink_callback *cb);
164 int (*tb_flush)(struct fib_table *table);
165 void (*tb_select_default)(struct fib_table *table,
166 const struct flowi *flp, struct fib_result *res);
168 unsigned char tb_data[0];
171 #ifndef CONFIG_IP_MULTIPLE_TABLES
173 extern struct fib_table *ip_fib_local_table;
174 extern struct fib_table *ip_fib_main_table;
176 static inline struct fib_table *fib_get_table(int id)
178 if (id != RT_TABLE_LOCAL)
179 return ip_fib_main_table;
180 return ip_fib_local_table;
183 static inline struct fib_table *fib_new_table(int id)
185 return fib_get_table(id);
188 static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
190 if (ip_fib_local_table->tb_lookup(ip_fib_local_table, flp, res) &&
191 ip_fib_main_table->tb_lookup(ip_fib_main_table, flp, res))
196 static inline void fib_select_default(const struct flowi *flp, struct fib_result *res)
198 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
199 ip_fib_main_table->tb_select_default(ip_fib_main_table, flp, res);
202 #else /* CONFIG_IP_MULTIPLE_TABLES */
203 #define ip_fib_local_table (fib_tables[RT_TABLE_LOCAL])
204 #define ip_fib_main_table (fib_tables[RT_TABLE_MAIN])
206 extern struct fib_table * fib_tables[RT_TABLE_MAX+1];
207 extern int fib_lookup(const struct flowi *flp, struct fib_result *res);
208 extern struct fib_table *__fib_new_table(int id);
209 extern void fib_rule_put(struct fib_rule *r);
211 static inline struct fib_table *fib_get_table(int id)
216 return fib_tables[id];
219 static inline struct fib_table *fib_new_table(int id)
224 return fib_tables[id] ? : __fib_new_table(id);
227 extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
229 #endif /* CONFIG_IP_MULTIPLE_TABLES */
231 /* Exported by fib_frontend.c */
232 extern void ip_fib_init(void);
233 extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
234 extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
235 extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
236 extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
237 extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif,
238 struct net_device *dev, u32 *spec_dst, u32 *itag);
239 extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
241 /* Exported by fib_semantics.c */
242 extern int ip_fib_check_default(u32 gw, struct net_device *dev);
243 extern int fib_sync_down(u32 local, struct net_device *dev, int force);
244 extern int fib_sync_up(struct net_device *dev);
245 extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
246 struct kern_rta *rta, struct rtentry *r);
247 extern u32 __fib_res_prefsrc(struct fib_result *res);
249 /* Exported by fib_hash.c */
250 extern struct fib_table *fib_hash_init(int id);
252 #ifdef CONFIG_IP_MULTIPLE_TABLES
253 /* Exported by fib_rules.c */
255 extern int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
256 extern int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
257 extern int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
258 #ifdef CONFIG_NET_CLS_ROUTE
259 extern u32 fib_rules_tclass(struct fib_result *res);
261 extern void fib_rules_init(void);
264 static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
266 #ifdef CONFIG_NET_CLS_ROUTE
267 #ifdef CONFIG_IP_MULTIPLE_TABLES
270 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
271 #ifdef CONFIG_IP_MULTIPLE_TABLES
272 rtag = fib_rules_tclass(res);
280 extern void free_fib_info(struct fib_info *fi);
282 static inline void fib_info_put(struct fib_info *fi)
284 if (atomic_dec_and_test(&fi->fib_clntref))
288 static inline void fib_res_put(struct fib_result *res)
291 fib_info_put(res->fi);
292 #ifdef CONFIG_IP_MULTIPLE_TABLES
294 fib_rule_put(res->r);
298 #endif /* _NET_FIB_H */