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, char *str)
366 u32 slen = (u32) strnlen_s_inline (str, 8);
367 u32 vlen = vec_len (vec);
374 for (start_index = 0; start_index < (vlen - slen); start_index++)
376 if (!memcmp (vec, 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_main_t *hm = &http_main;
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 send_error (hc, HTTP_STATUS_BAD_REQUEST);
406 http_disconnect_transport (hc);
410 if ((i = v_find_index (hc->rx_buf, "GET ")) >= 0)
412 hc->method = HTTP_REQ_GET;
413 hc->rx_buf_offset = i + 5;
415 else if ((i = v_find_index (hc->rx_buf, "POST ")) >= 0)
417 hc->method = HTTP_REQ_POST;
418 hc->rx_buf_offset = i + 6;
422 if (hm->debug_level > 1)
423 clib_warning ("Unknown http method");
425 send_error (hc, HTTP_STATUS_METHOD_NOT_ALLOWED);
426 http_disconnect_transport (hc);
430 buf = &hc->rx_buf[hc->rx_buf_offset];
431 len = vec_len (hc->rx_buf) - hc->rx_buf_offset;
433 msg.type = HTTP_MSG_REQUEST;
434 msg.data.content_type = HTTP_CONTENT_TEXT_HTML;
438 svm_fifo_seg_t segs[2] = { { (u8 *) &msg, sizeof (msg) }, { buf, len } };
440 as = session_get_from_handle (hc->h_pa_session_handle);
441 rv = svm_fifo_enqueue_segments (as->rx_fifo, segs, 2, 0 /* allow partial */);
442 if (rv < 0 || rv != sizeof (msg) + len)
444 clib_warning ("failed app enqueue");
445 /* This should not happen as we only handle 1 request per session,
446 * and fifo is allocated, but going forward we should consider
451 vec_free (hc->rx_buf);
452 hc->req_state = HTTP_REQ_STATE_WAIT_APP;
454 app_wrk = app_worker_get_if_valid (as->app_wrk_index);
455 app_worker_lock_and_send_event (app_wrk, as, SESSION_IO_EVT_RX);
461 * waiting for data from app
464 state_wait_app (http_conn_t *hc, transport_send_params_t *sp)
466 http_main_t *hm = &http_main;
467 http_status_code_t ec;
475 as = session_get_from_handle (hc->h_pa_session_handle);
477 rv = svm_fifo_dequeue (as->tx_fifo, sizeof (msg), (u8 *) &msg);
478 ASSERT (rv == sizeof (msg));
480 if (msg.type != HTTP_MSG_REPLY)
482 clib_warning ("unexpected msg type from app %u", msg.type);
483 ec = HTTP_STATUS_INTERNAL_ERROR;
487 if (msg.code != HTTP_STATUS_OK)
493 http_buffer_init (&hc->tx_buf, as->tx_fifo, msg.data.len);
496 * Add headers. For now:
502 now = clib_timebase_now (&hm->timebase);
503 header = format (0, http_response_template,
505 format_clib_timebase_time, now,
507 format_clib_timebase_time, now + 600.0,
509 http_content_type_str[msg.data.content_type],
513 offset = send_data (hc, header, vec_len (header), 0);
514 if (offset != vec_len (header))
516 clib_warning ("couldn't send response header!");
517 ec = HTTP_STATUS_INTERNAL_ERROR;
522 /* Start sending the actual data */
523 hc->req_state = HTTP_REQ_STATE_SEND_MORE_DATA;
530 hc->req_state = HTTP_REQ_STATE_WAIT_METHOD;
531 http_disconnect_transport (hc);
533 /* stop state machine processing */
538 state_send_more_data (http_conn_t *hc, transport_send_params_t *sp)
540 u32 max_send = 64 << 10, n_segs;
541 http_buffer_t *hb = &hc->tx_buf;
546 ts = session_get_from_handle (hc->h_tc_session_handle);
547 if ((seg = http_buffer_get_segs (hb, max_send, &n_segs)))
548 sent = svm_fifo_enqueue_segments (ts->tx_fifo, seg, n_segs,
549 1 /* allow partial */);
553 http_buffer_drain (hb, sent);
555 /* Ask scheduler to notify app of deq event if needed */
556 sp->max_burst_size = sent;
560 sp->max_burst_size = 0;
563 /* Not finished sending all data */
564 if (!http_buffer_is_drained (hb))
566 if (svm_fifo_set_event (ts->tx_fifo))
567 session_send_io_evt_to_thread (ts->tx_fifo, SESSION_IO_EVT_TX);
569 if (svm_fifo_max_enqueue (ts->tx_fifo) < 16 << 10)
571 /* Deschedule http session and wait for deq notification if
572 * underlying ts tx fifo almost full */
573 svm_fifo_add_want_deq_ntf (ts->tx_fifo, SVM_FIFO_WANT_DEQ_NOTIF);
574 transport_connection_deschedule (&hc->connection);
575 sp->flags |= TRANSPORT_SND_F_DESCHED;
580 if (svm_fifo_set_event (ts->tx_fifo))
581 session_send_io_evt_to_thread (ts->tx_fifo, SESSION_IO_EVT_TX_FLUSH);
583 /* Finished transaction, back to HTTP_REQ_STATE_WAIT_METHOD */
584 hc->req_state = HTTP_REQ_STATE_WAIT_METHOD;
585 http_buffer_free (&hc->tx_buf);
591 typedef int (*http_sm_handler) (http_conn_t *, transport_send_params_t *sp);
593 static http_sm_handler req_state_funcs[HTTP_REQ_N_STATES] = {
594 /* Waiting for GET, POST, etc. */
596 /* Wait for data from app */
599 state_send_more_data,
603 http_req_run_state_machine (http_conn_t *hc, transport_send_params_t *sp)
609 rv = req_state_funcs[hc->req_state](hc, sp);
615 /* Reset the session expiration timer */
616 http_conn_timer_update (hc);
620 http_ts_rx_callback (session_t *ts)
624 hc = http_conn_get_w_thread (ts->opaque, ts->thread_index);
626 if (hc->req_state != HTTP_REQ_STATE_WAIT_METHOD)
628 clib_warning ("tcp data in req state %u", hc->req_state);
632 http_req_run_state_machine (hc, 0);
634 if (hc->state == HTTP_CONN_STATE_TRANSPORT_CLOSED)
636 if (!svm_fifo_max_dequeue_cons (ts->rx_fifo))
637 session_transport_closing_notify (&hc->connection);
643 http_ts_builtin_tx_callback (session_t *ts)
645 clib_warning ("called");
650 http_ts_cleanup_callback (session_t *ts, session_cleanup_ntf_t ntf)
654 if (ntf == SESSION_CLEANUP_TRANSPORT)
657 hc = http_conn_get_w_thread (ts->opaque, ts->thread_index);
660 clib_warning ("no http connection for %u", ts->session_index);
664 vec_free (hc->rx_buf);
666 http_buffer_free (&hc->tx_buf);
667 http_conn_timer_stop (hc);
669 session_transport_delete_notify (&hc->connection);
674 http_add_segment_callback (u32 client_index, u64 segment_handle)
676 /* No-op for builtin */
681 http_del_segment_callback (u32 client_index, u64 segment_handle)
686 static session_cb_vft_t http_app_cb_vft = {
687 .session_accept_callback = http_ts_accept_callback,
688 .session_disconnect_callback = http_ts_disconnect_callback,
689 .session_connected_callback = http_ts_connected_callback,
690 .session_reset_callback = http_ts_reset_callback,
691 .session_cleanup_callback = http_ts_cleanup_callback,
692 .add_segment_callback = http_add_segment_callback,
693 .del_segment_callback = http_del_segment_callback,
694 .builtin_app_rx_callback = http_ts_rx_callback,
695 .builtin_app_tx_callback = http_ts_builtin_tx_callback,
698 static clib_error_t *
699 http_transport_enable (vlib_main_t *vm, u8 is_en)
701 u32 add_segment_size = 256 << 20, first_seg_size = 32 << 20;
702 vnet_app_detach_args_t _da, *da = &_da;
703 vnet_app_attach_args_t _a, *a = &_a;
704 u64 options[APP_OPTIONS_N_OPTIONS];
705 http_main_t *hm = &http_main;
706 u32 fifo_size = 128 << 12;
710 da->app_index = hm->app_index;
711 da->api_client_index = APP_INVALID_INDEX;
712 vnet_application_detach (da);
716 vec_validate (hm->wrk, vlib_num_workers ());
718 first_seg_size = hm->first_seg_size ? hm->first_seg_size : first_seg_size;
719 fifo_size = hm->fifo_size ? hm->fifo_size : fifo_size;
721 clib_memset (a, 0, sizeof (*a));
722 clib_memset (options, 0, sizeof (options));
724 a->session_cb_vft = &http_app_cb_vft;
725 a->api_client_index = APP_INVALID_INDEX;
726 a->options = options;
727 a->name = format (0, "http");
728 a->options[APP_OPTIONS_SEGMENT_SIZE] = first_seg_size;
729 a->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = add_segment_size;
730 a->options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size;
731 a->options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size;
732 a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
733 a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
734 a->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_IS_TRANSPORT_APP;
736 if (vnet_application_attach (a))
737 return clib_error_return (0, "failed to attach http app");
739 hm->app_index = a->app_index;
742 clib_timebase_init (&hm->timebase, 0 /* GMT */, CLIB_TIMEBASE_DAYLIGHT_NONE,
743 &vm->clib_time /* share the system clock */);
745 http_timers_init (vm, http_conn_timeout_cb);
751 http_transport_connect (transport_endpoint_cfg_t *tep)
757 http_start_listen (u32 app_listener_index, transport_endpoint_t *tep)
759 vnet_listen_args_t _args = {}, *args = &_args;
760 session_t *tc_listener, *app_listener;
761 http_main_t *hm = &http_main;
762 session_endpoint_cfg_t *sep;
763 app_worker_t *app_wrk;
764 transport_proto_t tp;
770 sep = (session_endpoint_cfg_t *) tep;
772 app_wrk = app_worker_get (sep->app_wrk_index);
773 app = application_get (app_wrk->app_index);
775 args->app_index = hm->app_index;
776 args->sep_ext = *sep;
777 args->sep_ext.ns_index = app->ns_index;
778 tp = sep->ext_cfg ? TRANSPORT_PROTO_TLS : TRANSPORT_PROTO_TCP;
779 args->sep_ext.transport_proto = tp;
781 if (vnet_listen (args))
782 return SESSION_INVALID_INDEX;
784 lhc_index = http_listener_alloc ();
785 lhc = http_listener_get (lhc_index);
787 /* Grab transport connection listener and link to http listener */
788 lhc->h_tc_session_handle = args->handle;
789 al = app_listener_get_w_handle (lhc->h_tc_session_handle);
790 tc_listener = app_listener_get_session (al);
791 tc_listener->opaque = lhc_index;
793 /* Grab application listener and link to http listener */
794 app_listener = listen_session_get (app_listener_index);
795 lhc->h_pa_wrk_index = sep->app_wrk_index;
796 lhc->h_pa_session_handle = listen_session_get_handle (app_listener);
797 lhc->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
803 http_transport_close (u32 hc_index, u32 thread_index)
808 HTTP_DBG (1, "App disconnecting %x", hc_index);
810 hc = http_conn_get_w_thread (hc_index, thread_index);
811 as = session_get_from_handle (hc->h_pa_session_handle);
813 /* Nothing more to send, confirm close */
814 if (!svm_fifo_max_dequeue_cons (as->tx_fifo))
816 session_transport_closed_notify (&hc->connection);
817 http_disconnect_transport (hc);
821 /* Wait for all data to be written to ts */
822 hc->state = HTTP_CONN_STATE_APP_CLOSED;
826 static transport_connection_t *
827 http_transport_get_connection (u32 hc_index, u32 thread_index)
829 http_conn_t *hc = http_conn_get_w_thread (hc_index, thread_index);
830 return &hc->connection;
833 static transport_connection_t *
834 http_transport_get_listener (u32 listener_index)
836 http_conn_t *lhc = http_listener_get (listener_index);
837 return &lhc->connection;
841 http_app_tx_callback (void *session, transport_send_params_t *sp)
843 session_t *as = (session_t *) session;
846 hc = http_conn_get_w_thread (as->connection_index, as->thread_index);
847 if (hc->req_state < HTTP_REQ_STATE_WAIT_APP)
849 clib_warning ("app data in req state %u", hc->req_state);
853 http_req_run_state_machine (hc, sp);
855 if (hc->state == HTTP_CONN_STATE_CLOSED)
857 if (!svm_fifo_max_dequeue_cons (as->rx_fifo))
858 http_disconnect_transport (hc);
864 format_http_connection (u8 *s, va_list *args)
866 http_conn_t *hc = va_arg (*args, http_conn_t *);
869 ts = session_get_from_handle (hc->h_tc_session_handle);
870 s = format (s, "[%d:%d][H] app_wrk %u ts %d:%d", hc->c_thread_index,
871 hc->c_s_index, hc->h_pa_wrk_index, ts->thread_index,
878 format_http_listener (u8 *s, va_list *args)
880 http_conn_t *lhc = va_arg (*args, http_conn_t *);
884 al = app_listener_get_w_handle (lhc->h_tc_session_handle);
885 lts = app_listener_get_session (al);
886 s = format (s, "[%d:%d][H] app_wrk %u ts %d:%d", lhc->c_thread_index,
887 lhc->c_s_index, lhc->h_pa_wrk_index, lts->thread_index,
894 format_http_conn_state (u8 *s, va_list *args)
896 http_conn_t *hc = va_arg (*args, http_conn_t *);
900 case HTTP_CONN_STATE_LISTEN:
901 s = format (s, "LISTEN");
903 case HTTP_CONN_STATE_CONNECTING:
904 s = format (s, "CONNECTING");
906 case HTTP_CONN_STATE_ESTABLISHED:
907 s = format (s, "ESTABLISHED");
909 case HTTP_CONN_STATE_TRANSPORT_CLOSED:
910 s = format (s, "TRANSPORT_CLOSED");
912 case HTTP_CONN_STATE_APP_CLOSED:
913 s = format (s, "APP_CLOSED");
915 case HTTP_CONN_STATE_CLOSED:
916 s = format (s, "CLOSED");
924 format_http_transport_connection (u8 *s, va_list *args)
926 u32 tc_index = va_arg (*args, u32);
927 u32 thread_index = va_arg (*args, u32);
928 u32 verbose = va_arg (*args, u32);
931 hc = http_conn_get_w_thread (tc_index, thread_index);
933 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_http_connection, hc);
937 format (s, "%-" SESSION_CLI_STATE_LEN "U", format_http_conn_state, hc);
939 s = format (s, "\n");
946 format_http_transport_listener (u8 *s, va_list *args)
948 u32 tc_index = va_arg (*args, u32);
949 u32 __clib_unused thread_index = va_arg (*args, u32);
950 u32 __clib_unused verbose = va_arg (*args, u32);
951 http_conn_t *lhc = http_listener_get (tc_index);
953 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_http_listener, lhc);
956 format (s, "%-" SESSION_CLI_STATE_LEN "U", format_http_conn_state, lhc);
960 static const transport_proto_vft_t http_proto = {
961 .enable = http_transport_enable,
962 .connect = http_transport_connect,
963 .start_listen = http_start_listen,
964 .close = http_transport_close,
965 .custom_tx = http_app_tx_callback,
966 .get_connection = http_transport_get_connection,
967 .get_listener = http_transport_get_listener,
968 .format_connection = format_http_transport_connection,
969 .format_listener = format_http_transport_listener,
970 .transport_options = {
973 .tx_type = TRANSPORT_TX_INTERNAL,
974 .service_type = TRANSPORT_SERVICE_APP,
978 static clib_error_t *
979 http_transport_init (vlib_main_t *vm)
981 transport_register_protocol (TRANSPORT_PROTO_HTTP, &http_proto,
982 FIB_PROTOCOL_IP4, ~0);
983 transport_register_protocol (TRANSPORT_PROTO_HTTP, &http_proto,
984 FIB_PROTOCOL_IP6, ~0);
988 VLIB_INIT_FUNCTION (http_transport_init);
990 VLIB_PLUGIN_REGISTER () = {
991 .version = VPP_BUILD_VER,
992 .description = "Hypertext Transfer Protocol (HTTP)",
993 .default_disabled = 0,
997 * fd.io coding-style-patch-verification: ON
1000 * eval: (c-set-style "gnu")