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