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