1 Index: linux-2.6.23-rc6/include/linux/rtnetlink.h
2 ===================================================================
3 --- linux-2.6.23-rc6.orig/include/linux/rtnetlink.h 2007-09-21 16:23:53.000000000 +0800
4 +++ linux-2.6.23-rc6/include/linux/rtnetlink.h 2007-09-21 16:24:04.000000000 +0800
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.23-rc6/include/net/flow.h
15 ===================================================================
16 --- linux-2.6.23-rc6.orig/include/net/flow.h 2007-09-21 16:23:53.000000000 +0800
17 +++ linux-2.6.23-rc6/include/net/flow.h 2007-09-21 16:24:04.000000000 +0800
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.23-rc6/net/ipv4/route.c
37 ===================================================================
38 --- linux-2.6.23-rc6.orig/net/ipv4/route.c 2007-09-21 16:23:53.000000000 +0800
39 +++ linux-2.6.23-rc6/net/ipv4/route.c 2007-09-21 16:24:04.000000000 +0800
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);
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;
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;
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)
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;
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;
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 @@ -1720,19 +1726,21 @@
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 @@ -1752,18 +1760,18 @@
125 static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
126 - u8 tos, struct net_device *dev)
127 + u8 tos, struct net_device *dev, u32 lsrc)
129 struct fib_result res;
130 struct in_device *in_dev = in_dev_get(dev);
131 struct flowi fl = { .nl_u = { .ip4_u =
134 + .saddr = lsrc ? : saddr,
136 .scope = RT_SCOPE_UNIVERSE,
139 - .iif = dev->ifindex };
140 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
144 @@ -1796,6 +1804,12 @@
145 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
146 goto martian_destination;
149 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
150 + ZERONET(lsrc) || LOOPBACK(lsrc))
155 * Now we are ready to route packet.
157 @@ -1805,6 +1819,10 @@
161 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
163 + fl.iif = dev->ifindex;
164 + fl.fl4_src = saddr;
166 RT_CACHE_STAT_INC(in_slow_tot);
168 @@ -1829,7 +1847,7 @@
169 if (res.type != RTN_UNICAST)
170 goto martian_destination;
172 - err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
173 + err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
177 @@ -1844,6 +1862,8 @@
179 if (skb->protocol != htons(ETH_P_IP))
185 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
186 @@ -1884,6 +1904,7 @@
187 rth->u.dst.dev = &loopback_dev;
188 dev_hold(rth->u.dst.dev);
189 rth->idev = in_dev_get(rth->u.dst.dev);
190 + rth->fl.fl4_gw = 0;
191 rth->rt_gateway = daddr;
192 rth->rt_spec_dst= spec_dst;
193 rth->u.dst.input= ip_local_deliver;
194 @@ -1933,8 +1954,9 @@
198 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
199 - u8 tos, struct net_device *dev)
201 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
202 + u8 tos, struct net_device *dev, u32 lsrc)
206 @@ -1949,6 +1971,7 @@
207 if (rth->fl.fl4_dst == daddr &&
208 rth->fl.fl4_src == saddr &&
209 rth->fl.iif == iif &&
210 + rth->fl.fl4_lsrc == lsrc &&
212 rth->fl.mark == skb->mark &&
213 rth->fl.fl4_tos == tos) {
214 @@ -1995,7 +2018,19 @@
218 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
219 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
222 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
223 + u8 tos, struct net_device *dev)
225 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
228 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
229 + u8 tos, struct net_device *dev, u32 lsrc)
231 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
234 static inline int __mkroute_output(struct rtable **result,
235 @@ -2067,6 +2102,7 @@
236 rth->fl.fl4_tos = tos;
237 rth->fl.fl4_src = oldflp->fl4_src;
238 rth->fl.oif = oldflp->oif;
239 + rth->fl.fl4_gw = oldflp->fl4_gw;
240 rth->fl.mark = oldflp->mark;
241 rth->rt_dst = fl->fl4_dst;
242 rth->rt_src = fl->fl4_src;
243 @@ -2145,6 +2181,7 @@
244 struct flowi fl = { .nl_u = { .ip4_u =
245 { .daddr = oldflp->fl4_dst,
246 .saddr = oldflp->fl4_src,
247 + .gw = oldflp->fl4_gw,
248 .tos = tos & IPTOS_RT_MASK,
249 .scope = ((tos & RTO_ONLINK) ?
251 @@ -2248,6 +2285,7 @@
252 dev_out = &loopback_dev;
254 fl.oif = loopback_dev.ifindex;
256 res.type = RTN_LOCAL;
259 @@ -2255,7 +2293,7 @@
261 if (fib_lookup(&fl, &res)) {
264 + if (oldflp->oif && dev_out->flags & IFF_UP) {
265 /* Apparently, routing tables are wrong. Assume,
266 that the destination is on link.
268 @@ -2295,6 +2333,7 @@
269 dev_out = &loopback_dev;
271 fl.oif = dev_out->ifindex;
274 fib_info_put(res.fi);
276 @@ -2302,13 +2341,12 @@
280 + if (res.type == RTN_UNICAST)
281 + fib_select_default(&fl, &res);
282 #ifdef CONFIG_IP_ROUTE_MULTIPATH
283 - if (res.fi->fib_nhs > 1 && fl.oif == 0)
284 + if (res.fi->fib_nhs > 1)
285 fib_select_multipath(&fl, &res);
288 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
289 - fib_select_default(&fl, &res);
292 fl.fl4_src = FIB_RES_PREFSRC(res);
293 @@ -2345,6 +2383,7 @@
294 rth->fl.fl4_src == flp->fl4_src &&
296 rth->fl.oif == flp->oif &&
297 + rth->fl.fl4_gw == flp->fl4_gw &&
298 rth->fl.mark == flp->mark &&
299 !((rth->fl.fl4_tos ^ flp->fl4_tos) &
300 (IPTOS_RT_MASK | RTO_ONLINK))) {
301 @@ -3034,3 +3073,4 @@
302 EXPORT_SYMBOL(__ip_select_ident);
303 EXPORT_SYMBOL(ip_route_input);
304 EXPORT_SYMBOL(ip_route_output_key);
305 +EXPORT_SYMBOL(ip_route_input_lookup);