You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.9 KiB

  1. From c9d7f8c0126b7b078b06f36096a2b3bbbc1f63b4 Mon Sep 17 00:00:00 2001
  2. From: Stephen Worley <sworley@cumulusnetworks.com>
  3. Date: Tue, 24 Mar 2020 17:10:08 -0400
  4. Subject: [PATCH 1/2] zebra: abstract route src determiniation into func
  5. Abstraction the route src determination from a nexthop in the
  6. netlink code into a function for both singlepath and mutlipath
  7. to call.
  8. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
  9. (cherry picked from commit 762288f50f5fa29512864fcc7814be83e1b58ff4)
  10. ---
  11. zebra/rt_netlink.c | 81 ++++++++++++++++------------------------------
  12. 1 file changed, 28 insertions(+), 53 deletions(-)
  13. diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
  14. index 705536595b..dcaf2155f0 100644
  15. --- a/zebra/rt_netlink.c
  16. +++ b/zebra/rt_netlink.c
  17. @@ -1513,6 +1513,30 @@ static int netlink_neigh_update(int cmd, int ifindex, uint32_t addr, char *lla,
  18. 0);
  19. }
  20. +static bool nexthop_set_src(const struct nexthop *nexthop, int family,
  21. + union g_addr *src)
  22. +{
  23. + if (family == AF_INET) {
  24. + if (nexthop->rmap_src.ipv4.s_addr != INADDR_ANY) {
  25. + src->ipv4 = nexthop->rmap_src.ipv4;
  26. + return true;
  27. + } else if (nexthop->src.ipv4.s_addr != INADDR_ANY) {
  28. + src->ipv4 = nexthop->src.ipv4;
  29. + return true;
  30. + }
  31. + } else if (family == AF_INET6) {
  32. + if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->rmap_src.ipv6)) {
  33. + src->ipv6 = nexthop->rmap_src.ipv6;
  34. + return true;
  35. + } else if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->src.ipv6)) {
  36. + src->ipv6 = nexthop->src.ipv6;
  37. + return true;
  38. + }
  39. + }
  40. +
  41. + return false;
  42. +}
  43. +
  44. /*
  45. * Routing table change via netlink interface, using a dataplane context object
  46. */
  47. @@ -1523,7 +1547,7 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
  48. unsigned int nexthop_num;
  49. int family;
  50. const char *routedesc;
  51. - int setsrc = 0;
  52. + bool setsrc = false;
  53. union g_addr src;
  54. const struct prefix *p, *src_p;
  55. uint32_t table_id;
  56. @@ -1689,32 +1713,8 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
  57. if (setsrc)
  58. continue;
  59. - if (family == AF_INET) {
  60. - if (nexthop->rmap_src.ipv4.s_addr
  61. - != 0) {
  62. - src.ipv4 =
  63. - nexthop->rmap_src.ipv4;
  64. - setsrc = 1;
  65. - } else if (nexthop->src.ipv4.s_addr
  66. - != 0) {
  67. - src.ipv4 =
  68. - nexthop->src.ipv4;
  69. - setsrc = 1;
  70. - }
  71. - } else if (family == AF_INET6) {
  72. - if (!IN6_IS_ADDR_UNSPECIFIED(
  73. - &nexthop->rmap_src.ipv6)) {
  74. - src.ipv6 =
  75. - nexthop->rmap_src.ipv6;
  76. - setsrc = 1;
  77. - } else if (
  78. - !IN6_IS_ADDR_UNSPECIFIED(
  79. - &nexthop->src.ipv6)) {
  80. - src.ipv6 =
  81. - nexthop->src.ipv6;
  82. - setsrc = 1;
  83. - }
  84. - }
  85. + setsrc = nexthop_set_src(nexthop, family, &src);
  86. +
  87. continue;
  88. }
  89. @@ -1757,32 +1757,7 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
  90. if (setsrc)
  91. continue;
  92. - if (family == AF_INET) {
  93. - if (nexthop->rmap_src.ipv4.s_addr
  94. - != 0) {
  95. - src.ipv4 =
  96. - nexthop->rmap_src.ipv4;
  97. - setsrc = 1;
  98. - } else if (nexthop->src.ipv4.s_addr
  99. - != 0) {
  100. - src.ipv4 =
  101. - nexthop->src.ipv4;
  102. - setsrc = 1;
  103. - }
  104. - } else if (family == AF_INET6) {
  105. - if (!IN6_IS_ADDR_UNSPECIFIED(
  106. - &nexthop->rmap_src.ipv6)) {
  107. - src.ipv6 =
  108. - nexthop->rmap_src.ipv6;
  109. - setsrc = 1;
  110. - } else if (
  111. - !IN6_IS_ADDR_UNSPECIFIED(
  112. - &nexthop->src.ipv6)) {
  113. - src.ipv6 =
  114. - nexthop->src.ipv6;
  115. - setsrc = 1;
  116. - }
  117. - }
  118. + setsrc = nexthop_set_src(nexthop, family, &src);
  119. continue;
  120. }
  121. From e85c67d05decf340dcf5663a48c652719d04387f Mon Sep 17 00:00:00 2001
  122. From: Stephen Worley <sworley@cumulusnetworks.com>
  123. Date: Tue, 24 Mar 2020 17:32:21 -0400
  124. Subject: [PATCH 2/2] zebra: determine src when using nexthop objects
  125. Determine src based on nexthop data even when we are using
  126. kernel nexthop objects.
  127. Before, we were entirely skipping this step and just sending the
  128. nexthop ID, ignoring src determination.
  129. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
  130. (cherry picked from commit d8bfd8dc9a899f841967257a6b5f30910fdc17c8)
  131. ---
  132. zebra/rt_netlink.c | 17 +++++++++++++++++
  133. 1 file changed, 17 insertions(+)
  134. diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
  135. index dcaf2155f0..ee8ef6558f 100644
  136. --- a/zebra/rt_netlink.c
  137. +++ b/zebra/rt_netlink.c
  138. @@ -1666,6 +1666,23 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
  139. /* Kernel supports nexthop objects */
  140. addattr32(&req.n, sizeof(req), RTA_NH_ID,
  141. dplane_ctx_get_nhe_id(ctx));
  142. +
  143. + /* Have to determine src still */
  144. + for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), nexthop)) {
  145. + if (setsrc)
  146. + break;
  147. +
  148. + setsrc = nexthop_set_src(nexthop, family, &src);
  149. + }
  150. +
  151. + if (setsrc) {
  152. + if (family == AF_INET)
  153. + addattr_l(&req.n, sizeof(req), RTA_PREFSRC,
  154. + &src.ipv4, bytelen);
  155. + else if (family == AF_INET6)
  156. + addattr_l(&req.n, sizeof(req), RTA_PREFSRC,
  157. + &src.ipv6, bytelen);
  158. + }
  159. goto skip;
  160. }