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