FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
static_server.c File Reference
+ Include dependency graph for static_server.c:

Go to the source code of this file.

Functions

static u8format_state_machine_called_from (u8 *s, va_list *args)
 Format the called-from enum. More...
 
static void http_static_server_sessions_reader_lock (void)
 Acquire reader lock on the sessions pools. More...
 
static void http_static_server_sessions_reader_unlock (void)
 Drop reader lock on the sessions pools. More...
 
static void http_static_server_sessions_writer_lock (void)
 Acquire writer lock on the sessions pools. More...
 
static void http_static_server_sessions_writer_unlock (void)
 Drop writer lock on the sessions pools. More...
 
static void http_static_server_session_timer_start (http_session_t *hs)
 Start a session cleanup timer. More...
 
static void http_static_server_session_timer_stop (http_session_t *hs)
 stop a session cleanup timer More...
 
static http_session_thttp_static_server_session_alloc (u32 thread_index)
 Allocate an http session. More...
 
static http_session_thttp_static_server_session_get (u32 thread_index, u32 hs_index)
 Get an http session by index. More...
 
static void http_static_server_session_free (http_session_t *hs)
 Free an http session. More...
 
static void http_static_server_session_lookup_add (u32 thread_index, u32 s_index, u32 hs_index)
 add a session to the vpp < – > http session index map More...
 
static void http_static_server_session_lookup_del (u32 thread_index, u32 s_index)
 Remove a session from the vpp < – > http session index map. More...
 
static http_session_thttp_static_server_session_lookup (u32 thread_index, u32 s_index)
 lookup a session in the vpp < – > http session index map More...
 
static void http_static_server_detach_cache_entry (http_session_t *hs)
 Detach cache entry from session. More...
 
static void http_static_server_session_cleanup (http_session_t *hs)
 clean up a session More...
 
static void http_static_server_session_disconnect (http_session_t *hs)
 Disconnect a session. More...
 
static u32 static_send_data (http_session_t *hs, u8 *data, u32 length, u32 offset)
 send http data More...
 
static void send_error (http_session_t *hs, char *str)
 Send an http error string. More...
 
static int session_rx_request (http_session_t *hs)
 Retrieve data from the application layer. More...
 
static void lru_validate (http_static_server_main_t *hsm)
 Sanity-check the forward and reverse LRU lists. More...
 
static void lru_remove (http_static_server_main_t *hsm, file_data_cache_t *ep)
 Remove a data cache entry from the LRU lists. More...
 
static void lru_add (http_static_server_main_t *hsm, file_data_cache_t *ep, f64 now)
 Add an entry to the LRU lists, tag w/ supplied timestamp. More...
 
static void lru_update (http_static_server_main_t *hsm, file_data_cache_t *ep, f64 now)
 Remove and re-add a cache entry from/to the LRU lists. More...
 
static int state_closed (session_t *s, http_session_t *hs, http_state_machine_called_from_t cf)
 Session-layer (main) data rx callback. More...
 
static void close_session (http_session_t *hs)
 
void http_static_server_register_builtin_handler (void *fp, char *url, int request_type)
 Register a builtin GET or POST handler. More...
 
static int v_find_index (u8 *vec, char *str)
 
static int state_established (session_t *s, http_session_t *hs, http_state_machine_called_from_t cf)
 established state - waiting for GET, POST, etc. More...
 
static int state_send_more_data (session_t *s, http_session_t *hs, http_state_machine_called_from_t cf)
 
static int state_sent_ok (session_t *s, http_session_t *hs, http_state_machine_called_from_t cf)
 
static int http_static_server_rx_tx_callback (session_t *s, http_state_machine_called_from_t cf)
 
static int http_static_server_rx_callback (session_t *s)
 
static int http_static_server_tx_callback (session_t *s)
 
static int http_static_server_session_accept_callback (session_t *s)
 Session accept callback. More...
 
static void http_static_server_session_disconnect_callback (session_t *s)
 Session disconnect callback. More...
 
static void http_static_server_session_reset_callback (session_t *s)
 Session reset callback. More...
 
static int http_static_server_session_connected_callback (u32 app_index, u32 api_context, session_t *s, u8 is_fail)
 
static int http_static_server_add_segment_callback (u32 client_index, u64 segment_handle)
 
static int http_static_server_attach ()
 
static int http_static_server_listen ()
 
static void http_static_server_session_cleanup_cb (void *hs_handlep)
 
static void http_expired_timers_dispatch (u32 *expired_timers)
 Expired session timer-wheel callback. More...
 
static uword http_static_server_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
 Timer-wheel expiration process. More...
 
static int http_static_server_create (vlib_main_t *vm)
 
int http_static_server_enable_api (u32 fifo_size, u32 cache_limit, u32 prealloc_fifos, u32 private_segment_size, u8 *www_root, u8 *uri)
 API helper function for vl_api_http_static_enable_t messages. More...
 
static clib_error_thttp_static_server_create_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
u8format_hsm_cache_entry (u8 *s, va_list *args)
 format a file cache entry More...
 
u8format_http_session_state (u8 *s, va_list *args)
 
u8format_http_session (u8 *s, va_list *args)
 
static clib_error_thttp_show_static_server_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_thttp_clear_static_cache_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_thttp_static_server_main_init (vlib_main_t *vm)
 

Variables

http_static_server_main_t http_static_server_main
 
static const char * http_error_template
 http error boilerplate More...
 
static const char * http_response_template
 http response boilerplate More...
 
static void * state_funcs [HTTP_STATE_N_STATES]
 
static session_cb_vft_t http_static_server_session_cb_vft
 Session-layer virtual function table. More...
 
vlib_node_registration_t http_static_server_process_node
 (constructor) VLIB_REGISTER_NODE (http_static_server_process_node) More...
 
static vlib_cli_command_t http_static_server_create_command
 (constructor) VLIB_CLI_COMMAND (http_static_server_create_command) More...
 
static vlib_cli_command_t http_show_static_server_command
 (constructor) VLIB_CLI_COMMAND (http_show_static_server_command) More...
 
static vlib_cli_command_t clear_http_static_cache_command
 (constructor) VLIB_CLI_COMMAND (clear_http_static_cache_command) More...
 

Function Documentation

◆ close_session()

static void close_session ( http_session_t hs)
static

Definition at line 531 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ format_hsm_cache_entry()

u8* format_hsm_cache_entry ( u8 s,
va_list *  args 
)

format a file cache entry

Definition at line 1486 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ format_http_session()

u8* format_http_session ( u8 s,
va_list *  args 
)

Definition at line 1530 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ format_http_session_state()

u8* format_http_session_state ( u8 s,
va_list *  args 
)

Definition at line 1503 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ format_state_machine_called_from()

static u8* format_state_machine_called_from ( u8 s,
va_list *  args 
)
static

Format the called-from enum.

Definition at line 39 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_clear_static_cache_command_fn()

static clib_error_t* http_clear_static_cache_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 1660 of file static_server.c.

+ Here is the call graph for this function:

◆ http_expired_timers_dispatch()

static void http_expired_timers_dispatch ( u32 expired_timers)
static

Expired session timer-wheel callback.

Definition at line 1234 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_show_static_server_command_fn()

static clib_error_t* http_show_static_server_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 1547 of file static_server.c.

+ Here is the call graph for this function:

◆ http_static_server_add_segment_callback()

static int http_static_server_add_segment_callback ( u32  client_index,
u64  segment_handle 
)
static

Definition at line 1126 of file static_server.c.

◆ http_static_server_attach()

static int http_static_server_attach ( )
static

Definition at line 1146 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_create()

static int http_static_server_create ( vlib_main_t vm)
static

Definition at line 1287 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_create_command_fn()

static clib_error_t* http_static_server_create_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 1370 of file static_server.c.

+ Here is the call graph for this function:

◆ http_static_server_detach_cache_entry()

static void http_static_server_detach_cache_entry ( http_session_t hs)
static

Detach cache entry from session.

Definition at line 219 of file static_server.c.

+ Here is the caller graph for this function:

◆ http_static_server_enable_api()

int http_static_server_enable_api ( u32  fifo_size,
u32  cache_limit,
u32  prealloc_fifos,
u32  private_segment_size,
u8 www_root,
u8 uri 
)

API helper function for vl_api_http_static_enable_t messages.

Definition at line 1333 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_listen()

static int http_static_server_listen ( )
static

Definition at line 1199 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_main_init()

static clib_error_t* http_static_server_main_init ( vlib_main_t vm)
static

Definition at line 1735 of file static_server.c.

+ Here is the call graph for this function:

◆ http_static_server_process()

static uword http_static_server_process ( vlib_main_t vm,
vlib_node_runtime_t rt,
vlib_frame_t f 
)
static

Timer-wheel expiration process.

Definition at line 1252 of file static_server.c.

◆ http_static_server_register_builtin_handler()

void http_static_server_register_builtin_handler ( void *  fp,
char *  url,
int  request_type 
)

Register a builtin GET or POST handler.

Definition at line 540 of file static_server.c.

+ Here is the caller graph for this function:

◆ http_static_server_rx_callback()

static int http_static_server_rx_callback ( session_t s)
static

Definition at line 1031 of file static_server.c.

+ Here is the call graph for this function:

◆ http_static_server_rx_tx_callback()

static int http_static_server_rx_tx_callback ( session_t s,
http_state_machine_called_from_t  cf 
)
inlinestatic

Definition at line 992 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_session_accept_callback()

static int http_static_server_session_accept_callback ( session_t s)
static

Session accept callback.

Definition at line 1047 of file static_server.c.

+ Here is the call graph for this function:

◆ http_static_server_session_alloc()

static http_session_t* http_static_server_session_alloc ( u32  thread_index)
static

Allocate an http session.

Definition at line 132 of file static_server.c.

+ Here is the caller graph for this function:

◆ http_static_server_session_cleanup()

static void http_static_server_session_cleanup ( http_session_t hs)
static

clean up a session

Definition at line 250 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_session_cleanup_cb()

static void http_static_server_session_cleanup_cb ( void *  hs_handlep)
static

Definition at line 1212 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_session_connected_callback()

static int http_static_server_session_connected_callback ( u32  app_index,
u32  api_context,
session_t s,
u8  is_fail 
)
static

Definition at line 1118 of file static_server.c.

◆ http_static_server_session_disconnect()

static void http_static_server_session_disconnect ( http_session_t hs)
static

Disconnect a session.

Definition at line 267 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_session_disconnect_callback()

static void http_static_server_session_disconnect_callback ( session_t s)
static

Session disconnect callback.

Definition at line 1077 of file static_server.c.

+ Here is the call graph for this function:

◆ http_static_server_session_free()

static void http_static_server_session_free ( http_session_t hs)
static

Free an http session.

Definition at line 159 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_session_get()

static http_session_t* http_static_server_session_get ( u32  thread_index,
u32  hs_index 
)
static

Get an http session by index.

Definition at line 148 of file static_server.c.

+ Here is the caller graph for this function:

◆ http_static_server_session_lookup()

static http_session_t* http_static_server_session_lookup ( u32  thread_index,
u32  s_index 
)
static

lookup a session in the vpp < – > http session index map

Definition at line 202 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_session_lookup_add()

static void http_static_server_session_lookup_add ( u32  thread_index,
u32  s_index,
u32  hs_index 
)
static

add a session to the vpp < – > http session index map

Definition at line 181 of file static_server.c.

+ Here is the caller graph for this function:

◆ http_static_server_session_lookup_del()

static void http_static_server_session_lookup_del ( u32  thread_index,
u32  s_index 
)
static

Remove a session from the vpp < – > http session index map.

Definition at line 192 of file static_server.c.

+ Here is the caller graph for this function:

◆ http_static_server_session_reset_callback()

static void http_static_server_session_reset_callback ( session_t s)
static

Session reset callback.

Definition at line 1099 of file static_server.c.

+ Here is the call graph for this function:

◆ http_static_server_session_timer_start()

static void http_static_server_session_timer_start ( http_session_t hs)
static

Start a session cleanup timer.

Definition at line 101 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_session_timer_stop()

static void http_static_server_session_timer_stop ( http_session_t hs)
static

stop a session cleanup timer

Definition at line 120 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_sessions_reader_lock()

static void http_static_server_sessions_reader_lock ( void  )
static

Acquire reader lock on the sessions pools.

Definition at line 69 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_sessions_reader_unlock()

static void http_static_server_sessions_reader_unlock ( void  )
static

Drop reader lock on the sessions pools.

Definition at line 77 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_sessions_writer_lock()

static void http_static_server_sessions_writer_lock ( void  )
static

Acquire writer lock on the sessions pools.

Definition at line 85 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_sessions_writer_unlock()

static void http_static_server_sessions_writer_unlock ( void  )
static

Drop writer lock on the sessions pools.

Definition at line 93 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ http_static_server_tx_callback()

static int http_static_server_tx_callback ( session_t s)
static

Definition at line 1037 of file static_server.c.

+ Here is the call graph for this function:

◆ lru_add()

static void lru_add ( http_static_server_main_t hsm,
file_data_cache_t ep,
f64  now 
)
inlinestatic

Add an entry to the LRU lists, tag w/ supplied timestamp.

Definition at line 467 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lru_remove()

static void lru_remove ( http_static_server_main_t hsm,
file_data_cache_t ep 
)
inlinestatic

Remove a data cache entry from the LRU lists.

Definition at line 433 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lru_update()

static void lru_update ( http_static_server_main_t hsm,
file_data_cache_t ep,
f64  now 
)
inlinestatic

Remove and re-add a cache entry from/to the LRU lists.

Definition at line 504 of file static_server.c.

+ Here is the call graph for this function:

◆ lru_validate()

static void lru_validate ( http_static_server_main_t hsm)
inlinestatic

Sanity-check the forward and reverse LRU lists.

Definition at line 388 of file static_server.c.

+ Here is the caller graph for this function:

◆ send_error()

static void send_error ( http_session_t hs,
char *  str 
)
static

Send an http error string.

Parameters
hs- the http session
str- the error string, e.g. "404 Not Found"

Definition at line 349 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ session_rx_request()

static int session_rx_request ( http_session_t hs)
static

Retrieve data from the application layer.

Definition at line 364 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_closed()

static int state_closed ( session_t s,
http_session_t hs,
http_state_machine_called_from_t  cf 
)
static

Session-layer (main) data rx callback.

Parse the http request, and reply to it. Future extensions might include POST processing, active content, etc.closed state - should never really get here

Definition at line 522 of file static_server.c.

+ Here is the call graph for this function:

◆ state_established()

static int state_established ( session_t s,
http_session_t hs,
http_state_machine_called_from_t  cf 
)
static

established state - waiting for GET, POST, etc.

Definition at line 594 of file static_server.c.

+ Here is the call graph for this function:

◆ state_send_more_data()

static int state_send_more_data ( session_t s,
http_session_t hs,
http_state_machine_called_from_t  cf 
)
static

Definition at line 898 of file static_server.c.

+ Here is the call graph for this function:

◆ state_sent_ok()

static int state_sent_ok ( session_t s,
http_session_t hs,
http_state_machine_called_from_t  cf 
)
static

Definition at line 924 of file static_server.c.

+ Here is the call graph for this function:

◆ static_send_data()

static u32 static_send_data ( http_session_t hs,
u8 data,
u32  length,
u32  offset 
)
static

send http data

Parameters
hs- http session
data- the data vector to transmit
offset- transmit offset for this operation
Returns
offset for next transmit operation, may be unchanged w/ full fifo

Definition at line 305 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ v_find_index()

static int v_find_index ( u8 vec,
char *  str 
)
static

Definition at line 571 of file static_server.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ clear_http_static_cache_command

vlib_cli_command_t clear_http_static_cache_command
static
Initial value:
=
{
.path = "clear http static cache",
.short_help = "clear http static cache",
}
static clib_error_t * http_clear_static_cache_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)

(constructor) VLIB_CLI_COMMAND (clear_http_static_cache_command)

Definition at line 1726 of file static_server.c.

◆ http_error_template

const char* http_error_template
static
Initial value:
=
"HTTP/1.1 %s\r\n"
"Date: %U GMT\r\n"
"Content-Type: text/html\r\n"
"Connection: close\r\n"
"Pragma: no-cache\r\n"
"Content-Length: 0\r\n\r\n"

http error boilerplate

Definition at line 278 of file static_server.c.

◆ http_response_template

const char* http_response_template
static
Initial value:
=
"Date: %U GMT\r\n"
"Expires: %U GMT\r\n"
"Server: VPP Static\r\n"
"Content-Type: %s\r\n"
"Content-Length: %d\r\n\r\n"

http response boilerplate

Definition at line 288 of file static_server.c.

◆ http_show_static_server_command

vlib_cli_command_t http_show_static_server_command
static
Initial value:
=
{
.path = "show http static server",
.short_help = "show http static server sessions cache [verbose [<nn>]]",
}
static clib_error_t * http_show_static_server_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)

(constructor) VLIB_CLI_COMMAND (http_show_static_server_command)

Definition at line 1651 of file static_server.c.

◆ http_static_server_create_command

vlib_cli_command_t http_static_server_create_command
static
Initial value:
=
{
.path = "http static server",
.short_help = "http static server www-root <path> [prealloc-fifos <nn>]\n"
"[private-segment-size <nnMG>] [fifo-size <nbytes>] [uri <uri>]\n"
"[debug [nn]]\n",
}
static clib_error_t * http_static_server_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)

(constructor) VLIB_CLI_COMMAND (http_static_server_create_command)

Definition at line 1473 of file static_server.c.

◆ http_static_server_main

http_static_server_main_t http_static_server_main

Definition at line 33 of file static_server.c.

◆ http_static_server_process_node

vlib_node_registration_t http_static_server_process_node
Initial value:
=
{
.name = "static-http-server-process",
.state = VLIB_NODE_STATE_DISABLED,
}
static uword http_static_server_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Timer-wheel expiration process.

(constructor) VLIB_REGISTER_NODE (http_static_server_process_node)

Definition at line 1277 of file static_server.c.

◆ http_static_server_session_cb_vft

session_cb_vft_t http_static_server_session_cb_vft
static
Initial value:
= {
.session_accept_callback = http_static_server_session_accept_callback,
.session_disconnect_callback =
.session_connected_callback = http_static_server_session_connected_callback,
.add_segment_callback = http_static_server_add_segment_callback,
.builtin_app_rx_callback = http_static_server_rx_callback,
.builtin_app_tx_callback = http_static_server_tx_callback,
}
static int http_static_server_session_connected_callback(u32 app_index, u32 api_context, session_t *s, u8 is_fail)
static int http_static_server_tx_callback(session_t *s)
static int http_static_server_session_accept_callback(session_t *s)
Session accept callback.
static int http_static_server_rx_callback(session_t *s)
static void http_static_server_session_reset_callback(session_t *s)
Session reset callback.
static void http_static_server_session_disconnect_callback(session_t *s)
Session disconnect callback.
static int http_static_server_add_segment_callback(u32 client_index, u64 segment_handle)

Session-layer virtual function table.

Definition at line 1134 of file static_server.c.

◆ state_funcs

void* state_funcs[HTTP_STATE_N_STATES]
static
Initial value:
= {
}
static int state_send_more_data(session_t *s, http_session_t *hs, http_state_machine_called_from_t cf)
static int state_established(session_t *s, http_session_t *hs, http_state_machine_called_from_t cf)
established state - waiting for GET, POST, etc.
static int state_closed(session_t *s, http_session_t *hs, http_state_machine_called_from_t cf)
Session-layer (main) data rx callback.
static int state_sent_ok(session_t *s, http_session_t *hs, http_state_machine_called_from_t cf)

Definition at line 981 of file static_server.c.