initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / net / ip_fib.h
blob48a6ea4c2565391417e6ff8a5f60d712e671f820
1 /*
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.
16 #ifndef _NET_IP_FIB_H
17 #define _NET_IP_FIB_H
19 #include <linux/config.h>
20 #include <net/flow.h>
21 #include <linux/seq_file.h>
23 /* WARNING: The ordering of these elements must match ordering
24 * of RTA_* rtnetlink attribute numbers.
26 struct kern_rta {
27 void *rta_dst;
28 void *rta_src;
29 int *rta_iif;
30 int *rta_oif;
31 void *rta_gw;
32 u32 *rta_priority;
33 void *rta_prefsrc;
34 struct rtattr *rta_mx;
35 struct rtattr *rta_mp;
36 unsigned char *rta_protoinfo;
37 u32 *rta_flow;
38 struct rta_cacheinfo *rta_ci;
39 struct rta_session *rta_sess;
42 struct fib_info;
44 struct fib_nh {
45 struct net_device *nh_dev;
46 struct hlist_node nh_hash;
47 struct fib_info *nh_parent;
48 unsigned nh_flags;
49 unsigned char nh_scope;
50 #ifdef CONFIG_IP_ROUTE_MULTIPATH
51 int nh_weight;
52 int nh_power;
53 #endif
54 #ifdef CONFIG_NET_CLS_ROUTE
55 __u32 nh_tclassid;
56 #endif
57 int nh_oif;
58 u32 nh_gw;
62 * This structure contains data shared by many of routes.
65 struct fib_info {
66 struct hlist_node fib_hash;
67 struct hlist_node fib_lhash;
68 int fib_treeref;
69 atomic_t fib_clntref;
70 int fib_dead;
71 unsigned fib_flags;
72 int fib_protocol;
73 u32 fib_prefsrc;
74 u32 fib_priority;
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]
80 int fib_nhs;
81 #ifdef CONFIG_IP_ROUTE_MULTIPATH
82 int fib_power;
83 #endif
84 struct fib_nh fib_nh[0];
85 #define fib_dev fib_nh[0].nh_dev
89 #ifdef CONFIG_IP_MULTIPLE_TABLES
90 struct fib_rule;
91 #endif
93 struct fib_result {
94 unsigned char prefixlen;
95 unsigned char nh_sel;
96 unsigned char type;
97 unsigned char scope;
98 struct fib_info *fi;
99 #ifdef CONFIG_IP_MULTIPLE_TABLES
100 struct fib_rule *r;
101 #endif
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)
122 struct fib_table {
123 unsigned char tb_id;
124 unsigned tb_stamp;
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))
162 return -ENETUNREACH;
163 return 0;
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)
183 if (id == 0)
184 id = RT_TABLE_MAIN;
186 return fib_tables[id];
189 static inline struct fib_table *fib_new_table(int id)
191 if (id == 0)
192 id = RT_TABLE_MAIN;
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 void fib_flush(void);
204 extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
205 extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
206 extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
207 extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
208 extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif,
209 struct net_device *dev, u32 *spec_dst, u32 *itag);
210 extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
212 /* Exported by fib_semantics.c */
213 extern int ip_fib_check_default(u32 gw, struct net_device *dev);
214 extern int fib_sync_down(u32 local, struct net_device *dev, int force);
215 extern int fib_sync_up(struct net_device *dev);
216 extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
217 struct kern_rta *rta, struct rtentry *r);
218 extern u32 __fib_res_prefsrc(struct fib_result *res);
220 /* Exported by fib_hash.c */
221 extern struct fib_table *fib_hash_init(int id);
223 #ifdef CONFIG_IP_MULTIPLE_TABLES
224 /* Exported by fib_rules.c */
226 extern int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
227 extern int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
228 extern int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
229 extern u32 fib_rules_map_destination(u32 daddr, struct fib_result *res);
230 #ifdef CONFIG_NET_CLS_ROUTE
231 extern u32 fib_rules_tclass(struct fib_result *res);
232 #endif
233 extern void fib_rules_init(void);
234 #endif
236 static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
238 #ifdef CONFIG_NET_CLS_ROUTE
239 #ifdef CONFIG_IP_MULTIPLE_TABLES
240 u32 rtag;
241 #endif
242 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
243 #ifdef CONFIG_IP_MULTIPLE_TABLES
244 rtag = fib_rules_tclass(res);
245 if (*itag == 0)
246 *itag = (rtag<<16);
247 *itag |= (rtag>>16);
248 #endif
249 #endif
252 extern void free_fib_info(struct fib_info *fi);
254 static inline void fib_info_put(struct fib_info *fi)
256 if (atomic_dec_and_test(&fi->fib_clntref))
257 free_fib_info(fi);
260 static inline void fib_res_put(struct fib_result *res)
262 if (res->fi)
263 fib_info_put(res->fi);
264 #ifdef CONFIG_IP_MULTIPLE_TABLES
265 if (res->r)
266 fib_rule_put(res->r);
267 #endif
270 #endif /* _NET_FIB_H */