summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-10-07 18:41:41 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-10-07 18:41:41 +0000
commitc0f9771dccaed58109b891f1928c896c30748b0d (patch)
tree11d9548015a4164a3363d63e6d43dabeaf1b5add /lib/command.c
parentfaf2a19de0badaba9327ce1cd05c6a586d85a121 (diff)
lib: Add naive deduplication checks when installing commands
Since not all duplicate commands can be caught during graph construction, do a linear search over all commands before installing. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/command.c b/lib/command.c
index 96ce661e4a..d1de9ef2aa 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -329,6 +329,17 @@ install_element (enum node_type ntype, struct cmd_element *cmd)
}
// add node to command graph and command vector
+ // idiotic O(n) deduplication logic, should just use a merkle tree
+ for (unsigned int i = 0; i < vector_active (cnode->cmd_vector); i++)
+ {
+ struct cmd_element *existing = vector_slot (cnode->cmd_vector, i);
+ if (strmatch (existing->string, cmd->string))
+ {
+ zlog_warn ("Duplicate command: %s\n", cmd->string);
+ return;
+ }
+ }
+
command_parse_format (cnode->cmdgraph, cmd);
vector_set (cnode->cmd_vector, cmd);
}