2 * Copyright (c) 2022 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <http/http.h>
17 #include <vnet/session/session.h>
18 #include <http/http_timer.h>
20 static http_main_t http_main;
22 const char *http_status_code_str[] = {
23 #define _(c, s, str) str,
24 foreach_http_status_code
28 const char *http_content_type_str[] = {
29 #define _(s, str) str,
30 foreach_http_content_type
34 static inline http_worker_t *
35 http_worker_get (u32 thread_index)
37 return &http_main.wrk[thread_index];
41 http_conn_alloc_w_thread (u32 thread_index)
43 http_worker_t *wrk = http_worker_get (thread_index);
46 pool_get_zero (wrk->conn_pool, hc);
47 hc->c_thread_index = thread_index;
48 hc->h_hc_index = hc - wrk->conn_pool;
49 hc->h_pa_session_handle = SESSION_INVALID_HANDLE;
50 hc->h_tc_session_handle = SESSION_INVALID_HANDLE;
51 return hc->h_hc_index;
54 static inline http_conn_t *
55 http_conn_get_w_thread (u32 hc_index, u32 thread_index)
57 http_worker_t *wrk = http_worker_get (thread_index);
58 return pool_elt_at_index (wrk->conn_pool, hc_index);
62 http_conn_free (http_conn_t *hc)
64 http_worker_t *wrk = http_worker_get (hc->c_thread_index);
65 pool_put (wrk->conn_pool, hc);
69 http_listener_alloc (void)
71 http_main_t *hm = &http_main;
74 pool_get_zero (hm->listener_ctx_pool, ctx);
75 ctx->c_c_index = ctx - hm->listener_ctx_pool;
76 return ctx->c_c_index;
80 http_listener_get (u32 ctx_index)
82 return pool_elt_at_index (http_main.listener_ctx_pool, ctx_index);
86 http_disconnect_transport (http_conn_t *hc)
88 vnet_disconnect_args_t a = {
89 .handle = hc->h_tc_session_handle,
90 .app_index = http_main.app_index,
93 hc->state = HTTP_CONN_STATE_CLOSED;
95 if (vnet_disconnect_session (&a))
96 clib_warning ("disconnect returned");
100 http_buffer_init (http_buffer_t *hb, svm_fifo_t *f, u32 data_len)
110 http_buffer_free (http_buffer_t *hb)
117 http_buffer_get_segs (http_buffer_t *hb, u32 max_len, u32 *n_segs)
122 max_len = clib_max (hb->len - hb->offset, max_len);
124 vec_validate (hb->segs, _n_segs);
126 len = svm_fifo_segments (hb->src, 0, hb->segs, &_n_segs, max_len);
132 HTTP_DBG (1, "available to send %u n_segs %u", len, *n_segs);
138 http_buffer_drain (http_buffer_t *hb, u32 len)
141 svm_fifo_dequeue_drop (hb->src, len);
142 HTTP_DBG (1, "drained %u len %u offset %u", len, hb->len, hb->offset);
146 http_buffer_is_drained (http_buffer_t *hb)
148 ASSERT (hb->offset <= hb->len);
149 return (hb->offset == hb->len);
153 http_conn_timeout_cb (void *hc_handlep)
158 hs_handle = pointer_to_uword (hc_handlep);
159 hc = http_conn_get_w_thread (hs_handle & 0x00FFFFFF, hs_handle >> 24);
161 HTTP_DBG (1, "terminate thread %d index %d hs %llx", hs_handle >> 24,
162 hs_handle & 0x00FFFFFF, hc);
166 hc->timer_handle = ~0;
167 session_transport_closing_notify (&hc->connection);
168 http_disconnect_transport (hc);
172 http_ts_accept_callback (session_t *ts)
174 session_t *ts_listener, *as, *asl;
175 app_worker_t *app_wrk;
176 http_conn_t *lhc, *hc;
180 ts_listener = listen_session_get_from_handle (ts->listener_handle);
181 lhc = http_listener_get (ts_listener->opaque);
183 hc_index = http_conn_alloc_w_thread (ts->thread_index);
184 hc = http_conn_get_w_thread (hc_index, ts->thread_index);
185 clib_memcpy_fast (hc, lhc, sizeof (*lhc));
186 hc->c_thread_index = vlib_get_thread_index ();
187 hc->h_hc_index = hc_index;
189 hc->h_tc_session_handle = session_handle (ts);
190 hc->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
192 hc->state = HTTP_CONN_STATE_ESTABLISHED;
193 hc->req_state = HTTP_REQ_STATE_WAIT_METHOD;
195 ts->session_state = SESSION_STATE_READY;
196 ts->opaque = hc_index;
199 * Alloc session and initialize
201 as = session_alloc (hc->c_thread_index);
202 as->session_state = SESSION_STATE_CREATED;
203 hc->c_s_index = as->session_index;
205 as->app_wrk_index = hc->h_pa_wrk_index;
206 as->connection_index = hc->c_c_index;
207 as->session_state = SESSION_STATE_ACCEPTING;
209 asl = listen_session_get_from_handle (lhc->h_pa_session_handle);
210 as->session_type = asl->session_type;
211 as->listener_handle = lhc->h_pa_session_handle;
214 * Init session fifos and notify app
216 if ((rv = app_worker_init_accepted (as)))
218 HTTP_DBG (1, "failed to allocate fifos");
223 hc->h_pa_session_handle = session_handle (as);
224 hc->h_pa_wrk_index = as->app_wrk_index;
225 app_wrk = app_worker_get (as->app_wrk_index);
227 HTTP_DBG (1, "Accepted on listener %u new connection [%u]%x",
228 ts_listener->opaque, vlib_get_thread_index (), hc_index);
230 if ((rv = app_worker_accept_notify (app_wrk, as)))
232 HTTP_DBG (0, "app accept returned");
237 http_conn_timer_start (hc);
243 http_ts_connected_callback (u32 http_app_index, u32 hc_index, session_t *ts,
246 clib_warning ("not supported");
251 http_ts_disconnect_callback (session_t *ts)
255 hc = http_conn_get_w_thread (ts->opaque, ts->thread_index);
257 if (hc->state < HTTP_CONN_STATE_TRANSPORT_CLOSED)
258 hc->state = HTTP_CONN_STATE_TRANSPORT_CLOSED;
260 if (!svm_fifo_max_dequeue_cons (ts->rx_fifo))
261 session_transport_closing_notify (&hc->connection);
265 http_ts_reset_callback (session_t *ts)
269 ctx = http_conn_get_w_thread (ts->opaque, ts->thread_index);
271 if (ctx->state < HTTP_CONN_STATE_TRANSPORT_CLOSED)
272 ctx->state = HTTP_CONN_STATE_TRANSPORT_CLOSED;
274 if (!svm_fifo_max_dequeue_cons (ts->rx_fifo))
275 session_transport_reset_notify (&ctx->connection);
279 * http error boilerplate
281 static const char *http_error_template = "HTTP/1.1 %s\r\n"
283 "Content-Type: text/html\r\n"
284 "Connection: close\r\n"
285 "Pragma: no-cache\r\n"
286 "Content-Length: 0\r\n\r\n";
289 * http response boilerplate
291 static const char *http_response_template = "HTTP/1.1 200 OK\r\n"
293 "Expires: %U GMT\r\n"
294 "Server: VPP Static\r\n"
295 "Content-Type: %s\r\n"
296 "Content-Length: %d\r\n\r\n";
299 send_data (http_conn_t *hc, u8 *data, u32 length, u32 offset)
301 const u32 max_burst = 64 << 10;
306 ts = session_get_from_handle (hc->h_tc_session_handle);
308 to_send = clib_min (length - offset, max_burst);
309 sent = svm_fifo_enqueue (ts->tx_fifo, to_send, data + offset);
314 if (svm_fifo_set_event (ts->tx_fifo))
315 session_send_io_evt_to_thread (ts->tx_fifo, SESSION_IO_EVT_TX);
317 return (offset + sent);
321 send_error (http_conn_t *hc, http_status_code_t ec)
323 http_main_t *hm = &http_main;
327 if (ec >= HTTP_N_STATUS)
328 ec = HTTP_STATUS_INTERNAL_ERROR;
330 now = clib_timebase_now (&hm->timebase);
331 data = format (0, http_error_template, http_status_code_str[ec],
332 format_clib_timebase_time, now);
333 send_data (hc, data, vec_len (data), 0);
338 read_request (http_conn_t *hc)
340 u32 max_deq, cursize;
344 ts = session_get_from_handle (hc->h_tc_session_handle);
346 cursize = vec_len (hc->rx_buf);
347 max_deq = svm_fifo_max_dequeue (ts->rx_fifo);
348 if (PREDICT_FALSE (max_deq == 0))
351 vec_validate (hc->rx_buf, cursize + max_deq - 1);
352 n_read = svm_fifo_dequeue (ts->rx_fifo, max_deq, hc->rx_buf + cursize);
353 ASSERT (n_read == max_deq);
355 if (svm_fifo_is_empty (ts->rx_fifo))
356 svm_fifo_unset_event (ts->rx_fifo);
358 _vec_len (hc->rx_buf) = cursize + n_read;
363 v_find_index (u8 *vec, u32 offset, char *str)
365 int start_index = offset;
366 u32 slen = (u32) strnlen_s_inline (str, 8);
367 u32 vlen = vec_len (vec);
374 for (; start_index < (vlen - slen); start_index++)
376 if (!memcmp (vec + start_index, str, slen))
384 * waiting for request method from peer - parse request method and data
387 state_wait_method (http_conn_t *hc, transport_send_params_t *sp)
389 http_status_code_t ec;
390 app_worker_t *app_wrk;
397 rv = read_request (hc);
399 /* Nothing yet, wait for data or timer expire */
403 if (vec_len (hc->rx_buf) < 8)
405 ec = HTTP_STATUS_BAD_REQUEST;
409 if ((i = v_find_index (hc->rx_buf, 0, "GET ")) >= 0)
411 hc->method = HTTP_REQ_GET;
412 hc->rx_buf_offset = i + 5;
414 i = v_find_index (hc->rx_buf, hc->rx_buf_offset, "HTTP");
417 ec = HTTP_STATUS_BAD_REQUEST;
421 len = i - hc->rx_buf_offset;
423 else if ((i = v_find_index (hc->rx_buf, 0, "POST ")) >= 0)
425 hc->method = HTTP_REQ_POST;
426 hc->rx_buf_offset = i + 6;
427 len = vec_len (hc->rx_buf) - hc->rx_buf_offset;
431 HTTP_DBG (0, "Unknown http method");
432 ec = HTTP_STATUS_METHOD_NOT_ALLOWED;
436 buf = &hc->rx_buf[hc->rx_buf_offset];
438 msg.type = HTTP_MSG_REQUEST;
439 msg.method_type = hc->method;
440 msg.data.content_type = HTTP_CONTENT_TEXT_HTML;
444 svm_fifo_seg_t segs[2] = { { (u8 *) &msg, sizeof (msg) }, { buf, len } };
446 as = session_get_from_handle (hc->h_pa_session_handle);
447 rv = svm_fifo_enqueue_segments (as->rx_fifo, segs, 2, 0 /* allow partial */);
448 if (rv < 0 || rv != sizeof (msg) + len)
450 clib_warning ("failed app enqueue");
451 /* This should not happen as we only handle 1 request per session,
452 * and fifo is allocated, but going forward we should consider
457 vec_free (hc->rx_buf);
458 hc->req_state = HTTP_REQ_STATE_WAIT_APP;
460 app_wrk = app_worker_get_if_valid (as->app_wrk_index);
461 app_worker_lock_and_send_event (app_wrk, as, SESSION_IO_EVT_RX);
468 session_transport_closing_notify (&hc->connection);
469 http_disconnect_transport (hc);
475 * waiting for data from app
478 state_wait_app (http_conn_t *hc, transport_send_params_t *sp)
480 http_main_t *hm = &http_main;
481 http_status_code_t ec;
489 as = session_get_from_handle (hc->h_pa_session_handle);
491 rv = svm_fifo_dequeue (as->tx_fifo, sizeof (msg), (u8 *) &msg);
492 ASSERT (rv == sizeof (msg));
494 if (msg.type != HTTP_MSG_REPLY)
496 clib_warning ("unexpected msg type from app %u", msg.type);
497 ec = HTTP_STATUS_INTERNAL_ERROR;
501 if (msg.code != HTTP_STATUS_OK)
507 http_buffer_init (&hc->tx_buf, as->tx_fifo, msg.data.len);
510 * Add headers. For now:
516 now = clib_timebase_now (&hm->timebase);
517 header = format (0, http_response_template,
519 format_clib_timebase_time, now,
521 format_clib_timebase_time, now + 600.0,
523 http_content_type_str[msg.data.content_type],
527 offset = send_data (hc, header, vec_len (header), 0);
528 if (offset != vec_len (header))
530 clib_warning ("couldn't send response header!");
531 ec = HTTP_STATUS_INTERNAL_ERROR;
536 /* Start sending the actual data */
537 hc->req_state = HTTP_REQ_STATE_SEND_MORE_DATA;
544 hc->req_state = HTTP_REQ_STATE_WAIT_METHOD;
545 session_transport_closing_notify (&hc->connection);
546 http_disconnect_transport (hc);
548 /* stop state machine processing */
553 state_send_more_data (http_conn_t *hc, transport_send_params_t *sp)
555 u32 max_send = 64 << 10, n_segs;
556 http_buffer_t *hb = &hc->tx_buf;
561 ts = session_get_from_handle (hc->h_tc_session_handle);
562 if ((seg = http_buffer_get_segs (hb, max_send, &n_segs)))
563 sent = svm_fifo_enqueue_segments (ts->tx_fifo, seg, n_segs,
564 1 /* allow partial */);
568 http_buffer_drain (hb, sent);
570 /* Ask scheduler to notify app of deq event if needed */
571 sp->max_burst_size = sent;
575 sp->max_burst_size = 0;
578 /* Not finished sending all data */
579 if (!http_buffer_is_drained (hb))
581 if (sent && svm_fifo_set_event (ts->tx_fifo))
582 session_send_io_evt_to_thread (ts->tx_fifo, SESSION_IO_EVT_TX);
584 if (svm_fifo_max_enqueue (ts->tx_fifo) < 16 << 10)
586 /* Deschedule http session and wait for deq notification if
587 * underlying ts tx fifo almost full */
588 svm_fifo_add_want_deq_ntf (ts->tx_fifo, SVM_FIFO_WANT_DEQ_NOTIF);
589 transport_connection_deschedule (&hc->connection);
590 sp->flags |= TRANSPORT_SND_F_DESCHED;
595 if (sent && svm_fifo_set_event (ts->tx_fifo))
596 session_send_io_evt_to_thread (ts->tx_fifo, SESSION_IO_EVT_TX_FLUSH);
598 /* Finished transaction, back to HTTP_REQ_STATE_WAIT_METHOD */
599 hc->req_state = HTTP_REQ_STATE_WAIT_METHOD;
600 http_buffer_free (&hc->tx_buf);
606 typedef int (*http_sm_handler) (http_conn_t *, transport_send_params_t *sp);
608 static http_sm_handler req_state_funcs[HTTP_REQ_N_STATES] = {
609 /* Waiting for GET, POST, etc. */
611 /* Wait for data from app */
614 state_send_more_data,
618 http_req_run_state_machine (http_conn_t *hc, transport_send_params_t *sp)
624 rv = req_state_funcs[hc->req_state](hc, sp);
630 /* Reset the session expiration timer */
631 http_conn_timer_update (hc);
635 http_ts_rx_callback (session_t *ts)
639 hc = http_conn_get_w_thread (ts->opaque, ts->thread_index);
641 if (hc->req_state != HTTP_REQ_STATE_WAIT_METHOD)
643 clib_warning ("tcp data in req state %u", hc->req_state);
647 http_req_run_state_machine (hc, 0);
649 if (hc->state == HTTP_CONN_STATE_TRANSPORT_CLOSED)
651 if (!svm_fifo_max_dequeue_cons (ts->rx_fifo))
652 session_transport_closing_notify (&hc->connection);
658 http_ts_builtin_tx_callback (session_t *ts)
662 hc = http_conn_get_w_thread (ts->opaque, ts->thread_index);
663 transport_connection_reschedule (&hc->connection);
669 http_ts_cleanup_callback (session_t *ts, session_cleanup_ntf_t ntf)
673 if (ntf == SESSION_CLEANUP_TRANSPORT)
676 hc = http_conn_get_w_thread (ts->opaque, ts->thread_index);
679 clib_warning ("no http connection for %u", ts->session_index);
683 vec_free (hc->rx_buf);
685 http_buffer_free (&hc->tx_buf);
686 http_conn_timer_stop (hc);
688 session_transport_delete_notify (&hc->connection);
693 http_add_segment_callback (u32 client_index, u64 segment_handle)
695 /* No-op for builtin */
700 http_del_segment_callback (u32 client_index, u64 segment_handle)
705 static session_cb_vft_t http_app_cb_vft = {
706 .session_accept_callback = http_ts_accept_callback,
707 .session_disconnect_callback = http_ts_disconnect_callback,
708 .session_connected_callback = http_ts_connected_callback,
709 .session_reset_callback = http_ts_reset_callback,
710 .session_cleanup_callback = http_ts_cleanup_callback,
711 .add_segment_callback = http_add_segment_callback,
712 .del_segment_callback = http_del_segment_callback,
713 .builtin_app_rx_callback = http_ts_rx_callback,
714 .builtin_app_tx_callback = http_ts_builtin_tx_callback,
717 static clib_error_t *
718 http_transport_enable (vlib_main_t *vm, u8 is_en)
720 u32 add_segment_size = 256 << 20, first_seg_size = 32 << 20;
721 vnet_app_detach_args_t _da, *da = &_da;
722 vnet_app_attach_args_t _a, *a = &_a;
723 u64 options[APP_OPTIONS_N_OPTIONS];
724 http_main_t *hm = &http_main;
725 u32 fifo_size = 128 << 12;
729 da->app_index = hm->app_index;
730 da->api_client_index = APP_INVALID_INDEX;
731 vnet_application_detach (da);
735 vec_validate (hm->wrk, vlib_num_workers ());
737 first_seg_size = hm->first_seg_size ? hm->first_seg_size : first_seg_size;
738 fifo_size = hm->fifo_size ? hm->fifo_size : fifo_size;
740 clib_memset (a, 0, sizeof (*a));
741 clib_memset (options, 0, sizeof (options));
743 a->session_cb_vft = &http_app_cb_vft;
744 a->api_client_index = APP_INVALID_INDEX;
745 a->options = options;
746 a->name = format (0, "http");
747 a->options[APP_OPTIONS_SEGMENT_SIZE] = first_seg_size;
748 a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = add_segment_size;
749 a->options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
750 a->options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
751 a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
752 a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
753 a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_IS_TRANSPORT_APP;
755 if (vnet_application_attach (a))
756 return clib_error_return (0, "failed to attach http app");
758 hm->app_index = a->app_index;
761 clib_timebase_init (&hm->timebase, 0 /* GMT */, CLIB_TIMEBASE_DAYLIGHT_NONE,
762 &vm->clib_time /* share the system clock */);
764 http_timers_init (vm, http_conn_timeout_cb);
770 http_transport_connect (transport_endpoint_cfg_t *tep)
776 http_start_listen (u32 app_listener_index, transport_endpoint_t *tep)
778 vnet_listen_args_t _args = {}, *args = &_args;
779 session_t *tc_listener, *app_listener;
780 http_main_t *hm = &http_main;
781 session_endpoint_cfg_t *sep;
782 app_worker_t *app_wrk;
783 transport_proto_t tp;
789 sep = (session_endpoint_cfg_t *) tep;
791 app_wrk = app_worker_get (sep->app_wrk_index);
792 app = application_get (app_wrk->app_index);
794 args->app_index = hm->app_index;
795 args->sep_ext = *sep;
796 args->sep_ext.ns_index = app->ns_index;
797 tp = sep->ext_cfg ? TRANSPORT_PROTO_TLS : TRANSPORT_PROTO_TCP;
798 args->sep_ext.transport_proto = tp;
800 if (vnet_listen (args))
801 return SESSION_INVALID_INDEX;
803 lhc_index = http_listener_alloc ();
804 lhc = http_listener_get (lhc_index);
806 /* Grab transport connection listener and link to http listener */
807 lhc->h_tc_session_handle = args->handle;
808 al = app_listener_get_w_handle (lhc->h_tc_session_handle);
809 tc_listener = app_listener_get_session (al);
810 tc_listener->opaque = lhc_index;
812 /* Grab application listener and link to http listener */
813 app_listener = listen_session_get (app_listener_index);
814 lhc->h_pa_wrk_index = sep->app_wrk_index;
815 lhc->h_pa_session_handle = listen_session_get_handle (app_listener);
816 lhc->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
822 http_transport_close (u32 hc_index, u32 thread_index)
827 HTTP_DBG (1, "App disconnecting %x", hc_index);
829 hc = http_conn_get_w_thread (hc_index, thread_index);
830 as = session_get_from_handle (hc->h_pa_session_handle);
832 /* Nothing more to send, confirm close */
833 if (!svm_fifo_max_dequeue_cons (as->tx_fifo))
835 session_transport_closed_notify (&hc->connection);
836 http_disconnect_transport (hc);
840 /* Wait for all data to be written to ts */
841 hc->state = HTTP_CONN_STATE_APP_CLOSED;
845 static transport_connection_t *
846 http_transport_get_connection (u32 hc_index, u32 thread_index)
848 http_conn_t *hc = http_conn_get_w_thread (hc_index, thread_index);
849 return &hc->connection;
852 static transport_connection_t *
853 http_transport_get_listener (u32 listener_index)
855 http_conn_t *lhc = http_listener_get (listener_index);
856 return &lhc->connection;
860 http_app_tx_callback (void *session, transport_send_params_t *sp)
862 session_t *as = (session_t *) session;
867 hc = http_conn_get_w_thread (as->connection_index, as->thread_index);
868 if (hc->req_state < HTTP_REQ_STATE_WAIT_APP)
870 clib_warning ("app data in req state %u", hc->req_state);
874 http_req_run_state_machine (hc, sp);
876 if (hc->state == HTTP_CONN_STATE_CLOSED)
878 if (!svm_fifo_max_dequeue_cons (as->rx_fifo))
879 http_disconnect_transport (hc);
885 format_http_connection (u8 *s, va_list *args)
887 http_conn_t *hc = va_arg (*args, http_conn_t *);
890 ts = session_get_from_handle (hc->h_tc_session_handle);
891 s = format (s, "[%d:%d][H] app_wrk %u ts %d:%d", hc->c_thread_index,
892 hc->c_s_index, hc->h_pa_wrk_index, ts->thread_index,
899 format_http_listener (u8 *s, va_list *args)
901 http_conn_t *lhc = va_arg (*args, http_conn_t *);
905 al = app_listener_get_w_handle (lhc->h_tc_session_handle);
906 lts = app_listener_get_session (al);
907 s = format (s, "[%d:%d][H] app_wrk %u ts %d:%d", lhc->c_thread_index,
908 lhc->c_s_index, lhc->h_pa_wrk_index, lts->thread_index,
915 format_http_conn_state (u8 *s, va_list *args)
917 http_conn_t *hc = va_arg (*args, http_conn_t *);
921 case HTTP_CONN_STATE_LISTEN:
922 s = format (s, "LISTEN");
924 case HTTP_CONN_STATE_CONNECTING:
925 s = format (s, "CONNECTING");
927 case HTTP_CONN_STATE_ESTABLISHED:
928 s = format (s, "ESTABLISHED");
930 case HTTP_CONN_STATE_TRANSPORT_CLOSED:
931 s = format (s, "TRANSPORT_CLOSED");
933 case HTTP_CONN_STATE_APP_CLOSED:
934 s = format (s, "APP_CLOSED");
936 case HTTP_CONN_STATE_CLOSED:
937 s = format (s, "CLOSED");
945 format_http_transport_connection (u8 *s, va_list *args)
947 u32 tc_index = va_arg (*args, u32);
948 u32 thread_index = va_arg (*args, u32);
949 u32 verbose = va_arg (*args, u32);
952 hc = http_conn_get_w_thread (tc_index, thread_index);
954 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_http_connection, hc);
958 format (s, "%-" SESSION_CLI_STATE_LEN "U", format_http_conn_state, hc);
960 s = format (s, "\n");
967 format_http_transport_listener (u8 *s, va_list *args)
969 u32 tc_index = va_arg (*args, u32);
970 u32 __clib_unused thread_index = va_arg (*args, u32);
971 u32 __clib_unused verbose = va_arg (*args, u32);
972 http_conn_t *lhc = http_listener_get (tc_index);
974 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_http_listener, lhc);
977 format (s, "%-" SESSION_CLI_STATE_LEN "U", format_http_conn_state, lhc);
981 static const transport_proto_vft_t http_proto = {
982 .enable = http_transport_enable,
983 .connect = http_transport_connect,
984 .start_listen = http_start_listen,
985 .close = http_transport_close,
986 .custom_tx = http_app_tx_callback,
987 .get_connection = http_transport_get_connection,
988 .get_listener = http_transport_get_listener,
989 .format_connection = format_http_transport_connection,
990 .format_listener = format_http_transport_listener,
991 .transport_options = {
994 .tx_type = TRANSPORT_TX_INTERNAL,
995 .service_type = TRANSPORT_SERVICE_APP,
999 static clib_error_t *
1000 http_transport_init (vlib_main_t *vm)
1002 transport_register_protocol (TRANSPORT_PROTO_HTTP, &http_proto,
1003 FIB_PROTOCOL_IP4, ~0);
1004 transport_register_protocol (TRANSPORT_PROTO_HTTP, &http_proto,
1005 FIB_PROTOCOL_IP6, ~0);
1009 VLIB_INIT_FUNCTION (http_transport_init);
1011 VLIB_PLUGIN_REGISTER () = {
1012 .version = VPP_BUILD_VER,
1013 .description = "Hypertext Transfer Protocol (HTTP)",
1014 .default_disabled = 0,
1018 * fd.io coding-style-patch-verification: ON
1021 * eval: (c-set-style "gnu")