Main Page | Class List | File List | Class Members | File Members

ip_fib.h

Go to the documentation of this file.
00001 /* 00002 * INET An implementation of the TCP/IP protocol suite for the LINUX 00003 * operating system. INET is implemented using the BSD Socket 00004 * interface as the means of communication with the user level. 00005 * 00006 * Definitions for the Forwarding Information Base. 00007 * 00008 * Authors: A.N.Kuznetsov, <kuznet@ms2.inr.ac.ru> 00009 * 00010 * This program is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU General Public License 00012 * as published by the Free Software Foundation; either version 00013 * 2 of the License, or (at your option) any later version. 00014 */ 00015 00016 #ifndef _NET_IP_FIB_H 00017 #define _NET_IP_FIB_H 00018 00019 #include <linux/config.h> 00020 00021 struct kern_rta 00022 { 00023 void *rta_dst; 00024 void *rta_src; 00025 int *rta_iif; 00026 int *rta_oif; 00027 void *rta_gw; 00028 u32 *rta_priority; 00029 void *rta_prefsrc; 00030 struct rtattr *rta_mx; 00031 struct rtattr *rta_mp; 00032 unsigned char *rta_protoinfo; 00033 unsigned char *rta_flow; 00034 struct rta_cacheinfo *rta_ci; 00035 }; 00036 00037 struct fib_nh 00038 { 00039 struct net_device *nh_dev; 00040 unsigned nh_flags; 00041 unsigned char nh_scope; 00042 #ifdef CONFIG_IP_ROUTE_MULTIPATH 00043 int nh_weight; 00044 int nh_power; 00045 #endif 00046 #ifdef CONFIG_NET_CLS_ROUTE 00047 __u32 nh_tclassid; 00048 #endif 00049 int nh_oif; 00050 u32 nh_gw; 00051 }; 00052 00053 /* 00054 * This structure contains data shared by many of routes. 00055 */ 00056 00057 struct fib_info 00058 { 00059 struct fib_info *fib_next; 00060 struct fib_info *fib_prev; 00061 int fib_treeref; 00062 atomic_t fib_clntref; 00063 int fib_dead; 00064 unsigned fib_flags; 00065 int fib_protocol; 00066 u32 fib_prefsrc; 00067 u32 fib_priority; 00068 unsigned fib_metrics[RTAX_MAX]; 00069 #define fib_mtu fib_metrics[RTAX_MTU-1] 00070 #define fib_window fib_metrics[RTAX_WINDOW-1] 00071 #define fib_rtt fib_metrics[RTAX_RTT-1] 00072 #define fib_advmss fib_metrics[RTAX_ADVMSS-1] 00073 int fib_nhs; 00074 #ifdef CONFIG_IP_ROUTE_MULTIPATH 00075 int fib_power; 00076 #endif 00077 struct fib_nh fib_nh[0]; 00078 #define fib_dev fib_nh[0].nh_dev 00079 }; 00080 00081 00082 #ifdef CONFIG_IP_MULTIPLE_TABLES 00083 struct fib_rule; 00084 #endif 00085 00086 struct fib_result 00087 { 00088 unsigned char prefixlen; 00089 unsigned char nh_sel; 00090 unsigned char type; 00091 unsigned char scope; 00092 struct fib_info *fi; 00093 #ifdef CONFIG_IP_MULTIPLE_TABLES 00094 struct fib_rule *r; 00095 #endif 00096 }; 00097 00098 00099 #ifdef CONFIG_IP_ROUTE_MULTIPATH 00100 00101 #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) 00102 #define FIB_RES_RESET(res) ((res).nh_sel = 0) 00103 00104 #else /* CONFIG_IP_ROUTE_MULTIPATH */ 00105 00106 #define FIB_RES_NH(res) ((res).fi->fib_nh[0]) 00107 #define FIB_RES_RESET(res) 00108 00109 #endif /* CONFIG_IP_ROUTE_MULTIPATH */ 00110 00111 #define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res)) 00112 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw) 00113 #define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev) 00114 #define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif) 00115 00120 struct fib_table 00121 { 00122 unsigned char tb_id; 00123 unsigned tb_stamp; 00124 int (*tb_lookup)(struct fib_table *tb, const struct rt_key *key, struct fib_result *res); 00125 int (*tb_insert)(struct fib_table *table, struct rtmsg *r, 00126 struct kern_rta *rta, struct nlmsghdr *n, 00127 struct netlink_skb_parms *req); 00128 int (*tb_delete)(struct fib_table *table, struct rtmsg *r, 00129 struct kern_rta *rta, struct nlmsghdr *n, 00130 struct netlink_skb_parms *req); 00131 int (*tb_dump)(struct fib_table *table, struct sk_buff *skb, 00132 struct netlink_callback *cb); 00133 int (*tb_flush)(struct fib_table *table); 00134 int (*tb_get_info)(struct fib_table *table, char *buf, 00135 int first, int count); 00136 void (*tb_select_default)(struct fib_table *table, 00137 const struct rt_key *key, struct fib_result *res); 00138 00139 unsigned char tb_data[0]; 00140 }; 00141 00142 #ifndef CONFIG_IP_MULTIPLE_TABLES 00143 00144 extern struct fib_table *local_table; 00145 extern struct fib_table *main_table; 00146 00147 static inline struct fib_table *fib_get_table(int id) 00148 { 00149 if (id != RT_TABLE_LOCAL) 00150 return main_table; 00151 return local_table; 00152 } 00153 00154 static inline struct fib_table *fib_new_table(int id) 00155 { 00156 return fib_get_table(id); 00157 } 00158 00159 static inline int fib_lookup(const struct rt_key *key, struct fib_result *res) 00160 { 00161 if (local_table->tb_lookup(local_table, key, res) && 00162 main_table->tb_lookup(main_table, key, res)) 00163 return -ENETUNREACH; 00164 return 0; 00165 } 00166 00167 static inline void fib_select_default(const struct rt_key *key, struct fib_result *res) 00168 { 00169 if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) 00170 main_table->tb_select_default(main_table, key, res); 00171 } 00172 00173 #else /* CONFIG_IP_MULTIPLE_TABLES */ 00174 #define local_table (fib_tables[RT_TABLE_LOCAL]) 00175 #define main_table (fib_tables[RT_TABLE_MAIN]) 00176 00177 extern struct fib_table * fib_tables[RT_TABLE_MAX+1]; 00178 extern int fib_lookup(const struct rt_key *key, struct fib_result *res); 00179 extern struct fib_table *__fib_new_table(int id); 00180 extern void fib_rule_put(struct fib_rule *r); 00181 00182 static inline struct fib_table *fib_get_table(int id) 00183 { 00184 if (id == 0) 00185 id = RT_TABLE_MAIN; 00186 00187 return fib_tables[id]; 00188 } 00189 00190 static inline struct fib_table *fib_new_table(int id) 00191 { 00192 if (id == 0) 00193 id = RT_TABLE_MAIN; 00194 00195 return fib_tables[id] ? : __fib_new_table(id); 00196 } 00197 00198 extern void fib_select_default(const struct rt_key *key, struct fib_result *res); 00199 00200 #endif /* CONFIG_IP_MULTIPLE_TABLES */ 00201 00202 /* Exported by fib_frontend.c */ 00203 extern void ip_fib_init(void); 00204 extern void fib_flush(void); 00205 extern int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg); 00206 extern int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg); 00207 extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg); 00208 extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb); 00209 extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif, 00210 struct net_device *dev, u32 *spec_dst, u32 *itag); 00211 extern void fib_select_multipath(const struct rt_key *key, struct fib_result *res); 00212 00213 /* Exported by fib_semantics.c */ 00214 extern int ip_fib_check_default(u32 gw, struct net_device *dev); 00215 extern void fib_release_info(struct fib_info *); 00216 extern int fib_semantic_match(int type, struct fib_info *, 00217 const struct rt_key *, struct fib_result*); 00218 extern struct fib_info *fib_create_info(const struct rtmsg *r, struct kern_rta *rta, 00219 const struct nlmsghdr *, int *err); 00220 extern int fib_nh_match(struct rtmsg *r, struct nlmsghdr *, struct kern_rta *rta, struct fib_info *fi); 00221 extern int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event, 00222 u8 tb_id, u8 type, u8 scope, void *dst, int dst_len, u8 tos, 00223 struct fib_info *fi); 00224 extern int fib_sync_down(u32 local, struct net_device *dev, int force); 00225 extern int fib_sync_up(struct net_device *dev); 00226 extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm, 00227 struct kern_rta *rta, struct rtentry *r); 00228 extern void fib_node_get_info(int type, int dead, struct fib_info *fi, u32 prefix, u32 mask, char *buffer); 00229 extern u32 __fib_res_prefsrc(struct fib_result *res); 00230 00231 /* Exported by fib_hash.c */ 00232 extern struct fib_table *fib_hash_init(int id); 00233 00234 #ifdef CONFIG_IP_MULTIPLE_TABLES 00235 /* Exported by fib_rules.c */ 00236 00237 extern int inet_rtm_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg); 00238 extern int inet_rtm_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg); 00239 extern int inet_dump_rules(struct sk_buff *skb, struct netlink_callback *cb); 00240 extern u32 fib_rules_map_destination(u32 daddr, struct fib_result *res); 00241 #ifdef CONFIG_NET_CLS_ROUTE 00242 extern u32 fib_rules_tclass(struct fib_result *res); 00243 #endif 00244 extern u32 fib_rules_policy(u32 saddr, struct fib_result *res, unsigned *flags); 00245 extern void fib_rules_init(void); 00246 #endif 00247 00248 static inline void fib_combine_itag(u32 *itag, struct fib_result *res) 00249 { 00250 #ifdef CONFIG_NET_CLS_ROUTE 00251 #ifdef CONFIG_IP_MULTIPLE_TABLES 00252 u32 rtag; 00253 #endif 00254 *itag = FIB_RES_NH(*res).nh_tclassid<<16; 00255 #ifdef CONFIG_IP_MULTIPLE_TABLES 00256 rtag = fib_rules_tclass(res); 00257 if (*itag == 0) 00258 *itag = (rtag<<16); 00259 *itag |= (rtag>>16); 00260 #endif 00261 #endif 00262 } 00263 00264 extern void free_fib_info(struct fib_info *fi); 00265 00266 static inline void fib_info_put(struct fib_info *fi) 00267 { 00268 if (atomic_dec_and_test(&fi->fib_clntref)) 00269 free_fib_info(fi); 00270 } 00271 00272 static inline void fib_res_put(struct fib_result *res) 00273 { 00274 if (res->fi) 00275 fib_info_put(res->fi); 00276 #ifdef CONFIG_IP_MULTIPLE_TABLES 00277 if (res->r) 00278 fib_rule_put(res->r); 00279 #endif 00280 } 00281 00282 00283 #endif /* _NET_FIB_H */

Generated on Wed Dec 1 21:25:30 2004 for Linux 2.4.23 Networking by doxygen 1.3.8