Typos. A bunch of typos I've been collecting.
[vpp.git] / src / vlib / unix / cli.c
index 727b954..f9d6b40 100644 (file)
@@ -60,6 +60,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <limits.h>
+#include <netinet/tcp.h>
 
 /** ANSI escape code. */
 #define ESC "\x1b"
@@ -580,7 +581,7 @@ unix_cli_del_pending_output (clib_file_t * uf,
  * @param str The buffer in which to search for the value.
  * @param len The depth into the buffer to search.
  *
- * @return The index of the first occurence of \c chr. If \c chr is not
+ * @return The index of the first occurrence of \c chr. If \c chr is not
  *          found then \c len instead.
  */
 always_inline word
@@ -898,7 +899,7 @@ unix_cli_pager_redraw (unix_cli_file_t * cf, clib_file_t * uf)
  *
  * If instead @c line is @c NULL then @c len_or_index is taken to mean the
  * index of an existing line in the pager buffer; this simply means that the
- * input line does not need to be cloned since we alreayd have it. This is
+ * input line does not need to be cloned since we already have it. This is
  * typical if we are reindexing the pager buffer.
  *
  * @param cf           The CLI session whose pager we are adding to.
@@ -1294,7 +1295,7 @@ unix_cli_process_telnet (unix_main_t * um,
     case DO:
     case DONT:
       /* Expect 3 bytes */
-      if (vec_len (input_vector) < 3)
+      if (len < 3)
        return -1;              /* want more bytes */
 
       consume = 2;
@@ -2489,6 +2490,10 @@ unix_cli_kill (unix_cli_main_t * cm, uword cli_file_index)
   clib_file_t *uf;
   int i;
 
+  /* Validate cli_file_index */
+  if (pool_is_free_index (cm->cli_file_pool, cli_file_index))
+    return;
+
   cf = pool_elt_at_index (cm->cli_file_pool, cli_file_index);
   uf = pool_elt_at_index (fm->file_pool, cf->clib_file_index);
 
@@ -2666,7 +2671,7 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd)
   unix_cli_file_t *cf;
   clib_file_t template = { 0 };
   vlib_main_t *vm = um->vlib_main;
-  vlib_node_t *n;
+  vlib_node_t *n = 0;
   u8 *file_desc = 0;
 
   file_desc = format (0, "%s", name);
@@ -2676,11 +2681,27 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd)
   if (vec_len (cm->unused_cli_process_node_indices) > 0)
     {
       uword l = vec_len (cm->unused_cli_process_node_indices);
+      int i;
+      vlib_main_t *this_vlib_main;
+      u8 *old_name = 0;
 
-      /* Find node and give it new name. */
-      n = vlib_get_node (vm, cm->unused_cli_process_node_indices[l - 1]);
-      vec_free (n->name);
-      n->name = (u8 *) name;
+      /*
+       * Nodes are bulk-copied, so node name pointers are shared.
+       * Find the cli node in all graph replicas, and give all of them
+       * the same new name.
+       * Then, throw away the old shared name-vector.
+       */
+      for (i = 0; i < vec_len (vlib_mains); i++)
+       {
+         this_vlib_main = vlib_mains[i];
+         if (this_vlib_main == 0)
+           continue;
+         n = vlib_get_node (this_vlib_main,
+                            cm->unused_cli_process_node_indices[l - 1]);
+         old_name = n->name;
+         n->name = (u8 *) name;
+       }
+      vec_free (old_name);
 
       vlib_node_set_state (vm, n->index, VLIB_NODE_STATE_POLLING);
 
@@ -2695,14 +2716,19 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd)
       };
 
       r.name = name;
+
+      vlib_worker_thread_barrier_sync (vm);
+
       vlib_register_node (vm, &r);
       vec_free (name);
 
       n = vlib_get_node (vm, r.index);
+      vlib_worker_thread_node_runtime_update ();
+      vlib_worker_thread_barrier_release (vm);
     }
 
   pool_get (cm->cli_file_pool, cf);
-  memset (cf, 0, sizeof (*cf));
+  clib_memset (cf, 0, sizeof (*cf));
 
   template.read_function = unix_cli_read_ready;
   template.write_function = unix_cli_write_ready;
@@ -2738,11 +2764,17 @@ unix_cli_listen_read_ready (clib_file_t * uf)
   clib_error_t *error;
   unix_cli_file_t *cf;
   u32 cf_index;
+  int one;
 
   error = clib_socket_accept (s, &client);
   if (error)
     return error;
 
+  /* Disable Nagle, ignore any errors doing so eg on PF_LOCAL socket */
+  one = 1;
+  (void) setsockopt (client.fd, IPPROTO_TCP, TCP_NODELAY,
+                    (void *) &one, sizeof (one));
+
   client_name = (char *) format (0, "%U%c", format_sockaddr, &client.peer, 0);
 
   cf_index = unix_cli_file_add (cm, client_name, client.fd);
@@ -2886,7 +2918,7 @@ unix_cli_config (vlib_main_t * vm, unformat_input_t * input)
       if (isatty (STDIN_FILENO) && um->cli_line_mode == 0)
        {
          /* Capture terminal resize events */
-         memset (&sa, 0, sizeof (sa));
+         clib_memset (&sa, 0, sizeof (sa));
          sa.sa_handler = unix_cli_resize_interrupt;
          if (sigaction (SIGWINCH, &sa, 0) < 0)
            clib_panic ("sigaction");