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.

120 lines
3.6 KiB

  1. From cc5934ed5939315ba5d95bfaf052625762107205 Mon Sep 17 00:00:00 2001
  2. From: Donald Sharp <sharpd@cumulusnetworks.com>
  3. Date: Tue, 30 Jun 2020 08:59:46 -0400
  4. Subject: [PATCH 1/2] vtysh: master is a non-sorted list
  5. The commit:
  6. a798241265a5808083a06b14ce1637d1ddf6a45a
  7. attempted to use sorted master lists to do faster lookups
  8. by using a RB Tree. Unfortunately the original code
  9. was creating a list->cmp function *but* never using it.
  10. If you look at the commit, it clearly shows that the
  11. function listnode_add is used to insert but when you
  12. look at that function it is a tail push.
  13. Fixes: #6573
  14. Namely now this ordering is preserved:
  15. bgp as-path access-list originate-only permit ^$
  16. bgp as-path access-list originate-only deny .*
  17. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  18. ---
  19. vtysh/vtysh_config.c | 21 ++++++++++-----------
  20. 1 file changed, 10 insertions(+), 11 deletions(-)
  21. diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c
  22. index abbb111f9d..2ab9dd5a9a 100644
  23. --- a/vtysh/vtysh_config.c
  24. +++ b/vtysh/vtysh_config.c
  25. @@ -34,7 +34,7 @@ DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CONFIG_LINE, "Vtysh configuration line")
  26. vector configvec;
  27. -PREDECL_RBTREE_UNIQ(config_master);
  28. +PREDECL_LIST(config_master);
  29. struct config {
  30. /* Configuration node name. */
  31. @@ -72,11 +72,6 @@ static struct config *config_new(void)
  32. return config;
  33. }
  34. -static int config_cmp(const struct config *c1, const struct config *c2)
  35. -{
  36. - return strcmp(c1->name, c2->name);
  37. -}
  38. -
  39. static void config_del(struct config *config)
  40. {
  41. list_delete(&config->line);
  42. @@ -84,13 +79,15 @@ static void config_del(struct config *config)
  43. XFREE(MTYPE_VTYSH_CONFIG, config);
  44. }
  45. -DECLARE_RBTREE_UNIQ(config_master, struct config, rbt_item, config_cmp)
  46. +DECLARE_LIST(config_master, struct config, rbt_item)
  47. static struct config *config_get(int index, const char *line)
  48. {
  49. - struct config *config;
  50. + struct config *config, *config_loop;
  51. struct config_master_head *master;
  52. + config = config_loop = NULL;
  53. +
  54. master = vector_lookup_ensure(configvec, index);
  55. if (!master) {
  56. @@ -99,8 +96,10 @@ static struct config *config_get(int index, const char *line)
  57. vector_set_index(configvec, index, master);
  58. }
  59. - const struct config config_ref = { .name = (char *)line };
  60. - config = config_master_find(master, &config_ref);
  61. + frr_each (config_master, master, config_loop) {
  62. + if (strcmp(config_loop->name, line) == 0)
  63. + config = config_loop;
  64. + }
  65. if (!config) {
  66. config = config_new();
  67. @@ -109,7 +108,7 @@ static struct config *config_get(int index, const char *line)
  68. config->line->cmp = (int (*)(void *, void *))line_cmp;
  69. config->name = XSTRDUP(MTYPE_VTYSH_CONFIG_LINE, line);
  70. config->index = index;
  71. - config_master_add(master, config);
  72. + config_master_add_tail(master, config);
  73. }
  74. return config;
  75. }
  76. From 3e4d90ec556649e11954f2f56b5282f95e7e013b Mon Sep 17 00:00:00 2001
  77. From: Donald Sharp <sharpd@cumulusnetworks.com>
  78. Date: Tue, 30 Jun 2020 09:03:55 -0400
  79. Subject: [PATCH 2/2] vtysh: Improve lookup performance
  80. When we find the line we are interested in, stop looking.
  81. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  82. ---
  83. vtysh/vtysh_config.c | 4 +++-
  84. 1 file changed, 3 insertions(+), 1 deletion(-)
  85. diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c
  86. index 2ab9dd5a9a..61bcf3b658 100644
  87. --- a/vtysh/vtysh_config.c
  88. +++ b/vtysh/vtysh_config.c
  89. @@ -97,8 +97,10 @@ static struct config *config_get(int index, const char *line)
  90. }
  91. frr_each (config_master, master, config_loop) {
  92. - if (strcmp(config_loop->name, line) == 0)
  93. + if (strcmp(config_loop->name, line) == 0) {
  94. config = config_loop;
  95. + break;
  96. + }
  97. }
  98. if (!config) {