aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/ip_fib.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/net/ip_fib.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/net/ip_fib.h')
-rw-r--r--include/net/ip_fib.h284
1 files changed, 284 insertions, 0 deletions
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
new file mode 100644
index 000000000000..e5a5f6b62f88
--- /dev/null
+++ b/include/net/ip_fib.h
@@ -0,0 +1,284 @@
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.
5 *
6 * Definitions for the Forwarding Information Base.
7 *
8 * Authors: A.N.Kuznetsov, <kuznet@ms2.inr.ac.ru>
9 *
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.
14 */
15
16#ifndef _NET_IP_FIB_H
17#define _NET_IP_FIB_H
18
19#include <linux/config.h>
20#include <net/flow.h>
21#include <linux/seq_file.h>
22
23/* WARNING: The ordering of these elements must match ordering
24 * of RTA_* rtnetlink attribute numbers.
25 */
26struct 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;
40 u32 *rta_mp_alg;
41};
42
43struct fib_info;
44
45struct fib_nh {
46 struct net_device *nh_dev;
47 struct hlist_node nh_hash;
48 struct fib_info *nh_parent;
49 unsigned nh_flags;
50 unsigned char nh_scope;
51#ifdef CONFIG_IP_ROUTE_MULTIPATH
52 int nh_weight;
53 int nh_power;
54#endif
55#ifdef CONFIG_NET_CLS_ROUTE
56 __u32 nh_tclassid;
57#endif
58 int nh_oif;
59 u32 nh_gw;
60};
61
62/*
63 * This structure contains data shared by many of routes.
64 */
65
66struct fib_info {
67 struct hlist_node fib_hash;
68 struct hlist_node fib_lhash;
69 int fib_treeref;
70 atomic_t fib_clntref;
71 int fib_dead;
72 unsigned fib_flags;
73 int fib_protocol;
74 u32 fib_prefsrc;
75 u32 fib_priority;
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]
81 int fib_nhs;
82#ifdef CONFIG_IP_ROUTE_MULTIPATH
83 int fib_power;
84#endif
85#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
86 u32 fib_mp_alg;
87#endif
88 struct fib_nh fib_nh[0];
89#define fib_dev fib_nh[0].nh_dev
90};
91
92
93#ifdef CONFIG_IP_MULTIPLE_TABLES
94struct fib_rule;
95#endif
96
97struct fib_result {
98 unsigned char prefixlen;
99 unsigned char nh_sel;
100 unsigned char type;
101 unsigned char scope;
102#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
103 __u32 network;
104 __u32 netmask;
105#endif
106 struct fib_info *fi;
107#ifdef CONFIG_IP_MULTIPLE_TABLES
108 struct fib_rule *r;
109#endif
110};
111
112
113#ifdef CONFIG_IP_ROUTE_MULTIPATH
114
115#define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
116#define FIB_RES_RESET(res) ((res).nh_sel = 0)
117
118#else /* CONFIG_IP_ROUTE_MULTIPATH */
119
120#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
121#define FIB_RES_RESET(res)
122
123#endif /* CONFIG_IP_ROUTE_MULTIPATH */
124
125#define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res))
126#define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
127#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
128#define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif)
129
130#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
131#define FIB_RES_NETWORK(res) ((res).network)
132#define FIB_RES_NETMASK(res) ((res).netmask)
133#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
134#define FIB_RES_NETWORK(res) (0)
135#define FIB_RES_NETMASK(res) (0)
136#endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */
137
138struct fib_table {
139 unsigned char tb_id;
140 unsigned tb_stamp;
141 int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
142 int (*tb_insert)(struct fib_table *table, struct rtmsg *r,
143 struct kern_rta *rta, struct nlmsghdr *n,
144 struct netlink_skb_parms *req);
145 int (*tb_delete)(struct fib_table *table, struct rtmsg *r,
146 struct kern_rta *rta, struct nlmsghdr *n,
147 struct netlink_skb_parms *req);
148 int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
149 struct netlink_callback *cb);
150 int (*tb_flush)(struct fib_table *table);
151 void (*tb_select_default)(struct fib_table *table,
152 const struct flowi *flp, struct fib_result *res);
153
154 unsigned char tb_data[0];
155};
156
157#ifndef CONFIG_IP_MULTIPLE_TABLES
158
159extern struct fib_table *ip_fib_local_table;
160extern struct fib_table *ip_fib_main_table;
161
162static inline struct fib_table *fib_get_table(int id)
163{
164 if (id != RT_TABLE_LOCAL)
165 return ip_fib_main_table;
166 return ip_fib_local_table;
167}
168
169static inline struct fib_table *fib_new_table(int id)
170{
171 return fib_get_table(id);
172}
173
174static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
175{
176 if (ip_fib_local_table->tb_lookup(ip_fib_local_table, flp, res) &&
177 ip_fib_main_table->tb_lookup(ip_fib_main_table, flp, res))
178 return -ENETUNREACH;
179 return 0;
180}
181
182static inline void fib_select_default(const struct flowi *flp, struct fib_result *res)
183{
184 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
185 ip_fib_main_table->tb_select_default(ip_fib_main_table, flp, res);
186}
187
188#else /* CONFIG_IP_MULTIPLE_TABLES */
189#define ip_fib_local_table (fib_tables[RT_TABLE_LOCAL])
190#define ip_fib_main_table (fib_tables[RT_TABLE_MAIN])
191
192extern struct fib_table * fib_tables[RT_TABLE_MAX+1];
193extern int fib_lookup(const struct flowi *flp, struct fib_result *res);
194extern struct fib_table *__fib_new_table(int id);
195extern void fib_rule_put(struct fib_rule *r);
196
197static inline struct fib_table *fib_get_table(int id)
198{
199 if (id == 0)
200 id = RT_TABLE_MAIN;
201
202 return fib_tables[id];
203}
204
205static inline struct fib_table *fib_new_table(int id)
206{
207 if (id == 0)
208 id = RT_TABLE_MAIN;
209
210 return fib_tables[id] ? : __fib_new_table(id);
211}
212
213extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
214
215#endif /* CONFIG_IP_MULTIPLE_TABLES */
216
217/* Exported by fib_frontend.c */
218extern void ip_fib_init(void);
219extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
220extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
221extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
222extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
223extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif,
224 struct net_device *dev, u32 *spec_dst, u32 *itag);
225extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
226
227/* Exported by fib_semantics.c */
228extern int ip_fib_check_default(u32 gw, struct net_device *dev);
229extern int fib_sync_down(u32 local, struct net_device *dev, int force);
230extern int fib_sync_up(struct net_device *dev);
231extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
232 struct kern_rta *rta, struct rtentry *r);
233extern u32 __fib_res_prefsrc(struct fib_result *res);
234
235/* Exported by fib_hash.c */
236extern struct fib_table *fib_hash_init(int id);
237
238#ifdef CONFIG_IP_MULTIPLE_TABLES
239/* Exported by fib_rules.c */
240
241extern int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
242extern int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
243extern int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb);
244#ifdef CONFIG_NET_CLS_ROUTE
245extern u32 fib_rules_tclass(struct fib_result *res);
246#endif
247extern void fib_rules_init(void);
248#endif
249
250static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
251{
252#ifdef CONFIG_NET_CLS_ROUTE
253#ifdef CONFIG_IP_MULTIPLE_TABLES
254 u32 rtag;
255#endif
256 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
257#ifdef CONFIG_IP_MULTIPLE_TABLES
258 rtag = fib_rules_tclass(res);
259 if (*itag == 0)
260 *itag = (rtag<<16);
261 *itag |= (rtag>>16);
262#endif
263#endif
264}
265
266extern void free_fib_info(struct fib_info *fi);
267
268static inline void fib_info_put(struct fib_info *fi)
269{
270 if (atomic_dec_and_test(&fi->fib_clntref))
271 free_fib_info(fi);
272}
273
274static inline void fib_res_put(struct fib_result *res)
275{
276 if (res->fi)
277 fib_info_put(res->fi);
278#ifdef CONFIG_IP_MULTIPLE_TABLES
279 if (res->r)
280 fib_rule_put(res->r);
281#endif
282}
283
284#endif /* _NET_FIB_H */