667-ipv6-Fixed-source-specific-default-route-handling.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From e16e888b525503be05b3aea64190e8b3bdef44d0 Mon Sep 17 00:00:00 2001
  2. From: Markus Stenberg <markus.stenberg@iki.fi>
  3. Date: Tue, 5 May 2015 13:36:59 +0300
  4. Subject: [PATCH] ipv6: Fixed source specific default route handling.
  5. If there are only IPv6 source specific default routes present, the
  6. host gets -ENETUNREACH on e.g. connect() because ip6_dst_lookup_tail
  7. calls ip6_route_output first, and given source address any, it fails,
  8. and ip6_route_get_saddr is never called.
  9. The change is to use the ip6_route_get_saddr, even if the initial
  10. ip6_route_output fails, and then doing ip6_route_output _again_ after
  11. we have appropriate source address available.
  12. Note that this is '99% fix' to the problem; a correct fix would be to
  13. do route lookups only within addrconf.c when picking a source address,
  14. and never call ip6_route_output before source address has been
  15. populated.
  16. Signed-off-by: Markus Stenberg <markus.stenberg@iki.fi>
  17. Signed-off-by: David S. Miller <davem@davemloft.net>
  18. ---
  19. net/ipv6/ip6_output.c | 39 +++++++++++++++++++++++++++++++--------
  20. net/ipv6/route.c | 5 +++--
  21. 2 files changed, 34 insertions(+), 10 deletions(-)
  22. --- a/net/ipv6/ip6_output.c
  23. +++ b/net/ipv6/ip6_output.c
  24. @@ -906,21 +906,45 @@ static int ip6_dst_lookup_tail(struct so
  25. #endif
  26. int err;
  27. - if (*dst == NULL)
  28. - *dst = ip6_route_output(net, sk, fl6);
  29. -
  30. - if ((err = (*dst)->error))
  31. - goto out_err_release;
  32. + /* The correct way to handle this would be to do
  33. + * ip6_route_get_saddr, and then ip6_route_output; however,
  34. + * the route-specific preferred source forces the
  35. + * ip6_route_output call _before_ ip6_route_get_saddr.
  36. + *
  37. + * In source specific routing (no src=any default route),
  38. + * ip6_route_output will fail given src=any saddr, though, so
  39. + * that's why we try it again later.
  40. + */
  41. + if (ipv6_addr_any(&fl6->saddr) && (!*dst || !(*dst)->error)) {
  42. + struct rt6_info *rt;
  43. + bool had_dst = *dst != NULL;
  44. - if (ipv6_addr_any(&fl6->saddr)) {
  45. - struct rt6_info *rt = (struct rt6_info *) *dst;
  46. + if (!had_dst)
  47. + *dst = ip6_route_output(net, sk, fl6);
  48. + rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
  49. err = ip6_route_get_saddr(net, rt, &fl6->daddr,
  50. sk ? inet6_sk(sk)->srcprefs : 0,
  51. &fl6->saddr);
  52. if (err)
  53. goto out_err_release;
  54. +
  55. + /* If we had an erroneous initial result, pretend it
  56. + * never existed and let the SA-enabled version take
  57. + * over.
  58. + */
  59. + if (!had_dst && (*dst)->error) {
  60. + dst_release(*dst);
  61. + *dst = NULL;
  62. + }
  63. }
  64. + if (!*dst)
  65. + *dst = ip6_route_output(net, sk, fl6);
  66. +
  67. + err = (*dst)->error;
  68. + if (err)
  69. + goto out_err_release;
  70. +
  71. #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
  72. /*
  73. * Here if the dst entry we've looked up
  74. --- a/net/ipv6/route.c
  75. +++ b/net/ipv6/route.c
  76. @@ -2184,9 +2184,10 @@ int ip6_route_get_saddr(struct net *net,
  77. unsigned int prefs,
  78. struct in6_addr *saddr)
  79. {
  80. - struct inet6_dev *idev = ip6_dst_idev((struct dst_entry *)rt);
  81. + struct inet6_dev *idev =
  82. + rt ? ip6_dst_idev((struct dst_entry *)rt) : NULL;
  83. int err = 0;
  84. - if (rt->rt6i_prefsrc.plen)
  85. + if (rt && rt->rt6i_prefsrc.plen)
  86. *saddr = rt->rt6i_prefsrc.addr;
  87. else
  88. err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,