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