Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2019 Cisco and/or its affiliates. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vnet/vnet.h> |
| 17 | #include <vlibmemory/api.h> |
| 18 | #include <vnet/session/application.h> |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 19 | #include <vnet/session/application_interface.h> |
| 20 | #include <vnet/session/session_rules_table.h> |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 21 | #include <vnet/session/session_table.h> |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 22 | #include <vnet/session/session.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 23 | |
| 24 | #include <vnet/vnet_msg_enum.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 25 | |
| 26 | #define vl_typedefs /* define message structures */ |
| 27 | #include <vnet/vnet_all_api_h.h> |
| 28 | #undef vl_typedefs |
| 29 | |
| 30 | #define vl_endianfun /* define message structures */ |
| 31 | #include <vnet/vnet_all_api_h.h> |
| 32 | #undef vl_endianfun |
| 33 | |
| 34 | /* instantiate all the print functions we know about */ |
| 35 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 36 | #define vl_printfun |
| 37 | #include <vnet/vnet_all_api_h.h> |
| 38 | #undef vl_printfun |
| 39 | |
| 40 | #include <vlibapi/api_helper_macros.h> |
| 41 | |
| 42 | #define foreach_session_api_msg \ |
| 43 | _(MAP_ANOTHER_SEGMENT_REPLY, map_another_segment_reply) \ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 44 | _(APPLICATION_ATTACH, application_attach) \ |
| 45 | _(APPLICATION_DETACH, application_detach) \ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 46 | _(BIND_URI, bind_uri) \ |
| 47 | _(UNBIND_URI, unbind_uri) \ |
| 48 | _(CONNECT_URI, connect_uri) \ |
| 49 | _(DISCONNECT_SESSION, disconnect_session) \ |
| 50 | _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \ |
| 51 | _(ACCEPT_SESSION_REPLY, accept_session_reply) \ |
| 52 | _(RESET_SESSION_REPLY, reset_session_reply) \ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 53 | _(BIND_SOCK, bind_sock) \ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 54 | _(UNBIND_SOCK, unbind_sock) \ |
| 55 | _(CONNECT_SOCK, connect_sock) \ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 56 | _(SESSION_ENABLE_DISABLE, session_enable_disable) \ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 57 | _(APP_NAMESPACE_ADD_DEL, app_namespace_add_del) \ |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 58 | _(SESSION_RULE_ADD_DEL, session_rule_add_del) \ |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 59 | _(SESSION_RULES_DUMP, session_rules_dump) \ |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 60 | _(APPLICATION_TLS_CERT_ADD, application_tls_cert_add) \ |
| 61 | _(APPLICATION_TLS_KEY_ADD, application_tls_key_add) \ |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 62 | _(APP_WORKER_ADD_DEL, app_worker_add_del) \ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 63 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 64 | static int |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 65 | session_send_fds (vl_api_registration_t * reg, int fds[], int n_fds) |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 66 | { |
| 67 | clib_error_t *error; |
| 68 | if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
| 69 | { |
| 70 | clib_warning ("can't send memfd fd"); |
| 71 | return -1; |
| 72 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 73 | error = vl_api_send_fd_msg (reg, fds, n_fds); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 74 | if (error) |
| 75 | { |
| 76 | clib_error_report (error); |
| 77 | return -1; |
| 78 | } |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static int |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 83 | send_add_segment_callback (u32 api_client_index, u64 segment_handle) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 84 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 85 | int fds[SESSION_N_FD_TYPE], n_fds = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 86 | vl_api_map_another_segment_t *mp; |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 87 | svm_fifo_segment_private_t *fs; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 88 | vl_api_registration_t *reg; |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 89 | ssvm_private_t *sp; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 90 | u8 fd_flags = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 91 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 92 | reg = vl_mem_api_client_index_to_registration (api_client_index); |
| 93 | if (!reg) |
| 94 | { |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 95 | clib_warning ("no api registration for client: %u", api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 96 | return -1; |
| 97 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 98 | |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 99 | fs = segment_manager_get_segment_w_handle (segment_handle); |
| 100 | sp = &fs->ssvm; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 101 | if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD) |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 102 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 103 | if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
| 104 | { |
| 105 | clib_warning ("can't send memfd fd"); |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 110 | fds[n_fds] = sp->fd; |
| 111 | n_fds += 1; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 112 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 113 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 114 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 115 | clib_memset (mp, 0, sizeof (*mp)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 116 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MAP_ANOTHER_SEGMENT); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 117 | mp->segment_size = sp->ssvm_size; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 118 | mp->fd_flags = fd_flags; |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 119 | mp->segment_handle = clib_host_to_net_u64 (segment_handle); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 120 | strncpy ((char *) mp->segment_name, (char *) sp->name, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 121 | sizeof (mp->segment_name) - 1); |
| 122 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 123 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
| 124 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 125 | if (n_fds) |
| 126 | return session_send_fds (reg, fds, n_fds); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | static int |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 132 | send_del_segment_callback (u32 api_client_index, u64 segment_handle) |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 133 | { |
| 134 | vl_api_unmap_segment_t *mp; |
| 135 | vl_api_registration_t *reg; |
| 136 | |
| 137 | reg = vl_mem_api_client_index_to_registration (api_client_index); |
| 138 | if (!reg) |
| 139 | { |
| 140 | clib_warning ("no registration: %u", api_client_index); |
| 141 | return -1; |
| 142 | } |
| 143 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 144 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 145 | clib_memset (mp, 0, sizeof (*mp)); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 146 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_UNMAP_SEGMENT); |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 147 | mp->segment_handle = clib_host_to_net_u64 (segment_handle); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 148 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
| 149 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 154 | send_app_cut_through_registration_add (u32 api_client_index, |
| 155 | u32 wrk_map_index, u64 mq_addr, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 156 | u64 peer_mq_addr) |
| 157 | { |
| 158 | vl_api_app_cut_through_registration_add_t *mp; |
| 159 | vl_api_registration_t *reg; |
| 160 | svm_msg_q_t *mq, *peer_mq; |
| 161 | int fds[2]; |
| 162 | |
| 163 | reg = vl_mem_api_client_index_to_registration (api_client_index); |
| 164 | if (!reg) |
| 165 | { |
| 166 | clib_warning ("no registration: %u", api_client_index); |
| 167 | return -1; |
| 168 | } |
| 169 | |
| 170 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 171 | clib_memset (mp, 0, sizeof (*mp)); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 172 | mp->_vl_msg_id = |
| 173 | clib_host_to_net_u16 (VL_API_APP_CUT_THROUGH_REGISTRATION_ADD); |
| 174 | |
| 175 | mp->evt_q_address = mq_addr; |
| 176 | mp->peer_evt_q_address = peer_mq_addr; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 177 | mp->wrk_index = wrk_map_index; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 178 | |
| 179 | mq = uword_to_pointer (mq_addr, svm_msg_q_t *); |
| 180 | peer_mq = uword_to_pointer (peer_mq_addr, svm_msg_q_t *); |
| 181 | |
| 182 | if (svm_msg_q_get_producer_eventfd (mq) != -1) |
| 183 | { |
| 184 | mp->fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
| 185 | mp->n_fds = 2; |
| 186 | /* app will overwrite exactly the fds we pass here. So |
| 187 | * when we swap mq with peer_mq (accept vs connect) the |
| 188 | * fds will still be valid */ |
| 189 | fds[0] = svm_msg_q_get_consumer_eventfd (mq); |
| 190 | fds[1] = svm_msg_q_get_producer_eventfd (peer_mq); |
| 191 | } |
| 192 | |
| 193 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
| 194 | |
| 195 | if (mp->n_fds != 0) |
| 196 | session_send_fds (reg, fds, mp->n_fds); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 202 | send_session_accept_callback (session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 203 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 204 | app_worker_t *server_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 205 | vl_api_accept_session_t *mp; |
| 206 | vl_api_registration_t *reg; |
| 207 | transport_connection_t *tc; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 208 | session_t *listener; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 209 | svm_msg_q_t *vpp_queue; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 210 | application_t *server; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 211 | app_listener_t *al; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 212 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 213 | server = application_get (server_wrk->app_index); |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 214 | reg = |
| 215 | vl_mem_api_client_index_to_registration (server_wrk->api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 216 | if (!reg) |
| 217 | { |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 218 | clib_warning ("no registration: %u", server_wrk->api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 219 | return -1; |
| 220 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 221 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 222 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 223 | clib_memset (mp, 0, sizeof (*mp)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 224 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 225 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 226 | mp->context = server_wrk->wrk_index; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 227 | mp->server_rx_fifo = pointer_to_uword (s->rx_fifo); |
| 228 | mp->server_tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 229 | |
| 230 | if (session_has_transport (s)) |
| 231 | { |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 232 | listener = listen_session_get (s->listener_index); |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 233 | al = app_listener_get (server, listener->al_index); |
| 234 | mp->listener_handle = app_listener_handle (al); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 235 | if (application_is_proxy (server)) |
| 236 | { |
| 237 | listener = |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 238 | app_worker_first_listener (server_wrk, session_get_fib_proto (s), |
| 239 | session_get_transport_proto (s)); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 240 | if (listener) |
| 241 | mp->listener_handle = listen_session_get_handle (listener); |
| 242 | } |
| 243 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 244 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 245 | mp->handle = session_handle (s); |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 246 | tc = transport_get_connection (session_get_transport_proto (s), |
| 247 | s->connection_index, s->thread_index); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 248 | mp->port = tc->rmt_port; |
| 249 | mp->is_ip4 = tc->is_ip4; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 250 | clib_memcpy_fast (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip)); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 251 | } |
| 252 | else |
| 253 | { |
| 254 | local_session_t *ls = (local_session_t *) s; |
| 255 | local_session_t *ll; |
| 256 | if (application_local_session_listener_has_transport (ls)) |
| 257 | { |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 258 | listener = listen_session_get (ls->listener_index); |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 259 | al = app_listener_get (server, listener->al_index); |
| 260 | mp->listener_handle = app_listener_handle (al); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 261 | mp->is_ip4 = session_type_is_ip4 (listener->session_type); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 262 | } |
| 263 | else |
| 264 | { |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 265 | ll = application_get_local_listen_session (server, |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 266 | ls->listener_index); |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 267 | al = app_listener_get (server, ll->al_index); |
| 268 | mp->listener_handle = app_listener_handle (al); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 269 | mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 270 | } |
| 271 | mp->handle = application_local_session_handle (ls); |
| 272 | mp->port = ls->port; |
| 273 | mp->vpp_event_queue_address = ls->client_evt_q; |
| 274 | mp->server_event_queue_address = ls->server_evt_q; |
| 275 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 276 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 282 | send_session_disconnect_callback (session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 283 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 284 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 285 | vl_api_disconnect_session_t *mp; |
| 286 | vl_api_registration_t *reg; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 287 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 288 | reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 289 | if (!reg) |
| 290 | { |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 291 | clib_warning ("no registration: %u", app_wrk->api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 292 | return; |
| 293 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 294 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 295 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 296 | clib_memset (mp, 0, sizeof (*mp)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 297 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 298 | mp->handle = session_handle (s); |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 299 | mp->context = app_wrk->api_client_index; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 300 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 301 | } |
| 302 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 303 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 304 | send_session_reset_callback (session_t * s) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 305 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 306 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 307 | vl_api_registration_t *reg; |
| 308 | vl_api_reset_session_t *mp; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 309 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 310 | reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 311 | if (!reg) |
| 312 | { |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 313 | clib_warning ("no registration: %u", app_wrk->api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 314 | return; |
| 315 | } |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 316 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 317 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 318 | clib_memset (mp, 0, sizeof (*mp)); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 319 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_RESET_SESSION); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 320 | mp->handle = session_handle (s); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 321 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Dave Barach | 0194f1a | 2017-05-15 10:11:39 -0400 | [diff] [blame] | 324 | int |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 325 | send_session_connected_callback (u32 app_wrk_index, u32 api_context, |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 326 | session_t * s, u8 is_fail) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 327 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 328 | vl_api_connect_session_reply_t *mp; |
Florin Coras | ade70e4 | 2017-10-14 18:56:41 -0700 | [diff] [blame] | 329 | transport_connection_t *tc; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 330 | vl_api_registration_t *reg; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 331 | svm_msg_q_t *vpp_queue; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 332 | app_worker_t *app_wrk; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 333 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 334 | app_wrk = app_worker_get (app_wrk_index); |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 335 | reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 336 | if (!reg) |
| 337 | { |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 338 | clib_warning ("no registration: %u", app_wrk->api_client_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 339 | return -1; |
| 340 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 341 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 342 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 343 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 344 | mp->context = api_context; |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 345 | |
| 346 | if (is_fail) |
| 347 | goto done; |
| 348 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 349 | if (session_has_transport (s)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 350 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 351 | tc = session_get_transport (s); |
| 352 | if (!tc) |
| 353 | { |
| 354 | is_fail = 1; |
| 355 | goto done; |
| 356 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 357 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 358 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 359 | mp->handle = session_handle (s); |
| 360 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 361 | clib_memcpy_fast (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 362 | mp->is_ip4 = tc->is_ip4; |
| 363 | mp->lcl_port = tc->lcl_port; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 364 | mp->server_rx_fifo = pointer_to_uword (s->rx_fifo); |
| 365 | mp->server_tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 366 | } |
| 367 | else |
| 368 | { |
| 369 | local_session_t *ls = (local_session_t *) s; |
| 370 | mp->handle = application_local_session_handle (ls); |
| 371 | mp->lcl_port = ls->port; |
| 372 | mp->vpp_event_queue_address = ls->server_evt_q; |
| 373 | mp->client_event_queue_address = ls->client_evt_q; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 374 | mp->server_rx_fifo = pointer_to_uword (s->tx_fifo); |
| 375 | mp->server_tx_fifo = pointer_to_uword (s->rx_fifo); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 376 | } |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 377 | |
| 378 | done: |
| 379 | mp->retval = is_fail ? |
| 380 | clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 381 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 382 | return 0; |
| 383 | } |
| 384 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 385 | static session_cb_vft_t session_cb_vft = { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 386 | .session_accept_callback = send_session_accept_callback, |
| 387 | .session_disconnect_callback = send_session_disconnect_callback, |
| 388 | .session_connected_callback = send_session_connected_callback, |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 389 | .session_reset_callback = send_session_reset_callback, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 390 | .add_segment_callback = send_add_segment_callback, |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 391 | .del_segment_callback = send_del_segment_callback, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 392 | }; |
| 393 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 394 | static int |
Florin Coras | 83ea669 | 2018-10-12 16:55:14 -0700 | [diff] [blame] | 395 | mq_try_lock_and_alloc_msg (svm_msg_q_t * app_mq, svm_msg_q_msg_t * msg) |
| 396 | { |
| 397 | int rv; |
| 398 | u8 try = 0; |
| 399 | while (try < 100) |
| 400 | { |
| 401 | rv = svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, |
| 402 | SESSION_MQ_CTRL_EVT_RING, |
| 403 | SVM_Q_NOWAIT, msg); |
| 404 | if (!rv) |
| 405 | return 0; |
| 406 | try++; |
Florin Coras | e2ea193 | 2018-12-17 23:08:14 -0800 | [diff] [blame] | 407 | usleep (1); |
Florin Coras | 83ea669 | 2018-10-12 16:55:14 -0700 | [diff] [blame] | 408 | } |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 409 | clib_warning ("failed to alloc msg"); |
Florin Coras | 83ea669 | 2018-10-12 16:55:14 -0700 | [diff] [blame] | 410 | return -1; |
| 411 | } |
| 412 | |
| 413 | static int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 414 | mq_send_session_accepted_cb (session_t * s) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 415 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 416 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 417 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 418 | svm_msg_q_t *vpp_queue, *app_mq; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 419 | transport_connection_t *tc; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 420 | session_t *listener; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 421 | session_accepted_msg_t *mp; |
| 422 | session_event_t *evt; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 423 | application_t *app; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 424 | app_listener_t *al; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 425 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 426 | app = application_get (app_wrk->app_index); |
| 427 | app_mq = app_wrk->event_queue; |
Florin Coras | 83ea669 | 2018-10-12 16:55:14 -0700 | [diff] [blame] | 428 | if (mq_try_lock_and_alloc_msg (app_mq, msg)) |
| 429 | return -1; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 430 | |
| 431 | evt = svm_msg_q_msg_data (app_mq, msg); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 432 | clib_memset (evt, 0, sizeof (*evt)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 433 | evt->event_type = SESSION_CTRL_EVT_ACCEPTED; |
| 434 | mp = (session_accepted_msg_t *) evt->data; |
Florin Coras | 87c6570 | 2019-01-26 14:33:26 -0800 | [diff] [blame] | 435 | clib_memset (mp, 0, sizeof (*mp)); |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 436 | mp->context = app->app_index; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 437 | mp->server_rx_fifo = pointer_to_uword (s->rx_fifo); |
| 438 | mp->server_tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 439 | mp->segment_handle = session_segment_handle (s); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 440 | |
| 441 | if (session_has_transport (s)) |
| 442 | { |
| 443 | listener = listen_session_get (s->listener_index); |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 444 | al = app_listener_get (app, listener->al_index); |
| 445 | mp->listener_handle = app_listener_handle (al); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 446 | if (application_is_proxy (app)) |
| 447 | { |
| 448 | listener = |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 449 | app_worker_first_listener (app_wrk, session_get_fib_proto (s), |
| 450 | session_get_transport_proto (s)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 451 | if (listener) |
| 452 | mp->listener_handle = listen_session_get_handle (listener); |
| 453 | } |
| 454 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 455 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 456 | mp->handle = session_handle (s); |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 457 | tc = transport_get_connection (session_get_transport_proto (s), |
| 458 | s->connection_index, s->thread_index); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 459 | mp->port = tc->rmt_port; |
| 460 | mp->is_ip4 = tc->is_ip4; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 461 | clib_memcpy_fast (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 462 | } |
| 463 | else |
| 464 | { |
| 465 | local_session_t *ls = (local_session_t *) s; |
| 466 | local_session_t *ll; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 467 | u8 main_thread = vlib_num_workers ()? 1 : 0; |
| 468 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 469 | send_app_cut_through_registration_add (app_wrk->api_client_index, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 470 | app_wrk->wrk_map_index, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 471 | ls->server_evt_q, |
| 472 | ls->client_evt_q); |
| 473 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 474 | if (application_local_session_listener_has_transport (ls)) |
| 475 | { |
| 476 | listener = listen_session_get (ls->listener_index); |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 477 | al = app_listener_get (app, listener->al_index); |
| 478 | mp->listener_handle = app_listener_handle (al); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 479 | mp->is_ip4 = session_type_is_ip4 (listener->session_type); |
| 480 | } |
| 481 | else |
| 482 | { |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 483 | ll = application_get_local_listen_session (app, ls->listener_index); |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 484 | al = app_listener_get (app, ll->al_index); |
| 485 | mp->listener_handle = app_listener_handle (al); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 486 | mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type); |
| 487 | } |
| 488 | mp->handle = application_local_session_handle (ls); |
| 489 | mp->port = ls->port; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 490 | vpp_queue = session_manager_get_vpp_event_queue (main_thread); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 491 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 492 | mp->client_event_queue_address = ls->client_evt_q; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 493 | mp->server_event_queue_address = ls->server_evt_q; |
| 494 | } |
Florin Coras | 537b17e | 2018-09-28 10:35:45 -0700 | [diff] [blame] | 495 | svm_msg_q_add_and_unlock (app_mq, msg); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 500 | static inline void |
| 501 | mq_send_session_close_evt (app_worker_t * app_wrk, session_handle_t sh, |
| 502 | session_evt_type_t evt_type) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 503 | { |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 504 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 505 | session_disconnected_msg_t *mp; |
| 506 | svm_msg_q_t *app_mq; |
| 507 | session_event_t *evt; |
| 508 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 509 | app_mq = app_wrk->event_queue; |
Florin Coras | 83ea669 | 2018-10-12 16:55:14 -0700 | [diff] [blame] | 510 | if (mq_try_lock_and_alloc_msg (app_mq, msg)) |
| 511 | return; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 512 | evt = svm_msg_q_msg_data (app_mq, msg); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 513 | clib_memset (evt, 0, sizeof (*evt)); |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 514 | evt->event_type = evt_type; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 515 | mp = (session_disconnected_msg_t *) evt->data; |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 516 | mp->handle = sh; |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 517 | mp->context = app_wrk->api_client_index; |
Florin Coras | 537b17e | 2018-09-28 10:35:45 -0700 | [diff] [blame] | 518 | svm_msg_q_add_and_unlock (app_mq, msg); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 521 | static inline void |
| 522 | mq_notify_close_subscribers (u32 app_index, session_handle_t sh, |
| 523 | svm_fifo_t * f, session_evt_type_t evt_type) |
| 524 | { |
| 525 | app_worker_t *app_wrk; |
| 526 | application_t *app; |
| 527 | int i; |
| 528 | |
| 529 | app = application_get (app_index); |
| 530 | if (!app) |
| 531 | return; |
| 532 | |
| 533 | for (i = 0; i < f->n_subscribers; i++) |
| 534 | { |
| 535 | if (!(app_wrk = application_get_worker (app, f->subscribers[i]))) |
| 536 | continue; |
| 537 | mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_DISCONNECTED); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 542 | mq_send_session_disconnected_cb (session_t * s) |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 543 | { |
| 544 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
| 545 | session_handle_t sh = session_handle (s); |
| 546 | |
| 547 | mq_send_session_close_evt (app_wrk, session_handle (s), |
| 548 | SESSION_CTRL_EVT_DISCONNECTED); |
| 549 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 550 | if (svm_fifo_n_subscribers (s->rx_fifo)) |
| 551 | mq_notify_close_subscribers (app_wrk->app_index, sh, s->rx_fifo, |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 552 | SESSION_CTRL_EVT_DISCONNECTED); |
| 553 | } |
| 554 | |
Florin Coras | aa27eb9 | 2018-10-13 12:20:01 -0700 | [diff] [blame] | 555 | void |
| 556 | mq_send_local_session_disconnected_cb (u32 app_wrk_index, |
| 557 | local_session_t * ls) |
| 558 | { |
| 559 | app_worker_t *app_wrk = app_worker_get (app_wrk_index); |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 560 | session_handle_t sh = application_local_session_handle (ls); |
Florin Coras | aa27eb9 | 2018-10-13 12:20:01 -0700 | [diff] [blame] | 561 | |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 562 | mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_DISCONNECTED); |
| 563 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 564 | if (svm_fifo_n_subscribers (ls->rx_fifo)) |
| 565 | mq_notify_close_subscribers (app_wrk->app_index, sh, ls->rx_fifo, |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 566 | SESSION_CTRL_EVT_DISCONNECTED); |
Florin Coras | aa27eb9 | 2018-10-13 12:20:01 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 569 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 570 | mq_send_session_reset_cb (session_t * s) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 571 | { |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 572 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
| 573 | session_handle_t sh = session_handle (s); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 574 | |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 575 | mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_RESET); |
| 576 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 577 | if (svm_fifo_n_subscribers (s->rx_fifo)) |
| 578 | mq_notify_close_subscribers (app_wrk->app_index, sh, s->rx_fifo, |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 579 | SESSION_CTRL_EVT_RESET); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | static int |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 583 | mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context, |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 584 | session_t * s, u8 is_fail) |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 585 | { |
| 586 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 587 | session_connected_msg_t *mp; |
| 588 | svm_msg_q_t *vpp_mq, *app_mq; |
| 589 | transport_connection_t *tc; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 590 | app_worker_t *app_wrk; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 591 | session_event_t *evt; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 592 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 593 | app_wrk = app_worker_get (app_wrk_index); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 594 | app_mq = app_wrk->event_queue; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 595 | if (!app_mq) |
| 596 | { |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 597 | clib_warning ("app %u with api index: %u not attached", |
| 598 | app_wrk->app_index, app_wrk->api_client_index); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 599 | return -1; |
| 600 | } |
| 601 | |
Florin Coras | 83ea669 | 2018-10-12 16:55:14 -0700 | [diff] [blame] | 602 | if (mq_try_lock_and_alloc_msg (app_mq, msg)) |
| 603 | return -1; |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 604 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 605 | evt = svm_msg_q_msg_data (app_mq, msg); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 606 | clib_memset (evt, 0, sizeof (*evt)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 607 | evt->event_type = SESSION_CTRL_EVT_CONNECTED; |
| 608 | mp = (session_connected_msg_t *) evt->data; |
Florin Coras | 87c6570 | 2019-01-26 14:33:26 -0800 | [diff] [blame] | 609 | clib_memset (mp, 0, sizeof (*mp)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 610 | mp->context = api_context; |
| 611 | |
| 612 | if (is_fail) |
| 613 | goto done; |
| 614 | |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 615 | mp->segment_handle = session_segment_handle (s); |
| 616 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 617 | if (session_has_transport (s)) |
| 618 | { |
| 619 | tc = session_get_transport (s); |
| 620 | if (!tc) |
| 621 | { |
| 622 | is_fail = 1; |
| 623 | goto done; |
| 624 | } |
| 625 | |
| 626 | vpp_mq = session_manager_get_vpp_event_queue (s->thread_index); |
| 627 | mp->handle = session_handle (s); |
| 628 | mp->vpp_event_queue_address = pointer_to_uword (vpp_mq); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 629 | clib_memcpy_fast (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 630 | mp->is_ip4 = tc->is_ip4; |
| 631 | mp->lcl_port = tc->lcl_port; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 632 | mp->server_rx_fifo = pointer_to_uword (s->rx_fifo); |
| 633 | mp->server_tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 634 | } |
| 635 | else |
| 636 | { |
| 637 | local_session_t *ls = (local_session_t *) s; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 638 | u8 main_thread = vlib_num_workers ()? 1 : 0; |
| 639 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 640 | send_app_cut_through_registration_add (app_wrk->api_client_index, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 641 | app_wrk->wrk_map_index, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 642 | ls->client_evt_q, |
| 643 | ls->server_evt_q); |
| 644 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 645 | mp->handle = application_local_session_handle (ls); |
| 646 | mp->lcl_port = ls->port; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 647 | vpp_mq = session_manager_get_vpp_event_queue (main_thread); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 648 | mp->vpp_event_queue_address = pointer_to_uword (vpp_mq); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 649 | mp->client_event_queue_address = ls->client_evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 650 | mp->server_event_queue_address = ls->server_evt_q; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 651 | mp->server_rx_fifo = pointer_to_uword (s->tx_fifo); |
| 652 | mp->server_tx_fifo = pointer_to_uword (s->rx_fifo); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | done: |
| 656 | mp->retval = is_fail ? |
| 657 | clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0; |
| 658 | |
Florin Coras | 537b17e | 2018-09-28 10:35:45 -0700 | [diff] [blame] | 659 | svm_msg_q_add_and_unlock (app_mq, msg); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 660 | return 0; |
| 661 | } |
| 662 | |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 663 | static int |
| 664 | mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context, |
| 665 | session_handle_t handle, int rv) |
| 666 | { |
| 667 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 668 | svm_msg_q_t *app_mq, *vpp_evt_q; |
| 669 | transport_connection_t *tc; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 670 | session_bound_msg_t *mp; |
| 671 | app_worker_t *app_wrk; |
| 672 | session_event_t *evt; |
| 673 | application_t *app; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 674 | app_listener_t *al; |
| 675 | session_t *ls = 0; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 676 | |
| 677 | app_wrk = app_worker_get (app_wrk_index); |
| 678 | app = application_get (app_wrk->app_index); |
| 679 | app_mq = app_wrk->event_queue; |
| 680 | if (!app_mq) |
| 681 | { |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 682 | clib_warning ("app %u with api index: %u not attached", |
| 683 | app_wrk->app_index, app_wrk->api_client_index); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 684 | return -1; |
| 685 | } |
| 686 | |
Florin Coras | 83ea669 | 2018-10-12 16:55:14 -0700 | [diff] [blame] | 687 | if (mq_try_lock_and_alloc_msg (app_mq, msg)) |
| 688 | return -1; |
| 689 | |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 690 | evt = svm_msg_q_msg_data (app_mq, msg); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 691 | clib_memset (evt, 0, sizeof (*evt)); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 692 | evt->event_type = SESSION_CTRL_EVT_BOUND; |
| 693 | mp = (session_bound_msg_t *) evt->data; |
| 694 | mp->context = api_context; |
| 695 | |
| 696 | if (rv) |
| 697 | goto done; |
| 698 | |
| 699 | mp->handle = handle; |
| 700 | if (application_has_global_scope (app)) |
| 701 | { |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 702 | al = app_listener_get_w_handle (handle); |
| 703 | ls = app_listener_get_session (al); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 704 | tc = listen_session_get_transport (ls); |
| 705 | mp->lcl_port = tc->lcl_port; |
| 706 | mp->lcl_is_ip4 = tc->is_ip4; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 707 | clib_memcpy_fast (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 708 | } |
| 709 | else |
| 710 | { |
| 711 | local_session_t *local; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 712 | local = application_get_local_listener_w_handle (handle); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 713 | mp->lcl_port = local->port; |
| 714 | mp->lcl_is_ip4 = session_type_is_ip4 (local->session_type); |
| 715 | } |
| 716 | |
Florin Coras | 5f45e01 | 2019-01-23 09:21:30 -0800 | [diff] [blame] | 717 | vpp_evt_q = session_manager_get_vpp_event_queue (0); |
| 718 | mp->vpp_evt_q = pointer_to_uword (vpp_evt_q); |
| 719 | |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 720 | if (ls && session_transport_service_type (ls) == TRANSPORT_SERVICE_CL) |
| 721 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 722 | mp->rx_fifo = pointer_to_uword (ls->rx_fifo); |
| 723 | mp->tx_fifo = pointer_to_uword (ls->tx_fifo); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | done: |
| 727 | mp->retval = rv; |
Florin Coras | 537b17e | 2018-09-28 10:35:45 -0700 | [diff] [blame] | 728 | svm_msg_q_add_and_unlock (app_mq, msg); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 732 | static session_cb_vft_t session_mq_cb_vft = { |
| 733 | .session_accept_callback = mq_send_session_accepted_cb, |
| 734 | .session_disconnect_callback = mq_send_session_disconnected_cb, |
| 735 | .session_connected_callback = mq_send_session_connected_cb, |
| 736 | .session_reset_callback = mq_send_session_reset_cb, |
| 737 | .add_segment_callback = send_add_segment_callback, |
| 738 | .del_segment_callback = send_del_segment_callback, |
| 739 | }; |
| 740 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 741 | static void |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 742 | vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp) |
| 743 | { |
| 744 | vl_api_session_enable_disable_reply_t *rmp; |
| 745 | vlib_main_t *vm = vlib_get_main (); |
| 746 | int rv = 0; |
| 747 | |
| 748 | vnet_session_enable_disable (vm, mp->is_enable); |
| 749 | REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY); |
| 750 | } |
| 751 | |
| 752 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 753 | vl_api_application_attach_t_handler (vl_api_application_attach_t * mp) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 754 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 755 | int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 756 | vl_api_application_attach_reply_t *rmp; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 757 | ssvm_private_t *segp, *evt_q_segment; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 758 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 759 | vl_api_registration_t *reg; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 760 | u8 fd_flags = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 761 | |
Florin Coras | fc804d9 | 2018-01-26 01:27:01 -0800 | [diff] [blame] | 762 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 763 | if (!reg) |
| 764 | return; |
| 765 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 766 | if (session_manager_is_enabled () == 0) |
| 767 | { |
| 768 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 769 | goto done; |
| 770 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 771 | |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 772 | STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <= |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 773 | sizeof (mp->options), |
| 774 | "Out of options, fix api message definition"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 775 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 776 | clib_memset (a, 0, sizeof (*a)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 777 | a->api_client_index = mp->client_index; |
| 778 | a->options = mp->options; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 779 | |
| 780 | if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS) |
| 781 | a->session_cb_vft = &session_mq_cb_vft; |
| 782 | else |
| 783 | a->session_cb_vft = &session_cb_vft; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 784 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 785 | if (mp->namespace_id_len > 64) |
| 786 | { |
| 787 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 788 | goto done; |
| 789 | } |
| 790 | |
| 791 | if (mp->namespace_id_len) |
| 792 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 793 | vec_validate (a->namespace_id, mp->namespace_id_len - 1); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 794 | clib_memcpy_fast (a->namespace_id, mp->namespace_id, |
| 795 | mp->namespace_id_len); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 798 | if ((rv = vnet_application_attach (a))) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 799 | { |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 800 | clib_warning ("attach returned: %d", rv); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 801 | vec_free (a->namespace_id); |
| 802 | goto done; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 803 | } |
| 804 | vec_free (a->namespace_id); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 805 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 806 | /* Send event queues segment */ |
| 807 | if ((evt_q_segment = session_manager_get_evt_q_segment ())) |
| 808 | { |
| 809 | fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT; |
| 810 | fds[n_fds] = evt_q_segment->fd; |
| 811 | n_fds += 1; |
| 812 | } |
| 813 | /* Send fifo segment fd if needed */ |
| 814 | if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD) |
| 815 | { |
| 816 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 817 | fds[n_fds] = a->segment->fd; |
| 818 | n_fds += 1; |
| 819 | } |
| 820 | if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD) |
| 821 | { |
| 822 | fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
| 823 | fds[n_fds] = svm_msg_q_get_producer_eventfd (a->app_evt_q); |
| 824 | n_fds += 1; |
| 825 | } |
| 826 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 827 | done: |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 828 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 829 | /* *INDENT-OFF* */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 830 | REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 831 | if (!rv) |
| 832 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 833 | segp = a->segment; |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 834 | rmp->app_index = clib_host_to_net_u32 (a->app_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 835 | rmp->segment_name_length = 0; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 836 | rmp->segment_size = segp->ssvm_size; |
| 837 | if (vec_len (segp->name)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 838 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 839 | memcpy (rmp->segment_name, segp->name, vec_len (segp->name)); |
| 840 | rmp->segment_name_length = vec_len (segp->name); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 841 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 842 | rmp->app_event_queue_address = pointer_to_uword (a->app_evt_q); |
| 843 | rmp->n_fds = n_fds; |
| 844 | rmp->fd_flags = fd_flags; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 845 | rmp->segment_handle = clib_host_to_net_u64 (a->segment_handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 846 | } |
| 847 | })); |
| 848 | /* *INDENT-ON* */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 849 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 850 | if (n_fds) |
| 851 | session_send_fds (reg, fds, n_fds); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 855 | vl_api_application_detach_t_handler (vl_api_application_detach_t * mp) |
| 856 | { |
| 857 | vl_api_application_detach_reply_t *rmp; |
| 858 | int rv = VNET_API_ERROR_INVALID_VALUE_2; |
| 859 | vnet_app_detach_args_t _a, *a = &_a; |
| 860 | application_t *app; |
| 861 | |
| 862 | if (session_manager_is_enabled () == 0) |
| 863 | { |
| 864 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 865 | goto done; |
| 866 | } |
| 867 | |
| 868 | app = application_lookup (mp->client_index); |
| 869 | if (app) |
| 870 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 871 | a->app_index = app->app_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 872 | a->api_client_index = mp->client_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 873 | rv = vnet_application_detach (a); |
| 874 | } |
| 875 | |
| 876 | done: |
| 877 | REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY); |
| 878 | } |
| 879 | |
| 880 | static void |
| 881 | vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp) |
| 882 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 883 | transport_connection_t *tc = 0; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 884 | vnet_listen_args_t _a, *a = &_a; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 885 | vl_api_bind_uri_reply_t *rmp; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 886 | session_t *s; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 887 | application_t *app = 0; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 888 | svm_msg_q_t *vpp_evt_q; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 889 | app_worker_t *app_wrk; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 890 | int rv; |
| 891 | |
| 892 | if (session_manager_is_enabled () == 0) |
| 893 | { |
| 894 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 895 | goto done; |
| 896 | } |
| 897 | |
| 898 | app = application_lookup (mp->client_index); |
| 899 | if (app) |
| 900 | { |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 901 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 902 | a->uri = (char *) mp->uri; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 903 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 904 | rv = vnet_bind_uri (a); |
| 905 | } |
| 906 | else |
| 907 | { |
| 908 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 909 | } |
| 910 | |
| 911 | done: |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 912 | |
| 913 | /* *INDENT-OFF* */ |
| 914 | REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({ |
| 915 | if (!rv) |
| 916 | { |
| 917 | rmp->handle = a->handle; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 918 | if (app && application_has_global_scope (app)) |
| 919 | { |
| 920 | s = listen_session_get_from_handle (a->handle); |
| 921 | tc = listen_session_get_transport (s); |
Florin Coras | 6c35494 | 2018-04-18 00:05:21 -0700 | [diff] [blame] | 922 | rmp->lcl_is_ip4 = tc->is_ip4; |
| 923 | rmp->lcl_port = tc->lcl_port; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 924 | clib_memcpy_fast (rmp->lcl_ip, &tc->lcl_ip, sizeof(tc->lcl_ip)); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 925 | if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL) |
| 926 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 927 | rmp->rx_fifo = pointer_to_uword (s->rx_fifo); |
| 928 | rmp->tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 929 | vpp_evt_q = session_manager_get_vpp_event_queue (0); |
| 930 | rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q); |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | })); |
| 935 | /* *INDENT-ON* */ |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 936 | |
| 937 | /* If app uses mq for control messages, send an mq message as well */ |
| 938 | if (app && application_use_mq_for_ctrl (app)) |
| 939 | { |
| 940 | app_wrk = application_get_worker (app, 0); |
| 941 | mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle, |
| 942 | rv); |
| 943 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 947 | vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp) |
| 948 | { |
| 949 | vl_api_unbind_uri_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 950 | application_t *app; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 951 | vnet_unlisten_args_t _a, *a = &_a; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 952 | int rv; |
| 953 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 954 | if (session_manager_is_enabled () == 0) |
| 955 | { |
| 956 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 957 | goto done; |
| 958 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 959 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 960 | app = application_lookup (mp->client_index); |
| 961 | if (app) |
| 962 | { |
| 963 | a->uri = (char *) mp->uri; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 964 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 965 | rv = vnet_unbind_uri (a); |
| 966 | } |
| 967 | else |
| 968 | { |
| 969 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 970 | } |
| 971 | |
| 972 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 973 | REPLY_MACRO (VL_API_UNBIND_URI_REPLY); |
| 974 | } |
| 975 | |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 976 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 977 | vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp) |
| 978 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 979 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 980 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 981 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 982 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 983 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 984 | if (session_manager_is_enabled () == 0) |
| 985 | { |
| 986 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 987 | goto done; |
| 988 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 989 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 990 | app = application_lookup (mp->client_index); |
| 991 | if (app) |
| 992 | { |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 993 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 994 | a->uri = (char *) mp->uri; |
| 995 | a->api_context = mp->context; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 996 | a->app_index = app->app_index; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 997 | if ((rv = vnet_connect_uri (a))) |
| 998 | clib_warning ("connect_uri returned: %d", rv); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 999 | } |
| 1000 | else |
| 1001 | { |
| 1002 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1003 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1004 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1005 | /* |
| 1006 | * Don't reply to stream (tcp) connects. The reply will come once |
| 1007 | * the connection is established. In case of the redirects, the reply |
| 1008 | * will come from the server app. |
| 1009 | */ |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1010 | if (rv == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1011 | return; |
| 1012 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1013 | done: |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1014 | /* *INDENT-OFF* */ |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1015 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1016 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | static void |
| 1020 | vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp) |
| 1021 | { |
| 1022 | vl_api_disconnect_session_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1023 | vnet_disconnect_args_t _a, *a = &_a; |
| 1024 | application_t *app; |
| 1025 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1026 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1027 | if (session_manager_is_enabled () == 0) |
| 1028 | { |
| 1029 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1030 | goto done; |
| 1031 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1032 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1033 | app = application_lookup (mp->client_index); |
| 1034 | if (app) |
| 1035 | { |
| 1036 | a->handle = mp->handle; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1037 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1038 | rv = vnet_disconnect_session (a); |
| 1039 | } |
| 1040 | else |
| 1041 | { |
| 1042 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1043 | } |
| 1044 | |
| 1045 | done: |
Dave Wallace | de5fec9 | 2017-11-11 22:41:34 -0500 | [diff] [blame] | 1046 | REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | static void |
| 1050 | vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t * |
| 1051 | mp) |
| 1052 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1053 | vnet_disconnect_args_t _a, *a = &_a; |
| 1054 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1055 | |
| 1056 | /* Client objected to disconnecting the session, log and continue */ |
| 1057 | if (mp->retval) |
| 1058 | { |
| 1059 | clib_warning ("client retval %d", mp->retval); |
| 1060 | return; |
| 1061 | } |
| 1062 | |
| 1063 | /* Disconnect has been confirmed. Confirm close to transport */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1064 | app = application_lookup (mp->context); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1065 | if (app) |
| 1066 | { |
| 1067 | a->handle = mp->handle; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1068 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1069 | vnet_disconnect_session (a); |
| 1070 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | static void |
| 1074 | vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp) |
| 1075 | { |
Florin Coras | 4af830c | 2018-12-04 09:21:36 -0800 | [diff] [blame] | 1076 | vnet_disconnect_args_t _a = { 0 }, *a = &_a; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1077 | app_worker_t *app_wrk; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1078 | application_t *app; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1079 | session_t *s; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1080 | u32 index, thread_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1081 | |
Ondrej Fabry | 6bd197e | 2018-08-15 08:46:46 +0200 | [diff] [blame] | 1082 | app = application_lookup (mp->context); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1083 | if (!app) |
| 1084 | return; |
| 1085 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1086 | session_parse_handle (mp->handle, &index, &thread_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1087 | s = session_get_if_valid (index, thread_index); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1088 | if (!s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1089 | { |
| 1090 | clib_warning ("Invalid session!"); |
| 1091 | return; |
| 1092 | } |
| 1093 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1094 | app_wrk = app_worker_get (s->app_wrk_index); |
| 1095 | if (app_wrk->app_index != app->app_index) |
| 1096 | { |
| 1097 | clib_warning ("app %u does not own handle 0x%lx", app->app_index, |
| 1098 | mp->handle); |
| 1099 | return; |
| 1100 | } |
| 1101 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1102 | /* Client objected to resetting the session, log and continue */ |
| 1103 | if (mp->retval) |
| 1104 | { |
| 1105 | clib_warning ("client retval %d", mp->retval); |
| 1106 | return; |
| 1107 | } |
| 1108 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1109 | /* This comes as a response to a reset, transport only waiting for |
| 1110 | * confirmation to remove connection state, no need to disconnect */ |
Florin Coras | 4af830c | 2018-12-04 09:21:36 -0800 | [diff] [blame] | 1111 | a->handle = mp->handle; |
| 1112 | a->app_index = app->app_index; |
| 1113 | vnet_disconnect_session (a); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | static void |
| 1117 | vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp) |
| 1118 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1119 | vnet_disconnect_args_t _a = { 0 }, *a = &_a; |
| 1120 | local_session_t *ls; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1121 | session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1122 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1123 | /* Server isn't interested, kill the session */ |
| 1124 | if (mp->retval) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1125 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1126 | a->app_index = mp->context; |
| 1127 | a->handle = mp->handle; |
| 1128 | vnet_disconnect_session (a); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1129 | return; |
| 1130 | } |
| 1131 | |
| 1132 | if (session_handle_is_local (mp->handle)) |
| 1133 | { |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 1134 | ls = app_worker_get_local_session_from_handle (mp->handle); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1135 | if (!ls || ls->app_wrk_index != mp->context) |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1136 | { |
| 1137 | clib_warning ("server %u doesn't own local handle %llu", |
| 1138 | mp->context, mp->handle); |
| 1139 | return; |
| 1140 | } |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 1141 | if (app_worker_local_session_connect_notify (ls)) |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1142 | return; |
| 1143 | ls->session_state = SESSION_STATE_READY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1144 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1145 | else |
| 1146 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1147 | s = session_get_from_handle_if_valid (mp->handle); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1148 | if (!s) |
| 1149 | { |
| 1150 | clib_warning ("session doesn't exist"); |
| 1151 | return; |
| 1152 | } |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1153 | if (s->app_wrk_index != mp->context) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1154 | { |
| 1155 | clib_warning ("app doesn't own session"); |
| 1156 | return; |
| 1157 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1158 | s->session_state = SESSION_STATE_READY; |
| 1159 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | static void |
| 1163 | vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t |
| 1164 | * mp) |
| 1165 | { |
| 1166 | clib_warning ("not implemented"); |
| 1167 | } |
| 1168 | |
| 1169 | static void |
| 1170 | vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp) |
| 1171 | { |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1172 | vnet_listen_args_t _a, *a = &_a; |
| 1173 | transport_connection_t *tc = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1174 | vl_api_bind_sock_reply_t *rmp; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1175 | svm_msg_q_t *vpp_evt_q; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1176 | application_t *app = 0; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 1177 | app_worker_t *app_wrk; |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1178 | ip46_address_t *ip46; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1179 | app_listener_t *al; |
| 1180 | session_t *s; |
| 1181 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1182 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1183 | if (session_manager_is_enabled () == 0) |
| 1184 | { |
| 1185 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1186 | goto done; |
| 1187 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1188 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1189 | app = application_lookup (mp->client_index); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1190 | if (!app) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1191 | { |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1192 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1193 | goto done; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1194 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1195 | |
| 1196 | ip46 = (ip46_address_t *) mp->ip; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1197 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1198 | a->sep.is_ip4 = mp->is_ip4; |
| 1199 | a->sep.ip = *ip46; |
| 1200 | a->sep.port = mp->port; |
| 1201 | a->sep.fib_index = mp->vrf; |
| 1202 | a->sep.sw_if_index = ENDPOINT_INVALID_INDEX; |
| 1203 | a->sep.transport_proto = mp->proto; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1204 | a->app_index = app->app_index; |
| 1205 | a->wrk_map_index = mp->wrk_index; |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1206 | |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 1207 | if ((rv = vnet_listen (a))) |
| 1208 | clib_warning ("listen returned: %d", rv); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1209 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1210 | done: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1211 | /* *INDENT-OFF* */ |
| 1212 | REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({ |
| 1213 | if (!rv) |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1214 | { |
| 1215 | rmp->handle = a->handle; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1216 | rmp->lcl_port = mp->port; |
Keith Burns (alagalah) | 60ae80f | 2018-03-15 10:04:20 -0700 | [diff] [blame] | 1217 | rmp->lcl_is_ip4 = mp->is_ip4; |
Dave Wallace | 97b1a27 | 2017-12-18 13:51:59 -0500 | [diff] [blame] | 1218 | if (app && application_has_global_scope (app)) |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1219 | { |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1220 | al = app_listener_get_w_handle (a->handle); |
| 1221 | s = app_listener_get_session (al); |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1222 | tc = listen_session_get_transport (s); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1223 | clib_memcpy_fast (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1224 | if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL) |
| 1225 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1226 | rmp->rx_fifo = pointer_to_uword (s->rx_fifo); |
| 1227 | rmp->tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1228 | vpp_evt_q = session_manager_get_vpp_event_queue (0); |
| 1229 | rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q); |
| 1230 | } |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1231 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1232 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1233 | })); |
| 1234 | /* *INDENT-ON* */ |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 1235 | |
| 1236 | /* If app uses mq for control messages, send an mq message as well */ |
| 1237 | if (app && application_use_mq_for_ctrl (app)) |
| 1238 | { |
| 1239 | app_wrk = application_get_worker (app, mp->wrk_index); |
| 1240 | mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle, |
| 1241 | rv); |
| 1242 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | static void |
| 1246 | vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp) |
| 1247 | { |
| 1248 | vl_api_unbind_sock_reply_t *rmp; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 1249 | vnet_unlisten_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1250 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1251 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1252 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1253 | if (session_manager_is_enabled () == 0) |
| 1254 | { |
| 1255 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1256 | goto done; |
| 1257 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1258 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1259 | app = application_lookup (mp->client_index); |
| 1260 | if (app) |
| 1261 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1262 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1263 | a->handle = mp->handle; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1264 | a->wrk_map_index = mp->wrk_index; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 1265 | if ((rv = vnet_unlisten (a))) |
| 1266 | clib_warning ("unlisten returned: %d", rv); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1267 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1268 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1269 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1270 | REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY); |
| 1271 | } |
| 1272 | |
| 1273 | static void |
| 1274 | vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp) |
| 1275 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1276 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1277 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1278 | application_t *app = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1279 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1280 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1281 | if (session_manager_is_enabled () == 0) |
| 1282 | { |
| 1283 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1284 | goto done; |
| 1285 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1286 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1287 | app = application_lookup (mp->client_index); |
| 1288 | if (app) |
| 1289 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 1290 | svm_queue_t *client_q; |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1291 | ip46_address_t *ip46 = (ip46_address_t *) mp->ip; |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 1292 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1293 | clib_memset (a, 0, sizeof (*a)); |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 1294 | client_q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1295 | mp->client_queue_address = pointer_to_uword (client_q); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1296 | a->sep.is_ip4 = mp->is_ip4; |
| 1297 | a->sep.ip = *ip46; |
| 1298 | a->sep.port = mp->port; |
| 1299 | a->sep.transport_proto = mp->proto; |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 1300 | a->sep.peer.fib_index = mp->vrf; |
| 1301 | a->sep.peer.sw_if_index = ENDPOINT_INVALID_INDEX; |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1302 | if (mp->hostname_len) |
| 1303 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1304 | vec_validate (a->sep_ext.hostname, mp->hostname_len - 1); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1305 | clib_memcpy_fast (a->sep_ext.hostname, mp->hostname, |
| 1306 | mp->hostname_len); |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1307 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1308 | a->api_context = mp->context; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1309 | a->app_index = app->app_index; |
| 1310 | a->wrk_map_index = mp->wrk_index; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 1311 | if ((rv = vnet_connect (a))) |
| 1312 | clib_warning ("connect returned: %u", rv); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1313 | vec_free (a->sep_ext.hostname); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1314 | } |
| 1315 | else |
| 1316 | { |
| 1317 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1318 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1319 | |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1320 | if (rv == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1321 | return; |
| 1322 | |
| 1323 | /* Got some error, relay it */ |
| 1324 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1325 | done: |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1326 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1327 | |
| 1328 | if (app && application_use_mq_for_ctrl (app)) |
| 1329 | { |
| 1330 | app_worker_t *app_wrk = application_get_worker (app, mp->wrk_index); |
| 1331 | mq_send_session_connected_cb (app_wrk->wrk_index, mp->context, 0, 1); |
| 1332 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1333 | } |
| 1334 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1335 | static void |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1336 | vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp) |
| 1337 | { |
| 1338 | int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0; |
| 1339 | vl_api_app_worker_add_del_reply_t *rmp; |
| 1340 | vl_api_registration_t *reg; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1341 | application_t *app; |
| 1342 | u8 fd_flags = 0; |
| 1343 | |
| 1344 | if (!session_manager_is_enabled ()) |
| 1345 | { |
| 1346 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1347 | goto done; |
| 1348 | } |
| 1349 | |
| 1350 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1351 | if (!reg) |
| 1352 | return; |
| 1353 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 1354 | app = application_get_if_valid (clib_net_to_host_u32 (mp->app_index)); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1355 | if (!app) |
| 1356 | { |
| 1357 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1358 | goto done; |
| 1359 | } |
| 1360 | |
| 1361 | vnet_app_worker_add_del_args_t args = { |
| 1362 | .app_index = app->app_index, |
Florin Coras | 349f8ca | 2018-11-20 16:52:49 -0800 | [diff] [blame] | 1363 | .wrk_map_index = clib_net_to_host_u32 (mp->wrk_index), |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 1364 | .api_client_index = mp->client_index, |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1365 | .is_add = mp->is_add |
| 1366 | }; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 1367 | rv = vnet_app_worker_add_del (&args); |
| 1368 | if (rv) |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1369 | { |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 1370 | clib_warning ("app worker add/del returned: %d", rv); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1371 | goto done; |
| 1372 | } |
| 1373 | |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 1374 | if (!mp->is_add) |
| 1375 | goto done; |
Florin Coras | c3638fe | 2018-08-24 13:58:49 -0700 | [diff] [blame] | 1376 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1377 | /* Send fifo segment fd if needed */ |
| 1378 | if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD) |
| 1379 | { |
| 1380 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 1381 | fds[n_fds] = args.segment->fd; |
| 1382 | n_fds += 1; |
| 1383 | } |
| 1384 | if (application_segment_manager_properties (app)->use_mq_eventfd) |
| 1385 | { |
| 1386 | fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
| 1387 | fds[n_fds] = svm_msg_q_get_producer_eventfd (args.evt_q); |
| 1388 | n_fds += 1; |
| 1389 | } |
| 1390 | |
| 1391 | /* *INDENT-OFF* */ |
| 1392 | done: |
| 1393 | REPLY_MACRO2 (VL_API_APP_WORKER_ADD_DEL_REPLY, ({ |
| 1394 | rmp->is_add = mp->is_add; |
Florin Coras | 349f8ca | 2018-11-20 16:52:49 -0800 | [diff] [blame] | 1395 | rmp->wrk_index = clib_host_to_net_u32 (args.wrk_map_index); |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 1396 | rmp->segment_handle = clib_host_to_net_u64 (args.segment_handle); |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 1397 | if (!rv && mp->is_add) |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1398 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1399 | if (vec_len (args.segment->name)) |
| 1400 | { |
| 1401 | memcpy (rmp->segment_name, args.segment->name, |
| 1402 | vec_len (args.segment->name)); |
| 1403 | rmp->segment_name_length = vec_len (args.segment->name); |
| 1404 | } |
| 1405 | rmp->app_event_queue_address = pointer_to_uword (args.evt_q); |
| 1406 | rmp->n_fds = n_fds; |
| 1407 | rmp->fd_flags = fd_flags; |
| 1408 | } |
| 1409 | })); |
| 1410 | /* *INDENT-ON* */ |
| 1411 | |
| 1412 | if (n_fds) |
| 1413 | session_send_fds (reg, fds, n_fds); |
| 1414 | } |
| 1415 | |
| 1416 | static void |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1417 | vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp) |
| 1418 | { |
| 1419 | vl_api_app_namespace_add_del_reply_t *rmp; |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1420 | u32 appns_index = 0; |
| 1421 | u8 *ns_id = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1422 | int rv = 0; |
| 1423 | if (!session_manager_is_enabled ()) |
| 1424 | { |
| 1425 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1426 | goto done; |
| 1427 | } |
| 1428 | |
| 1429 | if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id)) |
| 1430 | { |
| 1431 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1432 | goto done; |
| 1433 | } |
| 1434 | |
| 1435 | vec_validate (ns_id, mp->namespace_id_len - 1); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1436 | clib_memcpy_fast (ns_id, mp->namespace_id, mp->namespace_id_len); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1437 | vnet_app_namespace_add_del_args_t args = { |
| 1438 | .ns_id = ns_id, |
Florin Coras | 9a9adb2 | 2017-10-26 08:16:59 -0700 | [diff] [blame] | 1439 | .secret = clib_net_to_host_u64 (mp->secret), |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1440 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 1441 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 1442 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 1443 | .is_add = 1 |
| 1444 | }; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 1445 | rv = vnet_app_namespace_add_del (&args); |
| 1446 | if (!rv) |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1447 | { |
| 1448 | appns_index = app_namespace_index_from_id (ns_id); |
| 1449 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 1450 | { |
| 1451 | clib_warning ("app ns lookup failed"); |
| 1452 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1453 | } |
| 1454 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1455 | vec_free (ns_id); |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1456 | |
| 1457 | /* *INDENT-OFF* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1458 | done: |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1459 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({ |
| 1460 | if (!rv) |
| 1461 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 1462 | })); |
| 1463 | /* *INDENT-ON* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1466 | static void |
| 1467 | vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp) |
| 1468 | { |
| 1469 | vl_api_session_rule_add_del_reply_t *rmp; |
| 1470 | session_rule_add_del_args_t args; |
| 1471 | session_rule_table_add_del_args_t *table_args = &args.table_args; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1472 | u8 fib_proto; |
| 1473 | int rv = 0; |
| 1474 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1475 | clib_memset (&args, 0, sizeof (args)); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1476 | fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; |
| 1477 | |
| 1478 | table_args->lcl.fp_len = mp->lcl_plen; |
| 1479 | table_args->lcl.fp_proto = fib_proto; |
| 1480 | table_args->rmt.fp_len = mp->rmt_plen; |
| 1481 | table_args->rmt.fp_proto = fib_proto; |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1482 | table_args->lcl_port = mp->lcl_port; |
| 1483 | table_args->rmt_port = mp->rmt_port; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1484 | table_args->action_index = clib_net_to_host_u32 (mp->action_index); |
| 1485 | table_args->is_add = mp->is_add; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1486 | mp->tag[sizeof (mp->tag) - 1] = 0; |
| 1487 | table_args->tag = format (0, "%s", mp->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1488 | args.appns_index = clib_net_to_host_u32 (mp->appns_index); |
| 1489 | args.scope = mp->scope; |
Florin Coras | 42324ad | 2017-11-18 18:45:20 -0800 | [diff] [blame] | 1490 | args.transport_proto = mp->transport_proto; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1491 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1492 | clib_memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr)); |
| 1493 | clib_memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr)); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1494 | ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4); |
| 1495 | ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4); |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame^] | 1496 | rv = vnet_session_rule_add_del (&args); |
| 1497 | if (rv) |
| 1498 | clib_warning ("rule add del returned: %d", rv); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1499 | vec_free (table_args->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1500 | REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY); |
| 1501 | } |
| 1502 | |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1503 | static void |
| 1504 | send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1505 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1506 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1507 | { |
| 1508 | vl_api_session_rules_details_t *rmp = 0; |
| 1509 | session_mask_or_match_4_t *match = |
| 1510 | (session_mask_or_match_4_t *) & rule->match; |
| 1511 | session_mask_or_match_4_t *mask = |
| 1512 | (session_mask_or_match_4_t *) & rule->mask; |
| 1513 | |
| 1514 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1515 | clib_memset (rmp, 0, sizeof (*rmp)); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1516 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 1517 | rmp->context = context; |
| 1518 | |
| 1519 | rmp->is_ip4 = 1; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1520 | clib_memcpy_fast (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 1521 | clib_memcpy_fast (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip)); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1522 | rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip); |
| 1523 | rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1524 | rmp->lcl_port = match->lcl_port; |
| 1525 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1526 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
| 1527 | rmp->scope = |
| 1528 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
| 1529 | rmp->transport_proto = transport_proto; |
| 1530 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1531 | if (tag) |
| 1532 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1533 | clib_memcpy_fast (rmp->tag, tag, vec_len (tag)); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1534 | rmp->tag[vec_len (tag)] = 0; |
| 1535 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1536 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1537 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | static void |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1541 | send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local, |
| 1542 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1543 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1544 | { |
| 1545 | vl_api_session_rules_details_t *rmp = 0; |
| 1546 | session_mask_or_match_6_t *match = |
| 1547 | (session_mask_or_match_6_t *) & rule->match; |
| 1548 | session_mask_or_match_6_t *mask = |
| 1549 | (session_mask_or_match_6_t *) & rule->mask; |
| 1550 | |
| 1551 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1552 | clib_memset (rmp, 0, sizeof (*rmp)); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1553 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 1554 | rmp->context = context; |
| 1555 | |
| 1556 | rmp->is_ip4 = 0; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1557 | clib_memcpy_fast (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 1558 | clib_memcpy_fast (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip)); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1559 | rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip); |
| 1560 | rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1561 | rmp->lcl_port = match->lcl_port; |
| 1562 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1563 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1564 | rmp->scope = |
| 1565 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1566 | rmp->transport_proto = transport_proto; |
| 1567 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1568 | if (tag) |
| 1569 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1570 | clib_memcpy_fast (rmp->tag, tag, vec_len (tag)); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1571 | rmp->tag[vec_len (tag)] = 0; |
| 1572 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1573 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1574 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | static void |
| 1578 | send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1579 | u8 tp, u8 is_local, u32 appns_index, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1580 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1581 | { |
| 1582 | mma_rule_16_t *rule16; |
| 1583 | mma_rule_40_t *rule40; |
| 1584 | mma_rules_table_16_t *srt16; |
| 1585 | mma_rules_table_40_t *srt40; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1586 | u32 ri; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1587 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1588 | if (is_local || fib_proto == FIB_PROTOCOL_IP4) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1589 | { |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1590 | u8 *tag = 0; |
| 1591 | /* *INDENT-OFF* */ |
| 1592 | srt16 = &srt->session_rules_tables_16; |
| 1593 | pool_foreach (rule16, srt16->rules, ({ |
| 1594 | ri = mma_rules_table_rule_index_16 (srt16, rule16); |
| 1595 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1596 | send_session_rule_details4 (rule16, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1597 | reg, context); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1598 | })); |
| 1599 | /* *INDENT-ON* */ |
| 1600 | } |
| 1601 | if (is_local || fib_proto == FIB_PROTOCOL_IP6) |
| 1602 | { |
| 1603 | u8 *tag = 0; |
| 1604 | /* *INDENT-OFF* */ |
| 1605 | srt40 = &srt->session_rules_tables_40; |
| 1606 | pool_foreach (rule40, srt40->rules, ({ |
| 1607 | ri = mma_rules_table_rule_index_40 (srt40, rule40); |
| 1608 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1609 | send_session_rule_details6 (rule40, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1610 | reg, context); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1611 | })); |
| 1612 | /* *INDENT-ON* */ |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | static void |
| 1617 | vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp) |
| 1618 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1619 | vl_api_registration_t *reg; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1620 | session_table_t *st; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1621 | u8 tp; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1622 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1623 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1624 | if (!reg) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1625 | return; |
| 1626 | |
| 1627 | /* *INDENT-OFF* */ |
| 1628 | session_table_foreach (st, ({ |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1629 | for (tp = 0; tp < TRANSPORT_N_PROTO; tp++) |
| 1630 | { |
| 1631 | send_session_rules_table_details (&st->session_rules[tp], |
| 1632 | st->active_fib_proto, tp, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1633 | st->is_local, st->appns_index, reg, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1634 | mp->context); |
| 1635 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1636 | })); |
| 1637 | /* *INDENT-ON* */ |
| 1638 | } |
| 1639 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1640 | static void |
| 1641 | vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t * |
| 1642 | mp) |
| 1643 | { |
| 1644 | vl_api_app_namespace_add_del_reply_t *rmp; |
| 1645 | vnet_app_add_tls_cert_args_t _a, *a = &_a; |
| 1646 | clib_error_t *error; |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1647 | application_t *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1648 | u32 cert_len; |
| 1649 | int rv = 0; |
| 1650 | if (!session_manager_is_enabled ()) |
| 1651 | { |
| 1652 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1653 | goto done; |
| 1654 | } |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1655 | if (!(app = application_lookup (mp->client_index))) |
| 1656 | { |
| 1657 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1658 | goto done; |
| 1659 | } |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1660 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1661 | a->app_index = app->app_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1662 | cert_len = clib_net_to_host_u16 (mp->cert_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1663 | if (cert_len > 10000) |
| 1664 | { |
| 1665 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1666 | goto done; |
| 1667 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1668 | vec_validate (a->cert, cert_len); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1669 | clib_memcpy_fast (a->cert, mp->cert, cert_len); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1670 | if ((error = vnet_app_add_tls_cert (a))) |
| 1671 | { |
| 1672 | rv = clib_error_get_code (error); |
| 1673 | clib_error_report (error); |
| 1674 | } |
| 1675 | vec_free (a->cert); |
| 1676 | done: |
| 1677 | REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY); |
| 1678 | } |
| 1679 | |
| 1680 | static void |
| 1681 | vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t * |
| 1682 | mp) |
| 1683 | { |
| 1684 | vl_api_app_namespace_add_del_reply_t *rmp; |
| 1685 | vnet_app_add_tls_key_args_t _a, *a = &_a; |
| 1686 | clib_error_t *error; |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1687 | application_t *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1688 | u32 key_len; |
| 1689 | int rv = 0; |
| 1690 | if (!session_manager_is_enabled ()) |
| 1691 | { |
| 1692 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1693 | goto done; |
| 1694 | } |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1695 | if (!(app = application_lookup (mp->client_index))) |
| 1696 | { |
| 1697 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1698 | goto done; |
| 1699 | } |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1700 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1701 | a->app_index = app->app_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1702 | key_len = clib_net_to_host_u16 (mp->key_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1703 | if (key_len > 10000) |
| 1704 | { |
| 1705 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1706 | goto done; |
| 1707 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1708 | vec_validate (a->key, key_len); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1709 | clib_memcpy_fast (a->key, mp->key, key_len); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1710 | if ((error = vnet_app_add_tls_key (a))) |
| 1711 | { |
| 1712 | rv = clib_error_get_code (error); |
| 1713 | clib_error_report (error); |
| 1714 | } |
| 1715 | vec_free (a->key); |
| 1716 | done: |
| 1717 | REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY); |
| 1718 | } |
| 1719 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1720 | static clib_error_t * |
| 1721 | application_reaper_cb (u32 client_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1722 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1723 | application_t *app = application_lookup (client_index); |
| 1724 | vnet_app_detach_args_t _a, *a = &_a; |
| 1725 | if (app) |
| 1726 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1727 | a->app_index = app->app_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 1728 | a->api_client_index = client_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1729 | vnet_application_detach (a); |
| 1730 | } |
| 1731 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1732 | } |
| 1733 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1734 | VL_MSG_API_REAPER_FUNCTION (application_reaper_cb); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1735 | |
| 1736 | #define vl_msg_name_crc_list |
| 1737 | #include <vnet/vnet_all_api_h.h> |
| 1738 | #undef vl_msg_name_crc_list |
| 1739 | |
| 1740 | static void |
| 1741 | setup_message_id_table (api_main_t * am) |
| 1742 | { |
| 1743 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1744 | foreach_vl_msg_name_crc_session; |
| 1745 | #undef _ |
| 1746 | } |
| 1747 | |
| 1748 | /* |
| 1749 | * session_api_hookup |
| 1750 | * Add uri's API message handlers to the table. |
| 1751 | * vlib has alread mapped shared memory and |
| 1752 | * added the client registration handlers. |
| 1753 | * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process() |
| 1754 | */ |
| 1755 | static clib_error_t * |
| 1756 | session_api_hookup (vlib_main_t * vm) |
| 1757 | { |
| 1758 | api_main_t *am = &api_main; |
| 1759 | |
| 1760 | #define _(N,n) \ |
| 1761 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1762 | vl_api_##n##_t_handler, \ |
| 1763 | vl_noop_handler, \ |
| 1764 | vl_api_##n##_t_endian, \ |
| 1765 | vl_api_##n##_t_print, \ |
| 1766 | sizeof(vl_api_##n##_t), 1); |
| 1767 | foreach_session_api_msg; |
| 1768 | #undef _ |
| 1769 | |
| 1770 | /* |
| 1771 | * Messages which bounce off the data-plane to |
| 1772 | * an API client. Simply tells the message handling infra not |
| 1773 | * to free the message. |
| 1774 | * |
| 1775 | * Bounced message handlers MUST NOT block the data plane |
| 1776 | */ |
| 1777 | am->message_bounce[VL_API_CONNECT_URI] = 1; |
| 1778 | am->message_bounce[VL_API_CONNECT_SOCK] = 1; |
| 1779 | |
| 1780 | /* |
| 1781 | * Set up the (msg_name, crc, message-id) table |
| 1782 | */ |
| 1783 | setup_message_id_table (am); |
| 1784 | |
| 1785 | return 0; |
| 1786 | } |
| 1787 | |
| 1788 | VLIB_API_INIT_FUNCTION (session_api_hookup); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1789 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1790 | /* |
| 1791 | * fd.io coding-style-patch-verification: ON |
| 1792 | * |
| 1793 | * Local Variables: |
| 1794 | * eval: (c-set-style "gnu") |
| 1795 | * End: |
| 1796 | */ |