Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1 | /* |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 Cisco and/or its affiliates. |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this |
| 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 <vcl/vcl_private.h> |
| 17 | #include <vlibmemory/api.h> |
| 18 | #include <vpp/api/vpe_msg_enum.h> |
| 19 | |
| 20 | #define vl_typedefs /* define message structures */ |
| 21 | #include <vpp/api/vpe_all_api_h.h> |
| 22 | #undef vl_typedefs |
| 23 | |
| 24 | /* declare message handlers for each api */ |
| 25 | |
| 26 | #define vl_endianfun /* define message structures */ |
| 27 | #include <vpp/api/vpe_all_api_h.h> |
| 28 | #undef vl_endianfun |
| 29 | |
| 30 | /* instantiate all the print functions we know about */ |
| 31 | #define vl_print(handle, ...) |
| 32 | #define vl_printfun |
| 33 | #include <vpp/api/vpe_all_api_h.h> |
| 34 | #undef vl_printfun |
| 35 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 36 | u8 * |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 37 | format_api_error (u8 * s, va_list * args) |
| 38 | { |
| 39 | i32 error = va_arg (*args, u32); |
| 40 | uword *p; |
| 41 | |
| 42 | p = hash_get (vcm->error_string_by_error_number, -error); |
| 43 | |
| 44 | if (p) |
| 45 | s = format (s, "%s (%d)", p[0], error); |
| 46 | else |
| 47 | s = format (s, "%d", error); |
| 48 | return s; |
| 49 | } |
| 50 | |
| 51 | static void |
| 52 | vl_api_session_enable_disable_reply_t_handler |
| 53 | (vl_api_session_enable_disable_reply_t * mp) |
| 54 | { |
| 55 | if (mp->retval) |
| 56 | { |
| 57 | clib_warning ("VCL<%d>: session_enable_disable failed: %U", getpid (), |
| 58 | format_api_error, ntohl (mp->retval)); |
| 59 | } |
| 60 | else |
| 61 | vcm->app_state = STATE_APP_ENABLED; |
| 62 | } |
| 63 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 64 | static int |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 65 | vcl_segment_attach (u64 segment_handle, char *name, ssvm_segment_type_t type, |
| 66 | int fd) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 67 | { |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 68 | fifo_segment_create_args_t _a, *a = &_a; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 69 | int rv; |
| 70 | |
| 71 | memset (a, 0, sizeof (*a)); |
| 72 | a->segment_name = (char *) name; |
| 73 | a->segment_type = type; |
| 74 | |
| 75 | if (type == SSVM_SEGMENT_MEMFD) |
| 76 | a->memfd_fd = fd; |
| 77 | |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 78 | if ((rv = fifo_segment_attach (&vcm->segment_main, a))) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 79 | { |
| 80 | clib_warning ("svm_fifo_segment_attach ('%s') failed", name); |
| 81 | return rv; |
| 82 | } |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 83 | vcl_segment_table_add (segment_handle, a->new_segment_indices[0]); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 84 | vec_reset_length (a->new_segment_indices); |
| 85 | return 0; |
| 86 | } |
| 87 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 88 | static void |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 89 | vcl_segment_detach (u64 segment_handle) |
| 90 | { |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 91 | fifo_segment_main_t *sm = &vcm->segment_main; |
| 92 | fifo_segment_t *segment; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 93 | u32 segment_index; |
| 94 | |
| 95 | segment_index = vcl_segment_table_lookup (segment_handle); |
| 96 | if (segment_index == (u32) ~ 0) |
| 97 | return; |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 98 | segment = fifo_segment_get_segment (sm, segment_index); |
| 99 | fifo_segment_delete (sm, segment); |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 100 | vcl_segment_table_del (segment_handle); |
Florin Coras | 4850e3e | 2018-12-12 14:34:38 -0800 | [diff] [blame] | 101 | VDBG (0, "detached segment %u handle %u", segment_index, segment_handle); |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static u64 |
| 105 | vcl_vpp_worker_segment_handle (u32 wrk_index) |
| 106 | { |
| 107 | return (VCL_INVALID_SEGMENT_HANDLE - wrk_index - 1); |
| 108 | } |
| 109 | |
| 110 | static void |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 111 | vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t * |
| 112 | mp) |
| 113 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 114 | vcl_worker_t *wrk = vcl_worker_get (0); |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 115 | u64 segment_handle; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 116 | u32 n_fds = 0; |
| 117 | int *fds = 0; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 118 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 119 | if (mp->retval) |
| 120 | { |
Florin Coras | a5efca3 | 2019-03-20 08:33:10 -0700 | [diff] [blame] | 121 | VERR ("attach failed: %U", format_api_error, ntohl (mp->retval)); |
| 122 | goto failed; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 125 | wrk->app_event_queue = uword_to_pointer (mp->app_event_queue_address, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 126 | svm_msg_q_t *); |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 127 | segment_handle = clib_net_to_host_u64 (mp->segment_handle); |
| 128 | if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) |
| 129 | { |
Florin Coras | a5efca3 | 2019-03-20 08:33:10 -0700 | [diff] [blame] | 130 | VERR ("invalid segment handle"); |
| 131 | goto failed; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 134 | if (mp->n_fds) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 135 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 136 | vec_validate (fds, mp->n_fds); |
| 137 | vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5); |
| 138 | |
| 139 | if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT) |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 140 | if (vcl_segment_attach (vcl_vpp_worker_segment_handle (0), |
| 141 | "vpp-mq-seg", SSVM_SEGMENT_MEMFD, |
| 142 | fds[n_fds++])) |
Florin Coras | a5efca3 | 2019-03-20 08:33:10 -0700 | [diff] [blame] | 143 | goto failed; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 144 | |
| 145 | if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT) |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 146 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 147 | SSVM_SEGMENT_MEMFD, fds[n_fds++])) |
Florin Coras | a5efca3 | 2019-03-20 08:33:10 -0700 | [diff] [blame] | 148 | goto failed; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 149 | |
| 150 | if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD) |
| 151 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 152 | svm_msg_q_set_consumer_eventfd (wrk->app_event_queue, fds[n_fds]); |
| 153 | vcl_mq_epoll_add_evfd (wrk, wrk->app_event_queue); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 154 | n_fds++; |
| 155 | } |
| 156 | |
| 157 | vec_free (fds); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 158 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 159 | else |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 160 | { |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 161 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 162 | SSVM_SEGMENT_SHM, -1)) |
Florin Coras | a5efca3 | 2019-03-20 08:33:10 -0700 | [diff] [blame] | 163 | goto failed; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 166 | vcm->app_index = clib_net_to_host_u32 (mp->app_index); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 167 | vcm->app_state = STATE_APP_ATTACHED; |
Florin Coras | a5efca3 | 2019-03-20 08:33:10 -0700 | [diff] [blame] | 168 | return; |
| 169 | |
| 170 | failed: |
| 171 | vcm->app_state = STATE_APP_FAILED; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static void |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 175 | vl_api_app_worker_add_del_reply_t_handler (vl_api_app_worker_add_del_reply_t * |
| 176 | mp) |
| 177 | { |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 178 | int n_fds = 0, *fds = 0; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 179 | u64 segment_handle; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 180 | vcl_worker_t *wrk; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 181 | u32 wrk_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 182 | |
| 183 | if (mp->retval) |
| 184 | { |
| 185 | clib_warning ("VCL<%d>: add/del worker failed: %U", getpid (), |
| 186 | format_api_error, ntohl (mp->retval)); |
| 187 | goto failed; |
| 188 | } |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 189 | |
Florin Coras | 3348a4c | 2018-09-07 17:09:35 -0700 | [diff] [blame] | 190 | if (!mp->is_add) |
| 191 | return; |
| 192 | |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 193 | wrk_index = mp->context; |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 194 | wrk = vcl_worker_get_if_valid (wrk_index); |
| 195 | if (!wrk) |
| 196 | return; |
| 197 | |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 198 | wrk->vpp_wrk_index = clib_net_to_host_u32 (mp->wrk_index); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 199 | wrk->app_event_queue = uword_to_pointer (mp->app_event_queue_address, |
| 200 | svm_msg_q_t *); |
| 201 | |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 202 | segment_handle = clib_net_to_host_u64 (mp->segment_handle); |
| 203 | if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) |
| 204 | { |
| 205 | clib_warning ("invalid segment handle"); |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 206 | goto failed; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 209 | if (mp->n_fds) |
| 210 | { |
| 211 | vec_validate (fds, mp->n_fds); |
| 212 | vl_socket_client_recv_fd_msg (fds, mp->n_fds, 5); |
| 213 | |
| 214 | if (mp->fd_flags & SESSION_FD_F_VPP_MQ_SEGMENT) |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 215 | if (vcl_segment_attach (vcl_vpp_worker_segment_handle (wrk_index), |
| 216 | "vpp-worker-seg", SSVM_SEGMENT_MEMFD, |
| 217 | fds[n_fds++])) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 218 | goto failed; |
| 219 | |
| 220 | if (mp->fd_flags & SESSION_FD_F_MEMFD_SEGMENT) |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 221 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 222 | SSVM_SEGMENT_MEMFD, fds[n_fds++])) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 223 | goto failed; |
| 224 | |
| 225 | if (mp->fd_flags & SESSION_FD_F_MQ_EVENTFD) |
| 226 | { |
| 227 | svm_msg_q_set_consumer_eventfd (wrk->app_event_queue, fds[n_fds]); |
| 228 | vcl_mq_epoll_add_evfd (wrk, wrk->app_event_queue); |
| 229 | n_fds++; |
| 230 | } |
| 231 | |
| 232 | vec_free (fds); |
| 233 | } |
| 234 | else |
| 235 | { |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 236 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 237 | SSVM_SEGMENT_SHM, -1)) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 238 | goto failed; |
| 239 | } |
| 240 | vcm->app_state = STATE_APP_READY; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 241 | VDBG (0, "worker %u vpp-worker %u added", wrk_index, wrk->vpp_wrk_index); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 242 | return; |
| 243 | |
| 244 | failed: |
| 245 | vcm->app_state = STATE_APP_FAILED; |
| 246 | } |
| 247 | |
| 248 | static void |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 249 | vl_api_application_detach_reply_t_handler (vl_api_application_detach_reply_t * |
| 250 | mp) |
| 251 | { |
| 252 | if (mp->retval) |
| 253 | clib_warning ("VCL<%d>: detach failed: %U", getpid (), format_api_error, |
| 254 | ntohl (mp->retval)); |
| 255 | |
| 256 | vcm->app_state = STATE_APP_ENABLED; |
| 257 | } |
| 258 | |
| 259 | static void |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 260 | vl_api_map_another_segment_t_handler (vl_api_map_another_segment_t * mp) |
| 261 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 262 | ssvm_segment_type_t seg_type = SSVM_SEGMENT_SHM; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 263 | u64 segment_handle; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 264 | int fd = -1; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 265 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 266 | if (mp->fd_flags) |
| 267 | { |
| 268 | vl_socket_client_recv_fd_msg (&fd, 1, 5); |
| 269 | seg_type = SSVM_SEGMENT_MEMFD; |
| 270 | } |
| 271 | |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 272 | segment_handle = clib_net_to_host_u64 (mp->segment_handle); |
| 273 | if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) |
| 274 | { |
| 275 | clib_warning ("invalid segment handle"); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | if (vcl_segment_attach (segment_handle, (char *) mp->segment_name, |
| 280 | seg_type, fd)) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 281 | { |
| 282 | clib_warning ("VCL<%d>: svm_fifo_segment_attach ('%s') failed", |
| 283 | getpid (), mp->segment_name); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | VDBG (1, "VCL<%d>: mapped new segment '%s' size %d", getpid (), |
| 288 | mp->segment_name, mp->segment_size); |
| 289 | } |
| 290 | |
| 291 | static void |
| 292 | vl_api_unmap_segment_t_handler (vl_api_unmap_segment_t * mp) |
| 293 | { |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 294 | u64 segment_handle = clib_net_to_host_u64 (mp->segment_handle); |
| 295 | vcl_segment_detach (segment_handle); |
| 296 | VDBG (1, "Unmapped segment: %d", segment_handle); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static void |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 300 | vl_api_bind_sock_reply_t_handler (vl_api_bind_sock_reply_t * mp) |
| 301 | { |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 302 | /* Expecting a similar message on mq. So ignore this */ |
Florin Coras | 6442401 | 2019-03-02 10:47:47 -0800 | [diff] [blame] | 303 | VDBG (0, "bapi bind retval: %u!", mp->retval); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | static void |
| 307 | vl_api_unbind_sock_reply_t_handler (vl_api_unbind_sock_reply_t * mp) |
| 308 | { |
| 309 | if (mp->retval) |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 310 | VDBG (0, "ERROR: sid %u: unbind failed: %U", mp->context, |
| 311 | format_api_error, ntohl (mp->retval)); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 312 | |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 313 | VDBG (1, "sid %u: unbind succeeded!", mp->context); |
| 314 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 317 | static void |
| 318 | vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t * |
| 319 | mp) |
| 320 | { |
| 321 | if (mp->retval) |
Florin Coras | 6442401 | 2019-03-02 10:47:47 -0800 | [diff] [blame] | 322 | VDBG (0, "ERROR: sid %u: disconnect failed: %U", mp->context, |
| 323 | format_api_error, ntohl (mp->retval)); |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void |
Florin Coras | 6442401 | 2019-03-02 10:47:47 -0800 | [diff] [blame] | 327 | vl_api_connect_sock_reply_t_handler (vl_api_connect_sock_reply_t * mp) |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 328 | { |
| 329 | if (mp->retval) |
Florin Coras | 6442401 | 2019-03-02 10:47:47 -0800 | [diff] [blame] | 330 | VDBG (0, "ERROR: connect failed: %U", format_api_error, |
| 331 | ntohl (mp->retval)); |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 334 | static void |
| 335 | vl_api_application_tls_cert_add_reply_t_handler |
| 336 | (vl_api_application_tls_cert_add_reply_t * mp) |
| 337 | { |
| 338 | if (mp->retval) |
| 339 | { |
| 340 | clib_warning ("VCL<%d>: add cert failed: %U", getpid (), |
| 341 | format_api_error, ntohl (mp->retval)); |
| 342 | return; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | static void |
| 347 | vl_api_application_tls_key_add_reply_t_handler |
| 348 | (vl_api_application_tls_key_add_reply_t * mp) |
| 349 | { |
| 350 | if (mp->retval) |
| 351 | { |
| 352 | clib_warning ("VCL<%d>: add key failed: %U", getpid (), |
| 353 | format_api_error, ntohl (mp->retval)); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | } |
| 358 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 359 | #define foreach_sock_msg \ |
| 360 | _(SESSION_ENABLE_DISABLE_REPLY, session_enable_disable_reply) \ |
| 361 | _(BIND_SOCK_REPLY, bind_sock_reply) \ |
| 362 | _(UNBIND_SOCK_REPLY, unbind_sock_reply) \ |
Florin Coras | 6442401 | 2019-03-02 10:47:47 -0800 | [diff] [blame] | 363 | _(CONNECT_SOCK_REPLY, connect_sock_reply) \ |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 364 | _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \ |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 365 | _(APPLICATION_ATTACH_REPLY, application_attach_reply) \ |
| 366 | _(APPLICATION_DETACH_REPLY, application_detach_reply) \ |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 367 | _(APPLICATION_TLS_CERT_ADD_REPLY, application_tls_cert_add_reply) \ |
| 368 | _(APPLICATION_TLS_KEY_ADD_REPLY, application_tls_key_add_reply) \ |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 369 | _(MAP_ANOTHER_SEGMENT, map_another_segment) \ |
| 370 | _(UNMAP_SEGMENT, unmap_segment) \ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 371 | _(APP_WORKER_ADD_DEL_REPLY, app_worker_add_del_reply) \ |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 372 | |
| 373 | void |
| 374 | vppcom_api_hookup (void) |
| 375 | { |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 376 | #define _(N, n) \ |
| 377 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 378 | vl_api_##n##_t_handler, \ |
| 379 | vl_noop_handler, \ |
| 380 | vl_api_##n##_t_endian, \ |
| 381 | vl_api_##n##_t_print, \ |
| 382 | sizeof(vl_api_##n##_t), 1); |
| 383 | foreach_sock_msg; |
| 384 | #undef _ |
| 385 | } |
| 386 | |
| 387 | /* |
| 388 | * VPP-API message functions |
| 389 | */ |
| 390 | void |
| 391 | vppcom_send_session_enable_disable (u8 is_enable) |
| 392 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 393 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 394 | vl_api_session_enable_disable_t *bmp; |
| 395 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 396 | memset (bmp, 0, sizeof (*bmp)); |
| 397 | |
| 398 | bmp->_vl_msg_id = ntohs (VL_API_SESSION_ENABLE_DISABLE); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 399 | bmp->client_index = wrk->my_client_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 400 | bmp->context = htonl (0xfeedface); |
| 401 | bmp->is_enable = is_enable; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 402 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void |
| 406 | vppcom_app_send_attach (void) |
| 407 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 408 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 409 | vl_api_application_attach_t *bmp; |
| 410 | u8 nsid_len = vec_len (vcm->cfg.namespace_id); |
| 411 | u8 app_is_proxy = (vcm->cfg.app_proxy_transport_tcp || |
| 412 | vcm->cfg.app_proxy_transport_udp); |
| 413 | |
| 414 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 415 | memset (bmp, 0, sizeof (*bmp)); |
| 416 | |
| 417 | bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_ATTACH); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 418 | bmp->client_index = wrk->my_client_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 419 | bmp->context = htonl (0xfeedface); |
| 420 | bmp->options[APP_OPTIONS_FLAGS] = |
| 421 | APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT | |
| 422 | (vcm->cfg.app_scope_local ? APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE : 0) | |
| 423 | (vcm->cfg.app_scope_global ? APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE : 0) | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 424 | (app_is_proxy ? APP_OPTIONS_FLAGS_IS_PROXY : 0) | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 425 | (vcm->cfg.use_mq_eventfd ? APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD : 0); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 426 | bmp->options[APP_OPTIONS_PROXY_TRANSPORT] = |
| 427 | (u64) ((vcm->cfg.app_proxy_transport_tcp ? 1 << TRANSPORT_PROTO_TCP : 0) | |
| 428 | (vcm->cfg.app_proxy_transport_udp ? 1 << TRANSPORT_PROTO_UDP : 0)); |
| 429 | bmp->options[APP_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size; |
| 430 | bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size; |
| 431 | bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size; |
| 432 | bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size; |
| 433 | bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = |
| 434 | vcm->cfg.preallocated_fifo_pairs; |
| 435 | bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = vcm->cfg.event_queue_size; |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 436 | bmp->options[APP_OPTIONS_TLS_ENGINE] = TLS_ENGINE_OPENSSL; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 437 | if (nsid_len) |
| 438 | { |
| 439 | bmp->namespace_id_len = nsid_len; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 440 | clib_memcpy_fast (bmp->namespace_id, vcm->cfg.namespace_id, nsid_len); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 441 | bmp->options[APP_OPTIONS_NAMESPACE_SECRET] = vcm->cfg.namespace_secret; |
| 442 | } |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 443 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void |
| 447 | vppcom_app_send_detach (void) |
| 448 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 449 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 450 | vl_api_application_detach_t *bmp; |
| 451 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 452 | memset (bmp, 0, sizeof (*bmp)); |
| 453 | |
| 454 | bmp->_vl_msg_id = ntohs (VL_API_APPLICATION_DETACH); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 455 | bmp->client_index = wrk->my_client_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 456 | bmp->context = htonl (0xfeedface); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 457 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 461 | vcl_send_app_worker_add_del (u8 is_add) |
| 462 | { |
| 463 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 464 | vl_api_app_worker_add_del_t *mp; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 465 | |
| 466 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 467 | memset (mp, 0, sizeof (*mp)); |
| 468 | |
| 469 | mp->_vl_msg_id = ntohs (VL_API_APP_WORKER_ADD_DEL); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 470 | mp->client_index = wrk->my_client_index; |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 471 | mp->app_index = clib_host_to_net_u32 (vcm->app_index); |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 472 | mp->context = wrk->wrk_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 473 | mp->is_add = is_add; |
| 474 | if (!is_add) |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 475 | mp->wrk_index = clib_host_to_net_u32 (wrk->vpp_wrk_index); |
| 476 | |
| 477 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & mp); |
| 478 | } |
| 479 | |
| 480 | void |
| 481 | vcl_send_child_worker_del (vcl_worker_t * child_wrk) |
| 482 | { |
| 483 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 484 | vl_api_app_worker_add_del_t *mp; |
| 485 | |
| 486 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 487 | memset (mp, 0, sizeof (*mp)); |
| 488 | |
| 489 | mp->_vl_msg_id = ntohs (VL_API_APP_WORKER_ADD_DEL); |
| 490 | mp->client_index = wrk->my_client_index; |
| 491 | mp->app_index = clib_host_to_net_u32 (vcm->app_index); |
| 492 | mp->context = wrk->wrk_index; |
| 493 | mp->is_add = 0; |
| 494 | mp->wrk_index = clib_host_to_net_u32 (child_wrk->vpp_wrk_index); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 495 | |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 496 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & mp); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void |
| 500 | vppcom_send_connect_sock (vcl_session_t * session) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 501 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 502 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 503 | vl_api_connect_sock_t *cmp; |
| 504 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 505 | cmp = vl_msg_api_alloc (sizeof (*cmp)); |
| 506 | memset (cmp, 0, sizeof (*cmp)); |
| 507 | cmp->_vl_msg_id = ntohs (VL_API_CONNECT_SOCK); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 508 | cmp->client_index = wrk->my_client_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 509 | cmp->context = session->session_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 510 | cmp->wrk_index = wrk->vpp_wrk_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 511 | cmp->is_ip4 = session->transport.is_ip4; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 512 | clib_memcpy_fast (cmp->ip, &session->transport.rmt_ip, sizeof (cmp->ip)); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 513 | cmp->port = session->transport.rmt_port; |
| 514 | cmp->proto = session->session_type; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 515 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & cmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 519 | vppcom_send_disconnect_session (u64 vpp_handle) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 520 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 521 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 522 | vl_api_disconnect_session_t *dmp; |
| 523 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 524 | dmp = vl_msg_api_alloc (sizeof (*dmp)); |
| 525 | memset (dmp, 0, sizeof (*dmp)); |
| 526 | dmp->_vl_msg_id = ntohs (VL_API_DISCONNECT_SESSION); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 527 | dmp->client_index = wrk->my_client_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 528 | dmp->handle = vpp_handle; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 529 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & dmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /* VPP combines bind and listen as one operation. VCL manages the separation |
| 533 | * of bind and listen locally via vppcom_session_bind() and |
| 534 | * vppcom_session_listen() */ |
| 535 | void |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 536 | vppcom_send_bind_sock (vcl_session_t * session) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 537 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 538 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 539 | vl_api_bind_sock_t *bmp; |
| 540 | |
| 541 | /* Assumes caller has acquired spinlock: vcm->sessions_lockp */ |
| 542 | bmp = vl_msg_api_alloc (sizeof (*bmp)); |
| 543 | memset (bmp, 0, sizeof (*bmp)); |
| 544 | |
| 545 | bmp->_vl_msg_id = ntohs (VL_API_BIND_SOCK); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 546 | bmp->client_index = wrk->my_client_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 547 | bmp->context = session->session_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 548 | bmp->wrk_index = wrk->vpp_wrk_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 549 | bmp->is_ip4 = session->transport.is_ip4; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 550 | clib_memcpy_fast (bmp->ip, &session->transport.lcl_ip, sizeof (bmp->ip)); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 551 | bmp->port = session->transport.lcl_port; |
| 552 | bmp->proto = session->session_type; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 553 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & bmp); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void |
Florin Coras | 2d675d7 | 2019-01-28 15:54:27 -0800 | [diff] [blame] | 557 | vppcom_send_unbind_sock (vcl_worker_t * wrk, u64 vpp_handle) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 558 | { |
| 559 | vl_api_unbind_sock_t *ump; |
| 560 | |
| 561 | ump = vl_msg_api_alloc (sizeof (*ump)); |
| 562 | memset (ump, 0, sizeof (*ump)); |
| 563 | |
| 564 | ump->_vl_msg_id = ntohs (VL_API_UNBIND_SOCK); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 565 | ump->client_index = wrk->my_client_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 566 | ump->wrk_index = wrk->vpp_wrk_index; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 567 | ump->handle = vpp_handle; |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 568 | ump->context = wrk->wrk_index; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 569 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & ump); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | void |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 573 | vppcom_send_application_tls_cert_add (vcl_session_t * session, char *cert, |
| 574 | u32 cert_len) |
| 575 | { |
| 576 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 577 | vl_api_application_tls_cert_add_t *cert_mp; |
| 578 | |
| 579 | cert_mp = vl_msg_api_alloc (sizeof (*cert_mp) + cert_len); |
| 580 | clib_memset (cert_mp, 0, sizeof (*cert_mp)); |
| 581 | cert_mp->_vl_msg_id = ntohs (VL_API_APPLICATION_TLS_CERT_ADD); |
| 582 | cert_mp->client_index = wrk->my_client_index; |
| 583 | cert_mp->context = session->session_index; |
| 584 | cert_mp->cert_len = clib_host_to_net_u16 (cert_len); |
| 585 | clib_memcpy_fast (cert_mp->cert, cert, cert_len); |
| 586 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & cert_mp); |
| 587 | |
| 588 | } |
| 589 | |
| 590 | void |
| 591 | vppcom_send_application_tls_key_add (vcl_session_t * session, char *key, |
| 592 | u32 key_len) |
| 593 | { |
| 594 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 595 | vl_api_application_tls_key_add_t *key_mp; |
| 596 | |
| 597 | key_mp = vl_msg_api_alloc (sizeof (*key_mp) + key_len); |
| 598 | clib_memset (key_mp, 0, sizeof (*key_mp)); |
| 599 | key_mp->_vl_msg_id = ntohs (VL_API_APPLICATION_TLS_KEY_ADD); |
| 600 | key_mp->client_index = wrk->my_client_index; |
| 601 | key_mp->context = session->session_index; |
| 602 | key_mp->key_len = clib_host_to_net_u16 (key_len); |
| 603 | clib_memcpy_fast (key_mp->key, key, key_len); |
| 604 | vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & key_mp); |
| 605 | |
| 606 | } |
| 607 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 608 | u32 |
| 609 | vcl_max_nsid_len (void) |
| 610 | { |
| 611 | vl_api_application_attach_t *mp; |
| 612 | return (sizeof (mp->namespace_id) - 1); |
| 613 | } |
| 614 | |
| 615 | void |
| 616 | vppcom_init_error_string_table (void) |
| 617 | { |
| 618 | vcm->error_string_by_error_number = hash_create (0, sizeof (uword)); |
| 619 | |
| 620 | #define _(n, v, s) hash_set (vcm->error_string_by_error_number, -v, s); |
| 621 | foreach_vnet_api_error; |
| 622 | #undef _ |
| 623 | |
| 624 | hash_set (vcm->error_string_by_error_number, 99, "Misc"); |
| 625 | } |
| 626 | |
| 627 | int |
| 628 | vppcom_connect_to_vpp (char *app_name) |
| 629 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 630 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 631 | api_main_t *am = &api_main; |
| 632 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 633 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 634 | if (vcl_cfg->vpp_api_socket_name) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 635 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 636 | if (vl_socket_client_connect ((char *) vcl_cfg->vpp_api_socket_name, |
| 637 | app_name, 0 /* default rx/tx buffer */ )) |
| 638 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 639 | VERR ("app (%s) socket connect failed!", app_name); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 640 | return VPPCOM_ECONNREFUSED; |
| 641 | } |
| 642 | |
Tomasz Kulasek | 97dcf5b | 2019-01-31 18:26:32 +0100 | [diff] [blame] | 643 | if (vl_socket_client_init_shm (0, 1 /* want_pthread */ )) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 644 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 645 | VERR ("app (%s) init shm failed!", app_name); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 646 | return VPPCOM_ECONNREFUSED; |
| 647 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 648 | } |
| 649 | else |
| 650 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 651 | if (!vcl_cfg->vpp_api_filename) |
| 652 | vcl_cfg->vpp_api_filename = format (0, "/vpe-api%c", 0); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 653 | |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 654 | VDBG (0, "app (%s) connecting to VPP api (%s)...", |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 655 | app_name, vcl_cfg->vpp_api_filename); |
| 656 | |
| 657 | if (vl_client_connect_to_vlib ((char *) vcl_cfg->vpp_api_filename, |
| 658 | app_name, vcm->cfg.vpp_api_q_length) < 0) |
| 659 | { |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 660 | VERR ("app (%s) connect failed!", app_name); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 661 | return VPPCOM_ECONNREFUSED; |
| 662 | } |
| 663 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 666 | wrk->vl_input_queue = am->shmem_hdr->vl_input_queue; |
| 667 | wrk->my_client_index = (u32) am->my_client_index; |
| 668 | wrk->wrk_state = STATE_APP_CONN_VPP; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 669 | |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 670 | VDBG (0, "app (%s) is connected to VPP!", app_name); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 671 | vcl_evt (VCL_EVT_INIT, vcm); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 672 | return VPPCOM_OK; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /* |
| 676 | * fd.io coding-style-patch-verification: ON |
| 677 | * |
| 678 | * Local Variables: |
| 679 | * eval: (c-set-style "gnu") |
| 680 | * End: |
| 681 | */ |