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