1 diff -urN linux-2.6.21.1.old/include/linux/rtnetlink.h linux-2.6.21.1.dev/include/linux/rtnetlink.h
2 --- linux-2.6.21.1.old/include/linux/rtnetlink.h 2007-04-27 23:49:26.000000000 +0200
3 +++ linux-2.6.21.1.dev/include/linux/rtnetlink.h 2007-05-26 20:46:11.883321560 +0200
5 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
6 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
7 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
8 +#define RTNH_F_SUSPECT 8 /* We don't know the real state */
9 +#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
11 /* Macros to handle hexthops */
13 diff -urN linux-2.6.21.1.old/include/net/flow.h linux-2.6.21.1.dev/include/net/flow.h
14 --- linux-2.6.21.1.old/include/net/flow.h 2007-04-27 23:49:26.000000000 +0200
15 +++ linux-2.6.21.1.dev/include/net/flow.h 2007-05-26 20:46:11.922315632 +0200
26 #define fl6_flowlabel nl_u.ip6_u.flowlabel
27 #define fl4_dst nl_u.ip4_u.daddr
28 #define fl4_src nl_u.ip4_u.saddr
29 +#define fl4_lsrc nl_u.ip4_u.lsrc
30 +#define fl4_gw nl_u.ip4_u.gw
31 #define fl4_tos nl_u.ip4_u.tos
32 #define fl4_scope nl_u.ip4_u.scope
34 diff -urN linux-2.6.21.1.old/net/ipv4/route.c linux-2.6.21.1.dev/net/ipv4/route.c
35 --- linux-2.6.21.1.old/net/ipv4/route.c 2007-04-27 23:49:26.000000000 +0200
36 +++ linux-2.6.21.1.dev/net/ipv4/route.c 2007-05-26 20:46:11.967308792 +0200
39 /* Gateway is different ... */
40 rt->rt_gateway = new_gw;
41 + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
43 /* Redirect received -> path was valid */
44 dst_confirm(&rth->u.dst);
46 rth->fl.fl4_tos = tos;
47 rth->fl.mark = skb->mark;
48 rth->fl.fl4_src = saddr;
49 + rth->fl.fl4_lsrc = 0;
51 #ifdef CONFIG_NET_CLS_ROUTE
52 rth->u.dst.tclassid = itag;
54 dev_hold(rth->u.dst.dev);
55 rth->idev = in_dev_get(rth->u.dst.dev);
58 rth->rt_gateway = daddr;
59 rth->rt_spec_dst= spec_dst;
60 rth->rt_type = RTN_MULTICAST;
62 static inline int __mkroute_input(struct sk_buff *skb,
63 struct fib_result* res,
64 struct in_device *in_dev,
65 - __be32 daddr, __be32 saddr, u32 tos,
66 + __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
67 struct rtable **result)
71 flags |= RTCF_DIRECTSRC;
73 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
75 (IN_DEV_SHARED_MEDIA(out_dev) ||
76 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
77 flags |= RTCF_DOREDIRECT;
79 rth->fl.mark = skb->mark;
80 rth->fl.fl4_src = saddr;
82 + rth->fl.fl4_lsrc = lsrc;
83 rth->rt_gateway = daddr;
85 rth->fl.iif = in_dev->dev->ifindex;
87 dev_hold(rth->u.dst.dev);
88 rth->idev = in_dev_get(rth->u.dst.dev);
91 rth->rt_spec_dst= spec_dst;
93 rth->u.dst.input = ip_forward;
94 @@ -1816,19 +1822,21 @@
95 struct fib_result* res,
96 const struct flowi *fl,
97 struct in_device *in_dev,
98 - __be32 daddr, __be32 saddr, u32 tos)
99 + __be32 daddr, __be32 saddr, u32 tos,
102 struct rtable* rth = NULL;
106 + fib_select_default(fl, res);
107 #ifdef CONFIG_IP_ROUTE_MULTIPATH
108 - if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
109 + if (res->fi && res->fi->fib_nhs > 1)
110 fib_select_multipath(fl, res);
113 /* create a routing cache entry */
114 - err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
115 + err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
119 @@ -1841,7 +1849,8 @@
120 struct fib_result* res,
121 const struct flowi *fl,
122 struct in_device *in_dev,
123 - __be32 daddr, __be32 saddr, u32 tos)
124 + __be32 daddr, __be32 saddr, u32 tos,
127 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
128 struct rtable* rth = NULL, *rtres;
129 @@ -1857,7 +1866,7 @@
130 /* distinguish between multipath and singlepath */
132 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
136 /* add all alternatives to the routing cache */
137 for (hop = 0; hop < hopcount; hop++) {
138 @@ -1869,7 +1878,7 @@
140 /* create a routing cache entry */
141 err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
147 @@ -1889,7 +1898,7 @@
148 skb->dst = &rtres->u.dst;
150 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
151 - return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
152 + return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos, lsrc);
153 #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
156 @@ -1905,18 +1914,18 @@
159 static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
160 - u8 tos, struct net_device *dev)
161 + u8 tos, struct net_device *dev, u32 lsrc)
163 struct fib_result res;
164 struct in_device *in_dev = in_dev_get(dev);
165 struct flowi fl = { .nl_u = { .ip4_u =
168 + .saddr = lsrc ? : saddr,
170 .scope = RT_SCOPE_UNIVERSE,
173 - .iif = dev->ifindex };
174 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
178 @@ -1949,6 +1958,12 @@
179 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
180 goto martian_destination;
183 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
184 + ZERONET(lsrc) || LOOPBACK(lsrc))
189 * Now we are ready to route packet.
191 @@ -1958,6 +1973,10 @@
195 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
197 + fl.iif = dev->ifindex;
198 + fl.fl4_src = saddr;
200 RT_CACHE_STAT_INC(in_slow_tot);
202 @@ -1982,7 +2001,7 @@
203 if (res.type != RTN_UNICAST)
204 goto martian_destination;
206 - err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
207 + err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
211 @@ -1997,6 +2016,8 @@
213 if (skb->protocol != htons(ETH_P_IP))
219 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
220 @@ -2037,6 +2058,7 @@
221 rth->u.dst.dev = &loopback_dev;
222 dev_hold(rth->u.dst.dev);
223 rth->idev = in_dev_get(rth->u.dst.dev);
224 + rth->fl.fl4_gw = 0;
225 rth->rt_gateway = daddr;
226 rth->rt_spec_dst= spec_dst;
227 rth->u.dst.input= ip_local_deliver;
228 @@ -2086,8 +2108,9 @@
232 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
233 - u8 tos, struct net_device *dev)
235 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
236 + u8 tos, struct net_device *dev, u32 lsrc)
240 @@ -2102,6 +2125,7 @@
241 if (rth->fl.fl4_dst == daddr &&
242 rth->fl.fl4_src == saddr &&
243 rth->fl.iif == iif &&
244 + rth->fl.fl4_lsrc == lsrc &&
246 rth->fl.mark == skb->mark &&
247 rth->fl.fl4_tos == tos) {
248 @@ -2148,7 +2172,19 @@
252 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
253 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
256 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
257 + u8 tos, struct net_device *dev)
259 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
262 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
263 + u8 tos, struct net_device *dev, u32 lsrc)
265 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
268 static inline int __mkroute_output(struct rtable **result,
269 @@ -2227,6 +2263,7 @@
270 rth->fl.fl4_tos = tos;
271 rth->fl.fl4_src = oldflp->fl4_src;
272 rth->fl.oif = oldflp->oif;
273 + rth->fl.fl4_gw = oldflp->fl4_gw;
274 rth->fl.mark = oldflp->mark;
275 rth->rt_dst = fl->fl4_dst;
276 rth->rt_src = fl->fl4_src;
277 @@ -2367,6 +2404,7 @@
278 struct flowi fl = { .nl_u = { .ip4_u =
279 { .daddr = oldflp->fl4_dst,
280 .saddr = oldflp->fl4_src,
281 + .gw = oldflp->fl4_gw,
282 .tos = tos & IPTOS_RT_MASK,
283 .scope = ((tos & RTO_ONLINK) ?
285 @@ -2470,6 +2508,7 @@
286 dev_out = &loopback_dev;
288 fl.oif = loopback_dev.ifindex;
290 res.type = RTN_LOCAL;
293 @@ -2477,7 +2516,7 @@
295 if (fib_lookup(&fl, &res)) {
298 + if (oldflp->oif && dev_out->flags & IFF_UP) {
299 /* Apparently, routing tables are wrong. Assume,
300 that the destination is on link.
302 @@ -2517,6 +2556,7 @@
303 dev_out = &loopback_dev;
305 fl.oif = dev_out->ifindex;
308 fib_info_put(res.fi);
310 @@ -2524,13 +2564,12 @@
314 + if (res.type == RTN_UNICAST)
315 + fib_select_default(&fl, &res);
316 #ifdef CONFIG_IP_ROUTE_MULTIPATH
317 - if (res.fi->fib_nhs > 1 && fl.oif == 0)
318 + if (res.fi->fib_nhs > 1)
319 fib_select_multipath(&fl, &res);
322 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
323 - fib_select_default(&fl, &res);
326 fl.fl4_src = FIB_RES_PREFSRC(res);
327 @@ -2567,6 +2606,7 @@
328 rth->fl.fl4_src == flp->fl4_src &&
330 rth->fl.oif == flp->oif &&
331 + rth->fl.fl4_gw == flp->fl4_gw &&
332 rth->fl.mark == flp->mark &&
333 !((rth->fl.fl4_tos ^ flp->fl4_tos) &
334 (IPTOS_RT_MASK | RTO_ONLINK))) {
335 @@ -3271,3 +3311,4 @@
336 EXPORT_SYMBOL(__ip_select_ident);
337 EXPORT_SYMBOL(ip_route_input);
338 EXPORT_SYMBOL(ip_route_output_key);
339 +EXPORT_SYMBOL(ip_route_input_lookup);