LCOV - code coverage report
Current view: top level - plugins/hs_apps/sapi - vpp_echo_bapi.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 138 296 46.6 %
Date: 2023-07-05 22:20:52 Functions: 11 22 50.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2019 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       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.
      14             :  */
      15             : 
      16             : #include <stdio.h>
      17             : #include <signal.h>
      18             : 
      19             : #include <hs_apps/sapi/vpp_echo_common.h>
      20             : 
      21             : #define REPLY_MSG_ID_BASE msg_id_base
      22             : static u16 msg_id_base;
      23             : 
      24             : /*
      25             :  *
      26             :  *  Binary API Messages
      27             :  *
      28             :  */
      29             : 
      30             : void
      31           0 : echo_send_attach (echo_main_t * em)
      32             : {
      33             :   vl_api_app_attach_t *bmp;
      34           0 :   bmp = vl_msg_api_alloc (sizeof (*bmp));
      35           0 :   clib_memset (bmp, 0, sizeof (*bmp));
      36             : 
      37           0 :   bmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_APP_ATTACH);
      38           0 :   bmp->client_index = em->my_client_index;
      39           0 :   bmp->context = ntohl (0xfeedface);
      40           0 :   bmp->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_ACCEPT_REDIRECT;
      41           0 :   bmp->options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_ADD_SEGMENT;
      42           0 :   bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = em->prealloc_fifo_pairs;
      43           0 :   bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = em->fifo_size;
      44           0 :   bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = em->fifo_size;
      45           0 :   bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
      46           0 :   bmp->options[APP_OPTIONS_SEGMENT_SIZE] = 256 << 20;
      47           0 :   bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = em->evt_q_size;
      48           0 :   if (em->appns_id)
      49             :     {
      50           0 :       vl_api_vec_to_api_string (em->appns_id, &bmp->namespace_id);
      51           0 :       bmp->options[APP_OPTIONS_FLAGS] |= em->appns_flags;
      52           0 :       bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = em->appns_secret;
      53             :     }
      54           0 :   vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & bmp);
      55           0 : }
      56             : 
      57             : void
      58           0 : echo_send_detach (echo_main_t * em)
      59             : {
      60             :   vl_api_application_detach_t *bmp;
      61           0 :   bmp = vl_msg_api_alloc (sizeof (*bmp));
      62           0 :   clib_memset (bmp, 0, sizeof (*bmp));
      63             : 
      64           0 :   bmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_APPLICATION_DETACH);
      65           0 :   bmp->client_index = em->my_client_index;
      66           0 :   bmp->context = ntohl (0xfeedface);
      67             : 
      68           0 :   vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & bmp);
      69           0 : }
      70             : 
      71             : void
      72           0 : echo_send_add_cert_key (echo_main_t * em)
      73             : {
      74           0 :   u32 cert_len = test_srv_crt_rsa_len;
      75           0 :   u32 key_len = test_srv_key_rsa_len;
      76             :   vl_api_app_add_cert_key_pair_t *bmp;
      77             : 
      78           0 :   bmp = vl_msg_api_alloc (sizeof (*bmp) + cert_len + key_len);
      79           0 :   clib_memset (bmp, 0, sizeof (*bmp) + cert_len + key_len);
      80             : 
      81           0 :   bmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_APP_ADD_CERT_KEY_PAIR);
      82           0 :   bmp->client_index = em->my_client_index;
      83           0 :   bmp->context = ntohl (0xfeedface);
      84           0 :   bmp->cert_len = clib_host_to_net_u16 (cert_len);
      85           0 :   bmp->certkey_len = clib_host_to_net_u16 (key_len + cert_len);
      86           0 :   clib_memcpy_fast (bmp->certkey, test_srv_crt_rsa, cert_len);
      87           0 :   clib_memcpy_fast (bmp->certkey + cert_len, test_srv_key_rsa, key_len);
      88             : 
      89           0 :   vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & bmp);
      90           0 : }
      91             : 
      92             : void
      93           0 : echo_send_del_cert_key (echo_main_t * em)
      94             : {
      95             :   vl_api_app_del_cert_key_pair_t *bmp;
      96           0 :   bmp = vl_msg_api_alloc (sizeof (*bmp));
      97           0 :   clib_memset (bmp, 0, sizeof (*bmp));
      98             : 
      99           0 :   bmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_APP_DEL_CERT_KEY_PAIR);
     100           0 :   bmp->client_index = em->my_client_index;
     101           0 :   bmp->context = ntohl (0xfeedface);
     102           0 :   bmp->index = clib_host_to_net_u32 (em->ckpair_index);
     103           0 :   vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & bmp);
     104           0 : }
     105             : 
     106             : int
     107           0 : echo_bapi_recv_fd (echo_main_t *em, int *fds, int n_fds)
     108             : {
     109             :   clib_error_t *err;
     110           0 :   err = vl_socket_client_recv_fd_msg (fds, n_fds, 5);
     111           0 :   if (err)
     112             :     {
     113           0 :       clib_error_report (err);
     114           0 :       return -1;
     115             :     }
     116           0 :   return 0;
     117             : }
     118             : 
     119             : static u8
     120           6 : echo_transport_needs_crypto (transport_proto_t proto)
     121             : {
     122           6 :   return proto == TRANSPORT_PROTO_TLS || proto == TRANSPORT_PROTO_DTLS ||
     123             :          proto == TRANSPORT_PROTO_QUIC;
     124             : }
     125             : 
     126             : static void
     127           6 : echo_msg_add_crypto_ext_config (echo_main_t *em, uword *offset)
     128             : {
     129             :   transport_endpt_ext_cfg_t cfg;
     130             :   svm_fifo_chunk_t *c;
     131             : 
     132           6 :   c = echo_segment_alloc_chunk (ECHO_MQ_SEG_HANDLE, 0, sizeof (cfg), offset);
     133           6 :   if (!c)
     134           0 :     return;
     135             : 
     136           6 :   memset (&cfg, 0, sizeof (cfg));
     137           6 :   cfg.type = TRANSPORT_ENDPT_EXT_CFG_CRYPTO;
     138           6 :   cfg.len = sizeof (cfg);
     139           6 :   cfg.crypto.ckpair_index = em->ckpair_index;
     140           6 :   cfg.crypto.crypto_engine = em->crypto_engine;
     141           6 :   clib_memcpy_fast (c->data, &cfg, cfg.len);
     142             : }
     143             : 
     144             : void
     145           2 : echo_send_listen (echo_main_t * em, ip46_address_t * ip)
     146             : {
     147           2 :   app_session_evt_t _app_evt, *app_evt = &_app_evt;
     148             :   session_listen_msg_t *mp;
     149           2 :   svm_msg_q_t *mq = em->ctrl_mq;
     150             : 
     151           2 :   app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_LISTEN);
     152           2 :   mp = (session_listen_msg_t *) app_evt->evt->data;
     153           2 :   memset (mp, 0, sizeof (*mp));
     154           2 :   mp->client_index = em->my_client_index;
     155           2 :   mp->context = ntohl (0xfeedface);
     156           2 :   mp->wrk_index = 0;
     157           2 :   mp->is_ip4 = em->uri_elts.is_ip4;
     158           2 :   clib_memcpy_fast (&mp->ip, ip, sizeof (mp->ip));
     159           2 :   mp->port = em->uri_elts.port;
     160           2 :   mp->proto = em->uri_elts.transport_proto;
     161           2 :   if (echo_transport_needs_crypto (mp->proto))
     162           2 :     echo_msg_add_crypto_ext_config (em, &mp->ext_config);
     163           2 :   app_send_ctrl_evt_to_vpp (mq, app_evt);
     164           2 : }
     165             : 
     166             : void
     167           2 : echo_send_unbind (echo_main_t * em, echo_session_t * s)
     168             : {
     169           2 :   app_session_evt_t _app_evt, *app_evt = &_app_evt;
     170             :   session_unlisten_msg_t *mp;
     171           2 :   svm_msg_q_t *mq = em->ctrl_mq;
     172             : 
     173           2 :   app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_UNLISTEN);
     174           2 :   mp = (session_unlisten_msg_t *) app_evt->evt->data;
     175           2 :   memset (mp, 0, sizeof (*mp));
     176           2 :   mp->client_index = em->my_client_index;
     177           2 :   mp->wrk_index = 0;
     178           2 :   mp->handle = s->vpp_session_handle;
     179           2 :   mp->context = 0;
     180           2 :   app_send_ctrl_evt_to_vpp (mq, app_evt);
     181           2 : }
     182             : 
     183             : void
     184           4 : echo_send_connect (echo_main_t * em, void *args)
     185             : {
     186           4 :   app_session_evt_t _app_evt, *app_evt = &_app_evt;
     187             :   session_connect_msg_t *mp;
     188           4 :   echo_connect_args_t *a = (echo_connect_args_t *) args;
     189           4 :   svm_msg_q_t *mq = em->ctrl_mq;
     190             : 
     191           4 :   clib_atomic_sub_fetch (&em->max_sim_connects, 1);
     192           4 :   while (em->max_sim_connects <= 0)
     193             :     ;
     194             : 
     195           4 :   app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_CONNECT);
     196           4 :   mp = (session_connect_msg_t *) app_evt->evt->data;
     197           4 :   memset (mp, 0, sizeof (*mp));
     198           4 :   mp->client_index = em->my_client_index;
     199           4 :   mp->context = ntohl (a->context);
     200           4 :   mp->wrk_index = 0;
     201           4 :   mp->is_ip4 = em->uri_elts.is_ip4;
     202           4 :   clib_memcpy_fast (&mp->ip, &a->ip, sizeof (mp->ip));
     203           4 :   clib_memcpy_fast (&mp->lcl_ip, &a->lcl_ip, sizeof (mp->ip));
     204           4 :   mp->port = em->uri_elts.port;
     205           4 :   mp->proto = em->uri_elts.transport_proto;
     206           4 :   mp->parent_handle = a->parent_session_handle;
     207           4 :   if (echo_transport_needs_crypto (mp->proto))
     208           4 :     echo_msg_add_crypto_ext_config (em, &mp->ext_config);
     209           4 :   mp->flags = em->connect_flag;
     210           4 :   app_send_ctrl_evt_to_vpp (mq, app_evt);
     211           4 : }
     212             : 
     213             : void
     214           4 : echo_send_disconnect_session (echo_main_t * em, void *args)
     215             : {
     216             :   echo_session_t *s;
     217           4 :   app_session_evt_t _app_evt, *app_evt = &_app_evt;
     218             :   session_disconnect_msg_t *mp;
     219           4 :   svm_msg_q_t *mq = em->ctrl_mq;
     220           4 :   echo_disconnect_args_t *a = (echo_disconnect_args_t *) args;
     221             : 
     222           4 :   app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_DISCONNECT);
     223           4 :   mp = (session_disconnect_msg_t *) app_evt->evt->data;
     224           4 :   memset (mp, 0, sizeof (*mp));
     225           4 :   mp->client_index = em->my_client_index;
     226           4 :   mp->handle = a->session_handle;
     227           4 :   app_send_ctrl_evt_to_vpp (mq, app_evt);
     228             : 
     229           4 :   if (!(s = echo_get_session_from_handle (em, mp->handle)))
     230           0 :     return;
     231           4 :   em->proto_cb_vft->sent_disconnect_cb (s);
     232             : }
     233             : 
     234             : /*
     235             :  *
     236             :  *  Helpers
     237             :  *
     238             :  */
     239             : 
     240             : int
     241          10 : echo_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type,
     242             :                      int fd)
     243             : {
     244          10 :   fifo_segment_create_args_t _a, *a = &_a;
     245          10 :   echo_main_t *em = &echo_main;
     246             :   fifo_segment_main_t *sm;
     247             :   int rv;
     248             : 
     249          10 :   clib_memset (a, 0, sizeof (*a));
     250          10 :   a->segment_name = (char *) name;
     251          10 :   a->segment_type = type;
     252             : 
     253          10 :   if (type == SSVM_SEGMENT_MEMFD)
     254          10 :     a->memfd_fd = fd;
     255             : 
     256          10 :   sm = &em->segment_main;
     257             : 
     258          10 :   if ((rv = fifo_segment_attach (sm, a)))
     259           0 :     return rv;
     260             : 
     261          10 :   clib_spinlock_lock (&em->segment_handles_lock);
     262          10 :   hash_set (em->shared_segment_handles, segment_handle,
     263             :             a->new_segment_indices[0]);
     264          10 :   clib_spinlock_unlock (&em->segment_handles_lock);
     265             : 
     266          10 :   vec_free (a->new_segment_indices);
     267          10 :   return 0;
     268             : }
     269             : 
     270             : u32
     271          34 : echo_segment_lookup (u64 segment_handle)
     272             : {
     273          34 :   echo_main_t *em = &echo_main;
     274             :   uword *segment_idxp;
     275             : 
     276          34 :   ECHO_LOG (3, "Check if segment mapped 0x%lx...", segment_handle);
     277             : 
     278          34 :   clib_spinlock_lock (&em->segment_handles_lock);
     279          34 :   segment_idxp = hash_get (em->shared_segment_handles, segment_handle);
     280          34 :   clib_spinlock_unlock (&em->segment_handles_lock);
     281          34 :   if (segment_idxp)
     282          34 :     return ((u32) *segment_idxp);
     283             : 
     284           0 :   ECHO_LOG (2, "Segment not mapped (0x%lx)", segment_handle);
     285           0 :   return ~0;
     286             : }
     287             : 
     288             : void
     289           0 : echo_segment_detach (u64 segment_handle)
     290             : {
     291           0 :   echo_main_t *em = &echo_main;
     292             :   fifo_segment_main_t *sm;
     293             : 
     294           0 :   u32 segment_index = echo_segment_lookup (segment_handle);
     295           0 :   if (segment_index == (u32) ~0)
     296           0 :     return;
     297             : 
     298           0 :   sm = &em->segment_main;
     299             : 
     300           0 :   clib_spinlock_lock (&em->segment_handles_lock);
     301           0 :   fifo_segment_delete (sm, fifo_segment_get_segment (sm, segment_index));
     302           0 :   hash_unset (em->shared_segment_handles, segment_handle);
     303           0 :   clib_spinlock_unlock (&em->segment_handles_lock);
     304             : }
     305             : 
     306             : int
     307           8 : echo_attach_session (uword segment_handle, uword rxf_offset, uword txf_offset,
     308             :                      uword mq_offset, echo_session_t *s)
     309             : {
     310           8 :   echo_main_t *em = &echo_main;
     311             :   u32 fs_index, eqs_index;
     312             :   fifo_segment_t *fs;
     313             : 
     314           8 :   fs_index = echo_segment_lookup (segment_handle);
     315           8 :   if (fs_index == (u32) ~0)
     316             :     {
     317           0 :       ECHO_LOG (0, "ERROR: segment for session %u is not mounted!",
     318             :                 s->session_index);
     319           0 :       return -1;
     320             :     }
     321             : 
     322           8 :   if (mq_offset != (uword) ~0)
     323             :     {
     324           8 :       eqs_index = echo_segment_lookup (ECHO_MQ_SEG_HANDLE);
     325           8 :       ASSERT (eqs_index != (u32) ~0);
     326             :     }
     327             : 
     328           8 :   clib_spinlock_lock (&em->segment_handles_lock);
     329             : 
     330           8 :   fs = fifo_segment_get_segment (&em->segment_main, fs_index);
     331           8 :   s->rx_fifo = fifo_segment_alloc_fifo_w_offset (fs, rxf_offset);
     332           8 :   s->tx_fifo = fifo_segment_alloc_fifo_w_offset (fs, txf_offset);
     333           8 :   s->rx_fifo->segment_index = fs_index;
     334           8 :   s->tx_fifo->segment_index = fs_index;
     335           8 :   s->rx_fifo->shr->client_session_index = s->session_index;
     336           8 :   s->tx_fifo->shr->client_session_index = s->session_index;
     337             : 
     338           8 :   if (mq_offset != (uword) ~0)
     339             :     {
     340           8 :       fs = fifo_segment_get_segment (&em->segment_main, eqs_index);
     341           8 :       s->vpp_evt_q = fifo_segment_msg_q_attach (fs, mq_offset,
     342           8 :                                                 s->rx_fifo->shr->slice_index);
     343             :     }
     344             : 
     345           8 :   clib_spinlock_unlock (&em->segment_handles_lock);
     346             : 
     347           8 :   return 0;
     348             : }
     349             : 
     350             : int
     351           8 : echo_segment_attach_mq (uword segment_handle, uword mq_offset, u32 mq_index,
     352             :                         svm_msg_q_t **mq)
     353             : {
     354           8 :   echo_main_t *em = &echo_main;
     355             :   fifo_segment_t *fs;
     356             :   u32 fs_index;
     357             : 
     358           8 :   fs_index = echo_segment_lookup (segment_handle);
     359           8 :   if (fs_index == (u32) ~0)
     360             :     {
     361           0 :       ECHO_LOG (0, "ERROR: mq segment %lx for is not attached!",
     362             :                 segment_handle);
     363           0 :       return -1;
     364             :     }
     365             : 
     366           8 :   clib_spinlock_lock (&em->segment_handles_lock);
     367             : 
     368           8 :   fs = fifo_segment_get_segment (&em->segment_main, fs_index);
     369           8 :   *mq = fifo_segment_msg_q_attach (fs, mq_offset, mq_index);
     370             : 
     371           8 :   clib_spinlock_unlock (&em->segment_handles_lock);
     372             : 
     373           8 :   return 0;
     374             : }
     375             : 
     376             : svm_fifo_chunk_t *
     377           6 : echo_segment_alloc_chunk (uword segment_handle, u32 slice_index, u32 size,
     378             :                           uword *offset)
     379             : {
     380           6 :   echo_main_t *em = &echo_main;
     381             :   svm_fifo_chunk_t *c;
     382             :   fifo_segment_t *fs;
     383             :   u32 fs_index;
     384             : 
     385           6 :   fs_index = echo_segment_lookup (segment_handle);
     386           6 :   if (fs_index == (u32) ~0)
     387             :     {
     388           0 :       ECHO_LOG (0, "ERROR: mq segment %lx for is not attached!",
     389             :                 segment_handle);
     390           0 :       return 0;
     391             :     }
     392             : 
     393           6 :   clib_spinlock_lock (&em->segment_handles_lock);
     394             : 
     395           6 :   fs = fifo_segment_get_segment (&em->segment_main, fs_index);
     396           6 :   c = fifo_segment_alloc_chunk_w_slice (fs, slice_index, size);
     397           6 :   *offset = fifo_segment_chunk_offset (fs, c);
     398             : 
     399           6 :   clib_spinlock_unlock (&em->segment_handles_lock);
     400             : 
     401           6 :   return c;
     402             : }
     403             : 
     404             : /*
     405             :  *
     406             :  *  Binary API callbacks
     407             :  *
     408             :  */
     409             : 
     410             : static void
     411           0 :   vl_api_app_add_cert_key_pair_reply_t_handler
     412             :   (vl_api_app_add_cert_key_pair_reply_t * mp)
     413             : {
     414           0 :   echo_main_t *em = &echo_main;
     415           0 :   if (mp->retval)
     416             :     {
     417           0 :       ECHO_FAIL (ECHO_FAIL_VL_API_CERT_KEY_ADD_REPLY,
     418             :                  "Adding cert and key returned %d",
     419             :                  clib_net_to_host_u32 (mp->retval));
     420           0 :       return;
     421             :     }
     422             :   /* No concurrency here, only bapi thread writes */
     423           0 :   if (em->state != STATE_ATTACHED_NO_CERT)
     424             :     {
     425           0 :       ECHO_FAIL (ECHO_FAIL_VL_API_CERT_KEY_ADD_REPLY, "Wrong state");
     426           0 :       return;
     427             :     }
     428           0 :   em->ckpair_index = clib_net_to_host_u32 (mp->index);
     429           0 :   em->state = STATE_ATTACHED;
     430             : }
     431             : 
     432             : static void
     433           0 :   vl_api_app_del_cert_key_pair_reply_t_handler
     434             :   (vl_api_app_del_cert_key_pair_reply_t * mp)
     435             : {
     436           0 :   echo_main_t *em = &echo_main;
     437           0 :   if (mp->retval)
     438             :     {
     439           0 :       ECHO_FAIL (ECHO_FAIL_VL_API_CERT_KEY_DEL_REPLY,
     440             :                  "Delete cert and key returned %d",
     441             :                  clib_net_to_host_u32 (mp->retval));
     442           0 :       return;
     443             :     }
     444           0 :   em->state = STATE_CLEANED_CERT_KEY;
     445             : }
     446             : 
     447             : static void
     448           0 : vl_api_app_attach_reply_t_handler (vl_api_app_attach_reply_t * mp)
     449             : {
     450           0 :   echo_main_t *em = &echo_main;
     451           0 :   int *fds = 0, i, rv;
     452           0 :   u32 n_fds = 0;
     453             :   u64 segment_handle;
     454           0 :   char *segment_name = 0;
     455             : 
     456           0 :   segment_handle = clib_net_to_host_u64 (mp->segment_handle);
     457           0 :   ECHO_LOG (2, "Attached returned app %u", htons (mp->app_index));
     458             : 
     459           0 :   if (mp->retval)
     460             :     {
     461           0 :       ECHO_FAIL (ECHO_FAIL_VL_API_APP_ATTACH, "attach failed: %U",
     462             :                  format_api_error, clib_net_to_host_u32 (mp->retval));
     463           0 :       return;
     464             :     }
     465             : 
     466           0 :   if (!mp->app_mq)
     467             :     {
     468           0 :       ECHO_FAIL (ECHO_FAIL_VL_API_NULL_APP_MQ, "NULL app_mq");
     469           0 :       return;
     470             :     }
     471             : 
     472           0 :   if (mp->n_fds)
     473             :     {
     474           0 :       vec_validate (fds, mp->n_fds);
     475           0 :       if (vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5))
     476             :         {
     477           0 :           ECHO_FAIL (ECHO_FAIL_VL_API_RECV_FD_MSG,
     478             :                      "vl_socket_client_recv_fd_msg failed");
     479           0 :           goto failed;
     480             :         }
     481             : 
     482           0 :       if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT)
     483           0 :         if (echo_segment_attach (ECHO_MQ_SEG_HANDLE, 0, SSVM_SEGMENT_MEMFD,
     484           0 :                                  fds[n_fds++]))
     485             :           {
     486           0 :             ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
     487             :                        "svm_fifo_segment_attach failed on SSVM_SEGMENT_MEMFD");
     488           0 :             goto failed;
     489             :           }
     490           0 :       echo_segment_attach_mq (ECHO_MQ_SEG_HANDLE, mp->vpp_ctrl_mq,
     491           0 :                               mp->vpp_ctrl_mq_thread, &em->ctrl_mq);
     492             : 
     493           0 :       if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT)
     494             :         {
     495           0 :           segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name);
     496           0 :           rv = echo_segment_attach (segment_handle, segment_name,
     497           0 :                                     SSVM_SEGMENT_MEMFD, fds[n_fds++]);
     498           0 :           if (rv != 0)
     499             :             {
     500           0 :               ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
     501             :                          "svm_fifo_segment_attach ('%s') "
     502             :                          "failed on SSVM_SEGMENT_MEMFD", segment_name);
     503           0 :               vec_free (segment_name);
     504           0 :               goto failed;
     505             :             }
     506           0 :           vec_free (segment_name);
     507             :         }
     508           0 :       echo_segment_attach_mq (segment_handle, mp->app_mq, 0, &em->app_mq);
     509             : 
     510           0 :       if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD)
     511           0 :         svm_msg_q_set_eventfd (em->app_mq, fds[n_fds++]);
     512             : 
     513           0 :       vec_free (fds);
     514             :     }
     515             :   else
     516             :     {
     517           0 :       segment_name = vl_api_from_api_to_new_c_string (&mp->segment_name);
     518           0 :       rv = echo_segment_attach (segment_handle, segment_name, SSVM_SEGMENT_SHM,
     519             :                                 -1);
     520           0 :       if (rv != 0)
     521             :         {
     522           0 :           ECHO_FAIL (ECHO_FAIL_VL_API_SVM_FIFO_SEG_ATTACH,
     523             :                      "svm_fifo_segment_attach ('%s') "
     524             :                      "failed on SSVM_SEGMENT_SHM", segment_name);
     525           0 :           vec_free (segment_name);
     526           0 :           goto failed;
     527             :         }
     528           0 :       vec_free (segment_name);
     529             :     }
     530           0 :   ECHO_LOG (2, "Mapped segment 0x%lx", segment_handle);
     531             : 
     532           0 :   em->state = STATE_ATTACHED_NO_CERT;
     533           0 :   return;
     534           0 : failed:
     535           0 :   for (i = clib_max (n_fds - 1, 0); i < vec_len (fds); i++)
     536           0 :     close (fds[i]);
     537           0 :   vec_free (fds);
     538             : }
     539             : 
     540             : static void
     541           0 : vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t *
     542             :                                            mp)
     543             : {
     544           0 :   if (mp->retval)
     545             :     {
     546           0 :       ECHO_FAIL (ECHO_FAIL_VL_API_DETACH_REPLY,
     547             :                  "app detach returned with err: %d", mp->retval);
     548           0 :       return;
     549             :     }
     550           0 :   echo_main.state = STATE_DETACHED;
     551             : }
     552             : 
     553             : #define foreach_quic_echo_msg                                    \
     554             : _(APP_ATTACH_REPLY, app_attach_reply)                            \
     555             : _(APPLICATION_DETACH_REPLY, application_detach_reply)            \
     556             : _(APP_ADD_CERT_KEY_PAIR_REPLY, app_add_cert_key_pair_reply)      \
     557             : _(APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply)
     558             : 
     559             : #define vl_endianfun
     560             : #include <vnet/session/session.api.h>
     561             : #undef vl_endianfun
     562             : 
     563             : #define vl_calcsizefun
     564             : #include <vnet/session/session.api.h>
     565             : #undef vl_calcsizefun
     566             : 
     567             : #define vl_printfun
     568             : #include <vnet/session/session.api.h>
     569             : #undef vl_printfun
     570             : 
     571             : #define vl_api_version(n, v) static u32 api_version = v;
     572             : #include <vnet/session/session.api.h>
     573             : #undef vl_api_version
     574             : 
     575             : void
     576           0 : echo_api_hookup (echo_main_t * em)
     577             : {
     578           0 :   u8 *name = format (0, "session_%08x%c", api_version, 0);
     579             : 
     580           0 :   REPLY_MSG_ID_BASE = vl_client_get_first_plugin_msg_id ((char *) name);
     581             : 
     582           0 :   vec_free (name);
     583             : 
     584           0 :   if (REPLY_MSG_ID_BASE == (u16) ~0)
     585           0 :     return;
     586             : 
     587             : #define _(N, n)                                                               \
     588             :   vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
     589             :     .id = REPLY_MSG_ID_BASE + VL_API_##N,                                     \
     590             :     .name = #n,                                                               \
     591             :     .handler = vl_api_##n##_t_handler,                                        \
     592             :     .endian = vl_api_##n##_t_endian,                                          \
     593             :     .format_fn = vl_api_##n##_t_format,                                       \
     594             :     .size = sizeof (vl_api_##n##_t),                                          \
     595             :     .traced = 1,                                                              \
     596             :     .tojson = vl_api_##n##_t_tojson,                                          \
     597             :     .fromjson = vl_api_##n##_t_fromjson,                                      \
     598             :     .calc_size = vl_api_##n##_t_calc_size,                                    \
     599             :   });
     600           0 :   foreach_quic_echo_msg;
     601             : #undef _
     602             : }
     603             : 
     604             : /*
     605             :  * fd.io coding-style-patch-verification: ON
     606             :  *
     607             :  * Local Variables:
     608             :  * eval: (c-set-style "gnu")
     609             :  * End:
     610             :  */

Generated by: LCOV version 1.14