2 * Copyright (c) 2018 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.
16 #include <vcl/vcl_private.h>
17 #include <vlibmemory/api.h>
18 #include <vpp/api/vpe_msg_enum.h>
20 #define vl_typedefs /* define message structures */
21 #include <vpp/api/vpe_all_api_h.h>
24 /* declare message handlers for each api */
26 #define vl_endianfun /* define message structures */
27 #include <vpp/api/vpe_all_api_h.h>
30 /* instantiate all the print functions we know about */
31 #define vl_print(handle, ...)
33 #include <vpp/api/vpe_all_api_h.h>
37 format_api_error (u8 * s, va_list * args)
39 i32 error = va_arg (*args, u32);
42 p = hash_get (vcm->error_string_by_error_number, -error);
45 s = format (s, "%s (%d)", p[0], error);
47 s = format (s, "%d", error);
52 vl_api_session_enable_disable_reply_t_handler
53 (vl_api_session_enable_disable_reply_t * mp)
57 clib_warning ("VCL<%d>: session_enable_disable failed: %U", getpid (),
58 format_api_error, ntohl (mp->retval));
61 vcm->app_state = STATE_APP_ENABLED;
65 ssvm_segment_attach (char *name, ssvm_segment_type_t type, int fd)
67 svm_fifo_segment_create_args_t _a, *a = &_a;
70 memset (a, 0, sizeof (*a));
71 a->segment_name = (char *) name;
72 a->segment_type = type;
74 if (type == SSVM_SEGMENT_MEMFD)
77 if ((rv = svm_fifo_segment_attach (a)))
79 clib_warning ("svm_fifo_segment_attach ('%s') failed", name);
82 vec_reset_length (a->new_segment_indices);
87 vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
95 clib_warning ("VCL<%d>: attach failed: %U", getpid (),
96 format_api_error, ntohl (mp->retval));
100 vcm->app_event_queue = uword_to_pointer (mp->app_event_queue_address,
104 vec_validate (fds, mp->n_fds);
105 vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5);
107 if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT)
108 if (ssvm_segment_attach ("vpp-mq-seg", SSVM_SEGMENT_MEMFD,
112 if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
113 if (ssvm_segment_attach ((char *) mp->segment_name,
114 SSVM_SEGMENT_MEMFD, fds[n_fds++]))
117 if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD)
119 svm_msg_q_set_consumer_eventfd (vcm->app_event_queue, fds[n_fds]);
120 if (vcm->mqs_epfd < 0)
121 clib_unix_warning ("epoll_create() returned");
122 vcl_mq_epoll_add_evfd (vcm->app_event_queue);
130 if (ssvm_segment_attach ((char *) mp->segment_name, SSVM_SEGMENT_SHM,
135 vcm->app_state = STATE_APP_ATTACHED;
139 vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
143 clib_warning ("VCL<%d>: detach failed: %U", getpid (), format_api_error,
146 vcm->app_state = STATE_APP_ENABLED;
150 vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
154 clib_warning ("VCL<%d>: vpp handle 0x%llx: disconnect session failed: %U",
155 getpid (), mp->handle, format_api_error,
160 vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp)
162 ssvm_segment_type_t seg_type = SSVM_SEGMENT_SHM;
165 vcm->mounting_segment = 1;
169 vl_socket_client_recv_fd_msg (&fd, 1, 5);
170 seg_type = SSVM_SEGMENT_MEMFD;
173 if (PREDICT_FALSE (ssvm_segment_attach ((char *) mp->segment_name,
176 clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed",
177 getpid (), mp->segment_name);
181 VDBG (1, "VCL<%d>: mapped new segment '%s' size %d", getpid (),
182 mp->segment_name, mp->segment_size);
183 vcm->mounting_segment = 0;
187 vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp)
191 * XXX Need segment_name to session_id hash,
192 * XXX - have sessionID by handle hash currently
195 VDBG (1, "Unmapped segment '%s'", mp->segment_name);
199 vl_api_app_cut_through_registration_add_t_handler
200 (vl_api_app_cut_through_registration_add_t * mp)
202 vcl_cut_through_registration_t *ctr;
208 ASSERT (mp->n_fds == 2);
209 vec_validate (fds, mp->n_fds);
210 vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5);
213 ctr = vcl_ct_registration_lock_and_alloc ();
214 ctr->mq = uword_to_pointer (mp->evt_q_address, svm_msg_q_t *);
215 ctr->peer_mq = uword_to_pointer (mp->peer_evt_q_address, svm_msg_q_t *);
216 VDBG (0, "Adding ct registration %u", vcl_ct_registration_index (ctr));
218 if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD)
220 svm_msg_q_set_consumer_eventfd (ctr->mq, fds[0]);
221 svm_msg_q_set_producer_eventfd (ctr->peer_mq, fds[1]);
222 mqc_index = vcl_mq_epoll_add_evfd (ctr->mq);
223 ctr->epoll_evt_conn_index = mqc_index;
226 vcl_ct_registration_lookup_add (mp->evt_q_address,
227 vcl_ct_registration_index (ctr));
228 vcl_ct_registration_unlock ();
232 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
236 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
240 vcl_session_t *session = 0;
241 u32 session_index = p[0];
243 VCL_SESSION_LOCK_AND_GET (session_index, &session);
244 session->session_state = STATE_CLOSE_ON_EMPTY;
246 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: setting state to 0x%x "
247 "(%s)", getpid (), mp->handle, session_index,
248 session->session_state,
249 vppcom_session_state_str (session->session_state));
250 VCL_SESSION_UNLOCK ();
254 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session lookup failed!",
255 getpid (), mp->handle, session_index);
258 clib_warning ("VCL<%d>: vpp handle 0x%llx: session lookup by "
259 "handle failed!", getpid (), mp->handle);
263 vl_api_reset_session_t_handler (vl_api_reset_session_t * mp)
265 vcl_session_t *session = 0;
266 vl_api_reset_session_reply_t *rmp;
270 p = hash_get (vcm->session_index_by_vpp_handles, mp->handle);
275 rval = vppcom_session_at_index (p[0], &session);
276 if (PREDICT_FALSE (rval))
278 rv = VNET_API_ERROR_INVALID_VALUE_2;
279 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
280 "session lookup failed! returning %d %U",
281 getpid (), mp->handle, p[0],
282 rv, format_api_error, rv);
286 /* TBD: should this disconnect immediately and
289 session->session_state = STATE_CLOSE_ON_EMPTY;
291 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: state set to %d "
292 "(%s)!", getpid (), mp->handle, p[0], session->session_state,
293 vppcom_session_state_str (session->session_state));
295 VCL_SESSION_UNLOCK ();
299 rv = VNET_API_ERROR_INVALID_VALUE;
300 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx: session lookup "
301 "failed! returning %d %U",
302 getpid (), mp->handle, rv, format_api_error, rv);
305 rmp = vl_msg_api_alloc (sizeof (*rmp));
306 memset (rmp, 0, sizeof (*rmp));
307 rmp->_vl_msg_id = ntohs (VL_API_RESET_SESSION_REPLY);
308 rmp->retval = htonl (rv);
309 rmp->handle = mp->handle;
310 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
314 vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp)
316 vcl_session_t *session = 0;
318 svm_fifo_t *rx_fifo, *tx_fifo;
321 session_index = mp->context;
322 VCL_SESSION_LOCK_AND_GET (session_index, &session);
326 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: "
327 "connect failed! %U",
328 getpid (), mp->handle, session_index,
329 format_api_error, ntohl (mp->retval));
332 session->session_state = STATE_FAILED;
333 session->vpp_handle = mp->handle;
337 clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
338 "Invalid session index (%u)!",
339 getpid (), mp->handle, session_index);
350 if (vcm->session_io_thread.io_sessions_lockp)
352 // Add this connection to the active io sessions list
353 VCL_IO_SESSIONS_LOCK ();
354 u32 *active_session_index;
355 pool_get (vcm->session_io_thread.active_session_indexes,
356 active_session_index);
357 *active_session_index = session_index;
358 VCL_IO_SESSIONS_UNLOCK ();
360 session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
363 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
364 rx_fifo->client_session_index = session_index;
365 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
366 tx_fifo->client_session_index = session_index;
368 session->rx_fifo = rx_fifo;
369 session->tx_fifo = tx_fifo;
370 session->vpp_handle = mp->handle;
371 session->transport.is_ip4 = mp->is_ip4;
372 clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip,
373 sizeof (session->transport.rmt_ip));
374 session->transport.lcl_port = mp->lcl_port;
375 session->session_state = STATE_CONNECT;
377 /* Add it to lookup table */
378 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
380 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: connect succeeded! "
381 "session_rx_fifo %p, refcnt %d, session_tx_fifo %p, refcnt %d",
382 getpid (), mp->handle, session_index, session->rx_fifo,
383 session->rx_fifo->refcnt, session->tx_fifo, session->tx_fifo->refcnt);
385 VCL_SESSION_UNLOCK ();
389 vl_api_bind_sock_reply_t_handler (vl_api_bind_sock_reply_t * mp)
391 vcl_session_t *session = 0;
392 u32 session_index = mp->context;
395 VCL_SESSION_LOCK_AND_GET (session_index, &session);
399 clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, "
400 "sid %u: bind failed: %U",
401 getpid (), mp->handle, session_index,
402 format_api_error, ntohl (mp->retval));
403 rv = vppcom_session_at_index (session_index, &session);
406 session->session_state = STATE_FAILED;
407 session->vpp_handle = mp->handle;
411 clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: "
412 "Invalid session index (%u)!",
413 getpid (), mp->handle, session_index);
418 session->vpp_handle = mp->handle;
419 session->transport.is_ip4 = mp->lcl_is_ip4;
420 clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip,
421 sizeof (ip46_address_t));
422 session->transport.lcl_port = mp->lcl_port;
423 vppcom_session_table_add_listener (mp->handle, session_index);
424 session->session_state = STATE_LISTEN;
426 if (session->is_dgram)
428 svm_fifo_t *rx_fifo, *tx_fifo;
429 session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *);
430 rx_fifo = uword_to_pointer (mp->rx_fifo, svm_fifo_t *);
431 rx_fifo->client_session_index = session_index;
432 tx_fifo = uword_to_pointer (mp->tx_fifo, svm_fifo_t *);
433 tx_fifo->client_session_index = session_index;
434 session->rx_fifo = rx_fifo;
435 session->tx_fifo = tx_fifo;
438 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: bind succeeded!",
439 getpid (), mp->handle, mp->context);
441 VCL_SESSION_UNLOCK ();
445 vl_api_unbind_sock_reply_t_handler (vl_api_unbind_sock_reply_t * mp)
448 clib_warning ("VCL<%d>: ERROR: sid %u: unbind failed: %U",
449 getpid (), mp->context, format_api_error,
453 VDBG (1, "VCL<%d>: sid %u: unbind succeeded!", getpid (), mp->context);
457 vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
459 svm_fifo_t *rx_fifo, *tx_fifo;
460 vcl_session_t *session, *listen_session;
462 vce_event_connect_request_t *ecr;
470 VCL_ACCEPT_FIFO_LOCK ();
471 elts = clib_fifo_free_elts (vcm->client_session_index_fifo);
472 VCL_ACCEPT_FIFO_UNLOCK ();
476 clib_warning ("VCL<%d>: client session queue is full!", getpid ());
477 vppcom_send_accept_session_reply (mp->handle, mp->context,
478 VNET_API_ERROR_QUEUE_FULL);
479 VCL_SESSION_UNLOCK ();
483 listen_session = vppcom_session_table_lookup_listener (mp->listener_handle);
486 clib_warning ("VCL<%d>: ERROR: couldn't find listen session: "
487 "unknown vpp listener handle %llx",
488 getpid (), mp->listener_handle);
489 vppcom_send_accept_session_reply (mp->handle, mp->context,
490 VNET_API_ERROR_INVALID_ARGUMENT);
491 VCL_SESSION_UNLOCK ();
495 /* TODO check listener depth and update */
496 /* TODO on "child" fd close, update listener depth */
498 /* Allocate local session and set it up */
499 pool_get (vcm->sessions, session);
500 memset (session, 0, sizeof (*session));
501 session_index = (u32) (session - vcm->sessions);
503 rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
504 rx_fifo->client_session_index = session_index;
505 tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
506 tx_fifo->client_session_index = session_index;
508 session->vpp_handle = mp->handle;
509 session->client_context = mp->context;
510 session->rx_fifo = rx_fifo;
511 session->tx_fifo = tx_fifo;
512 session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address,
514 session->session_state = STATE_ACCEPT;
515 session->transport.rmt_port = mp->port;
516 session->transport.is_ip4 = mp->is_ip4;
517 clib_memcpy (&session->transport.rmt_ip, mp->ip, sizeof (ip46_address_t));
519 /* Add it to lookup table */
520 hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
521 session->transport.lcl_port = listen_session->transport.lcl_port;
522 session->transport.lcl_ip = listen_session->transport.lcl_ip;
524 /* Create an event for handlers */
528 pool_get (vcm->event_thread.vce_events, ev);
529 ev_idx = (u32) (ev - vcm->event_thread.vce_events);
530 ecr = vce_get_event_data (ev, sizeof (*ecr));
531 ev->evk.eid = VCL_EVENT_CONNECT_REQ_ACCEPTED;
532 listen_session = vppcom_session_table_lookup_listener (mp->listener_handle);
533 ev->evk.session_index = (u32) (listen_session - vcm->sessions);
534 ecr->accepted_session_index = session_index;
536 VCL_EVENTS_UNLOCK ();
538 rv = vce_generate_event (&vcm->event_thread, ev_idx);
541 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: client accept request from %s"
542 " address %U port %d queue %p!", getpid (), mp->handle, session_index,
543 mp->is_ip4 ? "IPv4" : "IPv6", format_ip46_address, &mp->ip,
544 mp->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6,
545 clib_net_to_host_u16 (mp->port), session->vpp_evt_q);
547 vcl_evt (VCL_EVT_ACCEPT, session, listen_session, session_index);
548 VCL_SESSION_UNLOCK ();
551 #define foreach_sock_msg \
552 _(SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \
553 _(BIND_SOCK_REPLY, bind_sock_reply) \
554 _(UNBIND_SOCK_REPLY, unbind_sock_reply) \
555 _(ACCEPT_SESSION, accept_session) \
556 _(CONNECT_SESSION_REPLY, connect_session_reply) \
557 _(DISCONNECT_SESSION, disconnect_session) \
558 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
559 _(RESET_SESSION, reset_session) \
560 _(APPLICATION_ATTACH_REPLY, application_attach_reply) \
561 _(APPLICATION_DETACH_REPLY, application_detach_reply) \
562 _(MAP_ANOTHER_SEGMENT, map_another_segment) \
563 _(UNMAP_SEGMENT, unmap_segment) \
564 _(APP_CUT_THROUGH_REGISTRATION_ADD, app_cut_through_registration_add) \
567 vppcom_api_hookup (void)
570 vl_msg_api_set_handlers(VL_API_##N, #n, \
571 vl_api_##n##_t_handler, \
573 vl_api_##n##_t_endian, \
574 vl_api_##n##_t_print, \
575 sizeof(vl_api_##n##_t), 1);
581 * VPP-API message functions
584 vppcom_send_session_enable_disable (u8 is_enable)
586 vl_api_session_enable_disable_t *bmp;
587 bmp = vl_msg_api_alloc (sizeof (*bmp));
588 memset (bmp, 0, sizeof (*bmp));
590 bmp->_vl_msg_id = ntohs (VL_API_SESSION_ENABLE_DISABLE);
591 bmp->client_index = vcm->my_client_index;
592 bmp->context = htonl (0xfeedface);
593 bmp->is_enable = is_enable;
594 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
598 vppcom_app_send_attach (void)
600 vl_api_application_attach_t *bmp;
601 u8 nsid_len = vec_len (vcm->cfg.namespace_id);
602 u8 app_is_proxy = (vcm->cfg.app_proxy_transport_tcp ||
603 vcm->cfg.app_proxy_transport_udp);
605 bmp = vl_msg_api_alloc (sizeof (*bmp));
606 memset (bmp, 0, sizeof (*bmp));
608 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH);
609 bmp->client_index = vcm->my_client_index;
610 bmp->context = htonl (0xfeedface);
611 bmp->options[APP_OPTIONS_FLAGS] =
612 APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT |
613 (vcm->cfg.app_scope_local ? APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE : 0) |
614 (vcm->cfg.app_scope_global ? APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE : 0) |
615 (app_is_proxy ? APP_OPTIONS_FLAGS_IS_PROXY : 0) |
616 APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS |
617 (vcm->cfg.use_mq_eventfd ? APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD : 0);
618 bmp->options[APP_OPTIONS_PROXY_TRANSPORT] =
619 (u64) ((vcm->cfg.app_proxy_transport_tcp ? 1 << TRANSPORT_PROTO_TCP : 0) |
620 (vcm->cfg.app_proxy_transport_udp ? 1 << TRANSPORT_PROTO_UDP : 0));
621 bmp->options[APP_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
622 bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
623 bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
624 bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
625 bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
626 vcm->cfg.preallocated_fifo_pairs;
627 bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = vcm->cfg.event_queue_size;
630 bmp->namespace_id_len = nsid_len;
631 clib_memcpy (bmp->namespace_id, vcm->cfg.namespace_id, nsid_len);
632 bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = vcm->cfg.namespace_secret;
634 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
638 vppcom_app_send_detach (void)
640 vl_api_application_detach_t *bmp;
641 bmp = vl_msg_api_alloc (sizeof (*bmp));
642 memset (bmp, 0, sizeof (*bmp));
644 bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH);
645 bmp->client_index = vcm->my_client_index;
646 bmp->context = htonl (0xfeedface);
647 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
651 vppcom_send_connect_sock (vcl_session_t * session, u32 session_index)
653 vl_api_connect_sock_t *cmp;
655 /* Assumes caller as acquired the spinlock: vcm->sessions_lockp */
656 cmp = vl_msg_api_alloc (sizeof (*cmp));
657 memset (cmp, 0, sizeof (*cmp));
658 cmp->_vl_msg_id = ntohs (VL_API_CONNECT_SOCK);
659 cmp->client_index = vcm->my_client_index;
660 cmp->context = session_index;
662 cmp->is_ip4 = session->transport.is_ip4;
663 clib_memcpy (cmp->ip, &session->transport.rmt_ip, sizeof (cmp->ip));
664 cmp->port = session->transport.rmt_port;
665 cmp->proto = session->session_type;
666 clib_memcpy (cmp->options, session->options, sizeof (cmp->options));
667 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & cmp);
671 vppcom_send_disconnect_session_reply (u64 vpp_handle, u32 session_index,
674 vl_api_disconnect_session_reply_t *rmp;
676 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect msg",
677 getpid (), vpp_handle, session_index);
679 rmp = vl_msg_api_alloc (sizeof (*rmp));
680 memset (rmp, 0, sizeof (*rmp));
682 rmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION_REPLY);
683 rmp->retval = htonl (rv);
684 rmp->handle = vpp_handle;
685 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
689 vppcom_send_disconnect_session (u64 vpp_handle, u32 session_index)
691 vl_api_disconnect_session_t *dmp;
693 VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect msg",
694 getpid (), vpp_handle, session_index);
696 dmp = vl_msg_api_alloc (sizeof (*dmp));
697 memset (dmp, 0, sizeof (*dmp));
698 dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION);
699 dmp->client_index = vcm->my_client_index;
700 dmp->handle = vpp_handle;
701 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & dmp);
704 /* VPP combines bind and listen as one operation. VCL manages the separation
705 * of bind and listen locally via vppcom_session_bind() and
706 * vppcom_session_listen() */
708 vppcom_send_bind_sock (vcl_session_t * session, u32 session_index)
710 vl_api_bind_sock_t *bmp;
712 /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
713 bmp = vl_msg_api_alloc (sizeof (*bmp));
714 memset (bmp, 0, sizeof (*bmp));
716 bmp->_vl_msg_id = ntohs (VL_API_BIND_SOCK);
717 bmp->client_index = vcm->my_client_index;
718 bmp->context = session_index;
719 bmp->is_ip4 = session->transport.is_ip4;
720 clib_memcpy (bmp->ip, &session->transport.lcl_ip, sizeof (bmp->ip));
721 bmp->port = session->transport.lcl_port;
722 bmp->proto = session->session_type;
723 clib_memcpy (bmp->options, session->options, sizeof (bmp->options));
724 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & bmp);
728 vppcom_send_unbind_sock (u64 vpp_handle)
730 vl_api_unbind_sock_t *ump;
732 ump = vl_msg_api_alloc (sizeof (*ump));
733 memset (ump, 0, sizeof (*ump));
735 ump->_vl_msg_id = ntohs (VL_API_UNBIND_SOCK);
736 ump->client_index = vcm->my_client_index;
737 ump->handle = vpp_handle;
738 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & ump);
742 vppcom_send_accept_session_reply (u64 handle, u32 context, int retval)
744 vl_api_accept_session_reply_t *rmp;
746 rmp = vl_msg_api_alloc (sizeof (*rmp));
747 memset (rmp, 0, sizeof (*rmp));
748 rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
749 rmp->retval = htonl (retval);
750 rmp->context = context;
751 rmp->handle = handle;
752 vl_msg_api_send_shmem (vcm->vl_input_queue, (u8 *) & rmp);
756 vcl_max_nsid_len (void)
758 vl_api_application_attach_t *mp;
759 return (sizeof (mp->namespace_id) - 1);
763 vppcom_init_error_string_table (void)
765 vcm->error_string_by_error_number = hash_create (0, sizeof (uword));
767 #define _(n, v, s) hash_set (vcm->error_string_by_error_number, -v, s);
768 foreach_vnet_api_error;
771 hash_set (vcm->error_string_by_error_number, 99, "Misc");
775 vppcom_connect_to_vpp (char *app_name)
777 api_main_t *am = &api_main;
778 vppcom_cfg_t *vcl_cfg = &vcm->cfg;
780 if (vcl_cfg->vpp_api_socket_name)
782 if (vl_socket_client_connect ((char *) vcl_cfg->vpp_api_socket_name,
783 app_name, 0 /* default rx/tx buffer */ ))
785 clib_warning ("VCL<%d>: app (%s) socket connect failed!",
786 getpid (), app_name);
787 return VPPCOM_ECONNREFUSED;
790 if (vl_socket_client_init_shm (0))
792 clib_warning ("VCL<%d>: app (%s) init shm failed!",
793 getpid (), app_name);
794 return VPPCOM_ECONNREFUSED;
799 if (!vcl_cfg->vpp_api_filename)
800 vcl_cfg->vpp_api_filename = format (0, "/vpe-api%c", 0);
802 VDBG (0, "VCL<%d>: app (%s) connecting to VPP api (%s)...", getpid (),
803 app_name, vcl_cfg->vpp_api_filename);
805 if (vl_client_connect_to_vlib ((char *) vcl_cfg->vpp_api_filename,
806 app_name, vcm->cfg.vpp_api_q_length) < 0)
808 clib_warning ("VCL<%d>: app (%s) connect failed!", getpid (),
810 return VPPCOM_ECONNREFUSED;
815 vcm->vl_input_queue = am->shmem_hdr->vl_input_queue;
816 vcm->my_client_index = (u32) am->my_client_index;
817 vcm->app_state = STATE_APP_CONN_VPP;
819 VDBG (0, "VCL<%d>: app (%s) is connected to VPP!", getpid (), app_name);
821 vcl_evt (VCL_EVT_INIT, vcm);
826 * fd.io coding-style-patch-verification: ON
829 * eval: (c-set-style "gnu")