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 <vcl/vppcom.h>
24 #include <vlib/unix/unix.h>
25 #include <vppinfra/vec_bootstrap.h>
26 #include <vppinfra/elog.h>
28 #define vl_typedefs /* define message structures */
29 #include <vpp/api/vpe_all_api_h.h>
32 /* declare message handlers for each api */
34 #define vl_endianfun /* define message structures */
35 #include <vpp/api/vpe_all_api_h.h>
38 /* instantiate all the print functions we know about */
39 #define vl_print(handle, ...)
41 #include <vpp/api/vpe_all_api_h.h>
45 /* Set VPPCOM_DEBUG_INIT 2 for connection debug,
46 * 3 for read/write debug output
48 * export VCL_DEBUG=<#> to set dynamically.
50 #define VPPCOM_DEBUG_INIT 1
52 #define VPPCOM_DEBUG_INIT 0
55 #define VPPCOM_DEBUG vcm->debug
58 * VPPCOM Private definitions and functions.
74 STATE_CLOSE_ON_EMPTY = 0x10,
75 STATE_DISCONNECT = 0x20,
79 #define SERVER_STATE_OPEN (STATE_ACCEPT|STATE_CLOSE_ON_EMPTY)
80 #define CLIENT_STATE_OPEN (STATE_CONNECT|STATE_CLOSE_ON_EMPTY)
82 typedef struct epoll_event vppcom_epoll_event_t;
89 vppcom_epoll_event_t ev;
90 #define VEP_DEFAULT_ET_MASK (EPOLLIN|EPOLLOUT)
91 #define VEP_UNSUPPORTED_EVENTS (EPOLLONESHOT|EPOLLEXCLUSIVE)
103 VCL_SESS_ATTR_SERVER,
104 VCL_SESS_ATTR_CUT_THRU,
106 VCL_SESS_ATTR_VEP_SESSION,
107 VCL_SESS_ATTR_LISTEN, // SOL_SOCKET,SO_ACCEPTCONN
108 VCL_SESS_ATTR_NONBLOCK, // fcntl,O_NONBLOCK
109 VCL_SESS_ATTR_REUSEADDR, // SOL_SOCKET,SO_REUSEADDR
110 VCL_SESS_ATTR_REUSEPORT, // SOL_SOCKET,SO_REUSEPORT
111 VCL_SESS_ATTR_BROADCAST, // SOL_SOCKET,SO_BROADCAST
112 VCL_SESS_ATTR_V6ONLY, // SOL_TCP,IPV6_V6ONLY
113 VCL_SESS_ATTR_KEEPALIVE, // SOL_SOCKET,SO_KEEPALIVE
114 VCL_SESS_ATTR_TCP_NODELAY, // SOL_TCP,TCP_NODELAY
115 VCL_SESS_ATTR_TCP_KEEPIDLE, // SOL_TCP,TCP_KEEPIDLE
116 VCL_SESS_ATTR_TCP_KEEPINTVL, // SOL_TCP,TCP_KEEPINTVL
118 } vppcom_session_attr_t;
120 #define VCL_SESS_ATTR_SET(ATTR, VAL) \
122 (ATTR) |= 1 << (VAL); \
125 #define VCL_SESS_ATTR_CLR(ATTR, VAL) \
127 (ATTR) &= ~(1 << (VAL)); \
130 #define VCL_SESS_ATTR_TEST(ATTR, VAL) \
131 ((ATTR) & (1 << (VAL)) ? 1 : 0)
135 volatile session_state_t state;
137 svm_fifo_t *server_rx_fifo;
138 svm_fifo_t *server_tx_fifo;
139 u32 sndbuf_size; // VPP-TBD: Hack until support setsockopt(SO_SNDBUF)
140 u32 rcvbuf_size; // VPP-TBD: Hack until support setsockopt(SO_RCVBUF)
141 u32 user_mss; // VPP-TBD: Hack until support setsockopt(TCP_MAXSEG)
146 svm_queue_t *vpp_event_queue;
148 /* Socket configuration state */
149 /* TBD: covert 'is_*' vars to bit in session->attr; */
160 vppcom_ip46_t lcl_addr;
161 vppcom_ip46_t peer_addr;
162 u16 lcl_port; // network order
163 u16 peer_port; // network order
165 u64 client_queue_address;
167 elog_track_t elog_track;
170 typedef struct vppcom_cfg_t_
173 u32 vpp_api_q_length;
176 u32 add_segment_size;
177 u32 preallocated_fifo_pairs;
180 u32 event_queue_size;
181 u32 listen_queue_size;
182 u8 app_proxy_transport_tcp;
183 u8 app_proxy_transport_udp;
187 u64 namespace_secret;
192 char *event_log_path;
195 typedef struct vppcom_main_t_
199 u32 *client_session_index_fifo;
202 /* vpe input queue */
203 svm_queue_t *vl_input_queue;
205 /* API client handle */
209 clib_spinlock_t sessions_lockp;
212 /* Hash table for disconnect processing */
213 uword *session_index_by_vpp_handles;
216 clib_bitmap_t *rd_bitmap;
217 clib_bitmap_t *wr_bitmap;
218 clib_bitmap_t *ex_bitmap;
220 /* Our event queue */
221 svm_queue_t *app_event_queue;
223 /* unique segment name counter */
224 u32 unique_segment_index;
226 /* For deadman timers */
227 clib_time_t clib_time;
229 /* State of the connection, shared between msg RX thread and main thread */
230 volatile app_state_t app_state;
235 elog_main_t elog_main;
236 elog_track_t elog_track;
238 /* VNET_API_ERROR_FOO -> "Foo" hash table */
239 uword *error_string_by_error_number;
242 /* NOTE: _vppcom_main is only used until the heap is allocated.
243 * Do not access it directly -- use vcm which will point to
244 * the heap allocated copy after init.
246 static vppcom_main_t _vppcom_main = {
247 .debug = VPPCOM_DEBUG_INIT,
248 .my_client_index = ~0
251 static vppcom_main_t *vcm = &_vppcom_main;
253 #define VCL_LOCK_AND_GET_SESSION(I, S) \
255 clib_spinlock_lock (&vcm->sessions_lockp); \
256 rv = vppcom_session_at_index (I, S); \
257 if (PREDICT_FALSE (rv)) \
259 clib_spinlock_unlock (&vcm->sessions_lockp); \
260 clib_warning ("VCL<%d>: ERROR: Invalid ##I (%u)!", \
267 vppcom_app_state_str (app_state_t state)
273 case STATE_APP_START:
274 st = "STATE_APP_START";
277 case STATE_APP_CONN_VPP:
278 st = "STATE_APP_CONN_VPP";
281 case STATE_APP_ENABLED:
282 st = "STATE_APP_ENABLED";
285 case STATE_APP_ATTACHED:
286 st = "STATE_APP_ATTACHED";
290 st = "UNKNOWN_APP_STATE";
298 vppcom_session_state_str (session_state_t state)
309 st = "STATE_CONNECT";
320 case STATE_CLOSE_ON_EMPTY:
321 st = "STATE_CLOSE_ON_EMPTY";
324 case STATE_DISCONNECT:
325 st = "STATE_DISCONNECT";
333 st = "UNKNOWN_STATE";
341 * VPPCOM Utility Functions
344 vppcom_session_at_index (u32 session_index, session_t * volatile *sess)
346 /* Assumes that caller has acquired spinlock: vcm->sessions_lockp */
347 if (PREDICT_FALSE ((session_index == ~0) ||
348 pool_is_free_index (vcm->sessions, session_index)))
350 clib_warning ("VCL<%d>: invalid session, sid (%u) has been closed!",
351 getpid (), session_index);
352 return VPPCOM_EBADFD;
354 *sess = pool_elt_at_index (vcm->sessions, session_index);
359 vppcom_session_table_add_listener (u64 listener_handle, u32 value)
361 /* Session and listener handles have different formats. The latter has
362 * the thread index in the upper 32 bits while the former has the session
363 * type. Knowing that, for listeners we just flip the MSB to 1 */
364 listener_handle |= 1ULL << 63;
365 hash_set (vcm->session_index_by_vpp_handles, listener_handle, value);
368 static inline session_t *
369 vppcom_session_table_lookup_listener (u64 listener_handle)
372 u64 handle = listener_handle | (1ULL << 63);
375 p = hash_get (vcm->session_index_by_vpp_handles, handle);
378 clib_warning ("VCL<%d>: couldn't find listen session: unknown vpp "
379 "listener handle %llx", getpid (), listener_handle);
382 if (pool_is_free_index (vcm->sessions, p[0]))
384 if (VPPCOM_DEBUG > 1)
385 clib_warning ("VCL<%d>: invalid listen session, sid (%u)",
390 session = pool_elt_at_index (vcm->sessions, p[0]);
391 ASSERT (session->is_listen);
396 vppcom_session_table_del_listener (u64 listener_handle)
398 listener_handle |= 1ULL << 63;
399 hash_unset (vcm->session_index_by_vpp_handles, listener_handle);
405 elog_main_t *em = &vcm->elog_main;
407 clib_error_t *error = 0;
410 (char *) format (0, "%s/%d-%d-vcl-elog%c", vcm->cfg.event_log_path,
411 vcm->my_client_index, getpid (), 0);
412 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
415 clib_error_report (error);
417 if (VPPCOM_DEBUG > 0)
418 clib_warning ("[%d] Event Log:'%s' ", getpid (), chroot_file);
423 vppcom_connect_to_vpp (char *app_name)
425 api_main_t *am = &api_main;
428 if (VPPCOM_DEBUG > 0)
429 clib_warning ("VCL<%d>: app (%s) connecting to VPP api...",
430 getpid (), app_name);
432 if (vl_client_connect_to_vlib ("/vpe-api", app_name,
433 vcm->cfg.vpp_api_q_length) < 0)
435 clib_warning ("VCL<%d>: app (%s) connect failed!", getpid (), app_name);
436 rv = VPPCOM_ECONNREFUSED;
440 vcm->vl_input_queue = am->shmem_hdr->vl_input_queue;
441 vcm->my_client_index = am->my_client_index;
442 vcm->app_state = STATE_APP_CONN_VPP;
444 if (VPPCOM_DEBUG > 0)
445 clib_warning ("VCL<%d>: app (%s) is connected to VPP!",
446 getpid (), app_name);
449 if (VPPCOM_DEBUG > 0)
451 vcm->elog_main.lock =
452 clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);
453 vcm->elog_main.lock[0] = 0;
454 vcm->elog_main.event_ring_size = vcm->cfg.event_ring_size;
455 elog_init (&vcm->elog_main, vcm->elog_main.event_ring_size);
456 elog_enable_disable (&vcm->elog_main, 1);
458 vcm->elog_track.name =
459 (char *) format (0, "P:%d:C:%d%c", getpid (),
460 vcm->my_client_index, 0);
461 elog_track_register (&vcm->elog_main, &vcm->elog_track);
464 ELOG_TYPE_DECLARE (e) =
466 .format = "connect_vpp:rv:%d",
473 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, vcm->elog_track);
481 format_api_error (u8 * s, va_list * args)
483 i32 error = va_arg (*args, u32);
486 p = hash_get (vcm->error_string_by_error_number, -error);
489 s = format (s, "%s (%d)", p[0], error);
491 s = format (s, "%d", error);
496 vppcom_init_error_string_table (void)
498 vcm->error_string_by_error_number = hash_create (0, sizeof (uword));
500 #define _(n,v,s) hash_set (vcm->error_string_by_error_number, -v, s);
501 foreach_vnet_api_error;
504 hash_set (vcm->error_string_by_error_number, 99, "Misc");
508 vppcom_wait_for_app_state_change (app_state_t app_state)
510 f64 timeout = clib_time_now (&vcm->clib_time) + vcm->cfg.app_timeout;
512 while (clib_time_now (&vcm->clib_time) < timeout)
514 if (vcm->app_state == app_state)
517 if (VPPCOM_DEBUG > 0)
518 clib_warning ("VCL<%d>: timeout waiting for state %s (%d)", getpid (),
519 vppcom_app_state_str (app_state), app_state);
521 if (VPPCOM_DEBUG > 0)
524 ELOG_TYPE_DECLARE (e) =
526 .format = "ERR: timeout state:%d",
534 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, vcm->elog_track);
536 ed->data = app_state;
540 return VPPCOM_ETIMEDOUT;
544 vppcom_wait_for_session_state_change (u32 session_index,
545 session_state_t state,
548 f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time;
549 session_t *volatile session;
554 clib_spinlock_lock (&vcm->sessions_lockp);
555 rv = vppcom_session_at_index (session_index, &session);
556 if (PREDICT_FALSE (rv))
558 clib_spinlock_unlock (&vcm->sessions_lockp);
561 if (session->state == state)
563 clib_spinlock_unlock (&vcm->sessions_lockp);
566 if (session->state == STATE_FAILED)
568 clib_spinlock_unlock (&vcm->sessions_lockp);
569 return VPPCOM_ECONNREFUSED;
572 clib_spinlock_unlock (&vcm->sessions_lockp);
574 while (clib_time_now (&vcm->clib_time) < timeout);
576 if (VPPCOM_DEBUG > 0)
577 clib_warning ("VCL<%d>: timeout waiting for state 0x%x (%s)", getpid (),
578 state, vppcom_session_state_str (state));
580 if (VPPCOM_DEBUG > 0)
583 ELOG_TYPE_DECLARE (e) =
585 .format = "ERR: timeout state:%d",
593 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
599 return VPPCOM_ETIMEDOUT;
603 vppcom_wait_for_client_session_index (f64 wait_for_time)
605 f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time;
609 if (clib_fifo_elts (vcm->client_session_index_fifo))
612 while (clib_time_now (&vcm->clib_time) < timeout);
614 if (wait_for_time == 0)
615 return VPPCOM_EAGAIN;
617 if (VPPCOM_DEBUG > 0)
618 clib_warning ("VCL<%d>: timeout waiting for client_session_index",
621 if (VPPCOM_DEBUG > 0)
624 ELOG_TYPE_DECLARE (e) =
626 .format = "ERR: timeout waiting for session index :%d",
634 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, vcm->elog_track);
640 return VPPCOM_ETIMEDOUT;
644 * VPP-API message functions
647 vppcom_send_session_enable_disable (u8 is_enable)
649 vl_api_session_enable_disable_t *bmp;
650 bmp = vl_msg_api_alloc (sizeof (*bmp));
651 memset (bmp, 0, sizeof (*bmp));
653 bmp->_vl_msg_id = ntohs (VL_API_SESSION_ENABLE_DISABLE);
654 bmp->client_index = vcm->my_client_index;
655 bmp->context = htonl (0xfeedface);
656 bmp->is_enable = is_enable;
657 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
661 vppcom_app_session_enable (void)
665 if (vcm->app_state != STATE_APP_ENABLED)
667 vppcom_send_session_enable_disable (1 /* is_enabled == TRUE */ );
668 rv = vppcom_wait_for_app_state_change (STATE_APP_ENABLED);
669 if (PREDICT_FALSE (rv))
671 if (VPPCOM_DEBUG > 0)
672 clib_warning ("VCL<%d>: application session enable timed out! "
674 getpid (), rv, vppcom_retval_str (rv));
682 vl_api_session_enable_disable_reply_t_handler
683 (vl_api_session_enable_disable_reply_t * mp)
687 clib_warning ("VCL<%d>: session_enable_disable failed: %U", getpid (),
688 format_api_error, ntohl (mp->retval));
691 vcm->app_state = STATE_APP_ENABLED;
695 vppcom_app_send_attach (void)
697 vl_api_application_attach_t *bmp;
698 u8 nsid_len = vec_len (vcm->cfg.namespace_id);
699 u8 app_is_proxy = (vcm->cfg.app_proxy_transport_tcp ||
700 vcm->cfg.app_proxy_transport_udp);
702 bmp = vl_msg_api_alloc (sizeof (*bmp));
703 memset (bmp, 0, sizeof (*bmp));
705 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
706 bmp->client_index = vcm->my_client_index;
707 bmp->context = htonl (0xfeedface);
708 bmp->options[APP_OPTIONS_FLAGS] =
709 APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT |
710 (vcm->cfg.app_scope_local ? APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE : 0) |
711 (vcm->cfg.app_scope_global ? APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE : 0) |
712 (app_is_proxy ? APP_OPTIONS_FLAGS_IS_PROXY : 0);
713 bmp->options[APP_OPTIONS_PROXY_TRANSPORT] =
714 (vcm->cfg.app_proxy_transport_tcp ? 1 << TRANSPORT_PROTO_TCP : 0) |
715 (vcm->cfg.app_proxy_transport_udp ? 1 << TRANSPORT_PROTO_UDP : 0);
716 bmp->options[APP_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
717 bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
718 bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
719 bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
720 bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
721 vcm->cfg.preallocated_fifo_pairs;
722 bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = vcm->cfg.event_queue_size;
725 bmp->namespace_id_len = nsid_len;
726 clib_memcpy (bmp->namespace_id, vcm->cfg.namespace_id, nsid_len);
727 bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = vcm->cfg.namespace_secret;
729 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
733 vppcom_app_attach (void)
737 vppcom_app_send_attach ();
738 rv = vppcom_wait_for_app_state_change (STATE_APP_ATTACHED);
739 if (PREDICT_FALSE (rv))
741 if (VPPCOM_DEBUG > 0)
742 clib_warning ("VCL<%d>: application attach timed out! "
744 getpid (), rv, vppcom_retval_str (rv));
751 vppcom_app_detach (void)
753 vl_api_application_detach_t *bmp;
754 bmp = vl_msg_api_alloc (sizeof (*bmp));
755 memset (bmp, 0, sizeof (*bmp));
757 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
758 bmp->client_index = vcm->my_client_index;
759 bmp->context = htonl (0xfeedface);
760 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
764 vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
767 static svm_fifo_segment_create_args_t _a;
768 svm_fifo_segment_create_args_t *a = &_a;
771 memset (a, 0, sizeof (*a));
774 clib_warning ("VCL<%d>: attach failed: %U", getpid (),
775 format_api_error, ntohl (mp->retval));
779 if (mp->segment_name_length == 0)
781 clib_warning ("VCL<%d>: segment_name_length zero", getpid ());
785 a->segment_name = (char *) mp->segment_name;
786 a->segment_size = mp->segment_size;
788 ASSERT (mp->app_event_queue_address);
790 /* Attach to the segment vpp created */
791 rv = svm_fifo_segment_attach (a);
792 vec_reset_length (a->new_segment_indices);
793 if (PREDICT_FALSE (rv))
795 clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed",
796 getpid (), mp->segment_name);
800 vcm->app_event_queue =
801 uword_to_pointer (mp->app_event_queue_address, svm_queue_t *);
803 vcm->app_state = STATE_APP_ATTACHED;
807 vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
811 clib_warning ("VCL<%d>: detach failed: %U", getpid (), format_api_error,
814 vcm->app_state = STATE_APP_ENABLED;
818 vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
822 clib_warning ("VCL<%d>: vpp handle 0x%llx: disconnect session failed: %U",
823 getpid (), mp->handle, format_api_error,
828 vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
830 static svm_fifo_segment_create_args_t _a;
831 svm_fifo_segment_create_args_t *a = &_a;
834 memset (a, 0, sizeof (*a));
835 a->segment_name = (char *) mp->segment_name;
836 a->segment_size = mp->segment_size;
837 /* Attach to the segment vpp created */
838 rv = svm_fifo_segment_attach (a);
839 vec_reset_length (a->new_segment_indices);
840 if (PREDICT_FALSE (rv))
842 clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed",
843 getpid (), mp->segment_name);
846 if (VPPCOM_DEBUG > 1)
847 clib_warning ("VCL<%d>: mapped new segment '%s' size %d", getpid (),
848 mp->segment_name, mp->segment_size);
852 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
856 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
860 session_t *session = 0;
861 u32 session_index = p[0];
863 VCL_LOCK_AND_GET_SESSION (session_index, &session);
864 session->state = STATE_CLOSE_ON_EMPTY;
866 if (VPPCOM_DEBUG > 1)
867 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
868 "setting state to 0x%x (%s)",
869 getpid (), mp->handle, session_index, session->state,
870 vppcom_session_state_str (session->state));
871 clib_spinlock_unlock (&vcm->sessions_lockp);
875 if (VPPCOM_DEBUG > 1)
876 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
877 "session lookup failed!",
878 getpid (), mp->handle, session_index);
881 clib_warning ("VCL<%d>: vpp handle 0x%llx: session lookup by "
882 "handle failed!", getpid (), mp->handle);
886 vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
888 session_t *session = 0;
889 vl_api_reset_session_reply_t *rmp;
893 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
897 clib_spinlock_lock (&vcm->sessions_lockp);
898 rval = vppcom_session_at_index (p[0], &session);
899 if (PREDICT_FALSE (rval))
901 rv = VNET_API_ERROR_INVALID_VALUE_2;
902 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
903 "session lookup failed! returning %d %U",
904 getpid (), mp->handle, p[0],
905 rv, format_api_error, rv);
909 /* TBD: should this disconnect immediately and
912 session->state = STATE_CLOSE_ON_EMPTY;
914 if (VPPCOM_DEBUG > 1)
915 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
916 "state set to %d (%s)!", getpid (),
917 mp->handle, p[0], session->state,
918 vppcom_session_state_str (session->state));
920 clib_spinlock_unlock (&vcm->sessions_lockp);
924 rv = VNET_API_ERROR_INVALID_VALUE;
925 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx: session lookup "
926 "failed! returning %d %U",
927 getpid (), mp->handle, rv, format_api_error, rv);
930 rmp = vl_msg_api_alloc (sizeof (*rmp));
931 memset (rmp, 0, sizeof (*rmp));
932 rmp->_vl_msg_id = ntohs (VL_API_RESET_SESSION_REPLY);
933 rmp->retval = htonl (rv);
934 rmp->handle = mp->handle;
935 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
939 vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp)
941 session_t *session = 0;
943 svm_fifo_t *rx_fifo, *tx_fifo;
947 session_index = mp->context;
948 VCL_LOCK_AND_GET_SESSION (session_index, &session);
952 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
953 "connect failed! %U",
954 getpid (), mp->handle, session_index,
955 format_api_error, ntohl (mp->retval));
958 session->state = STATE_FAILED;
959 session->vpp_handle = mp->handle;
963 clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
964 "Invalid session index (%u)!",
965 getpid (), mp->handle, session_index);
973 /* We've been redirected */
974 if (mp->segment_name_length > 0)
976 static svm_fifo_segment_create_args_t _a;
977 svm_fifo_segment_create_args_t *a = &_a;
980 memset (a, 0, sizeof (*a));
981 a->segment_name = (char *) mp->segment_name;
982 if (VPPCOM_DEBUG > 1)
983 clib_warning ("VCL<%d>: cut-thru segment: %s\n",
984 getpid (), a->segment_name);
986 rv = svm_fifo_segment_attach (a);
987 vec_reset_length (a->new_segment_indices);
988 if (PREDICT_FALSE (rv))
990 clib_warning ("VCL<%d>: sm_fifo_segment_attach ('%s') failed",
991 getpid (), a->segment_name);
999 session->is_cut_thru = is_cut_thru;
1000 session->vpp_event_queue = uword_to_pointer (mp->vpp_event_queue_address,
1003 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
1004 rx_fifo->client_session_index = session_index;
1005 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
1006 tx_fifo->client_session_index = session_index;
1008 session->server_rx_fifo = rx_fifo;
1009 session->server_tx_fifo = tx_fifo;
1010 session->vpp_handle = mp->handle;
1011 session->lcl_addr.is_ip4 = mp->is_ip4;
1012 clib_memcpy (&session->lcl_addr.ip46, mp->lcl_ip,
1013 sizeof (session->peer_addr.ip46));
1014 session->lcl_port = mp->lcl_port;
1015 session->state = STATE_CONNECT;
1017 /* Add it to lookup table */
1018 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
1020 if (VPPCOM_DEBUG > 1)
1021 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: connect succeeded!"
1022 " session_rx_fifo %p, refcnt %d,"
1023 " session_tx_fifo %p, refcnt %d",
1024 getpid (), mp->handle, session_index,
1025 session->server_rx_fifo,
1026 session->server_rx_fifo->refcnt,
1027 session->server_tx_fifo, session->server_tx_fifo->refcnt);
1029 clib_spinlock_unlock (&vcm->sessions_lockp);
1033 vppcom_send_connect_sock (session_t * session, u32 session_index)
1035 vl_api_connect_sock_t *cmp;
1037 /* Assumes caller as acquired the spinlock: vcm->sessions_lockp */
1038 session->is_server = 0;
1039 cmp = vl_msg_api_alloc (sizeof (*cmp));
1040 memset (cmp, 0, sizeof (*cmp));
1041 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_SOCK);
1042 cmp->client_index = vcm->my_client_index;
1043 cmp->context = session_index;
1045 cmp->is_ip4 = session->peer_addr.is_ip4;
1046 clib_memcpy (cmp->ip, &session->peer_addr.ip46, sizeof (cmp->ip));
1047 cmp->port = session->peer_port;
1048 cmp->proto = session->proto;
1049 clib_memcpy (cmp->options, session->options, sizeof (cmp->options));
1050 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & cmp);
1054 vppcom_send_disconnect_session_reply (u64 vpp_handle, u32 session_index,
1057 vl_api_disconnect_session_reply_t *rmp;
1059 if (VPPCOM_DEBUG > 1)
1060 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
1061 "sending disconnect msg",
1062 getpid (), vpp_handle, session_index);
1064 rmp = vl_msg_api_alloc (sizeof (*rmp));
1065 memset (rmp, 0, sizeof (*rmp));
1067 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
1068 rmp->retval = htonl (rv);
1069 rmp->handle = vpp_handle;
1070 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
1074 vppcom_send_disconnect_session (u64 vpp_handle, u32 session_index)
1076 vl_api_disconnect_session_t *dmp;
1078 if (VPPCOM_DEBUG > 1)
1079 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
1080 "sending disconnect msg",
1081 getpid (), vpp_handle, session_index);
1083 dmp = vl_msg_api_alloc (sizeof (*dmp));
1084 memset (dmp, 0, sizeof (*dmp));
1085 dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
1086 dmp->client_index = vcm->my_client_index;
1087 dmp->handle = vpp_handle;
1088 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & dmp);
1092 vl_api_bind_sock_reply_t_handler (vl_api_bind_sock_reply_t * mp)
1094 session_t *session = 0;
1095 u32 session_index = mp->context;
1098 VCL_LOCK_AND_GET_SESSION (session_index, &session);
1102 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, "
1103 "sid %u: bind failed: %U",
1104 getpid (), mp->handle, session_index,
1105 format_api_error, ntohl (mp->retval));
1106 rv = vppcom_session_at_index (session_index, &session);
1107 if (rv == VPPCOM_OK)
1109 session->state = STATE_FAILED;
1110 session->vpp_handle = mp->handle;
1114 clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
1115 "Invalid session index (%u)!",
1116 getpid (), mp->handle, session_index);
1121 session->vpp_handle = mp->handle;
1122 session->lcl_addr.is_ip4 = mp->lcl_is_ip4;
1123 clib_memcpy (&session->lcl_addr.ip46, mp->lcl_ip,
1124 sizeof (session->peer_addr.ip46));
1125 session->lcl_port = mp->lcl_port;
1126 vppcom_session_table_add_listener (mp->handle, session_index);
1127 session->is_listen = 1;
1128 session->state = STATE_LISTEN;
1130 if (VPPCOM_DEBUG > 1)
1131 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: bind succeeded!",
1132 getpid (), mp->handle, mp->context);
1134 clib_spinlock_unlock (&vcm->sessions_lockp);
1138 vl_api_unbind_sock_reply_t_handler (vl_api_unbind_sock_reply_t * mp)
1141 clib_warning ("VCL<%d>: ERROR: sid %u: unbind failed: %U",
1142 getpid (), mp->context, format_api_error,
1143 ntohl (mp->retval));
1145 else if (VPPCOM_DEBUG > 1)
1146 clib_warning ("VCL<%d>: sid %u: unbind succeeded!",
1147 getpid (), mp->context);
1151 format_ip4_address (u8 * s, va_list * args)
1153 u8 *a = va_arg (*args, u8 *);
1154 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
1158 format_ip6_address (u8 * s, va_list * args)
1160 ip6_address_t *a = va_arg (*args, ip6_address_t *);
1161 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
1163 i_max_n_zero = ARRAY_LEN (a->as_u16);
1165 i_first_zero = i_max_n_zero;
1167 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
1169 u32 is_zero = a->as_u16[i] == 0;
1170 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
1176 if ((!is_zero && n_zeros > max_n_zeros)
1177 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
1179 i_max_n_zero = i_first_zero;
1180 max_n_zeros = n_zeros;
1181 i_first_zero = ARRAY_LEN (a->as_u16);
1186 last_double_colon = 0;
1187 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
1189 if (i == i_max_n_zero && max_n_zeros > 1)
1191 s = format (s, "::");
1192 i += max_n_zeros - 1;
1193 last_double_colon = 1;
1197 s = format (s, "%s%x",
1198 (last_double_colon || i == 0) ? "" : ":",
1199 clib_net_to_host_u16 (a->as_u16[i]));
1200 last_double_colon = 0;
1207 /* Format an IP46 address. */
1209 format_ip46_address (u8 * s, va_list * args)
1211 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
1212 ip46_type_t type = va_arg (*args, ip46_type_t);
1218 is_ip4 = ip46_address_is_ip4 (ip46);
1229 format (s, "%U", format_ip4_address, &ip46->ip4) :
1230 format (s, "%U", format_ip6_address, &ip46->ip6);
1234 vppcom_send_accept_session_reply (u64 handle, u32 context, int retval)
1236 vl_api_accept_session_reply_t *rmp;
1238 rmp = vl_msg_api_alloc (sizeof (*rmp));
1239 memset (rmp, 0, sizeof (*rmp));
1240 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
1241 rmp->retval = htonl (retval);
1242 rmp->context = context;
1243 rmp->handle = handle;
1244 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
1248 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
1250 svm_fifo_t *rx_fifo, *tx_fifo;
1251 session_t *session, *listen_session;
1254 clib_spinlock_lock (&vcm->sessions_lockp);
1255 if (!clib_fifo_free_elts (vcm->client_session_index_fifo))
1257 clib_warning ("VCL<%d>: client session queue is full!", getpid ());
1258 vppcom_send_accept_session_reply (mp->handle, mp->context,
1259 VNET_API_ERROR_QUEUE_FULL);
1260 clib_spinlock_unlock (&vcm->sessions_lockp);
1264 listen_session = vppcom_session_table_lookup_listener (mp->listener_handle);
1265 if (!listen_session)
1267 clib_warning ("VCL<%d>: ERROR: couldn't find listen session: "
1268 "unknown vpp listener handle %llx",
1269 getpid (), mp->listener_handle);
1270 clib_spinlock_unlock (&vcm->sessions_lockp);
1274 /* Allocate local session and set it up */
1275 pool_get (vcm->sessions, session);
1276 memset (session, 0, sizeof (*session));
1277 session_index = session - vcm->sessions;
1279 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
1280 rx_fifo->client_session_index = session_index;
1281 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
1282 tx_fifo->client_session_index = session_index;
1284 session->vpp_handle = mp->handle;
1285 session->client_context = mp->context;
1286 session->server_rx_fifo = rx_fifo;
1287 session->server_tx_fifo = tx_fifo;
1288 session->vpp_event_queue = uword_to_pointer (mp->vpp_event_queue_address,
1290 session->state = STATE_ACCEPT;
1291 session->is_cut_thru = 0;
1292 session->is_server = 1;
1293 session->peer_port = mp->port;
1294 session->peer_addr.is_ip4 = mp->is_ip4;
1295 clib_memcpy (&session->peer_addr.ip46, mp->ip,
1296 sizeof (session->peer_addr.ip46));
1298 /* Add it to lookup table */
1299 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
1300 session->lcl_port = listen_session->lcl_port;
1301 session->lcl_addr = listen_session->lcl_addr;
1303 /* TBD: move client_session_index_fifo into listener session */
1304 clib_fifo_add1 (vcm->client_session_index_fifo, session_index);
1306 clib_spinlock_unlock (&vcm->sessions_lockp);
1308 if (VPPCOM_DEBUG > 1)
1309 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: client accept "
1310 "request from %s address %U port %d queue %p!", getpid (),
1311 mp->handle, session_index, mp->is_ip4 ? "IPv4" : "IPv6",
1312 format_ip46_address, &mp->ip, mp->is_ip4,
1313 clib_net_to_host_u16 (mp->port), session->vpp_event_queue);
1315 if (VPPCOM_DEBUG > 0)
1317 session->elog_track.name =
1318 (char *) format (0, "C:%d:S:%d%c", vcm->my_client_index,
1320 elog_track_register (&vcm->elog_main, &session->elog_track);
1322 if (session->peer_addr.is_ip4)
1325 ELOG_TYPE_DECLARE (e) =
1328 "client_accept:handle:%x addr:%d.%d.%d.%d:%d",
1329 .format_args = "i8i1i1i1i1i2",
1332 CLIB_PACKED (struct {
1338 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
1340 ed->handle = mp->handle;
1341 ed->addr[0] = session->peer_addr.ip46.ip4.as_u8[0];
1342 ed->addr[1] = session->peer_addr.ip46.ip4.as_u8[1];
1343 ed->addr[2] = session->peer_addr.ip46.ip4.as_u8[2];
1344 ed->addr[3] = session->peer_addr.ip46.ip4.as_u8[3];
1345 ed->port = clib_net_to_host_u16 (session->peer_port);
1350 clib_warning ("ip6");
1357 vppcom_send_connect_session_reply (session_t * session, u32 session_index,
1358 u64 vpp_handle, u32 context, int retval)
1360 vl_api_connect_session_reply_t *rmp;
1362 svm_queue_t *client_q;
1364 rmp = vl_msg_api_alloc (sizeof (*rmp));
1365 memset (rmp, 0, sizeof (*rmp));
1366 rmp->_vl_msg_id = ntohs (VL_API_CONNECT_SESSION_REPLY);
1370 rmp->context = context;
1371 rmp->handle = vpp_handle;
1372 rmp->retval = htonl (retval);
1373 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
1377 rmp->context = session->client_context;
1378 rmp->retval = htonl (retval);
1379 rmp->handle = session->vpp_handle;
1380 rmp->server_rx_fifo = pointer_to_uword (session->server_rx_fifo);
1381 rmp->server_tx_fifo = pointer_to_uword (session->server_tx_fifo);
1382 rmp->vpp_event_queue_address = pointer_to_uword (session->vpp_event_queue);
1383 rmp->segment_size = vcm->cfg.segment_size;
1384 len = vec_len (session->segment_name);
1385 rmp->segment_name_length = clib_min (len, sizeof (rmp->segment_name));
1386 clib_memcpy (rmp->segment_name, session->segment_name,
1387 rmp->segment_name_length - 1);
1388 clib_memcpy (rmp->lcl_ip, session->peer_addr.ip46.as_u8,
1389 sizeof (rmp->lcl_ip));
1390 rmp->is_ip4 = session->peer_addr.is_ip4;
1391 rmp->lcl_port = session->peer_port;
1392 client_q = uword_to_pointer (session->client_queue_address, svm_queue_t *);
1394 vl_msg_api_send_shmem (client_q, (u8 *) & rmp);
1398 * Acting as server for redirected connect requests
1401 vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
1404 session_t *session = 0;
1406 clib_spinlock_lock (&vcm->sessions_lockp);
1407 if (!clib_fifo_free_elts (vcm->client_session_index_fifo))
1409 clib_spinlock_unlock (&vcm->sessions_lockp);
1411 if (VPPCOM_DEBUG > 1)
1412 clib_warning ("VCL<%d>: client session queue is full!", getpid ());
1414 /* TBD: Fix api to include vpp handle */
1415 vppcom_send_connect_session_reply (0 /* session */ , 0 /* sid */ ,
1416 0 /* handle */ , mp->context,
1417 VNET_API_ERROR_QUEUE_FULL);
1421 pool_get (vcm->sessions, session);
1422 memset (session, 0, sizeof (*session));
1423 session_index = session - vcm->sessions;
1425 session->client_context = mp->context;
1426 session->vpp_handle = session_index;
1427 session->client_queue_address = mp->client_queue_address;
1428 session->is_cut_thru = 1;
1429 session->is_server = 1;
1430 session->lcl_port = mp->port;
1431 session->lcl_addr.is_ip4 = mp->is_ip4;
1432 clib_memcpy (&session->lcl_addr.ip46, mp->ip,
1433 sizeof (session->lcl_addr.ip46));
1435 /* TBD: missing peer info in api msg.
1437 session->peer_addr.is_ip4 = mp->is_ip4;
1438 ASSERT (session->lcl_addr.is_ip4 == session->peer_addr.is_ip4);
1440 session->state = STATE_ACCEPT;
1441 clib_fifo_add1 (vcm->client_session_index_fifo, session_index);
1442 if (VPPCOM_DEBUG > 1)
1443 clib_warning ("VCL<%d>: sid %u: Got a cut-thru connect request! "
1444 "clib_fifo_elts %u!\n", getpid (), session_index,
1445 clib_fifo_elts (vcm->client_session_index_fifo));
1447 if (VPPCOM_DEBUG > 0)
1449 session->elog_track.name =
1450 (char *) format (0, "C:%d:S:%d%c", vcm->my_client_index,
1452 elog_track_register (&vcm->elog_main, &session->elog_track);
1455 ELOG_TYPE_DECLARE (e) =
1457 .format = "cut-thru-connect:S:%d clib_fifo_elts:%d",
1458 .format_args = "i4i4",
1466 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
1468 ed->data[0] = session_index;
1469 ed->data[1] = clib_fifo_elts (vcm->client_session_index_fifo);
1473 clib_spinlock_unlock (&vcm->sessions_lockp);
1477 vppcom_send_bind_sock (session_t * session, u32 session_index)
1479 vl_api_bind_sock_t *bmp;
1481 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
1482 session->is_server = 1;
1483 bmp = vl_msg_api_alloc (sizeof (*bmp));
1484 memset (bmp, 0, sizeof (*bmp));
1486 bmp->_vl_msg_id = ntohs (VL_API_BIND_SOCK);
1487 bmp->client_index = vcm->my_client_index;
1488 bmp->context = session_index;
1489 bmp->is_ip4 = session->lcl_addr.is_ip4;
1490 clib_memcpy (bmp->ip, &session->lcl_addr.ip46, sizeof (bmp->ip));
1491 bmp->port = session->lcl_port;
1492 bmp->proto = session->proto;
1493 clib_memcpy (bmp->options, session->options, sizeof (bmp->options));
1494 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
1498 vppcom_send_unbind_sock (u64 vpp_handle)
1500 vl_api_unbind_sock_t *ump;
1502 ump = vl_msg_api_alloc (sizeof (*ump));
1503 memset (ump, 0, sizeof (*ump));
1505 ump->_vl_msg_id = ntohs (VL_API_UNBIND_SOCK);
1506 ump->client_index = vcm->my_client_index;
1507 ump->handle = vpp_handle;
1508 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & ump);
1512 vppcom_session_unbind (u32 session_index)
1514 session_t *session = 0;
1518 VCL_LOCK_AND_GET_SESSION (session_index, &session);
1520 vpp_handle = session->vpp_handle;
1521 vppcom_session_table_del_listener (vpp_handle);
1522 session->vpp_handle = ~0;
1523 session->state = STATE_DISCONNECT;
1525 clib_spinlock_unlock (&vcm->sessions_lockp);
1527 if (VPPCOM_DEBUG > 1)
1528 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
1529 "sending unbind msg! new state 0x%x (%s)",
1530 getpid (), vpp_handle, session_index,
1531 session->state, vppcom_session_state_str (session->state));
1533 if (VPPCOM_DEBUG > 0)
1536 ELOG_TYPE_DECLARE (e) =
1538 .format = "unbind: handle:%x",
1539 .format_args = "i8",
1547 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
1548 ed->handle = vpp_handle;
1551 vppcom_send_unbind_sock (vpp_handle);
1558 vppcom_session_disconnect (u32 session_index)
1562 u8 is_cut_thru, is_listen, is_server;
1564 session_state_t state;
1566 VCL_LOCK_AND_GET_SESSION (session_index, &session);
1568 vpp_handle = session->vpp_handle;
1569 is_server = session->is_server;
1570 is_listen = session->is_listen;
1571 is_cut_thru = session->is_cut_thru;
1572 state = session->state;
1573 clib_spinlock_unlock (&vcm->sessions_lockp);
1575 if (VPPCOM_DEBUG > 1)
1577 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: %s "
1578 "state 0x%x (%s), is_cut_thru %d, is_listen %d",
1579 getpid (), vpp_handle, session_index,
1580 is_server ? "server" : "client",
1581 state, vppcom_session_state_str (state),
1582 is_cut_thru, is_listen);
1585 if (PREDICT_FALSE (is_listen))
1587 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
1588 "Cannot disconnect a listen socket!",
1589 getpid (), vpp_handle, session_index);
1594 /* Through the VPP host stack...
1596 else if (!is_cut_thru)
1598 /* The peer has already initiated the close,
1599 * so send the disconnect session reply.
1601 if (state & STATE_CLOSE_ON_EMPTY)
1603 vppcom_send_disconnect_session_reply (vpp_handle,
1604 session_index, 0 /* rv */ );
1605 if (VPPCOM_DEBUG > 1)
1606 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
1607 "sending disconnect REPLY...",
1608 getpid (), vpp_handle, session_index);
1611 /* Otherwise, send a disconnect session msg...
1615 if (VPPCOM_DEBUG > 1)
1616 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
1617 "sending disconnect...",
1618 getpid (), vpp_handle, session_index);
1620 vppcom_send_disconnect_session (vpp_handle, session_index);
1624 /* Cut-thru connections...
1626 * server: free fifos and segment allocated during connect/redirect
1627 * client: no cleanup required
1633 svm_fifo_segment_private_t *seg;
1635 VCL_LOCK_AND_GET_SESSION (session_index, &session);
1637 if (VPPCOM_DEBUG > 1)
1638 clib_warning ("VCL<%d>: sid %d: freeing cut-thru fifos in "
1640 " server_rx_fifo %p, refcnt = %d"
1641 " server_tx_fifo %p, refcnt = %d",
1642 getpid (), session_index, session->sm_seg_index,
1643 session->server_rx_fifo,
1644 session->server_rx_fifo->refcnt,
1645 session->server_tx_fifo,
1646 session->server_tx_fifo->refcnt);
1648 seg = svm_fifo_segment_get_segment (session->sm_seg_index);
1649 svm_fifo_segment_free_fifo (seg, session->server_rx_fifo,
1650 FIFO_SEGMENT_RX_FREELIST);
1651 svm_fifo_segment_free_fifo (seg, session->server_tx_fifo,
1652 FIFO_SEGMENT_TX_FREELIST);
1653 svm_fifo_segment_delete (seg);
1655 /* TBD: Send cut-thru disconnect event to client */
1657 clib_spinlock_unlock (&vcm->sessions_lockp);
1661 /* TBD: Send cut-thru disconnect event to server */
1669 #define foreach_sock_msg \
1670 _(SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \
1671 _(BIND_SOCK_REPLY, bind_sock_reply) \
1672 _(UNBIND_SOCK_REPLY, unbind_sock_reply) \
1673 _(ACCEPT_SESSION, accept_session) \
1674 _(CONNECT_SOCK, connect_sock) \
1675 _(CONNECT_SESSION_REPLY, connect_session_reply) \
1676 _(DISCONNECT_SESSION, disconnect_session) \
1677 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
1678 _(RESET_SESSION, reset_session) \
1679 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
1680 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
1681 _(MAP_ANOTHER_SEGMENT, map_another_segment)
1684 vppcom_api_hookup (void)
1687 vl_msg_api_set_handlers(VL_API_##N, #n, \
1688 vl_api_##n##_t_handler, \
1690 vl_api_##n##_t_endian, \
1691 vl_api_##n##_t_print, \
1692 sizeof(vl_api_##n##_t), 1);
1698 vppcom_cfg_init (vppcom_cfg_t * vcl_cfg)
1702 vcl_cfg->heapsize = (256ULL << 20);
1703 vcl_cfg->vpp_api_q_length = 1024;
1704 vcl_cfg->segment_baseva = 0x200000000ULL;
1705 vcl_cfg->segment_size = (256 << 20);
1706 vcl_cfg->add_segment_size = (128 << 20);
1707 vcl_cfg->preallocated_fifo_pairs = 8;
1708 vcl_cfg->rx_fifo_size = (1 << 20);
1709 vcl_cfg->tx_fifo_size = (1 << 20);
1710 vcl_cfg->event_queue_size = 2048;
1711 vcl_cfg->listen_queue_size = CLIB_CACHE_LINE_BYTES / sizeof (u32);
1712 vcl_cfg->app_timeout = 10 * 60.0;
1713 vcl_cfg->session_timeout = 10 * 60.0;
1714 vcl_cfg->accept_timeout = 60.0;
1715 vcl_cfg->event_ring_size = (128 << 10);
1716 vcl_cfg->event_log_path = "/dev/shm";
1720 vppcom_cfg_heapsize (char *conf_fname)
1722 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
1735 fp = fopen (conf_fname, "r");
1738 if (VPPCOM_DEBUG > 0)
1739 fprintf (stderr, "open configuration file '%s' failed\n", conf_fname);
1742 argv = calloc (1, sizeof (char *));
1748 if (fgets (inbuf, 4096, fp) == 0)
1750 p = strtok (inbuf, " \t\n");
1756 char **tmp = realloc (argv, argc * sizeof (char *));
1760 arg = strndup (p, 1024);
1763 argv[argc - 1] = arg;
1764 p = strtok (NULL, " \t\n");
1771 char **tmp = realloc (argv, (argc + 1) * sizeof (char *));
1778 * Look for and parse the "heapsize" config parameter.
1779 * Manual since none of the clib infra has been bootstrapped yet.
1781 * Format: heapsize <nn>[mM][gG]
1784 for (i = 1; i < (argc - 1); i++)
1786 if (!strncmp (argv[i], "heapsize", 8))
1788 sizep = (u8 *) argv[i + 1];
1790 while (*sizep >= '0' && *sizep <= '9')
1793 size += *sizep++ - '0';
1797 if (VPPCOM_DEBUG > 0)
1798 clib_warning ("VCL<%d>: parse error '%s %s', "
1799 "using default heapsize %lld (0x%llx)",
1800 getpid (), argv[i], argv[i + 1],
1801 vcl_cfg->heapsize, vcl_cfg->heapsize);
1805 if (*sizep == 'g' || *sizep == 'G')
1806 vcl_cfg->heapsize = size << 30;
1807 else if (*sizep == 'm' || *sizep == 'M')
1808 vcl_cfg->heapsize = size << 20;
1811 if (VPPCOM_DEBUG > 0)
1812 clib_warning ("VCL<%d>: parse error '%s %s', "
1813 "using default heapsize %lld (0x%llx)",
1814 getpid (), argv[i], argv[i + 1],
1815 vcl_cfg->heapsize, vcl_cfg->heapsize);
1827 vcl_mem = mmap (0, vcl_cfg->heapsize, PROT_READ | PROT_WRITE,
1828 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
1829 if (vcl_mem == MAP_FAILED)
1831 clib_unix_error ("VCL<%d>: ERROR: mmap(0, %lld == 0x%llx, "
1832 "PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, "
1834 getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize);
1837 heap = clib_mem_init (vcl_mem, vcl_cfg->heapsize);
1840 clib_warning ("VCL<%d>: ERROR: clib_mem_init() failed!", getpid ());
1843 vcl_mem = clib_mem_alloc (sizeof (_vppcom_main));
1846 clib_warning ("VCL<%d>: ERROR: clib_mem_alloc() failed!", getpid ());
1850 clib_memcpy (vcl_mem, &_vppcom_main, sizeof (_vppcom_main));
1853 if (VPPCOM_DEBUG > 0)
1854 clib_warning ("VCL<%d>: allocated VCL heap = %p, size %lld (0x%llx)",
1855 getpid (), heap, vcl_cfg->heapsize, vcl_cfg->heapsize);
1859 vppcom_cfg_read (char *conf_fname)
1861 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
1863 unformat_input_t _input, *input = &_input;
1864 unformat_input_t _line_input, *line_input = &_line_input;
1865 u8 vc_cfg_input = 0;
1868 u32 uid, gid, q_len;
1870 fd = open (conf_fname, O_RDONLY);
1873 if (VPPCOM_DEBUG > 0)
1874 clib_warning ("VCL<%d>: open configuration file '%s' failed!",
1875 getpid (), conf_fname);
1879 if (fstat (fd, &s) < 0)
1881 if (VPPCOM_DEBUG > 0)
1882 clib_warning ("VCL<%d>: failed to stat `%s'", getpid (), conf_fname);
1886 if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode)))
1888 if (VPPCOM_DEBUG > 0)
1889 clib_warning ("VCL<%d>: not a regular file `%s'",
1890 getpid (), conf_fname);
1894 unformat_init_clib_file (input, fd);
1896 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1898 (void) unformat_user (input, unformat_line_input, line_input);
1899 unformat_skip_white_space (line_input);
1901 if (unformat (line_input, "vcl {"))
1909 if (unformat (line_input, "heapsize %s", &chroot_path))
1911 vec_terminate_c_string (chroot_path);
1912 if (VPPCOM_DEBUG > 0)
1913 clib_warning ("VCL<%d>: configured heapsize %s, "
1914 "actual heapsize %lld (0x%llx)",
1915 getpid (), chroot_path, vcl_cfg->heapsize,
1917 vec_free (chroot_path);
1919 else if (unformat (line_input, "api-prefix %s", &chroot_path))
1921 vec_terminate_c_string (chroot_path);
1922 vl_set_memory_root_path ((char *) chroot_path);
1923 if (VPPCOM_DEBUG > 0)
1924 clib_warning ("VCL<%d>: configured api-prefix %s",
1925 getpid (), chroot_path);
1926 chroot_path = 0; /* Don't vec_free() it! */
1928 else if (unformat (line_input, "vpp-api-q-length %d", &q_len))
1930 if (q_len < vcl_cfg->vpp_api_q_length)
1932 clib_warning ("VCL<%d>: ERROR: configured vpp-api-q-length "
1933 "(%u) is too small! Using default: %u ",
1934 getpid (), q_len, vcl_cfg->vpp_api_q_length);
1938 vcl_cfg->vpp_api_q_length = q_len;
1940 if (VPPCOM_DEBUG > 0)
1941 clib_warning ("VCL<%d>: configured vpp-api-q-length %u",
1942 getpid (), vcl_cfg->vpp_api_q_length);
1945 else if (unformat (line_input, "uid %d", &uid))
1947 vl_set_memory_uid (uid);
1948 if (VPPCOM_DEBUG > 0)
1949 clib_warning ("VCL<%d>: configured uid %d", getpid (), uid);
1951 else if (unformat (line_input, "gid %d", &gid))
1953 vl_set_memory_gid (gid);
1954 if (VPPCOM_DEBUG > 0)
1955 clib_warning ("VCL<%d>: configured gid %d", getpid (), gid);
1957 else if (unformat (line_input, "segment-baseva 0x%lx",
1958 &vcl_cfg->segment_baseva))
1960 if (VPPCOM_DEBUG > 0)
1961 clib_warning ("VCL<%d>: configured segment_baseva 0x%lx",
1962 getpid (), vcl_cfg->segment_baseva);
1964 else if (unformat (line_input, "segment-size 0x%lx",
1965 &vcl_cfg->segment_size))
1967 if (VPPCOM_DEBUG > 0)
1968 clib_warning ("VCL<%d>: configured segment_size 0x%lx (%ld)",
1969 getpid (), vcl_cfg->segment_size,
1970 vcl_cfg->segment_size);
1972 else if (unformat (line_input, "segment-size %ld",
1973 &vcl_cfg->segment_size))
1975 if (VPPCOM_DEBUG > 0)
1976 clib_warning ("VCL<%d>: configured segment_size %ld (0x%lx)",
1977 getpid (), vcl_cfg->segment_size,
1978 vcl_cfg->segment_size);
1980 else if (unformat (line_input, "add-segment-size 0x%lx",
1981 &vcl_cfg->add_segment_size))
1983 if (VPPCOM_DEBUG > 0)
1985 ("VCL<%d>: configured add_segment_size 0x%lx (%ld)",
1986 getpid (), vcl_cfg->add_segment_size,
1987 vcl_cfg->add_segment_size);
1989 else if (unformat (line_input, "add-segment-size %ld",
1990 &vcl_cfg->add_segment_size))
1992 if (VPPCOM_DEBUG > 0)
1994 ("VCL<%d>: configured add_segment_size %ld (0x%lx)",
1995 getpid (), vcl_cfg->add_segment_size,
1996 vcl_cfg->add_segment_size);
1998 else if (unformat (line_input, "preallocated-fifo-pairs %d",
1999 &vcl_cfg->preallocated_fifo_pairs))
2001 if (VPPCOM_DEBUG > 0)
2002 clib_warning ("VCL<%d>: configured preallocated_fifo_pairs "
2003 "%d (0x%x)", getpid (),
2004 vcl_cfg->preallocated_fifo_pairs,
2005 vcl_cfg->preallocated_fifo_pairs);
2007 else if (unformat (line_input, "rx-fifo-size 0x%lx",
2008 &vcl_cfg->rx_fifo_size))
2010 if (VPPCOM_DEBUG > 0)
2011 clib_warning ("VCL<%d>: configured rx_fifo_size 0x%lx (%ld)",
2012 getpid (), vcl_cfg->rx_fifo_size,
2013 vcl_cfg->rx_fifo_size);
2015 else if (unformat (line_input, "rx-fifo-size %ld",
2016 &vcl_cfg->rx_fifo_size))
2018 if (VPPCOM_DEBUG > 0)
2019 clib_warning ("VCL<%d>: configured rx_fifo_size %ld (0x%lx)",
2020 getpid (), vcl_cfg->rx_fifo_size,
2021 vcl_cfg->rx_fifo_size);
2023 else if (unformat (line_input, "tx-fifo-size 0x%lx",
2024 &vcl_cfg->tx_fifo_size))
2026 if (VPPCOM_DEBUG > 0)
2027 clib_warning ("VCL<%d>: configured tx_fifo_size 0x%lx (%ld)",
2028 getpid (), vcl_cfg->tx_fifo_size,
2029 vcl_cfg->tx_fifo_size);
2031 else if (unformat (line_input, "tx-fifo-size %ld",
2032 &vcl_cfg->tx_fifo_size))
2034 if (VPPCOM_DEBUG > 0)
2035 clib_warning ("VCL<%d>: configured tx_fifo_size %ld (0x%lx)",
2036 getpid (), vcl_cfg->tx_fifo_size,
2037 vcl_cfg->tx_fifo_size);
2039 else if (unformat (line_input, "event-queue-size 0x%lx",
2040 &vcl_cfg->event_queue_size))
2042 if (VPPCOM_DEBUG > 0)
2043 clib_warning ("VCL<%d>: configured event_queue_size "
2045 getpid (), vcl_cfg->event_queue_size,
2046 vcl_cfg->event_queue_size);
2048 else if (unformat (line_input, "event-queue-size %ld",
2049 &vcl_cfg->event_queue_size))
2051 if (VPPCOM_DEBUG > 0)
2052 clib_warning ("VCL<%d>: configured event_queue_size "
2054 getpid (), vcl_cfg->event_queue_size,
2055 vcl_cfg->event_queue_size);
2057 else if (unformat (line_input, "listen-queue-size 0x%lx",
2058 &vcl_cfg->listen_queue_size))
2060 if (VPPCOM_DEBUG > 0)
2061 clib_warning ("VCL<%d>: configured listen_queue_size "
2063 getpid (), vcl_cfg->listen_queue_size,
2064 vcl_cfg->listen_queue_size);
2066 else if (unformat (line_input, "listen-queue-size %ld",
2067 &vcl_cfg->listen_queue_size))
2069 if (VPPCOM_DEBUG > 0)
2070 clib_warning ("VCL<%d>: configured listen_queue_size "
2072 getpid (), vcl_cfg->listen_queue_size,
2073 vcl_cfg->listen_queue_size);
2075 else if (unformat (line_input, "app-timeout %f",
2076 &vcl_cfg->app_timeout))
2078 if (VPPCOM_DEBUG > 0)
2079 clib_warning ("VCL<%d>: configured app_timeout %f",
2080 getpid (), vcl_cfg->app_timeout);
2082 else if (unformat (line_input, "session-timeout %f",
2083 &vcl_cfg->session_timeout))
2085 if (VPPCOM_DEBUG > 0)
2086 clib_warning ("VCL<%d>: configured session_timeout %f",
2087 getpid (), vcl_cfg->session_timeout);
2089 else if (unformat (line_input, "accept-timeout %f",
2090 &vcl_cfg->accept_timeout))
2092 if (VPPCOM_DEBUG > 0)
2093 clib_warning ("VCL<%d>: configured accept_timeout %f",
2094 getpid (), vcl_cfg->accept_timeout);
2096 else if (unformat (line_input, "app-proxy-transport-tcp"))
2098 vcl_cfg->app_proxy_transport_tcp = 1;
2099 if (VPPCOM_DEBUG > 0)
2100 clib_warning ("VCL<%d>: configured "
2101 "app_proxy_transport_tcp (%d)",
2102 getpid (), vcl_cfg->app_proxy_transport_tcp);
2104 else if (unformat (line_input, "app-proxy-transport-udp"))
2106 vcl_cfg->app_proxy_transport_udp = 1;
2107 if (VPPCOM_DEBUG > 0)
2108 clib_warning ("VCL<%d>: configured "
2109 "app_proxy_transport_udp (%d)",
2110 getpid (), vcl_cfg->app_proxy_transport_udp);
2112 else if (unformat (line_input, "app-scope-local"))
2114 vcl_cfg->app_scope_local = 1;
2115 if (VPPCOM_DEBUG > 0)
2116 clib_warning ("VCL<%d>: configured app_scope_local (%d)",
2117 getpid (), vcl_cfg->app_scope_local);
2119 else if (unformat (line_input, "app-scope-global"))
2121 vcl_cfg->app_scope_global = 1;
2122 if (VPPCOM_DEBUG > 0)
2123 clib_warning ("VCL<%d>: configured app_scope_global (%d)",
2124 getpid (), vcl_cfg->app_scope_global);
2126 else if (unformat (line_input, "namespace-secret %lu",
2127 &vcl_cfg->namespace_secret))
2129 if (VPPCOM_DEBUG > 0)
2131 ("VCL<%d>: configured namespace_secret %lu (0x%lx)",
2132 getpid (), vcl_cfg->namespace_secret,
2133 vcl_cfg->namespace_secret);
2135 else if (unformat (line_input, "namespace-id %v",
2136 &vcl_cfg->namespace_id))
2138 vl_api_application_attach_t *mp;
2139 u32 max_nsid_vec_len = sizeof (mp->namespace_id) - 1;
2140 u32 nsid_vec_len = vec_len (vcl_cfg->namespace_id);
2141 if (nsid_vec_len > max_nsid_vec_len)
2143 _vec_len (vcl_cfg->namespace_id) = max_nsid_vec_len;
2144 if (VPPCOM_DEBUG > 0)
2145 clib_warning ("VCL<%d>: configured namespace_id is "
2146 "too long, truncated to %d characters!",
2147 getpid (), max_nsid_vec_len);
2150 if (VPPCOM_DEBUG > 0)
2151 clib_warning ("VCL<%d>: configured namespace_id %v",
2152 getpid (), vcl_cfg->namespace_id);
2154 else if (unformat (line_input, "}"))
2157 if (VPPCOM_DEBUG > 0)
2158 clib_warning ("VCL<%d>: completed parsing vppcom config!",
2164 if (line_input->buffer[line_input->index] != '#')
2166 clib_warning ("VCL<%d>: Unknown vppcom config option: '%s'",
2168 &line_input->buffer[line_input->index]);
2175 unformat_free (input);
2183 * VPPCOM Public API functions
2186 vppcom_app_create (char *app_name)
2188 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
2199 vppcom_cfg_init (vcl_cfg);
2200 env_var_str = getenv (VPPCOM_ENV_DEBUG);
2204 if (sscanf (env_var_str, "%u", &tmp) != 1)
2205 clib_warning ("VCL<%d>: Invalid debug level specified in "
2206 "the environment variable "
2208 " (%s)!\n", getpid (), env_var_str);
2212 clib_warning ("VCL<%d>: configured VCL debug level (%u) from "
2213 VPPCOM_ENV_DEBUG "!", getpid (), vcm->debug);
2216 conf_fname = getenv (VPPCOM_ENV_CONF);
2219 conf_fname = VPPCOM_CONF_DEFAULT;
2220 if (VPPCOM_DEBUG > 0)
2221 clib_warning ("VCL<%d>: getenv '%s' failed!", getpid (),
2224 vppcom_cfg_heapsize (conf_fname);
2225 clib_fifo_validate (vcm->client_session_index_fifo,
2226 vcm->cfg.listen_queue_size);
2227 vppcom_cfg_read (conf_fname);
2228 env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_ID);
2231 u32 ns_id_vec_len = strlen (env_var_str);
2233 vec_reset_length (vcm->cfg.namespace_id);
2234 vec_validate (vcm->cfg.namespace_id, ns_id_vec_len - 1);
2235 clib_memcpy (vcm->cfg.namespace_id, env_var_str, ns_id_vec_len);
2237 if (VPPCOM_DEBUG > 0)
2238 clib_warning ("VCL<%d>: configured namespace_id (%v) from "
2239 VPPCOM_ENV_APP_NAMESPACE_ID "!", getpid (),
2240 vcm->cfg.namespace_id);
2242 env_var_str = getenv (VPPCOM_ENV_APP_NAMESPACE_SECRET);
2246 if (sscanf (env_var_str, "%lu", &tmp) != 1)
2247 clib_warning ("VCL<%d>: Invalid namespace secret specified in "
2248 "the environment variable "
2249 VPPCOM_ENV_APP_NAMESPACE_SECRET
2250 " (%s)!\n", getpid (), env_var_str);
2253 vcm->cfg.namespace_secret = tmp;
2254 if (VPPCOM_DEBUG > 0)
2255 clib_warning ("VCL<%d>: configured namespace secret "
2256 "(%lu) from " VPPCOM_ENV_APP_NAMESPACE_ID "!",
2257 getpid (), vcm->cfg.namespace_secret);
2260 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP))
2262 vcm->cfg.app_proxy_transport_tcp = 1;
2263 if (VPPCOM_DEBUG > 0)
2264 clib_warning ("VCL<%d>: configured app_proxy_transport_tcp "
2265 "(%u) from " VPPCOM_ENV_APP_PROXY_TRANSPORT_TCP
2266 "!", getpid (), vcm->cfg.app_proxy_transport_tcp);
2268 if (getenv (VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP))
2270 vcm->cfg.app_proxy_transport_udp = 1;
2271 if (VPPCOM_DEBUG > 0)
2272 clib_warning ("VCL<%d>: configured app_proxy_transport_udp "
2273 "(%u) from " VPPCOM_ENV_APP_PROXY_TRANSPORT_UDP
2274 "!", getpid (), vcm->cfg.app_proxy_transport_udp);
2276 if (getenv (VPPCOM_ENV_APP_SCOPE_LOCAL))
2278 vcm->cfg.app_scope_local = 1;
2279 if (VPPCOM_DEBUG > 0)
2280 clib_warning ("VCL<%d>: configured app_scope_local (%u) from "
2281 VPPCOM_ENV_APP_SCOPE_LOCAL "!", getpid (),
2282 vcm->cfg.app_scope_local);
2284 if (getenv (VPPCOM_ENV_APP_SCOPE_GLOBAL))
2286 vcm->cfg.app_scope_global = 1;
2287 if (VPPCOM_DEBUG > 0)
2288 clib_warning ("VCL<%d>: configured app_scope_global (%u) from "
2289 VPPCOM_ENV_APP_SCOPE_GLOBAL "!", getpid (),
2290 vcm->cfg.app_scope_global);
2293 vcm->main_cpu = os_get_thread_index ();
2294 heap = clib_mem_get_per_cpu_heap ();
2295 h = mheap_header (heap);
2297 /* make the main heap thread-safe */
2298 h->flags |= MHEAP_FLAG_THREAD_SAFE;
2300 vcm->session_index_by_vpp_handles = hash_create (0, sizeof (uword));
2302 clib_time_init (&vcm->clib_time);
2303 vppcom_init_error_string_table ();
2304 svm_fifo_segment_main_init (vcl_cfg->segment_baseva,
2305 20 /* timeout in secs */ );
2306 clib_spinlock_init (&vcm->sessions_lockp);
2309 if (vcm->my_client_index == ~0)
2311 vppcom_api_hookup ();
2312 vcm->app_state = STATE_APP_START;
2313 rv = vppcom_connect_to_vpp (app_name);
2316 clib_warning ("VCL<%d>: ERROR: couldn't connect to VPP!",
2321 if (VPPCOM_DEBUG > 0)
2322 clib_warning ("VCL<%d>: sending session enable", getpid ());
2324 rv = vppcom_app_session_enable ();
2327 clib_warning ("VCL<%d>: ERROR: vppcom_app_session_enable() "
2328 "failed!", getpid ());
2332 if (VPPCOM_DEBUG > 0)
2333 clib_warning ("VCL<%d>: sending app attach", getpid ());
2335 rv = vppcom_app_attach ();
2338 clib_warning ("VCL<%d>: ERROR: vppcom_app_attach() failed!",
2343 if (VPPCOM_DEBUG > 0)
2344 clib_warning ("VCL<%d>: app_name '%s', my_client_index %d (0x%x)",
2345 getpid (), app_name, vcm->my_client_index,
2346 vcm->my_client_index);
2353 vppcom_app_destroy (void)
2357 if (vcm->my_client_index == ~0)
2360 if (VPPCOM_DEBUG > 0)
2361 clib_warning ("VCL<%d>: detaching from VPP, my_client_index %d (0x%x)",
2362 getpid (), vcm->my_client_index, vcm->my_client_index);
2364 if (VPPCOM_DEBUG > 0)
2367 ELOG_TYPE_DECLARE (e) =
2369 .format = "app_detach:C:%d",
2370 .format_args = "i4",
2377 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, vcm->elog_track);
2378 ed->data = vcm->my_client_index;
2382 vppcom_app_detach ();
2383 rv = vppcom_wait_for_app_state_change (STATE_APP_ENABLED);
2384 if (PREDICT_FALSE (rv))
2386 if (VPPCOM_DEBUG > 0)
2387 clib_warning ("VCL<%d>: application detach timed out! "
2388 "returning %d (%s)",
2389 getpid (), rv, vppcom_retval_str (rv));
2392 /* Finished with logging before client gets reset to ~0 */
2393 if (VPPCOM_DEBUG > 0)
2396 vl_client_disconnect_from_vlib ();
2397 vcm->my_client_index = ~0;
2398 vcm->app_state = STATE_APP_START;
2402 vppcom_session_create (u8 proto, u8 is_nonblocking)
2407 clib_spinlock_lock (&vcm->sessions_lockp);
2408 pool_get (vcm->sessions, session);
2409 memset (session, 0, sizeof (*session));
2410 session_index = session - vcm->sessions;
2412 session->proto = proto;
2413 session->state = STATE_START;
2414 session->is_nonblocking = is_nonblocking ? 1 : 0;
2415 session->vpp_handle = ~0;
2416 clib_spinlock_unlock (&vcm->sessions_lockp);
2418 if (VPPCOM_DEBUG > 0)
2419 clib_warning ("VCL<%d>: sid %u", getpid (), session_index);
2421 if (VPPCOM_DEBUG > 0)
2423 session->elog_track.name =
2424 (char *) format (0, "C:%d:S:%d%c", vcm->my_client_index,
2426 elog_track_register (&vcm->elog_main, &session->elog_track);
2429 ELOG_TYPE_DECLARE (e) =
2431 .format = "session_create:proto:%d state:%d is_nonblocking:%d",
2432 .format_args = "i4i4i4",
2440 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
2441 ed->data[0] = session->proto;
2442 ed->data[1] = session->state;
2443 ed->data[2] = session->is_nonblocking;
2447 return (int) session_index;
2451 vppcom_session_close (uint32_t session_index)
2453 session_t *session = 0;
2462 session_state_t state;
2464 VCL_LOCK_AND_GET_SESSION (session_index, &session);
2465 is_listen = session->is_listen;
2466 is_vep = session->is_vep;
2467 is_vep_session = session->is_vep_session;
2468 next_sid = session->vep.next_sid;
2469 vep_idx = session->vep.vep_idx;
2470 state = session->state;
2471 vpp_handle = session->vpp_handle;
2472 clib_spinlock_unlock (&vcm->sessions_lockp);
2474 if (VPPCOM_DEBUG > 0)
2477 clib_warning ("VCL<%d>: vep_idx %u / sid %u: "
2478 "closing epoll session...",
2479 getpid (), session_index, session_index);
2481 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %d: "
2482 "closing session...",
2483 getpid (), vpp_handle, session_index);
2488 while (next_sid != ~0)
2490 rv = vppcom_epoll_ctl (session_index, EPOLL_CTL_DEL, next_sid, 0);
2491 if ((VPPCOM_DEBUG > 0) && PREDICT_FALSE (rv < 0))
2492 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
2493 "EPOLL_CTL_DEL vep_idx %u failed! rv %d (%s)",
2494 getpid (), vpp_handle, next_sid, vep_idx,
2495 rv, vppcom_retval_str (rv));
2497 VCL_LOCK_AND_GET_SESSION (session_index, &session);
2498 next_sid = session->vep.next_sid;
2499 clib_spinlock_unlock (&vcm->sessions_lockp);
2506 rv = vppcom_epoll_ctl (vep_idx, EPOLL_CTL_DEL, session_index, 0);
2507 if ((VPPCOM_DEBUG > 0) && (rv < 0))
2508 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
2509 "EPOLL_CTL_DEL vep_idx %u failed! rv %d (%s)",
2510 getpid (), vpp_handle, session_index,
2511 vep_idx, rv, vppcom_retval_str (rv));
2516 if (state == STATE_LISTEN)
2518 rv = vppcom_session_unbind (session_index);
2519 if (PREDICT_FALSE (rv < 0))
2521 if (VPPCOM_DEBUG > 0)
2522 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
2523 "listener unbind failed! rv %d (%s)",
2524 getpid (), vpp_handle, session_index,
2525 rv, vppcom_retval_str (rv));
2530 else if (state & (CLIENT_STATE_OPEN | SERVER_STATE_OPEN))
2532 rv = vppcom_session_disconnect (session_index);
2533 if (PREDICT_FALSE (rv < 0))
2534 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
2535 "session disconnect failed! rv %d (%s)",
2536 getpid (), vpp_handle, session_index,
2537 rv, vppcom_retval_str (rv));
2541 VCL_LOCK_AND_GET_SESSION (session_index, &session);
2542 vpp_handle = session->vpp_handle;
2543 if (vpp_handle != ~0)
2545 p = hash_get (vcm->session_index_by_vpp_handles, vpp_handle);
2547 hash_unset (vcm->session_index_by_vpp_handles, vpp_handle);
2549 pool_put_index (vcm->sessions, session_index);
2550 clib_spinlock_unlock (&vcm->sessions_lockp);
2552 if (VPPCOM_DEBUG > 0)
2555 clib_warning ("VCL<%d>: vep_idx %u / sid %u: epoll session removed.",
2556 getpid (), session_index, session_index);
2558 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: session removed.",
2559 getpid (), vpp_handle, session_index);
2563 if (VPPCOM_DEBUG > 0)
2566 ELOG_TYPE_DECLARE (e) =
2568 .format = "session_close:rv:%d",
2569 .format_args = "i4",
2577 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
2586 vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep)
2588 session_t *session = 0;
2592 return VPPCOM_EINVAL;
2594 VCL_LOCK_AND_GET_SESSION (session_index, &session);
2596 if (session->is_vep)
2598 clib_spinlock_unlock (&vcm->sessions_lockp);
2599 clib_warning ("VCL<%d>: ERROR: sid %u: cannot "
2600 "bind to an epoll session!", getpid (), session_index);
2605 session->lcl_addr.is_ip4 = ep->is_ip4;
2606 session->lcl_addr.ip46 = to_ip46 (!ep->is_ip4, ep->ip);
2607 session->lcl_port = ep->port;
2609 if (VPPCOM_DEBUG > 0)
2610 clib_warning ("VCL<%d>: sid %u: binding to local %s address %U "
2611 "port %u, proto %s", getpid (), session_index,
2612 session->lcl_addr.is_ip4 ? "IPv4" : "IPv6",
2613 format_ip46_address, &session->lcl_addr.ip46,
2614 session->lcl_addr.is_ip4,
2615 clib_net_to_host_u16 (session->lcl_port),
2616 session->proto ? "UDP" : "TCP");
2618 if (VPPCOM_DEBUG > 0)
2620 if (session->lcl_addr.is_ip4)
2623 ELOG_TYPE_DECLARE (e) =
2625 .format = "bind local:%s:%d.%d.%d.%d:%d ",
2626 .format_args = "t1i1i1i1i1i2",
2627 .n_enum_strings = 2,
2628 .enum_strings = {"TCP", "UDP",},
2631 CLIB_PACKED (struct {
2637 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
2638 ed->proto = session->proto;
2639 ed->addr[0] = session->lcl_addr.ip46.ip4.as_u8[0];
2640 ed->addr[1] = session->lcl_addr.ip46.ip4.as_u8[1];
2641 ed->addr[2] = session->lcl_addr.ip46.ip4.as_u8[2];
2642 ed->addr[3] = session->lcl_addr.ip46.ip4.as_u8[3];
2643 ed->port = clib_net_to_host_u16 (session->lcl_port);
2648 clib_spinlock_unlock (&vcm->sessions_lockp);
2654 vppcom_session_listen (uint32_t listen_session_index, uint32_t q_len)
2656 session_t *listen_session = 0;
2657 u64 listen_vpp_handle;
2660 VCL_LOCK_AND_GET_SESSION (listen_session_index, &listen_session);
2662 if (listen_session->is_vep)
2664 clib_spinlock_unlock (&vcm->sessions_lockp);
2665 clib_warning ("VCL<%d>: ERROR: sid %u: cannot listen on an "
2666 "epoll session!", getpid (), listen_session_index);
2671 listen_vpp_handle = listen_session->vpp_handle;
2672 if (listen_session->is_listen)
2674 clib_spinlock_unlock (&vcm->sessions_lockp);
2675 if (VPPCOM_DEBUG > 0)
2676 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
2677 "already in listen state!",
2678 getpid (), listen_vpp_handle, listen_session_index);
2683 if (VPPCOM_DEBUG > 0)
2684 clib_warning ("VCL<%d>: vpp handle 0x%llx, "
2685 "sid %u: sending bind request...",
2686 getpid (), listen_vpp_handle, listen_session_index);
2688 vppcom_send_bind_sock (listen_session, listen_session_index);
2689 clib_spinlock_unlock (&vcm->sessions_lockp);
2691 vppcom_wait_for_session_state_change (listen_session_index, STATE_LISTEN,
2692 vcm->cfg.session_timeout);
2694 VCL_LOCK_AND_GET_SESSION (listen_session_index, &listen_session);
2695 if (PREDICT_FALSE (retval))
2697 if (VPPCOM_DEBUG > 0)
2698 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: bind failed! "
2699 "returning %d (%s)", getpid (),
2700 listen_session->vpp_handle, listen_session_index,
2701 retval, vppcom_retval_str (retval));
2702 clib_spinlock_unlock (&vcm->sessions_lockp);
2707 clib_fifo_validate (vcm->client_session_index_fifo, q_len);
2708 clib_spinlock_unlock (&vcm->sessions_lockp);
2714 vppcom_session_accept (uint32_t listen_session_index, vppcom_endpt_t * ep,
2717 session_t *listen_session = 0;
2718 session_t *client_session = 0;
2719 u32 client_session_index = ~0, n_fifos;
2723 u64 listen_vpp_handle;
2725 VCL_LOCK_AND_GET_SESSION (listen_session_index, &listen_session);
2727 if (listen_session->is_vep)
2729 clib_spinlock_unlock (&vcm->sessions_lockp);
2730 clib_warning ("VCL<%d>: ERROR: sid %u: cannot accept on an "
2731 "epoll session!", getpid (), listen_session_index);
2736 listen_vpp_handle = listen_session->vpp_handle;
2737 if (listen_session->state != STATE_LISTEN)
2739 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
2740 "not in listen state! state 0x%x (%s)", getpid (),
2741 listen_vpp_handle, listen_session_index,
2742 listen_session->state,
2743 vppcom_session_state_str (listen_session->state));
2744 clib_spinlock_unlock (&vcm->sessions_lockp);
2748 wait_for = (listen_session->is_nonblocking) ? 0 : vcm->cfg.accept_timeout;
2750 clib_spinlock_unlock (&vcm->sessions_lockp);
2754 rv = vppcom_wait_for_client_session_index (wait_for);
2757 if ((VPPCOM_DEBUG > 0))
2758 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
2759 "accept failed! returning %d (%s)", getpid (),
2760 listen_vpp_handle, listen_session_index,
2761 rv, vppcom_retval_str (rv));
2769 clib_spinlock_lock (&vcm->sessions_lockp);
2770 clib_fifo_sub1 (vcm->client_session_index_fifo, client_session_index);
2771 rv = vppcom_session_at_index (client_session_index, &client_session);
2772 if (PREDICT_FALSE (rv))
2774 rv = VPPCOM_ECONNABORTED;
2775 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: client sid %u "
2776 "lookup failed! returning %d (%s)", getpid (),
2777 listen_vpp_handle, listen_session_index,
2778 client_session_index, rv, vppcom_retval_str (rv));
2782 client_session->is_nonblocking = (flags & O_NONBLOCK) ? 1 : 0;
2783 if (VPPCOM_DEBUG > 0)
2784 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: Got a client request! "
2785 "vpp handle 0x%llx, sid %u, flags %d, is_nonblocking %u",
2786 getpid (), listen_vpp_handle, listen_session_index,
2787 client_session->vpp_handle, client_session_index,
2788 flags, client_session->is_nonblocking);
2792 ep->is_cut_thru = client_session->is_cut_thru;
2793 ep->is_ip4 = client_session->peer_addr.is_ip4;
2794 ep->port = client_session->peer_port;
2795 if (client_session->peer_addr.is_ip4)
2796 clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip4,
2797 sizeof (ip4_address_t));
2799 clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip6,
2800 sizeof (ip6_address_t));
2803 if (client_session->is_server && client_session->is_cut_thru)
2805 static svm_fifo_segment_create_args_t _a;
2806 svm_fifo_segment_create_args_t *a = &_a;
2807 svm_fifo_segment_private_t *seg;
2809 cut_thru_str = " cut-thru ";
2811 /* Create the segment */
2812 memset (a, 0, sizeof (*a));
2813 a->segment_name = (char *)
2814 format ((u8 *) a->segment_name, "%d:segment%d%c",
2815 getpid (), vcm->unique_segment_index++, 0);
2816 a->segment_size = vcm->cfg.segment_size;
2818 rv = svm_fifo_segment_create (a);
2819 if (PREDICT_FALSE (rv))
2821 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
2822 "client sid %u svm_fifo_segment_create ('%s') "
2823 "failed! rv %d", getpid (), listen_vpp_handle,
2824 listen_session_index, client_session_index,
2825 a->segment_name, rv);
2826 vec_reset_length (a->new_segment_indices);
2827 rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
2828 vppcom_send_connect_session_reply (client_session,
2829 client_session_index,
2830 client_session->vpp_handle,
2831 client_session->client_context,
2833 clib_spinlock_unlock (&vcm->sessions_lockp);
2838 client_session->segment_name = vec_dup ((u8 *) a->segment_name);
2839 client_session->sm_seg_index = a->new_segment_indices[0];
2840 vec_free (a->new_segment_indices);
2842 seg = svm_fifo_segment_get_segment (client_session->sm_seg_index);
2843 if (vcm->cfg.preallocated_fifo_pairs)
2845 n_fifos = vcm->cfg.preallocated_fifo_pairs;
2846 svm_fifo_segment_preallocate_fifo_pairs (seg, vcm->cfg.rx_fifo_size,
2847 vcm->cfg.tx_fifo_size,
2851 client_session->server_rx_fifo =
2852 svm_fifo_segment_alloc_fifo (seg, vcm->cfg.rx_fifo_size,
2853 FIFO_SEGMENT_RX_FREELIST);
2854 if (PREDICT_FALSE (!client_session->server_rx_fifo))
2856 svm_fifo_segment_delete (seg);
2857 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
2858 "client sid %u rx fifo alloc failed! "
2859 "size %ld (0x%lx)", getpid (), listen_vpp_handle,
2860 listen_session_index, client_session_index,
2861 vcm->cfg.rx_fifo_size, vcm->cfg.rx_fifo_size);
2862 rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
2863 vppcom_send_connect_session_reply (client_session,
2864 client_session_index,
2865 client_session->vpp_handle,
2866 client_session->client_context,
2868 clib_spinlock_unlock (&vcm->sessions_lockp);
2872 client_session->server_rx_fifo->master_session_index =
2873 client_session_index;
2875 client_session->server_tx_fifo =
2876 svm_fifo_segment_alloc_fifo (seg, vcm->cfg.tx_fifo_size,
2877 FIFO_SEGMENT_TX_FREELIST);
2878 if (PREDICT_FALSE (!client_session->server_tx_fifo))
2880 svm_fifo_segment_delete (seg);
2881 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
2882 "client sid %u tx fifo alloc failed! "
2883 "size %ld (0x%lx)", getpid (), listen_vpp_handle,
2884 listen_session_index, client_session_index,
2885 vcm->cfg.tx_fifo_size, vcm->cfg.tx_fifo_size);
2886 rv = VNET_API_ERROR_URI_FIFO_CREATE_FAILED;
2887 vppcom_send_connect_session_reply (client_session,
2888 client_session_index,
2889 client_session->vpp_handle,
2890 client_session->client_context,
2892 clib_spinlock_unlock (&vcm->sessions_lockp);
2896 client_session->server_tx_fifo->master_session_index =
2897 client_session_index;
2899 if (VPPCOM_DEBUG > 1)
2900 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: client sid %u "
2901 "created segment '%s', rx_fifo %p, tx_fifo %p",
2902 getpid (), listen_vpp_handle, listen_session_index,
2903 client_session_index, client_session->segment_name,
2904 client_session->server_rx_fifo,
2905 client_session->server_tx_fifo);
2907 #ifdef CUT_THRU_EVENT_QUEUE /* TBD */
2910 ssvm_shared_header_t *sh = seg->ssvm.sh;
2912 ssvm_lock_non_recursive (sh, 1);
2913 oldheap = ssvm_push_heap (sh);
2914 event_q = client_session->vpp_event_queue =
2915 svm_queue_init (vcm->cfg.event_queue_size,
2916 sizeof (session_fifo_event_t),
2917 getpid (), 0 /* signal not sent */ );
2918 ssvm_pop_heap (oldheap);
2919 ssvm_unlock_non_recursive (sh);
2922 vppcom_send_connect_session_reply (client_session,
2923 client_session_index,
2924 client_session->vpp_handle,
2925 client_session->client_context,
2926 0 /* retval OK */ );
2931 vppcom_send_accept_session_reply (client_session->vpp_handle,
2932 client_session->client_context,
2933 0 /* retval OK */ );
2936 if (VPPCOM_DEBUG > 0)
2937 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: accepted vpp handle "
2938 "0x%llx, sid %u%sconnection to local %s address "
2939 "%U port %u", getpid (), listen_vpp_handle,
2940 listen_session_index, client_session->vpp_handle,
2941 client_session_index, cut_thru_str,
2942 client_session->lcl_addr.is_ip4 ? "IPv4" : "IPv6",
2943 format_ip46_address, &client_session->lcl_addr.ip46,
2944 client_session->lcl_addr.is_ip4,
2945 clib_net_to_host_u16 (client_session->lcl_port));
2947 if (VPPCOM_DEBUG > 0)
2949 client_session->elog_track.name =
2950 (char *) format (0, "C:%d:S:%d%c", vcm->my_client_index,
2951 client_session_index, 0);
2952 elog_track_register (&vcm->elog_main, &client_session->elog_track);
2955 ELOG_TYPE_DECLARE (e) =
2957 .format = "accept cut-thru: listen_handle:%x from_handle:%x",
2958 .format_args = "i8i8",
2966 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, client_session->elog_track);
2967 ed->handle[0] = listen_vpp_handle;
2968 ed->handle[1] = client_session->vpp_handle;
2971 if (client_session->lcl_addr.is_ip4)
2974 ELOG_TYPE_DECLARE (e2) =
2976 .format = "accept cut-thru: S:%d %d.%d.%d.%d:%d ",
2977 .format_args = "i4i1i1i1i1i2",
2980 CLIB_PACKED (struct {
2987 ELOG_TRACK_DATA (&vcm->elog_main, e2, client_session->elog_track);
2988 ed2->session = client_session_index;
2989 ed2->addr[0] = client_session->lcl_addr.ip46.ip4.as_u8[0];
2990 ed2->addr[1] = client_session->lcl_addr.ip46.ip4.as_u8[1];
2991 ed2->addr[2] = client_session->lcl_addr.ip46.ip4.as_u8[2];
2992 ed2->addr[3] = client_session->lcl_addr.ip46.ip4.as_u8[3];
2993 ed2->port = clib_net_to_host_u16 (client_session->lcl_port);
2998 clib_spinlock_unlock (&vcm->sessions_lockp);
2999 rv = (int) client_session_index;
3005 vppcom_session_connect (uint32_t session_index, vppcom_endpt_t * server_ep)
3007 session_t *session = 0;
3008 int rv, retval = VPPCOM_OK;
3009 u64 vpp_handle = ~0;
3011 VCL_LOCK_AND_GET_SESSION (session_index, &session);
3013 if (PREDICT_FALSE (session->is_vep))
3015 clib_spinlock_unlock (&vcm->sessions_lockp);
3016 clib_warning ("VCL<%d>: ERROR: sid %u: cannot "
3017 "connect on an epoll session!", getpid (), session_index);
3022 vpp_handle = session->vpp_handle;
3023 if (PREDICT_FALSE (session->is_server))
3025 clib_spinlock_unlock (&vcm->sessions_lockp);
3026 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: is in use "
3027 "as a server session!", getpid (), vpp_handle,
3033 if (PREDICT_FALSE (session->state & CLIENT_STATE_OPEN))
3035 if (VPPCOM_DEBUG > 0)
3036 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: session already "
3037 "connected to %s %U port %d proto %s, state 0x%x (%s)",
3038 getpid (), vpp_handle, session_index,
3039 session->peer_addr.is_ip4 ? "IPv4" : "IPv6",
3040 format_ip46_address,
3041 &session->peer_addr.ip46, session->peer_addr.is_ip4,
3042 clib_net_to_host_u16 (session->peer_port),
3043 session->proto ? "UDP" : "TCP", session->state,
3044 vppcom_session_state_str (session->state));
3046 clib_spinlock_unlock (&vcm->sessions_lockp);
3050 session->peer_addr.is_ip4 = server_ep->is_ip4;
3051 session->peer_addr.ip46 = to_ip46 (!server_ep->is_ip4, server_ep->ip);
3052 session->peer_port = server_ep->port;
3054 if (VPPCOM_DEBUG > 0)
3055 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: connecting to server "
3056 "%s %U port %d proto %s",
3057 getpid (), vpp_handle, session_index,
3058 session->peer_addr.is_ip4 ? "IPv4" : "IPv6",
3059 format_ip46_address,
3060 &session->peer_addr.ip46, session->peer_addr.is_ip4,
3061 clib_net_to_host_u16 (session->peer_port),
3062 session->proto ? "UDP" : "TCP");
3064 vppcom_send_connect_sock (session, session_index);
3065 clib_spinlock_unlock (&vcm->sessions_lockp);
3068 vppcom_wait_for_session_state_change (session_index, STATE_CONNECT,
3069 vcm->cfg.session_timeout);
3071 VCL_LOCK_AND_GET_SESSION (session_index, &session);
3072 vpp_handle = session->vpp_handle;
3073 clib_spinlock_unlock (&vcm->sessions_lockp);
3076 if (PREDICT_FALSE (retval))
3079 if (VPPCOM_DEBUG > 0)
3080 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: connect failed! "
3081 "returning %d (%s)", getpid (), vpp_handle,
3082 session_index, rv, vppcom_retval_str (rv));
3084 else if (VPPCOM_DEBUG > 0)
3085 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: connected!",
3086 getpid (), vpp_handle, session_index);
3092 vppcom_session_read_internal (uint32_t session_index, void *buf, int n,
3095 session_t *session = 0;
3096 svm_fifo_t *rx_fifo;
3101 session_state_t state;
3108 VCL_LOCK_AND_GET_SESSION (session_index, &session);
3110 if (PREDICT_FALSE (session->is_vep))
3112 clib_spinlock_unlock (&vcm->sessions_lockp);
3113 clib_warning ("VCL<%d>: ERROR: sid %u: cannot "
3114 "read from an epoll session!", getpid (), session_index);
3119 vpp_handle = session->vpp_handle;
3120 is_server = session->is_server;
3121 is_nonblocking = session->is_nonblocking;
3122 state = session->state;
3123 if (PREDICT_FALSE (!(state & (SERVER_STATE_OPEN | CLIENT_STATE_OPEN))))
3125 clib_spinlock_unlock (&vcm->sessions_lockp);
3126 rv = ((state == STATE_DISCONNECT) ?
3127 VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
3129 if (VPPCOM_DEBUG > 0)
3130 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: %s session is "
3131 "not open! state 0x%x (%s), returning %d (%s)",
3132 getpid (), vpp_handle, session_index,
3133 is_server ? "server" : "client", state,
3134 vppcom_session_state_str (state),
3135 rv, vppcom_retval_str (rv));
3139 rx_fifo = ((!session->is_cut_thru || is_server) ?
3140 session->server_rx_fifo : session->server_tx_fifo);
3141 fifo_str = ((!session->is_cut_thru || is_server) ?
3142 "server_rx_fifo" : "server_tx_fifo");
3143 clib_spinlock_unlock (&vcm->sessions_lockp);
3148 n_read = svm_fifo_peek (rx_fifo, 0, n, buf);
3150 n_read = svm_fifo_dequeue_nowait (rx_fifo, n, buf);
3152 while (!is_nonblocking && (n_read <= 0));
3156 VCL_LOCK_AND_GET_SESSION (session_index, &session);
3158 poll_et = (((EPOLLET | EPOLLIN) & session->vep.ev.events) ==
3159 (EPOLLET | EPOLLIN));
3161 session->vep.et_mask |= EPOLLIN;
3163 if (state == STATE_CLOSE_ON_EMPTY)
3165 session_state_t new_state = STATE_DISCONNECT;
3166 rv = VPPCOM_ECONNRESET;
3168 if (VPPCOM_DEBUG > 1)
3170 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: Empty fifo "
3171 "with %s session state 0x%x (%s)!"
3172 " Setting state to 0x%x (%s), returning %d (%s)",
3173 getpid (), vpp_handle, session_index,
3174 is_server ? "server" : "client",
3175 state, vppcom_session_state_str (state),
3176 new_state, vppcom_session_state_str (new_state),
3177 rv, vppcom_retval_str (rv));
3180 session->state = new_state;
3185 clib_spinlock_unlock (&vcm->sessions_lockp);
3190 if (VPPCOM_DEBUG > 2)
3193 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: read %d bytes "
3194 "from %s (%p)", getpid (), vpp_handle,
3195 session_index, n_read, fifo_str, rx_fifo);
3197 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: nothing read! "
3198 "returning %d (%s)", getpid (), vpp_handle,
3199 session_index, rv, vppcom_retval_str (rv));
3206 vppcom_session_read (uint32_t session_index, void *buf, size_t n)
3208 return (vppcom_session_read_internal (session_index, buf, n, 0));
3212 vppcom_session_peek (uint32_t session_index, void *buf, int n)
3214 return (vppcom_session_read_internal (session_index, buf, n, 1));
3218 vppcom_session_read_ready (session_t * session, u32 session_index)
3220 svm_fifo_t *rx_fifo = 0;
3224 u8 is_server = session->is_server;
3225 session_state_t state = session->state;
3226 u64 vpp_handle = session->vpp_handle;
3228 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
3229 if (PREDICT_FALSE (session->is_vep))
3231 clib_warning ("VCL<%d>: ERROR: sid %u: cannot read from an "
3232 "epoll session!", getpid (), session_index);
3237 if (session->is_listen)
3238 ready = clib_fifo_elts (vcm->client_session_index_fifo);
3241 if (!(state & (SERVER_STATE_OPEN | CLIENT_STATE_OPEN | STATE_LISTEN)))
3243 rv = ((state == STATE_DISCONNECT) ? VPPCOM_ECONNRESET :
3246 if (VPPCOM_DEBUG > 1)
3247 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: %s session is "
3248 "not open! state 0x%x (%s), returning %d (%s)",
3249 getpid (), vpp_handle, session_index,
3250 is_server ? "server" : "client",
3251 state, vppcom_session_state_str (state),
3252 rv, vppcom_retval_str (rv));
3256 rx_fifo = ((!session->is_cut_thru || is_server) ?
3257 session->server_rx_fifo : session->server_tx_fifo);
3259 ready = svm_fifo_max_dequeue (rx_fifo);
3265 ((EPOLLET | EPOLLIN) & session->vep.ev.events) == (EPOLLET | EPOLLIN);
3267 session->vep.et_mask |= EPOLLIN;
3269 if (state == STATE_CLOSE_ON_EMPTY)
3271 rv = VPPCOM_ECONNRESET;
3272 session_state_t new_state = STATE_DISCONNECT;
3274 if (VPPCOM_DEBUG > 1)
3276 clib_warning ("VCL<%d>: vpp handle 0x%llx, "
3277 "sid %u: Empty fifo with"
3278 " %s session state 0x%x (%s)! Setting state to "
3279 "0x%x (%s), returning %d (%s)",
3280 getpid (), session_index, vpp_handle,
3281 is_server ? "server" : "client",
3282 state, vppcom_session_state_str (state),
3283 new_state, vppcom_session_state_str (new_state),
3284 rv, vppcom_retval_str (rv));
3286 session->state = new_state;
3292 if (vcm->app_event_queue->cursize &&
3293 !pthread_mutex_trylock (&vcm->app_event_queue->mutex))
3295 u32 i, n_to_dequeue = vcm->app_event_queue->cursize;
3296 session_fifo_event_t e;
3298 for (i = 0; i < n_to_dequeue; i++)
3299 svm_queue_sub_raw (vcm->app_event_queue, (u8 *) & e);
3301 pthread_mutex_unlock (&vcm->app_event_queue->mutex);
3308 vppcom_session_write (uint32_t session_index, void *buf, size_t n)
3310 session_t *session = 0;
3311 svm_fifo_t *tx_fifo;
3313 session_fifo_event_t evt;
3319 session_state_t state;
3324 VCL_LOCK_AND_GET_SESSION (session_index, &session);
3326 if (PREDICT_FALSE (session->is_vep))
3328 clib_spinlock_unlock (&vcm->sessions_lockp);
3329 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
3330 "cannot write to an epoll session!",
3331 getpid (), session->vpp_handle, session_index);
3337 is_server = session->is_server;
3338 is_nonblocking = session->is_nonblocking;
3339 vpp_handle = session->vpp_handle;
3340 state = session->state;
3341 if (!(state & (SERVER_STATE_OPEN | CLIENT_STATE_OPEN)))
3343 rv = ((state == STATE_DISCONNECT) ? VPPCOM_ECONNRESET :
3346 clib_spinlock_unlock (&vcm->sessions_lockp);
3347 if (VPPCOM_DEBUG > 1)
3348 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
3349 "%s session is not open! state 0x%x (%s)",
3350 getpid (), vpp_handle, session_index,
3351 is_server ? "server" : "client", state,
3352 vppcom_session_state_str (state));
3356 tx_fifo = ((!session->is_cut_thru || is_server) ?
3357 session->server_tx_fifo : session->server_rx_fifo);
3358 fifo_str = ((!session->is_cut_thru || is_server) ?
3359 "server_tx_fifo" : "server_rx_fifo");
3360 clib_spinlock_unlock (&vcm->sessions_lockp);
3364 n_write = svm_fifo_enqueue_nowait (tx_fifo, n, (void *) buf);
3366 while (!is_nonblocking && (n_write <= 0));
3368 /* If event wasn't set, add one */
3369 if (!session->is_cut_thru && (n_write > 0) && svm_fifo_set_event (tx_fifo))
3371 /* Fabricate TX event, send to vpp */
3373 evt.event_type = FIFO_EVENT_APP_TX;
3375 VCL_LOCK_AND_GET_SESSION (session_index, &session);
3376 q = session->vpp_event_queue;
3378 svm_queue_add (q, (u8 *) & evt, 0 /* do wait for mutex */ );
3379 clib_spinlock_unlock (&vcm->sessions_lockp);
3380 if (VPPCOM_DEBUG > 1)
3381 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
3382 "added FIFO_EVENT_APP_TX to "
3383 "vpp_event_q %p, n_write %d", getpid (),
3384 vpp_handle, session_index, q, n_write);
3389 VCL_LOCK_AND_GET_SESSION (session_index, &session);
3391 poll_et = (((EPOLLET | EPOLLOUT) & session->vep.ev.events) ==
3392 (EPOLLET | EPOLLOUT));
3394 session->vep.et_mask |= EPOLLOUT;
3396 if (state == STATE_CLOSE_ON_EMPTY)
3398 session_state_t new_state = STATE_DISCONNECT;
3399 rv = VPPCOM_ECONNRESET;
3401 if (VPPCOM_DEBUG > 1)
3403 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
3404 "Empty fifo with %s session state 0x%x (%s)!"
3405 " Setting state to 0x%x (%s), returning %d (%s)",
3406 getpid (), vpp_handle, session_index,
3407 is_server ? "server" : "client",
3408 state, vppcom_session_state_str (state),
3409 new_state, vppcom_session_state_str (new_state),
3410 rv, vppcom_retval_str (rv));
3413 session->state = new_state;
3418 clib_spinlock_unlock (&vcm->sessions_lockp);
3423 if (VPPCOM_DEBUG > 2)
3426 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
3427 "FIFO-FULL %s (%p)", getpid (), vpp_handle,
3428 session_index, fifo_str, tx_fifo);
3430 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
3431 "wrote %d bytes to %s (%p)", getpid (), vpp_handle,
3432 session_index, n_write, fifo_str, tx_fifo);
3439 vppcom_session_write_ready (session_t * session, u32 session_index)
3441 svm_fifo_t *tx_fifo;
3446 u8 is_server = session->is_server;
3447 session_state_t state = session->state;
3449 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
3450 if (PREDICT_FALSE (session->is_vep))
3452 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
3453 "cannot write to an epoll session!",
3454 getpid (), session->vpp_handle, session_index);
3459 if (PREDICT_FALSE (session->is_listen))
3461 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
3462 "cannot write to a listen session!",
3463 getpid (), session->vpp_handle, session_index);
3468 if (!(state & (SERVER_STATE_OPEN | CLIENT_STATE_OPEN)))
3470 session_state_t state = session->state;
3472 rv = ((state == STATE_DISCONNECT) ? VPPCOM_ECONNRESET :
3475 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
3476 "%s session is not open! state 0x%x (%s), "
3477 "returning %d (%s)", getpid (), session->vpp_handle,
3478 session_index, is_server ? "server" : "client",
3479 state, vppcom_session_state_str (state),
3480 rv, vppcom_retval_str (rv));
3484 tx_fifo = ((!session->is_cut_thru || session->is_server) ?
3485 session->server_tx_fifo : session->server_rx_fifo);
3486 fifo_str = ((!session->is_cut_thru || session->is_server) ?
3487 "server_tx_fifo" : "server_rx_fifo");
3489 ready = svm_fifo_max_enqueue (tx_fifo);
3491 if (VPPCOM_DEBUG > 3)
3492 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
3493 "peek %s (%p), ready = %d", getpid (),
3494 session->vpp_handle, session_index,
3495 fifo_str, tx_fifo, ready);
3499 poll_et = (((EPOLLET | EPOLLOUT) & session->vep.ev.events) ==
3500 (EPOLLET | EPOLLOUT));
3502 session->vep.et_mask |= EPOLLOUT;
3504 if (state == STATE_CLOSE_ON_EMPTY)
3506 rv = VPPCOM_ECONNRESET;
3507 session_state_t new_state = STATE_DISCONNECT;
3509 if (VPPCOM_DEBUG > 1)
3511 clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: "
3512 "Empty fifo with %s session "
3513 "state 0x%x (%s)! Setting state to 0x%x (%s), "
3514 "returning %d (%s)", getpid (),
3515 session->vpp_handle, session_index,
3516 is_server ? "server" : "client",
3517 state, vppcom_session_state_str (state),
3518 new_state, vppcom_session_state_str (new_state),
3519 rv, vppcom_retval_str (rv));
3521 session->state = new_state;
3531 vppcom_select (unsigned long n_bits, unsigned long *read_map,
3532 unsigned long *write_map, unsigned long *except_map,
3533 double time_to_wait)
3536 session_t *session = 0;
3537 int rv, bits_set = 0;
3538 f64 timeout = clib_time_now (&vcm->clib_time) + time_to_wait;
3539 u32 minbits = clib_max (n_bits, BITS (uword));
3541 ASSERT (sizeof (clib_bitmap_t) == sizeof (long int));
3543 if (n_bits && read_map)
3545 clib_bitmap_validate (vcm->rd_bitmap, minbits);
3546 clib_memcpy (vcm->rd_bitmap, read_map,
3547 vec_len (vcm->rd_bitmap) * sizeof (clib_bitmap_t));
3548 memset (read_map, 0, vec_len (vcm->rd_bitmap) * sizeof (clib_bitmap_t));
3550 if (n_bits && write_map)
3552 clib_bitmap_validate (vcm->wr_bitmap, minbits);
3553 clib_memcpy (vcm->wr_bitmap, write_map,
3554 vec_len (vcm->wr_bitmap) * sizeof (clib_bitmap_t));
3555 memset (write_map, 0,
3556 vec_len (vcm->wr_bitmap) * sizeof (clib_bitmap_t));
3558 if (n_bits && except_map)
3560 clib_bitmap_validate (vcm->ex_bitmap, minbits);
3561 clib_memcpy (vcm->ex_bitmap, except_map,
3562 vec_len (vcm->ex_bitmap) * sizeof (clib_bitmap_t));
3563 memset (except_map, 0,
3564 vec_len (vcm->ex_bitmap) * sizeof (clib_bitmap_t));
3574 clib_bitmap_foreach (session_index, vcm->rd_bitmap,
3576 clib_spinlock_lock (&vcm->sessions_lockp);
3577 rv = vppcom_session_at_index (session_index, &session);
3580 clib_spinlock_unlock (&vcm->sessions_lockp);
3581 if (VPPCOM_DEBUG > 1)
3582 clib_warning ("VCL<%d>: session %d specified in "
3583 "read_map is closed.", getpid (),
3585 bits_set = VPPCOM_EBADFD;
3589 rv = vppcom_session_read_ready (session, session_index);
3590 clib_spinlock_unlock (&vcm->sessions_lockp);
3591 if (except_map && vcm->ex_bitmap &&
3592 clib_bitmap_get (vcm->ex_bitmap, session_index) &&
3595 clib_bitmap_set_no_check (except_map, session_index, 1);
3600 clib_bitmap_set_no_check (read_map, session_index, 1);
3608 clib_bitmap_foreach (session_index, vcm->wr_bitmap,
3610 clib_spinlock_lock (&vcm->sessions_lockp);
3611 rv = vppcom_session_at_index (session_index, &session);
3614 clib_spinlock_unlock (&vcm->sessions_lockp);
3615 if (VPPCOM_DEBUG > 0)
3616 clib_warning ("VCL<%d>: session %d specified in "
3617 "write_map is closed.", getpid (),
3619 bits_set = VPPCOM_EBADFD;
3623 rv = vppcom_session_write_ready (session, session_index);
3624 clib_spinlock_unlock (&vcm->sessions_lockp);
3625 if (write_map && (rv > 0))
3627 clib_bitmap_set_no_check (write_map, session_index, 1);
3635 clib_bitmap_foreach (session_index, vcm->ex_bitmap,
3637 clib_spinlock_lock (&vcm->sessions_lockp);
3638 rv = vppcom_session_at_index (session_index, &session);
3641 clib_spinlock_unlock (&vcm->sessions_lockp);
3642 if (VPPCOM_DEBUG > 1)
3643 clib_warning ("VCL<%d>: session %d specified in "
3644 "except_map is closed.", getpid (),
3646 bits_set = VPPCOM_EBADFD;
3650 rv = vppcom_session_read_ready (session, session_index);
3651 clib_spinlock_unlock (&vcm->sessions_lockp);
3654 clib_bitmap_set_no_check (except_map, session_index, 1);
3662 while ((time_to_wait == -1) || (clib_time_now (&vcm->clib_time) < timeout));
3669 vep_verify_epoll_chain (u32 vep_idx)
3672 vppcom_epoll_t *vep;
3676 if (VPPCOM_DEBUG <= 1)
3679 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
3680 rv = vppcom_session_at_index (vep_idx, &session);
3681 if (PREDICT_FALSE (rv))
3683 clib_warning ("VCL<%d>: ERROR: Invalid vep_idx (%u)!",
3684 getpid (), vep_idx);
3687 if (PREDICT_FALSE (!session->is_vep))
3689 clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!",
3690 getpid (), vep_idx);
3693 vep = &session->vep;
3694 clib_warning ("VCL<%d>: vep_idx (%u): Dumping epoll chain\n"
3697 " is_vep_session = %u\n"
3698 " next_sid = 0x%x (%u)\n"
3699 " wait_cont_idx = 0x%x (%u)\n"
3700 "}\n", getpid (), vep_idx,
3701 session->is_vep, session->is_vep_session,
3702 vep->next_sid, vep->next_sid,
3703 session->wait_cont_idx, session->wait_cont_idx);
3705 for (sid = vep->next_sid; sid != ~0; sid = vep->next_sid)
3707 rv = vppcom_session_at_index (sid, &session);
3708 if (PREDICT_FALSE (rv))
3710 clib_warning ("VCL<%d>: ERROR: Invalid sid (%u)!", getpid (), sid);
3713 if (PREDICT_FALSE (session->is_vep))
3714 clib_warning ("VCL<%d>: ERROR: sid (%u) is a vep!",
3715 getpid (), vep_idx);
3716 else if (PREDICT_FALSE (!session->is_vep_session))
3718 clib_warning ("VCL<%d>: ERROR: session (%u) "
3719 "is not a vep session!", getpid (), sid);
3722 vep = &session->vep;
3723 if (PREDICT_FALSE (vep->vep_idx != vep_idx))
3724 clib_warning ("VCL<%d>: ERROR: session (%u) vep_idx (%u) != "
3725 "vep_idx (%u)!", getpid (),
3726 sid, session->vep.vep_idx, vep_idx);
3727 if (session->is_vep_session)
3729 clib_warning ("vep_idx[%u]: sid 0x%x (%u)\n"
3731 " next_sid = 0x%x (%u)\n"
3732 " prev_sid = 0x%x (%u)\n"
3733 " vep_idx = 0x%x (%u)\n"
3734 " ev.events = 0x%x\n"
3735 " ev.data.u64 = 0x%llx\n"
3739 vep->next_sid, vep->next_sid,
3740 vep->prev_sid, vep->prev_sid,
3741 vep->vep_idx, vep->vep_idx,
3742 vep->ev.events, vep->ev.data.u64, vep->et_mask);
3747 clib_warning ("VCL<%d>: vep_idx (%u): Dump complete!\n",
3748 getpid (), vep_idx);
3752 vppcom_epoll_create (void)
3754 session_t *vep_session;
3757 clib_spinlock_lock (&vcm->sessions_lockp);
3758 pool_get (vcm->sessions, vep_session);
3759 memset (vep_session, 0, sizeof (*vep_session));
3760 vep_idx = vep_session - vcm->sessions;
3762 vep_session->is_vep = 1;
3763 vep_session->vep.vep_idx = ~0;
3764 vep_session->vep.next_sid = ~0;
3765 vep_session->vep.prev_sid = ~0;
3766 vep_session->wait_cont_idx = ~0;
3767 vep_session->vpp_handle = ~0;
3768 clib_spinlock_unlock (&vcm->sessions_lockp);
3770 if (VPPCOM_DEBUG > 0)
3771 clib_warning ("VCL<%d>: Created vep_idx %u / sid %u!",
3772 getpid (), vep_idx, vep_idx);
3774 if (VPPCOM_DEBUG > 0)
3776 vep_session->elog_track.name =
3777 (char *) format (0, "C:%d:VEP:%d%c", vcm->my_client_index,
3779 elog_track_register (&vcm->elog_main, &vep_session->elog_track);
3782 ELOG_TYPE_DECLARE (e) =
3784 .format = "created epoll session:%d",
3785 .format_args = "i4",
3793 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, vep_session->elog_track);
3802 vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index,
3803 struct epoll_event *event)
3805 session_t *vep_session;
3809 if (vep_idx == session_index)
3811 clib_warning ("VCL<%d>: ERROR: vep_idx == session_index (%u)!",
3812 getpid (), vep_idx);
3813 return VPPCOM_EINVAL;
3816 clib_spinlock_lock (&vcm->sessions_lockp);
3817 rv = vppcom_session_at_index (vep_idx, &vep_session);
3818 if (PREDICT_FALSE (rv))
3820 clib_warning ("VCL<%d>: ERROR: Invalid vep_idx (%u)!", vep_idx);
3823 if (PREDICT_FALSE (!vep_session->is_vep))
3825 clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!",
3826 getpid (), vep_idx);
3831 ASSERT (vep_session->vep.vep_idx == ~0);
3832 ASSERT (vep_session->vep.prev_sid == ~0);
3834 rv = vppcom_session_at_index (session_index, &session);
3835 if (PREDICT_FALSE (rv))
3837 if (VPPCOM_DEBUG > 0)
3838 clib_warning ("VCL<%d>: ERROR: Invalid session_index (%u)!",
3839 getpid (), session_index);
3842 if (PREDICT_FALSE (session->is_vep))
3844 clib_warning ("ERROR: session_index (%u) is a vep!", vep_idx);
3852 if (PREDICT_FALSE (!event))
3854 clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_ADD: NULL pointer to "
3855 "epoll_event structure!", getpid ());
3859 if (vep_session->vep.next_sid != ~0)
3861 session_t *next_session;
3862 rv = vppcom_session_at_index (vep_session->vep.next_sid,
3864 if (PREDICT_FALSE (rv))
3866 clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_ADD: Invalid "
3867 "vep.next_sid (%u) on vep_idx (%u)!",
3868 getpid (), vep_session->vep.next_sid, vep_idx);
3871 ASSERT (next_session->vep.prev_sid == vep_idx);
3872 next_session->vep.prev_sid = session_index;
3874 session->vep.next_sid = vep_session->vep.next_sid;
3875 session->vep.prev_sid = vep_idx;
3876 session->vep.vep_idx = vep_idx;
3877 session->vep.et_mask = VEP_DEFAULT_ET_MASK;
3878 session->vep.ev = *event;
3879 session->is_vep = 0;
3880 session->is_vep_session = 1;
3881 vep_session->vep.next_sid = session_index;
3882 if (VPPCOM_DEBUG > 1)
3883 clib_warning ("VCL<%d>: EPOLL_CTL_ADD: vep_idx %u, "
3884 "sid %u, events 0x%x, data 0x%llx!",
3885 getpid (), vep_idx, session_index,
3886 event->events, event->data.u64);
3887 if (VPPCOM_DEBUG > 0)
3890 ELOG_TYPE_DECLARE (e) =
3892 .format = "epoll_ctladd: events:%x data:%x",
3893 .format_args = "i4i4i8",
3901 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
3903 ed->events = event->events;
3904 ed->event_data = event->data.u64;
3910 if (PREDICT_FALSE (!event))
3912 clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_MOD: NULL pointer to "
3913 "epoll_event structure!", getpid ());
3917 else if (PREDICT_FALSE (!session->is_vep_session))
3919 clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_MOD: "
3920 "not a vep session!", getpid (), session_index);
3924 else if (PREDICT_FALSE (session->vep.vep_idx != vep_idx))
3926 clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_MOD: "
3927 "vep_idx (%u) != vep_idx (%u)!",
3928 getpid (), session_index,
3929 session->vep.vep_idx, vep_idx);
3933 session->vep.et_mask = VEP_DEFAULT_ET_MASK;
3934 session->vep.ev = *event;
3935 if (VPPCOM_DEBUG > 1)
3937 ("VCL<%d>: EPOLL_CTL_MOD: vep_idx %u, sid %u, events 0x%x,"
3938 " data 0x%llx!", getpid (), vep_idx, session_index, event->events,
3943 if (PREDICT_FALSE (!session->is_vep_session))
3945 clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_DEL: "
3946 "not a vep session!", getpid (), session_index);
3950 else if (PREDICT_FALSE (session->vep.vep_idx != vep_idx))
3952 clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_DEL: "
3953 "vep_idx (%u) != vep_idx (%u)!",
3954 getpid (), session_index,
3955 session->vep.vep_idx, vep_idx);
3960 vep_session->wait_cont_idx =
3961 (vep_session->wait_cont_idx == session_index) ?
3962 session->vep.next_sid : vep_session->wait_cont_idx;
3964 if (session->vep.prev_sid == vep_idx)
3965 vep_session->vep.next_sid = session->vep.next_sid;
3968 session_t *prev_session;
3969 rv = vppcom_session_at_index (session->vep.prev_sid, &prev_session);
3970 if (PREDICT_FALSE (rv))
3972 clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_DEL: Invalid "
3973 "vep.prev_sid (%u) on sid (%u)!",
3974 getpid (), session->vep.prev_sid, session_index);
3977 ASSERT (prev_session->vep.next_sid == session_index);
3978 prev_session->vep.next_sid = session->vep.next_sid;
3980 if (session->vep.next_sid != ~0)
3982 session_t *next_session;
3983 rv = vppcom_session_at_index (session->vep.next_sid, &next_session);
3984 if (PREDICT_FALSE (rv))
3986 clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_DEL: Invalid "
3987 "vep.next_sid (%u) on sid (%u)!",
3988 getpid (), session->vep.next_sid, session_index);
3991 ASSERT (next_session->vep.prev_sid == session_index);
3992 next_session->vep.prev_sid = session->vep.prev_sid;
3995 memset (&session->vep, 0, sizeof (session->vep));
3996 session->vep.next_sid = ~0;
3997 session->vep.prev_sid = ~0;
3998 session->vep.vep_idx = ~0;
3999 session->is_vep_session = 0;
4000 if (VPPCOM_DEBUG > 1)
4001 clib_warning ("VCL<%d>: EPOLL_CTL_DEL: vep_idx %u, sid %u!",
4002 getpid (), vep_idx, session_index);
4003 if (VPPCOM_DEBUG > 0)
4006 ELOG_TYPE_DECLARE (e) =
4008 .format = "epoll_ctldel: vep:%d",
4009 .format_args = "i4",
4016 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4024 clib_warning ("VCL<%d>: ERROR: Invalid operation (%d)!", getpid (), op);
4028 vep_verify_epoll_chain (vep_idx);
4031 clib_spinlock_unlock (&vcm->sessions_lockp);
4036 vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events,
4037 int maxevents, double wait_for_time)
4039 session_t *vep_session;
4041 f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time;
4042 u32 keep_trying = 1;
4044 u32 vep_next_sid, wait_cont_idx;
4047 if (PREDICT_FALSE (maxevents <= 0))
4049 clib_warning ("VCL<%d>: ERROR: Invalid maxevents (%d)!",
4050 getpid (), maxevents);
4051 return VPPCOM_EINVAL;
4053 memset (events, 0, sizeof (*events) * maxevents);
4055 VCL_LOCK_AND_GET_SESSION (vep_idx, &vep_session);
4056 vep_next_sid = vep_session->vep.next_sid;
4057 is_vep = vep_session->is_vep;
4058 wait_cont_idx = vep_session->wait_cont_idx;
4059 clib_spinlock_unlock (&vcm->sessions_lockp);
4061 if (PREDICT_FALSE (!is_vep))
4063 clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!",
4064 getpid (), vep_idx);
4068 if (PREDICT_FALSE (vep_next_sid == ~0))
4070 if (VPPCOM_DEBUG > 0)
4071 clib_warning ("VCL<%d>: WARNING: vep_idx (%u) is empty!",
4072 getpid (), vep_idx);
4073 if (VPPCOM_DEBUG > 0)
4076 ELOG_TYPE_DECLARE (e) =
4078 .format = "WRN: vep_idx:%d empty",
4079 .format_args = "i4",
4086 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, vep_session->elog_track);
4100 for (sid = (wait_cont_idx == ~0) ? vep_next_sid : wait_cont_idx;
4101 sid != ~0; sid = next_sid)
4103 u32 session_events, et_mask, clear_et_mask, session_vep_idx;
4104 u8 add_event, is_vep_session;
4106 u64 session_ev_data;
4108 VCL_LOCK_AND_GET_SESSION (sid, &session);
4109 next_sid = session->vep.next_sid;
4110 session_events = session->vep.ev.events;
4111 et_mask = session->vep.et_mask;
4112 is_vep = session->is_vep;
4113 is_vep_session = session->is_vep_session;
4114 session_vep_idx = session->vep.vep_idx;
4115 session_ev_data = session->vep.ev.data.u64;
4116 clib_spinlock_unlock (&vcm->sessions_lockp);
4118 if (PREDICT_FALSE (is_vep))
4120 if (VPPCOM_DEBUG > 0)
4121 clib_warning ("VCL<%d>: ERROR: sid (%u) is a vep!",
4122 getpid (), vep_idx);
4123 if (VPPCOM_DEBUG > 0)
4126 ELOG_TYPE_DECLARE (e) =
4128 .format = "ERR:vep_idx:%d is vep",
4129 .format_args = "i4",
4136 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4145 if (PREDICT_FALSE (!is_vep_session))
4147 if (VPPCOM_DEBUG > 0)
4148 clib_warning ("VCL<%d>: ERROR: session (%u) is not "
4149 "a vep session!", getpid (), sid);
4150 if (VPPCOM_DEBUG > 0)
4153 ELOG_TYPE_DECLARE (e) =
4155 .format = "ERR:SID:%d not vep",
4156 .format_args = "i4",
4163 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4172 if (PREDICT_FALSE (session_vep_idx != vep_idx))
4174 clib_warning ("VCL<%d>: ERROR: session (%u) "
4175 "vep_idx (%u) != vep_idx (%u)!",
4176 getpid (), sid, session->vep.vep_idx, vep_idx);
4181 add_event = clear_et_mask = 0;
4183 if (EPOLLIN & session_events)
4185 VCL_LOCK_AND_GET_SESSION (sid, &session);
4186 ready = vppcom_session_read_ready (session, sid);
4187 clib_spinlock_unlock (&vcm->sessions_lockp);
4188 if ((ready > 0) && (EPOLLIN & et_mask))
4191 events[num_ev].events |= EPOLLIN;
4192 if (((EPOLLET | EPOLLIN) & session_events) ==
4193 (EPOLLET | EPOLLIN))
4194 clear_et_mask |= EPOLLIN;
4201 case VPPCOM_ECONNRESET:
4202 events[num_ev].events |= EPOLLHUP | EPOLLRDHUP;
4206 events[num_ev].events |= EPOLLERR;
4212 if (EPOLLOUT & session_events)
4214 VCL_LOCK_AND_GET_SESSION (sid, &session);
4215 ready = vppcom_session_write_ready (session, sid);
4216 clib_spinlock_unlock (&vcm->sessions_lockp);
4217 if ((ready > 0) && (EPOLLOUT & et_mask))
4220 events[num_ev].events |= EPOLLOUT;
4221 if (((EPOLLET | EPOLLOUT) & session_events) ==
4222 (EPOLLET | EPOLLOUT))
4223 clear_et_mask |= EPOLLOUT;
4230 case VPPCOM_ECONNRESET:
4231 events[num_ev].events |= EPOLLHUP;
4235 events[num_ev].events |= EPOLLERR;
4243 events[num_ev].data.u64 = session_ev_data;
4244 if (EPOLLONESHOT & session_events)
4246 VCL_LOCK_AND_GET_SESSION (sid, &session);
4247 session->vep.ev.events = 0;
4248 clib_spinlock_unlock (&vcm->sessions_lockp);
4251 if (num_ev == maxevents)
4253 VCL_LOCK_AND_GET_SESSION (vep_idx, &vep_session);
4254 vep_session->wait_cont_idx = next_sid;
4255 clib_spinlock_unlock (&vcm->sessions_lockp);
4259 if (wait_cont_idx != ~0)
4262 next_sid = vep_next_sid;
4263 else if (next_sid == wait_cont_idx)
4267 if (wait_for_time != -1)
4268 keep_trying = (clib_time_now (&vcm->clib_time) <= timeout) ? 1 : 0;
4270 while ((num_ev == 0) && keep_trying);
4272 if (wait_cont_idx != ~0)
4274 VCL_LOCK_AND_GET_SESSION (vep_idx, &vep_session);
4275 vep_session->wait_cont_idx = ~0;
4276 clib_spinlock_unlock (&vcm->sessions_lockp);
4279 return (rv != VPPCOM_OK) ? rv : num_ev;
4283 vppcom_session_attr (uint32_t session_index, uint32_t op,
4284 void *buffer, uint32_t * buflen)
4288 u32 *flags = buffer;
4289 vppcom_endpt_t *ep = buffer;
4291 VCL_LOCK_AND_GET_SESSION (session_index, &session);
4294 case VPPCOM_ATTR_GET_NREAD:
4295 rv = vppcom_session_read_ready (session, session_index);
4296 if (VPPCOM_DEBUG > 2)
4297 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_NREAD: sid %u, nread = %d",
4299 if (VPPCOM_DEBUG > 0)
4302 ELOG_TYPE_DECLARE (e) =
4304 .format = "VPPCOM_ATTR_GET_NREAD: nread=%d",
4305 .format_args = "i4",
4312 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4320 case VPPCOM_ATTR_GET_NWRITE:
4321 rv = vppcom_session_write_ready (session, session_index);
4322 if (VPPCOM_DEBUG > 2)
4323 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_NWRITE: sid %u, nwrite = %d",
4324 getpid (), session_index, rv);
4325 if (VPPCOM_DEBUG > 0)
4328 ELOG_TYPE_DECLARE (e) =
4330 .format = "VPPCOM_ATTR_GET_NWRITE: nwrite=%d",
4331 .format_args = "i4",
4338 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4345 case VPPCOM_ATTR_GET_FLAGS:
4346 if (PREDICT_TRUE (buffer && buflen && (*buflen >= sizeof (*flags))))
4348 *flags = O_RDWR | ((session->is_nonblocking) ? O_NONBLOCK : 0);
4349 *buflen = sizeof (*flags);
4350 if (VPPCOM_DEBUG > 2)
4351 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_FLAGS: sid %u, "
4352 "flags = 0x%08x, is_nonblocking = %u", getpid (),
4353 session_index, *flags, session->is_nonblocking);
4354 if (VPPCOM_DEBUG > 0)
4357 ELOG_TYPE_DECLARE (e) =
4359 .format = "VPPCOM_ATTR_GET_FLAGS: flags=%x is_nonblk=%d",
4360 .format_args = "i4i4",
4368 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4371 ed->is_nonblk = session->is_nonblocking;
4380 case VPPCOM_ATTR_SET_FLAGS:
4381 if (PREDICT_TRUE (buffer && buflen && (*buflen == sizeof (*flags))))
4383 session->is_nonblocking = (*flags & O_NONBLOCK) ? 1 : 0;
4384 if (VPPCOM_DEBUG > 2)
4385 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_FLAGS: sid %u, "
4386 "flags = 0x%08x, is_nonblocking = %u",
4387 getpid (), session_index, *flags,
4388 session->is_nonblocking);
4389 if (VPPCOM_DEBUG > 0)
4392 ELOG_TYPE_DECLARE (e) =
4394 .format = "VPPCOM_ATTR_SET_FLAGS: flags=%x is_nonblk=%d",
4395 .format_args = "i4i4",
4403 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4406 ed->is_nonblk = session->is_nonblocking;
4414 case VPPCOM_ATTR_GET_PEER_ADDR:
4415 if (PREDICT_TRUE (buffer && buflen &&
4416 (*buflen >= sizeof (*ep)) && ep->ip))
4418 ep->is_ip4 = session->peer_addr.is_ip4;
4419 ep->port = session->peer_port;
4420 if (session->peer_addr.is_ip4)
4421 clib_memcpy (ep->ip, &session->peer_addr.ip46.ip4,
4422 sizeof (ip4_address_t));
4424 clib_memcpy (ep->ip, &session->peer_addr.ip46.ip6,
4425 sizeof (ip6_address_t));
4426 *buflen = sizeof (*ep);
4427 if (VPPCOM_DEBUG > 1)
4428 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_PEER_ADDR: sid %u, "
4429 "is_ip4 = %u, addr = %U, port %u", getpid (),
4430 session_index, ep->is_ip4, format_ip46_address,
4431 &session->peer_addr.ip46, ep->is_ip4,
4432 clib_net_to_host_u16 (ep->port));
4433 if (VPPCOM_DEBUG > 0)
4438 ELOG_TYPE_DECLARE (e) =
4440 .format = "VPPCOM_ATTR_GET_PEER_ADDR: addr:%d.%d.%d.%d:%d",
4441 .format_args = "i1i1i1i1i2",
4443 CLIB_PACKED (struct {
4448 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4450 ed->addr[0] = session->peer_addr.ip46.ip4.as_u8[0];
4451 ed->addr[1] = session->peer_addr.ip46.ip4.as_u8[1];
4452 ed->addr[2] = session->peer_addr.ip46.ip4.as_u8[2];
4453 ed->addr[3] = session->peer_addr.ip46.ip4.as_u8[3];
4454 ed->port = clib_net_to_host_u16 (session->peer_port);
4460 ELOG_TYPE_DECLARE (e) =
4462 .format = "VPPCOM_ATTR_GET_PEER_ADDR: addr:IP6:%d",
4463 .format_args = "i2",
4465 CLIB_PACKED (struct {
4469 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4471 ed->port = clib_net_to_host_u16 (session->peer_port);
4480 case VPPCOM_ATTR_GET_LCL_ADDR:
4481 if (PREDICT_TRUE (buffer && buflen &&
4482 (*buflen >= sizeof (*ep)) && ep->ip))
4484 ep->is_ip4 = session->lcl_addr.is_ip4;
4485 ep->port = session->lcl_port;
4486 if (session->lcl_addr.is_ip4)
4487 clib_memcpy (ep->ip, &session->lcl_addr.ip46.ip4,
4488 sizeof (ip4_address_t));
4490 clib_memcpy (ep->ip, &session->lcl_addr.ip46.ip6,
4491 sizeof (ip6_address_t));
4492 *buflen = sizeof (*ep);
4493 if (VPPCOM_DEBUG > 1)
4494 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_LCL_ADDR: sid %u, "
4495 "is_ip4 = %u, addr = %U port %d", getpid (),
4496 session_index, ep->is_ip4, format_ip46_address,
4497 &session->lcl_addr.ip46, ep->is_ip4,
4498 clib_net_to_host_u16 (ep->port));
4499 if (VPPCOM_DEBUG > 0)
4504 ELOG_TYPE_DECLARE (e) =
4506 .format = "VPPCOM_ATTR_GET_LCL_ADDR: addr:%d.%d.%d.%d:%d",
4507 .format_args = "i1i1i1i1i2",
4509 CLIB_PACKED (struct {
4514 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4516 ed->addr[0] = session->lcl_addr.ip46.ip4.as_u8[0];
4517 ed->addr[1] = session->lcl_addr.ip46.ip4.as_u8[1];
4518 ed->addr[2] = session->lcl_addr.ip46.ip4.as_u8[2];
4519 ed->addr[3] = session->lcl_addr.ip46.ip4.as_u8[3];
4520 ed->port = clib_net_to_host_u16 (session->peer_port);
4526 ELOG_TYPE_DECLARE (e) =
4528 .format = "VPPCOM_ATTR_GET_LCL_ADDR: addr:IP6:%d",
4529 .format_args = "i2",
4531 CLIB_PACKED (struct {
4535 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4537 ed->port = clib_net_to_host_u16 (session->peer_port);
4546 case VPPCOM_ATTR_GET_LIBC_EPFD:
4547 rv = session->libc_epfd;
4548 if (VPPCOM_DEBUG > 2)
4549 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_LIBC_EPFD: libc_epfd %d",
4551 if (VPPCOM_DEBUG > 0)
4554 ELOG_TYPE_DECLARE (e) =
4556 .format = "VPPCOM_ATTR_GET_LIBC_EPFD: libc_epfd=%d",
4557 .format_args = "i4",
4559 CLIB_PACKED (struct {
4563 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4564 ed->data = session->libc_epfd;
4570 case VPPCOM_ATTR_SET_LIBC_EPFD:
4571 if (PREDICT_TRUE (buffer && buflen &&
4572 (*buflen == sizeof (session->libc_epfd))))
4574 session->libc_epfd = *(int *) buffer;
4575 *buflen = sizeof (session->libc_epfd);
4577 if (VPPCOM_DEBUG > 2)
4578 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_LIBC_EPFD: libc_epfd %d, "
4579 "buflen %d", getpid (), session->libc_epfd,
4581 if (VPPCOM_DEBUG > 0)
4584 ELOG_TYPE_DECLARE (e) =
4586 .format = "VPPCOM_ATTR_SET_LIBC_EPFD: libc_epfd=%s%d buflen=%d",
4587 .format_args = "t1i4i4",
4588 .n_enum_strings = 2,
4589 .enum_strings = {"", "-",},
4591 CLIB_PACKED (struct {
4596 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4598 ed->sign = (session->libc_epfd < 0);
4599 ed->data[0] = abs(session->libc_epfd);
4600 ed->data[1] = *buflen;
4608 case VPPCOM_ATTR_GET_PROTOCOL:
4609 if (buffer && buflen && (*buflen >= sizeof (int)))
4611 *(int *) buffer = session->proto;
4612 *buflen = sizeof (int);
4614 if (VPPCOM_DEBUG > 2)
4615 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_PROTOCOL: %d (%s), "
4616 "buflen %d", getpid (), *(int *) buffer,
4617 *(int *) buffer ? "UDP" : "TCP", *buflen);
4618 if (VPPCOM_DEBUG > 0)
4621 ELOG_TYPE_DECLARE (e) =
4623 .format = "VPPCOM_ATTR_GET_PROTOCOL: %s buflen=%d",
4624 .format_args = "t1i4",
4625 .n_enum_strings = 2,
4626 .enum_strings = {"TCP", "UDP",},
4629 CLIB_PACKED (struct {
4634 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4635 ed->proto = session->proto;
4636 ed->buflen = *(int *) buffer;
4644 case VPPCOM_ATTR_GET_LISTEN:
4645 if (buffer && buflen && (*buflen >= sizeof (int)))
4647 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
4648 VCL_SESS_ATTR_LISTEN);
4649 *buflen = sizeof (int);
4651 if (VPPCOM_DEBUG > 2)
4652 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_LISTEN: %d, "
4653 "buflen %d", getpid (), *(int *) buffer, *buflen);
4654 if (VPPCOM_DEBUG > 0)
4657 ELOG_TYPE_DECLARE (e) =
4659 .format = "VPPCOM_ATTR_GET_LISTEN: %d buflen=%d",
4660 .format_args = "i4i4",
4667 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4668 ed->data[0] = *(int *) buffer;
4669 ed->data[1] = *buflen;
4677 case VPPCOM_ATTR_GET_ERROR:
4678 if (buffer && buflen && (*buflen >= sizeof (int)))
4680 *(int *) buffer = 0;
4681 *buflen = sizeof (int);
4683 if (VPPCOM_DEBUG > 2)
4684 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_ERROR: %d, "
4685 "buflen %d, #VPP-TBD#", getpid (),
4686 *(int *) buffer, *buflen);
4687 if (VPPCOM_DEBUG > 0)
4690 ELOG_TYPE_DECLARE (e) =
4692 .format = "VPPCOM_ATTR_GET_ERROR: %d buflen=%d",
4693 .format_args = "i4i4",
4700 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4701 ed->data[0] = *(int *) buffer;
4702 ed->data[1] = *buflen;
4710 case VPPCOM_ATTR_GET_TX_FIFO_LEN:
4711 if (buffer && buflen && (*buflen >= sizeof (u32)))
4713 svm_fifo_t *tx_fifo;
4715 tx_fifo = ((!session->is_cut_thru || session->is_server) ?
4716 session->server_tx_fifo : session->server_rx_fifo);
4719 *(size_t *) buffer = (session->sndbuf_size ? session->sndbuf_size :
4720 tx_fifo ? tx_fifo->nitems :
4721 vcm->cfg.tx_fifo_size);
4722 *buflen = sizeof (u32);
4724 if (VPPCOM_DEBUG > 2)
4725 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_TX_FIFO_LEN: %u (0x%x), "
4726 "buflen %d, #VPP-TBD#", getpid (),
4727 *(size_t *) buffer, *(size_t *) buffer, *buflen);
4728 if (VPPCOM_DEBUG > 0)
4731 ELOG_TYPE_DECLARE (e) =
4733 .format = "VPPCOM_ATTR_GET_TX_FIFO_LEN: 0x%x buflen=%d",
4734 .format_args = "i4i4",
4741 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4742 ed->data[0] = *(size_t *) buffer;
4743 ed->data[1] = *buflen;
4751 case VPPCOM_ATTR_SET_TX_FIFO_LEN:
4752 if (buffer && buflen && (*buflen == sizeof (u32)))
4755 session->sndbuf_size = *(u32 *) buffer;
4756 if (VPPCOM_DEBUG > 2)
4757 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_TX_FIFO_LEN: %u (0x%x), "
4758 "buflen %d, #VPP-TBD#", getpid (),
4759 session->sndbuf_size, session->sndbuf_size,
4761 if (VPPCOM_DEBUG > 0)
4764 ELOG_TYPE_DECLARE (e) =
4766 .format = "VPPCOM_ATTR_SET_TX_FIFO_LEN: 0x%x buflen=%d",
4767 .format_args = "i4i4",
4774 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4775 ed->data[0] = session->sndbuf_size;
4776 ed->data[1] = *buflen;
4784 case VPPCOM_ATTR_GET_RX_FIFO_LEN:
4785 if (buffer && buflen && (*buflen >= sizeof (u32)))
4787 svm_fifo_t *rx_fifo;
4789 rx_fifo = ((!session->is_cut_thru || session->is_server) ?
4790 session->server_rx_fifo : session->server_tx_fifo);
4793 *(size_t *) buffer = (session->rcvbuf_size ? session->rcvbuf_size :
4794 rx_fifo ? rx_fifo->nitems :
4795 vcm->cfg.rx_fifo_size);
4796 *buflen = sizeof (u32);
4798 if (VPPCOM_DEBUG > 2)
4799 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_RX_FIFO_LEN: %u (0x%x), "
4800 "buflen %d, #VPP-TBD#", getpid (),
4801 *(size_t *) buffer, *(size_t *) buffer, *buflen);
4802 if (VPPCOM_DEBUG > 0)
4805 ELOG_TYPE_DECLARE (e) =
4807 .format = "VPPCOM_ATTR_GET_RX_FIFO_LEN: 0x%x buflen=%d",
4808 .format_args = "i4i4",
4815 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4816 ed->data[0] = *(size_t *) buffer;
4817 ed->data[1] = *buflen;
4825 case VPPCOM_ATTR_SET_RX_FIFO_LEN:
4826 if (buffer && buflen && (*buflen == sizeof (u32)))
4829 session->rcvbuf_size = *(u32 *) buffer;
4830 if (VPPCOM_DEBUG > 2)
4831 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_RX_FIFO_LEN: %u (0x%x), "
4832 "buflen %d, #VPP-TBD#", getpid (),
4833 session->sndbuf_size, session->sndbuf_size,
4835 if (VPPCOM_DEBUG > 0)
4838 ELOG_TYPE_DECLARE (e) =
4840 .format = "VPPCOM_ATTR_SET_RX_FIFO_LEN: 0x%x buflen=%d",
4841 .format_args = "i4i4",
4848 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4849 ed->data[0] = session->sndbuf_size;
4850 ed->data[1] = *buflen;
4858 case VPPCOM_ATTR_GET_REUSEADDR:
4859 if (buffer && buflen && (*buflen >= sizeof (int)))
4862 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
4863 VCL_SESS_ATTR_REUSEADDR);
4864 *buflen = sizeof (int);
4866 if (VPPCOM_DEBUG > 2)
4867 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_REUSEADDR: %d, "
4868 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
4870 if (VPPCOM_DEBUG > 0)
4873 ELOG_TYPE_DECLARE (e) =
4875 .format = "VPPCOM_ATTR_GET_REUSEADDR: %d buflen=%d",
4876 .format_args = "i4i4",
4883 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4884 ed->data[0] = *(int *) buffer;
4885 ed->data[1] = *buflen;
4893 case VPPCOM_ATTR_SET_REUSEADDR:
4894 if (buffer && buflen && (*buflen == sizeof (int)) &&
4895 !VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_LISTEN))
4898 if (*(int *) buffer)
4899 VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_REUSEADDR);
4901 VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_REUSEADDR);
4903 if (VPPCOM_DEBUG > 2)
4904 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_REUSEADDR: %d, "
4905 "buflen %d, #VPP-TBD#", getpid (),
4906 VCL_SESS_ATTR_TEST (session->attr,
4907 VCL_SESS_ATTR_REUSEADDR),
4909 if (VPPCOM_DEBUG > 0)
4912 ELOG_TYPE_DECLARE (e) =
4914 .format = "VPPCOM_ATTR_SET_REUSEADDR: %d buflen=%d",
4915 .format_args = "i4i4",
4922 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4923 ed->data[0] = VCL_SESS_ATTR_TEST (session->attr,
4924 VCL_SESS_ATTR_REUSEADDR);
4925 ed->data[1] = *buflen;
4933 case VPPCOM_ATTR_GET_REUSEPORT:
4934 if (buffer && buflen && (*buflen >= sizeof (int)))
4937 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
4938 VCL_SESS_ATTR_REUSEPORT);
4939 *buflen = sizeof (int);
4941 if (VPPCOM_DEBUG > 2)
4942 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_REUSEPORT: %d, "
4943 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
4945 if (VPPCOM_DEBUG > 0)
4948 ELOG_TYPE_DECLARE (e) =
4950 .format = "VPPCOM_ATTR_GET_REUSEPORT: %d buflen=%d",
4951 .format_args = "i4i4",
4958 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4959 ed->data[0] = *(int *) buffer;
4960 ed->data[1] = *buflen;
4968 case VPPCOM_ATTR_SET_REUSEPORT:
4969 if (buffer && buflen && (*buflen == sizeof (int)) &&
4970 !VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_LISTEN))
4973 if (*(int *) buffer)
4974 VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_REUSEPORT);
4976 VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_REUSEPORT);
4978 if (VPPCOM_DEBUG > 2)
4979 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_REUSEPORT: %d, "
4980 "buflen %d, #VPP-TBD#", getpid (),
4981 VCL_SESS_ATTR_TEST (session->attr,
4982 VCL_SESS_ATTR_REUSEPORT),
4984 if (VPPCOM_DEBUG > 0)
4987 ELOG_TYPE_DECLARE (e) =
4989 .format = "VPPCOM_ATTR_SET_REUSEPORT: %d buflen=%d",
4990 .format_args = "i4i4",
4997 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
4998 ed->data[0] = VCL_SESS_ATTR_TEST (session->attr,
4999 VCL_SESS_ATTR_REUSEPORT);
5000 ed->data[1] = *buflen;
5008 case VPPCOM_ATTR_GET_BROADCAST:
5009 if (buffer && buflen && (*buflen >= sizeof (int)))
5012 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
5013 VCL_SESS_ATTR_BROADCAST);
5014 *buflen = sizeof (int);
5016 if (VPPCOM_DEBUG > 2)
5017 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_BROADCAST: %d, "
5018 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
5020 if (VPPCOM_DEBUG > 0)
5023 ELOG_TYPE_DECLARE (e) =
5025 .format = "VPPCOM_ATTR_GET_BROADCAST: %d buflen=%d",
5026 .format_args = "i4i4",
5033 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5034 ed->data[0] = *(int *) buffer;
5035 ed->data[1] = *buflen;
5043 case VPPCOM_ATTR_SET_BROADCAST:
5044 if (buffer && buflen && (*buflen == sizeof (int)))
5047 if (*(int *) buffer)
5048 VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_BROADCAST);
5050 VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_BROADCAST);
5052 if (VPPCOM_DEBUG > 2)
5053 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_BROADCAST: %d, "
5054 "buflen %d, #VPP-TBD#", getpid (),
5055 VCL_SESS_ATTR_TEST (session->attr,
5056 VCL_SESS_ATTR_BROADCAST),
5058 if (VPPCOM_DEBUG > 0)
5061 ELOG_TYPE_DECLARE (e) =
5063 .format = "VPPCOM_ATTR_SET_BROADCAST: %d buflen=%d",
5064 .format_args = "i4i4",
5071 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5072 ed->data[0] = VCL_SESS_ATTR_TEST (session->attr,
5073 VCL_SESS_ATTR_BROADCAST);
5074 ed->data[1] = *buflen;
5082 case VPPCOM_ATTR_GET_V6ONLY:
5083 if (buffer && buflen && (*buflen >= sizeof (int)))
5086 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
5087 VCL_SESS_ATTR_V6ONLY);
5088 *buflen = sizeof (int);
5090 if (VPPCOM_DEBUG > 2)
5091 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_V6ONLY: %d, "
5092 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
5094 if (VPPCOM_DEBUG > 0)
5097 ELOG_TYPE_DECLARE (e) =
5099 .format = "VPPCOM_ATTR_GET_V6ONLY: %d buflen=%d",
5100 .format_args = "i4i4",
5107 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5108 ed->data[0] = *(int *) buffer;
5109 ed->data[1] = *buflen;
5117 case VPPCOM_ATTR_SET_V6ONLY:
5118 if (buffer && buflen && (*buflen == sizeof (int)))
5121 if (*(int *) buffer)
5122 VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_V6ONLY);
5124 VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_V6ONLY);
5126 if (VPPCOM_DEBUG > 2)
5127 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_V6ONLY: %d, "
5128 "buflen %d, #VPP-TBD#", getpid (),
5129 VCL_SESS_ATTR_TEST (session->attr,
5130 VCL_SESS_ATTR_V6ONLY), *buflen);
5131 if (VPPCOM_DEBUG > 0)
5134 ELOG_TYPE_DECLARE (e) =
5136 .format = "VPPCOM_ATTR_SET_V6ONLY: %d buflen=%d",
5137 .format_args = "i4i4",
5144 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5145 ed->data[0] = VCL_SESS_ATTR_TEST (session->attr,
5146 VCL_SESS_ATTR_V6ONLY);
5147 ed->data[1] = *buflen;
5155 case VPPCOM_ATTR_GET_KEEPALIVE:
5156 if (buffer && buflen && (*buflen >= sizeof (int)))
5159 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
5160 VCL_SESS_ATTR_KEEPALIVE);
5161 *buflen = sizeof (int);
5163 if (VPPCOM_DEBUG > 2)
5164 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_KEEPALIVE: %d, "
5165 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
5167 if (VPPCOM_DEBUG > 0)
5170 ELOG_TYPE_DECLARE (e) =
5172 .format = "VPPCOM_ATTR_GET_KEEPALIVE: %d buflen=%d",
5173 .format_args = "i4i4",
5180 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5181 ed->data[0] = *(int *) buffer;
5182 ed->data[1] = *buflen;
5190 case VPPCOM_ATTR_SET_KEEPALIVE:
5191 if (buffer && buflen && (*buflen == sizeof (int)))
5194 if (*(int *) buffer)
5195 VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_KEEPALIVE);
5197 VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_KEEPALIVE);
5199 if (VPPCOM_DEBUG > 2)
5200 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_KEEPALIVE: %d, "
5201 "buflen %d, #VPP-TBD#", getpid (),
5202 VCL_SESS_ATTR_TEST (session->attr,
5203 VCL_SESS_ATTR_KEEPALIVE),
5205 if (VPPCOM_DEBUG > 0)
5208 ELOG_TYPE_DECLARE (e) =
5210 .format = "VPPCOM_ATTR_SET_KEEPALIVE: %d buflen=%d",
5211 .format_args = "i4i4",
5218 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5219 ed->data[0] = VCL_SESS_ATTR_TEST (session->attr,
5220 VCL_SESS_ATTR_KEEPALIVE);
5221 ed->data[1] = *buflen;
5229 case VPPCOM_ATTR_GET_TCP_NODELAY:
5230 if (buffer && buflen && (*buflen >= sizeof (int)))
5233 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
5234 VCL_SESS_ATTR_TCP_NODELAY);
5235 *buflen = sizeof (int);
5237 if (VPPCOM_DEBUG > 2)
5238 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_TCP_NODELAY: %d, "
5239 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
5241 if (VPPCOM_DEBUG > 0)
5244 ELOG_TYPE_DECLARE (e) =
5246 .format = "VPPCOM_ATTR_GET_TCP_NODELAY: %d buflen=%d",
5247 .format_args = "i4i4",
5254 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5255 ed->data[0] = *(int *) buffer;
5256 ed->data[1] = *buflen;
5264 case VPPCOM_ATTR_SET_TCP_NODELAY:
5265 if (buffer && buflen && (*buflen == sizeof (int)))
5268 if (*(int *) buffer)
5269 VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_NODELAY);
5271 VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_NODELAY);
5273 if (VPPCOM_DEBUG > 2)
5274 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_TCP_NODELAY: %d, "
5275 "buflen %d, #VPP-TBD#", getpid (),
5276 VCL_SESS_ATTR_TEST (session->attr,
5277 VCL_SESS_ATTR_TCP_NODELAY),
5279 if (VPPCOM_DEBUG > 0)
5282 ELOG_TYPE_DECLARE (e) =
5284 .format = "VPPCOM_ATTR_SET_TCP_NODELAY: %d buflen=%d",
5285 .format_args = "i4i4",
5292 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5293 ed->data[0] = VCL_SESS_ATTR_TEST (session->attr,
5294 VCL_SESS_ATTR_TCP_NODELAY);
5295 ed->data[1] = *buflen;
5303 case VPPCOM_ATTR_GET_TCP_KEEPIDLE:
5304 if (buffer && buflen && (*buflen >= sizeof (int)))
5307 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
5308 VCL_SESS_ATTR_TCP_KEEPIDLE);
5309 *buflen = sizeof (int);
5311 if (VPPCOM_DEBUG > 2)
5312 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_TCP_KEEPIDLE: %d, "
5313 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
5315 if (VPPCOM_DEBUG > 0)
5318 ELOG_TYPE_DECLARE (e) =
5320 .format = "VPPCOM_ATTR_GET_TCP_KEEPIDLE: %d buflen=%d",
5321 .format_args = "i4i4",
5328 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5329 ed->data[0] = *(int *) buffer;
5330 ed->data[1] = *buflen;
5338 case VPPCOM_ATTR_SET_TCP_KEEPIDLE:
5339 if (buffer && buflen && (*buflen == sizeof (int)))
5342 if (*(int *) buffer)
5343 VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_KEEPIDLE);
5345 VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_KEEPIDLE);
5347 if (VPPCOM_DEBUG > 2)
5348 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_TCP_KEEPIDLE: %d, "
5349 "buflen %d, #VPP-TBD#", getpid (),
5350 VCL_SESS_ATTR_TEST (session->attr,
5351 VCL_SESS_ATTR_TCP_KEEPIDLE),
5353 if (VPPCOM_DEBUG > 0)
5356 ELOG_TYPE_DECLARE (e) =
5358 .format = "VPPCOM_ATTR_SET_TCP_KEEPIDLE: %d buflen=%d",
5359 .format_args = "i4i4",
5366 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5367 ed->data[0] = VCL_SESS_ATTR_TEST (session->attr,
5368 VCL_SESS_ATTR_TCP_KEEPIDLE);
5369 ed->data[1] = *buflen;
5377 case VPPCOM_ATTR_GET_TCP_KEEPINTVL:
5378 if (buffer && buflen && (*buflen >= sizeof (int)))
5381 *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr,
5382 VCL_SESS_ATTR_TCP_KEEPINTVL);
5383 *buflen = sizeof (int);
5385 if (VPPCOM_DEBUG > 2)
5386 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_TCP_KEEPINTVL: %d, "
5387 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
5389 if (VPPCOM_DEBUG > 0)
5392 ELOG_TYPE_DECLARE (e) =
5394 .format = "VPPCOM_ATTR_GET_TCP_KEEPIDLE: %d buflen=%d",
5395 .format_args = "i4i4",
5402 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5403 ed->data[0] = *(int *) buffer;
5404 ed->data[1] = *buflen;
5412 case VPPCOM_ATTR_SET_TCP_KEEPINTVL:
5413 if (buffer && buflen && (*buflen == sizeof (int)))
5416 if (*(int *) buffer)
5417 VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_KEEPINTVL);
5419 VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_KEEPINTVL);
5421 if (VPPCOM_DEBUG > 2)
5422 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_TCP_KEEPINTVL: %d, "
5423 "buflen %d, #VPP-TBD#", getpid (),
5424 VCL_SESS_ATTR_TEST (session->attr,
5425 VCL_SESS_ATTR_TCP_KEEPINTVL),
5427 if (VPPCOM_DEBUG > 0)
5430 ELOG_TYPE_DECLARE (e) =
5432 .format = "VPPCOM_ATTR_SET_TCP_KEEPINTVL: %d buflen=%d",
5433 .format_args = "i4i4",
5440 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5441 ed->data[0] = VCL_SESS_ATTR_TEST (session->attr,
5442 VCL_SESS_ATTR_TCP_KEEPINTVL);
5443 ed->data[1] = *buflen;
5451 case VPPCOM_ATTR_GET_TCP_USER_MSS:
5452 if (buffer && buflen && (*buflen >= sizeof (u32)))
5455 *(u32 *) buffer = session->user_mss;
5456 *buflen = sizeof (int);
5458 if (VPPCOM_DEBUG > 2)
5459 clib_warning ("VCL<%d>: VPPCOM_ATTR_GET_TCP_USER_MSS: %d, "
5460 "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer,
5462 if (VPPCOM_DEBUG > 0)
5465 ELOG_TYPE_DECLARE (e) =
5467 .format = "VPPCOM_ATTR_GET_TCP_USER_MSS: %d buflen=%d",
5468 .format_args = "i4i4",
5475 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5476 ed->data[0] = *(int *) buffer;
5477 ed->data[1] = *buflen;
5485 case VPPCOM_ATTR_SET_TCP_USER_MSS:
5486 if (buffer && buflen && (*buflen == sizeof (u32)))
5489 session->user_mss = *(u32 *) buffer;
5491 if (VPPCOM_DEBUG > 2)
5492 clib_warning ("VCL<%d>: VPPCOM_ATTR_SET_TCP_USER_MSS: %u, "
5493 "buflen %d, #VPP-TBD#", getpid (),
5494 session->user_mss, *buflen);
5495 if (VPPCOM_DEBUG > 0)
5498 ELOG_TYPE_DECLARE (e) =
5500 .format = "VPPCOM_ATTR_SET_TCP_USER_MSS: %d buflen=%d",
5501 .format_args = "i4i4",
5508 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, session->elog_track);
5509 ed->data[0] = session->user_mss;
5510 ed->data[1] = *buflen;
5524 clib_spinlock_unlock (&vcm->sessions_lockp);
5529 vppcom_session_recvfrom (uint32_t session_index, void *buffer,
5530 uint32_t buflen, int flags, vppcom_endpt_t * ep)
5533 session_t *session = 0;
5537 clib_spinlock_lock (&vcm->sessions_lockp);
5538 rv = vppcom_session_at_index (session_index, &session);
5539 if (PREDICT_FALSE (rv))
5541 clib_spinlock_unlock (&vcm->sessions_lockp);
5542 if (VPPCOM_DEBUG > 0)
5543 clib_warning ("VCL<%d>: invalid session, "
5544 "sid (%u) has been closed!",
5545 getpid (), session_index);
5546 if (VPPCOM_DEBUG > 0)
5549 ELOG_TYPE_DECLARE (e) =
5551 .format = "invalid session: %d closed",
5552 .format_args = "i4",
5559 ed = ELOG_TRACK_DATA (&vcm->elog_main, e, vcm->elog_track);
5560 ed->data = session_index;
5564 clib_spinlock_unlock (&vcm->sessions_lockp);
5567 ep->is_ip4 = session->peer_addr.is_ip4;
5568 ep->port = session->peer_port;
5569 if (session->peer_addr.is_ip4)
5570 clib_memcpy (ep->ip, &session->peer_addr.ip46.ip4,
5571 sizeof (ip4_address_t));
5573 clib_memcpy (ep->ip, &session->peer_addr.ip46.ip6,
5574 sizeof (ip6_address_t));
5575 clib_spinlock_unlock (&vcm->sessions_lockp);
5579 rv = vppcom_session_read (session_index, buffer, buflen);
5580 else if (flags & MSG_PEEK)
5581 rv = vppcom_session_peek (session_index, buffer, buflen);
5584 clib_warning ("VCL<%d>: Unsupport flags for recvfrom %d",
5586 rv = VPPCOM_EAFNOSUPPORT;
5594 vppcom_session_sendto (uint32_t session_index, void *buffer,
5595 uint32_t buflen, int flags, vppcom_endpt_t * ep)
5598 return VPPCOM_EINVAL;
5603 return VPPCOM_EINVAL;
5608 // TBD check the flags and do the right thing
5609 if (VPPCOM_DEBUG > 2)
5610 clib_warning ("VCL<%d>: handling flags 0x%u (%d) "
5611 "not implemented yet.", getpid (), flags, flags);
5614 return (vppcom_session_write (session_index, buffer, buflen));
5618 vppcom_poll (vcl_poll_t * vp, uint32_t n_sids, double wait_for_time)
5620 f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time;
5621 u32 i, keep_trying = 1;
5624 if (VPPCOM_DEBUG > 3)
5625 clib_warning ("VCL<%d>: vp %p, nsids %u, wait_for_time %f",
5626 getpid (), vp, n_sids, wait_for_time);
5629 return VPPCOM_EFAULT;
5635 for (i = 0; i < n_sids; i++)
5637 ASSERT (vp[i].revents);
5639 VCL_LOCK_AND_GET_SESSION (vp[i].sid, &session);
5640 clib_spinlock_unlock (&vcm->sessions_lockp);
5645 if (POLLIN & vp[i].events)
5647 VCL_LOCK_AND_GET_SESSION (vp[i].sid, &session);
5648 rv = vppcom_session_read_ready (session, vp[i].sid);
5649 clib_spinlock_unlock (&vcm->sessions_lockp);
5652 *vp[i].revents |= POLLIN;
5659 case VPPCOM_ECONNRESET:
5660 *vp[i].revents = POLLHUP;
5664 *vp[i].revents = POLLERR;
5671 if (POLLOUT & vp[i].events)
5673 VCL_LOCK_AND_GET_SESSION (vp[i].sid, &session);
5674 rv = vppcom_session_write_ready (session, vp[i].sid);
5675 clib_spinlock_unlock (&vcm->sessions_lockp);
5678 *vp[i].revents |= POLLOUT;
5685 case VPPCOM_ECONNRESET:
5686 *vp[i].revents = POLLHUP;
5690 *vp[i].revents = POLLERR;
5700 *vp[i].revents = POLLNVAL;
5704 if (wait_for_time != -1)
5705 keep_trying = (clib_time_now (&vcm->clib_time) <= timeout) ? 1 : 0;
5707 while ((num_ev == 0) && keep_trying);
5709 if (VPPCOM_DEBUG > 3)
5711 clib_warning ("VCL<%d>: returning %d", getpid (), num_ev);
5712 for (i = 0; i < n_sids; i++)
5714 clib_warning ("VCL<%d>: vp[%d].sid %d (0x%x), .events 0x%x, "
5715 ".revents 0x%x", getpid (), i, vp[i].sid, vp[i].sid,
5716 vp[i].events, *vp[i].revents);
5723 * fd.io coding-style-patch-verification: ON
5726 * eval: (c-set-style "gnu")