blob: a0dff90565af141a4a3f2596a266d4bb4872333d [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
2 * Copyright (c) 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#include <vnet/session/application_interface.h>
16
17#include <vnet/session/session.h>
18#include <vlibmemory/api.h>
19#include <vnet/dpo/load_balance.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050020
21/** @file
22 VPP's application/session API bind/unbind/connect/disconnect calls
23*/
24
25static u8
Florin Corascea194d2017-10-02 00:18:51 -070026session_endpoint_is_local (session_endpoint_t * sep)
Dave Barach68b0fb02017-02-28 15:15:56 -050027{
Florin Corascea194d2017-10-02 00:18:51 -070028 return (ip_is_zero (&sep->ip, sep->is_ip4)
29 || ip_is_local_host (&sep->ip, sep->is_ip4));
Dave Barach68b0fb02017-02-28 15:15:56 -050030}
31
32static u8
Florin Corascea194d2017-10-02 00:18:51 -070033session_endpoint_is_zero (session_endpoint_t * sep)
Dave Barach68b0fb02017-02-28 15:15:56 -050034{
Florin Corascea194d2017-10-02 00:18:51 -070035 return ip_is_zero (&sep->ip, sep->is_ip4);
36}
Dave Barach68b0fb02017-02-28 15:15:56 -050037
Florin Corascea194d2017-10-02 00:18:51 -070038u8
39session_endpoint_in_ns (session_endpoint_t * sep)
40{
41 u8 is_zero = ip_is_zero (&sep->ip, sep->is_ip4);
42 if (!is_zero && sep->sw_if_index != ENDPOINT_INVALID_INDEX
43 && !ip_interface_has_address (sep->sw_if_index, &sep->ip, sep->is_ip4))
Dave Barach68b0fb02017-02-28 15:15:56 -050044 {
Florin Corascea194d2017-10-02 00:18:51 -070045 clib_warning ("sw_if_index %u not configured with ip %U",
46 sep->sw_if_index, format_ip46_address, &sep->ip,
47 sep->is_ip4);
48 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -050049 }
Florin Corascea194d2017-10-02 00:18:51 -070050 return (is_zero || ip_is_local (sep->fib_index, &sep->ip, sep->is_ip4));
Dave Barach68b0fb02017-02-28 15:15:56 -050051}
52
53int
54api_parse_session_handle (u64 handle, u32 * session_index, u32 * thread_index)
55{
56 session_manager_main_t *smm = vnet_get_session_manager_main ();
57 stream_session_t *pool;
58
59 *thread_index = handle & 0xFFFFFFFF;
60 *session_index = handle >> 32;
61
62 if (*thread_index >= vec_len (smm->sessions))
63 return VNET_API_ERROR_INVALID_VALUE;
64
65 pool = smm->sessions[*thread_index];
66
67 if (pool_is_free_index (pool, *session_index))
68 return VNET_API_ERROR_INVALID_VALUE_2;
69
70 return 0;
71}
72
Florin Corascea194d2017-10-02 00:18:51 -070073static void
74session_endpoint_update_for_app (session_endpoint_t * sep,
75 application_t * app)
76{
77 app_namespace_t *app_ns;
78 app_ns = app_namespace_get (app->ns_index);
79 if (app_ns)
80 {
81 /* Ask transport and network to bind to/connect using local interface
82 * that "supports" app's namespace. This will fix our local connection
83 * endpoint.
84 */
85 sep->sw_if_index = app_ns->sw_if_index;
86 sep->fib_index =
87 sep->is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
88 }
89}
90
91static int
92vnet_bind_i (u32 app_index, session_endpoint_t * sep, u64 * handle)
Dave Barach68b0fb02017-02-28 15:15:56 -050093{
Florin Coras6cf30ad2017-04-04 23:08:23 -070094 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -070095 u32 table_index, listener_index;
96 int rv, have_local = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -050097
Florin Coras6cf30ad2017-04-04 23:08:23 -070098 app = application_get_if_valid (app_index);
99 if (!app)
100 {
Florin Corascea194d2017-10-02 00:18:51 -0700101 SESSION_DBG ("app not attached");
Florin Coras6cf30ad2017-04-04 23:08:23 -0700102 return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
103 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500104
Florin Corascea194d2017-10-02 00:18:51 -0700105 session_endpoint_update_for_app (sep, app);
106 if (!session_endpoint_in_ns (sep))
Dave Barach68b0fb02017-02-28 15:15:56 -0500107 return VNET_API_ERROR_INVALID_VALUE_2;
108
Florin Corascea194d2017-10-02 00:18:51 -0700109 table_index = application_session_table (app,
110 session_endpoint_fib_proto (sep));
111 listener_index = session_lookup_session_endpoint (table_index, sep);
112 if (listener_index != SESSION_INVALID_INDEX)
113 return VNET_API_ERROR_ADDRESS_IN_USE;
114
115 /*
116 * Add session endpoint to local session table. Only binds to "inaddr_any"
117 * (i.e., zero address) are added to local scope table.
118 */
119 if (application_has_local_scope (app) && session_endpoint_is_zero (sep))
120 {
121 table_index = application_local_session_table (app);
122 listener_index = session_lookup_session_endpoint (table_index, sep);
123 if (listener_index != SESSION_INVALID_INDEX)
124 return VNET_API_ERROR_ADDRESS_IN_USE;
125 session_lookup_add_session_endpoint (table_index, sep, app->index);
126 *handle = session_lookup_local_listener_make_handle (sep);
127 have_local = 1;
128 }
129
130 if (!application_has_global_scope (app))
131 return (have_local - 1);
132
133 /*
134 * Add session endpoint to global session table
135 */
136
Florin Coras6cf30ad2017-04-04 23:08:23 -0700137 /* Setup listen path down to transport */
Florin Corascea194d2017-10-02 00:18:51 -0700138 rv = application_start_listen (app, sep, handle);
139 if (rv && have_local)
140 session_lookup_del_session_endpoint (table_index, sep);
141 return rv;
Dave Barach68b0fb02017-02-28 15:15:56 -0500142}
143
144int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700145vnet_unbind_i (u32 app_index, u64 handle)
146{
147 application_t *app = application_get_if_valid (app_index);
Florin Corascea194d2017-10-02 00:18:51 -0700148 stream_session_t *listener = 0;
149 u32 table_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700150
151 if (!app)
152 {
Florin Corascea194d2017-10-02 00:18:51 -0700153 SESSION_DBG ("app (%d) not attached", app_index);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700154 return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
155 }
156
Florin Corascea194d2017-10-02 00:18:51 -0700157 /*
158 * Clean up local session table. If we have a listener session use it to
159 * find the port and proto. If not, the handle must be a local table handle
160 * so parse it.
161 */
162
163 if (application_has_local_scope (app))
164 {
165 session_endpoint_t sep = SESSION_ENDPOINT_NULL;
166 if (!session_lookup_local_is_handle (handle))
167 listener = listen_session_get_from_handle (handle);
168 if (listener)
169 {
170 if (listen_session_get_local_session_endpoint (listener, &sep))
171 {
172 clib_warning ("broken listener");
173 return -1;
174 }
175 }
176 else
177 {
178 if (session_lookup_local_listener_parse_handle (handle, &sep))
179 {
180 clib_warning ("can't parse handle");
181 return -1;
182 }
183 }
184 table_index = application_local_session_table (app);
185 session_lookup_del_session_endpoint (table_index, &sep);
186 }
187
188 /*
189 * Clear the global scope table of the listener
190 */
191 if (application_has_global_scope (app))
192 return application_stop_listen (app, handle);
193 return 0;
194}
195
196static int
197app_connect_redirect (application_t * server, void *mp)
198{
199 return server->cb_fns.redirect_connect_callback (server->api_client_index,
200 mp);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700201}
202
203int
Florin Corascea194d2017-10-02 00:18:51 -0700204vnet_connect_i (u32 app_index, u32 api_context, session_endpoint_t * sep,
205 void *mp)
Dave Barach68b0fb02017-02-28 15:15:56 -0500206{
Dave Barach68b0fb02017-02-28 15:15:56 -0500207 application_t *server, *app;
Florin Corascea194d2017-10-02 00:18:51 -0700208 u32 table_index;
209
210 if (session_endpoint_is_zero (sep))
211 return VNET_API_ERROR_INVALID_VALUE;
212
213 app = application_get (app_index);
214 session_endpoint_update_for_app (sep, app);
Dave Barach68b0fb02017-02-28 15:15:56 -0500215
216 /*
Florin Corascea194d2017-10-02 00:18:51 -0700217 * First check the the local scope for locally attached destinations.
218 * If we have local scope, we pass *all* connects through it since we may
219 * have special policy rules even for non-local destinations, think proxy.
Dave Barach68b0fb02017-02-28 15:15:56 -0500220 */
Florin Corascea194d2017-10-02 00:18:51 -0700221 if (application_has_local_scope (app))
Dave Barach68b0fb02017-02-28 15:15:56 -0500222 {
Florin Corascea194d2017-10-02 00:18:51 -0700223 table_index = application_local_session_table (app);
224 app_index = session_lookup_local_session_endpoint (table_index, sep);
225 server = application_get (app_index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500226 /*
227 * Server is willing to have a direct fifo connection created
228 * instead of going through the state machine, etc.
229 */
Florin Corascea194d2017-10-02 00:18:51 -0700230 if (server && (server->flags & APP_OPTIONS_FLAGS_ACCEPT_REDIRECT))
231 return app_connect_redirect (server, mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500232 }
233
Dave Barach68b0fb02017-02-28 15:15:56 -0500234 /*
Florin Corascea194d2017-10-02 00:18:51 -0700235 * If nothing found, check the global scope for locally attached
236 * destinations. Make sure first that we're allowed to.
Dave Barach68b0fb02017-02-28 15:15:56 -0500237 */
Florin Corascea194d2017-10-02 00:18:51 -0700238 if (session_endpoint_is_local (sep))
239 return VNET_API_ERROR_SESSION_CONNECT;
240
241 if (!application_has_global_scope (app))
242 return VNET_API_ERROR_APP_CONNECT_SCOPE;
243
244 table_index = application_session_table (app,
245 session_endpoint_fib_proto (sep));
246 app_index = session_lookup_session_endpoint (table_index, sep);
247 server = application_get (app_index);
248 if (server && (server->flags & APP_OPTIONS_FLAGS_ACCEPT_REDIRECT))
249 return app_connect_redirect (server, mp);
250
251 /*
252 * Not connecting to a local server, propagate to transport
253 */
254 if (application_open_session (app, sep, api_context))
255 return VNET_API_ERROR_SESSION_CONNECT;
256 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500257}
258
259/**
260 * unformat a vnet URI
261 *
262 * fifo://name
263 * tcp://ip46-addr:port
264 * udp://ip46-addr:port
265 *
266 * u8 ip46_address[16];
267 * u16 port_in_host_byte_order;
268 * stream_session_type_t sst;
269 * u8 *fifo_name;
270 *
271 * if (unformat (input, "%U", unformat_vnet_uri, &ip46_address,
272 * &sst, &port, &fifo_name))
273 * etc...
274 *
275 */
276uword
277unformat_vnet_uri (unformat_input_t * input, va_list * args)
278{
Florin Corascea194d2017-10-02 00:18:51 -0700279 session_endpoint_t *sep = va_arg (*args, session_endpoint_t *);
Dave Barach68b0fb02017-02-28 15:15:56 -0500280
Florin Corascea194d2017-10-02 00:18:51 -0700281 if (unformat (input, "tcp://%U/%d", unformat_ip4_address, &sep->ip.ip4,
282 &sep->port))
Dave Barach68b0fb02017-02-28 15:15:56 -0500283 {
Florin Corascea194d2017-10-02 00:18:51 -0700284 sep->transport_proto = TRANSPORT_PROTO_TCP;
285 sep->port = clib_host_to_net_u16 (sep->port);
286 sep->is_ip4 = 1;
Dave Barach68b0fb02017-02-28 15:15:56 -0500287 return 1;
288 }
Florin Corascea194d2017-10-02 00:18:51 -0700289 if (unformat (input, "udp://%U/%d", unformat_ip4_address, &sep->ip.ip4,
290 &sep->port))
Dave Barach68b0fb02017-02-28 15:15:56 -0500291 {
Florin Corascea194d2017-10-02 00:18:51 -0700292 sep->transport_proto = TRANSPORT_PROTO_UDP;
293 sep->port = clib_host_to_net_u16 (sep->port);
294 sep->is_ip4 = 1;
Dave Barach68b0fb02017-02-28 15:15:56 -0500295 return 1;
296 }
Florin Corascea194d2017-10-02 00:18:51 -0700297 if (unformat (input, "udp://%U/%d", unformat_ip6_address, &sep->ip.ip6,
298 &sep->port))
Dave Barach68b0fb02017-02-28 15:15:56 -0500299 {
Florin Corascea194d2017-10-02 00:18:51 -0700300 sep->transport_proto = TRANSPORT_PROTO_UDP;
301 sep->port = clib_host_to_net_u16 (sep->port);
302 sep->is_ip4 = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500303 return 1;
304 }
Florin Corascea194d2017-10-02 00:18:51 -0700305 if (unformat (input, "tcp://%U/%d", unformat_ip6_address, &sep->ip.ip6,
306 &sep->port))
Dave Barach68b0fb02017-02-28 15:15:56 -0500307 {
Florin Corascea194d2017-10-02 00:18:51 -0700308 sep->transport_proto = TRANSPORT_PROTO_TCP;
309 sep->port = clib_host_to_net_u16 (sep->port);
310 sep->is_ip4 = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500311 return 1;
312 }
313
314 return 0;
315}
316
Dave Barachb7f1faa2017-08-29 11:43:37 -0400317static u8 *cache_uri;
Florin Corascea194d2017-10-02 00:18:51 -0700318static session_endpoint_t *cache_sep;
Dave Barachb7f1faa2017-08-29 11:43:37 -0400319
Dave Barach68b0fb02017-02-28 15:15:56 -0500320int
Florin Corascea194d2017-10-02 00:18:51 -0700321parse_uri (char *uri, session_endpoint_t * sep)
Dave Barach68b0fb02017-02-28 15:15:56 -0500322{
323 unformat_input_t _input, *input = &_input;
324
Dave Barachb7f1faa2017-08-29 11:43:37 -0400325 if (cache_uri && !strncmp (uri, (char *) cache_uri, vec_len (cache_uri)))
326 {
Florin Corascea194d2017-10-02 00:18:51 -0700327 *sep = *cache_sep;
Dave Barachb7f1faa2017-08-29 11:43:37 -0400328 return 0;
329 }
330
Dave Barach68b0fb02017-02-28 15:15:56 -0500331 /* Make sure */
332 uri = (char *) format (0, "%s%c", uri, 0);
333
334 /* Parse uri */
335 unformat_init_string (input, uri, strlen (uri));
Florin Corascea194d2017-10-02 00:18:51 -0700336 if (!unformat (input, "%U", unformat_vnet_uri, sep))
Dave Barach68b0fb02017-02-28 15:15:56 -0500337 {
338 unformat_free (input);
339 return VNET_API_ERROR_INVALID_VALUE;
340 }
341 unformat_free (input);
342
Dave Barachb7f1faa2017-08-29 11:43:37 -0400343 vec_free (cache_uri);
344 cache_uri = (u8 *) uri;
Florin Corascea194d2017-10-02 00:18:51 -0700345 if (cache_sep)
346 clib_mem_free (cache_sep);
347 cache_sep = clib_mem_alloc (sizeof (*sep));
348 *cache_sep = *sep;
Dave Barachb7f1faa2017-08-29 11:43:37 -0400349
Dave Barach68b0fb02017-02-28 15:15:56 -0500350 return 0;
351}
352
Florin Corascea194d2017-10-02 00:18:51 -0700353static int
354session_validate_namespace (u8 * namespace_id, u64 secret, u32 * app_ns_index)
355{
356 app_namespace_t *app_ns;
357 if (vec_len (namespace_id) == 0)
358 {
359 /* Use default namespace */
360 *app_ns_index = 0;
361 return 0;
362 }
363
364 *app_ns_index = app_namespace_index_from_id (namespace_id);
365 if (*app_ns_index == APP_NAMESPACE_INVALID_INDEX)
366 return VNET_API_ERROR_APP_INVALID_NS;
367 app_ns = app_namespace_get (*app_ns_index);
368 if (!app_ns)
369 return VNET_API_ERROR_APP_INVALID_NS;
370 if (app_ns->ns_secret != secret)
371 return VNET_API_ERROR_APP_WRONG_NS_SECRET;
372 return 0;
373}
374
Florin Coras6cf30ad2017-04-04 23:08:23 -0700375/**
Florin Corascea194d2017-10-02 00:18:51 -0700376 * Attach application to vpp
Florin Coras6cf30ad2017-04-04 23:08:23 -0700377 *
378 * Allocates a vpp app, i.e., a structure that keeps back pointers
379 * to external app and a segment manager for shared memory fifo based
380 * communication with the external app.
381 */
Florin Corascea194d2017-10-02 00:18:51 -0700382clib_error_t *
Florin Coras6cf30ad2017-04-04 23:08:23 -0700383vnet_application_attach (vnet_app_attach_args_t * a)
Dave Barach68b0fb02017-02-28 15:15:56 -0500384{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700385 application_t *app = 0;
386 segment_manager_t *sm;
387 u8 *seg_name;
Florin Corascea194d2017-10-02 00:18:51 -0700388 u64 secret;
389 u32 app_ns_index = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500390 int rv;
391
Florin Corascea194d2017-10-02 00:18:51 -0700392 app = application_lookup (a->api_client_index);
393 if (app)
394 return clib_error_return_code (0, VNET_API_ERROR_APP_ALREADY_ATTACHED,
395 0, "app already attached");
396
397 secret = a->options[APP_OPTIONS_NAMESPACE_SECRET];
398 if ((rv = session_validate_namespace (a->namespace_id, secret,
399 &app_ns_index)))
400 return clib_error_return_code (0, rv, 0, "namespace validation: %d", rv);
401 a->options[APP_OPTIONS_NAMESPACE] = app_ns_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700402 app = application_new ();
403 if ((rv = application_init (app, a->api_client_index, a->options,
404 a->session_cb_vft)))
Florin Corascea194d2017-10-02 00:18:51 -0700405 return clib_error_return_code (0, rv, 0, "app init: %d", rv);
Dave Barach68b0fb02017-02-28 15:15:56 -0500406
Damjan Marion7bee80c2017-04-26 15:32:12 +0200407 a->app_event_queue_address = pointer_to_uword (app->event_queue);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700408 sm = segment_manager_get (app->first_segment_manager);
409 segment_manager_get_segment_info (sm->segment_indices[0],
410 &seg_name, &a->segment_size);
Dave Barach68b0fb02017-02-28 15:15:56 -0500411
Florin Coras6cf30ad2017-04-04 23:08:23 -0700412 a->segment_name_length = vec_len (seg_name);
413 a->segment_name = seg_name;
414 ASSERT (vec_len (a->segment_name) <= 128);
415 a->app_index = app->index;
416 return 0;
417}
418
Florin Corascea194d2017-10-02 00:18:51 -0700419/**
420 * Detach application from vpp
421 */
Florin Coras6cf30ad2017-04-04 23:08:23 -0700422int
423vnet_application_detach (vnet_app_detach_args_t * a)
424{
425 application_t *app;
426 app = application_get_if_valid (a->app_index);
427
428 if (!app)
429 {
430 clib_warning ("app not attached");
431 return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
432 }
433
434 application_del (app);
Dave Barach68b0fb02017-02-28 15:15:56 -0500435 return 0;
436}
437
Dave Barach68b0fb02017-02-28 15:15:56 -0500438int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700439vnet_bind_uri (vnet_bind_args_t * a)
Dave Barach68b0fb02017-02-28 15:15:56 -0500440{
Florin Corascea194d2017-10-02 00:18:51 -0700441 session_endpoint_t sep = SESSION_ENDPOINT_NULL;
Dave Barach68b0fb02017-02-28 15:15:56 -0500442 int rv;
443
Florin Corascea194d2017-10-02 00:18:51 -0700444 rv = parse_uri (a->uri, &sep);
Dave Barach68b0fb02017-02-28 15:15:56 -0500445 if (rv)
446 return rv;
447
Florin Corascea194d2017-10-02 00:18:51 -0700448 return vnet_bind_i (a->app_index, &sep, &a->handle);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700449}
450
451int
452vnet_unbind_uri (vnet_unbind_args_t * a)
453{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700454 stream_session_t *listener;
Florin Corascea194d2017-10-02 00:18:51 -0700455 session_endpoint_t sep = SESSION_ENDPOINT_NULL;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700456 int rv;
457
Florin Corascea194d2017-10-02 00:18:51 -0700458 rv = parse_uri (a->uri, &sep);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700459 if (rv)
460 return rv;
461
Florin Corascea194d2017-10-02 00:18:51 -0700462 /* NOTE: only default table supported for uri */
463 listener = session_lookup_listener (0, &sep);
Dave Barach68b0fb02017-02-28 15:15:56 -0500464 if (!listener)
465 return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
466
Florin Coras6cf30ad2017-04-04 23:08:23 -0700467 return vnet_unbind_i (a->app_index, listen_session_get_handle (listener));
Dave Barach68b0fb02017-02-28 15:15:56 -0500468}
469
Florin Corascea194d2017-10-02 00:18:51 -0700470clib_error_t *
Dave Barach68b0fb02017-02-28 15:15:56 -0500471vnet_connect_uri (vnet_connect_args_t * a)
472{
Florin Corascea194d2017-10-02 00:18:51 -0700473 session_endpoint_t sep = SESSION_ENDPOINT_NULL;
Dave Barach68b0fb02017-02-28 15:15:56 -0500474 int rv;
475
Dave Barach68b0fb02017-02-28 15:15:56 -0500476 /* Parse uri */
Florin Corascea194d2017-10-02 00:18:51 -0700477 rv = parse_uri (a->uri, &sep);
Dave Barach68b0fb02017-02-28 15:15:56 -0500478 if (rv)
Florin Corascea194d2017-10-02 00:18:51 -0700479 return clib_error_return_code (0, rv, 0, "app init: %d", rv);
480 if ((rv = vnet_connect_i (a->app_index, a->api_context, &sep, a->mp)))
481 return clib_error_return_code (0, rv, 0, "connect failed");
482 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500483}
484
485int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700486vnet_disconnect_session (vnet_disconnect_args_t * a)
Dave Barach68b0fb02017-02-28 15:15:56 -0500487{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700488 u32 index, thread_index;
489 stream_session_t *s;
Dave Barach68b0fb02017-02-28 15:15:56 -0500490
Florin Corascea194d2017-10-02 00:18:51 -0700491 session_parse_handle (a->handle, &index, &thread_index);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700492 s = stream_session_get_if_valid (index, thread_index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500493
Florin Coras6cf30ad2017-04-04 23:08:23 -0700494 if (!s || s->app_index != a->app_index)
495 return VNET_API_ERROR_INVALID_VALUE;
496
Florin Corasa5464812017-04-19 13:00:05 -0700497 /* We're peeking into another's thread pool. Make sure */
498 ASSERT (s->session_index == index);
499
500 session_send_session_evt_to_thread (a->handle, FIFO_EVENT_DISCONNECT,
501 thread_index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500502 return 0;
503}
504
Florin Corascea194d2017-10-02 00:18:51 -0700505clib_error_t *
Dave Barach68b0fb02017-02-28 15:15:56 -0500506vnet_bind (vnet_bind_args_t * a)
507{
Dave Barach68b0fb02017-02-28 15:15:56 -0500508 int rv;
Florin Corascea194d2017-10-02 00:18:51 -0700509 if ((rv = vnet_bind_i (a->app_index, &a->sep, &a->handle)))
510 return clib_error_return_code (0, rv, 0, "bind failed");
Dave Barach68b0fb02017-02-28 15:15:56 -0500511 return 0;
512}
513
Florin Corascea194d2017-10-02 00:18:51 -0700514clib_error_t *
Dave Barach68b0fb02017-02-28 15:15:56 -0500515vnet_unbind (vnet_unbind_args_t * a)
516{
Florin Corascea194d2017-10-02 00:18:51 -0700517 int rv;
518 if ((rv = vnet_unbind_i (a->app_index, a->handle)))
519 return clib_error_return_code (0, rv, 0, "unbind failed");
520 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500521}
522
Florin Corascea194d2017-10-02 00:18:51 -0700523clib_error_t *
Dave Barach68b0fb02017-02-28 15:15:56 -0500524vnet_connect (vnet_connect_args_t * a)
525{
Florin Corascea194d2017-10-02 00:18:51 -0700526 int rv;
527 if ((rv = vnet_connect_i (a->app_index, a->api_context, &a->sep, a->mp)))
528 return clib_error_return_code (0, rv, 0, "connect failed");
529 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500530}
531
Dave Barach68b0fb02017-02-28 15:15:56 -0500532/*
533 * fd.io coding-style-patch-verification: ON
534 *
535 * Local Variables:
536 * eval: (c-set-style "gnu")
537 * End:
538 */