X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fsession-apps%2Fhttp_server.c;h=37441bb2188533773529f2d44433ec13bc639a92;hb=fa76a76;hp=eeb755b0fc47b2ffb3cfdd5fe66aa9ddfe0ec190;hpb=f8f516a8b0ccab2f5d9796f90419bf2661c750af;p=vpp.git diff --git a/src/vnet/session-apps/http_server.c b/src/vnet/session-apps/http_server.c index eeb755b0fc4..37441bb2188 100644 --- a/src/vnet/session-apps/http_server.c +++ b/src/vnet/session-apps/http_server.c @@ -32,7 +32,7 @@ typedef struct typedef struct { u8 **rx_buf; - svm_queue_t **vpp_queue; + svm_msg_q_t **vpp_queue; u64 byte_index; uword *handler_by_get_request; @@ -53,6 +53,7 @@ typedef struct u32 prealloc_fifos; u32 private_segment_size; u32 fifo_size; + u8 *uri; vlib_main_t *vlib_main; } http_server_main_t; @@ -86,30 +87,37 @@ free_http_process (http_server_args * args) vec_add1 (hsm->free_http_cli_process_node_indices, node_index); } -static const char - *http_response = "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" - "Connection: close\r\n" - "Pragma: no-cache\r\n" "Content-Length: %d\r\n\r\n%s"; - -static const char - *http_error_template = "HTTP/1.1 %s\r\n" - "Content-Type: text/html\r\n" - "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" - "Connection: close\r\n" "Pragma: no-cache\r\n" "Content-Length: 0\r\n\r\n"; +/* *INDENT-OFF* */ +static const char *http_response = + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" + "Connection: keep-alive \r\n" + "Pragma: no-cache\r\n" + "Content-Length: %d\r\n\r\n%s"; + +static const char *http_error_template = + "HTTP/1.1 %s\r\n" + "Content-Type: text/html\r\n" + "Expires: Mon, 11 Jan 1970 10:10:10 GMT\r\n" + "Connection: close\r\n" + "Pragma: no-cache\r\n" + "Content-Length: 0\r\n\r\n"; /* Header, including incantation to suppress favicon.ico requests */ -static const char - *html_header_template = "%v" - "
";
-
-static const char *html_footer = "
\r\n"; - -static const char - *html_header_static = "static reply" - "
hello
" - "\r\n"; +static const char *html_header_template = + "%v" + "" + "
";
+
+static const char *html_footer =
+    "
\r\n"; + +static const char *html_header_static = + "static reply" + "" + "
hello
\r\n"; +/* *INDENT-ON* */ static u8 *static_http; @@ -124,7 +132,7 @@ http_cli_output (uword arg, u8 * buffer, uword buffer_bytes) offset = vec_len (output_vec); vec_validate (output_vec, offset + buffer_bytes - 1); - clib_memcpy (output_vec + offset, buffer, buffer_bytes); + clib_memcpy_fast (output_vec + offset, buffer, buffer_bytes); *output_vecp = output_vec; } @@ -132,7 +140,6 @@ http_cli_output (uword arg, u8 * buffer, uword buffer_bytes) void send_data (stream_session_t * s, u8 * data) { - session_fifo_event_t evt; u32 offset, bytes_to_send; f64 delay = 10e-3; http_server_main_t *hsm = &http_server_main; @@ -170,14 +177,8 @@ send_data (stream_session_t * s, u8 * data) bytes_to_send -= actual_transfer; if (svm_fifo_set_event (s->server_tx_fifo)) - { - /* Fabricate TX event, send to vpp */ - evt.fifo = s->server_tx_fifo; - evt.event_type = FIFO_EVENT_APP_TX; - - svm_queue_add (hsm->vpp_queue[s->thread_index], - (u8 *) & evt, 0 /* do wait for mutex */ ); - } + session_send_io_evt_to_thread (s->server_tx_fifo, + FIFO_EVENT_APP_TX); delay = 10e-3; } } @@ -371,15 +372,7 @@ http_server_rx_callback (stream_session_t * s) /* Send an RPC request via the thread-0 input node */ if (vlib_get_thread_index () != 0) - { - session_fifo_event_t evt; - evt.rpc_args.fp = alloc_http_process_callback; - evt.rpc_args.arg = args; - evt.event_type = FIFO_EVENT_RPC; - svm_queue_add - (session_manager_get_vpp_event_queue (0 /* main thread */ ), - (u8 *) & evt, 0 /* do wait for mutex */ ); - } + session_send_rpc_evt_to_thread (0, alloc_http_process_callback, args); else alloc_http_process (args); return 0; @@ -465,7 +458,7 @@ http_server_session_connected_callback (u32 app_index, u32 api_context, } static int -http_server_add_segment_callback (u32 client_index, const ssvm_private_t * sp) +http_server_add_segment_callback (u32 client_index, u64 segment_handle) { clib_warning ("called..."); return -1; @@ -476,7 +469,7 @@ static session_cb_vft_t http_server_session_cb_vft = { .session_disconnect_callback = http_server_session_disconnect_callback, .session_connected_callback = http_server_session_connected_callback, .add_segment_callback = http_server_add_segment_callback, - .builtin_server_rx_callback = http_server_rx_callback, + .builtin_app_rx_callback = http_server_rx_callback, .session_reset_callback = http_server_session_reset_callback }; @@ -498,13 +491,15 @@ create_api_loopback (vlib_main_t * vm) static int server_attach () { + vnet_app_add_tls_cert_args_t _a_cert, *a_cert = &_a_cert; + vnet_app_add_tls_key_args_t _a_key, *a_key = &_a_key; http_server_main_t *hsm = &http_server_main; u64 options[APP_OPTIONS_N_OPTIONS]; vnet_app_attach_args_t _a, *a = &_a; u32 segment_size = 128 << 20; - memset (a, 0, sizeof (*a)); - memset (options, 0, sizeof (options)); + clib_memset (a, 0, sizeof (*a)); + clib_memset (options, 0, sizeof (options)); if (hsm->private_segment_size) segment_size = hsm->private_segment_size; @@ -526,6 +521,19 @@ server_attach () return -1; } hsm->app_index = a->app_index; + + clib_memset (a_cert, 0, sizeof (*a_cert)); + a_cert->app_index = a->app_index; + vec_validate (a_cert->cert, test_srv_crt_rsa_len); + clib_memcpy_fast (a_cert->cert, test_srv_crt_rsa, test_srv_crt_rsa_len); + vnet_app_add_tls_cert (a_cert); + + clib_memset (a_key, 0, sizeof (*a_key)); + a_key->app_index = a->app_index; + vec_validate (a_key->key, test_srv_key_rsa_len); + clib_memcpy_fast (a_key->key, test_srv_key_rsa, test_srv_key_rsa_len); + vnet_app_add_tls_key (a_key); + return 0; } @@ -534,9 +542,11 @@ http_server_listen () { http_server_main_t *hsm = &http_server_main; vnet_bind_args_t _a, *a = &_a; - memset (a, 0, sizeof (*a)); + clib_memset (a, 0, sizeof (*a)); a->app_index = hsm->app_index; a->uri = "tcp://0.0.0.0/80"; + if (hsm->uri) + a->uri = (char *) hsm->uri; return vnet_bind_uri (a); } @@ -599,6 +609,8 @@ http_server_create_command_fn (vlib_main_t * vm, } else if (unformat (input, "fifo-size %d", &hsm->fifo_size)) hsm->fifo_size <<= 10; + else if (unformat (input, "uri %s", &hsm->uri)) + ; else return clib_error_return (0, "unknown input `%U'", format_unformat_error, input); @@ -610,7 +622,7 @@ http_server_create_command_fn (vlib_main_t * vm, if (is_static) { - http_server_session_cb_vft.builtin_server_rx_callback = + http_server_session_cb_vft.builtin_app_rx_callback = http_server_rx_callback_static; html = format (0, html_header_static); static_http = format (0, http_response, vec_len (html), html);