[ar71xx] improve SoC detection
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.21 / 201-multiple_default_gateways.patch
1 Index: linux-2.6.21.7/include/linux/netfilter_ipv4/ip_nat.h
2 ===================================================================
3 --- linux-2.6.21.7.orig/include/linux/netfilter_ipv4/ip_nat.h
4 +++ linux-2.6.21.7/include/linux/netfilter_ipv4/ip_nat.h
5 @@ -64,6 +64,13 @@ struct ip_nat_info
6
7 struct ip_conntrack;
8
9 +/* Call input routing for SNAT-ed traffic */
10 +extern unsigned int ip_nat_route_input(unsigned int hooknum,
11 + struct sk_buff **pskb,
12 + const struct net_device *in,
13 + const struct net_device *out,
14 + int (*okfn)(struct sk_buff *));
15 +
16 /* Set up the info structure to map into this range. */
17 extern unsigned int ip_nat_setup_info(struct ip_conntrack *conntrack,
18 const struct ip_nat_range *range,
19 Index: linux-2.6.21.7/include/linux/rtnetlink.h
20 ===================================================================
21 --- linux-2.6.21.7.orig/include/linux/rtnetlink.h
22 +++ linux-2.6.21.7/include/linux/rtnetlink.h
23 @@ -293,6 +293,8 @@ struct rtnexthop
24 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
25 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
26 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
27 +#define RTNH_F_SUSPECT 8 /* We don't know the real state */
28 +#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
29
30 /* Macros to handle hexthops */
31
32 Index: linux-2.6.21.7/include/net/flow.h
33 ===================================================================
34 --- linux-2.6.21.7.orig/include/net/flow.h
35 +++ linux-2.6.21.7/include/net/flow.h
36 @@ -19,6 +19,8 @@ struct flowi {
37 struct {
38 __be32 daddr;
39 __be32 saddr;
40 + __u32 lsrc;
41 + __u32 gw;
42 __u8 tos;
43 __u8 scope;
44 } ip4_u;
45 @@ -43,6 +45,8 @@ struct flowi {
46 #define fl6_flowlabel nl_u.ip6_u.flowlabel
47 #define fl4_dst nl_u.ip4_u.daddr
48 #define fl4_src nl_u.ip4_u.saddr
49 +#define fl4_lsrc nl_u.ip4_u.lsrc
50 +#define fl4_gw nl_u.ip4_u.gw
51 #define fl4_tos nl_u.ip4_u.tos
52 #define fl4_scope nl_u.ip4_u.scope
53
54 Index: linux-2.6.21.7/net/ipv4/route.c
55 ===================================================================
56 --- linux-2.6.21.7.orig/net/ipv4/route.c
57 +++ linux-2.6.21.7/net/ipv4/route.c
58 @@ -1208,6 +1208,7 @@ void ip_rt_redirect(__be32 old_gw, __be3
59
60 /* Gateway is different ... */
61 rt->rt_gateway = new_gw;
62 + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
63
64 /* Redirect received -> path was valid */
65 dst_confirm(&rth->u.dst);
66 @@ -1643,6 +1644,7 @@ static int ip_route_input_mc(struct sk_b
67 rth->fl.fl4_tos = tos;
68 rth->fl.mark = skb->mark;
69 rth->fl.fl4_src = saddr;
70 + rth->fl.fl4_lsrc = 0;
71 rth->rt_src = saddr;
72 #ifdef CONFIG_NET_CLS_ROUTE
73 rth->u.dst.tclassid = itag;
74 @@ -1653,6 +1655,7 @@ static int ip_route_input_mc(struct sk_b
75 dev_hold(rth->u.dst.dev);
76 rth->idev = in_dev_get(rth->u.dst.dev);
77 rth->fl.oif = 0;
78 + rth->fl.fl4_gw = 0;
79 rth->rt_gateway = daddr;
80 rth->rt_spec_dst= spec_dst;
81 rth->rt_type = RTN_MULTICAST;
82 @@ -1716,7 +1719,7 @@ static void ip_handle_martian_source(str
83 static inline int __mkroute_input(struct sk_buff *skb,
84 struct fib_result* res,
85 struct in_device *in_dev,
86 - __be32 daddr, __be32 saddr, u32 tos,
87 + __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
88 struct rtable **result)
89 {
90
91 @@ -1751,6 +1754,7 @@ static inline int __mkroute_input(struct
92 flags |= RTCF_DIRECTSRC;
93
94 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
95 + !lsrc &&
96 (IN_DEV_SHARED_MEDIA(out_dev) ||
97 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
98 flags |= RTCF_DOREDIRECT;
99 @@ -1788,6 +1792,7 @@ static inline int __mkroute_input(struct
100 rth->fl.mark = skb->mark;
101 rth->fl.fl4_src = saddr;
102 rth->rt_src = saddr;
103 + rth->fl.fl4_lsrc = lsrc;
104 rth->rt_gateway = daddr;
105 rth->rt_iif =
106 rth->fl.iif = in_dev->dev->ifindex;
107 @@ -1795,6 +1800,7 @@ static inline int __mkroute_input(struct
108 dev_hold(rth->u.dst.dev);
109 rth->idev = in_dev_get(rth->u.dst.dev);
110 rth->fl.oif = 0;
111 + rth->fl.fl4_gw = 0;
112 rth->rt_spec_dst= spec_dst;
113
114 rth->u.dst.input = ip_forward;
115 @@ -1816,19 +1822,21 @@ static inline int ip_mkroute_input_def(s
116 struct fib_result* res,
117 const struct flowi *fl,
118 struct in_device *in_dev,
119 - __be32 daddr, __be32 saddr, u32 tos)
120 + __be32 daddr, __be32 saddr, u32 tos,
121 + u32 lsrc)
122 {
123 struct rtable* rth = NULL;
124 int err;
125 unsigned hash;
126
127 + fib_select_default(fl, res);
128 #ifdef CONFIG_IP_ROUTE_MULTIPATH
129 - if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
130 + if (res->fi && res->fi->fib_nhs > 1)
131 fib_select_multipath(fl, res);
132 #endif
133
134 /* create a routing cache entry */
135 - err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
136 + err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
137 if (err)
138 return err;
139
140 @@ -1841,7 +1849,8 @@ static inline int ip_mkroute_input(struc
141 struct fib_result* res,
142 const struct flowi *fl,
143 struct in_device *in_dev,
144 - __be32 daddr, __be32 saddr, u32 tos)
145 + __be32 daddr, __be32 saddr, u32 tos,
146 + u32 lsrc)
147 {
148 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
149 struct rtable* rth = NULL, *rtres;
150 @@ -1857,7 +1866,7 @@ static inline int ip_mkroute_input(struc
151 /* distinguish between multipath and singlepath */
152 if (hopcount < 2)
153 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
154 - saddr, tos);
155 + saddr, tos, 0);
156
157 /* add all alternatives to the routing cache */
158 for (hop = 0; hop < hopcount; hop++) {
159 @@ -1869,7 +1878,7 @@ static inline int ip_mkroute_input(struc
160
161 /* create a routing cache entry */
162 err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
163 - &rth);
164 + 0, &rth);
165 if (err)
166 return err;
167
168 @@ -1889,7 +1898,7 @@ static inline int ip_mkroute_input(struc
169 skb->dst = &rtres->u.dst;
170 return err;
171 #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
172 - return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
173 + return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos, lsrc);
174 #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
175 }
176
177 @@ -1905,18 +1914,18 @@ static inline int ip_mkroute_input(struc
178 */
179
180 static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
181 - u8 tos, struct net_device *dev)
182 + u8 tos, struct net_device *dev, u32 lsrc)
183 {
184 struct fib_result res;
185 struct in_device *in_dev = in_dev_get(dev);
186 struct flowi fl = { .nl_u = { .ip4_u =
187 { .daddr = daddr,
188 - .saddr = saddr,
189 + .saddr = lsrc ? : saddr,
190 .tos = tos,
191 .scope = RT_SCOPE_UNIVERSE,
192 } },
193 .mark = skb->mark,
194 - .iif = dev->ifindex };
195 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
196 unsigned flags = 0;
197 u32 itag = 0;
198 struct rtable * rth;
199 @@ -1949,6 +1958,12 @@ static int ip_route_input_slow(struct sk
200 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
201 goto martian_destination;
202
203 + if (lsrc) {
204 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
205 + ZERONET(lsrc) || LOOPBACK(lsrc))
206 + goto e_inval;
207 + }
208 +
209 /*
210 * Now we are ready to route packet.
211 */
212 @@ -1958,6 +1973,10 @@ static int ip_route_input_slow(struct sk
213 goto no_route;
214 }
215 free_res = 1;
216 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
217 + goto e_inval;
218 + fl.iif = dev->ifindex;
219 + fl.fl4_src = saddr;
220
221 RT_CACHE_STAT_INC(in_slow_tot);
222
223 @@ -1982,7 +2001,7 @@ static int ip_route_input_slow(struct sk
224 if (res.type != RTN_UNICAST)
225 goto martian_destination;
226
227 - err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
228 + err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
229 if (err == -ENOBUFS)
230 goto e_nobufs;
231 if (err == -EINVAL)
232 @@ -1997,6 +2016,8 @@ out: return err;
233 brd_input:
234 if (skb->protocol != htons(ETH_P_IP))
235 goto e_inval;
236 + if (lsrc)
237 + goto e_inval;
238
239 if (ZERONET(saddr))
240 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
241 @@ -2037,6 +2058,7 @@ local_input:
242 rth->u.dst.dev = &loopback_dev;
243 dev_hold(rth->u.dst.dev);
244 rth->idev = in_dev_get(rth->u.dst.dev);
245 + rth->fl.fl4_gw = 0;
246 rth->rt_gateway = daddr;
247 rth->rt_spec_dst= spec_dst;
248 rth->u.dst.input= ip_local_deliver;
249 @@ -2086,8 +2108,9 @@ martian_source:
250 goto e_inval;
251 }
252
253 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
254 - u8 tos, struct net_device *dev)
255 +static inline int
256 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
257 + u8 tos, struct net_device *dev, u32 lsrc)
258 {
259 struct rtable * rth;
260 unsigned hash;
261 @@ -2102,6 +2125,7 @@ int ip_route_input(struct sk_buff *skb,
262 if (rth->fl.fl4_dst == daddr &&
263 rth->fl.fl4_src == saddr &&
264 rth->fl.iif == iif &&
265 + rth->fl.fl4_lsrc == lsrc &&
266 rth->fl.oif == 0 &&
267 rth->fl.mark == skb->mark &&
268 rth->fl.fl4_tos == tos) {
269 @@ -2148,7 +2172,19 @@ int ip_route_input(struct sk_buff *skb,
270 rcu_read_unlock();
271 return -EINVAL;
272 }
273 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
274 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
275 +}
276 +
277 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
278 + u8 tos, struct net_device *dev)
279 +{
280 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
281 +}
282 +
283 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
284 + u8 tos, struct net_device *dev, u32 lsrc)
285 +{
286 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
287 }
288
289 static inline int __mkroute_output(struct rtable **result,
290 @@ -2227,6 +2263,7 @@ static inline int __mkroute_output(struc
291 rth->fl.fl4_tos = tos;
292 rth->fl.fl4_src = oldflp->fl4_src;
293 rth->fl.oif = oldflp->oif;
294 + rth->fl.fl4_gw = oldflp->fl4_gw;
295 rth->fl.mark = oldflp->mark;
296 rth->rt_dst = fl->fl4_dst;
297 rth->rt_src = fl->fl4_src;
298 @@ -2367,6 +2404,7 @@ static int ip_route_output_slow(struct r
299 struct flowi fl = { .nl_u = { .ip4_u =
300 { .daddr = oldflp->fl4_dst,
301 .saddr = oldflp->fl4_src,
302 + .gw = oldflp->fl4_gw,
303 .tos = tos & IPTOS_RT_MASK,
304 .scope = ((tos & RTO_ONLINK) ?
305 RT_SCOPE_LINK :
306 @@ -2470,6 +2508,7 @@ static int ip_route_output_slow(struct r
307 dev_out = &loopback_dev;
308 dev_hold(dev_out);
309 fl.oif = loopback_dev.ifindex;
310 + fl.fl4_gw = 0;
311 res.type = RTN_LOCAL;
312 flags |= RTCF_LOCAL;
313 goto make_route;
314 @@ -2477,7 +2516,7 @@ static int ip_route_output_slow(struct r
315
316 if (fib_lookup(&fl, &res)) {
317 res.fi = NULL;
318 - if (oldflp->oif) {
319 + if (oldflp->oif && dev_out->flags & IFF_UP) {
320 /* Apparently, routing tables are wrong. Assume,
321 that the destination is on link.
322
323 @@ -2517,6 +2556,7 @@ static int ip_route_output_slow(struct r
324 dev_out = &loopback_dev;
325 dev_hold(dev_out);
326 fl.oif = dev_out->ifindex;
327 + fl.fl4_gw = 0;
328 if (res.fi)
329 fib_info_put(res.fi);
330 res.fi = NULL;
331 @@ -2524,13 +2564,12 @@ static int ip_route_output_slow(struct r
332 goto make_route;
333 }
334
335 + if (res.type == RTN_UNICAST)
336 + fib_select_default(&fl, &res);
337 #ifdef CONFIG_IP_ROUTE_MULTIPATH
338 - if (res.fi->fib_nhs > 1 && fl.oif == 0)
339 + if (res.fi->fib_nhs > 1)
340 fib_select_multipath(&fl, &res);
341 - else
342 #endif
343 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
344 - fib_select_default(&fl, &res);
345
346 if (!fl.fl4_src)
347 fl.fl4_src = FIB_RES_PREFSRC(res);
348 @@ -2567,6 +2606,7 @@ int __ip_route_output_key(struct rtable
349 rth->fl.fl4_src == flp->fl4_src &&
350 rth->fl.iif == 0 &&
351 rth->fl.oif == flp->oif &&
352 + rth->fl.fl4_gw == flp->fl4_gw &&
353 rth->fl.mark == flp->mark &&
354 !((rth->fl.fl4_tos ^ flp->fl4_tos) &
355 (IPTOS_RT_MASK | RTO_ONLINK))) {
356 @@ -3199,3 +3239,4 @@ int __init ip_rt_init(void)
357 EXPORT_SYMBOL(__ip_select_ident);
358 EXPORT_SYMBOL(ip_route_input);
359 EXPORT_SYMBOL(ip_route_output_key);
360 +EXPORT_SYMBOL(ip_route_input_lookup);
This page took 0.076209 seconds and 5 git commands to generate.