1 diff -urN linux-2.6.21.1.old/include/linux/netfilter_ipv4/ip_nat.h linux-2.6.21.1.dev/include/linux/netfilter_ipv4/ip_nat.h
2 --- linux-2.6.21.1.old/include/linux/netfilter_ipv4/ip_nat.h 2007-04-27 23:49:26.000000000 +0200
3 +++ linux-2.6.21.1.dev/include/linux/netfilter_ipv4/ip_nat.h 2007-05-26 20:46:11.801334024 +0200
8 +/* Call input routing for SNAT-ed traffic */
9 +extern unsigned int ip_nat_route_input(unsigned int hooknum,
10 + struct sk_buff **pskb,
11 + const struct net_device *in,
12 + const struct net_device *out,
13 + int (*okfn)(struct sk_buff *));
15 /* Set up the info structure to map into this range. */
16 extern unsigned int ip_nat_setup_info(struct ip_conntrack *conntrack,
17 const struct ip_nat_range *range,
18 diff -urN linux-2.6.21.1.old/include/linux/rtnetlink.h linux-2.6.21.1.dev/include/linux/rtnetlink.h
19 --- linux-2.6.21.1.old/include/linux/rtnetlink.h 2007-04-27 23:49:26.000000000 +0200
20 +++ linux-2.6.21.1.dev/include/linux/rtnetlink.h 2007-05-26 20:46:11.883321560 +0200
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)
28 /* Macros to handle hexthops */
30 diff -urN linux-2.6.21.1.old/include/net/flow.h linux-2.6.21.1.dev/include/net/flow.h
31 --- linux-2.6.21.1.old/include/net/flow.h 2007-04-27 23:49:26.000000000 +0200
32 +++ linux-2.6.21.1.dev/include/net/flow.h 2007-05-26 20:46:11.922315632 +0200
43 #define fl6_flowlabel nl_u.ip6_u.flowlabel
44 #define fl4_dst nl_u.ip4_u.daddr
45 #define fl4_src nl_u.ip4_u.saddr
46 +#define fl4_lsrc nl_u.ip4_u.lsrc
47 +#define fl4_gw nl_u.ip4_u.gw
48 #define fl4_tos nl_u.ip4_u.tos
49 #define fl4_scope nl_u.ip4_u.scope
51 diff -urN linux-2.6.21.1.old/net/ipv4/route.c linux-2.6.21.1.dev/net/ipv4/route.c
52 --- linux-2.6.21.1.old/net/ipv4/route.c 2007-04-27 23:49:26.000000000 +0200
53 +++ linux-2.6.21.1.dev/net/ipv4/route.c 2007-05-26 20:46:11.967308792 +0200
56 /* Gateway is different ... */
57 rt->rt_gateway = new_gw;
58 + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
60 /* Redirect received -> path was valid */
61 dst_confirm(&rth->u.dst);
63 rth->fl.fl4_tos = tos;
64 rth->fl.mark = skb->mark;
65 rth->fl.fl4_src = saddr;
66 + rth->fl.fl4_lsrc = 0;
68 #ifdef CONFIG_NET_CLS_ROUTE
69 rth->u.dst.tclassid = itag;
71 dev_hold(rth->u.dst.dev);
72 rth->idev = in_dev_get(rth->u.dst.dev);
75 rth->rt_gateway = daddr;
76 rth->rt_spec_dst= spec_dst;
77 rth->rt_type = RTN_MULTICAST;
79 static inline int __mkroute_input(struct sk_buff *skb,
80 struct fib_result* res,
81 struct in_device *in_dev,
82 - __be32 daddr, __be32 saddr, u32 tos,
83 + __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
84 struct rtable **result)
88 flags |= RTCF_DIRECTSRC;
90 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
92 (IN_DEV_SHARED_MEDIA(out_dev) ||
93 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
94 flags |= RTCF_DOREDIRECT;
96 rth->fl.mark = skb->mark;
97 rth->fl.fl4_src = saddr;
99 + rth->fl.fl4_lsrc = lsrc;
100 rth->rt_gateway = daddr;
102 rth->fl.iif = in_dev->dev->ifindex;
103 @@ -1795,6 +1800,7 @@
104 dev_hold(rth->u.dst.dev);
105 rth->idev = in_dev_get(rth->u.dst.dev);
107 + rth->fl.fl4_gw = 0;
108 rth->rt_spec_dst= spec_dst;
110 rth->u.dst.input = ip_forward;
111 @@ -1816,19 +1822,21 @@
112 struct fib_result* res,
113 const struct flowi *fl,
114 struct in_device *in_dev,
115 - __be32 daddr, __be32 saddr, u32 tos)
116 + __be32 daddr, __be32 saddr, u32 tos,
119 struct rtable* rth = NULL;
123 + fib_select_default(fl, res);
124 #ifdef CONFIG_IP_ROUTE_MULTIPATH
125 - if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
126 + if (res->fi && res->fi->fib_nhs > 1)
127 fib_select_multipath(fl, res);
130 /* create a routing cache entry */
131 - err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
132 + err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
136 @@ -1841,7 +1849,8 @@
137 struct fib_result* res,
138 const struct flowi *fl,
139 struct in_device *in_dev,
140 - __be32 daddr, __be32 saddr, u32 tos)
141 + __be32 daddr, __be32 saddr, u32 tos,
144 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
145 struct rtable* rth = NULL, *rtres;
146 @@ -1857,7 +1866,7 @@
147 /* distinguish between multipath and singlepath */
149 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
153 /* add all alternatives to the routing cache */
154 for (hop = 0; hop < hopcount; hop++) {
155 @@ -1869,7 +1878,7 @@
157 /* create a routing cache entry */
158 err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
164 @@ -1889,7 +1898,7 @@
165 skb->dst = &rtres->u.dst;
167 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
168 - return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
169 + return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos, lsrc);
170 #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
173 @@ -1905,18 +1914,18 @@
176 static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
177 - u8 tos, struct net_device *dev)
178 + u8 tos, struct net_device *dev, u32 lsrc)
180 struct fib_result res;
181 struct in_device *in_dev = in_dev_get(dev);
182 struct flowi fl = { .nl_u = { .ip4_u =
185 + .saddr = lsrc ? : saddr,
187 .scope = RT_SCOPE_UNIVERSE,
190 - .iif = dev->ifindex };
191 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
195 @@ -1949,6 +1958,12 @@
196 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
197 goto martian_destination;
200 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
201 + ZERONET(lsrc) || LOOPBACK(lsrc))
206 * Now we are ready to route packet.
208 @@ -1958,6 +1973,10 @@
212 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
214 + fl.iif = dev->ifindex;
215 + fl.fl4_src = saddr;
217 RT_CACHE_STAT_INC(in_slow_tot);
219 @@ -1982,7 +2001,7 @@
220 if (res.type != RTN_UNICAST)
221 goto martian_destination;
223 - err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
224 + err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
228 @@ -1997,6 +2016,8 @@
230 if (skb->protocol != htons(ETH_P_IP))
236 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
237 @@ -2037,6 +2058,7 @@
238 rth->u.dst.dev = &loopback_dev;
239 dev_hold(rth->u.dst.dev);
240 rth->idev = in_dev_get(rth->u.dst.dev);
241 + rth->fl.fl4_gw = 0;
242 rth->rt_gateway = daddr;
243 rth->rt_spec_dst= spec_dst;
244 rth->u.dst.input= ip_local_deliver;
245 @@ -2086,8 +2108,9 @@
249 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
250 - u8 tos, struct net_device *dev)
252 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
253 + u8 tos, struct net_device *dev, u32 lsrc)
257 @@ -2102,6 +2125,7 @@
258 if (rth->fl.fl4_dst == daddr &&
259 rth->fl.fl4_src == saddr &&
260 rth->fl.iif == iif &&
261 + rth->fl.fl4_lsrc == lsrc &&
263 rth->fl.mark == skb->mark &&
264 rth->fl.fl4_tos == tos) {
265 @@ -2148,7 +2172,19 @@
269 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
270 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
273 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
274 + u8 tos, struct net_device *dev)
276 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
279 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
280 + u8 tos, struct net_device *dev, u32 lsrc)
282 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
285 static inline int __mkroute_output(struct rtable **result,
286 @@ -2227,6 +2263,7 @@
287 rth->fl.fl4_tos = tos;
288 rth->fl.fl4_src = oldflp->fl4_src;
289 rth->fl.oif = oldflp->oif;
290 + rth->fl.fl4_gw = oldflp->fl4_gw;
291 rth->fl.mark = oldflp->mark;
292 rth->rt_dst = fl->fl4_dst;
293 rth->rt_src = fl->fl4_src;
294 @@ -2367,6 +2404,7 @@
295 struct flowi fl = { .nl_u = { .ip4_u =
296 { .daddr = oldflp->fl4_dst,
297 .saddr = oldflp->fl4_src,
298 + .gw = oldflp->fl4_gw,
299 .tos = tos & IPTOS_RT_MASK,
300 .scope = ((tos & RTO_ONLINK) ?
302 @@ -2470,6 +2508,7 @@
303 dev_out = &loopback_dev;
305 fl.oif = loopback_dev.ifindex;
307 res.type = RTN_LOCAL;
310 @@ -2477,7 +2516,7 @@
312 if (fib_lookup(&fl, &res)) {
315 + if (oldflp->oif && dev_out->flags & IFF_UP) {
316 /* Apparently, routing tables are wrong. Assume,
317 that the destination is on link.
319 @@ -2517,6 +2556,7 @@
320 dev_out = &loopback_dev;
322 fl.oif = dev_out->ifindex;
325 fib_info_put(res.fi);
327 @@ -2524,13 +2564,12 @@
331 + if (res.type == RTN_UNICAST)
332 + fib_select_default(&fl, &res);
333 #ifdef CONFIG_IP_ROUTE_MULTIPATH
334 - if (res.fi->fib_nhs > 1 && fl.oif == 0)
335 + if (res.fi->fib_nhs > 1)
336 fib_select_multipath(&fl, &res);
339 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
340 - fib_select_default(&fl, &res);
343 fl.fl4_src = FIB_RES_PREFSRC(res);
344 @@ -2567,6 +2606,7 @@
345 rth->fl.fl4_src == flp->fl4_src &&
347 rth->fl.oif == flp->oif &&
348 + rth->fl.fl4_gw == flp->fl4_gw &&
349 rth->fl.mark == flp->mark &&
350 !((rth->fl.fl4_tos ^ flp->fl4_tos) &
351 (IPTOS_RT_MASK | RTO_ONLINK))) {
352 @@ -3199,3 +3239,4 @@
353 EXPORT_SYMBOL(__ip_select_ident);
354 EXPORT_SYMBOL(ip_route_input);
355 EXPORT_SYMBOL(ip_route_output_key);
356 +EXPORT_SYMBOL(ip_route_input_lookup);