1 --- a/include/linux/rtnetlink.h
2 +++ b/include/linux/rtnetlink.h
4 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
5 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
6 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
7 +#define RTNH_F_SUSPECT 8 /* We don't know the real state */
8 +#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
10 /* Macros to handle hexthops */
12 --- a/include/net/flow.h
13 +++ b/include/net/flow.h
24 #define fl6_flowlabel nl_u.ip6_u.flowlabel
25 #define fl4_dst nl_u.ip4_u.daddr
26 #define fl4_src nl_u.ip4_u.saddr
27 +#define fl4_lsrc nl_u.ip4_u.lsrc
28 +#define fl4_gw nl_u.ip4_u.gw
29 #define fl4_tos nl_u.ip4_u.tos
30 #define fl4_scope nl_u.ip4_u.scope
32 --- a/net/ipv4/route.c
33 +++ b/net/ipv4/route.c
36 /* Gateway is different ... */
37 rt->rt_gateway = new_gw;
38 + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
40 /* Redirect received -> path was valid */
41 dst_confirm(&rth->u.dst);
43 rth->fl.fl4_tos = tos;
44 rth->fl.mark = skb->mark;
45 rth->fl.fl4_src = saddr;
46 + rth->fl.fl4_lsrc = 0;
48 #ifdef CONFIG_NET_CLS_ROUTE
49 rth->u.dst.tclassid = itag;
51 dev_hold(rth->u.dst.dev);
52 rth->idev = in_dev_get(rth->u.dst.dev);
55 rth->rt_gateway = daddr;
56 rth->rt_spec_dst= spec_dst;
57 rth->rt_type = RTN_MULTICAST;
59 static inline int __mkroute_input(struct sk_buff *skb,
60 struct fib_result* res,
61 struct in_device *in_dev,
62 - __be32 daddr, __be32 saddr, u32 tos,
63 + __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
64 struct rtable **result)
68 flags |= RTCF_DIRECTSRC;
70 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
72 (IN_DEV_SHARED_MEDIA(out_dev) ||
73 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
74 flags |= RTCF_DOREDIRECT;
76 rth->fl.mark = skb->mark;
77 rth->fl.fl4_src = saddr;
79 + rth->fl.fl4_lsrc = lsrc;
80 rth->rt_gateway = daddr;
82 rth->fl.iif = in_dev->dev->ifindex;
84 dev_hold(rth->u.dst.dev);
85 rth->idev = in_dev_get(rth->u.dst.dev);
88 rth->rt_spec_dst= spec_dst;
90 rth->u.dst.input = ip_forward;
91 @@ -1816,19 +1822,21 @@
92 struct fib_result* res,
93 const struct flowi *fl,
94 struct in_device *in_dev,
95 - __be32 daddr, __be32 saddr, u32 tos)
96 + __be32 daddr, __be32 saddr, u32 tos,
99 struct rtable* rth = NULL;
103 + fib_select_default(fl, res);
104 #ifdef CONFIG_IP_ROUTE_MULTIPATH
105 - if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
106 + if (res->fi && res->fi->fib_nhs > 1)
107 fib_select_multipath(fl, res);
110 /* create a routing cache entry */
111 - err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
112 + err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
116 @@ -1841,7 +1849,8 @@
117 struct fib_result* res,
118 const struct flowi *fl,
119 struct in_device *in_dev,
120 - __be32 daddr, __be32 saddr, u32 tos)
121 + __be32 daddr, __be32 saddr, u32 tos,
124 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
125 struct rtable* rth = NULL, *rtres;
126 @@ -1857,7 +1866,7 @@
127 /* distinguish between multipath and singlepath */
129 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
133 /* add all alternatives to the routing cache */
134 for (hop = 0; hop < hopcount; hop++) {
135 @@ -1869,7 +1878,7 @@
137 /* create a routing cache entry */
138 err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
144 @@ -1889,7 +1898,7 @@
145 skb->dst = &rtres->u.dst;
147 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
148 - return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
149 + return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos, lsrc);
150 #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
153 @@ -1905,18 +1914,18 @@
156 static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
157 - u8 tos, struct net_device *dev)
158 + u8 tos, struct net_device *dev, u32 lsrc)
160 struct fib_result res;
161 struct in_device *in_dev = in_dev_get(dev);
162 struct flowi fl = { .nl_u = { .ip4_u =
165 + .saddr = lsrc ? : saddr,
167 .scope = RT_SCOPE_UNIVERSE,
170 - .iif = dev->ifindex };
171 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
175 @@ -1949,6 +1958,12 @@
176 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
177 goto martian_destination;
180 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
181 + ZERONET(lsrc) || LOOPBACK(lsrc))
186 * Now we are ready to route packet.
188 @@ -1958,6 +1973,10 @@
192 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
194 + fl.iif = dev->ifindex;
195 + fl.fl4_src = saddr;
197 RT_CACHE_STAT_INC(in_slow_tot);
199 @@ -1982,7 +2001,7 @@
200 if (res.type != RTN_UNICAST)
201 goto martian_destination;
203 - err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
204 + err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
208 @@ -1997,6 +2016,8 @@
210 if (skb->protocol != htons(ETH_P_IP))
216 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
217 @@ -2037,6 +2058,7 @@
218 rth->u.dst.dev = &loopback_dev;
219 dev_hold(rth->u.dst.dev);
220 rth->idev = in_dev_get(rth->u.dst.dev);
221 + rth->fl.fl4_gw = 0;
222 rth->rt_gateway = daddr;
223 rth->rt_spec_dst= spec_dst;
224 rth->u.dst.input= ip_local_deliver;
225 @@ -2086,8 +2108,9 @@
229 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
230 - u8 tos, struct net_device *dev)
232 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
233 + u8 tos, struct net_device *dev, u32 lsrc)
237 @@ -2102,6 +2125,7 @@
238 if (rth->fl.fl4_dst == daddr &&
239 rth->fl.fl4_src == saddr &&
240 rth->fl.iif == iif &&
241 + rth->fl.fl4_lsrc == lsrc &&
243 rth->fl.mark == skb->mark &&
244 rth->fl.fl4_tos == tos) {
245 @@ -2148,7 +2172,19 @@
249 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
250 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
253 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
254 + u8 tos, struct net_device *dev)
256 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
259 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
260 + u8 tos, struct net_device *dev, u32 lsrc)
262 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
265 static inline int __mkroute_output(struct rtable **result,
266 @@ -2227,6 +2263,7 @@
267 rth->fl.fl4_tos = tos;
268 rth->fl.fl4_src = oldflp->fl4_src;
269 rth->fl.oif = oldflp->oif;
270 + rth->fl.fl4_gw = oldflp->fl4_gw;
271 rth->fl.mark = oldflp->mark;
272 rth->rt_dst = fl->fl4_dst;
273 rth->rt_src = fl->fl4_src;
274 @@ -2367,6 +2404,7 @@
275 struct flowi fl = { .nl_u = { .ip4_u =
276 { .daddr = oldflp->fl4_dst,
277 .saddr = oldflp->fl4_src,
278 + .gw = oldflp->fl4_gw,
279 .tos = tos & IPTOS_RT_MASK,
280 .scope = ((tos & RTO_ONLINK) ?
282 @@ -2470,6 +2508,7 @@
283 dev_out = &loopback_dev;
285 fl.oif = loopback_dev.ifindex;
287 res.type = RTN_LOCAL;
290 @@ -2477,7 +2516,7 @@
292 if (fib_lookup(&fl, &res)) {
295 + if (oldflp->oif && dev_out->flags & IFF_UP) {
296 /* Apparently, routing tables are wrong. Assume,
297 that the destination is on link.
299 @@ -2517,6 +2556,7 @@
300 dev_out = &loopback_dev;
302 fl.oif = dev_out->ifindex;
305 fib_info_put(res.fi);
307 @@ -2524,13 +2564,12 @@
311 + if (res.type == RTN_UNICAST)
312 + fib_select_default(&fl, &res);
313 #ifdef CONFIG_IP_ROUTE_MULTIPATH
314 - if (res.fi->fib_nhs > 1 && fl.oif == 0)
315 + if (res.fi->fib_nhs > 1)
316 fib_select_multipath(&fl, &res);
319 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
320 - fib_select_default(&fl, &res);
323 fl.fl4_src = FIB_RES_PREFSRC(res);
324 @@ -2567,6 +2606,7 @@
325 rth->fl.fl4_src == flp->fl4_src &&
327 rth->fl.oif == flp->oif &&
328 + rth->fl.fl4_gw == flp->fl4_gw &&
329 rth->fl.mark == flp->mark &&
330 !((rth->fl.fl4_tos ^ flp->fl4_tos) &
331 (IPTOS_RT_MASK | RTO_ONLINK))) {
332 @@ -3267,3 +3307,4 @@
333 EXPORT_SYMBOL(__ip_select_ident);
334 EXPORT_SYMBOL(ip_route_input);
335 EXPORT_SYMBOL(ip_route_output_key);
336 +EXPORT_SYMBOL(ip_route_input_lookup);