blob: c4eca2575b84a4b7094bc9d4ce48cbae86378292 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <net/flow.h>
20#include <linux/seq_file.h>
Thomas Grafe1ef4bf2006-08-04 03:39:22 -070021#include <net/fib_rules.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Thomas Graf4e902c52006-08-17 18:14:52 -070023struct fib_config {
24 u8 fc_family;
25 u8 fc_dst_len;
26 u8 fc_src_len;
27 u8 fc_tos;
28 u8 fc_protocol;
29 u8 fc_scope;
30 u8 fc_type;
31 /* 1 byte unused */
32 u32 fc_table;
33 u32 fc_dst;
34 u32 fc_src;
35 u32 fc_gw;
36 int fc_oif;
37 u32 fc_flags;
38 u32 fc_priority;
39 u32 fc_prefsrc;
40 struct nlattr *fc_mx;
41 struct rtnexthop *fc_mp;
42 int fc_mx_len;
43 int fc_mp_len;
44 u32 fc_flow;
45 u32 fc_mp_alg;
46 u32 fc_nlflags;
47 struct nl_info fc_nlinfo;
48 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50struct fib_info;
51
52struct fib_nh {
53 struct net_device *nh_dev;
54 struct hlist_node nh_hash;
55 struct fib_info *nh_parent;
56 unsigned nh_flags;
57 unsigned char nh_scope;
58#ifdef CONFIG_IP_ROUTE_MULTIPATH
59 int nh_weight;
60 int nh_power;
61#endif
62#ifdef CONFIG_NET_CLS_ROUTE
63 __u32 nh_tclassid;
64#endif
65 int nh_oif;
66 u32 nh_gw;
67};
68
69/*
70 * This structure contains data shared by many of routes.
71 */
72
73struct fib_info {
74 struct hlist_node fib_hash;
75 struct hlist_node fib_lhash;
76 int fib_treeref;
77 atomic_t fib_clntref;
78 int fib_dead;
79 unsigned fib_flags;
80 int fib_protocol;
81 u32 fib_prefsrc;
82 u32 fib_priority;
83 u32 fib_metrics[RTAX_MAX];
84#define fib_mtu fib_metrics[RTAX_MTU-1]
85#define fib_window fib_metrics[RTAX_WINDOW-1]
86#define fib_rtt fib_metrics[RTAX_RTT-1]
87#define fib_advmss fib_metrics[RTAX_ADVMSS-1]
88 int fib_nhs;
89#ifdef CONFIG_IP_ROUTE_MULTIPATH
90 int fib_power;
91#endif
92#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
93 u32 fib_mp_alg;
94#endif
95 struct fib_nh fib_nh[0];
96#define fib_dev fib_nh[0].nh_dev
97};
98
99
100#ifdef CONFIG_IP_MULTIPLE_TABLES
101struct fib_rule;
102#endif
103
104struct fib_result {
105 unsigned char prefixlen;
106 unsigned char nh_sel;
107 unsigned char type;
108 unsigned char scope;
109#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
110 __u32 network;
111 __u32 netmask;
112#endif
113 struct fib_info *fi;
114#ifdef CONFIG_IP_MULTIPLE_TABLES
115 struct fib_rule *r;
116#endif
117};
118
Robert Olsson246955f2005-06-20 13:36:39 -0700119struct fib_result_nl {
120 u32 fl_addr; /* To be looked up*/
121 u32 fl_fwmark;
122 unsigned char fl_tos;
123 unsigned char fl_scope;
124 unsigned char tb_id_in;
125
126 unsigned char tb_id; /* Results */
127 unsigned char prefixlen;
128 unsigned char nh_sel;
129 unsigned char type;
130 unsigned char scope;
131 int err;
132};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134#ifdef CONFIG_IP_ROUTE_MULTIPATH
135
136#define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
137#define FIB_RES_RESET(res) ((res).nh_sel = 0)
138
139#else /* CONFIG_IP_ROUTE_MULTIPATH */
140
141#define FIB_RES_NH(res) ((res).fi->fib_nh[0])
142#define FIB_RES_RESET(res)
143
144#endif /* CONFIG_IP_ROUTE_MULTIPATH */
145
146#define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res))
147#define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
148#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
149#define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif)
150
151#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
152#define FIB_RES_NETWORK(res) ((res).network)
153#define FIB_RES_NETMASK(res) ((res).netmask)
154#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
155#define FIB_RES_NETWORK(res) (0)
156#define FIB_RES_NETMASK(res) (0)
157#endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */
158
159struct fib_table {
Patrick McHardy1af5a8c2006-08-10 23:10:46 -0700160 struct hlist_node tb_hlist;
Patrick McHardy2dfe55b2006-08-10 23:08:33 -0700161 u32 tb_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 unsigned tb_stamp;
163 int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
Thomas Graf4e902c52006-08-17 18:14:52 -0700164 int (*tb_insert)(struct fib_table *, struct fib_config *);
165 int (*tb_delete)(struct fib_table *, struct fib_config *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
167 struct netlink_callback *cb);
168 int (*tb_flush)(struct fib_table *table);
169 void (*tb_select_default)(struct fib_table *table,
170 const struct flowi *flp, struct fib_result *res);
171
172 unsigned char tb_data[0];
173};
174
175#ifndef CONFIG_IP_MULTIPLE_TABLES
176
177extern struct fib_table *ip_fib_local_table;
178extern struct fib_table *ip_fib_main_table;
179
Patrick McHardy2dfe55b2006-08-10 23:08:33 -0700180static inline struct fib_table *fib_get_table(u32 id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 if (id != RT_TABLE_LOCAL)
183 return ip_fib_main_table;
184 return ip_fib_local_table;
185}
186
Patrick McHardy2dfe55b2006-08-10 23:08:33 -0700187static inline struct fib_table *fib_new_table(u32 id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 return fib_get_table(id);
190}
191
192static inline int fib_lookup(const struct flowi *flp, struct fib_result *res)
193{
194 if (ip_fib_local_table->tb_lookup(ip_fib_local_table, flp, res) &&
195 ip_fib_main_table->tb_lookup(ip_fib_main_table, flp, res))
196 return -ENETUNREACH;
197 return 0;
198}
199
200static inline void fib_select_default(const struct flowi *flp, struct fib_result *res)
201{
202 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
203 ip_fib_main_table->tb_select_default(ip_fib_main_table, flp, res);
204}
205
206#else /* CONFIG_IP_MULTIPLE_TABLES */
Patrick McHardy1af5a8c2006-08-10 23:10:46 -0700207#define ip_fib_local_table fib_get_table(RT_TABLE_LOCAL)
208#define ip_fib_main_table fib_get_table(RT_TABLE_MAIN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Thomas Grafe1ef4bf2006-08-04 03:39:22 -0700210extern int fib_lookup(struct flowi *flp, struct fib_result *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Patrick McHardy1af5a8c2006-08-10 23:10:46 -0700212extern struct fib_table *fib_new_table(u32 id);
213extern struct fib_table *fib_get_table(u32 id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214extern void fib_select_default(const struct flowi *flp, struct fib_result *res);
215
216#endif /* CONFIG_IP_MULTIPLE_TABLES */
217
218/* Exported by fib_frontend.c */
Thomas Grafd889ce32006-08-17 18:15:44 -0700219extern struct nla_policy rtm_ipv4_policy[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220extern void ip_fib_init(void);
221extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
222extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
223extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
224extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
Al Virod9c9df82006-09-26 21:28:14 -0700225extern int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
226 struct net_device *dev, __be32 *spec_dst, u32 *itag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res);
228
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -0200229struct rtentry;
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231/* Exported by fib_semantics.c */
232extern int ip_fib_check_default(u32 gw, struct net_device *dev);
233extern int fib_sync_down(u32 local, struct net_device *dev, int force);
234extern int fib_sync_up(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235extern u32 __fib_res_prefsrc(struct fib_result *res);
236
237/* Exported by fib_hash.c */
Patrick McHardy2dfe55b2006-08-10 23:08:33 -0700238extern struct fib_table *fib_hash_init(u32 id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240#ifdef CONFIG_IP_MULTIPLE_TABLES
Thomas Grafe1ef4bf2006-08-04 03:39:22 -0700241extern int fib4_rules_dump(struct sk_buff *skb, struct netlink_callback *cb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Thomas Grafe1ef4bf2006-08-04 03:39:22 -0700243extern void __init fib4_rules_init(void);
Thomas Grafe1ef4bf2006-08-04 03:39:22 -0700244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#ifdef CONFIG_NET_CLS_ROUTE
246extern u32 fib_rules_tclass(struct fib_result *res);
247#endif
Thomas Grafe1ef4bf2006-08-04 03:39:22 -0700248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249#endif
250
251static inline void fib_combine_itag(u32 *itag, struct fib_result *res)
252{
253#ifdef CONFIG_NET_CLS_ROUTE
254#ifdef CONFIG_IP_MULTIPLE_TABLES
255 u32 rtag;
256#endif
257 *itag = FIB_RES_NH(*res).nh_tclassid<<16;
258#ifdef CONFIG_IP_MULTIPLE_TABLES
259 rtag = fib_rules_tclass(res);
260 if (*itag == 0)
261 *itag = (rtag<<16);
262 *itag |= (rtag>>16);
263#endif
264#endif
265}
266
267extern void free_fib_info(struct fib_info *fi);
268
269static inline void fib_info_put(struct fib_info *fi)
270{
271 if (atomic_dec_and_test(&fi->fib_clntref))
272 free_fib_info(fi);
273}
274
275static inline void fib_res_put(struct fib_result *res)
276{
277 if (res->fi)
278 fib_info_put(res->fi);
279#ifdef CONFIG_IP_MULTIPLE_TABLES
280 if (res->r)
281 fib_rule_put(res->r);
282#endif
283}
284
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -0300285#ifdef CONFIG_PROC_FS
286extern int fib_proc_init(void);
287extern void fib_proc_exit(void);
288#endif
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290#endif /* _NET_FIB_H */