quic: fix timer update
[vpp.git] / src / plugins / quic / quic.c
index 0cd2800..c4ef459 100644 (file)
@@ -572,6 +572,12 @@ quic_connection_delete (quic_ctx_t * ctx)
   clib_bihash_kv_16_8_t kv;
   quicly_conn_t *conn;
 
+  if (ctx->conn == NULL)
+    {
+      QUIC_DBG (2, "Skipping redundant delete of connection %u",
+               ctx->c_c_index);
+      return;
+    }
   QUIC_DBG (2, "Deleting connection %u", ctx->c_c_index);
 
   QUIC_ASSERT (!quic_ctx_is_stream (ctx));
@@ -587,8 +593,8 @@ quic_connection_delete (quic_ctx_t * ctx)
 
   quic_disconnect_transport (ctx);
 
-  if (ctx->conn)
-    quicly_free (ctx->conn);
+  if (conn)
+    quicly_free (conn);
   session_transport_delete_notify (&ctx->connection);
 }
 
@@ -646,11 +652,11 @@ static int
 quic_send_datagram (session_t *udp_session, struct iovec *packet,
                    quicly_address_t *dest, quicly_address_t *src)
 {
-  u32 max_enqueue;
+  u32 max_enqueue, len;
   session_dgram_hdr_t hdr;
-  u32 len, ret;
   svm_fifo_t *f;
   transport_connection_t *tc;
+  int ret;
 
   len = packet->iov_len;
   f = udp_session->tx_fifo;
@@ -1008,6 +1014,7 @@ quic_on_stream_open (quicly_stream_open_t * self, quicly_stream_t * stream)
   sctx->stream = stream;
   sctx->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
   sctx->flags |= QUIC_F_IS_STREAM;
+  sctx->crypto_context_index = qctx->crypto_context_index;
   if (quicly_stream_is_unidirectional (stream->stream_id))
     stream_session->flags |= SESSION_F_UNIDIRECTIONAL;
 
@@ -1142,7 +1149,9 @@ quic_update_timer (quic_ctx_t * ctx)
        }
     }
 
-  tw = &quic_main.wrk_ctx[vlib_get_thread_index ()].timer_wheel;
+  ASSERT (vlib_get_thread_index () == ctx->c_thread_index ||
+         vlib_get_thread_index () == 0);
+  tw = &quic_main.wrk_ctx[ctx->c_thread_index].timer_wheel;
 
   QUIC_DBG (4, "Timer set to %ld (int %ld) for ctx %u", next_timeout,
            next_interval, ctx->c_c_index);
@@ -1246,6 +1255,7 @@ quic_connect_stream (session_t * quic_session, session_endpoint_cfg_t * sep)
   quic_increment_counter (QUIC_ERROR_OPENED_STREAM, 1);
 
   sctx->stream = stream;
+  sctx->crypto_context_index = qctx->crypto_context_index;
 
   QUIC_DBG (2, "Opened stream %d, creating session", stream->stream_id);
 
@@ -1298,16 +1308,17 @@ quic_connect_connection (session_endpoint_cfg_t * sep)
   vnet_connect_args_t _cargs, *cargs = &_cargs;
   transport_endpt_crypto_cfg_t *ccfg;
   quic_main_t *qm = &quic_main;
+  u32 ctx_index, thread_index;
   quic_ctx_t *ctx;
   app_worker_t *app_wrk;
   application_t *app;
-  u32 ctx_index;
-  u32 thread_index = vlib_get_thread_index ();
   int error;
 
   if (!sep->ext_cfg)
     return SESSION_E_NOEXTCFG;
 
+  /* Use pool on thread 1 if we have workers because of UDP */
+  thread_index = vlib_num_workers () ? 1 : 0;
   ccfg = &sep->ext_cfg->crypto;
 
   clib_memset (cargs, 0, sizeof (*cargs));
@@ -1451,9 +1462,6 @@ quic_start_listen (u32 quic_listen_session_index, transport_endpoint_t * tep)
 
   ccfg = &sep->ext_cfg->crypto;
   app_wrk = app_worker_get (sep->app_wrk_index);
-  /* We need to call this because we call app_worker_init_connected in
-   * quic_accept_stream, which assumes the connect segment manager exists */
-  app_worker_alloc_connects_segment_manager (app_wrk);
   app = application_get (app_wrk->app_index);
   QUIC_DBG (2, "Called quic_start_listen for app %d", app_wrk->app_index);
 
@@ -1788,11 +1796,15 @@ quic_udp_session_connected_callback (u32 quic_app_index, u32 ctx_index,
   app_worker_t *app_wrk;
   quicly_conn_t *conn;
   quic_ctx_t *ctx;
-  u32 thread_index = vlib_get_thread_index ();
+  u32 thread_index;
   int ret;
   quicly_context_t *quicly_ctx;
 
-
+  /* Allocate session on whatever thread udp used, i.e., probably first
+   * worker, although this may be main thread. If it is main, it's done
+   * with a worker barrier */
+  thread_index = udp_session->thread_index;
+  ASSERT (thread_index == 0 || thread_index == 1);
   ctx = quic_ctx_get (ctx_index, thread_index);
   if (err)
     {
@@ -1806,9 +1818,6 @@ quic_udp_session_connected_callback (u32 quic_app_index, u32 ctx_index,
       return 0;
     }
 
-  ctx->c_thread_index = thread_index;
-  ctx->c_c_index = ctx_index;
-
   QUIC_DBG (2, "New ctx [%u]%x", thread_index, (ctx) ? ctx_index : ~0);
 
   ctx->udp_session_handle = session_handle (udp_session);
@@ -1836,11 +1845,7 @@ quic_udp_session_connected_callback (u32 quic_app_index, u32 ctx_index,
   QUIC_DBG (2, "Registering conn with id %lu %lu", kv.key[0], kv.key[1]);
   clib_bihash_add_del_16_8 (&quic_main.connection_hash, &kv, 1 /* is_add */ );
 
-  /*  UDP stack quirk? preemptively transfer connection if that happens */
-  if (udp_session->thread_index != thread_index)
-    quic_transfer_connection (ctx_index, udp_session->thread_index);
-  else
-    quic_send_packets (ctx);
+  quic_send_packets (ctx);
 
   return ret;
 }