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.

177 lines
5.7 KiB

  1. From 33a9ff0045adfa605832187e570dbe1374ceb22e Mon Sep 17 00:00:00 2001
  2. From: Mark Stapp <mjs@voltanet.io>
  3. Date: Tue, 28 Jan 2020 11:00:42 -0500
  4. Subject: [PATCH] zebra: add config to disable use of kernel nexthops
  5. Add a config that disables use of kernel-level nexthop ids.
  6. Currently, zebra always uses nexthop ids if the kernel supports
  7. them.
  8. Signed-off-by: Mark Stapp <mjs@voltanet.io>
  9. ---
  10. zebra/rt_netlink.c | 20 ++++++++++++++++----
  11. zebra/zebra_nhg.c | 18 ++++++++++++++++++
  12. zebra/zebra_nhg.h | 10 +++++++++-
  13. zebra/zebra_vty.c | 18 ++++++++++++++++++
  14. 4 files changed, 61 insertions(+), 5 deletions(-)
  15. diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
  16. index 2abcd6ef2a..705536595b 100644
  17. --- a/zebra/rt_netlink.c
  18. +++ b/zebra/rt_netlink.c
  19. @@ -75,6 +75,10 @@
  20. static vlanid_t filter_vlan = 0;
  21. +/* We capture whether the current kernel supports nexthop ids; by
  22. + * default, we'll use them if possible. There's also a configuration
  23. + * available to _disable_ use of kernel nexthops.
  24. + */
  25. static bool supports_nh;
  26. struct gw_family_t {
  27. @@ -86,6 +90,12 @@ struct gw_family_t {
  28. static const char ipv4_ll_buf[16] = "169.254.0.1";
  29. static struct in_addr ipv4_ll;
  30. +/* Helper to control use of kernel-level nexthop ids */
  31. +static bool kernel_nexthops_supported(void)
  32. +{
  33. + return (supports_nh && zebra_nhg_kernel_nexthops_enabled());
  34. +}
  35. +
  36. /*
  37. * The ipv4_ll data structure is used for all 5549
  38. * additions to the kernel. Let's figure out the
  39. @@ -1628,7 +1638,7 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
  40. RTA_PAYLOAD(rta));
  41. }
  42. - if (supports_nh) {
  43. + if (kernel_nexthops_supported()) {
  44. /* Kernel supports nexthop objects */
  45. addattr32(&req.n, sizeof(req), RTA_NH_ID,
  46. dplane_ctx_get_nhe_id(ctx));
  47. @@ -1943,7 +1953,7 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx)
  48. size_t req_size = sizeof(req);
  49. /* Nothing to do if the kernel doesn't support nexthop objects */
  50. - if (!supports_nh)
  51. + if (!kernel_nexthops_supported())
  52. return 0;
  53. label_buf[0] = '\0';
  54. @@ -2504,8 +2514,10 @@ int netlink_nexthop_read(struct zebra_ns *zns)
  55. * this kernel must support them.
  56. */
  57. supports_nh = true;
  58. - else if (IS_ZEBRA_DEBUG_KERNEL)
  59. - zlog_debug("Nexthop objects not supported on this kernel");
  60. +
  61. + if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_NHG)
  62. + zlog_debug("Nexthop objects %ssupported on this kernel",
  63. + supports_nh ? "" : "not ");
  64. return ret;
  65. }
  66. diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c
  67. index cbeb73aed4..62c478cf85 100644
  68. --- a/zebra/zebra_nhg.c
  69. +++ b/zebra/zebra_nhg.c
  70. @@ -49,6 +49,9 @@ DEFINE_MTYPE_STATIC(ZEBRA, NHG_CTX, "Nexthop Group Context");
  71. /* id counter to keep in sync with kernel */
  72. uint32_t id_counter;
  73. +/* */
  74. +static bool g_nexthops_enabled = true;
  75. +
  76. static struct nhg_hash_entry *depends_find(const struct nexthop *nh,
  77. afi_t afi);
  78. static void depends_add(struct nhg_connected_tree_head *head,
  79. @@ -2004,3 +2007,18 @@ void zebra_nhg_sweep_table(struct hash *hash)
  80. {
  81. hash_iterate(hash, zebra_nhg_sweep_entry, NULL);
  82. }
  83. +
  84. +/* Global control to disable use of kernel nexthops, if available. We can't
  85. + * force the kernel to support nexthop ids, of course, but we can disable
  86. + * zebra's use of them, for testing e.g. By default, if the kernel supports
  87. + * nexthop ids, zebra uses them.
  88. + */
  89. +void zebra_nhg_enable_kernel_nexthops(bool set)
  90. +{
  91. + g_nexthops_enabled = set;
  92. +}
  93. +
  94. +bool zebra_nhg_kernel_nexthops_enabled(void)
  95. +{
  96. + return g_nexthops_enabled;
  97. +}
  98. diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h
  99. index c2e173e094..4d001944b7 100644
  100. --- a/zebra/zebra_nhg.h
  101. +++ b/zebra/zebra_nhg.h
  102. @@ -153,6 +153,13 @@ struct nhg_ctx {
  103. enum nhg_ctx_status status;
  104. };
  105. +/* Global control to disable use of kernel nexthops, if available. We can't
  106. + * force the kernel to support nexthop ids, of course, but we can disable
  107. + * zebra's use of them, for testing e.g. By default, if the kernel supports
  108. + * nexthop ids, zebra uses them.
  109. + */
  110. +void zebra_nhg_enable_kernel_nexthops(bool set);
  111. +bool zebra_nhg_kernel_nexthops_enabled(void);
  112. /**
  113. * NHE abstracted tree functions.
  114. @@ -227,4 +234,5 @@ extern void zebra_nhg_sweep_table(struct hash *hash);
  115. /* Nexthop resolution processing */
  116. struct route_entry; /* Forward ref to avoid circular includes */
  117. extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);
  118. -#endif
  119. +
  120. +#endif /* __ZEBRA_NHG_H__ */
  121. diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
  122. index 78001da170..866b38b47e 100644
  123. --- a/zebra/zebra_vty.c
  124. +++ b/zebra/zebra_vty.c
  125. @@ -1410,6 +1410,19 @@ DEFPY (show_nexthop_group,
  126. return CMD_SUCCESS;
  127. }
  128. +DEFPY_HIDDEN(nexthop_group_use_enable,
  129. + nexthop_group_use_enable_cmd,
  130. + "[no] zebra nexthop kernel enable",
  131. + NO_STR
  132. + ZEBRA_STR
  133. + "Nexthop configuration \n"
  134. + "Configure use of kernel nexthops\n"
  135. + "Enable kernel nexthops\n")
  136. +{
  137. + zebra_nhg_enable_kernel_nexthops(!no);
  138. + return CMD_SUCCESS;
  139. +}
  140. +
  141. DEFUN (no_ip_nht_default_route,
  142. no_ip_nht_default_route_cmd,
  143. "no ip nht resolve-via-default",
  144. @@ -3121,6 +3134,10 @@ static int config_write_protocol(struct vty *vty)
  145. /* Include dataplane info */
  146. dplane_config_write_helper(vty);
  147. + /* Include nexthop-group config */
  148. + if (!zebra_nhg_kernel_nexthops_enabled())
  149. + vty_out(vty, "no zebra nexthop kernel enable\n");
  150. +
  151. return 1;
  152. }
  153. @@ -3492,6 +3509,7 @@ void zebra_vty_init(void)
  154. install_element(CONFIG_NODE, &no_zebra_workqueue_timer_cmd);
  155. install_element(CONFIG_NODE, &zebra_packet_process_cmd);
  156. install_element(CONFIG_NODE, &no_zebra_packet_process_cmd);
  157. + install_element(CONFIG_NODE, &nexthop_group_use_enable_cmd);
  158. install_element(VIEW_NODE, &show_nexthop_group_cmd);
  159. install_element(VIEW_NODE, &show_interface_nexthop_group_cmd);