session: add transport deleted state 82/20782/7
authorFlorin Coras <fcoras@cisco.com>
Tue, 23 Jul 2019 02:03:03 +0000 (19:03 -0700)
committerDave Barach <openvpp@barachs.net>
Thu, 25 Jul 2019 17:59:17 +0000 (17:59 +0000)
Type: fix

Distinguish between closed and deleted states to avoid deleting the
session prior to the transport connection.

Change-Id: Ia285ce94b26a70773f8c0ce9d2c73095d3e2a337
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vnet/session/session.c
src/vnet/session/session_cli.c
src/vnet/session/session_types.h
src/vnet/tcp/tcp.c

index ea1a8c9..477215e 100644 (file)
@@ -793,13 +793,14 @@ session_transport_delete_notify (transport_connection_t * tc)
     case SESSION_STATE_ACCEPTING:
     case SESSION_STATE_TRANSPORT_CLOSING:
     case SESSION_STATE_CLOSING:
+    case SESSION_STATE_TRANSPORT_CLOSED:
       /* If transport finishes or times out before we get a reply
        * from the app, mark transport as closed and wait for reply
        * before removing the session. Cleanup session table in advance
        * because transport will soon be closed and closed sessions
        * are assumed to have been removed from the lookup table */
       session_lookup_del_session (s);
-      s->session_state = SESSION_STATE_TRANSPORT_CLOSED;
+      s->session_state = SESSION_STATE_TRANSPORT_DELETED;
       session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT);
       svm_fifo_dequeue_drop_all (s->tx_fifo);
       break;
@@ -815,7 +816,7 @@ session_transport_delete_notify (transport_connection_t * tc)
       svm_fifo_dequeue_drop_all (s->tx_fifo);
       session_program_transport_close (s);
       break;
-    case SESSION_STATE_TRANSPORT_CLOSED:
+    case SESSION_STATE_TRANSPORT_DELETED:
       break;
     case SESSION_STATE_CLOSED:
       session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT);
@@ -858,11 +859,10 @@ session_transport_closed_notify (transport_connection_t * tc)
    * a transport close, only mark the session transport as closed */
   else if (s->session_state <= SESSION_STATE_CLOSING)
     {
-      session_lookup_del_session (s);
       s->session_state = SESSION_STATE_TRANSPORT_CLOSED;
     }
-  /* In all closing states but transport closed switch to closed */
-  else if (s->session_state != SESSION_STATE_TRANSPORT_CLOSED)
+  /* If app also closed, switch to closed */
+  else if (s->session_state == SESSION_STATE_APP_CLOSED)
     s->session_state = SESSION_STATE_CLOSED;
 
   app_wrk = app_worker_get_if_valid (s->app_wrk_index);
@@ -1118,7 +1118,8 @@ session_close (session_t * s)
     {
       /* Session will only be removed once both app and transport
        * acknowledge the close */
-      if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED)
+      if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED
+         || s->session_state == SESSION_STATE_TRANSPORT_DELETED)
        session_program_transport_close (s);
       return;
     }
@@ -1139,8 +1140,10 @@ session_transport_close (session_t * s)
 {
   if (s->session_state >= SESSION_STATE_APP_CLOSED)
     {
-      /* If transport is already closed, just free the session */
-      if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
+      if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED)
+       s->session_state = SESSION_STATE_CLOSED;
+      /* If transport is already deleted, just free the session */
+      else if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED)
        session_free_w_fifos (s);
       return;
     }
index ca4b8c1..fd598f4 100755 (executable)
@@ -59,7 +59,7 @@ format_session (u8 * s, va_list * args)
   u32 tp = session_get_transport_proto (ss);
   u8 *str = 0;
 
-  if (ss->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
+  if (ss->session_state >= SESSION_STATE_TRANSPORT_DELETED)
     {
       s = format (s, "[%u:%u] CLOSED", ss->thread_index, ss->session_index);
       return s;
@@ -330,7 +330,7 @@ show_session_command_fn (vlib_main_t * vm, unformat_input_t * input,
 
       /* *INDENT-OFF* */
       pool_foreach (s, pool, ({
-        if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
+        if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED)
           {
             n_closed += 1;
             continue;
index 682094c..25b6116 100644 (file)
@@ -133,6 +133,7 @@ typedef enum
   SESSION_STATE_CLOSING,
   SESSION_STATE_APP_CLOSED,
   SESSION_STATE_TRANSPORT_CLOSED,
+  SESSION_STATE_TRANSPORT_DELETED,
   SESSION_STATE_CLOSED,
   SESSION_STATE_N_STATES,
 } session_state_t;
index f0d6478..928d1ba 100644 (file)
@@ -358,7 +358,6 @@ tcp_connection_reset (tcp_connection_t * tc)
       tcp_timer_set (tc, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME);
       /* Make sure we mark the session as closed. In some states we may
        * be still trying to send data */
-      session_transport_closed_notify (&tc->connection);
       tcp_connection_set_state (tc, TCP_STATE_CLOSED);
       session_transport_closed_notify (&tc->connection);
       break;