add proper email addresses to the comment headers
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.23 / 201-multiple_default_gateways.patch
1 Index: linux-2.6.23-rc6/include/linux/rtnetlink.h
2 ===================================================================
3 --- linux-2.6.23-rc6.orig/include/linux/rtnetlink.h 2007-09-21 16:23:53.000000000 +0800
4 +++ linux-2.6.23-rc6/include/linux/rtnetlink.h 2007-09-21 16:24:04.000000000 +0800
5 @@ -293,6 +293,8 @@
6 #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
7 #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
8 #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
9 +#define RTNH_F_SUSPECT 8 /* We don't know the real state */
10 +#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
11
12 /* Macros to handle hexthops */
13
14 Index: linux-2.6.23-rc6/include/net/flow.h
15 ===================================================================
16 --- linux-2.6.23-rc6.orig/include/net/flow.h 2007-09-21 16:23:53.000000000 +0800
17 +++ linux-2.6.23-rc6/include/net/flow.h 2007-09-21 16:24:04.000000000 +0800
18 @@ -19,6 +19,8 @@
19 struct {
20 __be32 daddr;
21 __be32 saddr;
22 + __u32 lsrc;
23 + __u32 gw;
24 __u8 tos;
25 __u8 scope;
26 } ip4_u;
27 @@ -43,6 +45,8 @@
28 #define fl6_flowlabel nl_u.ip6_u.flowlabel
29 #define fl4_dst nl_u.ip4_u.daddr
30 #define fl4_src nl_u.ip4_u.saddr
31 +#define fl4_lsrc nl_u.ip4_u.lsrc
32 +#define fl4_gw nl_u.ip4_u.gw
33 #define fl4_tos nl_u.ip4_u.tos
34 #define fl4_scope nl_u.ip4_u.scope
35
36 Index: linux-2.6.23-rc6/net/ipv4/route.c
37 ===================================================================
38 --- linux-2.6.23-rc6.orig/net/ipv4/route.c 2007-09-21 16:23:53.000000000 +0800
39 +++ linux-2.6.23-rc6/net/ipv4/route.c 2007-09-21 16:24:04.000000000 +0800
40 @@ -1116,6 +1116,7 @@
41
42 /* Gateway is different ... */
43 rt->rt_gateway = new_gw;
44 + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
45
46 /* Redirect received -> path was valid */
47 dst_confirm(&rth->u.dst);
48 @@ -1551,6 +1552,7 @@
49 rth->fl.fl4_tos = tos;
50 rth->fl.mark = skb->mark;
51 rth->fl.fl4_src = saddr;
52 + rth->fl.fl4_lsrc = 0;
53 rth->rt_src = saddr;
54 #ifdef CONFIG_NET_CLS_ROUTE
55 rth->u.dst.tclassid = itag;
56 @@ -1561,6 +1563,7 @@
57 dev_hold(rth->u.dst.dev);
58 rth->idev = in_dev_get(rth->u.dst.dev);
59 rth->fl.oif = 0;
60 + rth->fl.fl4_gw = 0;
61 rth->rt_gateway = daddr;
62 rth->rt_spec_dst= spec_dst;
63 rth->rt_type = RTN_MULTICAST;
64 @@ -1624,7 +1627,7 @@
65 static inline int __mkroute_input(struct sk_buff *skb,
66 struct fib_result* res,
67 struct in_device *in_dev,
68 - __be32 daddr, __be32 saddr, u32 tos,
69 + __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
70 struct rtable **result)
71 {
72
73 @@ -1659,6 +1662,7 @@
74 flags |= RTCF_DIRECTSRC;
75
76 if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
77 + !lsrc &&
78 (IN_DEV_SHARED_MEDIA(out_dev) ||
79 inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
80 flags |= RTCF_DOREDIRECT;
81 @@ -1692,6 +1696,7 @@
82 rth->fl.mark = skb->mark;
83 rth->fl.fl4_src = saddr;
84 rth->rt_src = saddr;
85 + rth->fl.fl4_lsrc = lsrc;
86 rth->rt_gateway = daddr;
87 rth->rt_iif =
88 rth->fl.iif = in_dev->dev->ifindex;
89 @@ -1699,6 +1704,7 @@
90 dev_hold(rth->u.dst.dev);
91 rth->idev = in_dev_get(rth->u.dst.dev);
92 rth->fl.oif = 0;
93 + rth->fl.fl4_gw = 0;
94 rth->rt_spec_dst= spec_dst;
95
96 rth->u.dst.input = ip_forward;
97 @@ -1720,19 +1726,21 @@
98 struct fib_result* res,
99 const struct flowi *fl,
100 struct in_device *in_dev,
101 - __be32 daddr, __be32 saddr, u32 tos)
102 + __be32 daddr, __be32 saddr, u32 tos,
103 + u32 lsrc)
104 {
105 struct rtable* rth = NULL;
106 int err;
107 unsigned hash;
108
109 + fib_select_default(fl, res);
110 #ifdef CONFIG_IP_ROUTE_MULTIPATH
111 - if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
112 + if (res->fi && res->fi->fib_nhs > 1)
113 fib_select_multipath(fl, res);
114 #endif
115
116 /* create a routing cache entry */
117 - err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
118 + err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
119 if (err)
120 return err;
121
122 @@ -1752,18 +1760,18 @@
123 */
124
125 static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
126 - u8 tos, struct net_device *dev)
127 + u8 tos, struct net_device *dev, u32 lsrc)
128 {
129 struct fib_result res;
130 struct in_device *in_dev = in_dev_get(dev);
131 struct flowi fl = { .nl_u = { .ip4_u =
132 { .daddr = daddr,
133 - .saddr = saddr,
134 + .saddr = lsrc ? : saddr,
135 .tos = tos,
136 .scope = RT_SCOPE_UNIVERSE,
137 } },
138 .mark = skb->mark,
139 - .iif = dev->ifindex };
140 + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
141 unsigned flags = 0;
142 u32 itag = 0;
143 struct rtable * rth;
144 @@ -1796,6 +1804,12 @@
145 if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
146 goto martian_destination;
147
148 + if (lsrc) {
149 + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
150 + ZERONET(lsrc) || LOOPBACK(lsrc))
151 + goto e_inval;
152 + }
153 +
154 /*
155 * Now we are ready to route packet.
156 */
157 @@ -1805,6 +1819,10 @@
158 goto no_route;
159 }
160 free_res = 1;
161 + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
162 + goto e_inval;
163 + fl.iif = dev->ifindex;
164 + fl.fl4_src = saddr;
165
166 RT_CACHE_STAT_INC(in_slow_tot);
167
168 @@ -1829,7 +1847,7 @@
169 if (res.type != RTN_UNICAST)
170 goto martian_destination;
171
172 - err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
173 + err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
174 if (err == -ENOBUFS)
175 goto e_nobufs;
176 if (err == -EINVAL)
177 @@ -1844,6 +1862,8 @@
178 brd_input:
179 if (skb->protocol != htons(ETH_P_IP))
180 goto e_inval;
181 + if (lsrc)
182 + goto e_inval;
183
184 if (ZERONET(saddr))
185 spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
186 @@ -1884,6 +1904,7 @@
187 rth->u.dst.dev = &loopback_dev;
188 dev_hold(rth->u.dst.dev);
189 rth->idev = in_dev_get(rth->u.dst.dev);
190 + rth->fl.fl4_gw = 0;
191 rth->rt_gateway = daddr;
192 rth->rt_spec_dst= spec_dst;
193 rth->u.dst.input= ip_local_deliver;
194 @@ -1933,8 +1954,9 @@
195 goto e_inval;
196 }
197
198 -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
199 - u8 tos, struct net_device *dev)
200 +static inline int
201 +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
202 + u8 tos, struct net_device *dev, u32 lsrc)
203 {
204 struct rtable * rth;
205 unsigned hash;
206 @@ -1949,6 +1971,7 @@
207 if (rth->fl.fl4_dst == daddr &&
208 rth->fl.fl4_src == saddr &&
209 rth->fl.iif == iif &&
210 + rth->fl.fl4_lsrc == lsrc &&
211 rth->fl.oif == 0 &&
212 rth->fl.mark == skb->mark &&
213 rth->fl.fl4_tos == tos) {
214 @@ -1995,7 +2018,19 @@
215 rcu_read_unlock();
216 return -EINVAL;
217 }
218 - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
219 + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
220 +}
221 +
222 +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
223 + u8 tos, struct net_device *dev)
224 +{
225 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
226 +}
227 +
228 +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
229 + u8 tos, struct net_device *dev, u32 lsrc)
230 +{
231 + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
232 }
233
234 static inline int __mkroute_output(struct rtable **result,
235 @@ -2067,6 +2102,7 @@
236 rth->fl.fl4_tos = tos;
237 rth->fl.fl4_src = oldflp->fl4_src;
238 rth->fl.oif = oldflp->oif;
239 + rth->fl.fl4_gw = oldflp->fl4_gw;
240 rth->fl.mark = oldflp->mark;
241 rth->rt_dst = fl->fl4_dst;
242 rth->rt_src = fl->fl4_src;
243 @@ -2145,6 +2181,7 @@
244 struct flowi fl = { .nl_u = { .ip4_u =
245 { .daddr = oldflp->fl4_dst,
246 .saddr = oldflp->fl4_src,
247 + .gw = oldflp->fl4_gw,
248 .tos = tos & IPTOS_RT_MASK,
249 .scope = ((tos & RTO_ONLINK) ?
250 RT_SCOPE_LINK :
251 @@ -2248,6 +2285,7 @@
252 dev_out = &loopback_dev;
253 dev_hold(dev_out);
254 fl.oif = loopback_dev.ifindex;
255 + fl.fl4_gw = 0;
256 res.type = RTN_LOCAL;
257 flags |= RTCF_LOCAL;
258 goto make_route;
259 @@ -2255,7 +2293,7 @@
260
261 if (fib_lookup(&fl, &res)) {
262 res.fi = NULL;
263 - if (oldflp->oif) {
264 + if (oldflp->oif && dev_out->flags & IFF_UP) {
265 /* Apparently, routing tables are wrong. Assume,
266 that the destination is on link.
267
268 @@ -2295,6 +2333,7 @@
269 dev_out = &loopback_dev;
270 dev_hold(dev_out);
271 fl.oif = dev_out->ifindex;
272 + fl.fl4_gw = 0;
273 if (res.fi)
274 fib_info_put(res.fi);
275 res.fi = NULL;
276 @@ -2302,13 +2341,12 @@
277 goto make_route;
278 }
279
280 + if (res.type == RTN_UNICAST)
281 + fib_select_default(&fl, &res);
282 #ifdef CONFIG_IP_ROUTE_MULTIPATH
283 - if (res.fi->fib_nhs > 1 && fl.oif == 0)
284 + if (res.fi->fib_nhs > 1)
285 fib_select_multipath(&fl, &res);
286 - else
287 #endif
288 - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
289 - fib_select_default(&fl, &res);
290
291 if (!fl.fl4_src)
292 fl.fl4_src = FIB_RES_PREFSRC(res);
293 @@ -2345,6 +2383,7 @@
294 rth->fl.fl4_src == flp->fl4_src &&
295 rth->fl.iif == 0 &&
296 rth->fl.oif == flp->oif &&
297 + rth->fl.fl4_gw == flp->fl4_gw &&
298 rth->fl.mark == flp->mark &&
299 !((rth->fl.fl4_tos ^ flp->fl4_tos) &
300 (IPTOS_RT_MASK | RTO_ONLINK))) {
301 @@ -3034,3 +3073,4 @@
302 EXPORT_SYMBOL(__ip_select_ident);
303 EXPORT_SYMBOL(ip_route_input);
304 EXPORT_SYMBOL(ip_route_output_key);
305 +EXPORT_SYMBOL(ip_route_input_lookup);
This page took 0.075914 seconds and 5 git commands to generate.