Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vnet/vnet.h> |
| 17 | #include <vlibmemory/api.h> |
| 18 | #include <vnet/session/application.h> |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 19 | #include <vnet/session/application_interface.h> |
| 20 | #include <vnet/session/session_rules_table.h> |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 21 | #include <vnet/session/session_table.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 22 | |
| 23 | #include <vnet/vnet_msg_enum.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 24 | |
| 25 | #define vl_typedefs /* define message structures */ |
| 26 | #include <vnet/vnet_all_api_h.h> |
| 27 | #undef vl_typedefs |
| 28 | |
| 29 | #define vl_endianfun /* define message structures */ |
| 30 | #include <vnet/vnet_all_api_h.h> |
| 31 | #undef vl_endianfun |
| 32 | |
| 33 | /* instantiate all the print functions we know about */ |
| 34 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 35 | #define vl_printfun |
| 36 | #include <vnet/vnet_all_api_h.h> |
| 37 | #undef vl_printfun |
| 38 | |
| 39 | #include <vlibapi/api_helper_macros.h> |
| 40 | |
| 41 | #define foreach_session_api_msg \ |
| 42 | _(MAP_ANOTHER_SEGMENT_REPLY, map_another_segment_reply) \ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 43 | _(APPLICATION_ATTACH, application_attach) \ |
| 44 | _(APPLICATION_DETACH, application_detach) \ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 45 | _(BIND_URI, bind_uri) \ |
| 46 | _(UNBIND_URI, unbind_uri) \ |
| 47 | _(CONNECT_URI, connect_uri) \ |
| 48 | _(DISCONNECT_SESSION, disconnect_session) \ |
| 49 | _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \ |
| 50 | _(ACCEPT_SESSION_REPLY, accept_session_reply) \ |
| 51 | _(RESET_SESSION_REPLY, reset_session_reply) \ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 52 | _(BIND_SOCK, bind_sock) \ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 53 | _(UNBIND_SOCK, unbind_sock) \ |
| 54 | _(CONNECT_SOCK, connect_sock) \ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 55 | _(SESSION_ENABLE_DISABLE, session_enable_disable) \ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 56 | _(APP_NAMESPACE_ADD_DEL, app_namespace_add_del) \ |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 57 | _(SESSION_RULE_ADD_DEL, session_rule_add_del) \ |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 58 | _(SESSION_RULES_DUMP, session_rules_dump) \ |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 59 | _(APPLICATION_TLS_CERT_ADD, application_tls_cert_add) \ |
| 60 | _(APPLICATION_TLS_KEY_ADD, application_tls_key_add) \ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 61 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 62 | static int |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 63 | session_send_memfd_fd (vl_api_registration_t * reg, const ssvm_private_t * sp) |
| 64 | { |
| 65 | clib_error_t *error; |
| 66 | if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
| 67 | { |
| 68 | clib_warning ("can't send memfd fd"); |
| 69 | return -1; |
| 70 | } |
| 71 | error = vl_api_send_fd_msg (reg, sp->fd); |
| 72 | if (error) |
| 73 | { |
| 74 | clib_error_report (error); |
| 75 | return -1; |
| 76 | } |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static int |
| 81 | send_add_segment_callback (u32 api_client_index, const ssvm_private_t * sp) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 82 | { |
| 83 | vl_api_map_another_segment_t *mp; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 84 | vl_api_registration_t *reg; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 85 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 86 | reg = vl_mem_api_client_index_to_registration (api_client_index); |
| 87 | if (!reg) |
| 88 | { |
| 89 | clib_warning ("no registration: %u", api_client_index); |
| 90 | return -1; |
| 91 | } |
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 | if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD |
| 94 | && vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
| 95 | { |
| 96 | clib_warning ("can't send memfd fd"); |
| 97 | return -1; |
| 98 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 99 | |
Florin Coras | 7a2e1bd | 2017-11-30 16:07:39 -0500 | [diff] [blame] | 100 | mp = vl_msg_api_alloc_as_if_client (sizeof (*mp)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 101 | memset (mp, 0, sizeof (*mp)); |
| 102 | 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] | 103 | mp->segment_size = sp->ssvm_size; |
| 104 | strncpy ((char *) mp->segment_name, (char *) sp->name, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 105 | sizeof (mp->segment_name) - 1); |
| 106 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 107 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
| 108 | |
| 109 | if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD) |
| 110 | return session_send_memfd_fd (reg, sp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static int |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 116 | send_del_segment_callback (u32 api_client_index, const ssvm_private_t * fs) |
| 117 | { |
| 118 | vl_api_unmap_segment_t *mp; |
| 119 | vl_api_registration_t *reg; |
| 120 | |
| 121 | reg = vl_mem_api_client_index_to_registration (api_client_index); |
| 122 | if (!reg) |
| 123 | { |
| 124 | clib_warning ("no registration: %u", api_client_index); |
| 125 | return -1; |
| 126 | } |
| 127 | |
| 128 | if (ssvm_type (fs) == SSVM_SEGMENT_MEMFD |
| 129 | && vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
| 130 | { |
| 131 | clib_warning ("can't send memfd fd"); |
| 132 | return -1; |
| 133 | } |
| 134 | |
| 135 | mp = vl_msg_api_alloc_as_if_client (sizeof (*mp)); |
| 136 | memset (mp, 0, sizeof (*mp)); |
| 137 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_UNMAP_SEGMENT); |
| 138 | strncpy ((char *) mp->segment_name, (char *) fs->name, |
| 139 | sizeof (mp->segment_name) - 1); |
| 140 | |
| 141 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
| 142 | |
| 143 | if (ssvm_type (fs) == SSVM_SEGMENT_MEMFD) |
| 144 | return session_send_memfd_fd (reg, fs); |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 150 | send_session_accept_callback (stream_session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 151 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 152 | application_t *server = application_get (s->app_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 153 | transport_proto_vft_t *tp_vft; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 154 | vl_api_accept_session_t *mp; |
| 155 | vl_api_registration_t *reg; |
| 156 | transport_connection_t *tc; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 157 | stream_session_t *listener; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 158 | svm_msg_q_t *vpp_queue; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 159 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 160 | reg = vl_mem_api_client_index_to_registration (server->api_client_index); |
| 161 | if (!reg) |
| 162 | { |
| 163 | clib_warning ("no registration: %u", server->api_client_index); |
| 164 | return -1; |
| 165 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 166 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 167 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 168 | memset (mp, 0, sizeof (*mp)); |
| 169 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 170 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 171 | mp->context = server->index; |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 172 | mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 173 | mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 174 | |
| 175 | if (session_has_transport (s)) |
| 176 | { |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 177 | listener = listen_session_get (s->listener_index); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 178 | mp->listener_handle = listen_session_get_handle (listener); |
| 179 | if (application_is_proxy (server)) |
| 180 | { |
| 181 | listener = |
| 182 | application_first_listener (server, session_get_fib_proto (s), |
| 183 | session_get_transport_proto (s)); |
| 184 | if (listener) |
| 185 | mp->listener_handle = listen_session_get_handle (listener); |
| 186 | } |
| 187 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 188 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 189 | mp->handle = session_handle (s); |
| 190 | tp_vft = transport_protocol_get_vft (session_get_transport_proto (s)); |
| 191 | tc = tp_vft->get_connection (s->connection_index, s->thread_index); |
| 192 | mp->port = tc->rmt_port; |
| 193 | mp->is_ip4 = tc->is_ip4; |
| 194 | clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip)); |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | local_session_t *ls = (local_session_t *) s; |
| 199 | local_session_t *ll; |
| 200 | if (application_local_session_listener_has_transport (ls)) |
| 201 | { |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 202 | listener = listen_session_get (ls->listener_index); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 203 | mp->listener_handle = listen_session_get_handle (listener); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 204 | mp->is_ip4 = session_type_is_ip4 (listener->session_type); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 205 | } |
| 206 | else |
| 207 | { |
| 208 | ll = application_get_local_listen_session (server, |
| 209 | ls->listener_index); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 210 | if (ll->transport_listener_index != ~0) |
| 211 | { |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 212 | listener = listen_session_get (ll->transport_listener_index); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 213 | mp->listener_handle = listen_session_get_handle (listener); |
| 214 | } |
| 215 | else |
| 216 | { |
| 217 | mp->listener_handle = application_local_session_handle (ll); |
| 218 | } |
| 219 | mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 220 | } |
| 221 | mp->handle = application_local_session_handle (ls); |
| 222 | mp->port = ls->port; |
| 223 | mp->vpp_event_queue_address = ls->client_evt_q; |
| 224 | mp->server_event_queue_address = ls->server_evt_q; |
| 225 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 226 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 231 | void |
| 232 | send_local_session_disconnect_callback (u32 app_index, local_session_t * ls) |
| 233 | { |
| 234 | application_t *app = application_get (app_index); |
| 235 | vl_api_disconnect_session_t *mp; |
| 236 | vl_api_registration_t *reg; |
| 237 | |
| 238 | reg = vl_mem_api_client_index_to_registration (app->api_client_index); |
| 239 | if (!reg) |
| 240 | { |
| 241 | clib_warning ("no registration: %u", app->api_client_index); |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
| 246 | memset (mp, 0, sizeof (*mp)); |
| 247 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION); |
| 248 | mp->handle = application_local_session_handle (ls); |
| 249 | mp->context = app->api_client_index; |
| 250 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
| 251 | } |
| 252 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 253 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 254 | send_session_disconnect_callback (stream_session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 255 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 256 | application_t *app = application_get (s->app_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 257 | vl_api_disconnect_session_t *mp; |
| 258 | vl_api_registration_t *reg; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 259 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 260 | reg = vl_mem_api_client_index_to_registration (app->api_client_index); |
| 261 | if (!reg) |
| 262 | { |
| 263 | clib_warning ("no registration: %u", app->api_client_index); |
| 264 | return; |
| 265 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 266 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 267 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 268 | memset (mp, 0, sizeof (*mp)); |
| 269 | 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] | 270 | mp->handle = session_handle (s); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 271 | mp->context = app->api_client_index; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 272 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 273 | } |
| 274 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 275 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 276 | send_session_reset_callback (stream_session_t * s) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 277 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 278 | application_t *app = application_get (s->app_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 279 | vl_api_registration_t *reg; |
| 280 | vl_api_reset_session_t *mp; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 281 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 282 | reg = vl_mem_api_client_index_to_registration (app->api_client_index); |
| 283 | if (!reg) |
| 284 | { |
| 285 | clib_warning ("no registration: %u", app->api_client_index); |
| 286 | return; |
| 287 | } |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 288 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 289 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 290 | memset (mp, 0, sizeof (*mp)); |
| 291 | 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] | 292 | mp->handle = session_handle (s); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 293 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Dave Barach | 0194f1a | 2017-05-15 10:11:39 -0400 | [diff] [blame] | 296 | int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 297 | send_session_connected_callback (u32 app_index, u32 api_context, |
| 298 | stream_session_t * s, u8 is_fail) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 299 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 300 | vl_api_connect_session_reply_t *mp; |
Florin Coras | ade70e4 | 2017-10-14 18:56:41 -0700 | [diff] [blame] | 301 | transport_connection_t *tc; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 302 | vl_api_registration_t *reg; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 303 | svm_msg_q_t *vpp_queue; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 304 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 305 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 306 | app = application_get (app_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 307 | reg = vl_mem_api_client_index_to_registration (app->api_client_index); |
| 308 | if (!reg) |
| 309 | { |
| 310 | clib_warning ("no registration: %u", app->api_client_index); |
| 311 | return -1; |
| 312 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 313 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 314 | 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] | 315 | 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] | 316 | mp->context = api_context; |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 317 | |
| 318 | if (is_fail) |
| 319 | goto done; |
| 320 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 321 | if (session_has_transport (s)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 322 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 323 | tc = session_get_transport (s); |
| 324 | if (!tc) |
| 325 | { |
| 326 | is_fail = 1; |
| 327 | goto done; |
| 328 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 329 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 330 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 331 | mp->handle = session_handle (s); |
| 332 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 333 | clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
| 334 | mp->is_ip4 = tc->is_ip4; |
| 335 | mp->lcl_port = tc->lcl_port; |
| 336 | mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 337 | mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | local_session_t *ls = (local_session_t *) s; |
| 342 | mp->handle = application_local_session_handle (ls); |
| 343 | mp->lcl_port = ls->port; |
| 344 | mp->vpp_event_queue_address = ls->server_evt_q; |
| 345 | mp->client_event_queue_address = ls->client_evt_q; |
| 346 | mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 347 | mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 348 | } |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 349 | |
| 350 | done: |
| 351 | mp->retval = is_fail ? |
| 352 | clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 353 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 354 | return 0; |
| 355 | } |
| 356 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 357 | static session_cb_vft_t session_cb_vft = { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 358 | .session_accept_callback = send_session_accept_callback, |
| 359 | .session_disconnect_callback = send_session_disconnect_callback, |
| 360 | .session_connected_callback = send_session_connected_callback, |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 361 | .session_reset_callback = send_session_reset_callback, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 362 | .add_segment_callback = send_add_segment_callback, |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 363 | .del_segment_callback = send_del_segment_callback, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 364 | }; |
| 365 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 366 | static int |
| 367 | mq_send_session_accepted_cb (stream_session_t * s) |
| 368 | { |
| 369 | application_t *app = application_get (s->app_index); |
| 370 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 371 | svm_msg_q_t *vpp_queue, *app_mq; |
| 372 | transport_proto_vft_t *tp_vft; |
| 373 | transport_connection_t *tc; |
| 374 | stream_session_t *listener; |
| 375 | session_accepted_msg_t *mp; |
| 376 | session_event_t *evt; |
| 377 | |
| 378 | app_mq = app->event_queue; |
| 379 | svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, |
| 380 | SVM_Q_WAIT, msg); |
| 381 | svm_msg_q_unlock (app_mq); |
| 382 | |
| 383 | evt = svm_msg_q_msg_data (app_mq, msg); |
| 384 | memset (evt, 0, sizeof (*evt)); |
| 385 | evt->event_type = SESSION_CTRL_EVT_ACCEPTED; |
| 386 | mp = (session_accepted_msg_t *) evt->data; |
| 387 | mp->context = app->index; |
| 388 | mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 389 | mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 390 | |
| 391 | if (session_has_transport (s)) |
| 392 | { |
| 393 | listener = listen_session_get (s->listener_index); |
| 394 | mp->listener_handle = listen_session_get_handle (listener); |
| 395 | if (application_is_proxy (app)) |
| 396 | { |
| 397 | listener = |
| 398 | application_first_listener (app, session_get_fib_proto (s), |
| 399 | session_get_transport_proto (s)); |
| 400 | if (listener) |
| 401 | mp->listener_handle = listen_session_get_handle (listener); |
| 402 | } |
| 403 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 404 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 405 | mp->handle = session_handle (s); |
| 406 | tp_vft = transport_protocol_get_vft (session_get_transport_proto (s)); |
| 407 | tc = tp_vft->get_connection (s->connection_index, s->thread_index); |
| 408 | mp->port = tc->rmt_port; |
| 409 | mp->is_ip4 = tc->is_ip4; |
| 410 | clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip)); |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | local_session_t *ls = (local_session_t *) s; |
| 415 | local_session_t *ll; |
| 416 | if (application_local_session_listener_has_transport (ls)) |
| 417 | { |
| 418 | listener = listen_session_get (ls->listener_index); |
| 419 | mp->listener_handle = listen_session_get_handle (listener); |
| 420 | mp->is_ip4 = session_type_is_ip4 (listener->session_type); |
| 421 | } |
| 422 | else |
| 423 | { |
| 424 | ll = application_get_local_listen_session (app, ls->listener_index); |
| 425 | if (ll->transport_listener_index != ~0) |
| 426 | { |
| 427 | listener = listen_session_get (ll->transport_listener_index); |
| 428 | mp->listener_handle = listen_session_get_handle (listener); |
| 429 | } |
| 430 | else |
| 431 | { |
| 432 | mp->listener_handle = application_local_session_handle (ll); |
| 433 | } |
| 434 | mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type); |
| 435 | } |
| 436 | mp->handle = application_local_session_handle (ls); |
| 437 | mp->port = ls->port; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 438 | vpp_queue = session_manager_get_vpp_event_queue (0); |
| 439 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 440 | mp->client_event_queue_address = ls->client_evt_q; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 441 | mp->server_event_queue_address = ls->server_evt_q; |
| 442 | } |
| 443 | svm_msg_q_add (app_mq, msg, SVM_Q_WAIT); |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static void |
| 449 | mq_send_session_disconnected_cb (stream_session_t * s) |
| 450 | { |
| 451 | application_t *app = application_get (s->app_index); |
| 452 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 453 | session_disconnected_msg_t *mp; |
| 454 | svm_msg_q_t *app_mq; |
| 455 | session_event_t *evt; |
| 456 | |
| 457 | app_mq = app->event_queue; |
| 458 | svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, |
| 459 | SVM_Q_WAIT, msg); |
| 460 | svm_msg_q_unlock (app_mq); |
| 461 | evt = svm_msg_q_msg_data (app_mq, msg); |
| 462 | memset (evt, 0, sizeof (*evt)); |
| 463 | evt->event_type = SESSION_CTRL_EVT_DISCONNECTED; |
| 464 | mp = (session_disconnected_msg_t *) evt->data; |
| 465 | mp->handle = session_handle (s); |
| 466 | mp->context = app->api_client_index; |
| 467 | svm_msg_q_add (app_mq, msg, SVM_Q_WAIT); |
| 468 | } |
| 469 | |
| 470 | static void |
| 471 | mq_send_session_reset_cb (stream_session_t * s) |
| 472 | { |
| 473 | application_t *app = application_get (s->app_index); |
| 474 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 475 | session_reset_msg_t *mp; |
| 476 | svm_msg_q_t *app_mq; |
| 477 | session_event_t *evt; |
| 478 | |
| 479 | app_mq = app->event_queue; |
| 480 | svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, |
| 481 | SVM_Q_WAIT, msg); |
| 482 | svm_msg_q_unlock (app_mq); |
| 483 | evt = svm_msg_q_msg_data (app_mq, msg); |
| 484 | memset (evt, 0, sizeof (*evt)); |
| 485 | evt->event_type = SESSION_CTRL_EVT_RESET; |
| 486 | mp = (session_reset_msg_t *) evt->data; |
| 487 | mp->handle = session_handle (s); |
| 488 | svm_msg_q_add (app_mq, msg, SVM_Q_WAIT); |
| 489 | } |
| 490 | |
| 491 | static int |
| 492 | mq_send_session_connected_cb (u32 app_index, u32 api_context, |
| 493 | stream_session_t * s, u8 is_fail) |
| 494 | { |
| 495 | svm_msg_q_msg_t _msg, *msg = &_msg; |
| 496 | session_connected_msg_t *mp; |
| 497 | svm_msg_q_t *vpp_mq, *app_mq; |
| 498 | transport_connection_t *tc; |
| 499 | session_event_t *evt; |
| 500 | application_t *app; |
| 501 | |
| 502 | app = application_get (app_index); |
| 503 | app_mq = app->event_queue; |
| 504 | if (!app_mq) |
| 505 | { |
| 506 | clib_warning ("app %u with api index: %u not attached", app->index, |
| 507 | app->api_client_index); |
| 508 | return -1; |
| 509 | } |
| 510 | |
| 511 | svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING, |
| 512 | SVM_Q_WAIT, msg); |
| 513 | svm_msg_q_unlock (app_mq); |
| 514 | evt = svm_msg_q_msg_data (app_mq, msg); |
| 515 | memset (evt, 0, sizeof (*evt)); |
| 516 | evt->event_type = SESSION_CTRL_EVT_CONNECTED; |
| 517 | mp = (session_connected_msg_t *) evt->data; |
| 518 | mp->context = api_context; |
| 519 | |
| 520 | if (is_fail) |
| 521 | goto done; |
| 522 | |
| 523 | if (session_has_transport (s)) |
| 524 | { |
| 525 | tc = session_get_transport (s); |
| 526 | if (!tc) |
| 527 | { |
| 528 | is_fail = 1; |
| 529 | goto done; |
| 530 | } |
| 531 | |
| 532 | vpp_mq = session_manager_get_vpp_event_queue (s->thread_index); |
| 533 | mp->handle = session_handle (s); |
| 534 | mp->vpp_event_queue_address = pointer_to_uword (vpp_mq); |
| 535 | clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
| 536 | mp->is_ip4 = tc->is_ip4; |
| 537 | mp->lcl_port = tc->lcl_port; |
| 538 | mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 539 | mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 540 | } |
| 541 | else |
| 542 | { |
| 543 | local_session_t *ls = (local_session_t *) s; |
| 544 | mp->handle = application_local_session_handle (ls); |
| 545 | mp->lcl_port = ls->port; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 546 | vpp_mq = session_manager_get_vpp_event_queue (0); |
| 547 | mp->vpp_event_queue_address = pointer_to_uword (vpp_mq); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 548 | mp->client_event_queue_address = ls->client_evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 549 | mp->server_event_queue_address = ls->server_evt_q; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 550 | mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 551 | mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 552 | } |
| 553 | |
| 554 | done: |
| 555 | mp->retval = is_fail ? |
| 556 | clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0; |
| 557 | |
| 558 | svm_msg_q_add (app_mq, msg, SVM_Q_WAIT); |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | static session_cb_vft_t session_mq_cb_vft = { |
| 563 | .session_accept_callback = mq_send_session_accepted_cb, |
| 564 | .session_disconnect_callback = mq_send_session_disconnected_cb, |
| 565 | .session_connected_callback = mq_send_session_connected_cb, |
| 566 | .session_reset_callback = mq_send_session_reset_cb, |
| 567 | .add_segment_callback = send_add_segment_callback, |
| 568 | .del_segment_callback = send_del_segment_callback, |
| 569 | }; |
| 570 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 571 | static void |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 572 | vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp) |
| 573 | { |
| 574 | vl_api_session_enable_disable_reply_t *rmp; |
| 575 | vlib_main_t *vm = vlib_get_main (); |
| 576 | int rv = 0; |
| 577 | |
| 578 | vnet_session_enable_disable (vm, mp->is_enable); |
| 579 | REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY); |
| 580 | } |
| 581 | |
| 582 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 583 | vl_api_application_attach_t_handler (vl_api_application_attach_t * mp) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 584 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 585 | vl_api_application_attach_reply_t *rmp; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 586 | ssvm_private_t *segp, *evt_q_segment; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 587 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 588 | vl_api_registration_t *reg; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 589 | clib_error_t *error = 0; |
| 590 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 591 | |
Florin Coras | fc804d9 | 2018-01-26 01:27:01 -0800 | [diff] [blame] | 592 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 593 | if (!reg) |
| 594 | return; |
| 595 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 596 | if (session_manager_is_enabled () == 0) |
| 597 | { |
| 598 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 599 | goto done; |
| 600 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 601 | |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 602 | STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <= |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 603 | sizeof (mp->options), |
| 604 | "Out of options, fix api message definition"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 605 | |
| 606 | memset (a, 0, sizeof (*a)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 607 | a->api_client_index = mp->client_index; |
| 608 | a->options = mp->options; |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 609 | |
| 610 | if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS) |
| 611 | a->session_cb_vft = &session_mq_cb_vft; |
| 612 | else |
| 613 | a->session_cb_vft = &session_cb_vft; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 614 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 615 | if (mp->namespace_id_len > 64) |
| 616 | { |
| 617 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 618 | goto done; |
| 619 | } |
| 620 | |
| 621 | if (mp->namespace_id_len) |
| 622 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 623 | vec_validate (a->namespace_id, mp->namespace_id_len - 1); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 624 | clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len); |
| 625 | } |
| 626 | |
| 627 | if ((error = vnet_application_attach (a))) |
| 628 | { |
| 629 | rv = clib_error_get_code (error); |
| 630 | clib_error_report (error); |
| 631 | } |
| 632 | vec_free (a->namespace_id); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 633 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 634 | done: |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 635 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 636 | /* *INDENT-OFF* */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 637 | REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 638 | if (!rv) |
| 639 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 640 | segp = a->segment; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 641 | rmp->segment_name_length = 0; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 642 | rmp->segment_size = segp->ssvm_size; |
| 643 | if (vec_len (segp->name)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 644 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 645 | memcpy (rmp->segment_name, segp->name, vec_len (segp->name)); |
| 646 | rmp->segment_name_length = vec_len (segp->name); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 647 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 648 | rmp->app_event_queue_address = a->app_event_queue_address; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 649 | } |
| 650 | })); |
| 651 | /* *INDENT-ON* */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 652 | |
| 653 | if (rv) |
| 654 | return; |
| 655 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 656 | /* Send fifo segment fd if needed */ |
| 657 | if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD) |
| 658 | session_send_memfd_fd (reg, a->segment); |
| 659 | /* Send event queues segment */ |
| 660 | if ((evt_q_segment = session_manager_get_evt_q_segment ())) |
| 661 | session_send_memfd_fd (reg, evt_q_segment); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 665 | vl_api_application_detach_t_handler (vl_api_application_detach_t * mp) |
| 666 | { |
| 667 | vl_api_application_detach_reply_t *rmp; |
| 668 | int rv = VNET_API_ERROR_INVALID_VALUE_2; |
| 669 | vnet_app_detach_args_t _a, *a = &_a; |
| 670 | application_t *app; |
| 671 | |
| 672 | if (session_manager_is_enabled () == 0) |
| 673 | { |
| 674 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 675 | goto done; |
| 676 | } |
| 677 | |
| 678 | app = application_lookup (mp->client_index); |
| 679 | if (app) |
| 680 | { |
| 681 | a->app_index = app->index; |
| 682 | rv = vnet_application_detach (a); |
| 683 | } |
| 684 | |
| 685 | done: |
| 686 | REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY); |
| 687 | } |
| 688 | |
| 689 | static void |
| 690 | vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp) |
| 691 | { |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 692 | transport_connection_t *tc = 0; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 693 | vnet_bind_args_t _a, *a = &_a; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 694 | vl_api_bind_uri_reply_t *rmp; |
| 695 | stream_session_t *s; |
| 696 | application_t *app = 0; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 697 | svm_msg_q_t *vpp_evt_q; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 698 | int rv; |
| 699 | |
| 700 | if (session_manager_is_enabled () == 0) |
| 701 | { |
| 702 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 703 | goto done; |
| 704 | } |
| 705 | |
| 706 | app = application_lookup (mp->client_index); |
| 707 | if (app) |
| 708 | { |
| 709 | memset (a, 0, sizeof (*a)); |
| 710 | a->uri = (char *) mp->uri; |
| 711 | a->app_index = app->index; |
| 712 | rv = vnet_bind_uri (a); |
| 713 | } |
| 714 | else |
| 715 | { |
| 716 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 717 | } |
| 718 | |
| 719 | done: |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 720 | |
| 721 | /* *INDENT-OFF* */ |
| 722 | REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({ |
| 723 | if (!rv) |
| 724 | { |
| 725 | rmp->handle = a->handle; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 726 | if (app && application_has_global_scope (app)) |
| 727 | { |
| 728 | s = listen_session_get_from_handle (a->handle); |
| 729 | tc = listen_session_get_transport (s); |
Florin Coras | 6c35494 | 2018-04-18 00:05:21 -0700 | [diff] [blame] | 730 | rmp->lcl_is_ip4 = tc->is_ip4; |
| 731 | rmp->lcl_port = tc->lcl_port; |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 732 | clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof(tc->lcl_ip)); |
| 733 | if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL) |
| 734 | { |
| 735 | rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 736 | rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 737 | vpp_evt_q = session_manager_get_vpp_event_queue (0); |
| 738 | rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q); |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | })); |
| 743 | /* *INDENT-ON* */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 747 | vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp) |
| 748 | { |
| 749 | vl_api_unbind_uri_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 750 | application_t *app; |
| 751 | vnet_unbind_args_t _a, *a = &_a; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 752 | int rv; |
| 753 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 754 | if (session_manager_is_enabled () == 0) |
| 755 | { |
| 756 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 757 | goto done; |
| 758 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 759 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 760 | app = application_lookup (mp->client_index); |
| 761 | if (app) |
| 762 | { |
| 763 | a->uri = (char *) mp->uri; |
| 764 | a->app_index = app->index; |
| 765 | rv = vnet_unbind_uri (a); |
| 766 | } |
| 767 | else |
| 768 | { |
| 769 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 770 | } |
| 771 | |
| 772 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 773 | REPLY_MACRO (VL_API_UNBIND_URI_REPLY); |
| 774 | } |
| 775 | |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 776 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 777 | vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp) |
| 778 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 779 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 780 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 781 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 782 | clib_error_t *error = 0; |
| 783 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 784 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 785 | if (session_manager_is_enabled () == 0) |
| 786 | { |
| 787 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 788 | goto done; |
| 789 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 790 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 791 | app = application_lookup (mp->client_index); |
| 792 | if (app) |
| 793 | { |
| 794 | a->uri = (char *) mp->uri; |
| 795 | a->api_context = mp->context; |
| 796 | a->app_index = app->index; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 797 | if ((error = vnet_connect_uri (a))) |
| 798 | { |
| 799 | rv = clib_error_get_code (error); |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 800 | clib_error_report (error); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 801 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 802 | } |
| 803 | else |
| 804 | { |
| 805 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 806 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 807 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 808 | /* |
| 809 | * Don't reply to stream (tcp) connects. The reply will come once |
| 810 | * the connection is established. In case of the redirects, the reply |
| 811 | * will come from the server app. |
| 812 | */ |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 813 | if (rv == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 814 | return; |
| 815 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 816 | done: |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 817 | /* *INDENT-OFF* */ |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 818 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 819 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | static void |
| 823 | vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp) |
| 824 | { |
| 825 | vl_api_disconnect_session_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 826 | vnet_disconnect_args_t _a, *a = &_a; |
| 827 | application_t *app; |
| 828 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 829 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 830 | if (session_manager_is_enabled () == 0) |
| 831 | { |
| 832 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 833 | goto done; |
| 834 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 835 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 836 | app = application_lookup (mp->client_index); |
| 837 | if (app) |
| 838 | { |
| 839 | a->handle = mp->handle; |
| 840 | a->app_index = app->index; |
| 841 | rv = vnet_disconnect_session (a); |
| 842 | } |
| 843 | else |
| 844 | { |
| 845 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 846 | } |
| 847 | |
| 848 | done: |
Dave Wallace | de5fec9 | 2017-11-11 22:41:34 -0500 | [diff] [blame] | 849 | REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static void |
| 853 | vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t * |
| 854 | mp) |
| 855 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 856 | vnet_disconnect_args_t _a, *a = &_a; |
| 857 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 858 | |
| 859 | /* Client objected to disconnecting the session, log and continue */ |
| 860 | if (mp->retval) |
| 861 | { |
| 862 | clib_warning ("client retval %d", mp->retval); |
| 863 | return; |
| 864 | } |
| 865 | |
| 866 | /* Disconnect has been confirmed. Confirm close to transport */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 867 | app = application_lookup (mp->context); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 868 | if (app) |
| 869 | { |
| 870 | a->handle = mp->handle; |
| 871 | a->app_index = app->index; |
| 872 | vnet_disconnect_session (a); |
| 873 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | static void |
| 877 | vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp) |
| 878 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 879 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 880 | stream_session_t *s; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 881 | u32 index, thread_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 882 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 883 | app = application_lookup (mp->client_index); |
| 884 | if (!app) |
| 885 | return; |
| 886 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 887 | session_parse_handle (mp->handle, &index, &thread_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 888 | s = session_get_if_valid (index, thread_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 889 | if (s == 0 || app->index != s->app_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 890 | { |
| 891 | clib_warning ("Invalid session!"); |
| 892 | return; |
| 893 | } |
| 894 | |
| 895 | /* Client objected to resetting the session, log and continue */ |
| 896 | if (mp->retval) |
| 897 | { |
| 898 | clib_warning ("client retval %d", mp->retval); |
| 899 | return; |
| 900 | } |
| 901 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 902 | /* This comes as a response to a reset, transport only waiting for |
| 903 | * confirmation to remove connection state, no need to disconnect */ |
| 904 | stream_session_cleanup (s); |
| 905 | } |
| 906 | |
| 907 | static void |
| 908 | vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp) |
| 909 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 910 | vnet_disconnect_args_t _a = { 0 }, *a = &_a; |
| 911 | local_session_t *ls; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 912 | stream_session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 913 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 914 | /* Server isn't interested, kill the session */ |
| 915 | if (mp->retval) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 916 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 917 | a->app_index = mp->context; |
| 918 | a->handle = mp->handle; |
| 919 | vnet_disconnect_session (a); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 920 | return; |
| 921 | } |
| 922 | |
| 923 | if (session_handle_is_local (mp->handle)) |
| 924 | { |
| 925 | ls = application_get_local_session_from_handle (mp->handle); |
| 926 | if (!ls || ls->app_index != mp->context) |
| 927 | { |
| 928 | clib_warning ("server %u doesn't own local handle %llu", |
| 929 | mp->context, mp->handle); |
| 930 | return; |
| 931 | } |
| 932 | if (application_local_session_connect_notify (ls)) |
| 933 | return; |
| 934 | ls->session_state = SESSION_STATE_READY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 935 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 936 | else |
| 937 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 938 | s = session_get_from_handle_if_valid (mp->handle); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 939 | if (!s) |
| 940 | { |
| 941 | clib_warning ("session doesn't exist"); |
| 942 | return; |
| 943 | } |
| 944 | if (s->app_index != mp->context) |
| 945 | { |
| 946 | clib_warning ("app doesn't own session"); |
| 947 | return; |
| 948 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 949 | s->session_state = SESSION_STATE_READY; |
| 950 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | static void |
| 954 | vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t |
| 955 | * mp) |
| 956 | { |
| 957 | clib_warning ("not implemented"); |
| 958 | } |
| 959 | |
| 960 | static void |
| 961 | vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp) |
| 962 | { |
| 963 | vl_api_bind_sock_reply_t *rmp; |
| 964 | vnet_bind_args_t _a, *a = &_a; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 965 | int rv = 0; |
| 966 | clib_error_t *error; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 967 | application_t *app = 0; |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 968 | stream_session_t *s; |
| 969 | transport_connection_t *tc = 0; |
| 970 | ip46_address_t *ip46; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 971 | svm_msg_q_t *vpp_evt_q; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 972 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 973 | if (session_manager_is_enabled () == 0) |
| 974 | { |
| 975 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 976 | goto done; |
| 977 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 978 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 979 | app = application_lookup (mp->client_index); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 980 | if (!app) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 981 | { |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 982 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 983 | goto done; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 984 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 985 | |
| 986 | ip46 = (ip46_address_t *) mp->ip; |
| 987 | memset (a, 0, sizeof (*a)); |
| 988 | a->sep.is_ip4 = mp->is_ip4; |
| 989 | a->sep.ip = *ip46; |
| 990 | a->sep.port = mp->port; |
| 991 | a->sep.fib_index = mp->vrf; |
| 992 | a->sep.sw_if_index = ENDPOINT_INVALID_INDEX; |
| 993 | a->sep.transport_proto = mp->proto; |
| 994 | a->app_index = app->index; |
| 995 | |
| 996 | if ((error = vnet_bind (a))) |
| 997 | { |
| 998 | rv = clib_error_get_code (error); |
| 999 | clib_error_report (error); |
| 1000 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1001 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1002 | done: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1003 | /* *INDENT-OFF* */ |
| 1004 | REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({ |
| 1005 | if (!rv) |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1006 | { |
| 1007 | rmp->handle = a->handle; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1008 | rmp->lcl_port = mp->port; |
Keith Burns (alagalah) | 60ae80f | 2018-03-15 10:04:20 -0700 | [diff] [blame] | 1009 | rmp->lcl_is_ip4 = mp->is_ip4; |
Dave Wallace | 97b1a27 | 2017-12-18 13:51:59 -0500 | [diff] [blame] | 1010 | if (app && application_has_global_scope (app)) |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1011 | { |
| 1012 | s = listen_session_get_from_handle (a->handle); |
| 1013 | tc = listen_session_get_transport (s); |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1014 | clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1015 | if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL) |
| 1016 | { |
| 1017 | rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 1018 | rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 1019 | vpp_evt_q = session_manager_get_vpp_event_queue (0); |
| 1020 | rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q); |
| 1021 | } |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 1022 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1023 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1024 | })); |
| 1025 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static void |
| 1029 | vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp) |
| 1030 | { |
| 1031 | vl_api_unbind_sock_reply_t *rmp; |
| 1032 | vnet_unbind_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1033 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1034 | clib_error_t *error; |
| 1035 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1036 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1037 | if (session_manager_is_enabled () == 0) |
| 1038 | { |
| 1039 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1040 | goto done; |
| 1041 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1042 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1043 | app = application_lookup (mp->client_index); |
| 1044 | if (app) |
| 1045 | { |
Florin Coras | ef24d42 | 2017-11-09 10:05:42 -0800 | [diff] [blame] | 1046 | a->app_index = app->index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1047 | a->handle = mp->handle; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1048 | if ((error = vnet_unbind (a))) |
| 1049 | { |
| 1050 | rv = clib_error_get_code (error); |
| 1051 | clib_error_report (error); |
| 1052 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1053 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1054 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1055 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1056 | REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY); |
| 1057 | } |
| 1058 | |
| 1059 | static void |
| 1060 | vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp) |
| 1061 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1062 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1063 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1064 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1065 | clib_error_t *error = 0; |
| 1066 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1067 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1068 | if (session_manager_is_enabled () == 0) |
| 1069 | { |
| 1070 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1071 | goto done; |
| 1072 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1073 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1074 | app = application_lookup (mp->client_index); |
| 1075 | if (app) |
| 1076 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 1077 | svm_queue_t *client_q; |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1078 | ip46_address_t *ip46 = (ip46_address_t *) mp->ip; |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 1079 | |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1080 | memset (a, 0, sizeof (*a)); |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 1081 | client_q = vl_api_client_index_to_input_queue (mp->client_index); |
| 1082 | mp->client_queue_address = pointer_to_uword (client_q); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1083 | a->sep.is_ip4 = mp->is_ip4; |
| 1084 | a->sep.ip = *ip46; |
| 1085 | a->sep.port = mp->port; |
| 1086 | a->sep.transport_proto = mp->proto; |
| 1087 | a->sep.fib_index = mp->vrf; |
| 1088 | a->sep.sw_if_index = ENDPOINT_INVALID_INDEX; |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1089 | if (mp->hostname_len) |
| 1090 | { |
| 1091 | vec_validate (a->sep.hostname, mp->hostname_len - 1); |
| 1092 | clib_memcpy (a->sep.hostname, mp->hostname, mp->hostname_len); |
| 1093 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1094 | a->api_context = mp->context; |
| 1095 | a->app_index = app->index; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1096 | if ((error = vnet_connect (a))) |
| 1097 | { |
| 1098 | rv = clib_error_get_code (error); |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1099 | clib_error_report (error); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1100 | } |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1101 | vec_free (a->sep.hostname); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1102 | } |
| 1103 | else |
| 1104 | { |
| 1105 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1106 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1107 | |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 1108 | if (rv == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1109 | return; |
| 1110 | |
| 1111 | /* Got some error, relay it */ |
| 1112 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1113 | done: |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1114 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1115 | } |
| 1116 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1117 | static void |
| 1118 | vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp) |
| 1119 | { |
| 1120 | vl_api_app_namespace_add_del_reply_t *rmp; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1121 | clib_error_t *error = 0; |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1122 | u32 appns_index = 0; |
| 1123 | u8 *ns_id = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1124 | int rv = 0; |
| 1125 | if (!session_manager_is_enabled ()) |
| 1126 | { |
| 1127 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1128 | goto done; |
| 1129 | } |
| 1130 | |
| 1131 | if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id)) |
| 1132 | { |
| 1133 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1134 | goto done; |
| 1135 | } |
| 1136 | |
| 1137 | vec_validate (ns_id, mp->namespace_id_len - 1); |
| 1138 | clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len); |
| 1139 | vnet_app_namespace_add_del_args_t args = { |
| 1140 | .ns_id = ns_id, |
Florin Coras | 9a9adb2 | 2017-10-26 08:16:59 -0700 | [diff] [blame] | 1141 | .secret = clib_net_to_host_u64 (mp->secret), |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1142 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 1143 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 1144 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 1145 | .is_add = 1 |
| 1146 | }; |
| 1147 | error = vnet_app_namespace_add_del (&args); |
| 1148 | if (error) |
| 1149 | { |
| 1150 | rv = clib_error_get_code (error); |
| 1151 | clib_error_report (error); |
| 1152 | } |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1153 | else |
| 1154 | { |
| 1155 | appns_index = app_namespace_index_from_id (ns_id); |
| 1156 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 1157 | { |
| 1158 | clib_warning ("app ns lookup failed"); |
| 1159 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1160 | } |
| 1161 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1162 | vec_free (ns_id); |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1163 | |
| 1164 | /* *INDENT-OFF* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1165 | done: |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 1166 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({ |
| 1167 | if (!rv) |
| 1168 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 1169 | })); |
| 1170 | /* *INDENT-ON* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1173 | static void |
| 1174 | vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp) |
| 1175 | { |
| 1176 | vl_api_session_rule_add_del_reply_t *rmp; |
| 1177 | session_rule_add_del_args_t args; |
| 1178 | session_rule_table_add_del_args_t *table_args = &args.table_args; |
| 1179 | clib_error_t *error; |
| 1180 | u8 fib_proto; |
| 1181 | int rv = 0; |
| 1182 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1183 | memset (&args, 0, sizeof (args)); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1184 | fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; |
| 1185 | |
| 1186 | table_args->lcl.fp_len = mp->lcl_plen; |
| 1187 | table_args->lcl.fp_proto = fib_proto; |
| 1188 | table_args->rmt.fp_len = mp->rmt_plen; |
| 1189 | table_args->rmt.fp_proto = fib_proto; |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1190 | table_args->lcl_port = mp->lcl_port; |
| 1191 | table_args->rmt_port = mp->rmt_port; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1192 | table_args->action_index = clib_net_to_host_u32 (mp->action_index); |
| 1193 | table_args->is_add = mp->is_add; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1194 | mp->tag[sizeof (mp->tag) - 1] = 0; |
| 1195 | table_args->tag = format (0, "%s", mp->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1196 | args.appns_index = clib_net_to_host_u32 (mp->appns_index); |
| 1197 | args.scope = mp->scope; |
Florin Coras | 42324ad | 2017-11-18 18:45:20 -0800 | [diff] [blame] | 1198 | args.transport_proto = mp->transport_proto; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1199 | |
| 1200 | memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr)); |
| 1201 | memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr)); |
| 1202 | ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4); |
| 1203 | ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4); |
| 1204 | error = vnet_session_rule_add_del (&args); |
| 1205 | if (error) |
| 1206 | { |
| 1207 | rv = clib_error_get_code (error); |
| 1208 | clib_error_report (error); |
| 1209 | } |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1210 | vec_free (table_args->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 1211 | REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY); |
| 1212 | } |
| 1213 | |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1214 | static void |
| 1215 | send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1216 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1217 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1218 | { |
| 1219 | vl_api_session_rules_details_t *rmp = 0; |
| 1220 | session_mask_or_match_4_t *match = |
| 1221 | (session_mask_or_match_4_t *) & rule->match; |
| 1222 | session_mask_or_match_4_t *mask = |
| 1223 | (session_mask_or_match_4_t *) & rule->mask; |
| 1224 | |
| 1225 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 1226 | memset (rmp, 0, sizeof (*rmp)); |
| 1227 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 1228 | rmp->context = context; |
| 1229 | |
| 1230 | rmp->is_ip4 = 1; |
| 1231 | clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 1232 | clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip)); |
| 1233 | rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip); |
| 1234 | rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1235 | rmp->lcl_port = match->lcl_port; |
| 1236 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1237 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
| 1238 | rmp->scope = |
| 1239 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
| 1240 | rmp->transport_proto = transport_proto; |
| 1241 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1242 | if (tag) |
| 1243 | { |
| 1244 | clib_memcpy (rmp->tag, tag, vec_len (tag)); |
| 1245 | rmp->tag[vec_len (tag)] = 0; |
| 1246 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1247 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1248 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | static void |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1252 | send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local, |
| 1253 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1254 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1255 | { |
| 1256 | vl_api_session_rules_details_t *rmp = 0; |
| 1257 | session_mask_or_match_6_t *match = |
| 1258 | (session_mask_or_match_6_t *) & rule->match; |
| 1259 | session_mask_or_match_6_t *mask = |
| 1260 | (session_mask_or_match_6_t *) & rule->mask; |
| 1261 | |
| 1262 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 1263 | memset (rmp, 0, sizeof (*rmp)); |
| 1264 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 1265 | rmp->context = context; |
| 1266 | |
| 1267 | rmp->is_ip4 = 0; |
| 1268 | clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 1269 | clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip)); |
| 1270 | rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip); |
| 1271 | rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1272 | rmp->lcl_port = match->lcl_port; |
| 1273 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1274 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1275 | rmp->scope = |
| 1276 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1277 | rmp->transport_proto = transport_proto; |
| 1278 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1279 | if (tag) |
| 1280 | { |
| 1281 | clib_memcpy (rmp->tag, tag, vec_len (tag)); |
| 1282 | rmp->tag[vec_len (tag)] = 0; |
| 1283 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1284 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1285 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | static void |
| 1289 | 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] | 1290 | u8 tp, u8 is_local, u32 appns_index, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1291 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1292 | { |
| 1293 | mma_rule_16_t *rule16; |
| 1294 | mma_rule_40_t *rule40; |
| 1295 | mma_rules_table_16_t *srt16; |
| 1296 | mma_rules_table_40_t *srt40; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1297 | u32 ri; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1298 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1299 | if (is_local || fib_proto == FIB_PROTOCOL_IP4) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1300 | { |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1301 | u8 *tag = 0; |
| 1302 | /* *INDENT-OFF* */ |
| 1303 | srt16 = &srt->session_rules_tables_16; |
| 1304 | pool_foreach (rule16, srt16->rules, ({ |
| 1305 | ri = mma_rules_table_rule_index_16 (srt16, rule16); |
| 1306 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1307 | send_session_rule_details4 (rule16, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1308 | reg, context); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1309 | })); |
| 1310 | /* *INDENT-ON* */ |
| 1311 | } |
| 1312 | if (is_local || fib_proto == FIB_PROTOCOL_IP6) |
| 1313 | { |
| 1314 | u8 *tag = 0; |
| 1315 | /* *INDENT-OFF* */ |
| 1316 | srt40 = &srt->session_rules_tables_40; |
| 1317 | pool_foreach (rule40, srt40->rules, ({ |
| 1318 | ri = mma_rules_table_rule_index_40 (srt40, rule40); |
| 1319 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1320 | send_session_rule_details6 (rule40, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1321 | reg, context); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1322 | })); |
| 1323 | /* *INDENT-ON* */ |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | static void |
| 1328 | vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp) |
| 1329 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1330 | vl_api_registration_t *reg; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1331 | session_table_t *st; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1332 | u8 tp; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1333 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1334 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1335 | if (!reg) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1336 | return; |
| 1337 | |
| 1338 | /* *INDENT-OFF* */ |
| 1339 | session_table_foreach (st, ({ |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1340 | for (tp = 0; tp < TRANSPORT_N_PROTO; tp++) |
| 1341 | { |
| 1342 | send_session_rules_table_details (&st->session_rules[tp], |
| 1343 | st->active_fib_proto, tp, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1344 | st->is_local, st->appns_index, reg, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1345 | mp->context); |
| 1346 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1347 | })); |
| 1348 | /* *INDENT-ON* */ |
| 1349 | } |
| 1350 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1351 | static void |
| 1352 | vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t * |
| 1353 | mp) |
| 1354 | { |
| 1355 | vl_api_app_namespace_add_del_reply_t *rmp; |
| 1356 | vnet_app_add_tls_cert_args_t _a, *a = &_a; |
| 1357 | clib_error_t *error; |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1358 | application_t *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1359 | u32 cert_len; |
| 1360 | int rv = 0; |
| 1361 | if (!session_manager_is_enabled ()) |
| 1362 | { |
| 1363 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1364 | goto done; |
| 1365 | } |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1366 | if (!(app = application_lookup (mp->client_index))) |
| 1367 | { |
| 1368 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1369 | goto done; |
| 1370 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1371 | memset (a, 0, sizeof (*a)); |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1372 | a->app_index = app->index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1373 | cert_len = clib_net_to_host_u16 (mp->cert_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1374 | if (cert_len > 10000) |
| 1375 | { |
| 1376 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1377 | goto done; |
| 1378 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1379 | vec_validate (a->cert, cert_len); |
| 1380 | clib_memcpy (a->cert, mp->cert, cert_len); |
| 1381 | if ((error = vnet_app_add_tls_cert (a))) |
| 1382 | { |
| 1383 | rv = clib_error_get_code (error); |
| 1384 | clib_error_report (error); |
| 1385 | } |
| 1386 | vec_free (a->cert); |
| 1387 | done: |
| 1388 | REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY); |
| 1389 | } |
| 1390 | |
| 1391 | static void |
| 1392 | vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t * |
| 1393 | mp) |
| 1394 | { |
| 1395 | vl_api_app_namespace_add_del_reply_t *rmp; |
| 1396 | vnet_app_add_tls_key_args_t _a, *a = &_a; |
| 1397 | clib_error_t *error; |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1398 | application_t *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1399 | u32 key_len; |
| 1400 | int rv = 0; |
| 1401 | if (!session_manager_is_enabled ()) |
| 1402 | { |
| 1403 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1404 | goto done; |
| 1405 | } |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1406 | if (!(app = application_lookup (mp->client_index))) |
| 1407 | { |
| 1408 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1409 | goto done; |
| 1410 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1411 | memset (a, 0, sizeof (*a)); |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1412 | a->app_index = app->index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1413 | key_len = clib_net_to_host_u16 (mp->key_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1414 | if (key_len > 10000) |
| 1415 | { |
| 1416 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1417 | goto done; |
| 1418 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1419 | vec_validate (a->key, key_len); |
| 1420 | clib_memcpy (a->key, mp->key, key_len); |
| 1421 | if ((error = vnet_app_add_tls_key (a))) |
| 1422 | { |
| 1423 | rv = clib_error_get_code (error); |
| 1424 | clib_error_report (error); |
| 1425 | } |
| 1426 | vec_free (a->key); |
| 1427 | done: |
| 1428 | REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY); |
| 1429 | } |
| 1430 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1431 | static clib_error_t * |
| 1432 | application_reaper_cb (u32 client_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1433 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1434 | application_t *app = application_lookup (client_index); |
| 1435 | vnet_app_detach_args_t _a, *a = &_a; |
| 1436 | if (app) |
| 1437 | { |
| 1438 | a->app_index = app->index; |
| 1439 | vnet_application_detach (a); |
| 1440 | } |
| 1441 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1442 | } |
| 1443 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1444 | VL_MSG_API_REAPER_FUNCTION (application_reaper_cb); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1445 | |
| 1446 | #define vl_msg_name_crc_list |
| 1447 | #include <vnet/vnet_all_api_h.h> |
| 1448 | #undef vl_msg_name_crc_list |
| 1449 | |
| 1450 | static void |
| 1451 | setup_message_id_table (api_main_t * am) |
| 1452 | { |
| 1453 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1454 | foreach_vl_msg_name_crc_session; |
| 1455 | #undef _ |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * session_api_hookup |
| 1460 | * Add uri's API message handlers to the table. |
| 1461 | * vlib has alread mapped shared memory and |
| 1462 | * added the client registration handlers. |
| 1463 | * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process() |
| 1464 | */ |
| 1465 | static clib_error_t * |
| 1466 | session_api_hookup (vlib_main_t * vm) |
| 1467 | { |
| 1468 | api_main_t *am = &api_main; |
| 1469 | |
| 1470 | #define _(N,n) \ |
| 1471 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1472 | vl_api_##n##_t_handler, \ |
| 1473 | vl_noop_handler, \ |
| 1474 | vl_api_##n##_t_endian, \ |
| 1475 | vl_api_##n##_t_print, \ |
| 1476 | sizeof(vl_api_##n##_t), 1); |
| 1477 | foreach_session_api_msg; |
| 1478 | #undef _ |
| 1479 | |
| 1480 | /* |
| 1481 | * Messages which bounce off the data-plane to |
| 1482 | * an API client. Simply tells the message handling infra not |
| 1483 | * to free the message. |
| 1484 | * |
| 1485 | * Bounced message handlers MUST NOT block the data plane |
| 1486 | */ |
| 1487 | am->message_bounce[VL_API_CONNECT_URI] = 1; |
| 1488 | am->message_bounce[VL_API_CONNECT_SOCK] = 1; |
| 1489 | |
| 1490 | /* |
| 1491 | * Set up the (msg_name, crc, message-id) table |
| 1492 | */ |
| 1493 | setup_message_id_table (am); |
| 1494 | |
| 1495 | return 0; |
| 1496 | } |
| 1497 | |
| 1498 | VLIB_API_INIT_FUNCTION (session_api_hookup); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1499 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1500 | /* |
| 1501 | * fd.io coding-style-patch-verification: ON |
| 1502 | * |
| 1503 | * Local Variables: |
| 1504 | * eval: (c-set-style "gnu") |
| 1505 | * End: |
| 1506 | */ |