]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Add naive deduplication checks when installing commands
authorQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 7 Oct 2016 18:41:41 +0000 (18:41 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 7 Oct 2016 18:41:41 +0000 (18:41 +0000)
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>
lib/command.c

index 96ce661e4a3156f27b084a2acab891f73744a9fe..d1de9ef2aab7f3840012a18387682298f8364290 100644 (file)
@@ -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);
 }