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