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