2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (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.
19 #include <svm/svm_fifo_segment.h>
20 #include <vlibmemory/api.h>
21 #include <vpp/api/vpe_msg_enum.h>
22 #include <vnet/session/application_interface.h>
23 #include <uri/vppcom.h>
24 #include <vlib/unix/unix.h>
25 #include <vppinfra/vec_bootstrap.h>
27 #define vl_typedefs /* define message structures */
28 #include <vpp/api/vpe_all_api_h.h>
31 /* declare message handlers for each api */
33 #define vl_endianfun /* define message structures */
34 #include <vpp/api/vpe_all_api_h.h>
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...)
40 #include <vpp/api/vpe_all_api_h.h>
44 /* Set VPPCOM_DEBUG 2 for connection debug, 3 for read/write debug output */
45 #define VPPCOM_DEBUG 1
47 #define VPPCOM_DEBUG 0
51 * VPPCOM Private definitions and functions.
71 typedef struct epoll_event vppcom_epoll_event_t;
78 vppcom_epoll_event_t ev;
79 #define VEP_DEFAULT_ET_MASK (EPOLLIN|EPOLLOUT)
91 volatile session_state_t state;
93 svm_fifo_t *server_rx_fifo;
94 svm_fifo_t *server_tx_fifo;
96 u64 vpp_session_handle;
97 unix_shared_memory_queue_t *vpp_event_queue;
99 /* Socket configuration state */
100 /* TBD: covert 'is_*' vars to bit in u8 flags; */
110 vppcom_ip46_t lcl_addr;
111 vppcom_ip46_t peer_addr;
114 u64 client_queue_address;
118 typedef struct vppcom_cfg_t_
123 u32 add_segment_size;
124 u32 preallocated_fifo_pairs;
127 u32 event_queue_size;
128 u32 listen_queue_size;
134 typedef struct vppcom_main_t_
137 u32 *client_session_index_fifo;
138 volatile u32 bind_session_index;
142 /* vpe input queue */
143 unix_shared_memory_queue_t *vl_input_queue;
145 /* API client handle */
149 clib_spinlock_t sessions_lockp;
152 /* Hash table for disconnect processing */
153 uword *session_index_by_vpp_handles;
156 clib_bitmap_t *rd_bitmap;
157 clib_bitmap_t *wr_bitmap;
158 clib_bitmap_t *ex_bitmap;
160 /* Our event queue */
161 unix_shared_memory_queue_t *app_event_queue;
163 /* unique segment name counter */
164 u32 unique_segment_index;
168 /* For deadman timers */
169 clib_time_t clib_time;
171 /* State of the connection, shared between msg RX thread and main thread */
172 volatile app_state_t app_state;
176 /* VNET_API_ERROR_FOO -> "Foo" hash table */
177 uword *error_string_by_error_number;
180 vppcom_main_t vppcom_main = {.my_client_index = ~0 };
183 vppcom_app_state_str (app_state_t state)
189 case STATE_APP_START:
190 st = "STATE_APP_START";
193 case STATE_APP_CONN_VPP:
194 st = "STATE_APP_CONN_VPP";
197 case STATE_APP_ENABLED:
198 st = "STATE_APP_ENABLED";
201 case STATE_APP_ATTACHED:
202 st = "STATE_APP_ATTACHED";
206 st = "UNKNOWN_APP_STATE";
214 vppcom_session_state_str (session_state_t state)
225 st = "STATE_CONNECT";
236 case STATE_DISCONNECT:
237 st = "STATE_DISCONNECT";
245 st = "UNKNOWN_STATE";
253 * VPPCOM Utility Functions
256 vppcom_session_at_index (u32 session_index, session_t * volatile *sess)
258 vppcom_main_t *vcm = &vppcom_main;
260 /* Assumes that caller has acquired spinlock: vcm->sessions_lockp */
261 if (PREDICT_FALSE ((session_index == ~0) ||
262 pool_is_free_index (vcm->sessions, session_index)))
264 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
265 vcm->my_pid, session_index);
266 return VPPCOM_EBADFD;
268 *sess = pool_elt_at_index (vcm->sessions, session_index);
273 vppcom_connect_to_vpp (char *app_name)
275 api_main_t *am = &api_main;
276 vppcom_main_t *vcm = &vppcom_main;
278 if (VPPCOM_DEBUG > 0)
279 printf ("\nConnecting to VPP api...");
280 if (vl_client_connect_to_vlib ("/vpe-api", app_name, 32) < 0)
282 clib_warning ("[%d] connect to vpp (%s) failed!",
283 vcm->my_pid, app_name);
284 return VPPCOM_ECONNREFUSED;
287 vcm->vl_input_queue = am->shmem_hdr->vl_input_queue;
288 vcm->my_client_index = am->my_client_index;
289 if (VPPCOM_DEBUG > 0)
290 printf (" connected!\n");
292 vcm->app_state = STATE_APP_CONN_VPP;
297 format_api_error (u8 * s, va_list * args)
299 vppcom_main_t *vcm = &vppcom_main;
300 i32 error = va_arg (*args, u32);
303 p = hash_get (vcm->error_string_by_error_number, -error);
306 s = format (s, "%s (%d)", p[0], error);
308 s = format (s, "%d", error);
313 vppcom_init_error_string_table (void)
315 vppcom_main_t *vcm = &vppcom_main;
317 vcm->error_string_by_error_number = hash_create (0, sizeof (uword));
319 #define _(n,v,s) hash_set (vcm->error_string_by_error_number, -v, s);
320 foreach_vnet_api_error;
323 hash_set (vcm->error_string_by_error_number, 99, "Misc");
327 vppcom_wait_for_app_state_change (app_state_t app_state)
329 vppcom_main_t *vcm = &vppcom_main;
330 f64 timeout = clib_time_now (&vcm->clib_time) + vcm->cfg.app_timeout;
332 while (clib_time_now (&vcm->clib_time) < timeout)
334 if (vcm->app_state == app_state)
337 if (VPPCOM_DEBUG > 0)
338 clib_warning ("[%d] timeout waiting for state %s (%d)", vcm->my_pid,
339 vppcom_app_state_str (app_state), app_state);
340 return VPPCOM_ETIMEDOUT;
344 vppcom_wait_for_session_state_change (u32 session_index,
345 session_state_t state,
348 vppcom_main_t *vcm = &vppcom_main;
349 f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time;
350 session_t *volatile session;
355 clib_spinlock_lock (&vcm->sessions_lockp);
356 rv = vppcom_session_at_index (session_index, &session);
357 if (PREDICT_FALSE (rv))
359 clib_spinlock_unlock (&vcm->sessions_lockp);
362 if (session->state == state)
364 clib_spinlock_unlock (&vcm->sessions_lockp);
367 clib_spinlock_unlock (&vcm->sessions_lockp);
369 while (clib_time_now (&vcm->clib_time) < timeout);
371 if (VPPCOM_DEBUG > 0)
372 clib_warning ("[%d] timeout waiting for state %s (%d)", vcm->my_pid,
373 vppcom_session_state_str (state), state);
374 return VPPCOM_ETIMEDOUT;
378 vppcom_wait_for_client_session_index (f64 wait_for_time)
380 vppcom_main_t *vcm = &vppcom_main;
381 f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time;
385 if (clib_fifo_elts (vcm->client_session_index_fifo))
388 while (clib_time_now (&vcm->clib_time) < timeout);
390 if (wait_for_time == 0)
391 return VPPCOM_EAGAIN;
393 if (VPPCOM_DEBUG > 0)
394 clib_warning ("[%d] timeout waiting for client_session_index",
396 return VPPCOM_ETIMEDOUT;
400 * VPP-API message functions
403 vppcom_send_session_enable_disable (u8 is_enable)
405 vppcom_main_t *vcm = &vppcom_main;
406 vl_api_session_enable_disable_t *bmp;
407 bmp = vl_msg_api_alloc (sizeof (*bmp));
408 memset (bmp, 0, sizeof (*bmp));
410 bmp->_vl_msg_id = ntohs (VL_API_SESSION_ENABLE_DISABLE);
411 bmp->client_index = vcm->my_client_index;
412 bmp->context = htonl (0xfeedface);
413 bmp->is_enable = is_enable;
414 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
418 vppcom_app_session_enable (void)
420 vppcom_main_t *vcm = &vppcom_main;
423 if (vcm->app_state != STATE_APP_ENABLED)
425 vppcom_send_session_enable_disable (1 /* is_enabled == TRUE */ );
426 rv = vppcom_wait_for_app_state_change (STATE_APP_ENABLED);
427 if (PREDICT_FALSE (rv))
429 if (VPPCOM_DEBUG > 0)
430 clib_warning ("[%d] Session enable timed out, rv = %s (%d)",
431 vcm->my_pid, vppcom_retval_str (rv), rv);
439 vl_api_session_enable_disable_reply_t_handler
440 (vl_api_session_enable_disable_reply_t * mp)
442 vppcom_main_t *vcm = &vppcom_main;
446 clib_warning ("[%d] session_enable_disable failed: %U", vcm->my_pid,
447 format_api_error, ntohl (mp->retval));
450 vcm->app_state = STATE_APP_ENABLED;
454 vppcom_app_send_attach (void)
456 vppcom_main_t *vcm = &vppcom_main;
457 vl_api_application_attach_t *bmp;
458 bmp = vl_msg_api_alloc (sizeof (*bmp));
459 memset (bmp, 0, sizeof (*bmp));
461 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
462 bmp->client_index = vcm->my_client_index;
463 bmp->context = htonl (0xfeedface);
464 bmp->options[APP_OPTIONS_FLAGS] =
465 APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT |
466 APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE | APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
467 bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
468 bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
469 bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
470 bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
471 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
475 vppcom_app_attach (void)
477 vppcom_main_t *vcm = &vppcom_main;
480 vppcom_app_send_attach ();
481 rv = vppcom_wait_for_app_state_change (STATE_APP_ATTACHED);
482 if (PREDICT_FALSE (rv))
484 if (VPPCOM_DEBUG > 0)
485 clib_warning ("[%d] application attach timed out, rv = %s (%d)",
486 vcm->my_pid, vppcom_retval_str (rv), rv);
493 vppcom_app_detach (void)
495 vppcom_main_t *vcm = &vppcom_main;
496 vl_api_application_detach_t *bmp;
497 bmp = vl_msg_api_alloc (sizeof (*bmp));
498 memset (bmp, 0, sizeof (*bmp));
500 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
501 bmp->client_index = vcm->my_client_index;
502 bmp->context = htonl (0xfeedface);
503 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
507 vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
510 vppcom_main_t *vcm = &vppcom_main;
511 static svm_fifo_segment_create_args_t _a;
512 svm_fifo_segment_create_args_t *a = &_a;
515 memset (a, 0, sizeof (*a));
518 clib_warning ("[%d] attach failed: %U", vcm->my_pid,
519 format_api_error, ntohl (mp->retval));
523 if (mp->segment_name_length == 0)
525 clib_warning ("[%d] segment_name_length zero", vcm->my_pid);
529 a->segment_name = (char *) mp->segment_name;
530 a->segment_size = mp->segment_size;
532 ASSERT (mp->app_event_queue_address);
534 /* Attach to the segment vpp created */
535 rv = svm_fifo_segment_attach (a);
536 vec_reset_length (a->new_segment_indices);
537 if (PREDICT_FALSE (rv))
539 clib_warning ("[%d] svm_fifo_segment_attach ('%s') failed", vcm->my_pid,
544 vcm->app_event_queue =
545 uword_to_pointer (mp->app_event_queue_address,
546 unix_shared_memory_queue_t *);
548 vcm->app_state = STATE_APP_ATTACHED;
552 vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
555 vppcom_main_t *vcm = &vppcom_main;
558 clib_warning ("[%d] detach failed: %U", vcm->my_pid, format_api_error,
561 vcm->app_state = STATE_APP_ENABLED;
565 vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
568 vppcom_main_t *vcm = &vppcom_main;
571 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
574 session_t *session = 0;
576 clib_spinlock_lock (&vcm->sessions_lockp);
577 rv = vppcom_session_at_index (p[0], &session);
578 if (PREDICT_FALSE (rv))
580 if (VPPCOM_DEBUG > 1)
581 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
584 hash_unset (vcm->session_index_by_vpp_handles, mp->handle);
585 session->state = STATE_DISCONNECT;
586 clib_spinlock_unlock (&vcm->sessions_lockp);
590 if (VPPCOM_DEBUG > 1)
591 clib_warning ("[%d] couldn't find session key %llx", vcm->my_pid,
596 clib_warning ("[%d] disconnect_session failed: %U", vcm->my_pid,
597 format_api_error, ntohl (mp->retval));
601 vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
603 vppcom_main_t *vcm = &vppcom_main;
604 static svm_fifo_segment_create_args_t _a;
605 svm_fifo_segment_create_args_t *a = &_a;
608 memset (a, 0, sizeof (*a));
609 a->segment_name = (char *) mp->segment_name;
610 a->segment_size = mp->segment_size;
611 /* Attach to the segment vpp created */
612 rv = svm_fifo_segment_attach (a);
613 vec_reset_length (a->new_segment_indices);
614 if (PREDICT_FALSE (rv))
616 clib_warning ("[%d] svm_fifo_segment_attach ('%s') failed",
617 vcm->my_pid, mp->segment_name);
620 if (VPPCOM_DEBUG > 1)
621 clib_warning ("[%d] mapped new segment '%s' size %d", vcm->my_pid,
622 mp->segment_name, mp->segment_size);
626 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
628 vppcom_main_t *vcm = &vppcom_main;
629 session_t *session = 0;
630 vl_api_disconnect_session_reply_t *rmp;
634 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
638 clib_spinlock_lock (&vcm->sessions_lockp);
639 rval = vppcom_session_at_index (p[0], &session);
640 if (PREDICT_FALSE (rval))
642 if (VPPCOM_DEBUG > 1)
643 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
647 pool_put (vcm->sessions, session);
648 clib_spinlock_unlock (&vcm->sessions_lockp);
649 hash_unset (vcm->session_index_by_vpp_handles, mp->handle);
653 clib_warning ("[%d] couldn't find session key %llx", vcm->my_pid,
658 rmp = vl_msg_api_alloc (sizeof (*rmp));
659 memset (rmp, 0, sizeof (*rmp));
661 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
662 rmp->retval = htonl (rv);
663 rmp->handle = mp->handle;
664 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
668 vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
670 vppcom_main_t *vcm = &vppcom_main;
671 session_t *session = 0;
672 vl_api_reset_session_reply_t *rmp;
676 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
680 clib_spinlock_lock (&vcm->sessions_lockp);
681 rval = vppcom_session_at_index (p[0], &session);
682 if (PREDICT_FALSE (rval))
684 if (VPPCOM_DEBUG > 1)
685 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
689 pool_put (vcm->sessions, session);
690 clib_spinlock_unlock (&vcm->sessions_lockp);
691 hash_unset (vcm->session_index_by_vpp_handles, mp->handle);
695 clib_warning ("[%d] couldn't find session key %llx", vcm->my_pid,
700 rmp = vl_msg_api_alloc (sizeof (*rmp));
701 memset (rmp, 0, sizeof (*rmp));
702 rmp->_vl_msg_id = ntohs (VL_API_RESET_SESSION_REPLY);
703 rmp->retval = htonl (rv);
704 rmp->handle = mp->handle;
705 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
709 vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp)
711 vppcom_main_t *vcm = &vppcom_main;
714 svm_fifo_t *rx_fifo, *tx_fifo;
720 clib_warning ("[%d] connect failed: %U", vcm->my_pid, format_api_error,
725 session_index = mp->context;
726 if (VPPCOM_DEBUG > 1)
727 clib_warning ("[%d] session_index = %d 0x%08x", vcm->my_pid,
728 session_index, session_index);
730 clib_spinlock_lock (&vcm->sessions_lockp);
731 if (pool_is_free_index (vcm->sessions, session_index))
733 clib_spinlock_unlock (&vcm->sessions_lockp);
734 if (VPPCOM_DEBUG > 1)
735 clib_warning ("[%d] invalid session, sid %d is closed!",
736 vcm->my_pid, session_index);
740 /* We've been redirected */
741 if (mp->segment_name_length > 0)
743 static svm_fifo_segment_create_args_t _a;
744 svm_fifo_segment_create_args_t *a = &_a;
747 memset (a, 0, sizeof (*a));
748 a->segment_name = (char *) mp->segment_name;
749 if (VPPCOM_DEBUG > 1)
750 clib_warning ("[%d] cut-thru segment: %s", vcm->my_pid,
752 rv = svm_fifo_segment_attach (a);
753 vec_reset_length (a->new_segment_indices);
754 if (PREDICT_FALSE (rv))
756 clib_spinlock_unlock (&vcm->sessions_lockp);
757 clib_warning ("[%d] sm_fifo_segment_attach ('%s') failed",
758 vcm->my_pid, a->segment_name);
766 if (VPPCOM_DEBUG > 1)
767 clib_warning ("[%d] client sid %d", vcm->my_pid, session_index);
769 session = pool_elt_at_index (vcm->sessions, session_index);
770 session->is_cut_thru = is_cut_thru;
771 session->vpp_event_queue = uword_to_pointer (mp->vpp_event_queue_address,
772 unix_shared_memory_queue_t *);
774 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
775 rx_fifo->client_session_index = session_index;
776 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
777 tx_fifo->client_session_index = session_index;
779 session->server_rx_fifo = rx_fifo;
780 session->server_tx_fifo = tx_fifo;
781 session->vpp_session_handle = mp->handle;
782 session->state = STATE_CONNECT;
784 /* Add it to lookup table */
785 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
786 clib_spinlock_unlock (&vcm->sessions_lockp);
790 vppcom_send_connect_sock (session_t * session, u32 session_index)
792 vppcom_main_t *vcm = &vppcom_main;
793 vl_api_connect_sock_t *cmp;
795 /* Assumes caller as acquired the spinlock: vcm->sessions_lockp */
796 session->is_server = 0;
797 cmp = vl_msg_api_alloc (sizeof (*cmp));
798 memset (cmp, 0, sizeof (*cmp));
799 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_SOCK);
800 cmp->client_index = vcm->my_client_index;
801 cmp->context = session_index;
803 if (VPPCOM_DEBUG > 1)
804 clib_warning ("[%d] session_index = %d 0x%08x",
805 vcm->my_pid, session_index, session_index);
807 cmp->vrf = session->vrf;
808 cmp->is_ip4 = session->peer_addr.is_ip4;
809 clib_memcpy (cmp->ip, &session->peer_addr.ip46, sizeof (cmp->ip));
810 cmp->port = session->port;
811 cmp->proto = session->proto;
812 clib_memcpy (cmp->options, session->options, sizeof (cmp->options));
813 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & cmp);
817 vppcom_send_disconnect (u32 session_index)
819 vppcom_main_t *vcm = &vppcom_main;
820 vl_api_disconnect_session_t *dmp;
821 session_t *session = 0;
824 clib_spinlock_lock (&vcm->sessions_lockp);
825 rv = vppcom_session_at_index (session_index, &session);
826 if (PREDICT_FALSE (rv))
828 clib_spinlock_unlock (&vcm->sessions_lockp);
829 if (VPPCOM_DEBUG > 1)
830 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
831 vcm->my_pid, session_index);
835 dmp = vl_msg_api_alloc (sizeof (*dmp));
836 memset (dmp, 0, sizeof (*dmp));
837 dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
838 dmp->client_index = vcm->my_client_index;
839 dmp->handle = session->vpp_session_handle;
840 clib_spinlock_unlock (&vcm->sessions_lockp);
841 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & dmp);
846 vl_api_bind_sock_reply_t_handler (vl_api_bind_sock_reply_t * mp)
848 vppcom_main_t *vcm = &vppcom_main;
849 session_t *session = 0;
853 clib_warning ("[%d] bind failed: %U", vcm->my_pid, format_api_error,
856 ASSERT (vcm->bind_session_index != ~0);
858 clib_spinlock_lock (&vcm->sessions_lockp);
859 rv = vppcom_session_at_index (vcm->bind_session_index, &session);
862 session->vpp_session_handle = mp->handle;
863 hash_set (vcm->session_index_by_vpp_handles, mp->handle,
864 vcm->bind_session_index);
865 session->state = mp->retval ? STATE_FAILED : STATE_LISTEN;
866 vcm->bind_session_index = ~0;
868 clib_spinlock_unlock (&vcm->sessions_lockp);
872 vl_api_unbind_sock_reply_t_handler (vl_api_unbind_sock_reply_t * mp)
874 vppcom_main_t *vcm = &vppcom_main;
875 session_t *session = 0;
878 clib_spinlock_lock (&vcm->sessions_lockp);
879 rv = vppcom_session_at_index (vcm->bind_session_index, &session);
882 if ((VPPCOM_DEBUG > 1) && (mp->retval))
883 clib_warning ("[%d] unbind failed: %U", vcm->my_pid, format_api_error,
886 vcm->bind_session_index = ~0;
887 session->state = STATE_START;
889 clib_spinlock_unlock (&vcm->sessions_lockp);
893 format_ip4_address (u8 * s, va_list * args)
895 u8 *a = va_arg (*args, u8 *);
896 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
900 format_ip6_address (u8 * s, va_list * args)
902 ip6_address_t *a = va_arg (*args, ip6_address_t *);
903 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
905 i_max_n_zero = ARRAY_LEN (a->as_u16);
907 i_first_zero = i_max_n_zero;
909 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
911 u32 is_zero = a->as_u16[i] == 0;
912 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
918 if ((!is_zero && n_zeros > max_n_zeros)
919 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
921 i_max_n_zero = i_first_zero;
922 max_n_zeros = n_zeros;
923 i_first_zero = ARRAY_LEN (a->as_u16);
928 last_double_colon = 0;
929 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
931 if (i == i_max_n_zero && max_n_zeros > 1)
933 s = format (s, "::");
934 i += max_n_zeros - 1;
935 last_double_colon = 1;
939 s = format (s, "%s%x",
940 (last_double_colon || i == 0) ? "" : ":",
941 clib_net_to_host_u16 (a->as_u16[i]));
942 last_double_colon = 0;
949 /* Format an IP46 address. */
951 format_ip46_address (u8 * s, va_list * args)
953 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
954 ip46_type_t type = va_arg (*args, ip46_type_t);
960 is_ip4 = ip46_address_is_ip4 (ip46);
971 format (s, "%U", format_ip4_address, &ip46->ip4) :
972 format (s, "%U", format_ip6_address, &ip46->ip6);
976 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
978 vppcom_main_t *vcm = &vppcom_main;
979 vl_api_accept_session_reply_t *rmp;
980 svm_fifo_t *rx_fifo, *tx_fifo;
985 if (!clib_fifo_free_elts (vcm->client_session_index_fifo))
987 clib_warning ("[%d] client session queue is full!", vcm->my_pid);
988 rv = VNET_API_ERROR_QUEUE_FULL;
992 if (VPPCOM_DEBUG > 1)
994 u8 *ip_str = format (0, "%U", format_ip46_address, &mp->ip, mp->is_ip4);
995 clib_warning ("[%d] accepted session from: %s:%d", vcm->my_pid, ip_str,
996 clib_net_to_host_u16 (mp->port));
1000 clib_spinlock_lock (&vcm->sessions_lockp);
1001 /* Allocate local session and set it up */
1002 pool_get (vcm->sessions, session);
1003 memset (session, 0, sizeof (*session));
1004 session_index = session - vcm->sessions;
1006 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
1007 rx_fifo->client_session_index = session_index;
1008 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
1009 tx_fifo->client_session_index = session_index;
1011 session->server_rx_fifo = rx_fifo;
1012 session->server_tx_fifo = tx_fifo;
1013 session->vpp_event_queue = uword_to_pointer (mp->vpp_event_queue_address,
1014 unix_shared_memory_queue_t *);
1015 session->state = STATE_ACCEPT;
1016 session->is_cut_thru = 0;
1017 session->is_server = 1;
1018 session->port = ntohs (mp->port);
1019 session->peer_addr.is_ip4 = mp->is_ip4;
1020 clib_memcpy (&session->peer_addr.ip46, mp->ip,
1021 sizeof (session->peer_addr.ip46));
1023 /* Add it to lookup table */
1024 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
1026 clib_fifo_add1 (vcm->client_session_index_fifo, session_index);
1027 clib_spinlock_unlock (&vcm->sessions_lockp);
1030 * Send accept reply to vpp
1033 rmp = vl_msg_api_alloc (sizeof (*rmp));
1034 memset (rmp, 0, sizeof (*rmp));
1035 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
1036 rmp->retval = htonl (rv);
1037 rmp->handle = mp->handle;
1038 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
1042 * Acting as server for redirected connect requests
1045 vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
1047 static svm_fifo_segment_create_args_t _a;
1048 svm_fifo_segment_create_args_t *a = &_a;
1049 vppcom_main_t *vcm = &vppcom_main;
1051 svm_fifo_segment_private_t *seg;
1052 unix_shared_memory_queue_t *client_q;
1053 vl_api_connect_session_reply_t *rmp;
1054 session_t *session = 0;
1056 svm_fifo_t *rx_fifo;
1057 svm_fifo_t *tx_fifo;
1058 unix_shared_memory_queue_t *event_q = 0;
1060 clib_spinlock_lock (&vcm->sessions_lockp);
1061 if (!clib_fifo_free_elts (vcm->client_session_index_fifo))
1063 if (VPPCOM_DEBUG > 1)
1064 clib_warning ("[%d] client session queue is full!", vcm->my_pid);
1065 rv = VNET_API_ERROR_QUEUE_FULL;
1066 clib_spinlock_unlock (&vcm->sessions_lockp);
1070 /* Create the segment */
1071 memset (a, 0, sizeof (*a));
1072 a->segment_name = (char *) format ((u8 *) a->segment_name, "%d:segment%d%c",
1073 vcm->my_pid, vcm->unique_segment_index++,
1075 a->segment_size = vcm->cfg.segment_size;
1076 a->preallocated_fifo_pairs = vcm->cfg.preallocated_fifo_pairs;
1077 a->rx_fifo_size = vcm->cfg.rx_fifo_size;
1078 a->tx_fifo_size = vcm->cfg.tx_fifo_size;
1080 rv = svm_fifo_segment_create (a);
1081 if (PREDICT_FALSE (rv))
1083 if (VPPCOM_DEBUG > 1)
1084 clib_warning ("[%d] svm_fifo_segment_create ('%s') failed",
1085 vcm->my_pid, a->segment_name);
1086 vec_reset_length (a->new_segment_indices);
1087 rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
1091 if (VPPCOM_DEBUG > 1)
1092 clib_warning ("[%d] created segment '%s'", vcm->my_pid, a->segment_name);
1094 pool_get (vcm->sessions, session);
1095 memset (session, 0, sizeof (*session));
1096 session_index = session - vcm->sessions;
1098 session->sm_seg_index = a->new_segment_indices[0];
1099 vec_reset_length (a->new_segment_indices);
1101 seg = svm_fifo_segment_get_segment (session->sm_seg_index);
1102 rx_fifo = session->server_rx_fifo =
1103 svm_fifo_segment_alloc_fifo (seg, vcm->cfg.rx_fifo_size,
1104 FIFO_SEGMENT_RX_FREELIST);
1105 if (PREDICT_FALSE (!session->server_rx_fifo))
1107 svm_fifo_segment_delete (seg);
1108 clib_warning ("[%d] rx fifo alloc failed, size %ld (0x%lx)",
1109 vcm->my_pid, vcm->cfg.rx_fifo_size,
1110 vcm->cfg.rx_fifo_size);
1111 rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
1112 clib_spinlock_unlock (&vcm->sessions_lockp);
1116 tx_fifo = session->server_tx_fifo =
1117 svm_fifo_segment_alloc_fifo (seg, vcm->cfg.tx_fifo_size,
1118 FIFO_SEGMENT_TX_FREELIST);
1119 if (PREDICT_FALSE (!session->server_tx_fifo))
1121 svm_fifo_segment_delete (seg);
1122 if (VPPCOM_DEBUG > 1)
1123 clib_warning ("[%d] tx fifo alloc failed, size %ld (0x%lx)",
1124 vcm->my_pid, vcm->cfg.tx_fifo_size,
1125 vcm->cfg.tx_fifo_size);
1126 rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
1127 clib_spinlock_unlock (&vcm->sessions_lockp);
1131 session->server_rx_fifo->master_session_index = session_index;
1132 session->server_tx_fifo->master_session_index = session_index;
1133 session->client_queue_address = mp->client_queue_address;
1134 session->is_cut_thru = 1;
1135 session->is_server = 1;
1136 session->port = mp->port;
1137 session->peer_addr.is_ip4 = mp->is_ip4;
1138 clib_memcpy (&session->peer_addr.ip46, mp->ip,
1139 sizeof (session->peer_addr.ip46));
1142 ssvm_shared_header_t *sh = seg->ssvm.sh;
1144 ssvm_lock_non_recursive (sh, 1);
1145 oldheap = ssvm_push_heap (sh);
1146 event_q = session->vpp_event_queue =
1147 unix_shared_memory_queue_init (vcm->cfg.event_queue_size,
1148 sizeof (session_fifo_event_t),
1149 vcm->my_pid, 0 /* signal not sent */ );
1150 ssvm_pop_heap (oldheap);
1151 ssvm_unlock_non_recursive (sh);
1154 session->state = STATE_ACCEPT;
1155 if (VPPCOM_DEBUG > 1)
1156 clib_warning ("[%d] Connected cut-thru to client: sid %d",
1157 vcm->my_pid, session_index);
1158 clib_fifo_add1 (vcm->client_session_index_fifo, session_index);
1159 clib_spinlock_unlock (&vcm->sessions_lockp);
1162 rmp = vl_msg_api_alloc (sizeof (*rmp));
1163 memset (rmp, 0, sizeof (*rmp));
1165 rmp->_vl_msg_id = ntohs (VL_API_CONNECT_SESSION_REPLY);
1166 rmp->context = mp->context;
1167 rmp->retval = htonl (rv);
1168 rmp->segment_name_length = vec_len (a->segment_name);
1169 clib_memcpy (rmp->segment_name, a->segment_name, vec_len (a->segment_name));
1170 vec_reset_length (a->segment_name);
1174 rmp->vpp_event_queue_address = pointer_to_uword (event_q);
1175 rmp->server_rx_fifo = pointer_to_uword (rx_fifo);
1176 rmp->server_tx_fifo = pointer_to_uword (tx_fifo);
1179 uword_to_pointer (mp->client_queue_address, unix_shared_memory_queue_t *);
1182 vl_msg_api_send_shmem (client_q, (u8 *) & rmp);
1186 vppcom_send_bind_sock (session_t * session)
1188 vppcom_main_t *vcm = &vppcom_main;
1189 vl_api_bind_sock_t *bmp;
1191 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
1192 session->is_server = 1;
1193 bmp = vl_msg_api_alloc (sizeof (*bmp));
1194 memset (bmp, 0, sizeof (*bmp));
1196 bmp->_vl_msg_id = ntohs (VL_API_BIND_SOCK);
1197 bmp->client_index = vcm->my_client_index;
1198 bmp->context = htonl (0xfeedface);
1199 bmp->vrf = session->vrf;
1200 bmp->is_ip4 = session->lcl_addr.is_ip4;
1201 clib_memcpy (bmp->ip, &session->lcl_addr.ip46, sizeof (bmp->ip));
1202 bmp->port = session->port;
1203 bmp->proto = session->proto;
1204 clib_memcpy (bmp->options, session->options, sizeof (bmp->options));
1205 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
1209 vppcom_send_unbind_sock (u32 session_index)
1211 vppcom_main_t *vcm = &vppcom_main;
1212 vl_api_unbind_sock_t *ump;
1213 session_t *session = 0;
1216 clib_spinlock_lock (&vcm->sessions_lockp);
1217 rv = vppcom_session_at_index (session_index, &session);
1218 if (PREDICT_FALSE (rv))
1220 clib_spinlock_unlock (&vcm->sessions_lockp);
1221 if (VPPCOM_DEBUG > 0)
1222 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
1223 vcm->my_pid, session_index);
1227 ump = vl_msg_api_alloc (sizeof (*ump));
1228 memset (ump, 0, sizeof (*ump));
1230 ump->_vl_msg_id = ntohs (VL_API_UNBIND_SOCK);
1231 ump->client_index = vcm->my_client_index;
1232 ump->handle = session->vpp_session_handle;
1233 clib_spinlock_unlock (&vcm->sessions_lockp);
1234 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & ump);
1238 vppcom_session_unbind_cut_thru (session_t * session)
1240 svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
1241 svm_fifo_segment_private_t *seg;
1244 seg = vec_elt_at_index (sm->segments, session->sm_seg_index);
1245 svm_fifo_segment_free_fifo (seg, session->server_rx_fifo,
1246 FIFO_SEGMENT_RX_FREELIST);
1247 svm_fifo_segment_free_fifo (seg, session->server_tx_fifo,
1248 FIFO_SEGMENT_TX_FREELIST);
1249 svm_fifo_segment_delete (seg);
1255 vppcom_session_unbind (u32 session_index)
1257 vppcom_main_t *vcm = &vppcom_main;
1260 clib_spinlock_lock (&vcm->sessions_lockp);
1261 if (PREDICT_FALSE (pool_is_free_index (vcm->sessions, session_index)))
1263 clib_spinlock_unlock (&vcm->sessions_lockp);
1264 if (VPPCOM_DEBUG > 1)
1265 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
1266 vcm->my_pid, session_index);
1267 return VPPCOM_EBADFD;
1269 clib_spinlock_unlock (&vcm->sessions_lockp);
1271 vcm->bind_session_index = session_index;
1272 vppcom_send_unbind_sock (session_index);
1273 rv = vppcom_wait_for_session_state_change (session_index, STATE_START,
1274 vcm->cfg.session_timeout);
1275 if (PREDICT_FALSE (rv))
1277 vcm->bind_session_index = ~0;
1278 if (VPPCOM_DEBUG > 0)
1279 clib_warning ("[%d] server unbind timed out, rv = %s (%d)",
1280 vcm->my_pid, vppcom_retval_str (rv), rv);
1287 vppcom_session_disconnect (u32 session_index)
1289 vppcom_main_t *vcm = &vppcom_main;
1292 rv = vppcom_send_disconnect (session_index);
1293 if (PREDICT_FALSE (rv))
1296 rv = vppcom_wait_for_session_state_change (session_index, STATE_DISCONNECT,
1297 vcm->cfg.session_timeout);
1298 if (PREDICT_FALSE (rv))
1300 if (VPPCOM_DEBUG > 0)
1301 clib_warning ("[%d] client disconnect timed out, rv = %s (%d)",
1302 vcm->my_pid, vppcom_retval_str (rv), rv);
1308 #define foreach_sock_msg \
1309 _(SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \
1310 _(BIND_SOCK_REPLY, bind_sock_reply) \
1311 _(UNBIND_SOCK_REPLY, unbind_sock_reply) \
1312 _(ACCEPT_SESSION, accept_session) \
1313 _(CONNECT_SOCK, connect_sock) \
1314 _(CONNECT_SESSION_REPLY, connect_session_reply) \
1315 _(DISCONNECT_SESSION, disconnect_session) \
1316 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
1317 _(RESET_SESSION, reset_session) \
1318 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
1319 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
1320 _(MAP_ANOTHER_SEGMENT, map_another_segment)
1323 vppcom_api_hookup (void)
1326 vl_msg_api_set_handlers(VL_API_##N, #n, \
1327 vl_api_##n##_t_handler, \
1329 vl_api_##n##_t_endian, \
1330 vl_api_##n##_t_print, \
1331 sizeof(vl_api_##n##_t), 1);
1337 vppcom_cfg_init (vppcom_cfg_t * vcl_cfg)
1341 vcl_cfg->heapsize = (256ULL << 20);
1342 vcl_cfg->segment_baseva = 0x200000000ULL;
1343 vcl_cfg->segment_size = (256 << 20);
1344 vcl_cfg->add_segment_size = (128 << 20);
1345 vcl_cfg->preallocated_fifo_pairs = 8;
1346 vcl_cfg->rx_fifo_size = (1 << 20);
1347 vcl_cfg->tx_fifo_size = (1 << 20);
1348 vcl_cfg->event_queue_size = 2048;
1349 vcl_cfg->listen_queue_size = CLIB_CACHE_LINE_BYTES / sizeof (u32);
1350 vcl_cfg->app_timeout = 10 * 60.0;
1351 vcl_cfg->session_timeout = 10 * 60.0;
1352 vcl_cfg->accept_timeout = 60.0;
1356 vppcom_cfg_heapsize (char *conf_fname)
1358 vppcom_main_t *vcm = &vppcom_main;
1359 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
1370 fp = fopen (conf_fname, "r");
1373 if (VPPCOM_DEBUG > 0)
1374 fprintf (stderr, "open configuration file '%s' failed\n", conf_fname);
1377 argv = calloc (1, sizeof (char *));
1383 if (fgets (inbuf, 4096, fp) == 0)
1385 p = strtok (inbuf, " \t\n");
1391 char **tmp = realloc (argv, argc * sizeof (char *));
1395 arg = strndup (p, 1024);
1398 argv[argc - 1] = arg;
1399 p = strtok (NULL, " \t\n");
1406 char **tmp = realloc (argv, (argc + 1) * sizeof (char *));
1413 * Look for and parse the "heapsize" config parameter.
1414 * Manual since none of the clib infra has been bootstrapped yet.
1416 * Format: heapsize <nn>[mM][gG]
1419 for (i = 1; i < (argc - 1); i++)
1421 if (!strncmp (argv[i], "heapsize", 8))
1423 sizep = (u8 *) argv[i + 1];
1425 while (*sizep >= '0' && *sizep <= '9')
1428 size += *sizep++ - '0';
1432 if (VPPCOM_DEBUG > 0)
1433 clib_warning ("[%d] parse error '%s %s', "
1434 "using default heapsize %lld (0x%llx)",
1435 vcm->my_pid, argv[i], argv[i + 1],
1436 vcl_cfg->heapsize, vcl_cfg->heapsize);
1440 if (*sizep == 'g' || *sizep == 'G')
1441 vcl_cfg->heapsize = size << 30;
1442 else if (*sizep == 'm' || *sizep == 'M')
1443 vcl_cfg->heapsize = size << 20;
1446 if (VPPCOM_DEBUG > 0)
1447 clib_warning ("[%d] parse error '%s %s', "
1448 "using default heapsize %lld (0x%llx)",
1449 vcm->my_pid, argv[i], argv[i + 1],
1450 vcl_cfg->heapsize, vcl_cfg->heapsize);
1461 if (!clib_mem_init (0, vcl_cfg->heapsize))
1462 clib_warning ("[%d] vppcom heap allocation failure!", vcm->my_pid);
1463 else if (VPPCOM_DEBUG > 0)
1464 clib_warning ("[%d] allocated vppcom heapsize %lld (0x%llx)",
1465 vcm->my_pid, vcl_cfg->heapsize, vcl_cfg->heapsize);
1469 vppcom_cfg_read (char *conf_fname)
1471 vppcom_main_t *vcm = &vppcom_main;
1472 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
1474 unformat_input_t _input, *input = &_input;
1475 unformat_input_t _line_input, *line_input = &_line_input;
1476 u8 vc_cfg_input = 0;
1481 fd = open (conf_fname, O_RDONLY);
1484 if (VPPCOM_DEBUG > 0)
1485 clib_warning ("[%d] open configuration file '%s' failed!",
1486 vcm->my_pid, conf_fname);
1490 if (fstat (fd, &s) < 0)
1492 if (VPPCOM_DEBUG > 0)
1493 clib_warning ("[%d] failed to stat `%s'", vcm->my_pid, conf_fname);
1497 if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode)))
1499 if (VPPCOM_DEBUG > 0)
1500 clib_warning ("[%d] not a regular file `%s'", vcm->my_pid,
1505 unformat_init_clib_file (input, fd);
1507 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1509 (void) unformat_user (input, unformat_line_input, line_input);
1510 unformat_skip_white_space (line_input);
1512 if (unformat (line_input, "vppcom {"))
1520 if (unformat (line_input, "heapsize %s", &chroot_path))
1522 vec_terminate_c_string (chroot_path);
1523 if (VPPCOM_DEBUG > 0)
1524 clib_warning ("[%d] configured heapsize %s, "
1525 "actual heapsize %lld (0x%llx)",
1526 vcm->my_pid, chroot_path, vcl_cfg->heapsize,
1528 vec_free (chroot_path);
1530 else if (unformat (line_input, "api-prefix %s", &chroot_path))
1532 vec_terminate_c_string (chroot_path);
1533 vl_set_memory_root_path ((char *) chroot_path);
1534 if (VPPCOM_DEBUG > 0)
1535 clib_warning ("[%d] configured api-prefix %s",
1536 vcm->my_pid, chroot_path);
1537 chroot_path = 0; /* Don't vec_free() it! */
1539 else if (unformat (line_input, "uid %d", &uid))
1541 vl_set_memory_uid (uid);
1542 if (VPPCOM_DEBUG > 0)
1543 clib_warning ("[%d] configured uid %d", vcm->my_pid, uid);
1545 else if (unformat (line_input, "gid %d", &gid))
1547 vl_set_memory_gid (gid);
1548 if (VPPCOM_DEBUG > 0)
1549 clib_warning ("[%d] configured gid %d", vcm->my_pid, gid);
1551 else if (unformat (line_input, "segment-baseva 0x%llx",
1552 &vcl_cfg->segment_baseva))
1554 if (VPPCOM_DEBUG > 0)
1555 clib_warning ("[%d] configured segment_baseva 0x%llx",
1556 vcm->my_pid, vcl_cfg->segment_baseva);
1558 else if (unformat (line_input, "segment-size 0x%lx",
1559 &vcl_cfg->segment_size))
1561 if (VPPCOM_DEBUG > 0)
1562 clib_warning ("[%d] configured segment_size 0x%lx (%ld)",
1563 vcm->my_pid, vcl_cfg->segment_size,
1564 vcl_cfg->segment_size);
1566 else if (unformat (line_input, "segment-size %ld",
1567 &vcl_cfg->segment_size))
1569 if (VPPCOM_DEBUG > 0)
1570 clib_warning ("[%d] configured segment_size %ld (0x%lx)",
1571 vcm->my_pid, vcl_cfg->segment_size,
1572 vcl_cfg->segment_size);
1574 else if (unformat (line_input, "add-segment-size 0x%lx",
1575 &vcl_cfg->add_segment_size))
1577 if (VPPCOM_DEBUG > 0)
1579 ("[%d] configured add_segment_size 0x%lx (%ld)",
1580 vcm->my_pid, vcl_cfg->add_segment_size,
1581 vcl_cfg->add_segment_size);
1583 else if (unformat (line_input, "add-segment-size %ld",
1584 &vcl_cfg->add_segment_size))
1586 if (VPPCOM_DEBUG > 0)
1588 ("[%d] configured add_segment_size %ld (0x%lx)",
1589 vcm->my_pid, vcl_cfg->add_segment_size,
1590 vcl_cfg->add_segment_size);
1592 else if (unformat (line_input, "preallocated-fifo-pairs %d",
1593 &vcl_cfg->preallocated_fifo_pairs))
1595 if (VPPCOM_DEBUG > 0)
1596 clib_warning ("[%d] configured preallocated_fifo_pairs "
1597 "%d (0x%x)", vcm->my_pid,
1598 vcl_cfg->preallocated_fifo_pairs,
1599 vcl_cfg->preallocated_fifo_pairs);
1601 else if (unformat (line_input, "rx-fifo-size 0x%lx",
1602 &vcl_cfg->rx_fifo_size))
1604 if (VPPCOM_DEBUG > 0)
1605 clib_warning ("[%d] configured rx_fifo_size 0x%lx (%ld)",
1606 vcm->my_pid, vcl_cfg->rx_fifo_size,
1607 vcl_cfg->rx_fifo_size);
1609 else if (unformat (line_input, "rx-fifo-size %ld",
1610 &vcl_cfg->rx_fifo_size))
1612 if (VPPCOM_DEBUG > 0)
1613 clib_warning ("[%d] configured rx_fifo_size %ld (0x%lx)",
1614 vcm->my_pid, vcl_cfg->rx_fifo_size,
1615 vcl_cfg->rx_fifo_size);
1617 else if (unformat (line_input, "tx-fifo-size 0x%lx",
1618 &vcl_cfg->tx_fifo_size))
1620 if (VPPCOM_DEBUG > 0)
1621 clib_warning ("[%d] configured tx_fifo_size 0x%lx (%ld)",
1622 vcm->my_pid, vcl_cfg->tx_fifo_size,
1623 vcl_cfg->tx_fifo_size);
1625 else if (unformat (line_input, "tx-fifo-size %ld",
1626 &vcl_cfg->tx_fifo_size))
1628 if (VPPCOM_DEBUG > 0)
1629 clib_warning ("[%d] configured tx_fifo_size %ld (0x%lx)",
1630 vcm->my_pid, vcl_cfg->tx_fifo_size,
1631 vcl_cfg->tx_fifo_size);
1633 else if (unformat (line_input, "event-queue-size 0x%lx",
1634 &vcl_cfg->event_queue_size))
1636 if (VPPCOM_DEBUG > 0)
1637 clib_warning ("[%d] configured event_queue_size 0x%lx (%ld)",
1638 vcm->my_pid, vcl_cfg->event_queue_size,
1639 vcl_cfg->event_queue_size);
1641 else if (unformat (line_input, "event-queue-size %ld",
1642 &vcl_cfg->event_queue_size))
1644 if (VPPCOM_DEBUG > 0)
1645 clib_warning ("[%d] configured event_queue_size %ld (0x%lx)",
1646 vcm->my_pid, vcl_cfg->event_queue_size,
1647 vcl_cfg->event_queue_size);
1649 else if (unformat (line_input, "listen-queue-size 0x%lx",
1650 &vcl_cfg->listen_queue_size))
1652 if (VPPCOM_DEBUG > 0)
1653 clib_warning ("[%d] configured listen_queue_size 0x%lx (%ld)",
1654 vcm->my_pid, vcl_cfg->listen_queue_size,
1655 vcl_cfg->listen_queue_size);
1657 else if (unformat (line_input, "listen-queue-size %ld",
1658 &vcl_cfg->listen_queue_size))
1660 if (VPPCOM_DEBUG > 0)
1661 clib_warning ("[%d] configured listen_queue_size %ld (0x%lx)",
1662 vcm->my_pid, vcl_cfg->listen_queue_size,
1663 vcl_cfg->listen_queue_size);
1665 else if (unformat (line_input, "app-timeout %f",
1666 &vcl_cfg->app_timeout))
1668 if (VPPCOM_DEBUG > 0)
1669 clib_warning ("[%d] configured app_timeout %f",
1670 vcm->my_pid, vcl_cfg->app_timeout);
1672 else if (unformat (line_input, "session-timeout %f",
1673 &vcl_cfg->session_timeout))
1675 if (VPPCOM_DEBUG > 0)
1676 clib_warning ("[%d] configured session_timeout %f",
1677 vcm->my_pid, vcl_cfg->session_timeout);
1679 else if (unformat (line_input, "accept-timeout %f",
1680 &vcl_cfg->accept_timeout))
1682 if (VPPCOM_DEBUG > 0)
1683 clib_warning ("[%d] configured accept_timeout %f",
1684 vcm->my_pid, vcl_cfg->accept_timeout);
1686 else if (unformat (line_input, "}"))
1689 if (VPPCOM_DEBUG > 0)
1690 clib_warning ("[%d] completed parsing vppcom config!",
1696 if (line_input->buffer[line_input->index] != '#')
1698 clib_warning ("[%d] Unknown vppcom config option: '%s'",
1699 vcm->my_pid, (char *)
1700 &line_input->buffer[line_input->index]);
1707 unformat_free (input);
1715 * VPPCOM Public API functions
1718 vppcom_app_create (char *app_name)
1720 vppcom_main_t *vcm = &vppcom_main;
1721 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
1731 vcm->my_pid = getpid ();
1732 clib_fifo_validate (vcm->client_session_index_fifo,
1733 vcm->cfg.listen_queue_size);
1734 vppcom_cfg_init (vcl_cfg);
1735 conf_fname = getenv (VPPCOM_CONF_ENV);
1738 conf_fname = VPPCOM_CONF_DEFAULT;
1739 if (VPPCOM_DEBUG > 0)
1740 clib_warning ("[%d] getenv '%s' failed!", vcm->my_pid,
1743 vppcom_cfg_heapsize (conf_fname);
1744 vppcom_cfg_read (conf_fname);
1745 vcm->bind_session_index = ~0;
1746 vcm->main_cpu = os_get_thread_index ();
1747 heap = clib_mem_get_per_cpu_heap ();
1748 h = mheap_header (heap);
1750 /* make the main heap thread-safe */
1751 h->flags |= MHEAP_FLAG_THREAD_SAFE;
1753 vcm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
1755 clib_time_init (&vcm->clib_time);
1756 vppcom_init_error_string_table ();
1757 svm_fifo_segment_init (vcl_cfg->segment_baseva,
1758 20 /* timeout in secs */ );
1759 clib_spinlock_init (&vcm->sessions_lockp);
1760 vppcom_api_hookup ();
1763 if (vcm->my_client_index == ~0)
1765 vcm->app_state = STATE_APP_START;
1766 rv = vppcom_connect_to_vpp (app_name);
1769 clib_warning ("[%d] couldn't connect to VPP.", vcm->my_pid);
1773 if (VPPCOM_DEBUG > 0)
1774 clib_warning ("[%d] sending session enable", vcm->my_pid);
1776 rv = vppcom_app_session_enable ();
1779 clib_warning ("[%d] vppcom_app_session_enable() failed!",
1784 if (VPPCOM_DEBUG > 0)
1785 clib_warning ("[%d] sending app attach", vcm->my_pid);
1787 rv = vppcom_app_attach ();
1790 clib_warning ("[%d] vppcom_app_attach() failed!", vcm->my_pid);
1795 if (VPPCOM_DEBUG > 0)
1796 clib_warning ("[%d] app_name '%s', my_client_index %d (0x%x)",
1797 vcm->my_pid, app_name, vcm->my_client_index,
1798 vcm->my_client_index);
1804 vppcom_app_destroy (void)
1806 vppcom_main_t *vcm = &vppcom_main;
1809 if (vcm->my_client_index == ~0)
1812 if (VPPCOM_DEBUG > 0)
1813 clib_warning ("[%d] detaching from VPP, my_client_index %d (0x%x)",
1814 vcm->my_pid, vcm->my_client_index, vcm->my_client_index);
1816 vppcom_app_detach ();
1817 rv = vppcom_wait_for_app_state_change (STATE_APP_ENABLED);
1818 if (PREDICT_FALSE (rv))
1820 if (VPPCOM_DEBUG > 0)
1821 clib_warning ("[%d] application detach timed out, rv = %s (%d)",
1822 vcm->my_pid, vppcom_retval_str (rv), rv);
1824 vl_client_disconnect_from_vlib ();
1825 vcm->my_client_index = ~0;
1826 vcm->app_state = STATE_APP_START;
1830 vppcom_session_create (u32 vrf, u8 proto, u8 is_nonblocking)
1832 vppcom_main_t *vcm = &vppcom_main;
1836 clib_spinlock_lock (&vcm->sessions_lockp);
1837 pool_get (vcm->sessions, session);
1838 memset (session, 0, sizeof (*session));
1839 session_index = session - vcm->sessions;
1842 session->proto = proto;
1843 session->state = STATE_START;
1844 session->is_nonblocking = is_nonblocking;
1845 clib_spinlock_unlock (&vcm->sessions_lockp);
1847 if (VPPCOM_DEBUG > 0)
1848 clib_warning ("[%d] sid %d", vcm->my_pid, session_index);
1850 return (int) session_index;
1854 vppcom_session_close (uint32_t session_index)
1856 vppcom_main_t *vcm = &vppcom_main;
1857 session_t *session = 0;
1860 clib_spinlock_lock (&vcm->sessions_lockp);
1861 rv = vppcom_session_at_index (session_index, &session);
1862 if (PREDICT_FALSE (rv))
1864 if (VPPCOM_DEBUG > 0)
1865 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
1866 vcm->my_pid, session_index);
1867 clib_spinlock_unlock (&vcm->sessions_lockp);
1870 clib_spinlock_unlock (&vcm->sessions_lockp);
1872 if (VPPCOM_DEBUG > 0)
1873 clib_warning ("[%d] sid %d", vcm->my_pid, session_index);
1875 if (session->is_vep)
1878 for (next_sid = session->vep.next_sid; next_sid != ~0;
1879 next_sid = session->vep.next_sid)
1881 rv = vppcom_epoll_ctl (session_index, EPOLL_CTL_DEL, next_sid, 0);
1882 if ((VPPCOM_DEBUG > 0) && (rv < 0))
1883 clib_warning ("[%d] EPOLL_CTL_DEL vep_idx %u, sid %u failed, "
1884 "rv = %s (%d)", session_index, next_sid,
1885 vcm->my_pid, session_index,
1886 vppcom_retval_str (rv), rv);
1888 clib_spinlock_lock (&vcm->sessions_lockp);
1889 rv = vppcom_session_at_index (session_index, &session);
1890 if (PREDICT_FALSE (rv))
1892 if (VPPCOM_DEBUG > 0)
1894 ("[%d] invalid session, sid (%u) has been closed!",
1895 vcm->my_pid, session_index);
1896 clib_spinlock_unlock (&vcm->sessions_lockp);
1899 clib_spinlock_unlock (&vcm->sessions_lockp);
1904 if (session->is_vep_session)
1906 u32 vep_idx = session->vep.vep_idx;
1907 rv = vppcom_epoll_ctl (vep_idx, EPOLL_CTL_DEL, session_index, 0);
1908 if ((VPPCOM_DEBUG > 0) && (rv < 0))
1909 clib_warning ("[%d] EPOLL_CTL_DEL vep_idx %u, sid %u failed, "
1910 "rv = %s (%d)", vep_idx, session_index,
1911 vcm->my_pid, session_index,
1912 vppcom_retval_str (rv), rv);
1914 clib_spinlock_lock (&vcm->sessions_lockp);
1915 rv = vppcom_session_at_index (session_index, &session);
1916 if (PREDICT_FALSE (rv))
1918 if (VPPCOM_DEBUG > 0)
1920 ("[%d] invalid session, sid (%u) has been closed!",
1921 vcm->my_pid, session_index);
1922 clib_spinlock_unlock (&vcm->sessions_lockp);
1925 clib_spinlock_unlock (&vcm->sessions_lockp);
1928 if (session->is_cut_thru)
1930 if (session->is_server)
1932 rv = vppcom_session_unbind_cut_thru (session);
1933 if ((VPPCOM_DEBUG > 0) && (rv < 0))
1934 clib_warning ("[%d] unbind cut-thru (session %d) failed, "
1936 vcm->my_pid, session_index,
1937 vppcom_retval_str (rv), rv);
1940 else if (session->is_server)
1942 rv = vppcom_session_unbind (session_index);
1943 if ((VPPCOM_DEBUG > 0) && (rv < 0))
1944 clib_warning ("[%d] unbind (session %d) failed, rv = %s (%d)",
1945 vcm->my_pid, session_index,
1946 vppcom_retval_str (rv), rv);
1950 rv = vppcom_session_disconnect (session_index);
1951 if ((VPPCOM_DEBUG > 0) && (rv < 0))
1952 clib_warning ("[%d] disconnect (session %d) failed, rv = %s (%d)",
1953 vcm->my_pid, session_index,
1954 vppcom_retval_str (rv), rv);
1957 pool_put_index (vcm->sessions, session_index);
1963 vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep)
1965 vppcom_main_t *vcm = &vppcom_main;
1966 session_t *session = 0;
1970 return VPPCOM_EINVAL;
1972 clib_spinlock_lock (&vcm->sessions_lockp);
1973 rv = vppcom_session_at_index (session_index, &session);
1974 if (PREDICT_FALSE (rv))
1976 clib_spinlock_unlock (&vcm->sessions_lockp);
1977 if (VPPCOM_DEBUG > 0)
1978 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
1979 vcm->my_pid, session_index);
1983 if (VPPCOM_DEBUG > 0)
1984 clib_warning ("[%d] sid %d", vcm->my_pid, session_index);
1986 session->vrf = ep->vrf;
1987 session->lcl_addr.is_ip4 = ep->is_ip4;
1988 session->lcl_addr.ip46 = to_ip46 (!ep->is_ip4, ep->ip);
1989 session->port = ep->port;
1991 clib_spinlock_unlock (&vcm->sessions_lockp);
1996 vppcom_session_listen (uint32_t listen_session_index, uint32_t q_len)
1998 vppcom_main_t *vcm = &vppcom_main;
1999 session_t *listen_session = 0;
2002 clib_spinlock_lock (&vcm->sessions_lockp);
2003 rv = vppcom_session_at_index (listen_session_index, &listen_session);
2004 if (PREDICT_FALSE (rv))
2006 clib_spinlock_unlock (&vcm->sessions_lockp);
2007 if (VPPCOM_DEBUG > 0)
2008 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
2009 vcm->my_pid, listen_session_index);
2013 if (VPPCOM_DEBUG > 0)
2014 clib_warning ("[%d] sid %d", vcm->my_pid, listen_session_index);
2016 ASSERT (vcm->bind_session_index == ~0);
2017 vcm->bind_session_index = listen_session_index;
2018 vppcom_send_bind_sock (listen_session);
2019 clib_spinlock_unlock (&vcm->sessions_lockp);
2021 vppcom_wait_for_session_state_change (listen_session_index, STATE_LISTEN,
2022 vcm->cfg.session_timeout);
2023 if (PREDICT_FALSE (rv))
2025 vcm->bind_session_index = ~0;
2026 if (VPPCOM_DEBUG > 0)
2027 clib_warning ("[%d] server listen timed out, rv = %d (%d)",
2028 vcm->my_pid, vppcom_retval_str (rv), rv);
2032 clib_spinlock_lock (&vcm->sessions_lockp);
2033 rv = vppcom_session_at_index (listen_session_index, &listen_session);
2034 if (PREDICT_FALSE (rv))
2036 clib_spinlock_unlock (&vcm->sessions_lockp);
2037 if (VPPCOM_DEBUG > 0)
2038 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
2039 vcm->my_pid, listen_session_index);
2042 listen_session->is_listen = 1;
2043 clib_fifo_validate (vcm->client_session_index_fifo, q_len);
2044 clib_spinlock_unlock (&vcm->sessions_lockp);
2050 vppcom_session_accept (uint32_t listen_session_index, vppcom_endpt_t * ep,
2051 double wait_for_time)
2053 vppcom_main_t *vcm = &vppcom_main;
2054 session_t *listen_session = 0;
2055 session_t *client_session = 0;
2056 u32 client_session_index;
2060 clib_spinlock_lock (&vcm->sessions_lockp);
2061 rv = vppcom_session_at_index (listen_session_index, &listen_session);
2062 if (PREDICT_FALSE (rv))
2064 clib_spinlock_unlock (&vcm->sessions_lockp);
2065 if (VPPCOM_DEBUG > 0)
2066 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
2067 vcm->my_pid, listen_session_index);
2071 if (listen_session->state != STATE_LISTEN)
2073 clib_spinlock_unlock (&vcm->sessions_lockp);
2074 if (VPPCOM_DEBUG > 0)
2075 clib_warning ("[%d] session not in listen state, state = %s",
2077 vppcom_session_state_str (listen_session->state));
2078 return VPPCOM_EBADFD;
2080 wait_for = listen_session->is_nonblocking ? 0 :
2081 (wait_for_time < 0) ? vcm->cfg.accept_timeout : wait_for_time;
2083 if (VPPCOM_DEBUG > 0)
2084 clib_warning ("[%d] sid %d: %s (%d)", vcm->my_pid,
2085 listen_session_index,
2086 vppcom_session_state_str (listen_session->state),
2087 listen_session->state);
2088 clib_spinlock_unlock (&vcm->sessions_lockp);
2092 rv = vppcom_wait_for_client_session_index (wait_for);
2095 if ((VPPCOM_DEBUG > 0))
2096 clib_warning ("[%d] sid %d, accept timed out, rv = %s (%d)",
2097 vcm->my_pid, listen_session_index,
2098 vppcom_retval_str (rv), rv);
2099 if ((wait_for == 0) || (wait_for_time > 0))
2106 clib_spinlock_lock (&vcm->sessions_lockp);
2107 clib_fifo_sub1 (vcm->client_session_index_fifo, client_session_index);
2108 rv = vppcom_session_at_index (client_session_index, &client_session);
2109 ASSERT (rv == VPPCOM_OK);
2110 ASSERT (client_session->peer_addr.is_ip4 ==
2111 listen_session->lcl_addr.is_ip4);
2113 if (VPPCOM_DEBUG > 0)
2114 clib_warning ("[%d] Got a request: client sid %d", vcm->my_pid,
2115 client_session_index);
2117 ep->vrf = client_session->vrf;
2118 ep->is_cut_thru = client_session->is_cut_thru;
2119 ep->is_ip4 = client_session->peer_addr.is_ip4;
2120 ep->port = client_session->port;
2121 if (client_session->peer_addr.is_ip4)
2122 clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip4,
2123 sizeof (ip4_address_t));
2125 clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip6,
2126 sizeof (ip6_address_t));
2127 clib_spinlock_unlock (&vcm->sessions_lockp);
2128 return (int) client_session_index;
2132 vppcom_session_connect (uint32_t session_index, vppcom_endpt_t * server_ep)
2134 vppcom_main_t *vcm = &vppcom_main;
2135 session_t *session = 0;
2138 clib_spinlock_lock (&vcm->sessions_lockp);
2139 rv = vppcom_session_at_index (session_index, &session);
2140 if (PREDICT_FALSE (rv))
2142 clib_spinlock_unlock (&vcm->sessions_lockp);
2143 if (VPPCOM_DEBUG > 0)
2144 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
2145 vcm->my_pid, session_index);
2149 if (session->state == STATE_CONNECT)
2151 clib_spinlock_unlock (&vcm->sessions_lockp);
2152 if (VPPCOM_DEBUG > 0)
2153 clib_warning ("[%d] session, sid (%u) already connected!",
2154 vcm->my_pid, session_index);
2158 session->vrf = server_ep->vrf;
2159 session->peer_addr.is_ip4 = server_ep->is_ip4;
2160 session->peer_addr.ip46 = to_ip46 (!server_ep->is_ip4, server_ep->ip);
2161 session->port = server_ep->port;
2163 if (VPPCOM_DEBUG > 0)
2165 u8 *ip_str = format (0, "%U", format_ip46_address,
2166 &session->peer_addr.ip46,
2167 session->peer_addr.is_ip4);
2168 clib_warning ("[%d] connect sid %d to %s server port %d",
2169 vcm->my_pid, session_index, ip_str,
2170 clib_net_to_host_u16 (session->port));
2174 vppcom_send_connect_sock (session, session_index);
2175 clib_spinlock_unlock (&vcm->sessions_lockp);
2176 rv = vppcom_wait_for_session_state_change (session_index, STATE_CONNECT,
2177 vcm->cfg.session_timeout);
2178 if (PREDICT_FALSE (rv))
2180 if (VPPCOM_DEBUG > 0)
2181 clib_warning ("[%d] connect timed out, rv = %s (%d)",
2182 vcm->my_pid, vppcom_retval_str (rv), rv);
2189 vppcom_session_read (uint32_t session_index, void *buf, int n)
2191 vppcom_main_t *vcm = &vppcom_main;
2192 session_t *session = 0;
2193 svm_fifo_t *rx_fifo;
2200 clib_spinlock_lock (&vcm->sessions_lockp);
2201 rv = vppcom_session_at_index (session_index, &session);
2202 if (PREDICT_FALSE (rv))
2204 clib_spinlock_unlock (&vcm->sessions_lockp);
2205 if (VPPCOM_DEBUG > 0)
2206 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
2207 vcm->my_pid, session_index);
2211 if (session->state == STATE_DISCONNECT)
2213 clib_spinlock_unlock (&vcm->sessions_lockp);
2214 if (VPPCOM_DEBUG > 0)
2215 clib_warning ("[%d] sid (%u) has been closed by remote peer!",
2216 vcm->my_pid, session_index);
2217 return VPPCOM_ECONNRESET;
2220 rx_fifo = ((!session->is_cut_thru || session->is_server) ?
2221 session->server_rx_fifo : session->server_tx_fifo);
2222 fifo_str = ((!session->is_cut_thru || session->is_server) ?
2223 "server_rx_fifo" : "server_tx_fifo");
2227 n_read = svm_fifo_dequeue_nowait (rx_fifo, n, buf);
2229 while (!session->is_nonblocking && (n_read <= 0));
2232 session->vep.et_mask |= EPOLLIN;
2234 clib_spinlock_unlock (&vcm->sessions_lockp);
2236 if ((VPPCOM_DEBUG > 2) && (n_read > 0))
2237 clib_warning ("[%d] sid %d, read %d bytes from %s (%p)", vcm->my_pid,
2238 session_index, n_read, fifo_str, rx_fifo);
2240 return (n_read <= 0) ? VPPCOM_EAGAIN : n_read;
2244 vppcom_session_read_ready (session_t * session, u32 session_index)
2246 vppcom_main_t *vcm = &vppcom_main;
2247 svm_fifo_t *rx_fifo;
2250 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
2251 if (session->state == STATE_DISCONNECT)
2253 if (VPPCOM_DEBUG > 0)
2254 clib_warning ("[%d] sid (%u) has been closed by remote peer!",
2255 vcm->my_pid, session_index);
2256 return VPPCOM_ECONNRESET;
2259 if (session->is_listen)
2260 ready = clib_fifo_elts (vcm->client_session_index_fifo);
2263 rx_fifo = ((!session->is_cut_thru || session->is_server) ?
2264 session->server_rx_fifo : session->server_tx_fifo);
2266 ready = svm_fifo_max_dequeue (rx_fifo);
2269 if (VPPCOM_DEBUG > 3)
2270 clib_warning ("[%d] sid %d, peek %s (%p), ready = %d", vcm->my_pid,
2272 session->is_server ? "server_rx_fifo" : "server_tx_fifo",
2275 session->vep.et_mask |= EPOLLIN;
2281 vppcom_session_write (uint32_t session_index, void *buf, int n)
2283 vppcom_main_t *vcm = &vppcom_main;
2284 session_t *session = 0;
2285 svm_fifo_t *tx_fifo;
2286 unix_shared_memory_queue_t *q;
2287 session_fifo_event_t evt;
2293 clib_spinlock_lock (&vcm->sessions_lockp);
2294 rv = vppcom_session_at_index (session_index, &session);
2295 if (PREDICT_FALSE (rv))
2297 clib_spinlock_unlock (&vcm->sessions_lockp);
2298 if (VPPCOM_DEBUG > 0)
2299 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
2300 vcm->my_pid, session_index);
2304 if (session->state == STATE_DISCONNECT)
2306 clib_spinlock_unlock (&vcm->sessions_lockp);
2307 if (VPPCOM_DEBUG > 0)
2308 clib_warning ("[%d] sid (%u) has been closed by remote peer!",
2309 vcm->my_pid, session_index);
2310 return VPPCOM_ECONNRESET;
2313 tx_fifo = ((!session->is_cut_thru || session->is_server) ?
2314 session->server_tx_fifo : session->server_rx_fifo);
2315 fifo_str = ((!session->is_cut_thru || session->is_server) ?
2316 "server_tx_fifo" : "server_rx_fifo");
2319 n_write = svm_fifo_enqueue_nowait (tx_fifo, n, buf);
2321 while (!session->is_nonblocking && (n_write <= 0));
2323 /* If event wasn't set, add one */
2324 if (!session->is_cut_thru && (n_write > 0) && svm_fifo_set_event (tx_fifo))
2328 /* Fabricate TX event, send to vpp */
2330 evt.event_type = FIFO_EVENT_APP_TX;
2331 evt.event_id = vcm->tx_event_id++;
2333 rval = vppcom_session_at_index (session_index, &session);
2334 if (PREDICT_FALSE (rval))
2336 clib_spinlock_unlock (&vcm->sessions_lockp);
2337 if (VPPCOM_DEBUG > 1)
2338 clib_warning ("[%d] invalid session, sid (%u) has been closed!",
2339 vcm->my_pid, session_index);
2342 q = session->vpp_event_queue;
2344 unix_shared_memory_queue_add (q, (u8 *) & evt,
2345 0 /* do wait for mutex */ );
2349 session->vep.et_mask |= EPOLLOUT;
2351 clib_spinlock_unlock (&vcm->sessions_lockp);
2353 if (VPPCOM_DEBUG > 2)
2354 clib_warning ("[%d] sid %d, wrote %d bytes to %s (%p)", vcm->my_pid,
2355 session_index, n_write, fifo_str, tx_fifo);
2360 vppcom_session_write_ready (session_t * session, u32 session_index)
2362 vppcom_main_t *vcm = &vppcom_main;
2363 svm_fifo_t *tx_fifo;
2367 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
2368 if (session->state == STATE_DISCONNECT)
2370 if (VPPCOM_DEBUG > 0)
2371 clib_warning ("[%d] sid (%u) has been closed by remote peer!",
2372 vcm->my_pid, session_index);
2373 return VPPCOM_ECONNRESET;
2376 tx_fifo = ((!session->is_cut_thru || session->is_server) ?
2377 session->server_tx_fifo : session->server_rx_fifo);
2378 fifo_str = ((!session->is_cut_thru || session->is_server) ?
2379 "server_tx_fifo" : "server_rx_fifo");
2381 ready = svm_fifo_max_enqueue (tx_fifo);
2383 if (VPPCOM_DEBUG > 3)
2384 clib_warning ("[%d] sid %d, peek %s (%p), ready = %d", vcm->my_pid,
2385 session_index, fifo_str, tx_fifo, ready);
2387 session->vep.et_mask |= EPOLLOUT;
2393 vppcom_select (unsigned long n_bits, unsigned long *read_map,
2394 unsigned long *write_map, unsigned long *except_map,
2395 double time_to_wait)
2397 vppcom_main_t *vcm = &vppcom_main;
2399 session_t *session = 0;
2400 int rv, bits_set = 0;
2401 f64 timeout = clib_time_now (&vcm->clib_time) + time_to_wait;
2402 u32 minbits = clib_max (n_bits, BITS (uword));
2404 ASSERT (sizeof (clib_bitmap_t) == sizeof (long int));
2408 clib_bitmap_validate (vcm->rd_bitmap, minbits);
2409 clib_memcpy (vcm->rd_bitmap, read_map, vec_len (vcm->rd_bitmap));
2410 memset (read_map, 0, vec_len (vcm->rd_bitmap));
2414 clib_bitmap_validate (vcm->wr_bitmap, minbits);
2415 clib_memcpy (vcm->wr_bitmap, write_map, vec_len (vcm->wr_bitmap));
2416 memset (write_map, 0, vec_len (vcm->wr_bitmap));
2420 clib_bitmap_validate (vcm->ex_bitmap, minbits);
2421 clib_memcpy (vcm->ex_bitmap, except_map, vec_len (vcm->ex_bitmap));
2422 memset (except_map, 0, vec_len (vcm->ex_bitmap));
2428 clib_bitmap_foreach (session_index, vcm->rd_bitmap,
2430 clib_spinlock_lock (&vcm->sessions_lockp);
2431 rv = vppcom_session_at_index (session_index, &session);
2434 clib_spinlock_unlock (&vcm->sessions_lockp);
2435 if (VPPCOM_DEBUG > 1)
2436 clib_warning ("[%d] session %d specified in "
2437 "read_map is closed.", vcm->my_pid,
2439 bits_set = VPPCOM_EBADFD;
2443 rv = vppcom_session_read_ready (session, session_index);
2444 clib_spinlock_unlock (&vcm->sessions_lockp);
2445 if (vcm->ex_bitmap &&
2446 clib_bitmap_get (vcm->ex_bitmap, session_index) && (rv < 0))
2448 // TBD: clib_warning
2449 /* coverity[FORWARD_NULL] */
2450 clib_bitmap_set_no_check (except_map, session_index, 1);
2455 // TBD: clib_warning
2456 /* coverity[FORWARD_NULL] */
2457 clib_bitmap_set_no_check (read_map, session_index, 1);
2462 clib_bitmap_foreach (session_index, vcm->wr_bitmap,
2464 clib_spinlock_lock (&vcm->sessions_lockp);
2465 rv = vppcom_session_at_index (session_index, &session);
2468 clib_spinlock_unlock (&vcm->sessions_lockp);
2469 if (VPPCOM_DEBUG > 0)
2470 clib_warning ("[%d] session %d specified in "
2471 "write_map is closed.", vcm->my_pid,
2473 bits_set = VPPCOM_EBADFD;
2477 rv = vppcom_session_write_ready (session, session_index);
2478 clib_spinlock_unlock (&vcm->sessions_lockp);
2481 // TBD: clib_warning
2482 /* coverity[FORWARD_NULL] */
2483 clib_bitmap_set_no_check (write_map, session_index, 1);
2488 clib_bitmap_foreach (session_index, vcm->ex_bitmap,
2490 clib_spinlock_lock (&vcm->sessions_lockp);
2491 rv = vppcom_session_at_index (session_index, &session);
2494 clib_spinlock_unlock (&vcm->sessions_lockp);
2495 if (VPPCOM_DEBUG > 1)
2496 clib_warning ("[%d] session %d specified in "
2497 "except_map is closed.", vcm->my_pid,
2499 bits_set = VPPCOM_EBADFD;
2503 rv = vppcom_session_read_ready (session, session_index);
2504 clib_spinlock_unlock (&vcm->sessions_lockp);
2507 // TBD: clib_warning
2508 /* coverity[FORWARD_NULL] */
2509 clib_bitmap_set_no_check (except_map, session_index, 1);
2515 while (clib_time_now (&vcm->clib_time) < timeout);
2522 vep_verify_epoll_chain (u32 vep_idx)
2525 vppcom_epoll_t *vep;
2529 if (VPPCOM_DEBUG < 1)
2532 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
2533 rv = vppcom_session_at_index (vep_idx, &session);
2534 if (PREDICT_FALSE (rv))
2536 clib_warning ("ERROR: Invalid vep_idx (%u)!", vep_idx);
2539 if (PREDICT_FALSE (!session->is_vep))
2541 clib_warning ("ERROR: vep_idx (%u) is not a vep!", vep_idx);
2544 if (VPPCOM_DEBUG > 1)
2545 clib_warning ("vep_idx (%u): Dumping epoll chain\n"
2548 " is_vep_session = %u\n"
2549 " wait_cont_idx = 0x%x (%u)\n"
2551 vep_idx, session->is_vep, session->is_vep_session,
2552 session->wait_cont_idx, session->wait_cont_idx);
2555 vep = &session->vep;
2556 if (session->is_vep_session)
2558 if (VPPCOM_DEBUG > 1)
2559 clib_warning ("vep_idx[%u]: sid 0x%x (%u)\n"
2561 " next_sid = 0x%x (%u)\n"
2562 " prev_sid = 0x%x (%u)\n"
2563 " vep_idx = 0x%x (%u)\n"
2564 " ev.events = 0x%x\n"
2565 " ev.data.u64 = 0x%llx\n"
2569 vep->next_sid, vep->next_sid,
2570 vep->prev_sid, vep->prev_sid,
2571 vep->vep_idx, vep->vep_idx,
2572 vep->ev.events, vep->ev.data.u64, vep->et_mask);
2574 sid = vep->next_sid;
2577 rv = vppcom_session_at_index (sid, &session);
2578 if (PREDICT_FALSE (rv))
2580 clib_warning ("ERROR: Invalid sid (%u)!", sid);
2583 if (PREDICT_FALSE (session->is_vep))
2584 clib_warning ("ERROR: sid (%u) is a vep!", vep_idx);
2585 else if (PREDICT_FALSE (!session->is_vep_session))
2587 clib_warning ("ERROR: session (%u) is not a vep session!", sid);
2590 if (PREDICT_FALSE (session->vep.vep_idx != vep_idx))
2591 clib_warning ("ERROR: session (%u) vep_idx (%u) != "
2593 sid, session->vep.vep_idx, vep_idx);
2599 if (VPPCOM_DEBUG > 1)
2600 clib_warning ("vep_idx (%u): Dump complete!", vep_idx);
2604 vppcom_epoll_create (void)
2606 vppcom_main_t *vcm = &vppcom_main;
2607 session_t *vep_session;
2610 clib_spinlock_lock (&vcm->sessions_lockp);
2611 pool_get (vcm->sessions, vep_session);
2612 memset (vep_session, 0, sizeof (*vep_session));
2613 vep_idx = vep_session - vcm->sessions;
2615 vep_session->is_vep = 1;
2616 vep_session->vep.vep_idx = ~0;
2617 vep_session->vep.next_sid = ~0;
2618 vep_session->vep.prev_sid = ~0;
2619 vep_session->wait_cont_idx = ~0;
2620 clib_spinlock_unlock (&vcm->sessions_lockp);
2622 if (VPPCOM_DEBUG > 0)
2623 clib_warning ("Created vep_idx %u!", vep_idx);
2629 vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
2630 struct epoll_event *event)
2632 vppcom_main_t *vcm = &vppcom_main;
2633 session_t *vep_session;
2637 if (vep_idx == session_index)
2639 if (VPPCOM_DEBUG > 0)
2640 clib_warning ("ERROR: vep_idx == session_index (%u)!", vep_idx);
2641 return VPPCOM_EINVAL;
2644 clib_spinlock_lock (&vcm->sessions_lockp);
2645 rv = vppcom_session_at_index (vep_idx, &vep_session);
2646 if (PREDICT_FALSE (rv))
2648 if (VPPCOM_DEBUG > 0)
2649 clib_warning ("ERROR: Invalid vep_idx (%u)!", vep_idx);
2652 if (PREDICT_FALSE (!vep_session->is_vep))
2654 if (VPPCOM_DEBUG > 0)
2655 clib_warning ("ERROR: vep_idx (%u) is not a vep!", vep_idx);
2660 ASSERT (vep_session->vep.vep_idx == ~0);
2661 ASSERT (vep_session->vep.prev_sid == ~0);
2663 rv = vppcom_session_at_index (session_index, &session);
2664 if (PREDICT_FALSE (rv))
2666 if (VPPCOM_DEBUG > 0)
2667 clib_warning ("ERROR: Invalid session_index (%u)!", session_index);
2670 if (PREDICT_FALSE (session->is_vep))
2672 if (VPPCOM_DEBUG > 0)
2673 clib_warning ("ERROR: session_index (%u) is a vep!", vep_idx);
2681 if (PREDICT_FALSE (!event))
2683 clib_warning ("NULL pointer to epoll_event structure!");
2687 if (vep_session->vep.next_sid != ~0)
2689 session_t *next_session;
2690 rv = vppcom_session_at_index (vep_session->vep.next_sid,
2692 if (PREDICT_FALSE (rv))
2694 if (VPPCOM_DEBUG > 0)
2695 clib_warning ("EPOLL_CTL_ADD: Invalid vep.next_sid (%u) on"
2696 " vep_idx (%u)!", vep_session->vep.next_sid,
2700 ASSERT (next_session->vep.prev_sid == vep_idx);
2701 next_session->vep.prev_sid = session_index;
2703 session->vep.next_sid = vep_session->vep.next_sid;
2704 session->vep.prev_sid = vep_idx;
2705 session->vep.vep_idx = vep_idx;
2706 session->vep.et_mask = VEP_DEFAULT_ET_MASK;
2707 session->vep.ev = *event;
2708 session->is_vep_session = 1;
2709 vep_session->vep.next_sid = session_index;
2710 if (VPPCOM_DEBUG > 1)
2711 clib_warning ("EPOLL_CTL_ADD: vep_idx %u, sid %u, events 0x%x,"
2712 " data 0x%llx!", vep_idx, session_index,
2713 event->events, event->data.u64);
2717 if (PREDICT_FALSE (!event))
2719 clib_warning ("NULL pointer to epoll_event structure!");
2723 if (PREDICT_FALSE (!session->is_vep_session &&
2724 (session->vep.vep_idx != vep_idx)))
2726 if (VPPCOM_DEBUG > 0)
2728 if (!session->is_vep_session)
2729 clib_warning ("EPOLL_CTL_MOD: session (%u) is not "
2730 "a vep session!", session_index);
2732 clib_warning ("EPOLL_CTL_MOD: session (%u) vep_idx (%u) != "
2733 "vep_idx (%u)!", session_index,
2734 session->vep.vep_idx, vep_idx);
2739 session->vep.et_mask = VEP_DEFAULT_ET_MASK;
2740 session->vep.ev = *event;
2741 if (VPPCOM_DEBUG > 1)
2742 clib_warning ("EPOLL_CTL_MOD: vep_idx %u, sid %u, events 0x%x,"
2743 " data 0x%llx!", vep_idx, session_index,
2744 event->events, event->data.u64);
2748 if (PREDICT_FALSE (!session->is_vep_session &&
2749 (session->vep.vep_idx != vep_idx)))
2751 if (VPPCOM_DEBUG > 0)
2753 if (!session->is_vep_session)
2754 clib_warning ("EPOLL_CTL_DEL: session (%u) is not "
2755 "a vep session!", session_index);
2757 clib_warning ("EPOLL_CTL_DEL: session (%u) vep_idx (%u) != "
2758 "vep_idx (%u)!", session_index,
2759 session->vep.vep_idx, vep_idx);
2765 vep_session->wait_cont_idx =
2766 (vep_session->wait_cont_idx == session_index) ?
2767 session->vep.next_sid : vep_session->wait_cont_idx;
2769 if (session->vep.prev_sid == vep_idx)
2770 vep_session->vep.next_sid = session->vep.next_sid;
2773 session_t *prev_session;
2774 rv = vppcom_session_at_index (session->vep.prev_sid, &prev_session);
2775 if (PREDICT_FALSE (rv))
2777 if (VPPCOM_DEBUG > 0)
2778 clib_warning ("EPOLL_CTL_DEL: Invalid vep.prev_sid (%u) on"
2779 " sid (%u)!", session->vep.prev_sid,
2783 ASSERT (prev_session->vep.next_sid == session_index);
2784 prev_session->vep.next_sid = session->vep.next_sid;
2786 if (session->vep.next_sid != ~0)
2788 session_t *next_session;
2789 rv = vppcom_session_at_index (session->vep.next_sid, &next_session);
2790 if (PREDICT_FALSE (rv))
2792 if (VPPCOM_DEBUG > 0)
2793 clib_warning ("EPOLL_CTL_DEL: Invalid vep.next_sid (%u) on"
2794 " sid (%u)!", session->vep.next_sid,
2798 ASSERT (next_session->vep.prev_sid == session_index);
2799 next_session->vep.prev_sid = session->vep.prev_sid;
2802 memset (&session->vep, 0, sizeof (session->vep));
2803 session->vep.next_sid = ~0;
2804 session->vep.prev_sid = ~0;
2805 session->vep.vep_idx = ~0;
2806 session->is_vep_session = 0;
2807 if (VPPCOM_DEBUG > 1)
2808 clib_warning ("EPOLL_CTL_DEL: vep_idx %u, sid %u!", vep_idx,
2813 clib_warning ("Invalid operation (%d)!", op);
2817 vep_verify_epoll_chain (vep_idx);
2820 clib_spinlock_unlock (&vcm->sessions_lockp);
2824 #define VCL_LOCK_AND_GET_SESSION(I, S) \
2826 vppcom_main_t *vcm = &vppcom_main; \
2828 clib_spinlock_lock (&vcm->sessions_lockp); \
2829 rv = vppcom_session_at_index (I, S); \
2830 if (PREDICT_FALSE (rv)) \
2832 clib_spinlock_unlock (&vcm->sessions_lockp); \
2834 if (VPPCOM_DEBUG > 0) \
2835 clib_warning ("ERROR: Invalid ##I (%u)!", I); \
2842 vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
2843 int maxevents, double wait_for_time)
2845 vppcom_main_t *vcm = &vppcom_main;
2846 session_t *vep_session;
2848 f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time;
2850 u32 vep_next_sid, wait_cont_idx;
2853 if (PREDICT_FALSE (maxevents <= 0))
2855 if (VPPCOM_DEBUG > 0)
2856 clib_warning ("ERROR: Invalid maxevents (%d)!", maxevents);
2857 return VPPCOM_EINVAL;
2859 if (PREDICT_FALSE (wait_for_time < 0))
2861 if (VPPCOM_DEBUG > 0)
2862 clib_warning ("ERROR: Invalid wait_for_time (%f)!", wait_for_time);
2863 return VPPCOM_EINVAL;
2865 memset (events, 0, sizeof (*events) * maxevents);
2867 VCL_LOCK_AND_GET_SESSION (vep_idx, &vep_session);
2868 vep_next_sid = vep_session->vep.next_sid;
2869 is_vep = vep_session->is_vep;
2870 wait_cont_idx = vep_session->wait_cont_idx;
2871 clib_spinlock_unlock (&vcm->sessions_lockp);
2873 if (PREDICT_FALSE (!is_vep))
2875 if (VPPCOM_DEBUG > 0)
2876 clib_warning ("ERROR: vep_idx (%u) is not a vep!", vep_idx);
2880 if ((VPPCOM_DEBUG > 0) && (PREDICT_FALSE (vep_next_sid == ~0)))
2882 clib_warning ("WARNING: vep_idx (%u) is empty!", vep_idx);
2892 for (sid = (wait_cont_idx == ~0) ? vep_next_sid : wait_cont_idx;
2893 sid != ~0; sid = next_sid)
2895 u32 session_events, et_mask, clear_et_mask, session_vep_idx;
2896 u8 add_event, is_vep_session;
2898 u64 session_ev_data;
2900 VCL_LOCK_AND_GET_SESSION (sid, &session);
2901 next_sid = session->vep.next_sid;
2902 session_events = session->vep.ev.events;
2903 et_mask = session->vep.et_mask;
2904 is_vep = session->is_vep;
2905 is_vep_session = session->is_vep_session;
2906 session_vep_idx = session->vep.vep_idx;
2907 session_ev_data = session->vep.ev.data.u64;
2908 clib_spinlock_unlock (&vcm->sessions_lockp);
2910 if (PREDICT_FALSE (is_vep))
2912 if (VPPCOM_DEBUG > 0)
2913 clib_warning ("ERROR: sid (%u) is a vep!", vep_idx);
2917 if (PREDICT_FALSE (!is_vep_session))
2919 if (VPPCOM_DEBUG > 0)
2920 clib_warning ("EPOLL_CTL_MOD: session (%u) is not "
2921 "a vep session!", sid);
2925 if (PREDICT_FALSE (session_vep_idx != vep_idx))
2927 clib_warning ("EPOLL_CTL_MOD: session (%u) "
2928 "vep_idx (%u) != vep_idx (%u)!",
2929 sid, session->vep.vep_idx, vep_idx);
2934 add_event = clear_et_mask = 0;
2936 if ((EPOLLIN & session_events) && (EPOLLIN & et_mask))
2938 VCL_LOCK_AND_GET_SESSION (sid, &session);
2939 ready = vppcom_session_read_ready (session, sid);
2940 clib_spinlock_unlock (&vcm->sessions_lockp);
2944 events[num_ev].events |= EPOLLIN;
2945 if (EPOLLET & session_events)
2946 clear_et_mask |= EPOLLIN;
2953 case VPPCOM_ECONNRESET:
2954 events[num_ev].events |= EPOLLHUP | EPOLLRDHUP;
2958 events[num_ev].events |= EPOLLERR;
2964 if ((EPOLLOUT & session_events) && (EPOLLOUT & et_mask))
2966 VCL_LOCK_AND_GET_SESSION (sid, &session);
2967 ready = vppcom_session_write_ready (session, sid);
2968 clib_spinlock_unlock (&vcm->sessions_lockp);
2972 events[num_ev].events |= EPOLLOUT;
2973 if (EPOLLET & session_events)
2974 clear_et_mask |= EPOLLOUT;
2981 case VPPCOM_ECONNRESET:
2982 events[num_ev].events |= EPOLLHUP;
2986 events[num_ev].events |= EPOLLERR;
2994 events[num_ev].data.u64 = session_ev_data;
2995 if (EPOLLONESHOT & session_events)
2997 VCL_LOCK_AND_GET_SESSION (sid, &session);
2998 session->vep.ev.events = 0;
2999 clib_spinlock_unlock (&vcm->sessions_lockp);
3002 if (num_ev == maxevents)
3004 VCL_LOCK_AND_GET_SESSION (vep_idx, &vep_session);
3005 vep_session->wait_cont_idx = next_sid;
3006 clib_spinlock_unlock (&vcm->sessions_lockp);
3010 if (wait_cont_idx != ~0)
3013 next_sid = vep_next_sid;
3014 else if (next_sid == wait_cont_idx)
3019 while ((num_ev == 0) && (clib_time_now (&vcm->clib_time) <= timeout));
3021 if (wait_cont_idx != ~0)
3023 VCL_LOCK_AND_GET_SESSION (vep_idx, &vep_session);
3024 vep_session->wait_cont_idx = ~0;
3025 clib_spinlock_unlock (&vcm->sessions_lockp);
3028 return (rv != VPPCOM_OK) ? rv : num_ev;
3032 vppcom_session_attr (uint32_t session_index, uint32_t op,
3033 void *buffer, uint32_t * buflen)
3035 vppcom_main_t *vcm = &vppcom_main;
3038 u32 *flags = buffer;
3039 vppcom_ip46_t *vcl_addr = buffer;
3041 VCL_LOCK_AND_GET_SESSION (session_index, &session);
3044 case VPPCOM_ATTR_GET_NREAD:
3045 rv = vppcom_session_read_ready (session, session_index);
3046 if (VPPCOM_DEBUG > 0)
3047 clib_warning ("VPPCOM_ATTR_GET_NREAD: nread = %d", rv);
3051 case VPPCOM_ATTR_PEEK_NREAD:
3055 case VPPCOM_ATTR_GET_FLAGS:
3056 if (buffer && buflen && (*buflen >= sizeof (*flags)))
3058 *flags = O_RDWR | ((session->is_nonblocking) ? O_NONBLOCK : 0);
3059 *buflen = sizeof (*flags);
3060 if (VPPCOM_DEBUG > 0)
3061 clib_warning ("VPPCOM_ATTR_GET_FLAGS: flags = 0x%08x, "
3062 "is_nonblocking = %u", *flags,
3063 session->is_nonblocking);
3069 case VPPCOM_ATTR_SET_FLAGS:
3070 if (buffer && buflen && (*buflen >= sizeof (*flags)))
3072 session->is_nonblocking = (*flags & O_NONBLOCK) ? 1 : 0;
3073 if (VPPCOM_DEBUG > 0)
3074 clib_warning ("VPPCOM_ATTR_SET_FLAGS: flags = 0x%08x, "
3075 "is_nonblocking = %u", *flags,
3076 session->is_nonblocking);
3082 case VPPCOM_ATTR_GET_PEER_ADDR:
3083 if (buffer && buflen && (*buflen >= sizeof (*vcl_addr)))
3085 *vcl_addr = session->peer_addr;
3086 *buflen = sizeof (*vcl_addr);
3087 if (VPPCOM_DEBUG > 0)
3088 clib_warning ("VPPCOM_ATTR_GET_PEER_ADDR: is_ip4 = %u, "
3089 "addr = %U", vcl_addr->is_ip4, format_ip46_address,
3090 &vcl_addr->ip46, vcl_addr->is_ip4);
3096 case VPPCOM_ATTR_GET_LCL_ADDR:
3097 if (buffer && buflen && (*buflen >= sizeof (*vcl_addr)))
3099 *vcl_addr = session->lcl_addr;
3100 *buflen = sizeof (*vcl_addr);
3101 if (VPPCOM_DEBUG > 0)
3102 clib_warning ("VPPCOM_ATTR_GET_LCL_ADDR: is_ip4 = %u, "
3103 "addr = %U", vcl_addr->is_ip4, format_ip46_address,
3104 &vcl_addr->ip46, vcl_addr->is_ip4);
3110 case VPPCOM_ATTR_SET_REUSEADDR:
3113 case VPPCOM_ATTR_SET_BROADCAST:
3116 case VPPCOM_ATTR_SET_V6ONLY:
3119 case VPPCOM_ATTR_SET_KEEPALIVE:
3122 case VPPCOM_ATTR_SET_TCP_KEEPIDLE:
3125 case VPPCOM_ATTR_SET_TCP_KEEPINTVL:
3130 clib_spinlock_unlock (&vcm->sessions_lockp);
3135 * fd.io coding-style-patch-verification: ON
3138 * eval: (c-set-style "gnu")