tls http srtp: fix session index for listeners
[vpp.git] / src / plugins / http / http.c
index 574c341..868d0dd 100644 (file)
@@ -192,6 +192,7 @@ http_ts_accept_callback (session_t *ts)
    * the fifo is small (under 16K) we set the threshold to it's size, meaning
    * a notification will be given when the fifo empties.
    */
+  ts = session_get_from_handle (hc->h_tc_session_handle);
   thresh = clib_min (svm_fifo_size (ts->tx_fifo), HTTP_FIFO_THRESH);
   svm_fifo_set_deq_thresh (ts->tx_fifo, thresh);
 
@@ -254,7 +255,7 @@ static const char *http_response_template = "HTTP/1.1 200 OK\r\n"
                                            "Expires: %U GMT\r\n"
                                            "Server: VPP Static\r\n"
                                            "Content-Type: %s\r\n"
-                                           "Content-Length: %d\r\n\r\n";
+                                           "Content-Length: %lu\r\n\r\n";
 
 static u32
 send_data (http_conn_t *hc, u8 *data, u32 length, u32 offset)
@@ -498,6 +499,9 @@ state_wait_app (http_conn_t *hc, transport_send_params_t *sp)
   /* Start sending the actual data */
   hc->req_state = HTTP_REQ_STATE_SEND_MORE_DATA;
 
+  ASSERT (sp->max_burst_size >= offset);
+  sp->max_burst_size -= offset;
+
   return 1;
 
 error:
@@ -520,6 +524,7 @@ state_send_more_data (http_conn_t *hc, transport_send_params_t *sp)
   session_t *ts;
   int sent = 0;
 
+  max_send = clib_min (max_send, sp->max_burst_size);
   ts = session_get_from_handle (hc->h_tc_session_handle);
   if ((seg = http_buffer_get_segs (hb, max_send, &n_segs)))
     sent = svm_fifo_enqueue_segments (ts->tx_fifo, seg, n_segs,
@@ -529,6 +534,7 @@ state_send_more_data (http_conn_t *hc, transport_send_params_t *sp)
     {
       /* Ask scheduler to notify app of deq event if needed */
       sp->bytes_dequeued += http_buffer_drain (hb, sent);
+      sp->max_burst_size -= sent;
     }
 
   /* Not finished sending all data */
@@ -673,12 +679,10 @@ static session_cb_vft_t http_app_cb_vft = {
 static clib_error_t *
 http_transport_enable (vlib_main_t *vm, u8 is_en)
 {
-  u32 add_segment_size = 256 << 20, first_seg_size = 32 << 20;
   vnet_app_detach_args_t _da, *da = &_da;
   vnet_app_attach_args_t _a, *a = &_a;
   u64 options[APP_OPTIONS_N_OPTIONS];
   http_main_t *hm = &http_main;
-  u32 fifo_size = 128 << 12;
 
   if (!is_en)
     {
@@ -690,9 +694,6 @@ http_transport_enable (vlib_main_t *vm, u8 is_en)
 
   vec_validate (hm->wrk, vlib_num_workers ());
 
-  first_seg_size = hm->first_seg_size ? hm->first_seg_size : first_seg_size;
-  fifo_size = hm->fifo_size ? hm->fifo_size : fifo_size;
-
   clib_memset (a, 0, sizeof (*a));
   clib_memset (options, 0, sizeof (options));
 
@@ -700,10 +701,10 @@ http_transport_enable (vlib_main_t *vm, u8 is_en)
   a->api_client_index = APP_INVALID_INDEX;
   a->options = options;
   a->name = format (0, "http");
-  a->options[APP_OPTIONS_SEGMENT_SIZE] = first_seg_size;
-  a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = add_segment_size;
-  a->options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
-  a->options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
+  a->options[APP_OPTIONS_SEGMENT_SIZE] = hm->first_seg_size;
+  a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = hm->add_seg_size;
+  a->options[APP_OPTIONS_RX_FIFO_SIZE] = hm->fifo_size;
+  a->options[APP_OPTIONS_TX_FIFO_SIZE] = hm->fifo_size;
   a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
   a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
   a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_IS_TRANSPORT_APP;
@@ -729,10 +730,10 @@ http_transport_connect (transport_endpoint_cfg_t *tep)
 }
 
 static u32
-http_start_listen (u32 app_listener_index, transport_endpoint_t *tep)
+http_start_listen (u32 app_listener_index, transport_endpoint_cfg_t *tep)
 {
   vnet_listen_args_t _args = {}, *args = &_args;
-  session_t *tc_listener, *app_listener;
+  session_t *ts_listener, *app_listener;
   http_main_t *hm = &http_main;
   session_endpoint_cfg_t *sep;
   app_worker_t *app_wrk;
@@ -762,13 +763,14 @@ http_start_listen (u32 app_listener_index, transport_endpoint_t *tep)
   /* Grab transport connection listener and link to http listener */
   lhc->h_tc_session_handle = args->handle;
   al = app_listener_get_w_handle (lhc->h_tc_session_handle);
-  tc_listener = app_listener_get_session (al);
-  tc_listener->opaque = lhc_index;
+  ts_listener = app_listener_get_session (al);
+  ts_listener->opaque = lhc_index;
 
   /* Grab application listener and link to http listener */
   app_listener = listen_session_get (app_listener_index);
   lhc->h_pa_wrk_index = sep->app_wrk_index;
   lhc->h_pa_session_handle = listen_session_get_handle (app_listener);
+  lhc->c_s_index = app_listener_index;
   lhc->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
 
   return lhc_index;
@@ -816,6 +818,7 @@ static int
 http_app_tx_callback (void *session, transport_send_params_t *sp)
 {
   session_t *as = (session_t *) session;
+  u32 max_burst_sz, sent;
   http_conn_t *hc;
 
   hc = http_conn_get_w_thread (as->connection_index, as->thread_index);
@@ -825,6 +828,9 @@ http_app_tx_callback (void *session, transport_send_params_t *sp)
       return 0;
     }
 
+  max_burst_sz = sp->max_burst_size * TRANSPORT_PACER_MIN_MSS;
+  sp->max_burst_size = max_burst_sz;
+
   http_req_run_state_machine (hc, sp);
 
   if (hc->state == HTTP_CONN_STATE_CLOSED)
@@ -832,7 +838,10 @@ http_app_tx_callback (void *session, transport_send_params_t *sp)
       if (!svm_fifo_max_dequeue_cons (as->rx_fifo))
        http_disconnect_transport (hc);
     }
-  return 0;
+
+  sent = max_burst_sz - sp->max_burst_size;
+
+  return sent > 0 ? clib_max (sent / TRANSPORT_PACER_MIN_MSS, 1) : 0;
 }
 
 static void
@@ -965,15 +974,60 @@ static const transport_proto_vft_t http_proto = {
 static clib_error_t *
 http_transport_init (vlib_main_t *vm)
 {
+  http_main_t *hm = &http_main;
+
   transport_register_protocol (TRANSPORT_PROTO_HTTP, &http_proto,
                               FIB_PROTOCOL_IP4, ~0);
   transport_register_protocol (TRANSPORT_PROTO_HTTP, &http_proto,
                               FIB_PROTOCOL_IP6, ~0);
+
+  /* Default values, configurable via startup conf */
+  hm->add_seg_size = 256 << 20;
+  hm->first_seg_size = 32 << 20;
+  hm->fifo_size = 512 << 10;
+
   return 0;
 }
 
 VLIB_INIT_FUNCTION (http_transport_init);
 
+static clib_error_t *
+http_config_fn (vlib_main_t *vm, unformat_input_t *input)
+{
+  http_main_t *hm = &http_main;
+  uword mem_sz;
+
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "first-segment-size %U", unformat_memory_size,
+                   &mem_sz))
+       {
+         hm->first_seg_size = clib_max (mem_sz, 1 << 20);
+         if (hm->first_seg_size != mem_sz)
+           clib_warning ("first seg size too small %u", mem_sz);
+       }
+      else if (unformat (input, "add-segment-size %U", unformat_memory_size,
+                        &mem_sz))
+       {
+         hm->add_seg_size = clib_max (mem_sz, 1 << 20);
+         if (hm->add_seg_size != mem_sz)
+           clib_warning ("add seg size too small %u", mem_sz);
+       }
+      else if (unformat (input, "fifo-size %U", unformat_memory_size, &mem_sz))
+       {
+         hm->fifo_size = clib_clamp (mem_sz, 4 << 10, 2 << 30);
+         if (hm->fifo_size != mem_sz)
+           clib_warning ("invalid fifo size %lu", mem_sz);
+       }
+      else
+       return clib_error_return (0, "unknown input `%U'",
+                                 format_unformat_error, input);
+    }
+  return 0;
+}
+
+VLIB_EARLY_CONFIG_FUNCTION (http_config_fn, "http");
+
 VLIB_PLUGIN_REGISTER () = {
   .version = VPP_BUILD_VER,
   .description = "Hypertext Transfer Protocol (HTTP)",