session: lock app worker mq for io events
[vpp.git] / src / vnet / session / session_node.c
index 1656e2e..f5aed74 100644 (file)
@@ -29,6 +29,7 @@ session_mq_accepted_reply_handler (void *data)
 {
   session_accepted_reply_msg_t *mp = (session_accepted_reply_msg_t *) data;
   vnet_disconnect_args_t _a = { 0 }, *a = &_a;
+  app_worker_t *app_wrk;
   local_session_t *ls;
   stream_session_t *s;
 
@@ -44,9 +45,15 @@ session_mq_accepted_reply_handler (void *data)
   if (session_handle_is_local (mp->handle))
     {
       ls = application_get_local_session_from_handle (mp->handle);
-      if (!ls || ls->app_wrk_index != mp->context)
+      if (!ls)
        {
-         clib_warning ("server %u doesn't own local handle %llu",
+         clib_warning ("unknown local handle 0x%lx", mp->handle);
+         return;
+       }
+      app_wrk = app_worker_get (ls->app_wrk_index);
+      if (app_wrk->app_index != mp->context)
+       {
+         clib_warning ("server %u doesn't own local handle 0x%lx",
                        mp->context, mp->handle);
          return;
        }
@@ -62,18 +69,15 @@ session_mq_accepted_reply_handler (void *data)
          clib_warning ("session doesn't exist");
          return;
        }
-      if (s->app_wrk_index != mp->context)
+      app_wrk = app_worker_get (s->app_wrk_index);
+      if (app_wrk->app_index != mp->context)
        {
          clib_warning ("app doesn't own session");
          return;
        }
       s->session_state = SESSION_STATE_READY;
       if (!svm_fifo_is_empty (s->server_rx_fifo))
-       {
-         app_worker_t *app;
-         app = app_worker_get (s->app_wrk_index);
-         application_send_event (app, s, FIFO_EVENT_APP_RX);
-       }
+       app_worker_lock_and_send_event (app_wrk, s, FIFO_EVENT_APP_RX);
     }
 }
 
@@ -132,12 +136,16 @@ session_mq_disconnected_handler (void *data)
   int rv = 0;
 
   mp = (session_disconnected_msg_t *) data;
-  s = session_get_from_handle_if_valid (mp->handle);
+  if (!(s = session_get_from_handle_if_valid (mp->handle)))
+    {
+      clib_warning ("could not disconnect handle %llu", mp->handle);
+      return;
+    }
   app_wrk = app_worker_get (s->app_wrk_index);
   app = application_lookup (mp->client_index);
-  if (!(app_wrk && s && app->app_index == app_wrk->app_index))
+  if (!(app_wrk && app && app->app_index == app_wrk->app_index))
     {
-      clib_warning ("could not disconnect session: %llu app_wrk: %u",
+      clib_warning ("could not disconnect session: %llu app: %u",
                    mp->handle, mp->client_index);
       return;
     }
@@ -303,7 +311,10 @@ session_tx_fifo_chain_tail (vlib_main_t * vm, session_tx_context_t * ctx,
 
              hdr->data_offset += n_bytes_read;
              if (hdr->data_offset == hdr->data_length)
-               svm_fifo_dequeue_drop (f, hdr->data_length);
+               {
+                 u32 offset = hdr->data_length + SESSION_CONN_HDR_LEN;
+                 svm_fifo_dequeue_drop (f, offset);
+               }
            }
          else
            n_bytes_read = svm_fifo_dequeue_nowait (ctx->s->server_tx_fifo,
@@ -719,7 +730,7 @@ session_tx_fifo_dequeue_internal (vlib_main_t * vm,
                                  stream_session_t * s, int *n_tx_pkts)
 {
   application_t *app;
-  app = application_get (s->opaque);
+  app = application_get (s->t_app_index);
   svm_fifo_unset_event (s->server_tx_fifo);
   return app->cb_fns.builtin_app_tx_callback (s);
 }