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 | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 59 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 60 | static int |
| 61 | send_add_segment_callback (u32 api_client_index, const u8 * segment_name, |
| 62 | u32 segment_size) |
| 63 | { |
| 64 | vl_api_map_another_segment_t *mp; |
| 65 | unix_shared_memory_queue_t *q; |
| 66 | |
| 67 | q = vl_api_client_index_to_input_queue (api_client_index); |
| 68 | |
| 69 | if (!q) |
| 70 | return -1; |
| 71 | |
| 72 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 73 | memset (mp, 0, sizeof (*mp)); |
| 74 | mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MAP_ANOTHER_SEGMENT); |
| 75 | mp->segment_size = segment_size; |
| 76 | strncpy ((char *) mp->segment_name, (char *) segment_name, |
| 77 | sizeof (mp->segment_name) - 1); |
| 78 | |
| 79 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 85 | send_session_accept_callback (stream_session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 86 | { |
| 87 | vl_api_accept_session_t *mp; |
| 88 | unix_shared_memory_queue_t *q, *vpp_queue; |
| 89 | application_t *server = application_get (s->app_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 90 | transport_connection_t *tc; |
| 91 | transport_proto_vft_t *tp_vft; |
| 92 | stream_session_t *listener; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 93 | |
| 94 | q = vl_api_client_index_to_input_queue (server->api_client_index); |
| 95 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 96 | |
| 97 | if (!q) |
| 98 | return -1; |
| 99 | |
| 100 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 101 | memset (mp, 0, sizeof (*mp)); |
| 102 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 103 | 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] | 104 | mp->context = server->index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 105 | listener = listen_session_get (s->session_type, s->listener_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 106 | tp_vft = transport_protocol_get_vft (s->session_type); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 107 | tc = tp_vft->get_connection (s->connection_index, s->thread_index); |
| 108 | mp->listener_handle = listen_session_get_handle (listener); |
Florin Coras | c3ddea8 | 2017-11-27 03:12:00 -0800 | [diff] [blame^] | 109 | |
| 110 | if (application_is_proxy (server)) |
| 111 | { |
| 112 | listener = |
| 113 | application_first_listener (server, |
| 114 | transport_connection_fib_proto (tc), |
| 115 | tc->proto); |
| 116 | if (listener) |
| 117 | mp->listener_handle = listen_session_get_handle (listener); |
| 118 | } |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 119 | mp->handle = session_handle (s); |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 120 | mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 121 | mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 122 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 123 | mp->port = tc->rmt_port; |
| 124 | mp->is_ip4 = tc->is_ip4; |
| 125 | clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 126 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 132 | send_session_disconnect_callback (stream_session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 133 | { |
| 134 | vl_api_disconnect_session_t *mp; |
| 135 | unix_shared_memory_queue_t *q; |
| 136 | application_t *app = application_get (s->app_index); |
| 137 | |
| 138 | q = vl_api_client_index_to_input_queue (app->api_client_index); |
| 139 | |
| 140 | if (!q) |
| 141 | return; |
| 142 | |
| 143 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 144 | memset (mp, 0, sizeof (*mp)); |
| 145 | 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] | 146 | mp->handle = session_handle (s); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 147 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 148 | } |
| 149 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 150 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 151 | send_session_reset_callback (stream_session_t * s) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 152 | { |
| 153 | vl_api_reset_session_t *mp; |
| 154 | unix_shared_memory_queue_t *q; |
| 155 | application_t *app = application_get (s->app_index); |
| 156 | |
| 157 | q = vl_api_client_index_to_input_queue (app->api_client_index); |
| 158 | |
| 159 | if (!q) |
| 160 | return; |
| 161 | |
| 162 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 163 | memset (mp, 0, sizeof (*mp)); |
| 164 | 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] | 165 | mp->handle = session_handle (s); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 166 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
| 167 | } |
| 168 | |
Dave Barach | 0194f1a | 2017-05-15 10:11:39 -0400 | [diff] [blame] | 169 | int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 170 | send_session_connected_callback (u32 app_index, u32 api_context, |
| 171 | stream_session_t * s, u8 is_fail) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 172 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 173 | vl_api_connect_session_reply_t *mp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 174 | unix_shared_memory_queue_t *q; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 175 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 176 | unix_shared_memory_queue_t *vpp_queue; |
Florin Coras | ade70e4 | 2017-10-14 18:56:41 -0700 | [diff] [blame] | 177 | transport_connection_t *tc; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 178 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 179 | app = application_get (app_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 180 | q = vl_api_client_index_to_input_queue (app->api_client_index); |
| 181 | |
| 182 | if (!q) |
| 183 | return -1; |
| 184 | |
| 185 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 186 | 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] | 187 | mp->context = api_context; |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 188 | |
| 189 | if (is_fail) |
| 190 | goto done; |
| 191 | |
| 192 | tc = session_get_transport (s); |
| 193 | if (!tc) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 194 | { |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 195 | is_fail = 1; |
| 196 | goto done; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 197 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 198 | |
Dave Wallace | 965fec9 | 2017-10-17 16:19:41 -0400 | [diff] [blame] | 199 | vpp_queue = session_manager_get_vpp_event_queue (s->thread_index); |
| 200 | mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo); |
| 201 | mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo); |
| 202 | mp->handle = session_handle (s); |
| 203 | mp->vpp_event_queue_address = pointer_to_uword (vpp_queue); |
| 204 | clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
| 205 | mp->is_ip4 = tc->is_ip4; |
| 206 | mp->lcl_port = tc->lcl_port; |
| 207 | |
| 208 | done: |
| 209 | mp->retval = is_fail ? |
| 210 | clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 211 | vl_msg_api_send_shmem (q, (u8 *) & mp); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Redirect a connect_uri message to the indicated server. |
| 217 | * Only sent if the server has bound the related port with |
| 218 | * URI_OPTIONS_FLAGS_USE_FIFO |
| 219 | */ |
| 220 | static int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 221 | redirect_connect_callback (u32 server_api_client_index, void *mp_arg) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 222 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 223 | vl_api_connect_sock_t *mp = mp_arg; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 224 | unix_shared_memory_queue_t *server_q, *client_q; |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 225 | segment_manager_properties_t *props; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 226 | vlib_main_t *vm = vlib_get_main (); |
| 227 | f64 timeout = vlib_time_now (vm) + 0.5; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 228 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 229 | int rv = 0; |
| 230 | |
| 231 | server_q = vl_api_client_index_to_input_queue (server_api_client_index); |
| 232 | |
| 233 | if (!server_q) |
| 234 | { |
| 235 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 236 | goto out; |
| 237 | } |
| 238 | |
| 239 | client_q = vl_api_client_index_to_input_queue (mp->client_index); |
| 240 | if (!client_q) |
| 241 | { |
| 242 | rv = VNET_API_ERROR_INVALID_VALUE_2; |
| 243 | goto out; |
| 244 | } |
| 245 | |
| 246 | /* Tell the server the client's API queue address, so it can reply */ |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 247 | mp->client_queue_address = pointer_to_uword (client_q); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 248 | app = application_lookup (mp->client_index); |
Florin Coras | 82b13a8 | 2017-04-25 11:58:06 -0700 | [diff] [blame] | 249 | if (!app) |
| 250 | { |
| 251 | clib_warning ("no client application"); |
| 252 | return -1; |
| 253 | } |
| 254 | |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 255 | props = segment_manager_properties_get (app->sm_properties); |
| 256 | mp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = props->rx_fifo_size; |
| 257 | mp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = props->tx_fifo_size; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | * Bounce message handlers MUST NOT block the data-plane. |
| 261 | * Spin waiting for the queue lock, but |
| 262 | */ |
| 263 | |
| 264 | while (vlib_time_now (vm) < timeout) |
| 265 | { |
| 266 | rv = |
| 267 | unix_shared_memory_queue_add (server_q, (u8 *) & mp, 1 /*nowait */ ); |
| 268 | switch (rv) |
| 269 | { |
| 270 | /* correctly enqueued */ |
| 271 | case 0: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 272 | return VNET_API_ERROR_SESSION_REDIRECT; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 273 | |
| 274 | /* continue spinning, wait for pthread_mutex_trylock to work */ |
| 275 | case -1: |
| 276 | continue; |
| 277 | |
| 278 | /* queue stuffed, drop the msg */ |
| 279 | case -2: |
| 280 | rv = VNET_API_ERROR_QUEUE_FULL; |
| 281 | goto out; |
| 282 | } |
| 283 | } |
| 284 | out: |
| 285 | /* Dispose of the message */ |
| 286 | vl_msg_api_free (mp); |
| 287 | return rv; |
| 288 | } |
| 289 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 290 | static session_cb_vft_t session_cb_vft = { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 291 | .session_accept_callback = send_session_accept_callback, |
| 292 | .session_disconnect_callback = send_session_disconnect_callback, |
| 293 | .session_connected_callback = send_session_connected_callback, |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 294 | .session_reset_callback = send_session_reset_callback, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 295 | .add_segment_callback = send_add_segment_callback, |
| 296 | .redirect_connect_callback = redirect_connect_callback |
| 297 | }; |
| 298 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 299 | static void |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 300 | vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp) |
| 301 | { |
| 302 | vl_api_session_enable_disable_reply_t *rmp; |
| 303 | vlib_main_t *vm = vlib_get_main (); |
| 304 | int rv = 0; |
| 305 | |
| 306 | vnet_session_enable_disable (vm, mp->is_enable); |
| 307 | REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY); |
| 308 | } |
| 309 | |
| 310 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 311 | vl_api_application_attach_t_handler (vl_api_application_attach_t * mp) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 312 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 313 | vl_api_application_attach_reply_t *rmp; |
| 314 | vnet_app_attach_args_t _a, *a = &_a; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 315 | clib_error_t *error = 0; |
| 316 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 317 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 318 | if (session_manager_is_enabled () == 0) |
| 319 | { |
| 320 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 321 | goto done; |
| 322 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 323 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 324 | STATIC_ASSERT (sizeof (u64) * SESSION_OPTIONS_N_OPTIONS <= |
| 325 | sizeof (mp->options), |
| 326 | "Out of options, fix api message definition"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 327 | |
| 328 | memset (a, 0, sizeof (*a)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 329 | a->api_client_index = mp->client_index; |
| 330 | a->options = mp->options; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 331 | a->session_cb_vft = &session_cb_vft; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 332 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 333 | if (mp->namespace_id_len > 64) |
| 334 | { |
| 335 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 336 | goto done; |
| 337 | } |
| 338 | |
| 339 | if (mp->namespace_id_len) |
| 340 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 341 | vec_validate (a->namespace_id, mp->namespace_id_len - 1); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 342 | clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len); |
| 343 | } |
| 344 | |
| 345 | if ((error = vnet_application_attach (a))) |
| 346 | { |
| 347 | rv = clib_error_get_code (error); |
| 348 | clib_error_report (error); |
| 349 | } |
| 350 | vec_free (a->namespace_id); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 351 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 352 | done: |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 353 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 354 | /* *INDENT-OFF* */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 355 | REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 356 | if (!rv) |
| 357 | { |
| 358 | rmp->segment_name_length = 0; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 359 | rmp->segment_size = a->segment_size; |
| 360 | if (a->segment_name_length) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 361 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 362 | memcpy (rmp->segment_name, a->segment_name, |
| 363 | a->segment_name_length); |
| 364 | rmp->segment_name_length = a->segment_name_length; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 365 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 366 | rmp->app_event_queue_address = a->app_event_queue_address; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 367 | } |
| 368 | })); |
| 369 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 373 | vl_api_application_detach_t_handler (vl_api_application_detach_t * mp) |
| 374 | { |
| 375 | vl_api_application_detach_reply_t *rmp; |
| 376 | int rv = VNET_API_ERROR_INVALID_VALUE_2; |
| 377 | vnet_app_detach_args_t _a, *a = &_a; |
| 378 | application_t *app; |
| 379 | |
| 380 | if (session_manager_is_enabled () == 0) |
| 381 | { |
| 382 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 383 | goto done; |
| 384 | } |
| 385 | |
| 386 | app = application_lookup (mp->client_index); |
| 387 | if (app) |
| 388 | { |
| 389 | a->app_index = app->index; |
| 390 | rv = vnet_application_detach (a); |
| 391 | } |
| 392 | |
| 393 | done: |
| 394 | REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY); |
| 395 | } |
| 396 | |
| 397 | static void |
| 398 | vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp) |
| 399 | { |
| 400 | vl_api_bind_uri_reply_t *rmp; |
| 401 | vnet_bind_args_t _a, *a = &_a; |
| 402 | application_t *app; |
| 403 | int rv; |
| 404 | |
| 405 | if (session_manager_is_enabled () == 0) |
| 406 | { |
| 407 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 408 | goto done; |
| 409 | } |
| 410 | |
| 411 | app = application_lookup (mp->client_index); |
| 412 | if (app) |
| 413 | { |
| 414 | memset (a, 0, sizeof (*a)); |
| 415 | a->uri = (char *) mp->uri; |
| 416 | a->app_index = app->index; |
| 417 | rv = vnet_bind_uri (a); |
| 418 | } |
| 419 | else |
| 420 | { |
| 421 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 422 | } |
| 423 | |
| 424 | done: |
| 425 | REPLY_MACRO (VL_API_BIND_URI_REPLY); |
| 426 | } |
| 427 | |
| 428 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 429 | vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp) |
| 430 | { |
| 431 | vl_api_unbind_uri_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 432 | application_t *app; |
| 433 | vnet_unbind_args_t _a, *a = &_a; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 434 | int rv; |
| 435 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 436 | if (session_manager_is_enabled () == 0) |
| 437 | { |
| 438 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 439 | goto done; |
| 440 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 441 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 442 | app = application_lookup (mp->client_index); |
| 443 | if (app) |
| 444 | { |
| 445 | a->uri = (char *) mp->uri; |
| 446 | a->app_index = app->index; |
| 447 | rv = vnet_unbind_uri (a); |
| 448 | } |
| 449 | else |
| 450 | { |
| 451 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 452 | } |
| 453 | |
| 454 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 455 | REPLY_MACRO (VL_API_UNBIND_URI_REPLY); |
| 456 | } |
| 457 | |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 458 | static void |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 459 | vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp) |
| 460 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 461 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 462 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 463 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 464 | clib_error_t *error = 0; |
| 465 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 466 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 467 | if (session_manager_is_enabled () == 0) |
| 468 | { |
| 469 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 470 | goto done; |
| 471 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 472 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 473 | app = application_lookup (mp->client_index); |
| 474 | if (app) |
| 475 | { |
| 476 | a->uri = (char *) mp->uri; |
| 477 | a->api_context = mp->context; |
| 478 | a->app_index = app->index; |
| 479 | a->mp = mp; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 480 | if ((error = vnet_connect_uri (a))) |
| 481 | { |
| 482 | rv = clib_error_get_code (error); |
| 483 | if (rv != VNET_API_ERROR_SESSION_REDIRECT) |
| 484 | clib_error_report (error); |
| 485 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 486 | } |
| 487 | else |
| 488 | { |
| 489 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 490 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 491 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 492 | /* |
| 493 | * Don't reply to stream (tcp) connects. The reply will come once |
| 494 | * the connection is established. In case of the redirects, the reply |
| 495 | * will come from the server app. |
| 496 | */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 497 | if (rv == 0 || rv == VNET_API_ERROR_SESSION_REDIRECT) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 498 | return; |
| 499 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 500 | done: |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 501 | /* *INDENT-OFF* */ |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 502 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 503 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static void |
| 507 | vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp) |
| 508 | { |
| 509 | vl_api_disconnect_session_reply_t *rmp; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 510 | vnet_disconnect_args_t _a, *a = &_a; |
| 511 | application_t *app; |
| 512 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 513 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 514 | if (session_manager_is_enabled () == 0) |
| 515 | { |
| 516 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 517 | goto done; |
| 518 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 519 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 520 | app = application_lookup (mp->client_index); |
| 521 | if (app) |
| 522 | { |
| 523 | a->handle = mp->handle; |
| 524 | a->app_index = app->index; |
| 525 | rv = vnet_disconnect_session (a); |
| 526 | } |
| 527 | else |
| 528 | { |
| 529 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 530 | } |
| 531 | |
| 532 | done: |
Dave Wallace | de5fec9 | 2017-11-11 22:41:34 -0500 | [diff] [blame] | 533 | REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static void |
| 537 | vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t * |
| 538 | mp) |
| 539 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 540 | vnet_disconnect_args_t _a, *a = &_a; |
| 541 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 542 | |
| 543 | /* Client objected to disconnecting the session, log and continue */ |
| 544 | if (mp->retval) |
| 545 | { |
| 546 | clib_warning ("client retval %d", mp->retval); |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | /* Disconnect has been confirmed. Confirm close to transport */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 551 | app = application_lookup (mp->client_index); |
| 552 | if (app) |
| 553 | { |
| 554 | a->handle = mp->handle; |
| 555 | a->app_index = app->index; |
| 556 | vnet_disconnect_session (a); |
| 557 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | static void |
| 561 | vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp) |
| 562 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 563 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 564 | stream_session_t *s; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 565 | u32 index, thread_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 566 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 567 | app = application_lookup (mp->client_index); |
| 568 | if (!app) |
| 569 | return; |
| 570 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 571 | session_parse_handle (mp->handle, &index, &thread_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 572 | s = session_get_if_valid (index, thread_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 573 | if (s == 0 || app->index != s->app_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 574 | { |
| 575 | clib_warning ("Invalid session!"); |
| 576 | return; |
| 577 | } |
| 578 | |
| 579 | /* Client objected to resetting the session, log and continue */ |
| 580 | if (mp->retval) |
| 581 | { |
| 582 | clib_warning ("client retval %d", mp->retval); |
| 583 | return; |
| 584 | } |
| 585 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 586 | /* This comes as a response to a reset, transport only waiting for |
| 587 | * confirmation to remove connection state, no need to disconnect */ |
| 588 | stream_session_cleanup (s); |
| 589 | } |
| 590 | |
| 591 | static void |
| 592 | vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp) |
| 593 | { |
| 594 | stream_session_t *s; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 595 | u32 session_index, thread_index; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 596 | vnet_disconnect_args_t _a, *a = &_a; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 597 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 598 | /* Server isn't interested, kill the session */ |
| 599 | if (mp->retval) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 600 | { |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 601 | a->app_index = mp->context; |
| 602 | a->handle = mp->handle; |
| 603 | vnet_disconnect_session (a); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 604 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 605 | else |
| 606 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 607 | session_parse_handle (mp->handle, &session_index, &thread_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 608 | s = session_get_if_valid (session_index, thread_index); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 609 | if (!s) |
| 610 | { |
| 611 | clib_warning ("session doesn't exist"); |
| 612 | return; |
| 613 | } |
| 614 | if (s->app_index != mp->context) |
| 615 | { |
| 616 | clib_warning ("app doesn't own session"); |
| 617 | return; |
| 618 | } |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 619 | s->session_state = SESSION_STATE_READY; |
| 620 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static void |
| 624 | vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t |
| 625 | * mp) |
| 626 | { |
| 627 | clib_warning ("not implemented"); |
| 628 | } |
| 629 | |
| 630 | static void |
| 631 | vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp) |
| 632 | { |
| 633 | vl_api_bind_sock_reply_t *rmp; |
| 634 | vnet_bind_args_t _a, *a = &_a; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 635 | int rv = 0; |
| 636 | clib_error_t *error; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 637 | application_t *app = 0; |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 638 | stream_session_t *s; |
| 639 | transport_connection_t *tc = 0; |
| 640 | ip46_address_t *ip46; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 641 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 642 | if (session_manager_is_enabled () == 0) |
| 643 | { |
| 644 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 645 | goto done; |
| 646 | } |
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 | app = application_lookup (mp->client_index); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 649 | if (!app) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 650 | { |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 651 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 652 | goto done; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 653 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 654 | |
| 655 | ip46 = (ip46_address_t *) mp->ip; |
| 656 | memset (a, 0, sizeof (*a)); |
| 657 | a->sep.is_ip4 = mp->is_ip4; |
| 658 | a->sep.ip = *ip46; |
| 659 | a->sep.port = mp->port; |
| 660 | a->sep.fib_index = mp->vrf; |
| 661 | a->sep.sw_if_index = ENDPOINT_INVALID_INDEX; |
| 662 | a->sep.transport_proto = mp->proto; |
| 663 | a->app_index = app->index; |
| 664 | |
| 665 | if ((error = vnet_bind (a))) |
| 666 | { |
| 667 | rv = clib_error_get_code (error); |
| 668 | clib_error_report (error); |
| 669 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 670 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 671 | done: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 672 | /* *INDENT-OFF* */ |
| 673 | REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({ |
| 674 | if (!rv) |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 675 | { |
| 676 | rmp->handle = a->handle; |
Florin Coras | eb2945c | 2017-11-22 10:39:09 -0800 | [diff] [blame] | 677 | rmp->lcl_port = mp->port; |
| 678 | if (application_has_global_scope (app)) |
| 679 | { |
| 680 | s = listen_session_get_from_handle (a->handle); |
| 681 | tc = listen_session_get_transport (s); |
| 682 | rmp->lcl_is_ip4 = tc->is_ip4; |
| 683 | clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip)); |
| 684 | } |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 685 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 686 | })); |
| 687 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | static void |
| 691 | vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp) |
| 692 | { |
| 693 | vl_api_unbind_sock_reply_t *rmp; |
| 694 | vnet_unbind_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 695 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 696 | clib_error_t *error; |
| 697 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 698 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 699 | if (session_manager_is_enabled () == 0) |
| 700 | { |
| 701 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 702 | goto done; |
| 703 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 704 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 705 | app = application_lookup (mp->client_index); |
| 706 | if (app) |
| 707 | { |
Florin Coras | ef24d42 | 2017-11-09 10:05:42 -0800 | [diff] [blame] | 708 | a->app_index = app->index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 709 | a->handle = mp->handle; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 710 | if ((error = vnet_unbind (a))) |
| 711 | { |
| 712 | rv = clib_error_get_code (error); |
| 713 | clib_error_report (error); |
| 714 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 715 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 716 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 717 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 718 | REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY); |
| 719 | } |
| 720 | |
| 721 | static void |
| 722 | vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp) |
| 723 | { |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 724 | vl_api_connect_session_reply_t *rmp; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 725 | vnet_connect_args_t _a, *a = &_a; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 726 | application_t *app; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 727 | clib_error_t *error = 0; |
| 728 | int rv = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 729 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 730 | if (session_manager_is_enabled () == 0) |
| 731 | { |
| 732 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 733 | goto done; |
| 734 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 735 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 736 | app = application_lookup (mp->client_index); |
| 737 | if (app) |
| 738 | { |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 739 | unix_shared_memory_queue_t *client_q; |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 740 | ip46_address_t *ip46 = (ip46_address_t *) mp->ip; |
Dave Wallace | b2d5ff3 | 2017-06-14 12:38:28 -0400 | [diff] [blame] | 741 | |
| 742 | client_q = vl_api_client_index_to_input_queue (mp->client_index); |
| 743 | mp->client_queue_address = pointer_to_uword (client_q); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 744 | a->sep.is_ip4 = mp->is_ip4; |
| 745 | a->sep.ip = *ip46; |
| 746 | a->sep.port = mp->port; |
| 747 | a->sep.transport_proto = mp->proto; |
| 748 | a->sep.fib_index = mp->vrf; |
| 749 | a->sep.sw_if_index = ENDPOINT_INVALID_INDEX; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 750 | a->api_context = mp->context; |
| 751 | a->app_index = app->index; |
| 752 | a->mp = mp; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 753 | if ((error = vnet_connect (a))) |
| 754 | { |
| 755 | rv = clib_error_get_code (error); |
| 756 | if (rv != VNET_API_ERROR_SESSION_REDIRECT) |
| 757 | clib_error_report (error); |
| 758 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 759 | } |
| 760 | else |
| 761 | { |
| 762 | rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 763 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 764 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 765 | if (rv == 0 || rv == VNET_API_ERROR_SESSION_REDIRECT) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 766 | return; |
| 767 | |
| 768 | /* Got some error, relay it */ |
| 769 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 770 | done: |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 771 | REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 772 | } |
| 773 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 774 | static void |
| 775 | vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp) |
| 776 | { |
| 777 | vl_api_app_namespace_add_del_reply_t *rmp; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 778 | clib_error_t *error = 0; |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 779 | u32 appns_index = 0; |
| 780 | u8 *ns_id = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 781 | int rv = 0; |
| 782 | if (!session_manager_is_enabled ()) |
| 783 | { |
| 784 | rv = VNET_API_ERROR_FEATURE_DISABLED; |
| 785 | goto done; |
| 786 | } |
| 787 | |
| 788 | if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id)) |
| 789 | { |
| 790 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 791 | goto done; |
| 792 | } |
| 793 | |
| 794 | vec_validate (ns_id, mp->namespace_id_len - 1); |
| 795 | clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len); |
| 796 | vnet_app_namespace_add_del_args_t args = { |
| 797 | .ns_id = ns_id, |
Florin Coras | 9a9adb2 | 2017-10-26 08:16:59 -0700 | [diff] [blame] | 798 | .secret = clib_net_to_host_u64 (mp->secret), |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 799 | .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index), |
| 800 | .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id), |
| 801 | .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id), |
| 802 | .is_add = 1 |
| 803 | }; |
| 804 | error = vnet_app_namespace_add_del (&args); |
| 805 | if (error) |
| 806 | { |
| 807 | rv = clib_error_get_code (error); |
| 808 | clib_error_report (error); |
| 809 | } |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 810 | else |
| 811 | { |
| 812 | appns_index = app_namespace_index_from_id (ns_id); |
| 813 | if (appns_index == APP_NAMESPACE_INVALID_INDEX) |
| 814 | { |
| 815 | clib_warning ("app ns lookup failed"); |
| 816 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 817 | } |
| 818 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 819 | vec_free (ns_id); |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 820 | |
| 821 | /* *INDENT-OFF* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 822 | done: |
Florin Coras | 6e8c667 | 2017-11-10 09:03:54 -0800 | [diff] [blame] | 823 | REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({ |
| 824 | if (!rv) |
| 825 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
| 826 | })); |
| 827 | /* *INDENT-ON* */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 830 | static void |
| 831 | vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp) |
| 832 | { |
| 833 | vl_api_session_rule_add_del_reply_t *rmp; |
| 834 | session_rule_add_del_args_t args; |
| 835 | session_rule_table_add_del_args_t *table_args = &args.table_args; |
| 836 | clib_error_t *error; |
| 837 | u8 fib_proto; |
| 838 | int rv = 0; |
| 839 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 840 | memset (&args, 0, sizeof (args)); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 841 | fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6; |
| 842 | |
| 843 | table_args->lcl.fp_len = mp->lcl_plen; |
| 844 | table_args->lcl.fp_proto = fib_proto; |
| 845 | table_args->rmt.fp_len = mp->rmt_plen; |
| 846 | table_args->rmt.fp_proto = fib_proto; |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 847 | table_args->lcl_port = mp->lcl_port; |
| 848 | table_args->rmt_port = mp->rmt_port; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 849 | table_args->action_index = clib_net_to_host_u32 (mp->action_index); |
| 850 | table_args->is_add = mp->is_add; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 851 | mp->tag[sizeof (mp->tag) - 1] = 0; |
| 852 | table_args->tag = format (0, "%s", mp->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 853 | args.appns_index = clib_net_to_host_u32 (mp->appns_index); |
| 854 | args.scope = mp->scope; |
Florin Coras | 42324ad | 2017-11-18 18:45:20 -0800 | [diff] [blame] | 855 | args.transport_proto = mp->transport_proto; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 856 | |
| 857 | memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr)); |
| 858 | memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr)); |
| 859 | ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4); |
| 860 | ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4); |
| 861 | error = vnet_session_rule_add_del (&args); |
| 862 | if (error) |
| 863 | { |
| 864 | rv = clib_error_get_code (error); |
| 865 | clib_error_report (error); |
| 866 | } |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 867 | vec_free (table_args->tag); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 868 | REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY); |
| 869 | } |
| 870 | |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 871 | static void |
| 872 | send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local, |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 873 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 874 | unix_shared_memory_queue_t * q, u32 context) |
| 875 | { |
| 876 | vl_api_session_rules_details_t *rmp = 0; |
| 877 | session_mask_or_match_4_t *match = |
| 878 | (session_mask_or_match_4_t *) & rule->match; |
| 879 | session_mask_or_match_4_t *mask = |
| 880 | (session_mask_or_match_4_t *) & rule->mask; |
| 881 | |
| 882 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 883 | memset (rmp, 0, sizeof (*rmp)); |
| 884 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 885 | rmp->context = context; |
| 886 | |
| 887 | rmp->is_ip4 = 1; |
| 888 | clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 889 | clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip)); |
| 890 | rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip); |
| 891 | rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 892 | rmp->lcl_port = match->lcl_port; |
| 893 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 894 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
| 895 | rmp->scope = |
| 896 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
| 897 | rmp->transport_proto = transport_proto; |
| 898 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 899 | if (tag) |
| 900 | { |
| 901 | clib_memcpy (rmp->tag, tag, vec_len (tag)); |
| 902 | rmp->tag[vec_len (tag)] = 0; |
| 903 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 904 | |
| 905 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 906 | } |
| 907 | |
| 908 | static void |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 909 | send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local, |
| 910 | u8 transport_proto, u32 appns_index, u8 * tag, |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 911 | unix_shared_memory_queue_t * q, u32 context) |
| 912 | { |
| 913 | vl_api_session_rules_details_t *rmp = 0; |
| 914 | session_mask_or_match_6_t *match = |
| 915 | (session_mask_or_match_6_t *) & rule->match; |
| 916 | session_mask_or_match_6_t *mask = |
| 917 | (session_mask_or_match_6_t *) & rule->mask; |
| 918 | |
| 919 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 920 | memset (rmp, 0, sizeof (*rmp)); |
| 921 | rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS); |
| 922 | rmp->context = context; |
| 923 | |
| 924 | rmp->is_ip4 = 0; |
| 925 | clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip)); |
| 926 | clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip)); |
| 927 | rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip); |
| 928 | rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip); |
Milan Lenco | 8b9a5d1 | 2017-11-24 17:12:33 +0100 | [diff] [blame] | 929 | rmp->lcl_port = match->lcl_port; |
| 930 | rmp->rmt_port = match->rmt_port; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 931 | rmp->action_index = clib_host_to_net_u32 (rule->action_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 932 | rmp->scope = |
| 933 | is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 934 | rmp->transport_proto = transport_proto; |
| 935 | rmp->appns_index = clib_host_to_net_u32 (appns_index); |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 936 | if (tag) |
| 937 | { |
| 938 | clib_memcpy (rmp->tag, tag, vec_len (tag)); |
| 939 | rmp->tag[vec_len (tag)] = 0; |
| 940 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 941 | |
| 942 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 943 | } |
| 944 | |
| 945 | static void |
| 946 | 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] | 947 | u8 tp, u8 is_local, u32 appns_index, |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 948 | unix_shared_memory_queue_t * q, u32 context) |
| 949 | { |
| 950 | mma_rule_16_t *rule16; |
| 951 | mma_rule_40_t *rule40; |
| 952 | mma_rules_table_16_t *srt16; |
| 953 | mma_rules_table_40_t *srt40; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 954 | u32 ri; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 955 | |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 956 | if (is_local || fib_proto == FIB_PROTOCOL_IP4) |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 957 | { |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 958 | u8 *tag = 0; |
| 959 | /* *INDENT-OFF* */ |
| 960 | srt16 = &srt->session_rules_tables_16; |
| 961 | pool_foreach (rule16, srt16->rules, ({ |
| 962 | ri = mma_rules_table_rule_index_16 (srt16, rule16); |
| 963 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 964 | send_session_rule_details4 (rule16, is_local, tp, appns_index, tag, |
| 965 | q, context); |
| 966 | })); |
| 967 | /* *INDENT-ON* */ |
| 968 | } |
| 969 | if (is_local || fib_proto == FIB_PROTOCOL_IP6) |
| 970 | { |
| 971 | u8 *tag = 0; |
| 972 | /* *INDENT-OFF* */ |
| 973 | srt40 = &srt->session_rules_tables_40; |
| 974 | pool_foreach (rule40, srt40->rules, ({ |
| 975 | ri = mma_rules_table_rule_index_40 (srt40, rule40); |
| 976 | tag = session_rules_table_rule_tag (srt, ri, 1); |
| 977 | send_session_rule_details6 (rule40, is_local, tp, appns_index, tag, |
| 978 | q, context); |
| 979 | })); |
| 980 | /* *INDENT-ON* */ |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
| 984 | static void |
| 985 | vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp) |
| 986 | { |
| 987 | unix_shared_memory_queue_t *q = NULL; |
| 988 | session_table_t *st; |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 989 | u8 tp; |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 990 | |
| 991 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 992 | if (q == 0) |
| 993 | return; |
| 994 | |
| 995 | /* *INDENT-OFF* */ |
| 996 | session_table_foreach (st, ({ |
Florin Coras | c97a739 | 2017-11-05 23:07:07 -0800 | [diff] [blame] | 997 | for (tp = 0; tp < TRANSPORT_N_PROTO; tp++) |
| 998 | { |
| 999 | send_session_rules_table_details (&st->session_rules[tp], |
| 1000 | st->active_fib_proto, tp, |
| 1001 | st->is_local, st->appns_index, q, |
| 1002 | mp->context); |
| 1003 | } |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 1004 | })); |
| 1005 | /* *INDENT-ON* */ |
| 1006 | } |
| 1007 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1008 | static clib_error_t * |
| 1009 | application_reaper_cb (u32 client_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1010 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1011 | application_t *app = application_lookup (client_index); |
| 1012 | vnet_app_detach_args_t _a, *a = &_a; |
| 1013 | if (app) |
| 1014 | { |
| 1015 | a->app_index = app->index; |
| 1016 | vnet_application_detach (a); |
| 1017 | } |
| 1018 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1019 | } |
| 1020 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1021 | VL_MSG_API_REAPER_FUNCTION (application_reaper_cb); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1022 | |
| 1023 | #define vl_msg_name_crc_list |
| 1024 | #include <vnet/vnet_all_api_h.h> |
| 1025 | #undef vl_msg_name_crc_list |
| 1026 | |
| 1027 | static void |
| 1028 | setup_message_id_table (api_main_t * am) |
| 1029 | { |
| 1030 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 1031 | foreach_vl_msg_name_crc_session; |
| 1032 | #undef _ |
| 1033 | } |
| 1034 | |
| 1035 | /* |
| 1036 | * session_api_hookup |
| 1037 | * Add uri's API message handlers to the table. |
| 1038 | * vlib has alread mapped shared memory and |
| 1039 | * added the client registration handlers. |
| 1040 | * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process() |
| 1041 | */ |
| 1042 | static clib_error_t * |
| 1043 | session_api_hookup (vlib_main_t * vm) |
| 1044 | { |
| 1045 | api_main_t *am = &api_main; |
| 1046 | |
| 1047 | #define _(N,n) \ |
| 1048 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1049 | vl_api_##n##_t_handler, \ |
| 1050 | vl_noop_handler, \ |
| 1051 | vl_api_##n##_t_endian, \ |
| 1052 | vl_api_##n##_t_print, \ |
| 1053 | sizeof(vl_api_##n##_t), 1); |
| 1054 | foreach_session_api_msg; |
| 1055 | #undef _ |
| 1056 | |
| 1057 | /* |
| 1058 | * Messages which bounce off the data-plane to |
| 1059 | * an API client. Simply tells the message handling infra not |
| 1060 | * to free the message. |
| 1061 | * |
| 1062 | * Bounced message handlers MUST NOT block the data plane |
| 1063 | */ |
| 1064 | am->message_bounce[VL_API_CONNECT_URI] = 1; |
| 1065 | am->message_bounce[VL_API_CONNECT_SOCK] = 1; |
| 1066 | |
| 1067 | /* |
| 1068 | * Set up the (msg_name, crc, message-id) table |
| 1069 | */ |
| 1070 | setup_message_id_table (am); |
| 1071 | |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | VLIB_API_INIT_FUNCTION (session_api_hookup); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1076 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1077 | /* |
| 1078 | * fd.io coding-style-patch-verification: ON |
| 1079 | * |
| 1080 | * Local Variables: |
| 1081 | * eval: (c-set-style "gnu") |
| 1082 | * End: |
| 1083 | */ |