add missing dependency on linux-atm
[openwrt.git] / target / linux / generic-2.4 / patches / 700-multiple_default_gateways.patch
1 diff -ur v2.4.29/linux/include/linux/netfilter_ipv4/ip_nat.h linux/include/linux/netfilter_ipv4/ip_nat.h
2 --- v2.4.29/linux/include/linux/netfilter_ipv4/ip_nat.h 2005-01-20 09:25:34.000000000 +0200
3 +++ linux/include/linux/netfilter_ipv4/ip_nat.h 2005-01-20 09:55:46.998651976 +0200
4 @@ -121,5 +121,13 @@
5 extern u_int16_t ip_nat_cheat_check(u_int32_t oldvalinv,
6 u_int32_t newval,
7 u_int16_t oldcheck);
8 +
9 +/* Call input routing for SNAT-ed traffic */
10 +extern unsigned int ip_nat_route_input(unsigned int hooknum,
11 + struct sk_buff **pskb,
12 + const struct net_device *in,
13 + const struct net_device *out,
14 + int (*okfn)(struct sk_buff *));
15 +
16 #endif /*__KERNEL__*/
17 #endif
18 diff -ur v2.4.29/linux/include/linux/rtnetlink.h linux/include/linux/rtnetlink.h
19 --- v2.4.29/linux/include/linux/rtnetlink.h 2004-08-08 10:56:48.000000000 +0300
20 +++ linux/include/linux/rtnetlink.h 2005-01-20 09:55:33.431714464 +0200
21 @@ -234,6 +234,8 @@
22 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
23 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
24 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
25 +#define RTNH_F_SUSPECT 8 /* We don't know the real state */
26 +#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
27
28 /* Macros to handle hexthops */
29
30 diff -ur v2.4.29/linux/include/net/ip_fib.h linux/include/net/ip_fib.h
31 --- v2.4.29/linux/include/net/ip_fib.h 2001-11-13 03:24:05.000000000 +0200
32 +++ linux/include/net/ip_fib.h 2005-01-20 09:55:33.432714312 +0200
33 @@ -162,7 +162,8 @@
34
35 static inline void fib_select_default(const struct rt_key *key, struct fib_result *res)
36 {
37 - if (FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
38 + if ((FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) ||
39 + FIB_RES_NH(*res).nh_scope == RT_SCOPE_HOST)
40 main_table->tb_select_default(main_table, key, res);
41 }
42
43 @@ -174,6 +175,7 @@
44 extern int fib_lookup(const struct rt_key *key, struct fib_result *res);
45 extern struct fib_table *__fib_new_table(int id);
46 extern void fib_rule_put(struct fib_rule *r);
47 +extern int fib_result_table(struct fib_result *res);
48
49 static inline struct fib_table *fib_get_table(int id)
50 {
51 @@ -275,5 +277,6 @@
52 #endif
53 }
54
55 +extern rwlock_t fib_nhflags_lock;
56
57 #endif /* _NET_FIB_H */
58 diff -ur v2.4.29/linux/include/net/route.h linux/include/net/route.h
59 --- v2.4.29/linux/include/net/route.h 2003-08-25 22:06:13.000000000 +0300
60 +++ linux/include/net/route.h 2005-01-20 09:55:46.999651824 +0200
61 @@ -49,6 +49,8 @@
62 {
63 __u32 dst;
64 __u32 src;
65 + __u32 lsrc;
66 + __u32 gw;
67 int iif;
68 int oif;
69 #ifdef CONFIG_IP_ROUTE_FWMARK
70 @@ -128,6 +130,7 @@
71 extern void rt_cache_flush(int how);
72 extern int ip_route_output_key(struct rtable **, const struct rt_key *key);
73 extern int ip_route_input(struct sk_buff*, u32 dst, u32 src, u8 tos, struct net_device *devin);
74 +extern int ip_route_input_lookup(struct sk_buff*, u32 dst, u32 src, u8 tos, struct net_device *devin, u32 lsrc);
75 extern unsigned short ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mtu);
76 extern void ip_rt_update_pmtu(struct dst_entry *dst, unsigned mtu);
77 extern void ip_rt_send_redirect(struct sk_buff *skb);
78 @@ -148,6 +151,15 @@
79 }
80
81
82 +static inline int
83 +ip_route_output_lookup(struct rtable **rp,
84 + u32 daddr, u32 saddr, u32 tos, int oif, u32 gw)
85 +{
86 + struct rt_key key = { dst:daddr, src:saddr, gw:gw, oif:oif, tos:tos };
87 +
88 + return ip_route_output_key(rp, &key);
89 +}
90 +
91 static inline void ip_rt_put(struct rtable * rt)
92 {
93 if (rt)
94 diff -ur v2.4.29/linux/net/ipv4/fib_frontend.c linux/net/ipv4/fib_frontend.c
95 --- v2.4.29/linux/net/ipv4/fib_frontend.c 2003-08-25 22:06:13.000000000 +0300
96 +++ linux/net/ipv4/fib_frontend.c 2005-01-20 09:55:46.999651824 +0200
97 @@ -54,6 +54,8 @@
98 struct fib_table *local_table;
99 struct fib_table *main_table;
100
101 +#define FIB_RES_TABLE(r) (RT_TABLE_MAIN)
102 +
103 #else
104
105 #define RT_TABLE_MIN 1
106 @@ -71,6 +73,7 @@
107 return tb;
108 }
109
110 +#define FIB_RES_TABLE(r) (fib_result_table(r))
111
112 #endif /* CONFIG_IP_MULTIPLE_TABLES */
113
114 @@ -209,6 +212,9 @@
115 struct in_device *in_dev;
116 struct rt_key key;
117 struct fib_result res;
118 + int table;
119 + unsigned char prefixlen;
120 + unsigned char scope;
121 int no_addr, rpf;
122 int ret;
123
124 @@ -216,6 +222,7 @@
125 key.src = dst;
126 key.tos = tos;
127 key.oif = 0;
128 + key.gw = 0;
129 key.iif = oif;
130 key.scope = RT_SCOPE_UNIVERSE;
131
132 @@ -237,31 +244,35 @@
133 goto e_inval_res;
134 *spec_dst = FIB_RES_PREFSRC(res);
135 fib_combine_itag(itag, &res);
136 -#ifdef CONFIG_IP_ROUTE_MULTIPATH
137 - if (FIB_RES_DEV(res) == dev || res.fi->fib_nhs > 1)
138 -#else
139 if (FIB_RES_DEV(res) == dev)
140 -#endif
141 {
142 ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST;
143 fib_res_put(&res);
144 return ret;
145 }
146 + table = FIB_RES_TABLE(&res);
147 + prefixlen = res.prefixlen;
148 + scope = res.scope;
149 fib_res_put(&res);
150 if (no_addr)
151 goto last_resort;
152 - if (rpf)
153 - goto e_inval;
154 key.oif = dev->ifindex;
155
156 ret = 0;
157 if (fib_lookup(&key, &res) == 0) {
158 - if (res.type == RTN_UNICAST) {
159 + if (res.type == RTN_UNICAST &&
160 + ((table == FIB_RES_TABLE(&res) &&
161 + res.prefixlen >= prefixlen && res.scope >= scope) ||
162 + !rpf)) {
163 *spec_dst = FIB_RES_PREFSRC(res);
164 ret = FIB_RES_NH(res).nh_scope >= RT_SCOPE_HOST;
165 + fib_res_put(&res);
166 + return ret;
167 }
168 fib_res_put(&res);
169 }
170 + if (rpf)
171 + goto e_inval;
172 return ret;
173
174 last_resort:
175 @@ -579,9 +590,7 @@
176 switch (event) {
177 case NETDEV_UP:
178 fib_add_ifaddr(ifa);
179 -#ifdef CONFIG_IP_ROUTE_MULTIPATH
180 fib_sync_up(ifa->ifa_dev->dev);
181 -#endif
182 rt_cache_flush(-1);
183 break;
184 case NETDEV_DOWN:
185 @@ -617,9 +626,7 @@
186 for_ifa(in_dev) {
187 fib_add_ifaddr(ifa);
188 } endfor_ifa(in_dev);
189 -#ifdef CONFIG_IP_ROUTE_MULTIPATH
190 fib_sync_up(dev);
191 -#endif
192 rt_cache_flush(-1);
193 break;
194 case NETDEV_DOWN:
195 diff -ur v2.4.29/linux/net/ipv4/fib_hash.c linux/net/ipv4/fib_hash.c
196 --- v2.4.29/linux/net/ipv4/fib_hash.c 2003-08-25 22:06:13.000000000 +0300
197 +++ linux/net/ipv4/fib_hash.c 2005-01-20 09:55:47.000651672 +0200
198 @@ -71,6 +71,7 @@
199 struct fib_info *fn_info;
200 #define FIB_INFO(f) ((f)->fn_info)
201 fn_key_t fn_key;
202 + int fn_last_dflt;
203 u8 fn_tos;
204 u8 fn_type;
205 u8 fn_scope;
206 @@ -336,72 +337,123 @@
207 return err;
208 }
209
210 -static int fn_hash_last_dflt=-1;
211 -
212 -static int fib_detect_death(struct fib_info *fi, int order,
213 - struct fib_info **last_resort, int *last_idx)
214 +static int fib_detect_death(struct fib_info *fi, int order, int last_dflt,
215 + struct fib_info **last_resort, int *last_idx,
216 + int *last_nhsel, const struct rt_key *key)
217 {
218 struct neighbour *n;
219 - int state = NUD_NONE;
220 + int nhsel;
221 + int state;
222 + struct fib_nh * nh;
223 + u32 dst;
224 + int flag, dead = 1;
225 +
226 + /* change_nexthops(fi) { */
227 + for (nhsel = 0, nh = fi->fib_nh; nhsel < fi->fib_nhs; nh++, nhsel++) {
228 + if (key->oif && key->oif != nh->nh_oif)
229 + continue;
230 + if (key->gw && key->gw != nh->nh_gw && nh->nh_gw &&
231 + nh->nh_scope == RT_SCOPE_LINK)
232 + continue;
233 + if (nh->nh_flags & RTNH_F_DEAD)
234 + continue;
235
236 - n = neigh_lookup(&arp_tbl, &fi->fib_nh[0].nh_gw, fi->fib_dev);
237 - if (n) {
238 - state = n->nud_state;
239 - neigh_release(n);
240 + flag = 0;
241 + if (nh->nh_dev->flags & IFF_NOARP) {
242 + dead = 0;
243 + goto setfl;
244 + }
245 +
246 + dst = nh->nh_gw;
247 + if (!nh->nh_gw || nh->nh_scope != RT_SCOPE_LINK)
248 + dst = key->dst;
249 +
250 + state = NUD_NONE;
251 + n = neigh_lookup(&arp_tbl, &dst, nh->nh_dev);
252 + if (n) {
253 + state = n->nud_state;
254 + neigh_release(n);
255 + }
256 + if (state==NUD_REACHABLE ||
257 + ((state&NUD_VALID) && order != last_dflt)) {
258 + dead = 0;
259 + goto setfl;
260 + }
261 + if (!(state&NUD_VALID))
262 + flag = 1;
263 + if (!dead)
264 + goto setfl;
265 + if ((state&NUD_VALID) ||
266 + (*last_idx<0 && order >= last_dflt)) {
267 + *last_resort = fi;
268 + *last_idx = order;
269 + *last_nhsel = nhsel;
270 + }
271 +
272 + setfl:
273 +
274 + read_lock_bh(&fib_nhflags_lock);
275 + if (flag)
276 + nh->nh_flags |= RTNH_F_SUSPECT;
277 + else
278 + nh->nh_flags &= ~RTNH_F_SUSPECT;
279 + read_unlock_bh(&fib_nhflags_lock);
280 }
281 - if (state==NUD_REACHABLE)
282 - return 0;
283 - if ((state&NUD_VALID) && order != fn_hash_last_dflt)
284 - return 0;
285 - if ((state&NUD_VALID) ||
286 - (*last_idx<0 && order > fn_hash_last_dflt)) {
287 - *last_resort = fi;
288 - *last_idx = order;
289 - }
290 - return 1;
291 + /* } endfor_nexthops(fi) */
292 +
293 + return dead;
294 }
295
296 static void
297 fn_hash_select_default(struct fib_table *tb, const struct rt_key *key, struct fib_result *res)
298 {
299 - int order, last_idx;
300 - struct fib_node *f;
301 + int order, last_idx, last_dflt, last_nhsel;
302 + struct fib_node *f, *first_node;
303 struct fib_info *fi = NULL;
304 struct fib_info *last_resort;
305 struct fn_hash *t = (struct fn_hash*)tb->tb_data;
306 - struct fn_zone *fz = t->fn_zones[0];
307 + struct fn_zone *fz = t->fn_zones[res->prefixlen];
308 + fn_key_t k;
309
310 if (fz == NULL)
311 return;
312
313 + k = fz_key(key->dst, fz);
314 + last_dflt = -2;
315 + first_node = NULL;
316 last_idx = -1;
317 last_resort = NULL;
318 + last_nhsel = 0;
319 order = -1;
320
321 read_lock(&fib_hash_lock);
322 - for (f = fz->fz_hash[0]; f; f = f->fn_next) {
323 + for (f = fz_chain(k, fz); f; f = f->fn_next) {
324 struct fib_info *next_fi = FIB_INFO(f);
325
326 - if ((f->fn_state&FN_S_ZOMBIE) ||
327 + if (!fn_key_eq(k, f->fn_key) ||
328 + (f->fn_state&FN_S_ZOMBIE) ||
329 f->fn_scope != res->scope ||
330 +#ifdef CONFIG_IP_ROUTE_TOS
331 + (f->fn_tos && f->fn_tos != key->tos) ||
332 +#endif
333 f->fn_type != RTN_UNICAST)
334 continue;
335
336 if (next_fi->fib_priority > res->fi->fib_priority)
337 break;
338 - if (!next_fi->fib_nh[0].nh_gw || next_fi->fib_nh[0].nh_scope != RT_SCOPE_LINK)
339 - continue;
340 f->fn_state |= FN_S_ACCESSED;
341
342 - if (fi == NULL) {
343 - if (next_fi != res->fi)
344 - break;
345 - } else if (!fib_detect_death(fi, order, &last_resort, &last_idx)) {
346 + if (!first_node) {
347 + last_dflt = f->fn_last_dflt;
348 + first_node = f;
349 + }
350 + if (fi && !fib_detect_death(fi, order, last_dflt,
351 + &last_resort, &last_idx, &last_nhsel, key)) {
352 if (res->fi)
353 fib_info_put(res->fi);
354 res->fi = fi;
355 atomic_inc(&fi->fib_clntref);
356 - fn_hash_last_dflt = order;
357 + first_node->fn_last_dflt = order;
358 goto out;
359 }
360 fi = next_fi;
361 @@ -409,16 +461,25 @@
362 }
363
364 if (order<=0 || fi==NULL) {
365 - fn_hash_last_dflt = -1;
366 + if (fi && fi->fib_nhs > 1 &&
367 + fib_detect_death(fi, order, last_dflt,
368 + &last_resort, &last_idx, &last_nhsel, key) &&
369 + last_resort == fi) {
370 + read_lock_bh(&fib_nhflags_lock);
371 + fi->fib_nh[last_nhsel].nh_flags &= ~RTNH_F_SUSPECT;
372 + read_unlock_bh(&fib_nhflags_lock);
373 + }
374 + if (first_node) first_node->fn_last_dflt = -1;
375 goto out;
376 }
377
378 - if (!fib_detect_death(fi, order, &last_resort, &last_idx)) {
379 + if (!fib_detect_death(fi, order, last_dflt, &last_resort, &last_idx,
380 + &last_nhsel, key)) {
381 if (res->fi)
382 fib_info_put(res->fi);
383 res->fi = fi;
384 atomic_inc(&fi->fib_clntref);
385 - fn_hash_last_dflt = order;
386 + first_node->fn_last_dflt = order;
387 goto out;
388 }
389
390 @@ -428,8 +489,11 @@
391 res->fi = last_resort;
392 if (last_resort)
393 atomic_inc(&last_resort->fib_clntref);
394 + read_lock_bh(&fib_nhflags_lock);
395 + last_resort->fib_nh[last_nhsel].nh_flags &= ~RTNH_F_SUSPECT;
396 + read_unlock_bh(&fib_nhflags_lock);
397 + first_node->fn_last_dflt = last_idx;
398 }
399 - fn_hash_last_dflt = last_idx;
400 out:
401 read_unlock(&fib_hash_lock);
402 }
403 @@ -589,6 +653,7 @@
404
405 memset(new_f, 0, sizeof(struct fib_node));
406
407 + new_f->fn_last_dflt = -1;
408 new_f->fn_key = key;
409 #ifdef CONFIG_IP_ROUTE_TOS
410 new_f->fn_tos = tos;
411 diff -ur v2.4.29/linux/net/ipv4/fib_rules.c linux/net/ipv4/fib_rules.c
412 --- v2.4.29/linux/net/ipv4/fib_rules.c 2004-02-19 00:23:39.000000000 +0200
413 +++ linux/net/ipv4/fib_rules.c 2005-01-20 09:55:33.433714160 +0200
414 @@ -307,6 +307,11 @@
415 }
416 }
417
418 +int fib_result_table(struct fib_result *res)
419 +{
420 + return res->r->r_table;
421 +}
422 +
423 int fib_lookup(const struct rt_key *key, struct fib_result *res)
424 {
425 int err;
426 @@ -371,8 +376,10 @@
427
428 void fib_select_default(const struct rt_key *key, struct fib_result *res)
429 {
430 - if (res->r && res->r->r_action == RTN_UNICAST &&
431 - FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) {
432 + if (res->r &&
433 + (res->r->r_action == RTN_UNICAST || res->r->r_action == RTN_NAT) &&
434 + ((FIB_RES_GW(*res) && FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK) ||
435 + FIB_RES_NH(*res).nh_scope == RT_SCOPE_HOST)) {
436 struct fib_table *tb;
437 if ((tb = fib_get_table(res->r->r_table)) != NULL)
438 tb->tb_select_default(tb, key, res);
439 diff -ur v2.4.29/linux/net/ipv4/fib_semantics.c linux/net/ipv4/fib_semantics.c
440 --- v2.4.29/linux/net/ipv4/fib_semantics.c 2003-08-25 22:06:13.000000000 +0300
441 +++ linux/net/ipv4/fib_semantics.c 2005-01-20 09:55:47.000651672 +0200
442 @@ -48,6 +48,7 @@
443 static struct fib_info *fib_info_list;
444 static rwlock_t fib_info_lock = RW_LOCK_UNLOCKED;
445 int fib_info_cnt;
446 +rwlock_t fib_nhflags_lock = RW_LOCK_UNLOCKED;
447
448 #define for_fib_info() { struct fib_info *fi; \
449 for (fi = fib_info_list; fi; fi = fi->fib_next)
450 @@ -150,7 +151,7 @@
451 #ifdef CONFIG_NET_CLS_ROUTE
452 nh->nh_tclassid != onh->nh_tclassid ||
453 #endif
454 - ((nh->nh_flags^onh->nh_flags)&~RTNH_F_DEAD))
455 + ((nh->nh_flags^onh->nh_flags)&~RTNH_F_BADSTATE))
456 return -1;
457 onh++;
458 } endfor_nexthops(fi);
459 @@ -166,7 +167,7 @@
460 nfi->fib_prefsrc == fi->fib_prefsrc &&
461 nfi->fib_priority == fi->fib_priority &&
462 memcmp(nfi->fib_metrics, fi->fib_metrics, sizeof(fi->fib_metrics)) == 0 &&
463 - ((nfi->fib_flags^fi->fib_flags)&~RTNH_F_DEAD) == 0 &&
464 + ((nfi->fib_flags^fi->fib_flags)&~RTNH_F_BADSTATE) == 0 &&
465 (nfi->fib_nhs == 0 || nh_comp(fi, nfi) == 0))
466 return fi;
467 } endfor_fib_info();
468 @@ -365,8 +366,11 @@
469 return -EINVAL;
470 if ((dev = __dev_get_by_index(nh->nh_oif)) == NULL)
471 return -ENODEV;
472 - if (!(dev->flags&IFF_UP))
473 - return -ENETDOWN;
474 + if (!(dev->flags&IFF_UP)) {
475 + if (fi->fib_protocol != RTPROT_STATIC)
476 + return -ENETDOWN;
477 + nh->nh_flags |= RTNH_F_DEAD;
478 + }
479 nh->nh_dev = dev;
480 dev_hold(dev);
481 nh->nh_scope = RT_SCOPE_LINK;
482 @@ -380,23 +384,48 @@
483 /* It is not necessary, but requires a bit of thinking */
484 if (key.scope < RT_SCOPE_LINK)
485 key.scope = RT_SCOPE_LINK;
486 - if ((err = fib_lookup(&key, &res)) != 0)
487 - return err;
488 - err = -EINVAL;
489 - if (res.type != RTN_UNICAST && res.type != RTN_LOCAL)
490 - goto out;
491 - nh->nh_scope = res.scope;
492 - nh->nh_oif = FIB_RES_OIF(res);
493 - if ((nh->nh_dev = FIB_RES_DEV(res)) == NULL)
494 - goto out;
495 - dev_hold(nh->nh_dev);
496 - err = -ENETDOWN;
497 - if (!(nh->nh_dev->flags & IFF_UP))
498 - goto out;
499 - err = 0;
500 +
501 + err = fib_lookup(&key, &res);
502 + if (err) {
503 + struct in_device *in_dev;
504 +
505 + if (err != -ENETUNREACH ||
506 + fi->fib_protocol != RTPROT_STATIC)
507 + return err;
508 +
509 + in_dev = inetdev_by_index(nh->nh_oif);
510 + if (in_dev == NULL ||
511 + in_dev->dev->flags & IFF_UP) {
512 + if (in_dev)
513 + in_dev_put(in_dev);
514 + return err;
515 + }
516 + nh->nh_flags |= RTNH_F_DEAD;
517 + nh->nh_scope = RT_SCOPE_LINK;
518 + nh->nh_dev = in_dev->dev;
519 + dev_hold(nh->nh_dev);
520 + in_dev_put(in_dev);
521 + } else {
522 + err = -EINVAL;
523 + if (res.type != RTN_UNICAST && res.type != RTN_LOCAL)
524 + goto out;
525 + nh->nh_scope = res.scope;
526 + nh->nh_oif = FIB_RES_OIF(res);
527 + if ((nh->nh_dev = FIB_RES_DEV(res)) == NULL)
528 + goto out;
529 + dev_hold(nh->nh_dev);
530 + if (!(nh->nh_dev->flags & IFF_UP)) {
531 + if (fi->fib_protocol != RTPROT_STATIC) {
532 + err = -ENETDOWN;
533 + goto out;
534 + }
535 + nh->nh_flags |= RTNH_F_DEAD;
536 + }
537 + err = 0;
538 out:
539 - fib_res_put(&res);
540 - return err;
541 + fib_res_put(&res);
542 + return err;
543 + }
544 } else {
545 struct in_device *in_dev;
546
547 @@ -407,8 +436,11 @@
548 if (in_dev == NULL)
549 return -ENODEV;
550 if (!(in_dev->dev->flags&IFF_UP)) {
551 - in_dev_put(in_dev);
552 - return -ENETDOWN;
553 + if (fi->fib_protocol != RTPROT_STATIC) {
554 + in_dev_put(in_dev);
555 + return -ENETDOWN;
556 + }
557 + nh->nh_flags |= RTNH_F_DEAD;
558 }
559 nh->nh_dev = in_dev->dev;
560 dev_hold(nh->nh_dev);
561 @@ -603,8 +635,12 @@
562 for_nexthops(fi) {
563 if (nh->nh_flags&RTNH_F_DEAD)
564 continue;
565 - if (!key->oif || key->oif == nh->nh_oif)
566 - break;
567 + if (key->oif && key->oif != nh->nh_oif)
568 + continue;
569 + if (key->gw && key->gw != nh->nh_gw &&
570 + nh->nh_gw && nh->nh_scope == RT_SCOPE_LINK)
571 + continue;
572 + break;
573 }
574 #ifdef CONFIG_IP_ROUTE_MULTIPATH
575 if (nhsel < fi->fib_nhs) {
576 @@ -870,22 +906,35 @@
577 if (local && fi->fib_prefsrc == local) {
578 fi->fib_flags |= RTNH_F_DEAD;
579 ret++;
580 - } else if (dev && fi->fib_nhs) {
581 + } else if (fi->fib_nhs) {
582 int dead = 0;
583
584 change_nexthops(fi) {
585 - if (nh->nh_flags&RTNH_F_DEAD)
586 - dead++;
587 - else if (nh->nh_dev == dev &&
588 - nh->nh_scope != scope) {
589 - nh->nh_flags |= RTNH_F_DEAD;
590 + if (nh->nh_flags&RTNH_F_DEAD) {
591 + if (fi->fib_protocol!=RTPROT_STATIC ||
592 + nh->nh_dev == NULL ||
593 + !__in_dev_get(nh->nh_dev) ||
594 + nh->nh_dev->flags&IFF_UP)
595 + dead++;
596 + } else if ((nh->nh_dev == dev && dev &&
597 + nh->nh_scope != scope) ||
598 + (local == nh->nh_gw && local &&
599 + nh->nh_oif)) {
600 + write_lock_bh(&fib_nhflags_lock);
601 #ifdef CONFIG_IP_ROUTE_MULTIPATH
602 - spin_lock_bh(&fib_multipath_lock);
603 + spin_lock(&fib_multipath_lock);
604 + nh->nh_flags |= RTNH_F_DEAD;
605 fi->fib_power -= nh->nh_power;
606 nh->nh_power = 0;
607 - spin_unlock_bh(&fib_multipath_lock);
608 + spin_unlock(&fib_multipath_lock);
609 +#else
610 + nh->nh_flags |= RTNH_F_DEAD;
611 #endif
612 - dead++;
613 + write_unlock_bh(&fib_nhflags_lock);
614 + if (fi->fib_protocol!=RTPROT_STATIC ||
615 + force ||
616 + (dev && __in_dev_get(dev) == NULL))
617 + dead++;
618 }
619 #ifdef CONFIG_IP_ROUTE_MULTIPATH
620 if (force > 1 && nh->nh_dev == dev) {
621 @@ -903,37 +952,55 @@
622 return ret;
623 }
624
625 -#ifdef CONFIG_IP_ROUTE_MULTIPATH
626 -
627 /*
628 - Dead device goes up. We wake up dead nexthops.
629 - It takes sense only on multipath routes.
630 + Dead device goes up or new address is added. We wake up dead nexthops.
631 */
632
633 int fib_sync_up(struct net_device *dev)
634 {
635 - int ret = 0;
636 + struct rt_key key;
637 + struct fib_result res;
638 + int ret, rep;
639
640 +repeat:
641 if (!(dev->flags&IFF_UP))
642 return 0;
643
644 + ret = 0;
645 + rep = 0;
646 for_fib_info() {
647 int alive = 0;
648
649 change_nexthops(fi) {
650 - if (!(nh->nh_flags&RTNH_F_DEAD)) {
651 - alive++;
652 + if (!(nh->nh_flags&RTNH_F_DEAD))
653 continue;
654 - }
655 if (nh->nh_dev == NULL || !(nh->nh_dev->flags&IFF_UP))
656 continue;
657 if (nh->nh_dev != dev || __in_dev_get(dev) == NULL)
658 continue;
659 + if (nh->nh_gw && fi->fib_protocol == RTPROT_STATIC) {
660 + memset(&key, 0, sizeof(key));
661 + key.dst = nh->nh_gw;
662 + key.oif = nh->nh_oif;
663 + key.scope = nh->nh_scope;
664 + if (fib_lookup(&key, &res) != 0)
665 + continue;
666 + if (res.type != RTN_UNICAST &&
667 + res.type != RTN_LOCAL) {
668 + fib_res_put(&res);
669 + continue;
670 + }
671 + nh->nh_scope = res.scope;
672 + fib_res_put(&res);
673 + rep = 1;
674 + }
675 alive++;
676 +#ifdef CONFIG_IP_ROUTE_MULTIPATH
677 spin_lock_bh(&fib_multipath_lock);
678 nh->nh_power = 0;
679 nh->nh_flags &= ~RTNH_F_DEAD;
680 spin_unlock_bh(&fib_multipath_lock);
681 +#endif
682 } endfor_nexthops(fi)
683
684 if (alive > 0) {
685 @@ -941,9 +1008,13 @@
686 ret++;
687 }
688 } endfor_fib_info();
689 + if (rep)
690 + goto repeat;
691 return ret;
692 }
693
694 +#ifdef CONFIG_IP_ROUTE_MULTIPATH
695 +
696 /*
697 The algorithm is suboptimal, but it provides really
698 fair weighted route distribution.
699 @@ -952,24 +1023,45 @@
700 void fib_select_multipath(const struct rt_key *key, struct fib_result *res)
701 {
702 struct fib_info *fi = res->fi;
703 - int w;
704 + int w, alive;
705
706 spin_lock_bh(&fib_multipath_lock);
707 + if (key->oif) {
708 + int sel = -1;
709 + w = -1;
710 + change_nexthops(fi) {
711 + if (key->oif != nh->nh_oif)
712 + continue;
713 + if (key->gw && key->gw != nh->nh_gw &&
714 + nh->nh_gw && nh->nh_scope == RT_SCOPE_LINK)
715 + continue;
716 + if (!(nh->nh_flags&RTNH_F_BADSTATE)) {
717 + if (nh->nh_power > w) {
718 + w = nh->nh_power;
719 + sel = nhsel;
720 + }
721 + }
722 + } endfor_nexthops(fi);
723 + if (sel >= 0) {
724 + spin_unlock_bh(&fib_multipath_lock);
725 + res->nh_sel = sel;
726 + return;
727 + }
728 + goto last_resort;
729 + }
730 +
731 +repeat:
732 if (fi->fib_power <= 0) {
733 int power = 0;
734 change_nexthops(fi) {
735 - if (!(nh->nh_flags&RTNH_F_DEAD)) {
736 + if (!(nh->nh_flags&RTNH_F_BADSTATE)) {
737 power += nh->nh_weight;
738 nh->nh_power = nh->nh_weight;
739 }
740 } endfor_nexthops(fi);
741 fi->fib_power = power;
742 - if (power <= 0) {
743 - spin_unlock_bh(&fib_multipath_lock);
744 - /* Race condition: route has just become dead. */
745 - res->nh_sel = 0;
746 - return;
747 - }
748 + if (power <= 0)
749 + goto last_resort;
750 }
751
752
753 @@ -979,20 +1071,40 @@
754
755 w = jiffies % fi->fib_power;
756
757 + alive = 0;
758 change_nexthops(fi) {
759 - if (!(nh->nh_flags&RTNH_F_DEAD) && nh->nh_power) {
760 + if (!(nh->nh_flags&RTNH_F_BADSTATE) && nh->nh_power) {
761 if ((w -= nh->nh_power) <= 0) {
762 nh->nh_power--;
763 fi->fib_power--;
764 - res->nh_sel = nhsel;
765 spin_unlock_bh(&fib_multipath_lock);
766 + res->nh_sel = nhsel;
767 return;
768 }
769 + alive = 1;
770 + }
771 + } endfor_nexthops(fi);
772 + if (alive) {
773 + fi->fib_power = 0;
774 + goto repeat;
775 + }
776 +
777 +last_resort:
778 +
779 + for_nexthops(fi) {
780 + if (!(nh->nh_flags&RTNH_F_DEAD)) {
781 + if (key->oif && key->oif != nh->nh_oif)
782 + continue;
783 + if (key->gw && key->gw != nh->nh_gw &&
784 + nh->nh_gw && nh->nh_scope == RT_SCOPE_LINK)
785 + continue;
786 + spin_unlock_bh(&fib_multipath_lock);
787 + res->nh_sel = nhsel;
788 + return;
789 }
790 } endfor_nexthops(fi);
791
792 /* Race condition: route has just become dead. */
793 - res->nh_sel = 0;
794 spin_unlock_bh(&fib_multipath_lock);
795 }
796 #endif
797 diff -ur v2.4.29/linux/net/ipv4/ip_nat_dumb.c linux/net/ipv4/ip_nat_dumb.c
798 --- v2.4.29/linux/net/ipv4/ip_nat_dumb.c 2001-11-13 03:25:26.000000000 +0200
799 +++ linux/net/ipv4/ip_nat_dumb.c 2005-01-20 09:55:47.001651520 +0200
800 @@ -124,6 +124,7 @@
801 key.dst = ciph->saddr;
802 key.iif = skb->dev->ifindex;
803 key.oif = 0;
804 + key.gw = 0;
805 #ifdef CONFIG_IP_ROUTE_TOS
806 key.tos = RT_TOS(ciph->tos);
807 #endif
808 diff -ur v2.4.29/linux/net/ipv4/netfilter/ip_fw_compat_masq.c linux/net/ipv4/netfilter/ip_fw_compat_masq.c
809 --- v2.4.29/linux/net/ipv4/netfilter/ip_fw_compat_masq.c 2005-01-20 09:25:34.000000000 +0200
810 +++ linux/net/ipv4/netfilter/ip_fw_compat_masq.c 2005-01-20 09:55:47.001651520 +0200
811 @@ -41,6 +41,10 @@
812 enum ip_conntrack_info ctinfo;
813 struct ip_conntrack *ct;
814 unsigned int ret;
815 + struct rtable *rt, *skb_rt;
816 + struct net_device *skb_dev;
817 + __u32 saddr;
818 + int new;
819
820 /* Sorry, only ICMP, TCP and UDP. */
821 if (iph->protocol != IPPROTO_ICMP
822 @@ -64,22 +68,28 @@
823 }
824
825 info = &ct->nat.info;
826 + iph = (*pskb)->nh.iph;
827 + saddr = iph->saddr;
828 + new = 0;
829
830 WRITE_LOCK(&ip_nat_lock);
831 /* Setup the masquerade, if not already */
832 if (!info->initialized) {
833 u_int32_t newsrc;
834 - struct rtable *rt;
835 struct ip_nat_multi_range range;
836
837 + skb_rt = (struct rtable *) (*pskb)->dst;
838 + skb_dev = skb_rt->u.dst.dev;
839 /* Pass 0 instead of saddr, since it's going to be changed
840 anyway. */
841 - if (ip_route_output(&rt, iph->daddr, 0, 0, 0) != 0) {
842 + if (ip_route_output_lookup(&rt, iph->daddr, 0, RT_TOS(iph->tos),
843 + skb_dev? skb_dev->ifindex : 0,
844 + skb_dev? skb_rt->rt_gateway : 0) != 0) {
845 + WRITE_UNLOCK(&ip_nat_lock);
846 DEBUGP("ipnat_rule_masquerade: Can't reroute.\n");
847 return NF_DROP;
848 }
849 - newsrc = inet_select_addr(rt->u.dst.dev, rt->rt_gateway,
850 - RT_SCOPE_UNIVERSE);
851 + newsrc = rt->rt_src;
852 ip_rt_put(rt);
853 range = ((struct ip_nat_multi_range)
854 { 1,
855 @@ -92,11 +102,31 @@
856 WRITE_UNLOCK(&ip_nat_lock);
857 return ret;
858 }
859 + new = 1;
860 } else
861 DEBUGP("Masquerading already done on this conn.\n");
862 WRITE_UNLOCK(&ip_nat_lock);
863
864 - return do_bindings(ct, ctinfo, info, NF_IP_POST_ROUTING, pskb);
865 + ret = do_bindings(ct, ctinfo, info, NF_IP_POST_ROUTING, pskb);
866 + if (ret != NF_ACCEPT || saddr == (*pskb)->nh.iph->saddr || new)
867 + return ret;
868 +
869 + iph = (*pskb)->nh.iph;
870 + if (ip_route_output(&rt, iph->daddr, iph->saddr, RT_TOS(iph->tos), 0) != 0)
871 + return NF_DROP;
872 +
873 + skb_rt = (struct rtable *) (*pskb)->dst;
874 + skb_dev = skb_rt->u.dst.dev;
875 + if (skb_dev != rt->u.dst.dev || rt->rt_gateway != skb_rt->rt_gateway) {
876 + if (skb_dev != rt->u.dst.dev) {
877 + /* TODO: check the new mtu and reply FRAG_NEEDED */
878 + }
879 + dst_release((*pskb)->dst);
880 + (*pskb)->dst = &rt->u.dst;
881 + } else {
882 + ip_rt_put(rt);
883 + }
884 + return NF_ACCEPT;
885 }
886
887 void
888 diff -ur v2.4.29/linux/net/ipv4/netfilter/ip_nat_core.c linux/net/ipv4/netfilter/ip_nat_core.c
889 --- v2.4.29/linux/net/ipv4/netfilter/ip_nat_core.c 2005-01-20 09:25:34.000000000 +0200
890 +++ linux/net/ipv4/netfilter/ip_nat_core.c 2005-01-20 09:55:47.002651368 +0200
891 @@ -994,6 +994,60 @@
892 return NF_ACCEPT;
893 }
894
895 +unsigned int
896 +ip_nat_route_input(unsigned int hooknum,
897 + struct sk_buff **pskb,
898 + const struct net_device *in,
899 + const struct net_device *out,
900 + int (*okfn)(struct sk_buff *))
901 +{
902 + struct sk_buff *skb = *pskb;
903 + struct iphdr *iph;
904 + struct ip_conntrack *ct;
905 + enum ip_conntrack_info ctinfo;
906 + struct ip_nat_info *info;
907 + enum ip_conntrack_dir dir;
908 + __u32 saddr;
909 + int i;
910 +
911 + if (!(ct = ip_conntrack_get(skb, &ctinfo)))
912 + return NF_ACCEPT;
913 +
914 + info = &ct->nat.info;
915 + if (!info->initialized)
916 + return NF_ACCEPT;
917 +
918 + if (skb->dst)
919 + return NF_ACCEPT;
920 +
921 + if (skb->len < sizeof(struct iphdr))
922 + return NF_ACCEPT;
923 +
924 + iph = skb->nh.iph;
925 + saddr = iph->saddr;
926 + hooknum = NF_IP_POST_ROUTING;
927 + dir = CTINFO2DIR(ctinfo);
928 +
929 + READ_LOCK(&ip_nat_lock);
930 + for (i = 0; i < info->num_manips; i++) {
931 + if (info->manips[i].direction == dir
932 + && info->manips[i].hooknum == hooknum
933 + && info->manips[i].maniptype == IP_NAT_MANIP_SRC) {
934 + saddr = info->manips[i].manip.ip;
935 + }
936 + }
937 + READ_UNLOCK(&ip_nat_lock);
938 +
939 + if (saddr == iph->saddr)
940 + return NF_ACCEPT;
941 +
942 + if (ip_route_input_lookup(skb, iph->daddr, iph->saddr, iph->tos,
943 + skb->dev, saddr))
944 + return NF_DROP;
945 +
946 + return NF_ACCEPT;
947 +}
948 +
949 int __init ip_nat_init(void)
950 {
951 size_t i;
952 diff -ur v2.4.29/linux/net/ipv4/netfilter/ip_nat_standalone.c linux/net/ipv4/netfilter/ip_nat_standalone.c
953 --- v2.4.29/linux/net/ipv4/netfilter/ip_nat_standalone.c 2005-01-20 09:25:34.000000000 +0200
954 +++ linux/net/ipv4/netfilter/ip_nat_standalone.c 2005-01-20 09:55:47.002651368 +0200
955 @@ -241,6 +241,9 @@
956 /* Before packet filtering, change destination */
957 static struct nf_hook_ops ip_nat_in_ops
958 = { { NULL, NULL }, ip_nat_in, PF_INET, NF_IP_PRE_ROUTING, NF_IP_PRI_NAT_DST };
959 +/* Before routing, route before mangling */
960 +static struct nf_hook_ops ip_nat_inr_ops
961 += { { NULL, NULL }, ip_nat_route_input, PF_INET, NF_IP_PRE_ROUTING, NF_IP_PRI_LAST-1 };
962 /* After packet filtering, change source */
963 static struct nf_hook_ops ip_nat_out_ops
964 = { { NULL, NULL }, ip_nat_out, PF_INET, NF_IP_POST_ROUTING, NF_IP_PRI_NAT_SRC};
965 @@ -309,10 +312,15 @@
966 printk("ip_nat_init: can't register in hook.\n");
967 goto cleanup_nat;
968 }
969 + ret = nf_register_hook(&ip_nat_inr_ops);
970 + if (ret < 0) {
971 + printk("ip_nat_init: can't register inr hook.\n");
972 + goto cleanup_inops;
973 + }
974 ret = nf_register_hook(&ip_nat_out_ops);
975 if (ret < 0) {
976 printk("ip_nat_init: can't register out hook.\n");
977 - goto cleanup_inops;
978 + goto cleanup_inrops;
979 }
980 ret = nf_register_hook(&ip_nat_local_out_ops);
981 if (ret < 0) {
982 @@ -332,6 +340,8 @@
983 nf_unregister_hook(&ip_nat_local_out_ops);
984 cleanup_outops:
985 nf_unregister_hook(&ip_nat_out_ops);
986 + cleanup_inrops:
987 + nf_unregister_hook(&ip_nat_inr_ops);
988 cleanup_inops:
989 nf_unregister_hook(&ip_nat_in_ops);
990 cleanup_nat:
991 diff -ur v2.4.29/linux/net/ipv4/netfilter/ipt_MASQUERADE.c linux/net/ipv4/netfilter/ipt_MASQUERADE.c
992 --- v2.4.29/linux/net/ipv4/netfilter/ipt_MASQUERADE.c 2005-01-20 09:25:34.000000000 +0200
993 +++ linux/net/ipv4/netfilter/ipt_MASQUERADE.c 2005-01-20 09:55:47.003651216 +0200
994 @@ -87,7 +87,8 @@
995 key.dst = (*pskb)->nh.iph->daddr;
996 key.src = 0; /* Unknown: that's what we're trying to establish */
997 key.tos = RT_TOS((*pskb)->nh.iph->tos)|RTO_CONN;
998 - key.oif = 0;
999 + key.oif = out->ifindex;
1000 + key.gw = ((struct rtable *) (*pskb)->dst)->rt_gateway;
1001 #ifdef CONFIG_IP_ROUTE_FWMARK
1002 key.fwmark = (*pskb)->nfmark;
1003 #endif
1004 @@ -98,13 +99,6 @@
1005 " No route: Rusty's brain broke!\n");
1006 return NF_DROP;
1007 }
1008 - if (rt->u.dst.dev != out) {
1009 - if (net_ratelimit())
1010 - printk("MASQUERADE:"
1011 - " Route sent us somewhere else.\n");
1012 - ip_rt_put(rt);
1013 - return NF_DROP;
1014 - }
1015
1016 newsrc = rt->rt_src;
1017 DEBUGP("newsrc = %u.%u.%u.%u\n", NIPQUAD(newsrc));
1018 diff -ur v2.4.29/linux/net/ipv4/route.c linux/net/ipv4/route.c
1019 --- v2.4.29/linux/net/ipv4/route.c 2004-11-18 08:30:33.000000000 +0200
1020 +++ linux/net/ipv4/route.c 2005-01-20 09:55:47.004651064 +0200
1021 @@ -919,6 +919,7 @@
1022
1023 /* Gateway is different ... */
1024 rt->rt_gateway = new_gw;
1025 + if (rt->key.gw) rt->key.gw = new_gw;
1026
1027 /* Redirect received -> path was valid */
1028 dst_confirm(&rth->u.dst);
1029 @@ -1343,6 +1344,7 @@
1030 rth->key.fwmark = skb->nfmark;
1031 #endif
1032 rth->key.src = saddr;
1033 + rth->key.lsrc = 0;
1034 rth->rt_src = saddr;
1035 #ifdef CONFIG_IP_ROUTE_NAT
1036 rth->rt_dst_map = daddr;
1037 @@ -1356,6 +1358,7 @@
1038 rth->u.dst.dev = &loopback_dev;
1039 dev_hold(rth->u.dst.dev);
1040 rth->key.oif = 0;
1041 + rth->key.gw = 0;
1042 rth->rt_gateway = daddr;
1043 rth->rt_spec_dst= spec_dst;
1044 rth->rt_type = RTN_MULTICAST;
1045 @@ -1395,7 +1398,7 @@
1046 */
1047
1048 int ip_route_input_slow(struct sk_buff *skb, u32 daddr, u32 saddr,
1049 - u8 tos, struct net_device *dev)
1050 + u8 tos, struct net_device *dev, u32 lsrc)
1051 {
1052 struct rt_key key;
1053 struct fib_result res;
1054 @@ -1415,16 +1418,17 @@
1055 goto out;
1056
1057 key.dst = daddr;
1058 - key.src = saddr;
1059 + key.src = lsrc? : saddr;
1060 key.tos = tos;
1061 #ifdef CONFIG_IP_ROUTE_FWMARK
1062 key.fwmark = skb->nfmark;
1063 #endif
1064 - key.iif = dev->ifindex;
1065 + key.iif = lsrc? loopback_dev.ifindex : dev->ifindex;
1066 key.oif = 0;
1067 + key.gw = 0;
1068 key.scope = RT_SCOPE_UNIVERSE;
1069
1070 - hash = rt_hash_code(daddr, saddr ^ (key.iif << 5), tos);
1071 + hash = rt_hash_code(daddr, saddr ^ (dev->ifindex << 5), tos);
1072
1073 /* Check for the most weird martians, which can be not detected
1074 by fib_lookup.
1075 @@ -1445,6 +1449,12 @@
1076 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
1077 goto martian_destination;
1078
1079 + if (lsrc) {
1080 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
1081 + ZERONET(lsrc) || LOOPBACK(lsrc))
1082 + goto e_inval;
1083 + }
1084 +
1085 /*
1086 * Now we are ready to route packet.
1087 */
1088 @@ -1454,6 +1464,10 @@
1089 goto no_route;
1090 }
1091 free_res = 1;
1092 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
1093 + goto e_inval;
1094 + key.iif = dev->ifindex;
1095 + key.src = saddr;
1096
1097 rt_cache_stat[smp_processor_id()].in_slow_tot++;
1098
1099 @@ -1464,7 +1478,7 @@
1100
1101 if (1) {
1102 u32 src_map = saddr;
1103 - if (res.r)
1104 + if (res.r && !lsrc)
1105 src_map = fib_rules_policy(saddr, &res, &flags);
1106
1107 if (res.type == RTN_NAT) {
1108 @@ -1503,8 +1517,9 @@
1109 if (res.type != RTN_UNICAST)
1110 goto martian_destination;
1111
1112 + fib_select_default(&key, &res);
1113 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1114 - if (res.fi->fib_nhs > 1 && key.oif == 0)
1115 + if (res.fi->fib_nhs > 1)
1116 fib_select_multipath(&key, &res);
1117 #endif
1118 out_dev = in_dev_get(FIB_RES_DEV(res));
1119 @@ -1524,6 +1539,7 @@
1120 flags |= RTCF_DIRECTSRC;
1121
1122 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
1123 + !lsrc &&
1124 (IN_DEV_SHARED_MEDIA(out_dev) ||
1125 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(res))))
1126 flags |= RTCF_DOREDIRECT;
1127 @@ -1550,6 +1566,7 @@
1128 #endif
1129 rth->key.src = saddr;
1130 rth->rt_src = saddr;
1131 + rth->key.lsrc = lsrc;
1132 rth->rt_gateway = daddr;
1133 #ifdef CONFIG_IP_ROUTE_NAT
1134 rth->rt_src_map = key.src;
1135 @@ -1562,6 +1579,7 @@
1136 rth->u.dst.dev = out_dev->dev;
1137 dev_hold(rth->u.dst.dev);
1138 rth->key.oif = 0;
1139 + rth->key.gw = 0;
1140 rth->rt_spec_dst= spec_dst;
1141
1142 rth->u.dst.input = ip_forward;
1143 @@ -1572,7 +1590,8 @@
1144 rth->rt_flags = flags;
1145
1146 #ifdef CONFIG_NET_FASTROUTE
1147 - if (netdev_fastroute && !(flags&(RTCF_NAT|RTCF_MASQ|RTCF_DOREDIRECT))) {
1148 + if (netdev_fastroute && !(flags&(RTCF_NAT|RTCF_MASQ|RTCF_DOREDIRECT)) &&
1149 + !lsrc) {
1150 struct net_device *odev = rth->u.dst.dev;
1151 if (odev != dev &&
1152 dev->accept_fastpath &&
1153 @@ -1595,6 +1614,8 @@
1154 brd_input:
1155 if (skb->protocol != htons(ETH_P_IP))
1156 goto e_inval;
1157 + if (lsrc)
1158 + goto e_inval;
1159
1160 if (ZERONET(saddr))
1161 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
1162 @@ -1627,6 +1648,7 @@
1163 #endif
1164 rth->key.src = saddr;
1165 rth->rt_src = saddr;
1166 + rth->key.lsrc = 0;
1167 #ifdef CONFIG_IP_ROUTE_NAT
1168 rth->rt_dst_map = key.dst;
1169 rth->rt_src_map = key.src;
1170 @@ -1639,6 +1661,7 @@
1171 rth->u.dst.dev = &loopback_dev;
1172 dev_hold(rth->u.dst.dev);
1173 rth->key.oif = 0;
1174 + rth->key.gw = 0;
1175 rth->rt_gateway = daddr;
1176 rth->rt_spec_dst= spec_dst;
1177 rth->u.dst.input= ip_local_deliver;
1178 @@ -1704,8 +1727,9 @@
1179 goto e_inval;
1180 }
1181
1182 -int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
1183 - u8 tos, struct net_device *dev)
1184 +static inline int
1185 +ip_route_input_cached(struct sk_buff *skb, u32 daddr, u32 saddr,
1186 + u8 tos, struct net_device *dev, u32 lsrc)
1187 {
1188 struct rtable * rth;
1189 unsigned hash;
1190 @@ -1719,6 +1743,7 @@
1191 if (rth->key.dst == daddr &&
1192 rth->key.src == saddr &&
1193 rth->key.iif == iif &&
1194 + rth->key.lsrc == lsrc &&
1195 rth->key.oif == 0 &&
1196 #ifdef CONFIG_IP_ROUTE_FWMARK
1197 rth->key.fwmark == skb->nfmark &&
1198 @@ -1766,9 +1791,21 @@
1199 read_unlock(&inetdev_lock);
1200 return -EINVAL;
1201 }
1202 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
1203 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
1204 +}
1205 +
1206 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
1207 + u8 tos, struct net_device *dev)
1208 +{
1209 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
1210 }
1211
1212 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
1213 + u8 tos, struct net_device *dev, u32 lsrc)
1214 +{
1215 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
1216 +}
1217 +
1218 /*
1219 * Major route resolver routine.
1220 */
1221 @@ -1791,6 +1828,7 @@
1222 key.tos = tos & IPTOS_RT_MASK;
1223 key.iif = loopback_dev.ifindex;
1224 key.oif = oldkey->oif;
1225 + key.gw = oldkey->gw;
1226 #ifdef CONFIG_IP_ROUTE_FWMARK
1227 key.fwmark = oldkey->fwmark;
1228 #endif
1229 @@ -1880,6 +1918,7 @@
1230 dev_out = &loopback_dev;
1231 dev_hold(dev_out);
1232 key.oif = loopback_dev.ifindex;
1233 + key.gw = 0;
1234 res.type = RTN_LOCAL;
1235 flags |= RTCF_LOCAL;
1236 goto make_route;
1237 @@ -1887,7 +1926,7 @@
1238
1239 if (fib_lookup(&key, &res)) {
1240 res.fi = NULL;
1241 - if (oldkey->oif) {
1242 + if (oldkey->oif && dev_out->flags&IFF_UP) {
1243 /* Apparently, routing tables are wrong. Assume,
1244 that the destination is on link.
1245
1246 @@ -1930,6 +1969,7 @@
1247 dev_out = &loopback_dev;
1248 dev_hold(dev_out);
1249 key.oif = dev_out->ifindex;
1250 + key.gw = 0;
1251 if (res.fi)
1252 fib_info_put(res.fi);
1253 res.fi = NULL;
1254 @@ -1937,13 +1977,12 @@
1255 goto make_route;
1256 }
1257
1258 + if (res.type == RTN_UNICAST)
1259 + fib_select_default(&key, &res);
1260 #ifdef CONFIG_IP_ROUTE_MULTIPATH
1261 - if (res.fi->fib_nhs > 1 && key.oif == 0)
1262 + if (res.fi->fib_nhs > 1)
1263 fib_select_multipath(&key, &res);
1264 - else
1265 #endif
1266 - if (!res.prefixlen && res.type == RTN_UNICAST && !key.oif)
1267 - fib_select_default(&key, &res);
1268
1269 if (!key.src)
1270 key.src = FIB_RES_PREFSRC(res);
1271 @@ -2001,7 +2040,9 @@
1272 rth->key.tos = tos;
1273 rth->key.src = oldkey->src;
1274 rth->key.iif = 0;
1275 + rth->key.lsrc = 0;
1276 rth->key.oif = oldkey->oif;
1277 + rth->key.gw = oldkey->gw;
1278 #ifdef CONFIG_IP_ROUTE_FWMARK
1279 rth->key.fwmark = oldkey->fwmark;
1280 #endif
1281 @@ -2080,6 +2121,7 @@
1282 rth->key.src == key->src &&
1283 rth->key.iif == 0 &&
1284 rth->key.oif == key->oif &&
1285 + rth->key.gw == key->gw &&
1286 #ifdef CONFIG_IP_ROUTE_FWMARK
1287 rth->key.fwmark == key->fwmark &&
1288 #endif
1289 diff -ur v2.4.29/linux/net/netsyms.c linux/net/netsyms.c
1290 --- v2.4.29/linux/net/netsyms.c 2005-01-20 09:25:34.000000000 +0200
1291 +++ linux/net/netsyms.c 2005-01-20 09:55:47.005650912 +0200
1292 @@ -260,6 +260,7 @@
1293 EXPORT_SYMBOL(inet_unregister_protosw);
1294 EXPORT_SYMBOL(ip_route_output_key);
1295 EXPORT_SYMBOL(ip_route_input);
1296 +EXPORT_SYMBOL(ip_route_input_lookup);
1297 EXPORT_SYMBOL(icmp_send);
1298 EXPORT_SYMBOL(icmp_statistics);
1299 EXPORT_SYMBOL(icmp_err_convert);
This page took 0.140983 seconds and 5 git commands to generate.