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 */
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;
40 };
41
42 struct fib_info;
43
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;
59 };
60
61 /*
62 * This structure contains data shared by many of routes.
63 */
64
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
86 };
87
88
89 #ifdef CONFIG_IP_MULTIPLE_TABLES
90 struct fib_rule;
91 #endif
92
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
102 };
103
104
105 #ifdef CONFIG_IP_ROUTE_MULTIPATH
106
107 #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
108 #define FIB_RES_RESET(res) ((res).nh_sel = 0)
109
110 #else /* CONFIG_IP_ROUTE_MULTIPATH */
111
112 #define FIB_RES_NH(res) ((res).fi->fib_nh[0])
113 #define FIB_RES_RESET(res)
114
115 #endif /* CONFIG_IP_ROUTE_MULTIPATH */
116
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)
121
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);
137
138 unsigned char tb_data[0];
139 };
140
141 #ifndef CONFIG_IP_MULTIPLE_TABLES
142
143 extern struct fib_table *ip_fib_local_table;
144 extern struct fib_table *ip_fib_main_table;
145
146 static inline struct fib_table *fib_get_table(int id)
147 {
148 if (id != RT_TABLE_LOCAL)
149 return ip_fib_main_table;
150 return ip_fib_local_table;
151 }
152
153 static inline struct fib_table *fib_new_table(int id)
154 {
155 return fib_get_table(id);
156 }
157
158 static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
159 {
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;
164 }
165
166 static inline void fib_select_default(const struct flowi *flp, struct fib_result *res)
167 {
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);
170 }
171
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])
175
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);
180
181 static inline struct fib_table *fib_get_table(int id)
182 {
183 if (id == 0)
184 id = RT_TABLE_MAIN;
185
186 return fib_tables[id];
187 }
188
189 static inline struct fib_table *fib_new_table(int id)
190 {
191 if (id == 0)
192 id = RT_TABLE_MAIN;
193
194 return fib_tables[id] ? : __fib_new_table(id);
195 }
196
197 extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
198
199 #endif /* CONFIG_IP_MULTIPLE_TABLES */
200
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);
210
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);
218
219 /* Exported by fib_hash.c */
220 extern struct fib_table *fib_hash_init(int id);
221
222 #ifdef CONFIG_IP_MULTIPLE_TABLES
223 /* Exported by fib_rules.c */
224
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);
230 #endif
231 extern void fib_rules_init(void);
232 #endif
233
234 static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
235 {
236 #ifdef CONFIG_NET_CLS_ROUTE
237 #ifdef CONFIG_IP_MULTIPLE_TABLES
238 u32 rtag;
239 #endif
240 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
241 #ifdef CONFIG_IP_MULTIPLE_TABLES
242 rtag = fib_rules_tclass(res);
243 if (*itag == 0)
244 *itag = (rtag<<16);
245 *itag |= (rtag>>16);
246 #endif
247 #endif
248 }
249
250 extern void free_fib_info(struct fib_info *fi);
251
252 static inline void fib_info_put(struct fib_info *fi)
253 {
254 if (atomic_dec_and_test(&fi->fib_clntref))
255 free_fib_info(fi);
256 }
257
258 static inline void fib_res_put(struct fib_result *res)
259 {
260 if (res->fi)
261 fib_info_put(res->fi);
262 #ifdef CONFIG_IP_MULTIPLE_TABLES
263 if (res->r)
264 fib_rule_put(res->r);
265 #endif
266 }
267
268 #endif /* _NET_FIB_H */
269
|
This page was automatically generated by the
LXR engine.
|