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