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