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;
45 struct net_device *nh_dev;
46 struct hlist_node nh_hash;
47 struct fib_info *nh_parent;
49 unsigned char nh_scope;
50 #ifdef CONFIG_IP_ROUTE_MULTIPATH
54 #ifdef CONFIG_NET_CLS_ROUTE
62 * This structure contains data shared by many of routes.
66 struct hlist_node fib_hash;
67 struct hlist_node fib_lhash;
75 u32 fib_metrics[RTAX_MAX];
76 #define fib_mtu fib_metrics[RTAX_MTU-1]
77 #define fib_window fib_metrics[RTAX_WINDOW-1]
78 #define fib_rtt fib_metrics[RTAX_RTT-1]
79 #define fib_advmss fib_metrics[RTAX_ADVMSS-1]
81 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84 struct fib_nh fib_nh[0];
85 #define fib_dev fib_nh[0].nh_dev
89 #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)
125 int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
126 int (*tb_insert)(struct fib_table *table, struct rtmsg *r,
127 struct kern_rta *rta, struct nlmsghdr *n,
128 struct netlink_skb_parms *req);
129 int (*tb_delete)(struct fib_table *table, struct rtmsg *r,
130 struct kern_rta *rta, struct nlmsghdr *n,
131 struct netlink_skb_parms *req);
132 int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
133 struct netlink_callback *cb);
134 int (*tb_flush)(struct fib_table *table);
135 void (*tb_select_default)(struct fib_table *table,
136 const struct flowi *flp, struct fib_result *res);
138 unsigned char tb_data[0];
141 #ifndef CONFIG_IP_MULTIPLE_TABLES
143 extern struct fib_table *ip_fib_local_table;
144 extern struct fib_table *ip_fib_main_table;
146 static inline struct fib_table *fib_get_table(int id)
148 if (id != RT_TABLE_LOCAL)
149 return ip_fib_main_table;
150 return ip_fib_local_table;
153 static inline struct fib_table *fib_new_table(int id)
155 return fib_get_table(id);
158 static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
160 if (ip_fib_local_table->tb_lookup(ip_fib_local_table, flp, res) &&
161 ip_fib_main_table->tb_lookup(ip_fib_main_table, flp, res))
166 static inline void fib_select_default(const struct flowi *flp, struct fib_result *res)
168 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
169 ip_fib_main_table->tb_select_default(ip_fib_main_table, flp, res);
172 #else /* CONFIG_IP_MULTIPLE_TABLES */
173 #define ip_fib_local_table (fib_tables[RT_TABLE_LOCAL])
174 #define ip_fib_main_table (fib_tables[RT_TABLE_MAIN])
176 extern struct fib_table * fib_tables[RT_TABLE_MAX+1];
177 extern int fib_lookup(const struct flowi *flp, struct fib_result *res);
178 extern struct fib_table *__fib_new_table(int id);
179 extern void fib_rule_put(struct fib_rule *r);
181 static inline struct fib_table *fib_get_table(int id)
186 return fib_tables[id];
189 static inline struct fib_table *fib_new_table(int id)
194 return fib_tables[id] ? : __fib_new_table(id);
197 extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
199 #endif /* CONFIG_IP_MULTIPLE_TABLES */
201 /* Exported by fib_frontend.c */
202 extern void ip_fib_init(void);
203 extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
204 extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
205 extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
206 extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
207 extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif,
208 struct net_device *dev, u32 *spec_dst, u32 *itag);
209 extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
211 /* Exported by fib_semantics.c */
212 extern int ip_fib_check_default(u32 gw, struct net_device *dev);
213 extern int fib_sync_down(u32 local, struct net_device *dev, int force);
214 extern int fib_sync_up(struct net_device *dev);
215 extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
216 struct kern_rta *rta, struct rtentry *r);
217 extern u32 __fib_res_prefsrc(struct fib_result *res);
219 /* Exported by fib_hash.c */
220 extern struct fib_table *fib_hash_init(int id);
222 #ifdef CONFIG_IP_MULTIPLE_TABLES
223 /* Exported by fib_rules.c */
225 extern int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
226 extern int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
227 extern int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
228 #ifdef CONFIG_NET_CLS_ROUTE
229 extern u32 fib_rules_tclass(struct fib_result *res);
231 extern void fib_rules_init(void);
234 static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
236 #ifdef CONFIG_NET_CLS_ROUTE
237 #ifdef CONFIG_IP_MULTIPLE_TABLES
240 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
241 #ifdef CONFIG_IP_MULTIPLE_TABLES
242 rtag = fib_rules_tclass(res);
250 extern void free_fib_info(struct fib_info *fi);
252 static inline void fib_info_put(struct fib_info *fi)
254 if (atomic_dec_and_test(&fi->fib_clntref))
258 static inline void fib_res_put(struct fib_result *res)
261 fib_info_put(res->fi);
262 #ifdef CONFIG_IP_MULTIPLE_TABLES
264 fib_rule_put(res->r);
268 #endif /* _NET_FIB_H */