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.
6 * Definitions for the Forwarding Information Base.
8 * Authors: A.N.Kuznetsov, <kuznet@ms2.inr.ac.ru>
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.
20 #include <linux/seq_file.h>
21 #include <net/fib_rules.h>
41 struct rtnexthop
*fc_mp
;
47 struct nl_info fc_nlinfo
;
53 struct net_device
*nh_dev
;
54 struct hlist_node nh_hash
;
55 struct fib_info
*nh_parent
;
57 unsigned char nh_scope
;
58 #ifdef CONFIG_IP_ROUTE_MULTIPATH
62 #ifdef CONFIG_NET_CLS_ROUTE
70 * This structure contains data shared by many of routes.
74 struct hlist_node fib_hash
;
75 struct hlist_node fib_lhash
;
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]
89 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
95 struct fib_nh fib_nh
[0];
96 #define fib_dev fib_nh[0].nh_dev
100 #ifdef CONFIG_IP_MULTIPLE_TABLES
105 unsigned char prefixlen
;
106 unsigned char nh_sel
;
109 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
114 #ifdef CONFIG_IP_MULTIPLE_TABLES
119 struct fib_result_nl
{
120 __be32 fl_addr
; /* To be looked up*/
122 unsigned char fl_tos
;
123 unsigned char fl_scope
;
124 unsigned char tb_id_in
;
126 unsigned char tb_id
; /* Results */
127 unsigned char prefixlen
;
128 unsigned char nh_sel
;
134 #ifdef CONFIG_IP_ROUTE_MULTIPATH
136 #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel])
137 #define FIB_RES_RESET(res) ((res).nh_sel = 0)
139 #else /* CONFIG_IP_ROUTE_MULTIPATH */
141 #define FIB_RES_NH(res) ((res).fi->fib_nh[0])
142 #define FIB_RES_RESET(res)
144 #endif /* CONFIG_IP_ROUTE_MULTIPATH */
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)
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 */
160 struct hlist_node tb_hlist
;
163 int (*tb_lookup
)(struct fib_table
*tb
, const struct flowi
*flp
, struct fib_result
*res
);
164 int (*tb_insert
)(struct fib_table
*, struct fib_config
*);
165 int (*tb_delete
)(struct fib_table
*, struct fib_config
*);
166 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
);
172 unsigned char tb_data
[0];
175 #ifndef CONFIG_IP_MULTIPLE_TABLES
177 extern struct fib_table
*ip_fib_local_table
;
178 extern struct fib_table
*ip_fib_main_table
;
180 static inline struct fib_table
*fib_get_table(u32 id
)
182 if (id
!= RT_TABLE_LOCAL
)
183 return ip_fib_main_table
;
184 return ip_fib_local_table
;
187 static inline struct fib_table
*fib_new_table(u32 id
)
189 return fib_get_table(id
);
192 static inline int fib_lookup(const struct flowi
*flp
, struct fib_result
*res
)
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
))
200 static inline void fib_select_default(const struct flowi
*flp
, struct fib_result
*res
)
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
);
206 #else /* CONFIG_IP_MULTIPLE_TABLES */
207 #define ip_fib_local_table fib_get_table(RT_TABLE_LOCAL)
208 #define ip_fib_main_table fib_get_table(RT_TABLE_MAIN)
210 extern int fib_lookup(struct flowi
*flp
, struct fib_result
*res
);
212 extern struct fib_table
*fib_new_table(u32 id
);
213 extern struct fib_table
*fib_get_table(u32 id
);
214 extern void fib_select_default(const struct flowi
*flp
, struct fib_result
*res
);
216 #endif /* CONFIG_IP_MULTIPLE_TABLES */
218 /* Exported by fib_frontend.c */
219 extern struct nla_policy rtm_ipv4_policy
[];
220 extern void ip_fib_init(void);
221 extern int inet_rtm_delroute(struct sk_buff
*skb
, struct nlmsghdr
* nlh
, void *arg
);
222 extern int inet_rtm_newroute(struct sk_buff
*skb
, struct nlmsghdr
* nlh
, void *arg
);
223 extern int inet_rtm_getroute(struct sk_buff
*skb
, struct nlmsghdr
* nlh
, void *arg
);
224 extern int inet_dump_fib(struct sk_buff
*skb
, struct netlink_callback
*cb
);
225 extern int fib_validate_source(__be32 src
, __be32 dst
, u8 tos
, int oif
,
226 struct net_device
*dev
, __be32
*spec_dst
, u32
*itag
);
227 extern void fib_select_multipath(const struct flowi
*flp
, struct fib_result
*res
);
231 /* Exported by fib_semantics.c */
232 extern int ip_fib_check_default(__be32 gw
, struct net_device
*dev
);
233 extern int fib_sync_down(__be32 local
, struct net_device
*dev
, int force
);
234 extern int fib_sync_up(struct net_device
*dev
);
235 extern __be32
__fib_res_prefsrc(struct fib_result
*res
);
237 /* Exported by fib_hash.c */
238 extern struct fib_table
*fib_hash_init(u32 id
);
240 #ifdef CONFIG_IP_MULTIPLE_TABLES
241 extern int fib4_rules_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
);
243 extern void __init
fib4_rules_init(void);
245 #ifdef CONFIG_NET_CLS_ROUTE
246 extern u32
fib_rules_tclass(struct fib_result
*res
);
251 static inline void fib_combine_itag(u32
*itag
, struct fib_result
*res
)
253 #ifdef CONFIG_NET_CLS_ROUTE
254 #ifdef CONFIG_IP_MULTIPLE_TABLES
257 *itag
= FIB_RES_NH(*res
).nh_tclassid
<<16;
258 #ifdef CONFIG_IP_MULTIPLE_TABLES
259 rtag
= fib_rules_tclass(res
);
267 extern void free_fib_info(struct fib_info
*fi
);
269 static inline void fib_info_put(struct fib_info
*fi
)
271 if (atomic_dec_and_test(&fi
->fib_clntref
))
275 static inline void fib_res_put(struct fib_result
*res
)
278 fib_info_put(res
->fi
);
279 #ifdef CONFIG_IP_MULTIPLE_TABLES
281 fib_rule_put(res
->r
);
285 #ifdef CONFIG_PROC_FS
286 extern int fib_proc_init(void);
287 extern void fib_proc_exit(void);
290 #endif /* _NET_FIB_H */