ip: use main heap for mtrie, part 2 (remove args)
[vpp.git] / src / vnet / tls / tls.c
index 89dbd36..9caa5d7 100644 (file)
@@ -232,17 +232,17 @@ tls_notify_app_connected (tls_ctx_t * ctx, session_error_t err)
   if ((err = app_worker_init_connected (app_wrk, app_session)))
     goto failed;
 
-  app_session->session_state = SESSION_STATE_CONNECTING;
+  app_session->session_state = SESSION_STATE_READY;
   if (app_worker_connect_notify (app_wrk, app_session,
                                 SESSION_E_NONE, ctx->parent_app_api_context))
     {
       TLS_DBG (1, "failed to notify app");
+      app_session->session_state = SESSION_STATE_CONNECTING;
       tls_disconnect (ctx->tls_ctx_handle, vlib_get_thread_index ());
       return -1;
     }
 
   ctx->app_session_handle = session_handle (app_session);
-  app_session->session_state = SESSION_STATE_READY;
 
   return 0;
 
@@ -518,7 +518,12 @@ tls_app_session_cleanup (session_t * s, session_cleanup_ntf_t ntf)
   tls_ctx_t *ctx;
 
   if (ntf == SESSION_CLEANUP_TRANSPORT)
-    return;
+    {
+      /* Allow cleanup of tcp session */
+      if (s->session_state == SESSION_STATE_TRANSPORT_DELETED)
+       session_close (s);
+      return;
+    }
 
   ctx = tls_ctx_get (s->opaque);
   if (!ctx->no_app_session)
@@ -740,14 +745,14 @@ tls_custom_tx_callback (void *session, transport_send_params_t * sp)
 u8 *
 format_tls_ctx (u8 * s, va_list * args)
 {
-  u32 tcp_si, tcp_ti, ctx_index, ctx_engine, app_si, app_ti;
+  u32 tcp_si, tcp_ti, ctx_index, ctx_engine;
   tls_ctx_t *ctx = va_arg (*args, tls_ctx_t *);
 
   session_parse_handle (ctx->tls_session_handle, &tcp_si, &tcp_ti);
   tls_ctx_parse_handle (ctx->tls_ctx_handle, &ctx_index, &ctx_engine);
-  session_parse_handle (ctx->app_session_handle, &app_si, &app_ti);
   s = format (s, "[%d:%d][TLS] app_wrk %u index %u engine %u tcp %d:%d",
-             app_ti, app_si, ctx->parent_app_wrk_index, ctx_index,
+             ctx->c_thread_index, ctx->c_s_index,
+             ctx->parent_app_wrk_index, ctx_index,
              ctx_engine, tcp_ti, tcp_si);
 
   return s;
@@ -758,16 +763,15 @@ format_tls_listener_ctx (u8 * s, va_list * args)
 {
   session_t *tls_listener;
   app_listener_t *al;
-  u32 app_si, app_ti;
   tls_ctx_t *ctx;
 
   ctx = va_arg (*args, tls_ctx_t *);
 
   al = app_listener_get_w_handle (ctx->tls_session_handle);
   tls_listener = app_listener_get_session (al);
-  session_parse_handle (ctx->app_session_handle, &app_si, &app_ti);
   s = format (s, "[%d:%d][TLS] app_wrk %u engine %u tcp %d:%d",
-             app_ti, app_si, ctx->parent_app_wrk_index, ctx->tls_ctx_engine,
+             ctx->c_thread_index, ctx->c_s_index,
+             ctx->parent_app_wrk_index, ctx->tls_ctx_engine,
              tls_listener->thread_index, tls_listener->session_index);
 
   return s;
@@ -780,13 +784,22 @@ format_tls_ctx_state (u8 * s, va_list * args)
   session_t *ts;
 
   ctx = va_arg (*args, tls_ctx_t *);
-  ts = session_get_from_handle (ctx->app_session_handle);
+  ts = session_get (ctx->c_s_index, ctx->c_thread_index);
   if (ts->session_state == SESSION_STATE_LISTENING)
     s = format (s, "%s", "LISTEN");
-  else if (tls_ctx_handshake_is_over (ctx))
-    s = format (s, "%s", "ESTABLISHED");
   else
-    s = format (s, "%s", "HANDSHAKE");
+    {
+      if (ts->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
+       s = format (s, "%s", "CLOSED");
+      else if (ts->session_state == SESSION_STATE_APP_CLOSED)
+       s = format (s, "%s", "APP-CLOSED");
+      else if (ts->session_state >= SESSION_STATE_TRANSPORT_CLOSING)
+       s = format (s, "%s", "CLOSING");
+      else if (tls_ctx_handshake_is_over (ctx))
+       s = format (s, "%s", "ESTABLISHED");
+      else
+       s = format (s, "%s", "HANDSHAKE");
+    }
 
   return s;
 }