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 | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 713 | local = application_get_local_listener_w_handle (handle); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 714 | mp->lcl_port = local->port; |
| 715 | mp->lcl_is_ip4 = session_type_is_ip4 (local->session_type); |
| 716 | } |
| 717 | |
Florin Coras | 5f45e01 | 2019-01-23 09:21:30 -0800 | [diff] [blame] | 718 | vpp_evt_q = session_manager_get_vpp_event_queue (0); |
| 719 | mp->vpp_evt_q = pointer_to_uword (vpp_evt_q); |
| 720 | |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 721 | if (ls && session_transport_service_type (ls) == TRANSPORT_SERVICE_CL) |
| 722 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 723 | mp->rx_fifo = pointer_to_uword (ls->rx_fifo); |
| 724 | mp->tx_fifo = pointer_to_uword (ls->tx_fifo); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | done: |
| 728 | mp->retval = rv; |
Florin Coras | 537b17e | 2018-09-28 10:35:45 -0700 | [diff] [blame] | 729 | svm_msg_q_add_and_unlock (app_mq, msg); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 730 | return 0; |
| 731 | } |
| 732 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 733 | static session_cb_vft_t session_mq_cb_vft = { |
| 734 | .session_accept_callback = mq_send_session_accepted_cb, |
| 735 | .session_disconnect_callback = mq_send_session_disconnected_cb, |
| 736 | .session_connected_callback = mq_send_session_connected_cb, |
| 737 | .session_reset_callback = mq_send_session_reset_cb, |
| 738 | .add_segment_callback = send_add_segment_callback, |
| 739 | .del_segment_callback = send_del_segment_callback, |
| 740 | }; |
| 741 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 742 | static void |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 743 | vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp) |
| 744 | { |
| 745 | vl_api_session_enable_disable_reply_t *rmp; |
| 746 | vlib_main_t *vm = vlib_get_main (); |
| 747 | int rv = 0; |
| 748 | |
| 749 | vnet_session_enable_disable (vm, mp->is_enable); |
| 750 | REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY); |
| 751 | } |
| 752 | |
| 753 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 754 | vl_api_application_attach_t_handler (vl_api_application_attach_t * mp) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 755 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 756 | int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 757 | vl_api_application_attach_reply_t *rmp; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 758 | ssvm_private_t *segp, *evt_q_segment; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 759 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 760 | vl_api_registration_t *reg; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 761 | u8 fd_flags = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 762 | |
Florin Coras | fc804d9 | 2018-01-26 01:27:01 -0800 | [diff] [blame] | 763 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 764 | if (!reg) |
| 765 | return; |
| 766 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 767 | if (session_manager_is_enabled () == 0) |
| 768 | { |
| 769 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 770 | goto done; |
| 771 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 772 | |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 773 | STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <= |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 774 | sizeof (mp->options), |
| 775 | "Out of options, fix api message definition"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 776 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 777 | clib_memset (a, 0, sizeof (*a)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 778 | a->api_client_index = mp->client_index; |
| 779 | a->options = mp->options; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 780 | |
| 781 | if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS) |
| 782 | a->session_cb_vft = &session_mq_cb_vft; |
| 783 | else |
| 784 | a->session_cb_vft = &session_cb_vft; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 785 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 786 | if (mp->namespace_id_len > 64) |
| 787 | { |
| 788 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 789 | goto done; |
| 790 | } |
| 791 | |
| 792 | if (mp->namespace_id_len) |
| 793 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 794 | vec_validate (a->namespace_id, mp->namespace_id_len - 1); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 795 | clib_memcpy_fast (a->namespace_id, mp->namespace_id, |
| 796 | mp->namespace_id_len); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 799 | if ((rv = vnet_application_attach (a))) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 800 | { |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 801 | clib_warning ("attach returned: %d", rv); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 802 | vec_free (a->namespace_id); |
| 803 | goto done; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 804 | } |
| 805 | vec_free (a->namespace_id); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 806 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 807 | /* Send event queues segment */ |
| 808 | if ((evt_q_segment = session_manager_get_evt_q_segment ())) |
| 809 | { |
| 810 | fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT; |
| 811 | fds[n_fds] = evt_q_segment->fd; |
| 812 | n_fds += 1; |
| 813 | } |
| 814 | /* Send fifo segment fd if needed */ |
| 815 | if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD) |
| 816 | { |
| 817 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 818 | fds[n_fds] = a->segment->fd; |
| 819 | n_fds += 1; |
| 820 | } |
| 821 | if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD) |
| 822 | { |
| 823 | fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
| 824 | fds[n_fds] = svm_msg_q_get_producer_eventfd (a->app_evt_q); |
| 825 | n_fds += 1; |
| 826 | } |
| 827 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 828 | done: |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 829 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 830 | /* *INDENT-OFF* */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 831 | REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 832 | if (!rv) |
| 833 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 834 | segp = a->segment; |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 835 | rmp->app_index = clib_host_to_net_u32 (a->app_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 836 | rmp->segment_name_length = 0; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 837 | rmp->segment_size = segp->ssvm_size; |
| 838 | if (vec_len (segp->name)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 839 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 840 | memcpy (rmp->segment_name, segp->name, vec_len (segp->name)); |
| 841 | rmp->segment_name_length = vec_len (segp->name); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 842 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 843 | rmp->app_event_queue_address = pointer_to_uword (a->app_evt_q); |
| 844 | rmp->n_fds = n_fds; |
| 845 | rmp->fd_flags = fd_flags; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 846 | rmp->segment_handle = clib_host_to_net_u64 (a->segment_handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 847 | } |
| 848 | })); |
| 849 | /* *INDENT-ON* */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 850 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 851 | if (n_fds) |
| 852 | session_send_fds (reg, fds, n_fds); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 856 | vl_api_application_detach_t_handler (vl_api_application_detach_t * mp) |
| 857 | { |
| 858 | vl_api_application_detach_reply_t *rmp; |
| 859 | int rv = VNET_API_ERROR_INVALID_VALUE_2; |
| 860 | vnet_app_detach_args_t _a, *a = &_a; |
| 861 | application_t *app; |
| 862 | |
| 863 | if (session_manager_is_enabled () == 0) |
| 864 | { |
| 865 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 866 | goto done; |
| 867 | } |
| 868 | |
| 869 | app = application_lookup (mp->client_index); |
| 870 | if (app) |
| 871 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 872 | a->app_index = app->app_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 873 | a->api_client_index = mp->client_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 874 | rv = vnet_application_detach (a); |
| 875 | } |
| 876 | |
| 877 | done: |
| 878 | REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY); |
| 879 | } |
| 880 | |
| 881 | static void |
| 882 | vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp) |
| 883 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 884 | transport_connection_t *tc = 0; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 885 | vnet_listen_args_t _a, *a = &_a; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 886 | vl_api_bind_uri_reply_t *rmp; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 887 | session_t *s; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 888 | application_t *app = 0; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 889 | svm_msg_q_t *vpp_evt_q; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 890 | app_worker_t *app_wrk; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 891 | int rv; |
| 892 | |
| 893 | if (session_manager_is_enabled () == 0) |
| 894 | { |
| 895 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 896 | goto done; |
| 897 | } |
| 898 | |
| 899 | app = application_lookup (mp->client_index); |
| 900 | if (app) |
| 901 | { |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 902 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 903 | a->uri = (char *) mp->uri; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 904 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 905 | rv = vnet_bind_uri (a); |
| 906 | } |
| 907 | else |
| 908 | { |
| 909 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 910 | } |
| 911 | |
| 912 | done: |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 913 | |
| 914 | /* *INDENT-OFF* */ |
| 915 | REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({ |
| 916 | if (!rv) |
| 917 | { |
| 918 | rmp->handle = a->handle; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 919 | if (app && application_has_global_scope (app)) |
| 920 | { |
Nathan Skrzypczak | bb65ba1 | 2019-02-14 13:24:43 +0100 | [diff] [blame] | 921 | app_listener_t* al = app_listener_get_w_handle(a->handle); |
| 922 | s = app_listener_get_session(al); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 923 | tc = listen_session_get_transport (s); |
Florin Coras | 6c35494 | 2018-04-18 00:05:21 -0700 | [diff] [blame] | 924 | rmp->lcl_is_ip4 = tc->is_ip4; |
| 925 | rmp->lcl_port = tc->lcl_port; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 926 | 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] | 927 | if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL) |
| 928 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 929 | rmp->rx_fifo = pointer_to_uword (s->rx_fifo); |
| 930 | rmp->tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 931 | vpp_evt_q = session_manager_get_vpp_event_queue (0); |
| 932 | rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q); |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | })); |
| 937 | /* *INDENT-ON* */ |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 938 | |
| 939 | /* If app uses mq for control messages, send an mq message as well */ |
| 940 | if (app && application_use_mq_for_ctrl (app)) |
| 941 | { |
| 942 | app_wrk = application_get_worker (app, 0); |
| 943 | mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle, |
| 944 | rv); |
| 945 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 949 | vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp) |
| 950 | { |
| 951 | vl_api_unbind_uri_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 952 | application_t *app; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 953 | vnet_unlisten_args_t _a, *a = &_a; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 954 | int rv; |
| 955 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 956 | if (session_manager_is_enabled () == 0) |
| 957 | { |
| 958 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 959 | goto done; |
| 960 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 961 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 962 | app = application_lookup (mp->client_index); |
| 963 | if (app) |
| 964 | { |
| 965 | a->uri = (char *) mp->uri; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 966 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 967 | rv = vnet_unbind_uri (a); |
| 968 | } |
| 969 | else |
| 970 | { |
| 971 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 972 | } |
| 973 | |
| 974 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 975 | REPLY_MACRO (VL_API_UNBIND_URI_REPLY); |
| 976 | } |
| 977 | |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 978 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 979 | vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp) |
| 980 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 981 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 982 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 983 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 984 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 985 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 986 | if (session_manager_is_enabled () == 0) |
| 987 | { |
| 988 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 989 | goto done; |
| 990 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 991 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 992 | app = application_lookup (mp->client_index); |
| 993 | if (app) |
| 994 | { |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 995 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 996 | a->uri = (char *) mp->uri; |
| 997 | a->api_context = mp->context; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 998 | a->app_index = app->app_index; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 999 | if ((rv = vnet_connect_uri (a))) |
| 1000 | clib_warning ("connect_uri returned: %d", rv); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1001 | } |
| 1002 | else |
| 1003 | { |
| 1004 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1005 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1006 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1007 | /* |
| 1008 | * Don't reply to stream (tcp) connects. The reply will come once |
| 1009 | * the connection is established. In case of the redirects, the reply |
| 1010 | * will come from the server app. |
| 1011 | */ |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1012 | if (rv == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1013 | return; |
| 1014 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1015 | done: |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1016 | /* *INDENT-OFF* */ |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1017 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1018 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | static void |
| 1022 | vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp) |
| 1023 | { |
| 1024 | vl_api_disconnect_session_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1025 | vnet_disconnect_args_t _a, *a = &_a; |
| 1026 | application_t *app; |
| 1027 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1028 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1029 | if (session_manager_is_enabled () == 0) |
| 1030 | { |
| 1031 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1032 | goto done; |
| 1033 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1034 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1035 | app = application_lookup (mp->client_index); |
| 1036 | if (app) |
| 1037 | { |
| 1038 | a->handle = mp->handle; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1039 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1040 | rv = vnet_disconnect_session (a); |
| 1041 | } |
| 1042 | else |
| 1043 | { |
| 1044 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1045 | } |
| 1046 | |
| 1047 | done: |
Dave Wallace | de5fec9 | 2017-11-11 22:41:34 -0500 | [diff] [blame] | 1048 | REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static void |
| 1052 | vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t * |
| 1053 | mp) |
| 1054 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1055 | vnet_disconnect_args_t _a, *a = &_a; |
| 1056 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1057 | |
| 1058 | /* Client objected to disconnecting the session, log and continue */ |
| 1059 | if (mp->retval) |
| 1060 | { |
| 1061 | clib_warning ("client retval %d", mp->retval); |
| 1062 | return; |
| 1063 | } |
| 1064 | |
| 1065 | /* Disconnect has been confirmed. Confirm close to transport */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1066 | app = application_lookup (mp->context); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1067 | if (app) |
| 1068 | { |
| 1069 | a->handle = mp->handle; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1070 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1071 | vnet_disconnect_session (a); |
| 1072 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | static void |
| 1076 | vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp) |
| 1077 | { |
Florin Coras | 4af830c | 2018-12-04 09:21:36 -0800 | [diff] [blame] | 1078 | vnet_disconnect_args_t _a = { 0 }, *a = &_a; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1079 | app_worker_t *app_wrk; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1080 | application_t *app; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1081 | session_t *s; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1082 | u32 index, thread_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1083 | |
Ondrej Fabry | 6bd197e | 2018-08-15 08:46:46 +0200 | [diff] [blame] | 1084 | app = application_lookup (mp->context); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1085 | if (!app) |
| 1086 | return; |
| 1087 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1088 | session_parse_handle (mp->handle, &index, &thread_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1089 | s = session_get_if_valid (index, thread_index); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1090 | if (!s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1091 | { |
| 1092 | clib_warning ("Invalid session!"); |
| 1093 | return; |
| 1094 | } |
| 1095 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1096 | app_wrk = app_worker_get (s->app_wrk_index); |
| 1097 | if (app_wrk->app_index != app->app_index) |
| 1098 | { |
| 1099 | clib_warning ("app %u does not own handle 0x%lx", app->app_index, |
| 1100 | mp->handle); |
| 1101 | return; |
| 1102 | } |
| 1103 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1104 | /* Client objected to resetting the session, log and continue */ |
| 1105 | if (mp->retval) |
| 1106 | { |
| 1107 | clib_warning ("client retval %d", mp->retval); |
| 1108 | return; |
| 1109 | } |
| 1110 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1111 | /* This comes as a response to a reset, transport only waiting for |
| 1112 | * confirmation to remove connection state, no need to disconnect */ |
Florin Coras | 4af830c | 2018-12-04 09:21:36 -0800 | [diff] [blame] | 1113 | a->handle = mp->handle; |
| 1114 | a->app_index = app->app_index; |
| 1115 | vnet_disconnect_session (a); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static void |
| 1119 | vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp) |
| 1120 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1121 | vnet_disconnect_args_t _a = { 0 }, *a = &_a; |
| 1122 | local_session_t *ls; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1123 | session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1124 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1125 | /* Server isn't interested, kill the session */ |
| 1126 | if (mp->retval) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1127 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1128 | a->app_index = mp->context; |
| 1129 | a->handle = mp->handle; |
| 1130 | vnet_disconnect_session (a); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1131 | return; |
| 1132 | } |
| 1133 | |
| 1134 | if (session_handle_is_local (mp->handle)) |
| 1135 | { |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 1136 | ls = app_worker_get_local_session_from_handle (mp->handle); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1137 | if (!ls || ls->app_wrk_index != mp->context) |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1138 | { |
| 1139 | clib_warning ("server %u doesn't own local handle %llu", |
| 1140 | mp->context, mp->handle); |
| 1141 | return; |
| 1142 | } |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 1143 | if (app_worker_local_session_connect_notify (ls)) |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1144 | return; |
| 1145 | ls->session_state = SESSION_STATE_READY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1146 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1147 | else |
| 1148 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1149 | s = session_get_from_handle_if_valid (mp->handle); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1150 | if (!s) |
| 1151 | { |
| 1152 | clib_warning ("session doesn't exist"); |
| 1153 | return; |
| 1154 | } |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1155 | if (s->app_wrk_index != mp->context) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1156 | { |
| 1157 | clib_warning ("app doesn't own session"); |
| 1158 | return; |
| 1159 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1160 | s->session_state = SESSION_STATE_READY; |
| 1161 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | static void |
| 1165 | vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t |
| 1166 | * mp) |
| 1167 | { |
| 1168 | clib_warning ("not implemented"); |
| 1169 | } |
| 1170 | |
| 1171 | static void |
| 1172 | vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp) |
| 1173 | { |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1174 | vnet_listen_args_t _a, *a = &_a; |
| 1175 | transport_connection_t *tc = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1176 | vl_api_bind_sock_reply_t *rmp; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1177 | svm_msg_q_t *vpp_evt_q; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1178 | application_t *app = 0; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 1179 | app_worker_t *app_wrk; |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1180 | ip46_address_t *ip46; |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1181 | app_listener_t *al; |
| 1182 | session_t *s; |
| 1183 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1184 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1185 | if (session_manager_is_enabled () == 0) |
| 1186 | { |
| 1187 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1188 | goto done; |
| 1189 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1190 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1191 | app = application_lookup (mp->client_index); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1192 | if (!app) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1193 | { |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1194 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1195 | goto done; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1196 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1197 | |
| 1198 | ip46 = (ip46_address_t *) mp->ip; |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1199 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1200 | a->sep.is_ip4 = mp->is_ip4; |
| 1201 | a->sep.ip = *ip46; |
| 1202 | a->sep.port = mp->port; |
| 1203 | a->sep.fib_index = mp->vrf; |
| 1204 | a->sep.sw_if_index = ENDPOINT_INVALID_INDEX; |
| 1205 | a->sep.transport_proto = mp->proto; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1206 | a->app_index = app->app_index; |
| 1207 | a->wrk_map_index = mp->wrk_index; |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1208 | |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 1209 | if ((rv = vnet_listen (a))) |
| 1210 | clib_warning ("listen returned: %d", rv); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1211 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1212 | done: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1213 | /* *INDENT-OFF* */ |
| 1214 | REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({ |
| 1215 | if (!rv) |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1216 | { |
| 1217 | rmp->handle = a->handle; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1218 | rmp->lcl_port = mp->port; |
Keith Burns (alagalah) | 60ae80f | 2018-03-15 10:04:20 -0700 | [diff] [blame] | 1219 | rmp->lcl_is_ip4 = mp->is_ip4; |
Dave Wallace | 97b1a27 | 2017-12-18 13:51:59 -0500 | [diff] [blame] | 1220 | if (app && application_has_global_scope (app)) |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1221 | { |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1222 | al = app_listener_get_w_handle (a->handle); |
| 1223 | s = app_listener_get_session (al); |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1224 | tc = listen_session_get_transport (s); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1225 | 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] | 1226 | if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL) |
| 1227 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1228 | rmp->rx_fifo = pointer_to_uword (s->rx_fifo); |
| 1229 | rmp->tx_fifo = pointer_to_uword (s->tx_fifo); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1230 | vpp_evt_q = session_manager_get_vpp_event_queue (0); |
| 1231 | rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q); |
| 1232 | } |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1233 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1234 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1235 | })); |
| 1236 | /* *INDENT-ON* */ |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 1237 | |
| 1238 | /* If app uses mq for control messages, send an mq message as well */ |
| 1239 | if (app && application_use_mq_for_ctrl (app)) |
| 1240 | { |
| 1241 | app_wrk = application_get_worker (app, mp->wrk_index); |
| 1242 | mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle, |
| 1243 | rv); |
| 1244 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | static void |
| 1248 | vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp) |
| 1249 | { |
| 1250 | vl_api_unbind_sock_reply_t *rmp; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 1251 | vnet_unlisten_args_t _a, *a = &_a; |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 1252 | app_worker_t *app_wrk; |
| 1253 | application_t *app = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1254 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1255 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1256 | if (session_manager_is_enabled () == 0) |
| 1257 | { |
| 1258 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1259 | goto done; |
| 1260 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1261 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1262 | app = application_lookup (mp->client_index); |
| 1263 | if (app) |
| 1264 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1265 | a->app_index = app->app_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1266 | a->handle = mp->handle; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1267 | a->wrk_map_index = mp->wrk_index; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 1268 | if ((rv = vnet_unlisten (a))) |
| 1269 | clib_warning ("unlisten returned: %d", rv); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1270 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1271 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1272 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1273 | REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY); |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 1274 | |
| 1275 | /* |
| 1276 | * Send reply over msg queue |
| 1277 | */ |
| 1278 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 1279 | session_unlisten_reply_msg_t *ump; |
| 1280 | svm_msg_q_t *app_mq; |
| 1281 | session_event_t *evt; |
| 1282 | |
| 1283 | if (!app) |
| 1284 | return; |
| 1285 | |
| 1286 | app_wrk = application_get_worker (app, a->wrk_map_index); |
| 1287 | if (!app_wrk) |
| 1288 | return; |
| 1289 | |
| 1290 | app_mq = app_wrk->event_queue; |
| 1291 | if (mq_try_lock_and_alloc_msg (app_mq, msg)) |
| 1292 | return; |
| 1293 | |
| 1294 | evt = svm_msg_q_msg_data (app_mq, msg); |
| 1295 | clib_memset (evt, 0, sizeof (*evt)); |
| 1296 | evt->event_type = SESSION_CTRL_EVT_UNLISTEN_REPLY; |
| 1297 | ump = (session_unlisten_reply_msg_t *) evt->data; |
| 1298 | ump->context = mp->context; |
| 1299 | ump->handle = mp->handle; |
| 1300 | ump->retval = rv; |
| 1301 | svm_msg_q_add_and_unlock (app_mq, msg); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | static void |
| 1305 | vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp) |
| 1306 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1307 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1308 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1309 | application_t *app = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1310 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1311 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1312 | if (session_manager_is_enabled () == 0) |
| 1313 | { |
| 1314 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1315 | goto done; |
| 1316 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1317 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1318 | app = application_lookup (mp->client_index); |
| 1319 | if (app) |
| 1320 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 1321 | svm_queue_t *client_q; |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1322 | ip46_address_t *ip46 = (ip46_address_t *) mp->ip; |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 1323 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1324 | clib_memset (a, 0, sizeof (*a)); |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 1325 | client_q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1326 | mp->client_queue_address = pointer_to_uword (client_q); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1327 | a->sep.is_ip4 = mp->is_ip4; |
| 1328 | a->sep.ip = *ip46; |
| 1329 | a->sep.port = mp->port; |
| 1330 | a->sep.transport_proto = mp->proto; |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 1331 | a->sep.peer.fib_index = mp->vrf; |
| 1332 | a->sep.peer.sw_if_index = ENDPOINT_INVALID_INDEX; |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1333 | if (mp->hostname_len) |
| 1334 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1335 | vec_validate (a->sep_ext.hostname, mp->hostname_len - 1); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1336 | clib_memcpy_fast (a->sep_ext.hostname, mp->hostname, |
| 1337 | mp->hostname_len); |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1338 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1339 | a->api_context = mp->context; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1340 | a->app_index = app->app_index; |
| 1341 | a->wrk_map_index = mp->wrk_index; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 1342 | if ((rv = vnet_connect (a))) |
| 1343 | clib_warning ("connect returned: %u", rv); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1344 | vec_free (a->sep_ext.hostname); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1345 | } |
| 1346 | else |
| 1347 | { |
| 1348 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1349 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1350 | |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1351 | if (rv == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1352 | return; |
| 1353 | |
| 1354 | /* Got some error, relay it */ |
| 1355 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1356 | done: |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1357 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1358 | |
| 1359 | if (app && application_use_mq_for_ctrl (app)) |
| 1360 | { |
| 1361 | app_worker_t *app_wrk = application_get_worker (app, mp->wrk_index); |
| 1362 | mq_send_session_connected_cb (app_wrk->wrk_index, mp->context, 0, 1); |
| 1363 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1364 | } |
| 1365 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1366 | static void |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1367 | vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp) |
| 1368 | { |
| 1369 | int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0; |
| 1370 | vl_api_app_worker_add_del_reply_t *rmp; |
| 1371 | vl_api_registration_t *reg; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1372 | application_t *app; |
| 1373 | u8 fd_flags = 0; |
| 1374 | |
| 1375 | if (!session_manager_is_enabled ()) |
| 1376 | { |
| 1377 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1378 | goto done; |
| 1379 | } |
| 1380 | |
| 1381 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1382 | if (!reg) |
| 1383 | return; |
| 1384 | |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 1385 | 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] | 1386 | if (!app) |
| 1387 | { |
| 1388 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1389 | goto done; |
| 1390 | } |
| 1391 | |
| 1392 | vnet_app_worker_add_del_args_t args = { |
| 1393 | .app_index = app->app_index, |
Florin Coras | 349f8ca | 2018-11-20 16:52:49 -0800 | [diff] [blame] | 1394 | .wrk_map_index = clib_net_to_host_u32 (mp->wrk_index), |
Florin Coras | c1f5a43 | 2018-11-20 11:31:26 -0800 | [diff] [blame] | 1395 | .api_client_index = mp->client_index, |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1396 | .is_add = mp->is_add |
| 1397 | }; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 1398 | rv = vnet_app_worker_add_del (&args); |
| 1399 | if (rv) |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1400 | { |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 1401 | clib_warning ("app worker add/del returned: %d", rv); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1402 | goto done; |
| 1403 | } |
| 1404 | |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 1405 | if (!mp->is_add) |
| 1406 | goto done; |
Florin Coras | c3638fe | 2018-08-24 13:58:49 -0700 | [diff] [blame] | 1407 | |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1408 | /* Send fifo segment fd if needed */ |
| 1409 | if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD) |
| 1410 | { |
| 1411 | fd_flags |= SESSION_FD_F_MEMFD_SEGMENT; |
| 1412 | fds[n_fds] = args.segment->fd; |
| 1413 | n_fds += 1; |
| 1414 | } |
| 1415 | if (application_segment_manager_properties (app)->use_mq_eventfd) |
| 1416 | { |
| 1417 | fd_flags |= SESSION_FD_F_MQ_EVENTFD; |
| 1418 | fds[n_fds] = svm_msg_q_get_producer_eventfd (args.evt_q); |
| 1419 | n_fds += 1; |
| 1420 | } |
| 1421 | |
| 1422 | /* *INDENT-OFF* */ |
| 1423 | done: |
| 1424 | REPLY_MACRO2 (VL_API_APP_WORKER_ADD_DEL_REPLY, ({ |
| 1425 | rmp->is_add = mp->is_add; |
Florin Coras | 349f8ca | 2018-11-20 16:52:49 -0800 | [diff] [blame] | 1426 | rmp->wrk_index = clib_host_to_net_u32 (args.wrk_map_index); |
Florin Coras | fa76a76 | 2018-11-29 12:40:10 -0800 | [diff] [blame] | 1427 | rmp->segment_handle = clib_host_to_net_u64 (args.segment_handle); |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 1428 | if (!rv && mp->is_add) |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1429 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1430 | if (vec_len (args.segment->name)) |
| 1431 | { |
| 1432 | memcpy (rmp->segment_name, args.segment->name, |
| 1433 | vec_len (args.segment->name)); |
| 1434 | rmp->segment_name_length = vec_len (args.segment->name); |
| 1435 | } |
| 1436 | rmp->app_event_queue_address = pointer_to_uword (args.evt_q); |
| 1437 | rmp->n_fds = n_fds; |
| 1438 | rmp->fd_flags = fd_flags; |
| 1439 | } |
| 1440 | })); |
| 1441 | /* *INDENT-ON* */ |
| 1442 | |
| 1443 | if (n_fds) |
| 1444 | session_send_fds (reg, fds, n_fds); |
| 1445 | } |
| 1446 | |
| 1447 | static void |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1448 | vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp) |
| 1449 | { |
| 1450 | vl_api_app_namespace_add_del_reply_t *rmp; |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1451 | u32 appns_index = 0; |
| 1452 | u8 *ns_id = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1453 | int rv = 0; |
| 1454 | if (!session_manager_is_enabled ()) |
| 1455 | { |
| 1456 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1457 | goto done; |
| 1458 | } |
| 1459 | |
| 1460 | if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id)) |
| 1461 | { |
| 1462 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1463 | goto done; |
| 1464 | } |
| 1465 | |
| 1466 | vec_validate (ns_id, mp->namespace_id_len - 1); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1467 | clib_memcpy_fast (ns_id, mp->namespace_id, mp->namespace_id_len); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1468 | vnet_app_namespace_add_del_args_t args = { |
| 1469 | .ns_id = ns_id, |
Florin Coras | 9a9adb2 | 2017-10-26 08:16:59 -0700 | [diff] [blame] | 1470 | .secret = clib_net_to_host_u64 (mp->secret), |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1471 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 1472 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 1473 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 1474 | .is_add = 1 |
| 1475 | }; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 1476 | rv = vnet_app_namespace_add_del (&args); |
| 1477 | if (!rv) |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1478 | { |
| 1479 | appns_index = app_namespace_index_from_id (ns_id); |
| 1480 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 1481 | { |
| 1482 | clib_warning ("app ns lookup failed"); |
| 1483 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1484 | } |
| 1485 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1486 | vec_free (ns_id); |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1487 | |
| 1488 | /* *INDENT-OFF* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1489 | done: |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1490 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({ |
| 1491 | if (!rv) |
| 1492 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 1493 | })); |
| 1494 | /* *INDENT-ON* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1497 | static void |
| 1498 | vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp) |
| 1499 | { |
| 1500 | vl_api_session_rule_add_del_reply_t *rmp; |
| 1501 | session_rule_add_del_args_t args; |
| 1502 | session_rule_table_add_del_args_t *table_args = &args.table_args; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1503 | u8 fib_proto; |
| 1504 | int rv = 0; |
| 1505 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1506 | clib_memset (&args, 0, sizeof (args)); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1507 | fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; |
| 1508 | |
| 1509 | table_args->lcl.fp_len = mp->lcl_plen; |
| 1510 | table_args->lcl.fp_proto = fib_proto; |
| 1511 | table_args->rmt.fp_len = mp->rmt_plen; |
| 1512 | table_args->rmt.fp_proto = fib_proto; |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1513 | table_args->lcl_port = mp->lcl_port; |
| 1514 | table_args->rmt_port = mp->rmt_port; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1515 | table_args->action_index = clib_net_to_host_u32 (mp->action_index); |
| 1516 | table_args->is_add = mp->is_add; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1517 | mp->tag[sizeof (mp->tag) - 1] = 0; |
| 1518 | table_args->tag = format (0, "%s", mp->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1519 | args.appns_index = clib_net_to_host_u32 (mp->appns_index); |
| 1520 | args.scope = mp->scope; |
Florin Coras | 42324ad | 2017-11-18 18:45:20 -0800 | [diff] [blame] | 1521 | args.transport_proto = mp->transport_proto; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1522 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1523 | clib_memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr)); |
| 1524 | 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] | 1525 | ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4); |
| 1526 | 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] | 1527 | rv = vnet_session_rule_add_del (&args); |
| 1528 | if (rv) |
| 1529 | clib_warning ("rule add del returned: %d", rv); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1530 | vec_free (table_args->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1531 | REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY); |
| 1532 | } |
| 1533 | |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1534 | static void |
| 1535 | send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1536 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1537 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1538 | { |
| 1539 | vl_api_session_rules_details_t *rmp = 0; |
| 1540 | session_mask_or_match_4_t *match = |
| 1541 | (session_mask_or_match_4_t *) & rule->match; |
| 1542 | session_mask_or_match_4_t *mask = |
| 1543 | (session_mask_or_match_4_t *) & rule->mask; |
| 1544 | |
| 1545 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1546 | clib_memset (rmp, 0, sizeof (*rmp)); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1547 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 1548 | rmp->context = context; |
| 1549 | |
| 1550 | rmp->is_ip4 = 1; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1551 | clib_memcpy_fast (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 1552 | 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] | 1553 | rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip); |
| 1554 | rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1555 | rmp->lcl_port = match->lcl_port; |
| 1556 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1557 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
| 1558 | rmp->scope = |
| 1559 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
| 1560 | rmp->transport_proto = transport_proto; |
| 1561 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1562 | if (tag) |
| 1563 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1564 | clib_memcpy_fast (rmp->tag, tag, vec_len (tag)); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1565 | rmp->tag[vec_len (tag)] = 0; |
| 1566 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1567 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1568 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static void |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1572 | send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local, |
| 1573 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1574 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1575 | { |
| 1576 | vl_api_session_rules_details_t *rmp = 0; |
| 1577 | session_mask_or_match_6_t *match = |
| 1578 | (session_mask_or_match_6_t *) & rule->match; |
| 1579 | session_mask_or_match_6_t *mask = |
| 1580 | (session_mask_or_match_6_t *) & rule->mask; |
| 1581 | |
| 1582 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1583 | clib_memset (rmp, 0, sizeof (*rmp)); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1584 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 1585 | rmp->context = context; |
| 1586 | |
| 1587 | rmp->is_ip4 = 0; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1588 | clib_memcpy_fast (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 1589 | 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] | 1590 | rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip); |
| 1591 | rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1592 | rmp->lcl_port = match->lcl_port; |
| 1593 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1594 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1595 | rmp->scope = |
| 1596 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1597 | rmp->transport_proto = transport_proto; |
| 1598 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1599 | if (tag) |
| 1600 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1601 | clib_memcpy_fast (rmp->tag, tag, vec_len (tag)); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1602 | rmp->tag[vec_len (tag)] = 0; |
| 1603 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1604 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1605 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | static void |
| 1609 | 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] | 1610 | u8 tp, u8 is_local, u32 appns_index, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1611 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1612 | { |
| 1613 | mma_rule_16_t *rule16; |
| 1614 | mma_rule_40_t *rule40; |
| 1615 | mma_rules_table_16_t *srt16; |
| 1616 | mma_rules_table_40_t *srt40; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1617 | u32 ri; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1618 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1619 | if (is_local || fib_proto == FIB_PROTOCOL_IP4) |
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 | u8 *tag = 0; |
| 1622 | /* *INDENT-OFF* */ |
| 1623 | srt16 = &srt->session_rules_tables_16; |
| 1624 | pool_foreach (rule16, srt16->rules, ({ |
| 1625 | ri = mma_rules_table_rule_index_16 (srt16, rule16); |
| 1626 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1627 | send_session_rule_details4 (rule16, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1628 | reg, context); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1629 | })); |
| 1630 | /* *INDENT-ON* */ |
| 1631 | } |
| 1632 | if (is_local || fib_proto == FIB_PROTOCOL_IP6) |
| 1633 | { |
| 1634 | u8 *tag = 0; |
| 1635 | /* *INDENT-OFF* */ |
| 1636 | srt40 = &srt->session_rules_tables_40; |
| 1637 | pool_foreach (rule40, srt40->rules, ({ |
| 1638 | ri = mma_rules_table_rule_index_40 (srt40, rule40); |
| 1639 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1640 | send_session_rule_details6 (rule40, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1641 | reg, context); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1642 | })); |
| 1643 | /* *INDENT-ON* */ |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | static void |
| 1648 | vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp) |
| 1649 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1650 | vl_api_registration_t *reg; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1651 | session_table_t *st; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1652 | u8 tp; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1653 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1654 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1655 | if (!reg) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1656 | return; |
| 1657 | |
| 1658 | /* *INDENT-OFF* */ |
| 1659 | session_table_foreach (st, ({ |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1660 | for (tp = 0; tp < TRANSPORT_N_PROTO; tp++) |
| 1661 | { |
| 1662 | send_session_rules_table_details (&st->session_rules[tp], |
| 1663 | st->active_fib_proto, tp, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1664 | st->is_local, st->appns_index, reg, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1665 | mp->context); |
| 1666 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1667 | })); |
| 1668 | /* *INDENT-ON* */ |
| 1669 | } |
| 1670 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1671 | static void |
| 1672 | vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t * |
| 1673 | mp) |
| 1674 | { |
| 1675 | vl_api_app_namespace_add_del_reply_t *rmp; |
| 1676 | vnet_app_add_tls_cert_args_t _a, *a = &_a; |
| 1677 | clib_error_t *error; |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1678 | application_t *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1679 | u32 cert_len; |
| 1680 | int rv = 0; |
| 1681 | if (!session_manager_is_enabled ()) |
| 1682 | { |
| 1683 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1684 | goto done; |
| 1685 | } |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1686 | if (!(app = application_lookup (mp->client_index))) |
| 1687 | { |
| 1688 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1689 | goto done; |
| 1690 | } |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1691 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1692 | a->app_index = app->app_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1693 | cert_len = clib_net_to_host_u16 (mp->cert_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1694 | if (cert_len > 10000) |
| 1695 | { |
| 1696 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1697 | goto done; |
| 1698 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1699 | vec_validate (a->cert, cert_len); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1700 | clib_memcpy_fast (a->cert, mp->cert, cert_len); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1701 | if ((error = vnet_app_add_tls_cert (a))) |
| 1702 | { |
| 1703 | rv = clib_error_get_code (error); |
| 1704 | clib_error_report (error); |
| 1705 | } |
| 1706 | vec_free (a->cert); |
| 1707 | done: |
| 1708 | REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY); |
| 1709 | } |
| 1710 | |
| 1711 | static void |
| 1712 | vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t * |
| 1713 | mp) |
| 1714 | { |
| 1715 | vl_api_app_namespace_add_del_reply_t *rmp; |
| 1716 | vnet_app_add_tls_key_args_t _a, *a = &_a; |
| 1717 | clib_error_t *error; |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1718 | application_t *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1719 | u32 key_len; |
| 1720 | int rv = 0; |
| 1721 | if (!session_manager_is_enabled ()) |
| 1722 | { |
| 1723 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1724 | goto done; |
| 1725 | } |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1726 | if (!(app = application_lookup (mp->client_index))) |
| 1727 | { |
| 1728 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1729 | goto done; |
| 1730 | } |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 1731 | clib_memset (a, 0, sizeof (*a)); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1732 | a->app_index = app->app_index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1733 | key_len = clib_net_to_host_u16 (mp->key_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1734 | if (key_len > 10000) |
| 1735 | { |
| 1736 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1737 | goto done; |
| 1738 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1739 | vec_validate (a->key, key_len); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1740 | clib_memcpy_fast (a->key, mp->key, key_len); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1741 | if ((error = vnet_app_add_tls_key (a))) |
| 1742 | { |
| 1743 | rv = clib_error_get_code (error); |
| 1744 | clib_error_report (error); |
| 1745 | } |
| 1746 | vec_free (a->key); |
| 1747 | done: |
| 1748 | REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY); |
| 1749 | } |
| 1750 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1751 | static clib_error_t * |
| 1752 | application_reaper_cb (u32 client_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1753 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1754 | application_t *app = application_lookup (client_index); |
| 1755 | vnet_app_detach_args_t _a, *a = &_a; |
| 1756 | if (app) |
| 1757 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1758 | a->app_index = app->app_index; |
Florin Coras | 053a0e4 | 2018-11-13 15:52:38 -0800 | [diff] [blame] | 1759 | a->api_client_index = client_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1760 | vnet_application_detach (a); |
| 1761 | } |
| 1762 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1763 | } |
| 1764 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1765 | VL_MSG_API_REAPER_FUNCTION (application_reaper_cb); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1766 | |
| 1767 | #define vl_msg_name_crc_list |
| 1768 | #include <vnet/vnet_all_api_h.h> |
| 1769 | #undef vl_msg_name_crc_list |
| 1770 | |
| 1771 | static void |
| 1772 | setup_message_id_table (api_main_t * am) |
| 1773 | { |
| 1774 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1775 | foreach_vl_msg_name_crc_session; |
| 1776 | #undef _ |
| 1777 | } |
| 1778 | |
| 1779 | /* |
| 1780 | * session_api_hookup |
| 1781 | * Add uri's API message handlers to the table. |
| 1782 | * vlib has alread mapped shared memory and |
| 1783 | * added the client registration handlers. |
| 1784 | * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process() |
| 1785 | */ |
| 1786 | static clib_error_t * |
| 1787 | session_api_hookup (vlib_main_t * vm) |
| 1788 | { |
| 1789 | api_main_t *am = &api_main; |
| 1790 | |
| 1791 | #define _(N,n) \ |
| 1792 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1793 | vl_api_##n##_t_handler, \ |
| 1794 | vl_noop_handler, \ |
| 1795 | vl_api_##n##_t_endian, \ |
| 1796 | vl_api_##n##_t_print, \ |
| 1797 | sizeof(vl_api_##n##_t), 1); |
| 1798 | foreach_session_api_msg; |
| 1799 | #undef _ |
| 1800 | |
| 1801 | /* |
| 1802 | * Messages which bounce off the data-plane to |
| 1803 | * an API client. Simply tells the message handling infra not |
| 1804 | * to free the message. |
| 1805 | * |
| 1806 | * Bounced message handlers MUST NOT block the data plane |
| 1807 | */ |
| 1808 | am->message_bounce[VL_API_CONNECT_URI] = 1; |
| 1809 | am->message_bounce[VL_API_CONNECT_SOCK] = 1; |
| 1810 | |
| 1811 | /* |
| 1812 | * Set up the (msg_name, crc, message-id) table |
| 1813 | */ |
| 1814 | setup_message_id_table (am); |
| 1815 | |
| 1816 | return 0; |
| 1817 | } |
| 1818 | |
| 1819 | VLIB_API_INIT_FUNCTION (session_api_hookup); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1820 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1821 | /* |
| 1822 | * fd.io coding-style-patch-verification: ON |
| 1823 | * |
| 1824 | * Local Variables: |
| 1825 | * eval: (c-set-style "gnu") |
| 1826 | * End: |
| 1827 | */ |