[NET/IPV4/IPV6]: Change some sysctl variables to __read_mostly
[deliverable/linux.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
LT
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
246955fe
RO
112struct fib_result_nl {
113 u32 fl_addr; /* To be looked up*/
114 u32 fl_fwmark;
115 unsigned char fl_tos;
116 unsigned char fl_scope;
117 unsigned char tb_id_in;
118
119 unsigned char tb_id; /* Results */
120 unsigned char prefixlen;
121 unsigned char nh_sel;
122 unsigned char type;
123 unsigned char scope;
124 int err;
125};
1da177e4
LT
126
127#ifdef CONFIG_IP_ROUTE_MULTIPATH
128
129#define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
130#define FIB_RES_RESET(res) ((res).nh_sel = 0)
131
132#else /* CONFIG_IP_ROUTE_MULTIPATH */
133
134#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
135#define FIB_RES_RESET(res)
136
137#endif /* CONFIG_IP_ROUTE_MULTIPATH */
138
139#define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res))
140#define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
141#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
142#define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif)
143
144#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
145#define FIB_RES_NETWORK(res) ((res).network)
146#define FIB_RES_NETMASK(res) ((res).netmask)
147#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
148#define FIB_RES_NETWORK(res) (0)
149#define FIB_RES_NETMASK(res) (0)
150#endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */
151
152struct fib_table {
1af5a8c4 153 struct hlist_node tb_hlist;
2dfe55b4 154 u32 tb_id;
1da177e4
LT
155 unsigned tb_stamp;
156 int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
157 int (*tb_insert)(struct fib_table *table, struct rtmsg *r,
158 struct kern_rta *rta, struct nlmsghdr *n,
159 struct netlink_skb_parms *req);
160 int (*tb_delete)(struct fib_table *table, struct rtmsg *r,
161 struct kern_rta *rta, struct nlmsghdr *n,
162 struct netlink_skb_parms *req);
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 */
216extern void ip_fib_init(void);
217extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
218extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
219extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
220extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
221extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif,
222 struct net_device *dev, u32 *spec_dst, u32 *itag);
223extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
224
14c85021
ACM
225struct rtentry;
226
1da177e4
LT
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 */
2dfe55b4 236extern struct fib_table *fib_hash_init(u32 id);
1da177e4
LT
237
238#ifdef CONFIG_IP_MULTIPLE_TABLES
e1ef4bf2
TG
239extern int fib4_rules_dump(struct sk_buff *skb, struct netlink_callback *cb);
240
241extern void __init fib4_rules_init(void);
1da177e4 242
1da177e4
LT
243#ifdef CONFIG_NET_CLS_ROUTE
244extern u32 fib_rules_tclass(struct fib_result *res);
245#endif
e1ef4bf2 246
1da177e4
LT
247#endif
248
249static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
250{
251#ifdef CONFIG_NET_CLS_ROUTE
252#ifdef CONFIG_IP_MULTIPLE_TABLES
253 u32 rtag;
254#endif
255 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
256#ifdef CONFIG_IP_MULTIPLE_TABLES
257 rtag = fib_rules_tclass(res);
258 if (*itag == 0)
259 *itag = (rtag<<16);
260 *itag |= (rtag>>16);
261#endif
262#endif
263}
264
265extern void free_fib_info(struct fib_info *fi);
266
267static inline void fib_info_put(struct fib_info *fi)
268{
269 if (atomic_dec_and_test(&fi->fib_clntref))
270 free_fib_info(fi);
271}
272
273static inline void fib_res_put(struct fib_result *res)
274{
275 if (res->fi)
276 fib_info_put(res->fi);
277#ifdef CONFIG_IP_MULTIPLE_TABLES
278 if (res->r)
279 fib_rule_put(res->r);
280#endif
281}
282
20380731
ACM
283#ifdef CONFIG_PROC_FS
284extern int fib_proc_init(void);
285extern void fib_proc_exit(void);
286#endif
287
1da177e4 288#endif /* _NET_FIB_H */
This page took 0.194736 seconds and 5 git commands to generate.