diff options
Diffstat (limited to 'include/net/ip_fib.h')
-rw-r--r-- | include/net/ip_fib.h | 73 |
1 files changed, 40 insertions, 33 deletions
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index ed514bfb61ba..9daa60b544ba 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h | |||
@@ -125,11 +125,15 @@ struct fib_result_nl { | |||
125 | #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) | 125 | #define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) |
126 | #define FIB_RES_RESET(res) ((res).nh_sel = 0) | 126 | #define FIB_RES_RESET(res) ((res).nh_sel = 0) |
127 | 127 | ||
128 | #define FIB_TABLE_HASHSZ 2 | ||
129 | |||
128 | #else /* CONFIG_IP_ROUTE_MULTIPATH */ | 130 | #else /* CONFIG_IP_ROUTE_MULTIPATH */ |
129 | 131 | ||
130 | #define FIB_RES_NH(res) ((res).fi->fib_nh[0]) | 132 | #define FIB_RES_NH(res) ((res).fi->fib_nh[0]) |
131 | #define FIB_RES_RESET(res) | 133 | #define FIB_RES_RESET(res) |
132 | 134 | ||
135 | #define FIB_TABLE_HASHSZ 256 | ||
136 | |||
133 | #endif /* CONFIG_IP_ROUTE_MULTIPATH */ | 137 | #endif /* CONFIG_IP_ROUTE_MULTIPATH */ |
134 | 138 | ||
135 | #define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res)) | 139 | #define FIB_RES_PREFSRC(res) ((res).fi->fib_prefsrc ? : __fib_res_prefsrc(&res)) |
@@ -141,6 +145,7 @@ struct fib_table { | |||
141 | struct hlist_node tb_hlist; | 145 | struct hlist_node tb_hlist; |
142 | u32 tb_id; | 146 | u32 tb_id; |
143 | unsigned tb_stamp; | 147 | unsigned tb_stamp; |
148 | int tb_default; | ||
144 | int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res); | 149 | int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res); |
145 | int (*tb_insert)(struct fib_table *, struct fib_config *); | 150 | int (*tb_insert)(struct fib_table *, struct fib_config *); |
146 | int (*tb_delete)(struct fib_table *, struct fib_config *); | 151 | int (*tb_delete)(struct fib_table *, struct fib_config *); |
@@ -155,50 +160,51 @@ struct fib_table { | |||
155 | 160 | ||
156 | #ifndef CONFIG_IP_MULTIPLE_TABLES | 161 | #ifndef CONFIG_IP_MULTIPLE_TABLES |
157 | 162 | ||
158 | extern struct fib_table *ip_fib_local_table; | 163 | #define TABLE_LOCAL_INDEX 0 |
159 | extern struct fib_table *ip_fib_main_table; | 164 | #define TABLE_MAIN_INDEX 1 |
160 | 165 | ||
161 | static inline struct fib_table *fib_get_table(u32 id) | 166 | static inline struct fib_table *fib_get_table(struct net *net, u32 id) |
162 | { | 167 | { |
163 | if (id != RT_TABLE_LOCAL) | 168 | struct hlist_head *ptr; |
164 | return ip_fib_main_table; | ||
165 | return ip_fib_local_table; | ||
166 | } | ||
167 | 169 | ||
168 | static inline struct fib_table *fib_new_table(u32 id) | 170 | ptr = id == RT_TABLE_LOCAL ? |
169 | { | 171 | &net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX] : |
170 | return fib_get_table(id); | 172 | &net->ipv4.fib_table_hash[TABLE_MAIN_INDEX]; |
173 | return hlist_entry(ptr->first, struct fib_table, tb_hlist); | ||
171 | } | 174 | } |
172 | 175 | ||
173 | static inline int fib_lookup(const struct flowi *flp, struct fib_result *res) | 176 | static inline struct fib_table *fib_new_table(struct net *net, u32 id) |
174 | { | 177 | { |
175 | if (ip_fib_local_table->tb_lookup(ip_fib_local_table, flp, res) && | 178 | return fib_get_table(net, id); |
176 | ip_fib_main_table->tb_lookup(ip_fib_main_table, flp, res)) | ||
177 | return -ENETUNREACH; | ||
178 | return 0; | ||
179 | } | 179 | } |
180 | 180 | ||
181 | static inline void fib_select_default(const struct flowi *flp, struct fib_result *res) | 181 | static inline int fib_lookup(struct net *net, const struct flowi *flp, |
182 | struct fib_result *res) | ||
182 | { | 183 | { |
183 | if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) | 184 | struct fib_table *table; |
184 | ip_fib_main_table->tb_select_default(ip_fib_main_table, flp, res); | 185 | |
186 | table = fib_get_table(net, RT_TABLE_LOCAL); | ||
187 | if (!table->tb_lookup(table, flp, res)) | ||
188 | return 0; | ||
189 | |||
190 | table = fib_get_table(net, RT_TABLE_MAIN); | ||
191 | if (!table->tb_lookup(table, flp, res)) | ||
192 | return 0; | ||
193 | return -ENETUNREACH; | ||
185 | } | 194 | } |
186 | 195 | ||
187 | #else /* CONFIG_IP_MULTIPLE_TABLES */ | 196 | #else /* CONFIG_IP_MULTIPLE_TABLES */ |
188 | extern void __init fib4_rules_init(void); | 197 | extern int __net_init fib4_rules_init(struct net *net); |
198 | extern void __net_exit fib4_rules_exit(struct net *net); | ||
189 | 199 | ||
190 | #ifdef CONFIG_NET_CLS_ROUTE | 200 | #ifdef CONFIG_NET_CLS_ROUTE |
191 | extern u32 fib_rules_tclass(struct fib_result *res); | 201 | extern u32 fib_rules_tclass(struct fib_result *res); |
192 | #endif | 202 | #endif |
193 | 203 | ||
194 | #define ip_fib_local_table fib_get_table(RT_TABLE_LOCAL) | 204 | extern int fib_lookup(struct net *n, struct flowi *flp, struct fib_result *res); |
195 | #define ip_fib_main_table fib_get_table(RT_TABLE_MAIN) | ||
196 | |||
197 | extern int fib_lookup(struct flowi *flp, struct fib_result *res); | ||
198 | 205 | ||
199 | extern struct fib_table *fib_new_table(u32 id); | 206 | extern struct fib_table *fib_new_table(struct net *net, u32 id); |
200 | extern struct fib_table *fib_get_table(u32 id); | 207 | extern struct fib_table *fib_get_table(struct net *net, u32 id); |
201 | extern void fib_select_default(const struct flowi *flp, struct fib_result *res); | ||
202 | 208 | ||
203 | #endif /* CONFIG_IP_MULTIPLE_TABLES */ | 209 | #endif /* CONFIG_IP_MULTIPLE_TABLES */ |
204 | 210 | ||
@@ -207,18 +213,19 @@ extern const struct nla_policy rtm_ipv4_policy[]; | |||
207 | extern void ip_fib_init(void); | 213 | extern void ip_fib_init(void); |
208 | extern int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif, | 214 | extern int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif, |
209 | struct net_device *dev, __be32 *spec_dst, u32 *itag); | 215 | struct net_device *dev, __be32 *spec_dst, u32 *itag); |
210 | extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res); | 216 | extern void fib_select_default(struct net *net, const struct flowi *flp, |
211 | 217 | struct fib_result *res); | |
212 | struct rtentry; | ||
213 | 218 | ||
214 | /* Exported by fib_semantics.c */ | 219 | /* Exported by fib_semantics.c */ |
215 | extern int ip_fib_check_default(__be32 gw, struct net_device *dev); | 220 | extern int ip_fib_check_default(__be32 gw, struct net_device *dev); |
216 | extern int fib_sync_down(__be32 local, struct net_device *dev, int force); | 221 | extern int fib_sync_down(__be32 local, struct net_device *dev, int force); |
217 | extern int fib_sync_up(struct net_device *dev); | 222 | extern int fib_sync_up(struct net_device *dev); |
218 | extern __be32 __fib_res_prefsrc(struct fib_result *res); | 223 | extern __be32 __fib_res_prefsrc(struct fib_result *res); |
224 | extern void fib_select_multipath(const struct flowi *flp, struct fib_result *res); | ||
219 | 225 | ||
220 | /* Exported by fib_hash.c */ | 226 | /* Exported by fib_{hash|trie}.c */ |
221 | extern struct fib_table *fib_hash_init(u32 id); | 227 | extern void fib_hash_init(void); |
228 | extern struct fib_table *fib_hash_table(u32 id); | ||
222 | 229 | ||
223 | static inline void fib_combine_itag(u32 *itag, struct fib_result *res) | 230 | static inline void fib_combine_itag(u32 *itag, struct fib_result *res) |
224 | { | 231 | { |
@@ -255,8 +262,8 @@ static inline void fib_res_put(struct fib_result *res) | |||
255 | } | 262 | } |
256 | 263 | ||
257 | #ifdef CONFIG_PROC_FS | 264 | #ifdef CONFIG_PROC_FS |
258 | extern int fib_proc_init(void); | 265 | extern int __net_init fib_proc_init(struct net *net); |
259 | extern void fib_proc_exit(void); | 266 | extern void __net_exit fib_proc_exit(struct net *net); |
260 | #endif | 267 | #endif |
261 | 268 | ||
262 | #endif /* _NET_FIB_H */ | 269 | #endif /* _NET_FIB_H */ |