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 (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 (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)
660 clib_warning ("called");
665 http_ts_cleanup_callback (session_t *ts, session_cleanup_ntf_t ntf)
669 if (ntf == SESSION_CLEANUP_TRANSPORT)
672 hc = http_conn_get_w_thread (ts->opaque, ts->thread_index);
675 clib_warning ("no http connection for %u", ts->session_index);
679 vec_free (hc->rx_buf);
681 http_buffer_free (&hc->tx_buf);
682 http_conn_timer_stop (hc);
684 session_transport_delete_notify (&hc->connection);
689 http_add_segment_callback (u32 client_index, u64 segment_handle)
691 /* No-op for builtin */
696 http_del_segment_callback (u32 client_index, u64 segment_handle)
701 static session_cb_vft_t http_app_cb_vft = {
702 .session_accept_callback = http_ts_accept_callback,
703 .session_disconnect_callback = http_ts_disconnect_callback,
704 .session_connected_callback = http_ts_connected_callback,
705 .session_reset_callback = http_ts_reset_callback,
706 .session_cleanup_callback = http_ts_cleanup_callback,
707 .add_segment_callback = http_add_segment_callback,
708 .del_segment_callback = http_del_segment_callback,
709 .builtin_app_rx_callback = http_ts_rx_callback,
710 .builtin_app_tx_callback = http_ts_builtin_tx_callback,
713 static clib_error_t *
714 http_transport_enable (vlib_main_t *vm, u8 is_en)
716 u32 add_segment_size = 256 << 20, first_seg_size = 32 << 20;
717 vnet_app_detach_args_t _da, *da = &_da;
718 vnet_app_attach_args_t _a, *a = &_a;
719 u64 options[APP_OPTIONS_N_OPTIONS];
720 http_main_t *hm = &http_main;
721 u32 fifo_size = 128 << 12;
725 da->app_index = hm->app_index;
726 da->api_client_index = APP_INVALID_INDEX;
727 vnet_application_detach (da);
731 vec_validate (hm->wrk, vlib_num_workers ());
733 first_seg_size = hm->first_seg_size ? hm->first_seg_size : first_seg_size;
734 fifo_size = hm->fifo_size ? hm->fifo_size : fifo_size;
736 clib_memset (a, 0, sizeof (*a));
737 clib_memset (options, 0, sizeof (options));
739 a->session_cb_vft = &http_app_cb_vft;
740 a->api_client_index = APP_INVALID_INDEX;
741 a->options = options;
742 a->name = format (0, "http");
743 a->options[APP_OPTIONS_SEGMENT_SIZE] = first_seg_size;
744 a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = add_segment_size;
745 a->options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
746 a->options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
747 a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
748 a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
749 a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_IS_TRANSPORT_APP;
751 if (vnet_application_attach (a))
752 return clib_error_return (0, "failed to attach http app");
754 hm->app_index = a->app_index;
757 clib_timebase_init (&hm->timebase, 0 /* GMT */, CLIB_TIMEBASE_DAYLIGHT_NONE,
758 &vm->clib_time /* share the system clock */);
760 http_timers_init (vm, http_conn_timeout_cb);
766 http_transport_connect (transport_endpoint_cfg_t *tep)
772 http_start_listen (u32 app_listener_index, transport_endpoint_t *tep)
774 vnet_listen_args_t _args = {}, *args = &_args;
775 session_t *tc_listener, *app_listener;
776 http_main_t *hm = &http_main;
777 session_endpoint_cfg_t *sep;
778 app_worker_t *app_wrk;
779 transport_proto_t tp;
785 sep = (session_endpoint_cfg_t *) tep;
787 app_wrk = app_worker_get (sep->app_wrk_index);
788 app = application_get (app_wrk->app_index);
790 args->app_index = hm->app_index;
791 args->sep_ext = *sep;
792 args->sep_ext.ns_index = app->ns_index;
793 tp = sep->ext_cfg ? TRANSPORT_PROTO_TLS : TRANSPORT_PROTO_TCP;
794 args->sep_ext.transport_proto = tp;
796 if (vnet_listen (args))
797 return SESSION_INVALID_INDEX;
799 lhc_index = http_listener_alloc ();
800 lhc = http_listener_get (lhc_index);
802 /* Grab transport connection listener and link to http listener */
803 lhc->h_tc_session_handle = args->handle;
804 al = app_listener_get_w_handle (lhc->h_tc_session_handle);
805 tc_listener = app_listener_get_session (al);
806 tc_listener->opaque = lhc_index;
808 /* Grab application listener and link to http listener */
809 app_listener = listen_session_get (app_listener_index);
810 lhc->h_pa_wrk_index = sep->app_wrk_index;
811 lhc->h_pa_session_handle = listen_session_get_handle (app_listener);
812 lhc->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
818 http_transport_close (u32 hc_index, u32 thread_index)
823 HTTP_DBG (1, "App disconnecting %x", hc_index);
825 hc = http_conn_get_w_thread (hc_index, thread_index);
826 as = session_get_from_handle (hc->h_pa_session_handle);
828 /* Nothing more to send, confirm close */
829 if (!svm_fifo_max_dequeue_cons (as->tx_fifo))
831 session_transport_closed_notify (&hc->connection);
832 http_disconnect_transport (hc);
836 /* Wait for all data to be written to ts */
837 hc->state = HTTP_CONN_STATE_APP_CLOSED;
841 static transport_connection_t *
842 http_transport_get_connection (u32 hc_index, u32 thread_index)
844 http_conn_t *hc = http_conn_get_w_thread (hc_index, thread_index);
845 return &hc->connection;
848 static transport_connection_t *
849 http_transport_get_listener (u32 listener_index)
851 http_conn_t *lhc = http_listener_get (listener_index);
852 return &lhc->connection;
856 http_app_tx_callback (void *session, transport_send_params_t *sp)
858 session_t *as = (session_t *) session;
861 hc = http_conn_get_w_thread (as->connection_index, as->thread_index);
862 if (hc->req_state < HTTP_REQ_STATE_WAIT_APP)
864 clib_warning ("app data in req state %u", hc->req_state);
868 http_req_run_state_machine (hc, sp);
870 if (hc->state == HTTP_CONN_STATE_CLOSED)
872 if (!svm_fifo_max_dequeue_cons (as->rx_fifo))
873 http_disconnect_transport (hc);
879 format_http_connection (u8 *s, va_list *args)
881 http_conn_t *hc = va_arg (*args, http_conn_t *);
884 ts = session_get_from_handle (hc->h_tc_session_handle);
885 s = format (s, "[%d:%d][H] app_wrk %u ts %d:%d", hc->c_thread_index,
886 hc->c_s_index, hc->h_pa_wrk_index, ts->thread_index,
893 format_http_listener (u8 *s, va_list *args)
895 http_conn_t *lhc = va_arg (*args, http_conn_t *);
899 al = app_listener_get_w_handle (lhc->h_tc_session_handle);
900 lts = app_listener_get_session (al);
901 s = format (s, "[%d:%d][H] app_wrk %u ts %d:%d", lhc->c_thread_index,
902 lhc->c_s_index, lhc->h_pa_wrk_index, lts->thread_index,
909 format_http_conn_state (u8 *s, va_list *args)
911 http_conn_t *hc = va_arg (*args, http_conn_t *);
915 case HTTP_CONN_STATE_LISTEN:
916 s = format (s, "LISTEN");
918 case HTTP_CONN_STATE_CONNECTING:
919 s = format (s, "CONNECTING");
921 case HTTP_CONN_STATE_ESTABLISHED:
922 s = format (s, "ESTABLISHED");
924 case HTTP_CONN_STATE_TRANSPORT_CLOSED:
925 s = format (s, "TRANSPORT_CLOSED");
927 case HTTP_CONN_STATE_APP_CLOSED:
928 s = format (s, "APP_CLOSED");
930 case HTTP_CONN_STATE_CLOSED:
931 s = format (s, "CLOSED");
939 format_http_transport_connection (u8 *s, va_list *args)
941 u32 tc_index = va_arg (*args, u32);
942 u32 thread_index = va_arg (*args, u32);
943 u32 verbose = va_arg (*args, u32);
946 hc = http_conn_get_w_thread (tc_index, thread_index);
948 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_http_connection, hc);
952 format (s, "%-" SESSION_CLI_STATE_LEN "U", format_http_conn_state, hc);
954 s = format (s, "\n");
961 format_http_transport_listener (u8 *s, va_list *args)
963 u32 tc_index = va_arg (*args, u32);
964 u32 __clib_unused thread_index = va_arg (*args, u32);
965 u32 __clib_unused verbose = va_arg (*args, u32);
966 http_conn_t *lhc = http_listener_get (tc_index);
968 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_http_listener, lhc);
971 format (s, "%-" SESSION_CLI_STATE_LEN "U", format_http_conn_state, lhc);
975 static const transport_proto_vft_t http_proto = {
976 .enable = http_transport_enable,
977 .connect = http_transport_connect,
978 .start_listen = http_start_listen,
979 .close = http_transport_close,
980 .custom_tx = http_app_tx_callback,
981 .get_connection = http_transport_get_connection,
982 .get_listener = http_transport_get_listener,
983 .format_connection = format_http_transport_connection,
984 .format_listener = format_http_transport_listener,
985 .transport_options = {
988 .tx_type = TRANSPORT_TX_INTERNAL,
989 .service_type = TRANSPORT_SERVICE_APP,
993 static clib_error_t *
994 http_transport_init (vlib_main_t *vm)
996 transport_register_protocol (TRANSPORT_PROTO_HTTP, &http_proto,
997 FIB_PROTOCOL_IP4, ~0);
998 transport_register_protocol (TRANSPORT_PROTO_HTTP, &http_proto,
999 FIB_PROTOCOL_IP6, ~0);
1003 VLIB_INIT_FUNCTION (http_transport_init);
1005 VLIB_PLUGIN_REGISTER () = {
1006 .version = VPP_BUILD_VER,
1007 .description = "Hypertext Transfer Protocol (HTTP)",
1008 .default_disabled = 0,
1012 * fd.io coding-style-patch-verification: ON
1015 * eval: (c-set-style "gnu")