201-multiple_default_gateways.patch 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. diff -urN linux-2.6.21.1.old/include/linux/rtnetlink.h linux-2.6.21.1.dev/include/linux/rtnetlink.h
  2. --- linux-2.6.21.1.old/include/linux/rtnetlink.h 2007-04-27 23:49:26.000000000 +0200
  3. +++ linux-2.6.21.1.dev/include/linux/rtnetlink.h 2007-05-26 20:46:11.883321560 +0200
  4. @@ -293,6 +293,8 @@
  5. #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
  6. #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
  7. #define RTNH_F_ONLINK 4 /* Gateway is forced on link */
  8. +#define RTNH_F_SUSPECT 8 /* We don't know the real state */
  9. +#define RTNH_F_BADSTATE (RTNH_F_DEAD | RTNH_F_SUSPECT)
  10. /* Macros to handle hexthops */
  11. diff -urN linux-2.6.21.1.old/include/net/flow.h linux-2.6.21.1.dev/include/net/flow.h
  12. --- linux-2.6.21.1.old/include/net/flow.h 2007-04-27 23:49:26.000000000 +0200
  13. +++ linux-2.6.21.1.dev/include/net/flow.h 2007-05-26 20:46:11.922315632 +0200
  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. diff -urN linux-2.6.21.1.old/net/ipv4/route.c linux-2.6.21.1.dev/net/ipv4/route.c
  32. --- linux-2.6.21.1.old/net/ipv4/route.c 2007-04-27 23:49:26.000000000 +0200
  33. +++ linux-2.6.21.1.dev/net/ipv4/route.c 2007-05-26 20:46:11.967308792 +0200
  34. @@ -1208,6 +1208,7 @@
  35. /* Gateway is different ... */
  36. rt->rt_gateway = new_gw;
  37. + if (rt->fl.fl4_gw) rt->fl.fl4_gw = new_gw;
  38. /* Redirect received -> path was valid */
  39. dst_confirm(&rth->u.dst);
  40. @@ -1643,6 +1644,7 @@
  41. rth->fl.fl4_tos = tos;
  42. rth->fl.mark = skb->mark;
  43. rth->fl.fl4_src = saddr;
  44. + rth->fl.fl4_lsrc = 0;
  45. rth->rt_src = saddr;
  46. #ifdef CONFIG_NET_CLS_ROUTE
  47. rth->u.dst.tclassid = itag;
  48. @@ -1653,6 +1655,7 @@
  49. dev_hold(rth->u.dst.dev);
  50. rth->idev = in_dev_get(rth->u.dst.dev);
  51. rth->fl.oif = 0;
  52. + rth->fl.fl4_gw = 0;
  53. rth->rt_gateway = daddr;
  54. rth->rt_spec_dst= spec_dst;
  55. rth->rt_type = RTN_MULTICAST;
  56. @@ -1716,7 +1719,7 @@
  57. static inline int __mkroute_input(struct sk_buff *skb,
  58. struct fib_result* res,
  59. struct in_device *in_dev,
  60. - __be32 daddr, __be32 saddr, u32 tos,
  61. + __be32 daddr, __be32 saddr, u32 tos, u32 lsrc,
  62. struct rtable **result)
  63. {
  64. @@ -1751,6 +1754,7 @@
  65. flags |= RTCF_DIRECTSRC;
  66. if (out_dev == in_dev && err && !(flags & (RTCF_NAT | RTCF_MASQ)) &&
  67. + !lsrc &&
  68. (IN_DEV_SHARED_MEDIA(out_dev) ||
  69. inet_addr_onlink(out_dev, saddr, FIB_RES_GW(*res))))
  70. flags |= RTCF_DOREDIRECT;
  71. @@ -1788,6 +1792,7 @@
  72. rth->fl.mark = skb->mark;
  73. rth->fl.fl4_src = saddr;
  74. rth->rt_src = saddr;
  75. + rth->fl.fl4_lsrc = lsrc;
  76. rth->rt_gateway = daddr;
  77. rth->rt_iif =
  78. rth->fl.iif = in_dev->dev->ifindex;
  79. @@ -1795,6 +1800,7 @@
  80. dev_hold(rth->u.dst.dev);
  81. rth->idev = in_dev_get(rth->u.dst.dev);
  82. rth->fl.oif = 0;
  83. + rth->fl.fl4_gw = 0;
  84. rth->rt_spec_dst= spec_dst;
  85. rth->u.dst.input = ip_forward;
  86. @@ -1816,19 +1822,21 @@
  87. struct fib_result* res,
  88. const struct flowi *fl,
  89. struct in_device *in_dev,
  90. - __be32 daddr, __be32 saddr, u32 tos)
  91. + __be32 daddr, __be32 saddr, u32 tos,
  92. + u32 lsrc)
  93. {
  94. struct rtable* rth = NULL;
  95. int err;
  96. unsigned hash;
  97. + fib_select_default(fl, res);
  98. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  99. - if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
  100. + if (res->fi && res->fi->fib_nhs > 1)
  101. fib_select_multipath(fl, res);
  102. #endif
  103. /* create a routing cache entry */
  104. - err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, &rth);
  105. + err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos, lsrc, &rth);
  106. if (err)
  107. return err;
  108. @@ -1841,7 +1849,8 @@
  109. struct fib_result* res,
  110. const struct flowi *fl,
  111. struct in_device *in_dev,
  112. - __be32 daddr, __be32 saddr, u32 tos)
  113. + __be32 daddr, __be32 saddr, u32 tos,
  114. + u32 lsrc)
  115. {
  116. #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
  117. struct rtable* rth = NULL, *rtres;
  118. @@ -1857,7 +1866,7 @@
  119. /* distinguish between multipath and singlepath */
  120. if (hopcount < 2)
  121. return ip_mkroute_input_def(skb, res, fl, in_dev, daddr,
  122. - saddr, tos);
  123. + saddr, tos, 0);
  124. /* add all alternatives to the routing cache */
  125. for (hop = 0; hop < hopcount; hop++) {
  126. @@ -1869,7 +1878,7 @@
  127. /* create a routing cache entry */
  128. err = __mkroute_input(skb, res, in_dev, daddr, saddr, tos,
  129. - &rth);
  130. + 0, &rth);
  131. if (err)
  132. return err;
  133. @@ -1889,7 +1898,7 @@
  134. skb->dst = &rtres->u.dst;
  135. return err;
  136. #else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
  137. - return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
  138. + return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos, lsrc);
  139. #endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
  140. }
  141. @@ -1905,18 +1914,18 @@
  142. */
  143. static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
  144. - u8 tos, struct net_device *dev)
  145. + u8 tos, struct net_device *dev, u32 lsrc)
  146. {
  147. struct fib_result res;
  148. struct in_device *in_dev = in_dev_get(dev);
  149. struct flowi fl = { .nl_u = { .ip4_u =
  150. { .daddr = daddr,
  151. - .saddr = saddr,
  152. + .saddr = lsrc ? : saddr,
  153. .tos = tos,
  154. .scope = RT_SCOPE_UNIVERSE,
  155. } },
  156. .mark = skb->mark,
  157. - .iif = dev->ifindex };
  158. + .iif = lsrc? loopback_dev.ifindex : dev->ifindex };
  159. unsigned flags = 0;
  160. u32 itag = 0;
  161. struct rtable * rth;
  162. @@ -1949,6 +1958,12 @@
  163. if (BADCLASS(daddr) || ZERONET(daddr) || LOOPBACK(daddr))
  164. goto martian_destination;
  165. + if (lsrc) {
  166. + if (MULTICAST(lsrc) || BADCLASS(lsrc) ||
  167. + ZERONET(lsrc) || LOOPBACK(lsrc))
  168. + goto e_inval;
  169. + }
  170. +
  171. /*
  172. * Now we are ready to route packet.
  173. */
  174. @@ -1958,6 +1973,10 @@
  175. goto no_route;
  176. }
  177. free_res = 1;
  178. + if (lsrc && res.type != RTN_UNICAST && res.type != RTN_NAT)
  179. + goto e_inval;
  180. + fl.iif = dev->ifindex;
  181. + fl.fl4_src = saddr;
  182. RT_CACHE_STAT_INC(in_slow_tot);
  183. @@ -1982,7 +2001,7 @@
  184. if (res.type != RTN_UNICAST)
  185. goto martian_destination;
  186. - err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos);
  187. + err = ip_mkroute_input(skb, &res, &fl, in_dev, daddr, saddr, tos, lsrc);
  188. if (err == -ENOBUFS)
  189. goto e_nobufs;
  190. if (err == -EINVAL)
  191. @@ -1997,6 +2016,8 @@
  192. brd_input:
  193. if (skb->protocol != htons(ETH_P_IP))
  194. goto e_inval;
  195. + if (lsrc)
  196. + goto e_inval;
  197. if (ZERONET(saddr))
  198. spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK);
  199. @@ -2037,6 +2058,7 @@
  200. rth->u.dst.dev = &loopback_dev;
  201. dev_hold(rth->u.dst.dev);
  202. rth->idev = in_dev_get(rth->u.dst.dev);
  203. + rth->fl.fl4_gw = 0;
  204. rth->rt_gateway = daddr;
  205. rth->rt_spec_dst= spec_dst;
  206. rth->u.dst.input= ip_local_deliver;
  207. @@ -2086,8 +2108,9 @@
  208. goto e_inval;
  209. }
  210. -int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
  211. - u8 tos, struct net_device *dev)
  212. +static inline int
  213. +ip_route_input_cached(struct sk_buff *skb, __be32 daddr, __be32 saddr,
  214. + u8 tos, struct net_device *dev, u32 lsrc)
  215. {
  216. struct rtable * rth;
  217. unsigned hash;
  218. @@ -2102,6 +2125,7 @@
  219. if (rth->fl.fl4_dst == daddr &&
  220. rth->fl.fl4_src == saddr &&
  221. rth->fl.iif == iif &&
  222. + rth->fl.fl4_lsrc == lsrc &&
  223. rth->fl.oif == 0 &&
  224. rth->fl.mark == skb->mark &&
  225. rth->fl.fl4_tos == tos) {
  226. @@ -2148,7 +2172,19 @@
  227. rcu_read_unlock();
  228. return -EINVAL;
  229. }
  230. - return ip_route_input_slow(skb, daddr, saddr, tos, dev);
  231. + return ip_route_input_slow(skb, daddr, saddr, tos, dev, lsrc);
  232. +}
  233. +
  234. +int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr,
  235. + u8 tos, struct net_device *dev)
  236. +{
  237. + return ip_route_input_cached(skb, daddr, saddr, tos, dev, 0);
  238. +}
  239. +
  240. +int ip_route_input_lookup(struct sk_buff *skb, u32 daddr, u32 saddr,
  241. + u8 tos, struct net_device *dev, u32 lsrc)
  242. +{
  243. + return ip_route_input_cached(skb, daddr, saddr, tos, dev, lsrc);
  244. }
  245. static inline int __mkroute_output(struct rtable **result,
  246. @@ -2227,6 +2263,7 @@
  247. rth->fl.fl4_tos = tos;
  248. rth->fl.fl4_src = oldflp->fl4_src;
  249. rth->fl.oif = oldflp->oif;
  250. + rth->fl.fl4_gw = oldflp->fl4_gw;
  251. rth->fl.mark = oldflp->mark;
  252. rth->rt_dst = fl->fl4_dst;
  253. rth->rt_src = fl->fl4_src;
  254. @@ -2367,6 +2404,7 @@
  255. struct flowi fl = { .nl_u = { .ip4_u =
  256. { .daddr = oldflp->fl4_dst,
  257. .saddr = oldflp->fl4_src,
  258. + .gw = oldflp->fl4_gw,
  259. .tos = tos & IPTOS_RT_MASK,
  260. .scope = ((tos & RTO_ONLINK) ?
  261. RT_SCOPE_LINK :
  262. @@ -2470,6 +2508,7 @@
  263. dev_out = &loopback_dev;
  264. dev_hold(dev_out);
  265. fl.oif = loopback_dev.ifindex;
  266. + fl.fl4_gw = 0;
  267. res.type = RTN_LOCAL;
  268. flags |= RTCF_LOCAL;
  269. goto make_route;
  270. @@ -2477,7 +2516,7 @@
  271. if (fib_lookup(&fl, &res)) {
  272. res.fi = NULL;
  273. - if (oldflp->oif) {
  274. + if (oldflp->oif && dev_out->flags & IFF_UP) {
  275. /* Apparently, routing tables are wrong. Assume,
  276. that the destination is on link.
  277. @@ -2517,6 +2556,7 @@
  278. dev_out = &loopback_dev;
  279. dev_hold(dev_out);
  280. fl.oif = dev_out->ifindex;
  281. + fl.fl4_gw = 0;
  282. if (res.fi)
  283. fib_info_put(res.fi);
  284. res.fi = NULL;
  285. @@ -2524,13 +2564,12 @@
  286. goto make_route;
  287. }
  288. + if (res.type == RTN_UNICAST)
  289. + fib_select_default(&fl, &res);
  290. #ifdef CONFIG_IP_ROUTE_MULTIPATH
  291. - if (res.fi->fib_nhs > 1 && fl.oif == 0)
  292. + if (res.fi->fib_nhs > 1)
  293. fib_select_multipath(&fl, &res);
  294. - else
  295. #endif
  296. - if (!res.prefixlen && res.type == RTN_UNICAST && !fl.oif)
  297. - fib_select_default(&fl, &res);
  298. if (!fl.fl4_src)
  299. fl.fl4_src = FIB_RES_PREFSRC(res);
  300. @@ -2567,6 +2606,7 @@
  301. rth->fl.fl4_src == flp->fl4_src &&
  302. rth->fl.iif == 0 &&
  303. rth->fl.oif == flp->oif &&
  304. + rth->fl.fl4_gw == flp->fl4_gw &&
  305. rth->fl.mark == flp->mark &&
  306. !((rth->fl.fl4_tos ^ flp->fl4_tos) &
  307. (IPTOS_RT_MASK | RTO_ONLINK))) {
  308. @@ -3271,3 +3311,4 @@
  309. EXPORT_SYMBOL(__ip_select_ident);
  310. EXPORT_SYMBOL(ip_route_input);
  311. EXPORT_SYMBOL(ip_route_output_key);
  312. +EXPORT_SYMBOL(ip_route_input_lookup);