fix rootfs split partition renaming (fix by Eric L. Chen)
[openwrt.git] / target / linux / generic-2.6 / patches / 201-multiple_default_gateways.patch
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
4 @@ -64,6 +64,13 @@
5
6 struct ip_conntrack;
7
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 *));
14 +
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
21 @@ -293,6 +293,8 @@
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)
27
28 /* Macros to handle hexthops */
29
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
33 @@ -19,6 +19,8 @@
34 struct {
35 __be32 daddr;
36 __be32 saddr;
37 + __u32 lsrc;
38 + __u32 gw;
39 __u8 tos;
40 __u8 scope;
41 } ip4_u;
42 @@ -43,6 +45,8 @@
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
50
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
54 @@ -1208,6 +1208,7 @@
55
56 /* Gateway is different ... */
57 rt->rt_gateway = new_gw;
58 + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
59
60 /* Redirect received -> path was valid */
61 dst_confirm(&rth->u.dst);
62 @@ -1643,6 +1644,7 @@
63 rth->fl.fl4_tos = tos;
64 rth->fl.mark = skb->mark;
65 rth->fl.fl4_src = saddr;
66 + rth->fl.fl4_lsrc = 0;
67 rth->rt_src = saddr;
68 #ifdef CONFIG_NET_CLS_ROUTE
69 rth->u.dst.tclassid = itag;
70 @@ -1653,6 +1655,7 @@
71 dev_hold(rth->u.dst.dev);
72 rth->idev = in_dev_get(rth->u.dst.dev);
73 rth->fl.oif = 0;
74 + rth->fl.fl4_gw = 0;
75 rth->rt_gateway = daddr;
76 rth->rt_spec_dst= spec_dst;
77 rth->rt_type = RTN_MULTICAST;
78 @@ -1716,7 +1719,7 @@
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)
85 {
86
87 @@ -1751,6 +1754,7 @@
88 flags |= RTCF_DIRECTSRC;
89
90 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
91 + !lsrc &&
92 (IN_DEV_SHARED_MEDIA(out_dev) ||
93 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
94 flags |= RTCF_DOREDIRECT;
95 @@ -1788,6 +1792,7 @@
96 rth->fl.mark = skb->mark;
97 rth->fl.fl4_src = saddr;
98 rth->rt_src = saddr;
99 + rth->fl.fl4_lsrc = lsrc;
100 rth->rt_gateway = daddr;
101 rth->rt_iif =
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);
106 rth->fl.oif = 0;
107 + rth->fl.fl4_gw = 0;
108 rth->rt_spec_dst= spec_dst;
109
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,
117 + u32 lsrc)
118 {
119 struct rtable* rth = NULL;
120 int err;
121 unsigned hash;
122
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);
128 #endif
129
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);
133 if (err)
134 return err;
135
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,
142 + u32 lsrc)
143 {
144 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
145 struct rtable* rth = NULL, *rtres;
146 @@ -1857,7 +1866,7 @@
147 /* distinguish between multipath and singlepath */
148 if (hopcount < 2)
149 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
150 - saddr, tos);
151 + saddr, tos, 0);
152
153 /* add all alternatives to the routing cache */
154 for (hop = 0; hop < hopcount; hop++) {
155 @@ -1869,7 +1878,7 @@
156
157 /* create a routing cache entry */
158 err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
159 - &rth);
160 + 0, &rth);
161 if (err)
162 return err;
163
164 @@ -1889,7 +1898,7 @@
165 skb->dst = &rtres->u.dst;
166 return err;
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 */
171 }
172
173 @@ -1905,18 +1914,18 @@
174 */
175
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)
179 {
180 struct fib_result res;
181 struct in_device *in_dev = in_dev_get(dev);
182 struct flowi fl = { .nl_u = { .ip4_u =
183 { .daddr = daddr,
184 - .saddr = saddr,
185 + .saddr = lsrc ? : saddr,
186 .tos = tos,
187 .scope = RT_SCOPE_UNIVERSE,
188 } },
189 .mark = skb->mark,
190 - .iif = dev->ifindex };
191 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
192 unsigned flags = 0;
193 u32 itag = 0;
194 struct rtable * rth;
195 @@ -1949,6 +1958,12 @@
196 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
197 goto martian_destination;
198
199 + if (lsrc) {
200 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
201 + ZERONET(lsrc) || LOOPBACK(lsrc))
202 + goto e_inval;
203 + }
204 +
205 /*
206 * Now we are ready to route packet.
207 */
208 @@ -1958,6 +1973,10 @@
209 goto no_route;
210 }
211 free_res = 1;
212 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
213 + goto e_inval;
214 + fl.iif = dev->ifindex;
215 + fl.fl4_src = saddr;
216
217 RT_CACHE_STAT_INC(in_slow_tot);
218
219 @@ -1982,7 +2001,7 @@
220 if (res.type != RTN_UNICAST)
221 goto martian_destination;
222
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);
225 if (err == -ENOBUFS)
226 goto e_nobufs;
227 if (err == -EINVAL)
228 @@ -1997,6 +2016,8 @@
229 brd_input:
230 if (skb->protocol != htons(ETH_P_IP))
231 goto e_inval;
232 + if (lsrc)
233 + goto e_inval;
234
235 if (ZERONET(saddr))
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 @@
246 goto e_inval;
247 }
248
249 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
250 - u8 tos, struct net_device *dev)
251 +static inline int
252 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
253 + u8 tos, struct net_device *dev, u32 lsrc)
254 {
255 struct rtable * rth;
256 unsigned hash;
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 &&
262 rth->fl.oif == 0 &&
263 rth->fl.mark == skb->mark &&
264 rth->fl.fl4_tos == tos) {
265 @@ -2148,7 +2172,19 @@
266 rcu_read_unlock();
267 return -EINVAL;
268 }
269 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
270 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
271 +}
272 +
273 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
274 + u8 tos, struct net_device *dev)
275 +{
276 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
277 +}
278 +
279 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
280 + u8 tos, struct net_device *dev, u32 lsrc)
281 +{
282 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
283 }
284
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) ?
301 RT_SCOPE_LINK :
302 @@ -2470,6 +2508,7 @@
303 dev_out = &loopback_dev;
304 dev_hold(dev_out);
305 fl.oif = loopback_dev.ifindex;
306 + fl.fl4_gw = 0;
307 res.type = RTN_LOCAL;
308 flags |= RTCF_LOCAL;
309 goto make_route;
310 @@ -2477,7 +2516,7 @@
311
312 if (fib_lookup(&fl, &res)) {
313 res.fi = NULL;
314 - if (oldflp->oif) {
315 + if (oldflp->oif && dev_out->flags & IFF_UP) {
316 /* Apparently, routing tables are wrong. Assume,
317 that the destination is on link.
318
319 @@ -2517,6 +2556,7 @@
320 dev_out = &loopback_dev;
321 dev_hold(dev_out);
322 fl.oif = dev_out->ifindex;
323 + fl.fl4_gw = 0;
324 if (res.fi)
325 fib_info_put(res.fi);
326 res.fi = NULL;
327 @@ -2524,13 +2564,12 @@
328 goto make_route;
329 }
330
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);
337 - else
338 #endif
339 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
340 - fib_select_default(&fl, &res);
341
342 if (!fl.fl4_src)
343 fl.fl4_src = FIB_RES_PREFSRC(res);
344 @@ -2567,6 +2606,7 @@
345 rth->fl.fl4_src == flp->fl4_src &&
346 rth->fl.iif == 0 &&
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);
This page took 0.064142 seconds and 5 git commands to generate.