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 | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 158 | svm_queue_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 | { |
| 177 | listener = listen_session_get (s->session_type, s->listener_index); |
| 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 | { |
| 202 | listener = listen_session_get (ls->listener_session_type, |
| 203 | ls->listener_index); |
| 204 | mp->listener_handle = listen_session_get_handle (listener); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 205 | mp->is_ip4 = session_type_is_ip4 (listener->session_type); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 206 | } |
| 207 | else |
| 208 | { |
| 209 | ll = application_get_local_listen_session (server, |
| 210 | ls->listener_index); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 211 | if (ll->transport_listener_index != ~0) |
| 212 | { |
| 213 | listener = listen_session_get (ll->listener_session_type, |
| 214 | ll->transport_listener_index); |
| 215 | mp->listener_handle = listen_session_get_handle (listener); |
| 216 | } |
| 217 | else |
| 218 | { |
| 219 | mp->listener_handle = application_local_session_handle (ll); |
| 220 | } |
| 221 | mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 222 | } |
| 223 | mp->handle = application_local_session_handle (ls); |
| 224 | mp->port = ls->port; |
| 225 | mp->vpp_event_queue_address = ls->client_evt_q; |
| 226 | mp->server_event_queue_address = ls->server_evt_q; |
| 227 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 228 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 233 | void |
| 234 | send_local_session_disconnect_callback (u32 app_index, local_session_t * ls) |
| 235 | { |
| 236 | application_t *app = application_get (app_index); |
| 237 | vl_api_disconnect_session_t *mp; |
| 238 | vl_api_registration_t *reg; |
| 239 | |
| 240 | reg = vl_mem_api_client_index_to_registration (app->api_client_index); |
| 241 | if (!reg) |
| 242 | { |
| 243 | clib_warning ("no registration: %u", app->api_client_index); |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp)); |
| 248 | memset (mp, 0, sizeof (*mp)); |
| 249 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION); |
| 250 | mp->handle = application_local_session_handle (ls); |
| 251 | mp->context = app->api_client_index; |
| 252 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
| 253 | } |
| 254 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 255 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 256 | send_session_disconnect_callback (stream_session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 257 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 258 | application_t *app = application_get (s->app_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 259 | vl_api_disconnect_session_t *mp; |
| 260 | vl_api_registration_t *reg; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 261 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 262 | reg = vl_mem_api_client_index_to_registration (app->api_client_index); |
| 263 | if (!reg) |
| 264 | { |
| 265 | clib_warning ("no registration: %u", app->api_client_index); |
| 266 | return; |
| 267 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 268 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 269 | 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] | 270 | memset (mp, 0, sizeof (*mp)); |
| 271 | 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] | 272 | mp->handle = session_handle (s); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 273 | mp->context = app->api_client_index; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 274 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 275 | } |
| 276 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 277 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 278 | send_session_reset_callback (stream_session_t * s) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 279 | { |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 280 | application_t *app = application_get (s->app_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 281 | vl_api_registration_t *reg; |
| 282 | vl_api_reset_session_t *mp; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 283 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 284 | reg = vl_mem_api_client_index_to_registration (app->api_client_index); |
| 285 | if (!reg) |
| 286 | { |
| 287 | clib_warning ("no registration: %u", app->api_client_index); |
| 288 | return; |
| 289 | } |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 290 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 291 | 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] | 292 | memset (mp, 0, sizeof (*mp)); |
| 293 | 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] | 294 | mp->handle = session_handle (s); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 295 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Dave Barach | 0194f1a | 2017-05-15 10:11:39 -0400 | [diff] [blame] | 298 | int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 299 | send_session_connected_callback (u32 app_index, u32 api_context, |
| 300 | stream_session_t * s, u8 is_fail) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 301 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 302 | vl_api_connect_session_reply_t *mp; |
Florin Coras | ade70e4 | 2017-10-14 18:56:41 -0700 | [diff] [blame] | 303 | transport_connection_t *tc; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 304 | vl_api_registration_t *reg; |
| 305 | svm_queue_t *vpp_queue; |
| 306 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 307 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 308 | app = application_get (app_index); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 309 | reg = vl_mem_api_client_index_to_registration (app->api_client_index); |
| 310 | if (!reg) |
| 311 | { |
| 312 | clib_warning ("no registration: %u", app->api_client_index); |
| 313 | return -1; |
| 314 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 315 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 316 | 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] | 317 | 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] | 318 | mp->context = api_context; |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 319 | |
| 320 | if (is_fail) |
| 321 | goto done; |
| 322 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 323 | if (session_has_transport (s)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 324 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 325 | tc = session_get_transport (s); |
| 326 | if (!tc) |
| 327 | { |
| 328 | is_fail = 1; |
| 329 | goto done; |
| 330 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 331 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 332 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 333 | mp->handle = session_handle (s); |
| 334 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 335 | clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
| 336 | mp->is_ip4 = tc->is_ip4; |
| 337 | mp->lcl_port = tc->lcl_port; |
| 338 | mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 339 | mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 340 | } |
| 341 | else |
| 342 | { |
| 343 | local_session_t *ls = (local_session_t *) s; |
| 344 | mp->handle = application_local_session_handle (ls); |
| 345 | mp->lcl_port = ls->port; |
| 346 | mp->vpp_event_queue_address = ls->server_evt_q; |
| 347 | mp->client_event_queue_address = ls->client_evt_q; |
| 348 | mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 349 | mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 350 | } |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 351 | |
| 352 | done: |
| 353 | mp->retval = is_fail ? |
| 354 | clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 355 | vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 359 | static session_cb_vft_t session_cb_vft = { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 360 | .session_accept_callback = send_session_accept_callback, |
| 361 | .session_disconnect_callback = send_session_disconnect_callback, |
| 362 | .session_connected_callback = send_session_connected_callback, |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 363 | .session_reset_callback = send_session_reset_callback, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 364 | .add_segment_callback = send_add_segment_callback, |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 365 | .del_segment_callback = send_del_segment_callback, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 366 | }; |
| 367 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 368 | static void |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 369 | vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp) |
| 370 | { |
| 371 | vl_api_session_enable_disable_reply_t *rmp; |
| 372 | vlib_main_t *vm = vlib_get_main (); |
| 373 | int rv = 0; |
| 374 | |
| 375 | vnet_session_enable_disable (vm, mp->is_enable); |
| 376 | REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY); |
| 377 | } |
| 378 | |
| 379 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 380 | vl_api_application_attach_t_handler (vl_api_application_attach_t * mp) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 381 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 382 | vl_api_application_attach_reply_t *rmp; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 383 | ssvm_private_t *segp, *evt_q_segment; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 384 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 385 | vl_api_registration_t *reg; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 386 | clib_error_t *error = 0; |
| 387 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 388 | |
Florin Coras | fc804d9 | 2018-01-26 01:27:01 -0800 | [diff] [blame] | 389 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 390 | if (!reg) |
| 391 | return; |
| 392 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 393 | if (session_manager_is_enabled () == 0) |
| 394 | { |
| 395 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 396 | goto done; |
| 397 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 398 | |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 399 | STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <= |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 400 | sizeof (mp->options), |
| 401 | "Out of options, fix api message definition"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 402 | |
| 403 | memset (a, 0, sizeof (*a)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 404 | a->api_client_index = mp->client_index; |
| 405 | a->options = mp->options; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 406 | a->session_cb_vft = &session_cb_vft; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 407 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 408 | if (mp->namespace_id_len > 64) |
| 409 | { |
| 410 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 411 | goto done; |
| 412 | } |
| 413 | |
| 414 | if (mp->namespace_id_len) |
| 415 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 416 | vec_validate (a->namespace_id, mp->namespace_id_len - 1); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 417 | clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len); |
| 418 | } |
| 419 | |
| 420 | if ((error = vnet_application_attach (a))) |
| 421 | { |
| 422 | rv = clib_error_get_code (error); |
| 423 | clib_error_report (error); |
| 424 | } |
| 425 | vec_free (a->namespace_id); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 426 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 427 | done: |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 428 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 429 | /* *INDENT-OFF* */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 430 | REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 431 | if (!rv) |
| 432 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 433 | segp = a->segment; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 434 | rmp->segment_name_length = 0; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 435 | rmp->segment_size = segp->ssvm_size; |
| 436 | if (vec_len (segp->name)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 437 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 438 | memcpy (rmp->segment_name, segp->name, vec_len (segp->name)); |
| 439 | rmp->segment_name_length = vec_len (segp->name); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 440 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 441 | rmp->app_event_queue_address = a->app_event_queue_address; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 442 | } |
| 443 | })); |
| 444 | /* *INDENT-ON* */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 445 | |
| 446 | if (rv) |
| 447 | return; |
| 448 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 449 | /* Send fifo segment fd if needed */ |
| 450 | if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD) |
| 451 | session_send_memfd_fd (reg, a->segment); |
| 452 | /* Send event queues segment */ |
| 453 | if ((evt_q_segment = session_manager_get_evt_q_segment ())) |
| 454 | session_send_memfd_fd (reg, evt_q_segment); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 458 | vl_api_application_detach_t_handler (vl_api_application_detach_t * mp) |
| 459 | { |
| 460 | vl_api_application_detach_reply_t *rmp; |
| 461 | int rv = VNET_API_ERROR_INVALID_VALUE_2; |
| 462 | vnet_app_detach_args_t _a, *a = &_a; |
| 463 | application_t *app; |
| 464 | |
| 465 | if (session_manager_is_enabled () == 0) |
| 466 | { |
| 467 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 468 | goto done; |
| 469 | } |
| 470 | |
| 471 | app = application_lookup (mp->client_index); |
| 472 | if (app) |
| 473 | { |
| 474 | a->app_index = app->index; |
| 475 | rv = vnet_application_detach (a); |
| 476 | } |
| 477 | |
| 478 | done: |
| 479 | REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY); |
| 480 | } |
| 481 | |
| 482 | static void |
| 483 | vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp) |
| 484 | { |
| 485 | vl_api_bind_uri_reply_t *rmp; |
| 486 | vnet_bind_args_t _a, *a = &_a; |
| 487 | application_t *app; |
| 488 | int rv; |
| 489 | |
| 490 | if (session_manager_is_enabled () == 0) |
| 491 | { |
| 492 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 493 | goto done; |
| 494 | } |
| 495 | |
| 496 | app = application_lookup (mp->client_index); |
| 497 | if (app) |
| 498 | { |
| 499 | memset (a, 0, sizeof (*a)); |
| 500 | a->uri = (char *) mp->uri; |
| 501 | a->app_index = app->index; |
| 502 | rv = vnet_bind_uri (a); |
| 503 | } |
| 504 | else |
| 505 | { |
| 506 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 507 | } |
| 508 | |
| 509 | done: |
| 510 | REPLY_MACRO (VL_API_BIND_URI_REPLY); |
| 511 | } |
| 512 | |
| 513 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 514 | vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp) |
| 515 | { |
| 516 | vl_api_unbind_uri_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 517 | application_t *app; |
| 518 | vnet_unbind_args_t _a, *a = &_a; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 519 | int rv; |
| 520 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 521 | if (session_manager_is_enabled () == 0) |
| 522 | { |
| 523 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 524 | goto done; |
| 525 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 526 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 527 | app = application_lookup (mp->client_index); |
| 528 | if (app) |
| 529 | { |
| 530 | a->uri = (char *) mp->uri; |
| 531 | a->app_index = app->index; |
| 532 | rv = vnet_unbind_uri (a); |
| 533 | } |
| 534 | else |
| 535 | { |
| 536 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 537 | } |
| 538 | |
| 539 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 540 | REPLY_MACRO (VL_API_UNBIND_URI_REPLY); |
| 541 | } |
| 542 | |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 543 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 544 | vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp) |
| 545 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 546 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 547 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 548 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 549 | clib_error_t *error = 0; |
| 550 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 551 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 552 | if (session_manager_is_enabled () == 0) |
| 553 | { |
| 554 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 555 | goto done; |
| 556 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 557 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 558 | app = application_lookup (mp->client_index); |
| 559 | if (app) |
| 560 | { |
| 561 | a->uri = (char *) mp->uri; |
| 562 | a->api_context = mp->context; |
| 563 | a->app_index = app->index; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 564 | if ((error = vnet_connect_uri (a))) |
| 565 | { |
| 566 | rv = clib_error_get_code (error); |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 567 | clib_error_report (error); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 568 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 569 | } |
| 570 | else |
| 571 | { |
| 572 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 573 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 574 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 575 | /* |
| 576 | * Don't reply to stream (tcp) connects. The reply will come once |
| 577 | * the connection is established. In case of the redirects, the reply |
| 578 | * will come from the server app. |
| 579 | */ |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 580 | if (rv == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 581 | return; |
| 582 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 583 | done: |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 584 | /* *INDENT-OFF* */ |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 585 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 586 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | static void |
| 590 | vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp) |
| 591 | { |
| 592 | vl_api_disconnect_session_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 593 | vnet_disconnect_args_t _a, *a = &_a; |
| 594 | application_t *app; |
| 595 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 596 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 597 | if (session_manager_is_enabled () == 0) |
| 598 | { |
| 599 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 600 | goto done; |
| 601 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 602 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 603 | app = application_lookup (mp->client_index); |
| 604 | if (app) |
| 605 | { |
| 606 | a->handle = mp->handle; |
| 607 | a->app_index = app->index; |
| 608 | rv = vnet_disconnect_session (a); |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 613 | } |
| 614 | |
| 615 | done: |
Dave Wallace | de5fec9 | 2017-11-11 22:41:34 -0500 | [diff] [blame] | 616 | REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | static void |
| 620 | vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t * |
| 621 | mp) |
| 622 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 623 | vnet_disconnect_args_t _a, *a = &_a; |
| 624 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 625 | |
| 626 | /* Client objected to disconnecting the session, log and continue */ |
| 627 | if (mp->retval) |
| 628 | { |
| 629 | clib_warning ("client retval %d", mp->retval); |
| 630 | return; |
| 631 | } |
| 632 | |
| 633 | /* Disconnect has been confirmed. Confirm close to transport */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 634 | app = application_lookup (mp->context); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 635 | if (app) |
| 636 | { |
| 637 | a->handle = mp->handle; |
| 638 | a->app_index = app->index; |
| 639 | vnet_disconnect_session (a); |
| 640 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static void |
| 644 | vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp) |
| 645 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 646 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 647 | stream_session_t *s; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 648 | u32 index, thread_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 649 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 650 | app = application_lookup (mp->client_index); |
| 651 | if (!app) |
| 652 | return; |
| 653 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 654 | session_parse_handle (mp->handle, &index, &thread_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 655 | s = session_get_if_valid (index, thread_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 656 | if (s == 0 || app->index != s->app_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 657 | { |
| 658 | clib_warning ("Invalid session!"); |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | /* Client objected to resetting the session, log and continue */ |
| 663 | if (mp->retval) |
| 664 | { |
| 665 | clib_warning ("client retval %d", mp->retval); |
| 666 | return; |
| 667 | } |
| 668 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 669 | /* This comes as a response to a reset, transport only waiting for |
| 670 | * confirmation to remove connection state, no need to disconnect */ |
| 671 | stream_session_cleanup (s); |
| 672 | } |
| 673 | |
| 674 | static void |
| 675 | vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp) |
| 676 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 677 | vnet_disconnect_args_t _a = { 0 }, *a = &_a; |
| 678 | local_session_t *ls; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 679 | stream_session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 680 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 681 | /* Server isn't interested, kill the session */ |
| 682 | if (mp->retval) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 683 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 684 | a->app_index = mp->context; |
| 685 | a->handle = mp->handle; |
| 686 | vnet_disconnect_session (a); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 687 | return; |
| 688 | } |
| 689 | |
| 690 | if (session_handle_is_local (mp->handle)) |
| 691 | { |
| 692 | ls = application_get_local_session_from_handle (mp->handle); |
| 693 | if (!ls || ls->app_index != mp->context) |
| 694 | { |
| 695 | clib_warning ("server %u doesn't own local handle %llu", |
| 696 | mp->context, mp->handle); |
| 697 | return; |
| 698 | } |
| 699 | if (application_local_session_connect_notify (ls)) |
| 700 | return; |
| 701 | ls->session_state = SESSION_STATE_READY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 702 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 703 | else |
| 704 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 705 | s = session_get_from_handle_if_valid (mp->handle); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 706 | if (!s) |
| 707 | { |
| 708 | clib_warning ("session doesn't exist"); |
| 709 | return; |
| 710 | } |
| 711 | if (s->app_index != mp->context) |
| 712 | { |
| 713 | clib_warning ("app doesn't own session"); |
| 714 | return; |
| 715 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 716 | s->session_state = SESSION_STATE_READY; |
| 717 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static void |
| 721 | vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t |
| 722 | * mp) |
| 723 | { |
| 724 | clib_warning ("not implemented"); |
| 725 | } |
| 726 | |
| 727 | static void |
| 728 | vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp) |
| 729 | { |
| 730 | vl_api_bind_sock_reply_t *rmp; |
| 731 | vnet_bind_args_t _a, *a = &_a; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 732 | int rv = 0; |
| 733 | clib_error_t *error; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 734 | application_t *app = 0; |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 735 | stream_session_t *s; |
| 736 | transport_connection_t *tc = 0; |
| 737 | ip46_address_t *ip46; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 738 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 739 | if (session_manager_is_enabled () == 0) |
| 740 | { |
| 741 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 742 | goto done; |
| 743 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 744 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 745 | app = application_lookup (mp->client_index); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 746 | if (!app) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 747 | { |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 748 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 749 | goto done; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 750 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 751 | |
| 752 | ip46 = (ip46_address_t *) mp->ip; |
| 753 | memset (a, 0, sizeof (*a)); |
| 754 | a->sep.is_ip4 = mp->is_ip4; |
| 755 | a->sep.ip = *ip46; |
| 756 | a->sep.port = mp->port; |
| 757 | a->sep.fib_index = mp->vrf; |
| 758 | a->sep.sw_if_index = ENDPOINT_INVALID_INDEX; |
| 759 | a->sep.transport_proto = mp->proto; |
| 760 | a->app_index = app->index; |
| 761 | |
| 762 | if ((error = vnet_bind (a))) |
| 763 | { |
| 764 | rv = clib_error_get_code (error); |
| 765 | clib_error_report (error); |
| 766 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 767 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 768 | done: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 769 | /* *INDENT-OFF* */ |
| 770 | REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({ |
| 771 | if (!rv) |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 772 | { |
| 773 | rmp->handle = a->handle; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 774 | rmp->lcl_port = mp->port; |
Keith Burns (alagalah) | 60ae80f | 2018-03-15 10:04:20 -0700 | [diff] [blame] | 775 | rmp->lcl_is_ip4 = mp->is_ip4; |
Dave Wallace | 97b1a27 | 2017-12-18 13:51:59 -0500 | [diff] [blame] | 776 | if (app && application_has_global_scope (app)) |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 777 | { |
| 778 | s = listen_session_get_from_handle (a->handle); |
| 779 | tc = listen_session_get_transport (s); |
| 780 | rmp->lcl_is_ip4 = tc->is_ip4; |
| 781 | clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
| 782 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 783 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 784 | })); |
| 785 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | static void |
| 789 | vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp) |
| 790 | { |
| 791 | vl_api_unbind_sock_reply_t *rmp; |
| 792 | vnet_unbind_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 793 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 794 | clib_error_t *error; |
| 795 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 796 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 797 | if (session_manager_is_enabled () == 0) |
| 798 | { |
| 799 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 800 | goto done; |
| 801 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 802 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 803 | app = application_lookup (mp->client_index); |
| 804 | if (app) |
| 805 | { |
Florin Coras | ef24d42 | 2017-11-09 10:05:42 -0800 | [diff] [blame] | 806 | a->app_index = app->index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 807 | a->handle = mp->handle; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 808 | if ((error = vnet_unbind (a))) |
| 809 | { |
| 810 | rv = clib_error_get_code (error); |
| 811 | clib_error_report (error); |
| 812 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 813 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 814 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 815 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 816 | REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY); |
| 817 | } |
| 818 | |
| 819 | static void |
| 820 | vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp) |
| 821 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 822 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 823 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 824 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 825 | clib_error_t *error = 0; |
| 826 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 827 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 828 | if (session_manager_is_enabled () == 0) |
| 829 | { |
| 830 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 831 | goto done; |
| 832 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 833 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 834 | app = application_lookup (mp->client_index); |
| 835 | if (app) |
| 836 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 837 | svm_queue_t *client_q; |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 838 | ip46_address_t *ip46 = (ip46_address_t *) mp->ip; |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 839 | |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 840 | memset (a, 0, sizeof (*a)); |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 841 | client_q = vl_api_client_index_to_input_queue (mp->client_index); |
| 842 | mp->client_queue_address = pointer_to_uword (client_q); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 843 | a->sep.is_ip4 = mp->is_ip4; |
| 844 | a->sep.ip = *ip46; |
| 845 | a->sep.port = mp->port; |
| 846 | a->sep.transport_proto = mp->proto; |
| 847 | a->sep.fib_index = mp->vrf; |
| 848 | a->sep.sw_if_index = ENDPOINT_INVALID_INDEX; |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 849 | if (mp->hostname_len) |
| 850 | { |
| 851 | vec_validate (a->sep.hostname, mp->hostname_len - 1); |
| 852 | clib_memcpy (a->sep.hostname, mp->hostname, mp->hostname_len); |
| 853 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 854 | a->api_context = mp->context; |
| 855 | a->app_index = app->index; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 856 | if ((error = vnet_connect (a))) |
| 857 | { |
| 858 | rv = clib_error_get_code (error); |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 859 | clib_error_report (error); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 860 | } |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 861 | vec_free (a->sep.hostname); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 862 | } |
| 863 | else |
| 864 | { |
| 865 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 866 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 867 | |
Florin Coras | 8f89dd0 | 2018-03-05 16:53:07 -0800 | [diff] [blame] | 868 | if (rv == 0) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 869 | return; |
| 870 | |
| 871 | /* Got some error, relay it */ |
| 872 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 873 | done: |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 874 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 875 | } |
| 876 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 877 | static void |
| 878 | vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp) |
| 879 | { |
| 880 | vl_api_app_namespace_add_del_reply_t *rmp; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 881 | clib_error_t *error = 0; |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 882 | u32 appns_index = 0; |
| 883 | u8 *ns_id = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 884 | int rv = 0; |
| 885 | if (!session_manager_is_enabled ()) |
| 886 | { |
| 887 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 888 | goto done; |
| 889 | } |
| 890 | |
| 891 | if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id)) |
| 892 | { |
| 893 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 894 | goto done; |
| 895 | } |
| 896 | |
| 897 | vec_validate (ns_id, mp->namespace_id_len - 1); |
| 898 | clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len); |
| 899 | vnet_app_namespace_add_del_args_t args = { |
| 900 | .ns_id = ns_id, |
Florin Coras | 9a9adb2 | 2017-10-26 08:16:59 -0700 | [diff] [blame] | 901 | .secret = clib_net_to_host_u64 (mp->secret), |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 902 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 903 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 904 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 905 | .is_add = 1 |
| 906 | }; |
| 907 | error = vnet_app_namespace_add_del (&args); |
| 908 | if (error) |
| 909 | { |
| 910 | rv = clib_error_get_code (error); |
| 911 | clib_error_report (error); |
| 912 | } |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 913 | else |
| 914 | { |
| 915 | appns_index = app_namespace_index_from_id (ns_id); |
| 916 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 917 | { |
| 918 | clib_warning ("app ns lookup failed"); |
| 919 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 920 | } |
| 921 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 922 | vec_free (ns_id); |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 923 | |
| 924 | /* *INDENT-OFF* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 925 | done: |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 926 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({ |
| 927 | if (!rv) |
| 928 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 929 | })); |
| 930 | /* *INDENT-ON* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 933 | static void |
| 934 | vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp) |
| 935 | { |
| 936 | vl_api_session_rule_add_del_reply_t *rmp; |
| 937 | session_rule_add_del_args_t args; |
| 938 | session_rule_table_add_del_args_t *table_args = &args.table_args; |
| 939 | clib_error_t *error; |
| 940 | u8 fib_proto; |
| 941 | int rv = 0; |
| 942 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 943 | memset (&args, 0, sizeof (args)); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 944 | fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; |
| 945 | |
| 946 | table_args->lcl.fp_len = mp->lcl_plen; |
| 947 | table_args->lcl.fp_proto = fib_proto; |
| 948 | table_args->rmt.fp_len = mp->rmt_plen; |
| 949 | table_args->rmt.fp_proto = fib_proto; |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 950 | table_args->lcl_port = mp->lcl_port; |
| 951 | table_args->rmt_port = mp->rmt_port; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 952 | table_args->action_index = clib_net_to_host_u32 (mp->action_index); |
| 953 | table_args->is_add = mp->is_add; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 954 | mp->tag[sizeof (mp->tag) - 1] = 0; |
| 955 | table_args->tag = format (0, "%s", mp->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 956 | args.appns_index = clib_net_to_host_u32 (mp->appns_index); |
| 957 | args.scope = mp->scope; |
Florin Coras | 42324ad | 2017-11-18 18:45:20 -0800 | [diff] [blame] | 958 | args.transport_proto = mp->transport_proto; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 959 | |
| 960 | memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr)); |
| 961 | memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr)); |
| 962 | ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4); |
| 963 | ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4); |
| 964 | error = vnet_session_rule_add_del (&args); |
| 965 | if (error) |
| 966 | { |
| 967 | rv = clib_error_get_code (error); |
| 968 | clib_error_report (error); |
| 969 | } |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 970 | vec_free (table_args->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 971 | REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY); |
| 972 | } |
| 973 | |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 974 | static void |
| 975 | send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 976 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 977 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 978 | { |
| 979 | vl_api_session_rules_details_t *rmp = 0; |
| 980 | session_mask_or_match_4_t *match = |
| 981 | (session_mask_or_match_4_t *) & rule->match; |
| 982 | session_mask_or_match_4_t *mask = |
| 983 | (session_mask_or_match_4_t *) & rule->mask; |
| 984 | |
| 985 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 986 | memset (rmp, 0, sizeof (*rmp)); |
| 987 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 988 | rmp->context = context; |
| 989 | |
| 990 | rmp->is_ip4 = 1; |
| 991 | clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 992 | clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip)); |
| 993 | rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip); |
| 994 | rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 995 | rmp->lcl_port = match->lcl_port; |
| 996 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 997 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
| 998 | rmp->scope = |
| 999 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
| 1000 | rmp->transport_proto = transport_proto; |
| 1001 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1002 | if (tag) |
| 1003 | { |
| 1004 | clib_memcpy (rmp->tag, tag, vec_len (tag)); |
| 1005 | rmp->tag[vec_len (tag)] = 0; |
| 1006 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1007 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1008 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | static void |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1012 | send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local, |
| 1013 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1014 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1015 | { |
| 1016 | vl_api_session_rules_details_t *rmp = 0; |
| 1017 | session_mask_or_match_6_t *match = |
| 1018 | (session_mask_or_match_6_t *) & rule->match; |
| 1019 | session_mask_or_match_6_t *mask = |
| 1020 | (session_mask_or_match_6_t *) & rule->mask; |
| 1021 | |
| 1022 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 1023 | memset (rmp, 0, sizeof (*rmp)); |
| 1024 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 1025 | rmp->context = context; |
| 1026 | |
| 1027 | rmp->is_ip4 = 0; |
| 1028 | clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 1029 | clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip)); |
| 1030 | rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip); |
| 1031 | rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 1032 | rmp->lcl_port = match->lcl_port; |
| 1033 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1034 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1035 | rmp->scope = |
| 1036 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1037 | rmp->transport_proto = transport_proto; |
| 1038 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1039 | if (tag) |
| 1040 | { |
| 1041 | clib_memcpy (rmp->tag, tag, vec_len (tag)); |
| 1042 | rmp->tag[vec_len (tag)] = 0; |
| 1043 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1044 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1045 | vl_api_send_msg (reg, (u8 *) rmp); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static void |
| 1049 | 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] | 1050 | u8 tp, u8 is_local, u32 appns_index, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1051 | vl_api_registration_t * reg, u32 context) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1052 | { |
| 1053 | mma_rule_16_t *rule16; |
| 1054 | mma_rule_40_t *rule40; |
| 1055 | mma_rules_table_16_t *srt16; |
| 1056 | mma_rules_table_40_t *srt40; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1057 | u32 ri; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1058 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1059 | if (is_local || fib_proto == FIB_PROTOCOL_IP4) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1060 | { |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1061 | u8 *tag = 0; |
| 1062 | /* *INDENT-OFF* */ |
| 1063 | srt16 = &srt->session_rules_tables_16; |
| 1064 | pool_foreach (rule16, srt16->rules, ({ |
| 1065 | ri = mma_rules_table_rule_index_16 (srt16, rule16); |
| 1066 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1067 | send_session_rule_details4 (rule16, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1068 | reg, context); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1069 | })); |
| 1070 | /* *INDENT-ON* */ |
| 1071 | } |
| 1072 | if (is_local || fib_proto == FIB_PROTOCOL_IP6) |
| 1073 | { |
| 1074 | u8 *tag = 0; |
| 1075 | /* *INDENT-OFF* */ |
| 1076 | srt40 = &srt->session_rules_tables_40; |
| 1077 | pool_foreach (rule40, srt40->rules, ({ |
| 1078 | ri = mma_rules_table_rule_index_40 (srt40, rule40); |
| 1079 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 1080 | send_session_rule_details6 (rule40, is_local, tp, appns_index, tag, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1081 | reg, context); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1082 | })); |
| 1083 | /* *INDENT-ON* */ |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | static void |
| 1088 | vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp) |
| 1089 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1090 | vl_api_registration_t *reg; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1091 | session_table_t *st; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1092 | u8 tp; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1093 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1094 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1095 | if (!reg) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1096 | return; |
| 1097 | |
| 1098 | /* *INDENT-OFF* */ |
| 1099 | session_table_foreach (st, ({ |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1100 | for (tp = 0; tp < TRANSPORT_N_PROTO; tp++) |
| 1101 | { |
| 1102 | send_session_rules_table_details (&st->session_rules[tp], |
| 1103 | st->active_fib_proto, tp, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1104 | st->is_local, st->appns_index, reg, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 1105 | mp->context); |
| 1106 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1107 | })); |
| 1108 | /* *INDENT-ON* */ |
| 1109 | } |
| 1110 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1111 | static void |
| 1112 | vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t * |
| 1113 | mp) |
| 1114 | { |
| 1115 | vl_api_app_namespace_add_del_reply_t *rmp; |
| 1116 | vnet_app_add_tls_cert_args_t _a, *a = &_a; |
| 1117 | clib_error_t *error; |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1118 | application_t *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1119 | u32 cert_len; |
| 1120 | int rv = 0; |
| 1121 | if (!session_manager_is_enabled ()) |
| 1122 | { |
| 1123 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1124 | goto done; |
| 1125 | } |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1126 | if (!(app = application_lookup (mp->client_index))) |
| 1127 | { |
| 1128 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1129 | goto done; |
| 1130 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1131 | memset (a, 0, sizeof (*a)); |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1132 | a->app_index = app->index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1133 | cert_len = clib_net_to_host_u16 (mp->cert_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1134 | if (cert_len > 10000) |
| 1135 | { |
| 1136 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1137 | goto done; |
| 1138 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1139 | vec_validate (a->cert, cert_len); |
| 1140 | clib_memcpy (a->cert, mp->cert, cert_len); |
| 1141 | if ((error = vnet_app_add_tls_cert (a))) |
| 1142 | { |
| 1143 | rv = clib_error_get_code (error); |
| 1144 | clib_error_report (error); |
| 1145 | } |
| 1146 | vec_free (a->cert); |
| 1147 | done: |
| 1148 | REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY); |
| 1149 | } |
| 1150 | |
| 1151 | static void |
| 1152 | vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t * |
| 1153 | mp) |
| 1154 | { |
| 1155 | vl_api_app_namespace_add_del_reply_t *rmp; |
| 1156 | vnet_app_add_tls_key_args_t _a, *a = &_a; |
| 1157 | clib_error_t *error; |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1158 | application_t *app; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1159 | u32 key_len; |
| 1160 | int rv = 0; |
| 1161 | if (!session_manager_is_enabled ()) |
| 1162 | { |
| 1163 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 1164 | goto done; |
| 1165 | } |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1166 | if (!(app = application_lookup (mp->client_index))) |
| 1167 | { |
| 1168 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 1169 | goto done; |
| 1170 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1171 | memset (a, 0, sizeof (*a)); |
Florin Coras | e3e2f07 | 2018-03-04 07:24:30 -0800 | [diff] [blame] | 1172 | a->app_index = app->index; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1173 | key_len = clib_net_to_host_u16 (mp->key_len); |
Florin Coras | 5090c57 | 2018-03-18 08:22:17 -0700 | [diff] [blame] | 1174 | if (key_len > 10000) |
| 1175 | { |
| 1176 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1177 | goto done; |
| 1178 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1179 | vec_validate (a->key, key_len); |
| 1180 | clib_memcpy (a->key, mp->key, key_len); |
| 1181 | if ((error = vnet_app_add_tls_key (a))) |
| 1182 | { |
| 1183 | rv = clib_error_get_code (error); |
| 1184 | clib_error_report (error); |
| 1185 | } |
| 1186 | vec_free (a->key); |
| 1187 | done: |
| 1188 | REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY); |
| 1189 | } |
| 1190 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1191 | static clib_error_t * |
| 1192 | application_reaper_cb (u32 client_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1193 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1194 | application_t *app = application_lookup (client_index); |
| 1195 | vnet_app_detach_args_t _a, *a = &_a; |
| 1196 | if (app) |
| 1197 | { |
| 1198 | a->app_index = app->index; |
| 1199 | vnet_application_detach (a); |
| 1200 | } |
| 1201 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1202 | } |
| 1203 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1204 | VL_MSG_API_REAPER_FUNCTION (application_reaper_cb); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1205 | |
| 1206 | #define vl_msg_name_crc_list |
| 1207 | #include <vnet/vnet_all_api_h.h> |
| 1208 | #undef vl_msg_name_crc_list |
| 1209 | |
| 1210 | static void |
| 1211 | setup_message_id_table (api_main_t * am) |
| 1212 | { |
| 1213 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1214 | foreach_vl_msg_name_crc_session; |
| 1215 | #undef _ |
| 1216 | } |
| 1217 | |
| 1218 | /* |
| 1219 | * session_api_hookup |
| 1220 | * Add uri's API message handlers to the table. |
| 1221 | * vlib has alread mapped shared memory and |
| 1222 | * added the client registration handlers. |
| 1223 | * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process() |
| 1224 | */ |
| 1225 | static clib_error_t * |
| 1226 | session_api_hookup (vlib_main_t * vm) |
| 1227 | { |
| 1228 | api_main_t *am = &api_main; |
| 1229 | |
| 1230 | #define _(N,n) \ |
| 1231 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1232 | vl_api_##n##_t_handler, \ |
| 1233 | vl_noop_handler, \ |
| 1234 | vl_api_##n##_t_endian, \ |
| 1235 | vl_api_##n##_t_print, \ |
| 1236 | sizeof(vl_api_##n##_t), 1); |
| 1237 | foreach_session_api_msg; |
| 1238 | #undef _ |
| 1239 | |
| 1240 | /* |
| 1241 | * Messages which bounce off the data-plane to |
| 1242 | * an API client. Simply tells the message handling infra not |
| 1243 | * to free the message. |
| 1244 | * |
| 1245 | * Bounced message handlers MUST NOT block the data plane |
| 1246 | */ |
| 1247 | am->message_bounce[VL_API_CONNECT_URI] = 1; |
| 1248 | am->message_bounce[VL_API_CONNECT_SOCK] = 1; |
| 1249 | |
| 1250 | /* |
| 1251 | * Set up the (msg_name, crc, message-id) table |
| 1252 | */ |
| 1253 | setup_message_id_table (am); |
| 1254 | |
| 1255 | return 0; |
| 1256 | } |
| 1257 | |
| 1258 | VLIB_API_INIT_FUNCTION (session_api_hookup); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1259 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1260 | /* |
| 1261 | * fd.io coding-style-patch-verification: ON |
| 1262 | * |
| 1263 | * Local Variables: |
| 1264 | * eval: (c-set-style "gnu") |
| 1265 | * End: |
| 1266 | */ |