MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / include / net / ip_fib.h
blob949b932d2f08c8f72017f8d61ce1f773192f55e0
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 <net/flow.h>
20 #include <linux/seq_file.h>
21 #include <net/fib_rules.h>
23 struct fib_config {
24 u8 fc_dst_len;
25 u8 fc_tos;
26 u8 fc_protocol;
27 u8 fc_scope;
28 u8 fc_type;
29 /* 3 bytes unused */
30 u32 fc_table;
31 __be32 fc_dst;
32 __be32 fc_gw;
33 int fc_oif;
34 u32 fc_flags;
35 u32 fc_priority;
36 __be32 fc_prefsrc;
37 struct nlattr *fc_mx;
38 struct rtnexthop *fc_mp;
39 int fc_mx_len;
40 int fc_mp_len;
41 u32 fc_flow;
42 u32 fc_mp_alg;
43 u32 fc_nlflags;
44 struct nl_info fc_nlinfo;
47 struct fib_info;
49 struct fib_nh {
50 struct net_device *nh_dev;
51 struct hlist_node nh_hash;
52 struct fib_info *nh_parent;
53 unsigned nh_flags;
54 unsigned char nh_scope;
55 #ifdef CONFIG_IP_ROUTE_MULTIPATH
56 int nh_weight;
57 int nh_power;
58 #endif
59 #ifdef CONFIG_NET_CLS_ROUTE
60 __u32 nh_tclassid;
61 #endif
62 int nh_oif;
63 __be32 nh_gw;
67 * This structure contains data shared by many of routes.
70 struct fib_info {
71 struct hlist_node fib_hash;
72 struct hlist_node fib_lhash;
73 int fib_treeref;
74 atomic_t fib_clntref;
75 int fib_dead;
76 unsigned fib_flags;
77 int fib_protocol;
78 __be32 fib_prefsrc;
79 u32 fib_priority;
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]
85 int fib_nhs;
86 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87 int fib_power;
88 #endif
89 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
90 u32 fib_mp_alg;
91 #endif
92 struct fib_nh fib_nh[0];
93 #define fib_dev fib_nh[0].nh_dev
97 #ifdef CONFIG_IP_MULTIPLE_TABLES
98 struct fib_rule;
99 #endif
101 struct fib_result {
102 unsigned char prefixlen;
103 unsigned char nh_sel;
104 unsigned char type;
105 unsigned char scope;
106 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
107 __be32 network;
108 __be32 netmask;
109 #endif
110 struct fib_info *fi;
111 #ifdef CONFIG_IP_MULTIPLE_TABLES
112 struct fib_rule *r;
113 #endif
116 struct fib_result_nl {
117 __be32 fl_addr; /* To be looked up*/
118 u32 fl_fwmark;
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;
126 unsigned char type;
127 unsigned char scope;
128 int err;
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 */
156 struct fib_table {
157 struct hlist_node tb_hlist;
158 u32 tb_id;
159 unsigned tb_stamp;
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))
193 return -ENETUNREACH;
194 return 0;
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);
226 struct rtentry;
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);
244 #endif
246 #endif
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
252 u32 rtag;
253 #endif
254 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
255 #ifdef CONFIG_IP_MULTIPLE_TABLES
256 rtag = fib_rules_tclass(res);
257 if (*itag == 0)
258 *itag = (rtag<<16);
259 *itag |= (rtag>>16);
260 #endif
261 #endif
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))
269 free_fib_info(fi);
272 static inline void fib_res_put(struct fib_result *res)
274 if (res->fi)
275 fib_info_put(res->fi);
276 #ifdef CONFIG_IP_MULTIPLE_TABLES
277 if (res->r)
278 fib_rule_put(res->r);
279 #endif
282 #ifdef CONFIG_PROC_FS
283 extern int fib_proc_init(void);
284 extern void fib_proc_exit(void);
285 #endif
287 #endif /* _NET_FIB_H */