]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/net/ip_fib.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[net-next-2.6.git] / include / net / ip_fib.h
CommitLineData
1da177e4
LT
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
1da177e4
LT
19#include <net/flow.h>
20#include <linux/seq_file.h>
e1ef4bf2 21#include <net/fib_rules.h>
1da177e4 22
4e902c57 23struct fib_config {
4e902c57 24 u8 fc_dst_len;
4e902c57
TG
25 u8 fc_tos;
26 u8 fc_protocol;
27 u8 fc_scope;
28 u8 fc_type;
b52f070c 29 /* 3 bytes unused */
4e902c57 30 u32 fc_table;
6d85c10a 31 __be32 fc_dst;
6d85c10a 32 __be32 fc_gw;
4e902c57
TG
33 int fc_oif;
34 u32 fc_flags;
35 u32 fc_priority;
6d85c10a 36 __be32 fc_prefsrc;
4e902c57
TG
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;
45 };
1da177e4
LT
46
47struct fib_info;
48
49struct 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;
ed49e3ca 63 __be32 nh_gw;
1da177e4
LT
64};
65
66/*
67 * This structure contains data shared by many of routes.
68 */
69
70struct 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;
b83738ae 78 __be32 fib_prefsrc;
1da177e4
LT
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
94};
95
96
97#ifdef CONFIG_IP_MULTIPLE_TABLES
98struct fib_rule;
99#endif
100
101struct 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
80e856e1
AV
107 __be32 network;
108 __be32 netmask;
1da177e4
LT
109#endif
110 struct fib_info *fi;
111#ifdef CONFIG_IP_MULTIPLE_TABLES
112 struct fib_rule *r;
113#endif
114};
115
246955fe 116struct fib_result_nl {
80e856e1 117 __be32 fl_addr; /* To be looked up*/
5f300893 118 u32 fl_mark;
246955fe
RO
119 unsigned char fl_tos;
120 unsigned char fl_scope;
121 unsigned char tb_id_in;
122
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;
129};
1da177e4
LT
130
131#ifdef CONFIG_IP_ROUTE_MULTIPATH
132
133#define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
134#define FIB_RES_RESET(res) ((res).nh_sel = 0)
135
136#else /* CONFIG_IP_ROUTE_MULTIPATH */
137
138#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
139#define FIB_RES_RESET(res)
140
141#endif /* CONFIG_IP_ROUTE_MULTIPATH */
142
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)
147
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 */
155
156struct fib_table {
1af5a8c4 157 struct hlist_node tb_hlist;
2dfe55b4 158 u32 tb_id;
1da177e4
LT
159 unsigned tb_stamp;
160 int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
4e902c57
TG
161 int (*tb_insert)(struct fib_table *, struct fib_config *);
162 int (*tb_delete)(struct fib_table *, struct fib_config *);
1da177e4
LT
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);
168
169 unsigned char tb_data[0];
170};
171
172#ifndef CONFIG_IP_MULTIPLE_TABLES
173
174extern struct fib_table *ip_fib_local_table;
175extern struct fib_table *ip_fib_main_table;
176
2dfe55b4 177static inline struct fib_table *fib_get_table(u32 id)
1da177e4
LT
178{
179 if (id != RT_TABLE_LOCAL)
180 return ip_fib_main_table;
181 return ip_fib_local_table;
182}
183
2dfe55b4 184static inline struct fib_table *fib_new_table(u32 id)
1da177e4
LT
185{
186 return fib_get_table(id);
187}
188
189static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
190{
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;
195}
196
197static inline void fib_select_default(const struct flowi *flp, struct fib_result *res)
198{
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);
201}
202
203#else /* CONFIG_IP_MULTIPLE_TABLES */
1af5a8c4
PM
204#define ip_fib_local_table fib_get_table(RT_TABLE_LOCAL)
205#define ip_fib_main_table fib_get_table(RT_TABLE_MAIN)
1da177e4 206
e1ef4bf2 207extern int fib_lookup(struct flowi *flp, struct fib_result *res);
1da177e4 208
1af5a8c4
PM
209extern struct fib_table *fib_new_table(u32 id);
210extern struct fib_table *fib_get_table(u32 id);
1da177e4
LT
211extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
212
213#endif /* CONFIG_IP_MULTIPLE_TABLES */
214
215/* Exported by fib_frontend.c */
d889ce3b 216extern struct nla_policy rtm_ipv4_policy[];
1da177e4
LT
217extern void ip_fib_init(void);
218extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
219extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
220extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
221extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
d9c9df8c
AV
222extern int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
223 struct net_device *dev, __be32 *spec_dst, u32 *itag);
1da177e4
LT
224extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
225
14c85021
ACM
226struct rtentry;
227
1da177e4 228/* Exported by fib_semantics.c */
d878e72e 229extern int ip_fib_check_default(__be32 gw, struct net_device *dev);
81f7bf6c 230extern int fib_sync_down(__be32 local, struct net_device *dev, int force);
1da177e4 231extern int fib_sync_up(struct net_device *dev);
b83738ae 232extern __be32 __fib_res_prefsrc(struct fib_result *res);
1da177e4
LT
233
234/* Exported by fib_hash.c */
2dfe55b4 235extern struct fib_table *fib_hash_init(u32 id);
1da177e4
LT
236
237#ifdef CONFIG_IP_MULTIPLE_TABLES
e1ef4bf2
TG
238extern int fib4_rules_dump(struct sk_buff *skb, struct netlink_callback *cb);
239
240extern void __init fib4_rules_init(void);
1da177e4 241
1da177e4
LT
242#ifdef CONFIG_NET_CLS_ROUTE
243extern u32 fib_rules_tclass(struct fib_result *res);
244#endif
e1ef4bf2 245
1da177e4
LT
246#endif
247
248static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
249{
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
262}
263
264extern void free_fib_info(struct fib_info *fi);
265
266static inline void fib_info_put(struct fib_info *fi)
267{
268 if (atomic_dec_and_test(&fi->fib_clntref))
269 free_fib_info(fi);
270}
271
272static inline void fib_res_put(struct fib_result *res)
273{
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
280}
281
20380731
ACM
282#ifdef CONFIG_PROC_FS
283extern int fib_proc_init(void);
284extern void fib_proc_exit(void);
285#endif
286
1da177e4 287#endif /* _NET_FIB_H */