1 Index: linux-2.6.22.19/include/linux/rtnetlink.h
2 ===================================================================
3 --- linux-2.6.22.19.orig/include/linux/rtnetlink.h
4 +++ linux-2.6.22.19/include/linux/rtnetlink.h
5 @@ -293,6 +293,8 @@ struct rtnexthop
6 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
7 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
8 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
9 +#define RTNH_F_SUSPECT 8 /* We don't know the real state */
10 +#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
12 /* Macros to handle hexthops */
14 Index: linux-2.6.22.19/include/net/flow.h
15 ===================================================================
16 --- linux-2.6.22.19.orig/include/net/flow.h
17 +++ linux-2.6.22.19/include/net/flow.h
18 @@ -19,6 +19,8 @@ struct flowi {
27 @@ -43,6 +45,8 @@ struct flowi {
28 #define fl6_flowlabel nl_u.ip6_u.flowlabel
29 #define fl4_dst nl_u.ip4_u.daddr
30 #define fl4_src nl_u.ip4_u.saddr
31 +#define fl4_lsrc nl_u.ip4_u.lsrc
32 +#define fl4_gw nl_u.ip4_u.gw
33 #define fl4_tos nl_u.ip4_u.tos
34 #define fl4_scope nl_u.ip4_u.scope
36 Index: linux-2.6.22.19/net/ipv4/route.c
37 ===================================================================
38 --- linux-2.6.22.19.orig/net/ipv4/route.c
39 +++ linux-2.6.22.19/net/ipv4/route.c
40 @@ -1208,6 +1208,7 @@ void ip_rt_redirect(__be32 old_gw, __be3
42 /* Gateway is different ... */
43 rt->rt_gateway = new_gw;
44 + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
46 /* Redirect received -> path was valid */
47 dst_confirm(&rth->u.dst);
48 @@ -1643,6 +1644,7 @@ static int ip_route_input_mc(struct sk_b
49 rth->fl.fl4_tos = tos;
50 rth->fl.mark = skb->mark;
51 rth->fl.fl4_src = saddr;
52 + rth->fl.fl4_lsrc = 0;
54 #ifdef CONFIG_NET_CLS_ROUTE
55 rth->u.dst.tclassid = itag;
56 @@ -1653,6 +1655,7 @@ static int ip_route_input_mc(struct sk_b
57 dev_hold(rth->u.dst.dev);
58 rth->idev = in_dev_get(rth->u.dst.dev);
61 rth->rt_gateway = daddr;
62 rth->rt_spec_dst= spec_dst;
63 rth->rt_type = RTN_MULTICAST;
64 @@ -1716,7 +1719,7 @@ static void ip_handle_martian_source(str
65 static inline int __mkroute_input(struct sk_buff *skb,
66 struct fib_result* res,
67 struct in_device *in_dev,
68 - __be32 daddr, __be32 saddr, u32 tos,
69 + __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
70 struct rtable **result)
73 @@ -1751,6 +1754,7 @@ static inline int __mkroute_input(struct
74 flags |= RTCF_DIRECTSRC;
76 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
78 (IN_DEV_SHARED_MEDIA(out_dev) ||
79 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
80 flags |= RTCF_DOREDIRECT;
81 @@ -1788,6 +1792,7 @@ static inline int __mkroute_input(struct
82 rth->fl.mark = skb->mark;
83 rth->fl.fl4_src = saddr;
85 + rth->fl.fl4_lsrc = lsrc;
86 rth->rt_gateway = daddr;
88 rth->fl.iif = in_dev->dev->ifindex;
89 @@ -1795,6 +1800,7 @@ static inline int __mkroute_input(struct
90 dev_hold(rth->u.dst.dev);
91 rth->idev = in_dev_get(rth->u.dst.dev);
94 rth->rt_spec_dst= spec_dst;
96 rth->u.dst.input = ip_forward;
97 @@ -1816,19 +1822,21 @@ static inline int ip_mkroute_input_def(s
98 struct fib_result* res,
99 const struct flowi *fl,
100 struct in_device *in_dev,
101 - __be32 daddr, __be32 saddr, u32 tos)
102 + __be32 daddr, __be32 saddr, u32 tos,
105 struct rtable* rth = NULL;
109 + fib_select_default(fl, res);
110 #ifdef CONFIG_IP_ROUTE_MULTIPATH
111 - if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
112 + if (res->fi && res->fi->fib_nhs > 1)
113 fib_select_multipath(fl, res);
116 /* create a routing cache entry */
117 - err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
118 + err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
122 @@ -1841,7 +1849,8 @@ static inline int ip_mkroute_input(struc
123 struct fib_result* res,
124 const struct flowi *fl,
125 struct in_device *in_dev,
126 - __be32 daddr, __be32 saddr, u32 tos)
127 + __be32 daddr, __be32 saddr, u32 tos,
130 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
131 struct rtable* rth = NULL, *rtres;
132 @@ -1857,7 +1866,7 @@ static inline int ip_mkroute_input(struc
133 /* distinguish between multipath and singlepath */
135 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
139 /* add all alternatives to the routing cache */
140 for (hop = 0; hop < hopcount; hop++) {
141 @@ -1869,7 +1878,7 @@ static inline int ip_mkroute_input(struc
143 /* create a routing cache entry */
144 err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
150 @@ -1889,7 +1898,7 @@ static inline int ip_mkroute_input(struc
151 skb->dst = &rtres->u.dst;
153 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
154 - return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
155 + return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos, lsrc);
156 #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
159 @@ -1905,18 +1914,18 @@ static inline int ip_mkroute_input(struc
162 static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
163 - u8 tos, struct net_device *dev)
164 + u8 tos, struct net_device *dev, u32 lsrc)
166 struct fib_result res;
167 struct in_device *in_dev = in_dev_get(dev);
168 struct flowi fl = { .nl_u = { .ip4_u =
171 + .saddr = lsrc ? : saddr,
173 .scope = RT_SCOPE_UNIVERSE,
176 - .iif = dev->ifindex };
177 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
181 @@ -1949,6 +1958,12 @@ static int ip_route_input_slow(struct sk
182 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
183 goto martian_destination;
186 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
187 + ZERONET(lsrc) || LOOPBACK(lsrc))
192 * Now we are ready to route packet.
194 @@ -1958,6 +1973,10 @@ static int ip_route_input_slow(struct sk
198 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
200 + fl.iif = dev->ifindex;
201 + fl.fl4_src = saddr;
203 RT_CACHE_STAT_INC(in_slow_tot);
205 @@ -1982,7 +2001,7 @@ static int ip_route_input_slow(struct sk
206 if (res.type != RTN_UNICAST)
207 goto martian_destination;
209 - err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
210 + err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
214 @@ -1997,6 +2016,8 @@ out: return err;
216 if (skb->protocol != htons(ETH_P_IP))
222 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
223 @@ -2037,6 +2058,7 @@ local_input:
224 rth->u.dst.dev = &loopback_dev;
225 dev_hold(rth->u.dst.dev);
226 rth->idev = in_dev_get(rth->u.dst.dev);
227 + rth->fl.fl4_gw = 0;
228 rth->rt_gateway = daddr;
229 rth->rt_spec_dst= spec_dst;
230 rth->u.dst.input= ip_local_deliver;
231 @@ -2086,8 +2108,9 @@ martian_source:
235 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
236 - u8 tos, struct net_device *dev)
238 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
239 + u8 tos, struct net_device *dev, u32 lsrc)
243 @@ -2102,6 +2125,7 @@ int ip_route_input(struct sk_buff *skb,
244 if (rth->fl.fl4_dst == daddr &&
245 rth->fl.fl4_src == saddr &&
246 rth->fl.iif == iif &&
247 + rth->fl.fl4_lsrc == lsrc &&
249 rth->fl.mark == skb->mark &&
250 rth->fl.fl4_tos == tos) {
251 @@ -2148,7 +2172,19 @@ int ip_route_input(struct sk_buff *skb,
255 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
256 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
259 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
260 + u8 tos, struct net_device *dev)
262 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
265 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
266 + u8 tos, struct net_device *dev, u32 lsrc)
268 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
271 static inline int __mkroute_output(struct rtable **result,
272 @@ -2227,6 +2263,7 @@ static inline int __mkroute_output(struc
273 rth->fl.fl4_tos = tos;
274 rth->fl.fl4_src = oldflp->fl4_src;
275 rth->fl.oif = oldflp->oif;
276 + rth->fl.fl4_gw = oldflp->fl4_gw;
277 rth->fl.mark = oldflp->mark;
278 rth->rt_dst = fl->fl4_dst;
279 rth->rt_src = fl->fl4_src;
280 @@ -2367,6 +2404,7 @@ static int ip_route_output_slow(struct r
281 struct flowi fl = { .nl_u = { .ip4_u =
282 { .daddr = oldflp->fl4_dst,
283 .saddr = oldflp->fl4_src,
284 + .gw = oldflp->fl4_gw,
285 .tos = tos & IPTOS_RT_MASK,
286 .scope = ((tos & RTO_ONLINK) ?
288 @@ -2470,6 +2508,7 @@ static int ip_route_output_slow(struct r
289 dev_out = &loopback_dev;
291 fl.oif = loopback_dev.ifindex;
293 res.type = RTN_LOCAL;
296 @@ -2477,7 +2516,7 @@ static int ip_route_output_slow(struct r
298 if (fib_lookup(&fl, &res)) {
301 + if (oldflp->oif && dev_out->flags & IFF_UP) {
302 /* Apparently, routing tables are wrong. Assume,
303 that the destination is on link.
305 @@ -2517,6 +2556,7 @@ static int ip_route_output_slow(struct r
306 dev_out = &loopback_dev;
308 fl.oif = dev_out->ifindex;
311 fib_info_put(res.fi);
313 @@ -2524,13 +2564,12 @@ static int ip_route_output_slow(struct r
317 + if (res.type == RTN_UNICAST)
318 + fib_select_default(&fl, &res);
319 #ifdef CONFIG_IP_ROUTE_MULTIPATH
320 - if (res.fi->fib_nhs > 1 && fl.oif == 0)
321 + if (res.fi->fib_nhs > 1)
322 fib_select_multipath(&fl, &res);
325 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
326 - fib_select_default(&fl, &res);
329 fl.fl4_src = FIB_RES_PREFSRC(res);
330 @@ -2567,6 +2606,7 @@ int __ip_route_output_key(struct rtable
331 rth->fl.fl4_src == flp->fl4_src &&
333 rth->fl.oif == flp->oif &&
334 + rth->fl.fl4_gw == flp->fl4_gw &&
335 rth->fl.mark == flp->mark &&
336 !((rth->fl.fl4_tos ^ flp->fl4_tos) &
337 (IPTOS_RT_MASK | RTO_ONLINK))) {
338 @@ -3267,3 +3307,4 @@ int __init ip_rt_init(void)
339 EXPORT_SYMBOL(__ip_select_ident);
340 EXPORT_SYMBOL(ip_route_input);
341 EXPORT_SYMBOL(ip_route_output_key);
342 +EXPORT_SYMBOL(ip_route_input_lookup);