session: accept reply improvements 86/34586/6
authorFlorin Coras <fcoras@cisco.com>
Thu, 25 Nov 2021 19:37:33 +0000 (11:37 -0800)
committerDave Barach <openvpp@barachs.net>
Fri, 26 Nov 2021 21:48:20 +0000 (21:48 +0000)
- Always check session ownership
- Improve test for main thread rpc

Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I5fa60f7f5de199af0966987f9ce9a4cc8180cf98

src/vnet/session/session_node.c

index 7565b43..1d7ebf9 100644 (file)
@@ -454,19 +454,10 @@ session_mq_accepted_reply_handler (void *data)
   app_worker_t *app_wrk;
   session_t *s;
 
-  /* Server isn't interested, kill the session */
-  if (mp->retval)
-    {
-      a->app_index = mp->context;
-      a->handle = mp->handle;
-      vnet_disconnect_session (a);
-      return;
-    }
-
   /* Mail this back from the main thread. We're not polling in main
    * thread so we're using other workers for notifications. */
-  if (vlib_num_workers () && vlib_get_thread_index () != 0
-      && session_thread_from_handle (mp->handle) == 0)
+  if (session_thread_from_handle (mp->handle) == 0 && vlib_num_workers () &&
+      vlib_get_thread_index () != 0)
     {
       vlib_rpc_call_main_thread (session_mq_accepted_reply_handler,
                                 (u8 *) mp, sizeof (*mp));
@@ -484,27 +475,35 @@ session_mq_accepted_reply_handler (void *data)
       return;
     }
 
-  if (!session_has_transport (s))
+  /* Server isn't interested, disconnect the session */
+  if (mp->retval)
     {
-      s->session_state = SESSION_STATE_READY;
-      if (ct_session_connect_notify (s, SESSION_E_NONE))
-       return;
+      a->app_index = mp->context;
+      a->handle = mp->handle;
+      vnet_disconnect_session (a);
+      return;
     }
-  else
+
+  /* Special handling for cut-through sessions */
+  if (!session_has_transport (s))
     {
-      old_state = s->session_state;
       s->session_state = SESSION_STATE_READY;
+      ct_session_connect_notify (s, SESSION_E_NONE);
+      return;
+    }
 
-      if (!svm_fifo_is_empty_prod (s->rx_fifo))
-       app_worker_lock_and_send_event (app_wrk, s, SESSION_IO_EVT_RX);
+  old_state = s->session_state;
+  s->session_state = SESSION_STATE_READY;
 
-      /* Closed while waiting for app to reply. Resend disconnect */
-      if (old_state >= SESSION_STATE_TRANSPORT_CLOSING)
-       {
-         app_worker_close_notify (app_wrk, s);
-         s->session_state = old_state;
-         return;
-       }
+  if (!svm_fifo_is_empty_prod (s->rx_fifo))
+    app_worker_lock_and_send_event (app_wrk, s, SESSION_IO_EVT_RX);
+
+  /* Closed while waiting for app to reply. Resend disconnect */
+  if (old_state >= SESSION_STATE_TRANSPORT_CLOSING)
+    {
+      app_worker_close_notify (app_wrk, s);
+      s->session_state = old_state;
+      return;
     }
 }