47d53b7f14269d84b406455ab9087edb41fd7909
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.22 / 201-multiple_default_gateways.patch
1 --- a/include/linux/rtnetlink.h
2 +++ b/include/linux/rtnetlink.h
3 @@ -293,6 +293,8 @@
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)
9
10 /* Macros to handle hexthops */
11
12 --- a/include/net/flow.h
13 +++ b/include/net/flow.h
14 @@ -19,6 +19,8 @@
15 struct {
16 __be32 daddr;
17 __be32 saddr;
18 + __u32 lsrc;
19 + __u32 gw;
20 __u8 tos;
21 __u8 scope;
22 } ip4_u;
23 @@ -43,6 +45,8 @@
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
31
32 --- a/net/ipv4/route.c
33 +++ b/net/ipv4/route.c
34 @@ -1208,6 +1208,7 @@
35
36 /* Gateway is different ... */
37 rt->rt_gateway = new_gw;
38 + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
39
40 /* Redirect received -> path was valid */
41 dst_confirm(&rth->u.dst);
42 @@ -1643,6 +1644,7 @@
43 rth->fl.fl4_tos = tos;
44 rth->fl.mark = skb->mark;
45 rth->fl.fl4_src = saddr;
46 + rth->fl.fl4_lsrc = 0;
47 rth->rt_src = saddr;
48 #ifdef CONFIG_NET_CLS_ROUTE
49 rth->u.dst.tclassid = itag;
50 @@ -1653,6 +1655,7 @@
51 dev_hold(rth->u.dst.dev);
52 rth->idev = in_dev_get(rth->u.dst.dev);
53 rth->fl.oif = 0;
54 + rth->fl.fl4_gw = 0;
55 rth->rt_gateway = daddr;
56 rth->rt_spec_dst= spec_dst;
57 rth->rt_type = RTN_MULTICAST;
58 @@ -1716,7 +1719,7 @@
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)
65 {
66
67 @@ -1751,6 +1754,7 @@
68 flags |= RTCF_DIRECTSRC;
69
70 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
71 + !lsrc &&
72 (IN_DEV_SHARED_MEDIA(out_dev) ||
73 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
74 flags |= RTCF_DOREDIRECT;
75 @@ -1788,6 +1792,7 @@
76 rth->fl.mark = skb->mark;
77 rth->fl.fl4_src = saddr;
78 rth->rt_src = saddr;
79 + rth->fl.fl4_lsrc = lsrc;
80 rth->rt_gateway = daddr;
81 rth->rt_iif =
82 rth->fl.iif = in_dev->dev->ifindex;
83 @@ -1795,6 +1800,7 @@
84 dev_hold(rth->u.dst.dev);
85 rth->idev = in_dev_get(rth->u.dst.dev);
86 rth->fl.oif = 0;
87 + rth->fl.fl4_gw = 0;
88 rth->rt_spec_dst= spec_dst;
89
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,
97 + u32 lsrc)
98 {
99 struct rtable* rth = NULL;
100 int err;
101 unsigned hash;
102
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);
108 #endif
109
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);
113 if (err)
114 return err;
115
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,
122 + u32 lsrc)
123 {
124 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
125 struct rtable* rth = NULL, *rtres;
126 @@ -1857,7 +1866,7 @@
127 /* distinguish between multipath and singlepath */
128 if (hopcount < 2)
129 return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
130 - saddr, tos);
131 + saddr, tos, 0);
132
133 /* add all alternatives to the routing cache */
134 for (hop = 0; hop < hopcount; hop++) {
135 @@ -1869,7 +1878,7 @@
136
137 /* create a routing cache entry */
138 err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
139 - &rth);
140 + 0, &rth);
141 if (err)
142 return err;
143
144 @@ -1889,7 +1898,7 @@
145 skb->dst = &rtres->u.dst;
146 return err;
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 */
151 }
152
153 @@ -1905,18 +1914,18 @@
154 */
155
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)
159 {
160 struct fib_result res;
161 struct in_device *in_dev = in_dev_get(dev);
162 struct flowi fl = { .nl_u = { .ip4_u =
163 { .daddr = daddr,
164 - .saddr = saddr,
165 + .saddr = lsrc ? : saddr,
166 .tos = tos,
167 .scope = RT_SCOPE_UNIVERSE,
168 } },
169 .mark = skb->mark,
170 - .iif = dev->ifindex };
171 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
172 unsigned flags = 0;
173 u32 itag = 0;
174 struct rtable * rth;
175 @@ -1949,6 +1958,12 @@
176 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
177 goto martian_destination;
178
179 + if (lsrc) {
180 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
181 + ZERONET(lsrc) || LOOPBACK(lsrc))
182 + goto e_inval;
183 + }
184 +
185 /*
186 * Now we are ready to route packet.
187 */
188 @@ -1958,6 +1973,10 @@
189 goto no_route;
190 }
191 free_res = 1;
192 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
193 + goto e_inval;
194 + fl.iif = dev->ifindex;
195 + fl.fl4_src = saddr;
196
197 RT_CACHE_STAT_INC(in_slow_tot);
198
199 @@ -1982,7 +2001,7 @@
200 if (res.type != RTN_UNICAST)
201 goto martian_destination;
202
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);
205 if (err == -ENOBUFS)
206 goto e_nobufs;
207 if (err == -EINVAL)
208 @@ -1997,6 +2016,8 @@
209 brd_input:
210 if (skb->protocol != htons(ETH_P_IP))
211 goto e_inval;
212 + if (lsrc)
213 + goto e_inval;
214
215 if (ZERONET(saddr))
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 @@
226 goto e_inval;
227 }
228
229 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
230 - u8 tos, struct net_device *dev)
231 +static inline int
232 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
233 + u8 tos, struct net_device *dev, u32 lsrc)
234 {
235 struct rtable * rth;
236 unsigned hash;
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 &&
242 rth->fl.oif == 0 &&
243 rth->fl.mark == skb->mark &&
244 rth->fl.fl4_tos == tos) {
245 @@ -2148,7 +2172,19 @@
246 rcu_read_unlock();
247 return -EINVAL;
248 }
249 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
250 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
251 +}
252 +
253 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
254 + u8 tos, struct net_device *dev)
255 +{
256 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
257 +}
258 +
259 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
260 + u8 tos, struct net_device *dev, u32 lsrc)
261 +{
262 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
263 }
264
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) ?
281 RT_SCOPE_LINK :
282 @@ -2470,6 +2508,7 @@
283 dev_out = &loopback_dev;
284 dev_hold(dev_out);
285 fl.oif = loopback_dev.ifindex;
286 + fl.fl4_gw = 0;
287 res.type = RTN_LOCAL;
288 flags |= RTCF_LOCAL;
289 goto make_route;
290 @@ -2477,7 +2516,7 @@
291
292 if (fib_lookup(&fl, &res)) {
293 res.fi = NULL;
294 - if (oldflp->oif) {
295 + if (oldflp->oif && dev_out->flags & IFF_UP) {
296 /* Apparently, routing tables are wrong. Assume,
297 that the destination is on link.
298
299 @@ -2517,6 +2556,7 @@
300 dev_out = &loopback_dev;
301 dev_hold(dev_out);
302 fl.oif = dev_out->ifindex;
303 + fl.fl4_gw = 0;
304 if (res.fi)
305 fib_info_put(res.fi);
306 res.fi = NULL;
307 @@ -2524,13 +2564,12 @@
308 goto make_route;
309 }
310
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);
317 - else
318 #endif
319 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
320 - fib_select_default(&fl, &res);
321
322 if (!fl.fl4_src)
323 fl.fl4_src = FIB_RES_PREFSRC(res);
324 @@ -2567,6 +2606,7 @@
325 rth->fl.fl4_src == flp->fl4_src &&
326 rth->fl.iif == 0 &&
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);
This page took 0.074675 seconds and 3 git commands to generate.