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.
35 struct rtattr *rta_mx;
36 struct rtattr *rta_mp;
37 unsigned char *rta_protoinfo;
39 struct rta_cacheinfo *rta_ci;
40 struct rta_session *rta_sess;
45 struct net_device *nh_dev;
47 unsigned char nh_scope;
48 #ifdef CONFIG_IP_ROUTE_MULTIPATH
52 #ifdef CONFIG_NET_CLS_ROUTE
60 * This structure contains data shared by many of routes.
65 struct fib_info *fib_next;
66 struct fib_info *fib_prev;
74 u32 fib_metrics[RTAX_MAX];
75 #define fib_mtu fib_metrics[RTAX_MTU-1]
76 #define fib_window fib_metrics[RTAX_WINDOW-1]
77 #define fib_rtt fib_metrics[RTAX_RTT-1]
78 #define fib_advmss fib_metrics[RTAX_ADVMSS-1]
80 #ifdef CONFIG_IP_ROUTE_MULTIPATH
83 struct fib_nh fib_nh[0];
84 #define fib_dev fib_nh[0].nh_dev
88 #ifdef CONFIG_IP_MULTIPLE_TABLES
94 unsigned char prefixlen;
99 #ifdef CONFIG_IP_MULTIPLE_TABLES
105 #ifdef CONFIG_IP_ROUTE_MULTIPATH
107 #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
108 #define FIB_RES_RESET(res) ((res).nh_sel = 0)
110 #else /* CONFIG_IP_ROUTE_MULTIPATH */
112 #define FIB_RES_NH(res) ((res).fi->fib_nh[0])
113 #define FIB_RES_RESET(res)
115 #endif /* CONFIG_IP_ROUTE_MULTIPATH */
117 #define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res))
118 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
119 #define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
120 #define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif)
126 int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
127 int (*tb_insert)(struct fib_table *table, struct rtmsg *r,
128 struct kern_rta *rta, struct nlmsghdr *n,
129 struct netlink_skb_parms *req);
130 int (*tb_delete)(struct fib_table *table, struct rtmsg *r,
131 struct kern_rta *rta, struct nlmsghdr *n,
132 struct netlink_skb_parms *req);
133 int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
134 struct netlink_callback *cb);
135 int (*tb_flush)(struct fib_table *table);
136 void (*tb_select_default)(struct fib_table *table,
137 const struct flowi *flp, struct fib_result *res);
139 unsigned char tb_data[0];
142 #ifndef CONFIG_IP_MULTIPLE_TABLES
144 extern struct fib_table *ip_fib_local_table;
145 extern struct fib_table *ip_fib_main_table;
147 static inline struct fib_table *fib_get_table(int id)
149 if (id != RT_TABLE_LOCAL)
150 return ip_fib_main_table;
151 return ip_fib_local_table;
154 static inline struct fib_table *fib_new_table(int id)
156 return fib_get_table(id);
159 static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
161 if (ip_fib_local_table->tb_lookup(ip_fib_local_table, flp, res) &&
162 ip_fib_main_table->tb_lookup(ip_fib_main_table, flp, res))
167 static inline void fib_select_default(const struct flowi *flp, struct fib_result *res)
169 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
170 ip_fib_main_table->tb_select_default(ip_fib_main_table, flp, res);
173 #else /* CONFIG_IP_MULTIPLE_TABLES */
174 #define ip_fib_local_table (fib_tables[RT_TABLE_LOCAL])
175 #define ip_fib_main_table (fib_tables[RT_TABLE_MAIN])
177 extern struct fib_table * fib_tables[RT_TABLE_MAX+1];
178 extern int fib_lookup(const struct flowi *flp, struct fib_result *res);
179 extern struct fib_table *__fib_new_table(int id);
180 extern void fib_rule_put(struct fib_rule *r);
182 static inline struct fib_table *fib_get_table(int id)
187 return fib_tables[id];
190 static inline struct fib_table *fib_new_table(int id)
195 return fib_tables[id] ? : __fib_new_table(id);
198 extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
200 #endif /* CONFIG_IP_MULTIPLE_TABLES */
202 /* Exported by fib_frontend.c */
203 extern void ip_fib_init(void);
204 extern void fib_flush(void);
205 extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
206 extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
207 extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
208 extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
209 extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif,
210 struct net_device *dev, u32 *spec_dst, u32 *itag);
211 extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
213 /* Exported by fib_semantics.c */
214 extern int ip_fib_check_default(u32 gw, struct net_device *dev);
215 extern void fib_release_info(struct fib_info *);
216 extern int fib_semantic_match(int type, struct fib_info *,
217 const struct flowi *, struct fib_result*);
218 extern struct fib_info *fib_create_info(const struct rtmsg *r, struct kern_rta *rta,
219 const struct nlmsghdr *, int *err);
220 extern int fib_nh_match(struct rtmsg *r, struct nlmsghdr *, struct kern_rta *rta, struct fib_info *fi);
221 extern int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
222 u8 tb_id, u8 type, u8 scope, void *dst, int dst_len, u8 tos,
223 struct fib_info *fi);
224 extern int fib_sync_down(u32 local, struct net_device *dev, int force);
225 extern int fib_sync_up(struct net_device *dev);
226 extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
227 struct kern_rta *rta, struct rtentry *r);
228 extern void fib_node_seq_show(struct seq_file *seq, int type, int dead,
229 struct fib_info *fi, u32 prefix, u32 mask);
230 extern u32 __fib_res_prefsrc(struct fib_result *res);
232 /* Exported by fib_hash.c */
233 extern struct fib_table *fib_hash_init(int id);
235 #ifdef CONFIG_IP_MULTIPLE_TABLES
236 /* Exported by fib_rules.c */
238 extern int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
239 extern int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
240 extern int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
241 extern u32 fib_rules_map_destination(u32 daddr, struct fib_result *res);
242 #ifdef CONFIG_NET_CLS_ROUTE
243 extern u32 fib_rules_tclass(struct fib_result *res);
245 extern u32 fib_rules_policy(u32 saddr, struct fib_result *res, unsigned *flags);
246 extern void fib_rules_init(void);
249 static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
251 #ifdef CONFIG_NET_CLS_ROUTE
252 #ifdef CONFIG_IP_MULTIPLE_TABLES
255 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
256 #ifdef CONFIG_IP_MULTIPLE_TABLES
257 rtag = fib_rules_tclass(res);
265 extern void free_fib_info(struct fib_info *fi);
267 static inline void fib_info_put(struct fib_info *fi)
269 if (atomic_dec_and_test(&fi->fib_clntref))
273 static inline void fib_res_put(struct fib_result *res)
276 fib_info_put(res->fi);
277 #ifdef CONFIG_IP_MULTIPLE_TABLES
279 fib_rule_put(res->r);
283 #endif /* _NET_FIB_H */