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