2 * Copyright (c) 2017 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.
17 * @brief Session and session manager
20 #include <vnet/session/session.h>
21 #include <vnet/session/session_debug.h>
22 #include <vnet/session/application.h>
23 #include <vlibmemory/api.h>
24 #include <vnet/dpo/load_balance.h>
25 #include <vnet/fib/ip4_fib.h>
26 #include <vnet/tcp/tcp.h>
28 session_manager_main_t session_manager_main;
29 extern transport_proto_vft_t *tp_vfts;
32 stream_session_create_i (segment_manager_t * sm, transport_connection_t * tc,
33 u8 alloc_fifos, stream_session_t ** ret_s)
35 session_manager_main_t *smm = &session_manager_main;
36 svm_fifo_t *server_rx_fifo = 0, *server_tx_fifo = 0;
37 u32 fifo_segment_index;
41 u32 thread_index = tc->thread_index;
44 ASSERT (thread_index == vlib_get_thread_index ());
46 /* Create the session */
47 pool_get_aligned (smm->sessions[thread_index], s, CLIB_CACHE_LINE_BYTES);
48 memset (s, 0, sizeof (*s));
49 pool_index = s - smm->sessions[thread_index];
54 if ((rv = segment_manager_alloc_session_fifos (sm, &server_rx_fifo,
56 &fifo_segment_index)))
58 pool_put (smm->sessions[thread_index], s);
61 /* Initialize backpointers */
62 server_rx_fifo->master_session_index = pool_index;
63 server_rx_fifo->master_thread_index = thread_index;
65 server_tx_fifo->master_session_index = pool_index;
66 server_tx_fifo->master_thread_index = thread_index;
68 s->server_rx_fifo = server_rx_fifo;
69 s->server_tx_fifo = server_tx_fifo;
70 s->svm_segment_index = fifo_segment_index;
73 /* Initialize state machine, such as it is... */
74 s->session_type = session_type_from_proto_and_ip (tc->transport_proto,
76 s->session_state = SESSION_STATE_CONNECTING;
77 s->thread_index = thread_index;
78 s->session_index = pool_index;
80 /* Attach transport to session */
81 s->connection_index = tc->c_index;
83 /* Attach session to transport */
84 tc->s_index = s->session_index;
86 /* Add to the main lookup table */
87 value = stream_session_handle (s);
88 session_lookup_add_connection (tc, value);
96 * Discards bytes from buffer chain
98 * It discards n_bytes_to_drop starting at first buffer after chain_b
101 session_enqueue_discard_chain_bytes (vlib_main_t * vm, vlib_buffer_t * b,
102 vlib_buffer_t ** chain_b,
105 vlib_buffer_t *next = *chain_b;
106 u32 to_drop = n_bytes_to_drop;
107 ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
108 while (to_drop && (next->flags & VLIB_BUFFER_NEXT_PRESENT))
110 next = vlib_get_buffer (vm, next->next_buffer);
111 if (next->current_length > to_drop)
113 vlib_buffer_advance (next, to_drop);
118 to_drop -= next->current_length;
119 next->current_length = 0;
125 b->total_length_not_including_first_buffer -= n_bytes_to_drop;
129 * Enqueue buffer chain tail
132 session_enqueue_chain_tail (stream_session_t * s, vlib_buffer_t * b,
133 u32 offset, u8 is_in_order)
135 vlib_buffer_t *chain_b;
136 u32 chain_bi, len, diff;
137 vlib_main_t *vm = vlib_get_main ();
142 if (is_in_order && offset)
144 diff = offset - b->current_length;
145 if (diff > b->total_length_not_including_first_buffer)
148 session_enqueue_discard_chain_bytes (vm, b, &chain_b, diff);
149 chain_bi = vlib_get_buffer_index (vm, chain_b);
152 chain_bi = b->next_buffer;
156 chain_b = vlib_get_buffer (vm, chain_bi);
157 data = vlib_buffer_get_current (chain_b);
158 len = chain_b->current_length;
163 rv = svm_fifo_enqueue_nowait (s->server_rx_fifo, len, data);
170 return (rv > 0) ? (written + rv) : written;
176 /* written more than what was left in chain */
177 if (written > b->total_length_not_including_first_buffer)
180 /* drop the bytes that have already been delivered */
181 session_enqueue_discard_chain_bytes (vm, b, &chain_b, rv - len);
186 rv = svm_fifo_enqueue_with_offset (s->server_rx_fifo, offset, len,
190 clib_warning ("failed to enqueue multi-buffer seg");
196 while ((chain_bi = (chain_b->flags & VLIB_BUFFER_NEXT_PRESENT)
197 ? chain_b->next_buffer : 0));
206 * Enqueue data for delivery to session peer. Does not notify peer of enqueue
207 * event but on request can queue notification events for later delivery by
208 * calling stream_server_flush_enqueue_events().
210 * @param tc Transport connection which is to be enqueued data
211 * @param b Buffer to be enqueued
212 * @param offset Offset at which to start enqueueing if out-of-order
213 * @param queue_event Flag to indicate if peer is to be notified or if event
214 * is to be queued. The former is useful when more data is
215 * enqueued and only one event is to be generated.
216 * @param is_in_order Flag to indicate if data is in order
217 * @return Number of bytes enqueued or a negative value if enqueueing failed.
220 stream_session_enqueue_data (transport_connection_t * tc, vlib_buffer_t * b,
221 u32 offset, u8 queue_event, u8 is_in_order)
224 int enqueued = 0, rv, in_order_off;
226 s = session_get (tc->s_index, tc->thread_index);
230 enqueued = svm_fifo_enqueue_nowait (s->server_rx_fifo,
232 vlib_buffer_get_current (b));
233 if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_NEXT_PRESENT)
236 in_order_off = enqueued > b->current_length ? enqueued : 0;
237 rv = session_enqueue_chain_tail (s, b, in_order_off, 1);
244 rv = svm_fifo_enqueue_with_offset (s->server_rx_fifo, offset,
246 vlib_buffer_get_current (b));
247 if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) && !rv))
248 session_enqueue_chain_tail (s, b, offset + b->current_length, 0);
249 /* if something was enqueued, report even this as success for ooo
250 * segment handling */
256 /* Queue RX event on this fifo. Eventually these will need to be flushed
257 * by calling stream_server_flush_enqueue_events () */
258 session_manager_main_t *smm = vnet_get_session_manager_main ();
259 u32 thread_index = s->thread_index;
260 u32 my_enqueue_epoch = smm->current_enqueue_epoch[thread_index];
262 if (s->enqueue_epoch != my_enqueue_epoch)
264 s->enqueue_epoch = my_enqueue_epoch;
265 vec_add1 (smm->session_indices_to_enqueue_by_thread[thread_index],
266 s - smm->sessions[thread_index]);
273 /** Check if we have space in rx fifo to push more bytes */
275 stream_session_no_space (transport_connection_t * tc, u32 thread_index,
278 stream_session_t *s = session_get (tc->s_index, thread_index);
280 if (PREDICT_FALSE (s->session_state != SESSION_STATE_READY))
283 if (data_len > svm_fifo_max_enqueue (s->server_rx_fifo))
290 stream_session_tx_fifo_max_dequeue (transport_connection_t * tc)
292 stream_session_t *s = session_get (tc->s_index, tc->thread_index);
293 if (!s->server_tx_fifo)
295 return svm_fifo_max_dequeue (s->server_tx_fifo);
299 stream_session_peek_bytes (transport_connection_t * tc, u8 * buffer,
300 u32 offset, u32 max_bytes)
302 stream_session_t *s = session_get (tc->s_index, tc->thread_index);
303 return svm_fifo_peek (s->server_tx_fifo, offset, max_bytes, buffer);
307 stream_session_dequeue_drop (transport_connection_t * tc, u32 max_bytes)
309 stream_session_t *s = session_get (tc->s_index, tc->thread_index);
310 return svm_fifo_dequeue_drop (s->server_tx_fifo, max_bytes);
314 * Notify session peer that new data has been enqueued.
316 * @param s Stream session for which the event is to be generated.
317 * @param block Flag to indicate if call should block if event queue is full.
319 * @return 0 on succes or negative number if failed to send notification.
322 stream_session_enqueue_notify (stream_session_t * s, u8 block)
325 session_fifo_event_t evt;
326 unix_shared_memory_queue_t *q;
327 static u32 serial_number;
329 if (PREDICT_FALSE (s->session_state == SESSION_STATE_CLOSED))
331 /* Session is closed so app will never clean up. Flush rx fifo */
332 u32 to_dequeue = svm_fifo_max_dequeue (s->server_rx_fifo);
334 svm_fifo_dequeue_drop (s->server_rx_fifo, to_dequeue);
338 /* Get session's server */
339 app = application_get_if_valid (s->app_index);
341 if (PREDICT_FALSE (app == 0))
343 clib_warning ("invalid s->app_index = %d", s->app_index);
347 /* Built-in server? Hand event to the callback... */
348 if (app->cb_fns.builtin_server_rx_callback)
349 return app->cb_fns.builtin_server_rx_callback (s);
351 /* If no event, send one */
352 if (svm_fifo_set_event (s->server_rx_fifo))
354 /* Fabricate event */
355 evt.fifo = s->server_rx_fifo;
356 evt.event_type = FIFO_EVENT_APP_RX;
357 evt.event_id = serial_number++;
359 /* Add event to server's event queue */
360 q = app->event_queue;
362 /* Based on request block (or not) for lack of space */
363 if (block || PREDICT_TRUE (q->cursize < q->maxsize))
364 unix_shared_memory_queue_add (app->event_queue, (u8 *) & evt,
365 0 /* do wait for mutex */ );
368 clib_warning ("fifo full");
374 SESSION_EVT_DBG(SESSION_EVT_ENQ, s, ({
375 ed->data[0] = evt.event_id;
376 ed->data[1] = svm_fifo_max_dequeue (s->server_rx_fifo);
384 * Flushes queue of sessions that are to be notified of new data
387 * @param thread_index Thread index for which the flush is to be performed.
388 * @return 0 on success or a positive number indicating the number of
389 * failures due to API queue being full.
392 session_manager_flush_enqueue_events (u32 thread_index)
394 session_manager_main_t *smm = &session_manager_main;
395 u32 *session_indices_to_enqueue;
398 session_indices_to_enqueue =
399 smm->session_indices_to_enqueue_by_thread[thread_index];
401 for (i = 0; i < vec_len (session_indices_to_enqueue); i++)
403 stream_session_t *s0;
406 s0 = stream_session_get_if_valid (session_indices_to_enqueue[i],
408 if (s0 == 0 || stream_session_enqueue_notify (s0, 0 /* don't block */ ))
414 vec_reset_length (session_indices_to_enqueue);
416 smm->session_indices_to_enqueue_by_thread[thread_index] =
417 session_indices_to_enqueue;
419 /* Increment enqueue epoch for next round */
420 smm->current_enqueue_epoch[thread_index]++;
426 * Init fifo tail and head pointers
428 * Useful if transport uses absolute offsets for tracking ooo segments.
431 stream_session_init_fifos_pointers (transport_connection_t * tc,
432 u32 rx_pointer, u32 tx_pointer)
435 s = session_get (tc->s_index, tc->thread_index);
436 svm_fifo_init_pointers (s->server_rx_fifo, rx_pointer);
437 svm_fifo_init_pointers (s->server_tx_fifo, tx_pointer);
441 stream_session_connect_notify (transport_connection_t * tc, u8 is_fail)
444 stream_session_t *new_s = 0;
449 handle = session_lookup_half_open_handle (tc);
450 if (handle == HALF_OPEN_LOOKUP_INVALID_VALUE)
452 SESSION_DBG ("half-open was removed!");
456 /* Cleanup half-open table */
457 session_lookup_del_half_open (tc);
459 /* Get the app's index from the handle we stored when opening connection
460 * and the opaque (api_context for external apps) from transport session
462 app = application_get_if_valid (handle >> 32);
466 opaque = tc->s_index;
470 segment_manager_t *sm;
472 sm = application_get_connect_segment_manager (app);
473 alloc_fifos = application_is_proxy (app);
474 /* Create new session (svm segments are allocated if needed) */
475 if (stream_session_create_i (sm, tc, alloc_fifos, &new_s))
481 new_s->app_index = app->index;
484 /* Notify client application */
485 if (app->cb_fns.session_connected_callback (app->index, opaque, new_s,
488 SESSION_DBG ("failed to notify app");
490 stream_session_disconnect (new_s);
495 new_s->session_state = SESSION_STATE_READY;
502 stream_session_accept_notify (transport_connection_t * tc)
504 application_t *server;
507 s = session_get (tc->s_index, tc->thread_index);
508 server = application_get (s->app_index);
509 server->cb_fns.session_accept_callback (s);
513 * Notification from transport that connection is being closed.
515 * A disconnect is sent to application but state is not removed. Once
516 * disconnect is acknowledged by application, session disconnect is called.
517 * Ultimately this leads to close being called on transport (passive close).
520 stream_session_disconnect_notify (transport_connection_t * tc)
522 application_t *server;
525 s = session_get (tc->s_index, tc->thread_index);
526 server = application_get (s->app_index);
527 server->cb_fns.session_disconnect_callback (s);
531 * Cleans up session and lookup table.
534 stream_session_delete (stream_session_t * s)
536 session_manager_main_t *smm = vnet_get_session_manager_main ();
539 /* Delete from the main lookup table. */
540 if ((rv = session_lookup_del_session (s)))
541 clib_warning ("hash delete error, rv %d", rv);
543 /* Cleanup fifo segments */
544 segment_manager_dealloc_fifos (s->svm_segment_index, s->server_rx_fifo,
547 pool_put (smm->sessions[s->thread_index], s);
549 memset (s, 0xFA, sizeof (*s));
553 * Notification from transport that connection is being deleted
555 * This removes the session if it is still valid. It should be called only on
556 * previously fully established sessions. For instance failed connects should
557 * call stream_session_connect_notify and indicate that the connect has
561 stream_session_delete_notify (transport_connection_t * tc)
565 /* App might've been removed already */
566 s = stream_session_get_if_valid (tc->s_index, tc->thread_index);
569 stream_session_delete (s);
573 * Notify application that connection has been reset.
576 stream_session_reset_notify (transport_connection_t * tc)
580 s = session_get (tc->s_index, tc->thread_index);
582 app = application_get (s->app_index);
583 app->cb_fns.session_reset_callback (s);
587 * Accept a stream session. Optionally ping the server by callback.
590 stream_session_accept (transport_connection_t * tc, u32 listener_index,
593 application_t *server;
594 stream_session_t *s, *listener;
595 segment_manager_t *sm;
599 sst = session_type_from_proto_and_ip (tc->transport_proto, tc->is_ip4);
601 /* Find the server */
602 listener = listen_session_get (sst, listener_index);
603 server = application_get (listener->app_index);
605 sm = application_get_listen_segment_manager (server, listener);
606 if ((rv = stream_session_create_i (sm, tc, 1, &s)))
609 s->app_index = server->index;
610 s->listener_index = listener_index;
611 s->session_state = SESSION_STATE_ACCEPTING;
613 /* Shoulder-tap the server */
616 server->cb_fns.session_accept_callback (s);
623 * Ask transport to open connection to remote transport endpoint.
625 * Stores handle for matching request with reply since the call can be
626 * asynchronous. For instance, for TCP the 3-way handshake must complete
627 * before reply comes. Session is only created once connection is established.
629 * @param app_index Index of the application requesting the connect
630 * @param st Session type requested.
631 * @param tep Remote transport endpoint
632 * @param res Resulting transport connection .
635 stream_session_open (u32 app_index, session_endpoint_t * rmt,
636 transport_connection_t ** res)
638 transport_connection_t *tc;
643 sst = session_type_from_proto_and_ip (rmt->transport_proto, rmt->is_ip4);
644 rv = tp_vfts[sst].open (session_endpoint_to_transport (rmt));
647 clib_warning ("Transport failed to open connection.");
648 return VNET_API_ERROR_SESSION_CONNECT;
651 tc = tp_vfts[sst].get_half_open ((u32) rv);
653 /* Save app and tc index. The latter is needed to help establish the
654 * connection while the former is needed when the connect notify comes
655 * and we have to notify the external app */
656 handle = (((u64) app_index) << 32) | (u64) tc->c_index;
658 /* Add to the half-open lookup table */
659 session_lookup_add_half_open (tc, handle);
667 * Ask transport to listen on local transport endpoint.
669 * @param s Session for which listen will be called. Note that unlike
670 * established sessions, listen sessions are not associated to a
672 * @param tep Local endpoint to be listened on.
675 stream_session_listen (stream_session_t * s, session_endpoint_t * tep)
677 transport_connection_t *tc;
680 /* Transport bind/listen */
681 tci = tp_vfts[s->session_type].bind (s->session_index,
682 session_endpoint_to_transport (tep));
684 if (tci == (u32) ~ 0)
687 /* Attach transport to session */
688 s->connection_index = tci;
689 tc = tp_vfts[s->session_type].get_listener (tci);
691 /* Weird but handle it ... */
695 /* Add to the main lookup table */
696 session_lookup_add_connection (tc, s->session_index);
702 * Ask transport to stop listening on local transport endpoint.
704 * @param s Session to stop listening on. It must be in state LISTENING.
707 stream_session_stop_listen (stream_session_t * s)
709 transport_connection_t *tc;
711 if (s->session_state != SESSION_STATE_LISTENING)
713 clib_warning ("not a listening session");
717 tc = tp_vfts[s->session_type].get_listener (s->connection_index);
720 clib_warning ("no transport");
721 return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
724 session_lookup_del_connection (tc);
725 tp_vfts[s->session_type].unbind (s->connection_index);
730 session_send_session_evt_to_thread (u64 session_handle,
731 fifo_event_type_t evt_type,
734 static u16 serial_number = 0;
736 session_fifo_event_t evt;
737 unix_shared_memory_queue_t *q;
739 /* Fabricate event */
740 evt.session_handle = session_handle;
741 evt.event_type = evt_type;
742 evt.event_id = serial_number++;
744 q = session_manager_get_vpp_event_queue (thread_index);
745 while (unix_shared_memory_queue_add (q, (u8 *) & evt, 1))
749 TCP_DBG ("failed to enqueue evt");
756 * Disconnect session and propagate to transport. This should eventually
757 * result in a delete notification that allows us to cleanup session state.
758 * Called for both active/passive disconnects.
760 * Should be called from the session's thread.
763 stream_session_disconnect (stream_session_t * s)
765 s->session_state = SESSION_STATE_CLOSED;
766 tp_vfts[s->session_type].close (s->connection_index, s->thread_index);
770 * Cleanup transport and session state.
772 * Notify transport of the cleanup, wait for a delete notify to actually
773 * remove the session state.
776 stream_session_cleanup (stream_session_t * s)
780 s->session_state = SESSION_STATE_CLOSED;
782 /* Delete from the main lookup table to avoid more enqueues */
783 rv = session_lookup_del_session (s);
785 clib_warning ("hash delete error, rv %d", rv);
787 tp_vfts[s->session_type].cleanup (s->connection_index, s->thread_index);
791 * Allocate vpp event queue (once) per worker thread
794 session_vpp_event_queue_allocate (session_manager_main_t * smm,
797 api_main_t *am = &api_main;
799 u32 event_queue_length = 2048;
801 if (smm->vpp_event_queues[thread_index] == 0)
803 /* Allocate event fifo in the /vpe-api shared-memory segment */
804 oldheap = svm_push_data_heap (am->vlib_rp);
806 if (smm->configured_event_queue_length)
807 event_queue_length = smm->configured_event_queue_length;
809 smm->vpp_event_queues[thread_index] =
810 unix_shared_memory_queue_init
812 sizeof (session_fifo_event_t), 0 /* consumer pid */ ,
813 0 /* (do not) send signal when queue non-empty */ );
815 svm_pop_heap (oldheap);
820 session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
822 if (proto == TRANSPORT_PROTO_TCP)
825 return SESSION_TYPE_IP4_TCP;
827 return SESSION_TYPE_IP6_TCP;
832 return SESSION_TYPE_IP4_UDP;
834 return SESSION_TYPE_IP6_UDP;
837 return SESSION_N_TYPES;
841 listen_session_get_local_session_endpoint (stream_session_t * listener,
842 session_endpoint_t * sep)
844 transport_connection_t *tc;
846 tp_vfts[listener->session_type].get_listener (listener->connection_index);
849 clib_warning ("no transport");
853 /* N.B. The ip should not be copied because this is the local endpoint */
854 sep->port = tc->lcl_port;
855 sep->transport_proto = tc->transport_proto;
856 sep->is_ip4 = tc->is_ip4;
860 static clib_error_t *
861 session_manager_main_enable (vlib_main_t * vm)
863 session_manager_main_t *smm = &session_manager_main;
864 vlib_thread_main_t *vtm = vlib_get_thread_main ();
866 u32 preallocated_sessions_per_worker;
869 num_threads = 1 /* main thread */ + vtm->n_threads;
872 return clib_error_return (0, "n_thread_stacks not set");
874 /* $$$ config parameters */
875 svm_fifo_segment_init (0x200000000ULL /* first segment base VA */ ,
876 20 /* timeout in seconds */ );
878 /* configure per-thread ** vectors */
879 vec_validate (smm->sessions, num_threads - 1);
880 vec_validate (smm->session_indices_to_enqueue_by_thread, num_threads - 1);
881 vec_validate (smm->tx_buffers, num_threads - 1);
882 vec_validate (smm->pending_event_vector, num_threads - 1);
883 vec_validate (smm->free_event_vector, num_threads - 1);
884 vec_validate (smm->current_enqueue_epoch, num_threads - 1);
885 vec_validate (smm->vpp_event_queues, num_threads - 1);
887 for (i = 0; i < num_threads; i++)
889 vec_validate (smm->free_event_vector[i], 0);
890 _vec_len (smm->free_event_vector[i]) = 0;
891 vec_validate (smm->pending_event_vector[i], 0);
892 _vec_len (smm->pending_event_vector[i]) = 0;
896 vec_validate (smm->last_event_poll_by_thread, num_threads - 1);
899 /* Allocate vpp event queues */
900 for (i = 0; i < vec_len (smm->vpp_event_queues); i++)
901 session_vpp_event_queue_allocate (smm, i);
903 /* Preallocate sessions */
904 if (smm->preallocated_sessions)
906 if (num_threads == 1)
908 pool_init_fixed (smm->sessions[0], smm->preallocated_sessions);
913 preallocated_sessions_per_worker =
914 (1.1 * (f64) smm->preallocated_sessions /
915 (f64) (num_threads - 1));
917 for (j = 1; j < num_threads; j++)
919 pool_init_fixed (smm->sessions[j],
920 preallocated_sessions_per_worker);
925 session_lookup_init ();
926 app_namespaces_init ();
930 /* Enable TCP transport */
931 vnet_tcp_enable_disable (vm, 1);
937 session_node_enable_disable (u8 is_en)
939 u8 state = is_en ? VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_DISABLED;
941 foreach_vlib_main (({
942 vlib_node_set_state (this_vlib_main, session_queue_node.index,
949 vnet_session_enable_disable (vlib_main_t * vm, u8 is_en)
951 clib_error_t *error = 0;
954 if (session_manager_main.is_enabled)
957 session_node_enable_disable (is_en);
958 error = session_manager_main_enable (vm);
962 session_manager_main.is_enabled = 0;
963 session_node_enable_disable (is_en);
970 session_manager_main_init (vlib_main_t * vm)
972 session_manager_main_t *smm = &session_manager_main;
977 VLIB_INIT_FUNCTION (session_manager_main_init);
979 static clib_error_t *
980 session_config_fn (vlib_main_t * vm, unformat_input_t * input)
982 session_manager_main_t *smm = &session_manager_main;
986 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
988 if (unformat (input, "event-queue-length %d", &nitems))
991 smm->configured_event_queue_length = nitems;
993 clib_warning ("event queue length %d too small, ignored", nitems);
995 else if (unformat (input, "preallocated-sessions %d",
996 &smm->preallocated_sessions))
998 else if (unformat (input, "v4-session-table-buckets %d",
999 &smm->configured_v4_session_table_buckets))
1001 else if (unformat (input, "v4-halfopen-table-buckets %d",
1002 &smm->configured_v4_halfopen_table_buckets))
1004 else if (unformat (input, "v6-session-table-buckets %d",
1005 &smm->configured_v6_session_table_buckets))
1007 else if (unformat (input, "v6-halfopen-table-buckets %d",
1008 &smm->configured_v6_halfopen_table_buckets))
1010 else if (unformat (input, "v4-session-table-memory %U",
1011 unformat_memory_size, &tmp))
1013 if (tmp >= 0x100000000)
1014 return clib_error_return (0, "memory size %llx (%lld) too large",
1016 smm->configured_v4_session_table_memory = tmp;
1018 else if (unformat (input, "v4-halfopen-table-memory %U",
1019 unformat_memory_size, &tmp))
1021 if (tmp >= 0x100000000)
1022 return clib_error_return (0, "memory size %llx (%lld) too large",
1024 smm->configured_v4_halfopen_table_memory = tmp;
1026 else if (unformat (input, "v6-session-table-memory %U",
1027 unformat_memory_size, &tmp))
1029 if (tmp >= 0x100000000)
1030 return clib_error_return (0, "memory size %llx (%lld) too large",
1032 smm->configured_v6_session_table_memory = tmp;
1034 else if (unformat (input, "v6-halfopen-table-memory %U",
1035 unformat_memory_size, &tmp))
1037 if (tmp >= 0x100000000)
1038 return clib_error_return (0, "memory size %llx (%lld) too large",
1040 smm->configured_v6_halfopen_table_memory = tmp;
1043 return clib_error_return (0, "unknown input `%U'",
1044 format_unformat_error, input);
1049 VLIB_CONFIG_FUNCTION (session_config_fn, "session");
1052 * fd.io coding-style-patch-verification: ON
1055 * eval: (c-set-style "gnu")