summaryrefslogtreecommitdiff
path: root/lib/command.h
diff options
context:
space:
mode:
authorPaul Jakma <paul.jakma@hpe.com>2016-06-16 16:03:11 +0100
committerDonald Sharp <sharpd@cumulusnetworks.com>2016-10-19 22:28:45 -0400
commit274f29b2f43c82e223d7a8d6899fae74fdcc5105 (patch)
treec9fd58aa80c7a507ab0a6e59b2003a8bb5cfed1e /lib/command.h
parent2d35a720b9f997d08dd3da5441fc7ce889135a05 (diff)
lib: keep hash of node's commands to detect duplicate installs
* command.h: (struct cmd_node) Add a hash, so duplicate installs of a cmd_element to a command node can be detected. To help catch strays from the VIEW/ENABLE node consolidation particularly (installs to VIEW automatically install to ENABLE too now). * command.c: (cmd_hash_{key,cmp}) helpers for the hash - just directly on the pointer value is sufficient to catch the main problem. (install_node) setup the hash for the command node. (install_element) check for duplicate installs. The assert on the cmd_parse_format seems misplaced. (install_default_basic) separate the basic, VIEW, node default commands to here. (cmd_init) get rid of dupes, given consolidation. (cmd_terminate) clean up the node command hash. Not done: The (struct cmd_node)'s vector could be replaced with the cmd hash, however much of the command parser depends heavily on the vector and it's a lot of work to change. A vector_lookup_value could also work, particularly if vector could be backed by a hash. The duplicate check could be disabled in releases - but useful in development. It's a little extra overhead at startup. The command initialisation overhead is already something that bites in micro-benchmarks - makes it easy for other implementations to show how much faster they are with benchmarks where other load is low enough that startup time is a factor.
Diffstat (limited to 'lib/command.h')
-rw-r--r--lib/command.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/command.h b/lib/command.h
index ad9ccf505e..e4aa10196f 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -27,6 +27,7 @@
#include "vty.h"
#include "lib/route_types.h"
#include "memory.h"
+#include "hash.h"
DECLARE_MTYPE(HOST)
@@ -147,7 +148,10 @@ struct cmd_node
int (*func) (struct vty *);
/* Vector of this node's command list. */
- vector cmd_vector;
+ vector cmd_vector;
+
+ /* Hashed index of command node list, for de-dupping primarily */
+ struct hash *cmd_hash;
};
enum