session: first approximation implementation of tls
[vpp.git] / src / vnet / session / application_interface.c
1 /*
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>
20
21 /** @file
22     VPP's application/session API bind/unbind/connect/disconnect calls
23 */
24
25 /*
26  * TLS server cert and keys to be used for testing only
27  */
28 const char test_srv_crt_rsa[] =
29   "-----BEGIN CERTIFICATE-----\r\n"
30   "MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n"
31   "MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n"
32   "MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n"
33   "A1UEChMIUG9sYXJTU0wxEjAQBgNVBAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n"
34   "AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n"
35   "owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n"
36   "NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n"
37   "tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n"
38   "hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n"
39   "HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n"
40   "VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n"
41   "FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQEFBQADggEBAJxnXClY\r\n"
42   "oHkbp70cqBrsGXLybA74czbO5RdLEgFs7rHVS9r+c293luS/KdliLScZqAzYVylw\r\n"
43   "UfRWvKMoWhHYKp3dEIS4xTXk6/5zXxhv9Rw8SGc8qn6vITHk1S1mPevtekgasY5Y\r\n"
44   "iWQuM3h4YVlRH3HHEMAD1TnAexfXHHDFQGe+Bd1iAbz1/sH9H8l4StwX6egvTK3M\r\n"
45   "wXRwkKkvjKaEDA9ATbZx0mI8LGsxSuCqe9r9dyjmttd47J1p1Rulz3CLzaRcVIuS\r\n"
46   "RRQfaD8neM9c1S/iJ/amTVqJxA1KOdOS5780WhPfSArA+g4qAmSjelc3p4wWpha8\r\n"
47   "zhuYwjVuX6JHG0c=\r\n" "-----END CERTIFICATE-----\r\n";
48 const u32 test_srv_crt_rsa_len = sizeof (test_srv_crt_rsa);
49
50 const char test_srv_key_rsa[] =
51   "-----BEGIN RSA PRIVATE KEY-----\r\n"
52   "MIIEpAIBAAKCAQEAwU2j3efNHdEE10lyuJmsDnjkOjxKzzoTFtBa5M2jAIin7h5r\r\n"
53   "lqdStJDvLXJ6PiSa/LY0rCT1d+AmZIycsCh9odrqjObJHJa8/sEEUrM21KP64bF2\r\n"
54   "2JDBYbRmUjaiJlOqq3ReB30Zgtsq2B+g2Q0cLUlm91slc0boC4pPaQy1AJDh2oIQ\r\n"
55   "Zn2uVCuLZXmRoeJhw81ASQjuaAzxi4bSRr/QuKoRAx5/VqgaHkQYDw+Fi9qLRF7i\r\n"
56   "GMZiL8dmjfpd2H3zJ4kpAcWQDj8n8TDISg7v1t7HxydrxwU9esQCPJodPg/oNJhb\r\n"
57   "y3NLUpbYEaIsgIhpOVrTD7DeWS8Rx/fqEgEwlwIDAQABAoIBAQCXR0S8EIHFGORZ\r\n"
58   "++AtOg6eENxD+xVs0f1IeGz57Tjo3QnXX7VBZNdj+p1ECvhCE/G7XnkgU5hLZX+G\r\n"
59   "Z0jkz/tqJOI0vRSdLBbipHnWouyBQ4e/A1yIJdlBtqXxJ1KE/ituHRbNc4j4kL8Z\r\n"
60   "/r6pvwnTI0PSx2Eqs048YdS92LT6qAv4flbNDxMn2uY7s4ycS4Q8w1JXnCeaAnYm\r\n"
61   "WYI5wxO+bvRELR2Mcz5DmVnL8jRyml6l6582bSv5oufReFIbyPZbQWlXgYnpu6He\r\n"
62   "GTc7E1zKYQGG/9+DQUl/1vQuCPqQwny0tQoX2w5tdYpdMdVm+zkLtbajzdTviJJa\r\n"
63   "TWzL6lt5AoGBAN86+SVeJDcmQJcv4Eq6UhtRr4QGMiQMz0Sod6ettYxYzMgxtw28\r\n"
64   "CIrgpozCc+UaZJLo7UxvC6an85r1b2nKPCLQFaggJ0H4Q0J/sZOhBIXaoBzWxveK\r\n"
65   "nupceKdVxGsFi8CDy86DBfiyFivfBj+47BbaQzPBj7C4rK7UlLjab2rDAoGBAN2u\r\n"
66   "AM2gchoFiu4v1HFL8D7lweEpi6ZnMJjnEu/dEgGQJFjwdpLnPbsj4c75odQ4Gz8g\r\n"
67   "sw9lao9VVzbusoRE/JGI4aTdO0pATXyG7eG1Qu+5Yc1YGXcCrliA2xM9xx+d7f+s\r\n"
68   "mPzN+WIEg5GJDYZDjAzHG5BNvi/FfM1C9dOtjv2dAoGAF0t5KmwbjWHBhcVqO4Ic\r\n"
69   "BVvN3BIlc1ue2YRXEDlxY5b0r8N4XceMgKmW18OHApZxfl8uPDauWZLXOgl4uepv\r\n"
70   "whZC3EuWrSyyICNhLY21Ah7hbIEBPF3L3ZsOwC+UErL+dXWLdB56Jgy3gZaBeW7b\r\n"
71   "vDrEnocJbqCm7IukhXHOBK8CgYEAwqdHB0hqyNSzIOGY7v9abzB6pUdA3BZiQvEs\r\n"
72   "3LjHVd4HPJ2x0N8CgrBIWOE0q8+0hSMmeE96WW/7jD3fPWwCR5zlXknxBQsfv0gP\r\n"
73   "3BC5PR0Qdypz+d+9zfMf625kyit4T/hzwhDveZUzHnk1Cf+IG7Q+TOEnLnWAWBED\r\n"
74   "ISOWmrUCgYAFEmRxgwAc/u+D6t0syCwAYh6POtscq9Y0i9GyWk89NzgC4NdwwbBH\r\n"
75   "4AgahOxIxXx2gxJnq3yfkJfIjwf0s2DyP0kY2y6Ua1OeomPeY9mrIS4tCuDQ6LrE\r\n"
76   "TB6l9VGoxJL4fyHnZb8L5gGvnB1bbD8cL6YPaDiOhcRseC9vBiEuVg==\r\n"
77   "-----END RSA PRIVATE KEY-----\r\n";
78 const u32 test_srv_key_rsa_len = sizeof (test_srv_key_rsa);
79
80 static u8
81 session_endpoint_is_local (session_endpoint_t * sep)
82 {
83   return (ip_is_zero (&sep->ip, sep->is_ip4)
84           || ip_is_local_host (&sep->ip, sep->is_ip4));
85 }
86
87 static u8
88 session_endpoint_is_zero (session_endpoint_t * sep)
89 {
90   return ip_is_zero (&sep->ip, sep->is_ip4);
91 }
92
93 u8
94 session_endpoint_in_ns (session_endpoint_t * sep)
95 {
96   u8 is_zero = ip_is_zero (&sep->ip, sep->is_ip4);
97   if (!is_zero && sep->sw_if_index != ENDPOINT_INVALID_INDEX
98       && !ip_interface_has_address (sep->sw_if_index, &sep->ip, sep->is_ip4))
99     {
100       clib_warning ("sw_if_index %u not configured with ip %U",
101                     sep->sw_if_index, format_ip46_address, &sep->ip,
102                     sep->is_ip4);
103       return 0;
104     }
105   return (is_zero || ip_is_local (sep->fib_index, &sep->ip, sep->is_ip4));
106 }
107
108 int
109 api_parse_session_handle (u64 handle, u32 * session_index, u32 * thread_index)
110 {
111   session_manager_main_t *smm = vnet_get_session_manager_main ();
112   stream_session_t *pool;
113
114   *thread_index = handle & 0xFFFFFFFF;
115   *session_index = handle >> 32;
116
117   if (*thread_index >= vec_len (smm->sessions))
118     return VNET_API_ERROR_INVALID_VALUE;
119
120   pool = smm->sessions[*thread_index];
121
122   if (pool_is_free_index (pool, *session_index))
123     return VNET_API_ERROR_INVALID_VALUE_2;
124
125   return 0;
126 }
127
128 static void
129 session_endpoint_update_for_app (session_endpoint_t * sep,
130                                  application_t * app)
131 {
132   app_namespace_t *app_ns;
133   app_ns = app_namespace_get (app->ns_index);
134   if (app_ns)
135     {
136       /* Ask transport and network to bind to/connect using local interface
137        * that "supports" app's namespace. This will fix our local connection
138        * endpoint.
139        */
140       sep->sw_if_index = app_ns->sw_if_index;
141       sep->fib_index =
142         sep->is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
143     }
144 }
145
146 static int
147 vnet_bind_i (u32 app_index, session_endpoint_t * sep, u64 * handle)
148 {
149   u64 lh, ll_handle = SESSION_INVALID_HANDLE;
150   application_t *app;
151   u32 table_index;
152   int rv;
153
154   app = application_get_if_valid (app_index);
155   if (!app)
156     {
157       SESSION_DBG ("app not attached");
158       return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
159     }
160
161   session_endpoint_update_for_app (sep, app);
162   if (!session_endpoint_in_ns (sep))
163     return VNET_API_ERROR_INVALID_VALUE_2;
164
165   table_index = application_session_table (app,
166                                            session_endpoint_fib_proto (sep));
167   lh = session_lookup_endpoint_listener (table_index, sep, 1);
168   if (lh != SESSION_INVALID_HANDLE)
169     return VNET_API_ERROR_ADDRESS_IN_USE;
170
171   /*
172    * Add session endpoint to local session table. Only binds to "inaddr_any"
173    * (i.e., zero address) are added to local scope table.
174    */
175   if (application_has_local_scope (app) && session_endpoint_is_zero (sep))
176     {
177       if ((rv = application_start_local_listen (app, sep, handle)))
178         return rv;
179       ll_handle = *handle;
180     }
181
182   if (!application_has_global_scope (app))
183     return (ll_handle == SESSION_INVALID_HANDLE ? -1 : 0);
184
185   /*
186    * Add session endpoint to global session table
187    */
188
189   /* Setup listen path down to transport */
190   rv = application_start_listen (app, sep, handle);
191   if (rv && ll_handle != SESSION_INVALID_HANDLE)
192     session_lookup_del_session_endpoint (table_index, sep);
193
194   /*
195    * Store in local table listener the index of the transport layer
196    * listener. We'll need local listeners are hit and we need to
197    * return global handle
198    */
199   if (ll_handle != SESSION_INVALID_HANDLE)
200     {
201       local_session_t *ll;
202       stream_session_t *tl;
203       ll = application_get_local_listener_w_handle (ll_handle);
204       tl = listen_session_get_from_handle (*handle);
205       ll->transport_listener_index = tl->session_index;
206     }
207   return rv;
208 }
209
210 int
211 vnet_unbind_i (u32 app_index, session_handle_t handle)
212 {
213   application_t *app;
214   int rv;
215
216   if (!(app = application_get_if_valid (app_index)))
217     {
218       SESSION_DBG ("app (%d) not attached", app_index);
219       return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
220     }
221
222   if (application_has_local_scope (app))
223     {
224       if ((rv = application_stop_local_listen (app, handle)))
225         return rv;
226     }
227
228   /*
229    * Clear the global scope table of the listener
230    */
231   if (application_has_global_scope (app))
232     return application_stop_listen (app, handle);
233   return 0;
234 }
235
236 int
237 application_connect (u32 client_index, u32 api_context,
238                      session_endpoint_t * sep)
239 {
240   application_t *server, *client;
241   u32 table_index, server_index, li;
242   stream_session_t *listener;
243   local_session_t *ll;
244   u64 lh;
245
246   if (session_endpoint_is_zero (sep))
247     return VNET_API_ERROR_INVALID_VALUE;
248
249   client = application_get (client_index);
250   session_endpoint_update_for_app (sep, client);
251
252   /*
253    * First check the local scope for locally attached destinations.
254    * If we have local scope, we pass *all* connects through it since we may
255    * have special policy rules even for non-local destinations, think proxy.
256    */
257   if (application_has_local_scope (client))
258     {
259       table_index = application_local_session_table (client);
260       lh = session_lookup_local_endpoint (table_index, sep);
261       if (lh == SESSION_DROP_HANDLE)
262         return VNET_API_ERROR_APP_CONNECT_FILTERED;
263
264       if (lh == SESSION_INVALID_HANDLE)
265         goto global_scope;
266
267       local_session_parse_handle (lh, &server_index, &li);
268
269       /*
270        * Break loop if rule in local table points to connecting app. This
271        * can happen if client is a generic proxy. Route connect through
272        * global table instead.
273        */
274       if (server_index != client_index)
275         {
276           server = application_get (server_index);
277           ll = application_get_local_listen_session (server, li);
278           return application_local_session_connect (table_index, client,
279                                                     server, ll, api_context);
280         }
281     }
282
283   /*
284    * If nothing found, check the global scope for locally attached
285    * destinations. Make sure first that we're allowed to.
286    */
287
288 global_scope:
289   if (session_endpoint_is_local (sep))
290     return VNET_API_ERROR_SESSION_CONNECT;
291
292   if (!application_has_global_scope (client))
293     return VNET_API_ERROR_APP_CONNECT_SCOPE;
294
295   table_index = application_session_table (client,
296                                            session_endpoint_fib_proto (sep));
297   listener = session_lookup_listener (table_index, sep);
298   if (listener)
299     {
300       server = application_get (listener->app_index);
301       if (server)
302         return application_local_session_connect (table_index, client, server,
303                                                   (local_session_t *)
304                                                   listener, api_context);
305     }
306
307   /*
308    * Not connecting to a local server, propagate to transport
309    */
310   if (application_open_session (client, sep, api_context))
311     return VNET_API_ERROR_SESSION_CONNECT;
312   return 0;
313 }
314
315 /**
316  * unformat a vnet URI
317  *
318  * transport-proto://ip46-addr:port
319  * eg. tcp://ip46-addr:port
320  *
321  * u8 ip46_address[16];
322  * u16  port_in_host_byte_order;
323  * stream_session_type_t sst;
324  * u8 *fifo_name;
325  *
326  * if (unformat (input, "%U", unformat_vnet_uri, &ip46_address,
327  *              &sst, &port, &fifo_name))
328  *  etc...
329  *
330  */
331 uword
332 unformat_vnet_uri (unformat_input_t * input, va_list * args)
333 {
334   session_endpoint_t *sep = va_arg (*args, session_endpoint_t *);
335   u32 transport_proto = 0, port;
336
337   if (unformat
338       (input, "%U://%U/%d", unformat_transport_proto, &transport_proto,
339        unformat_ip4_address, &sep->ip.ip4, &port))
340     {
341       sep->transport_proto = transport_proto;
342       sep->port = clib_host_to_net_u16 (port);
343       sep->is_ip4 = 1;
344       return 1;
345     }
346   else if (unformat (input, "%U://%U/%d", unformat_transport_proto,
347                      &transport_proto, unformat_ip6_address, &sep->ip.ip6,
348                      &port))
349     {
350       sep->transport_proto = transport_proto;
351       sep->port = clib_host_to_net_u16 (port);
352       sep->is_ip4 = 0;
353       return 1;
354     }
355   return 0;
356 }
357
358 static u8 *cache_uri;
359 static session_endpoint_t *cache_sep;
360
361 int
362 parse_uri (char *uri, session_endpoint_t * sep)
363 {
364   unformat_input_t _input, *input = &_input;
365
366   if (cache_uri && !strncmp (uri, (char *) cache_uri, vec_len (cache_uri)))
367     {
368       *sep = *cache_sep;
369       return 0;
370     }
371
372   /* Make sure */
373   uri = (char *) format (0, "%s%c", uri, 0);
374
375   /* Parse uri */
376   unformat_init_string (input, uri, strlen (uri));
377   if (!unformat (input, "%U", unformat_vnet_uri, sep))
378     {
379       unformat_free (input);
380       return VNET_API_ERROR_INVALID_VALUE;
381     }
382   unformat_free (input);
383
384   vec_free (cache_uri);
385   cache_uri = (u8 *) uri;
386   if (cache_sep)
387     clib_mem_free (cache_sep);
388   cache_sep = clib_mem_alloc (sizeof (*sep));
389   *cache_sep = *sep;
390
391   return 0;
392 }
393
394 static int
395 session_validate_namespace (u8 * namespace_id, u64 secret, u32 * app_ns_index)
396 {
397   app_namespace_t *app_ns;
398   if (vec_len (namespace_id) == 0)
399     {
400       /* Use default namespace */
401       *app_ns_index = 0;
402       return 0;
403     }
404
405   *app_ns_index = app_namespace_index_from_id (namespace_id);
406   if (*app_ns_index == APP_NAMESPACE_INVALID_INDEX)
407     return VNET_API_ERROR_APP_INVALID_NS;
408   app_ns = app_namespace_get (*app_ns_index);
409   if (!app_ns)
410     return VNET_API_ERROR_APP_INVALID_NS;
411   if (app_ns->ns_secret != secret)
412     return VNET_API_ERROR_APP_WRONG_NS_SECRET;
413   return 0;
414 }
415
416 /**
417  * Attach application to vpp
418  *
419  * Allocates a vpp app, i.e., a structure that keeps back pointers
420  * to external app and a segment manager for shared memory fifo based
421  * communication with the external app.
422  */
423 clib_error_t *
424 vnet_application_attach (vnet_app_attach_args_t * a)
425 {
426   svm_fifo_segment_private_t *fs;
427   application_t *app = 0;
428   segment_manager_t *sm;
429   u32 app_ns_index = 0;
430   u64 secret;
431   int rv;
432
433   app = application_lookup (a->api_client_index);
434   if (app)
435     return clib_error_return_code (0, VNET_API_ERROR_APP_ALREADY_ATTACHED,
436                                    0, "app already attached");
437
438   secret = a->options[APP_OPTIONS_NAMESPACE_SECRET];
439   if ((rv = session_validate_namespace (a->namespace_id, secret,
440                                         &app_ns_index)))
441     return clib_error_return_code (0, rv, 0, "namespace validation: %d", rv);
442   a->options[APP_OPTIONS_NAMESPACE] = app_ns_index;
443   app = application_new ();
444   if ((rv = application_init (app, a->api_client_index, a->options,
445                               a->session_cb_vft)))
446     return clib_error_return_code (0, rv, 0, "app init: %d", rv);
447
448   a->app_event_queue_address = pointer_to_uword (app->event_queue);
449   sm = segment_manager_get (app->first_segment_manager);
450   fs = segment_manager_get_segment_w_lock (sm, 0);
451
452   if (application_is_proxy (app))
453     application_setup_proxy (app);
454
455   ASSERT (vec_len (fs->ssvm.name) <= 128);
456   a->segment = &fs->ssvm;
457   a->app_index = app->index;
458
459   segment_manager_segment_reader_unlock (sm);
460
461   return 0;
462 }
463
464 /**
465  * Detach application from vpp
466  */
467 int
468 vnet_application_detach (vnet_app_detach_args_t * a)
469 {
470   application_t *app;
471   app = application_get_if_valid (a->app_index);
472
473   if (!app)
474     {
475       clib_warning ("app not attached");
476       return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
477     }
478
479   application_del (app);
480   return 0;
481 }
482
483 int
484 vnet_bind_uri (vnet_bind_args_t * a)
485 {
486   session_endpoint_t sep = SESSION_ENDPOINT_NULL;
487   int rv;
488
489   rv = parse_uri (a->uri, &sep);
490   if (rv)
491     return rv;
492
493   return vnet_bind_i (a->app_index, &sep, &a->handle);
494 }
495
496 int
497 vnet_unbind_uri (vnet_unbind_args_t * a)
498 {
499   session_endpoint_t sep = SESSION_ENDPOINT_NULL;
500   stream_session_t *listener;
501   int rv;
502
503   rv = parse_uri (a->uri, &sep);
504   if (rv)
505     return rv;
506
507   /* NOTE: only default table supported for uri */
508   listener = session_lookup_listener (0, &sep);
509   if (!listener)
510     return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
511
512   return vnet_unbind_i (a->app_index, listen_session_get_handle (listener));
513 }
514
515 clib_error_t *
516 vnet_connect_uri (vnet_connect_args_t * a)
517 {
518   session_endpoint_t sep = SESSION_ENDPOINT_NULL;
519   int rv;
520
521   /* Parse uri */
522   rv = parse_uri (a->uri, &sep);
523   if (rv)
524     return clib_error_return_code (0, rv, 0, "app init: %d", rv);
525
526   if ((rv = application_connect (a->app_index, a->api_context, &sep)))
527     return clib_error_return_code (0, rv, 0, "connect failed");
528   return 0;
529 }
530
531 int
532 vnet_disconnect_session (vnet_disconnect_args_t * a)
533 {
534   if (session_handle_is_local (a->handle))
535     {
536       local_session_t *ls;
537       ls = application_get_local_session_from_handle (a->handle);
538       if (ls->app_index != a->app_index && ls->client_index != a->app_index)
539         {
540           clib_warning ("app %u is neither client nor server for session %u",
541                         a->app_index, a->app_index);
542           return VNET_API_ERROR_INVALID_VALUE;
543         }
544       return application_local_session_disconnect (a->app_index, ls);
545     }
546   else
547     {
548       stream_session_t *s;
549       s = session_get_from_handle_if_valid (a->handle);
550       if (!s || s->app_index != a->app_index)
551         return VNET_API_ERROR_INVALID_VALUE;
552
553       /* We're peeking into another's thread pool. Make sure */
554       ASSERT (s->session_index == session_index_from_handle (a->handle));
555
556       stream_session_disconnect (s);
557     }
558   return 0;
559 }
560
561 clib_error_t *
562 vnet_bind (vnet_bind_args_t * a)
563 {
564   int rv;
565   if ((rv = vnet_bind_i (a->app_index, &a->sep, &a->handle)))
566     return clib_error_return_code (0, rv, 0, "bind failed");
567   return 0;
568 }
569
570 clib_error_t *
571 vnet_unbind (vnet_unbind_args_t * a)
572 {
573   int rv;
574   if ((rv = vnet_unbind_i (a->app_index, a->handle)))
575     return clib_error_return_code (0, rv, 0, "unbind failed");
576   return 0;
577 }
578
579 clib_error_t *
580 vnet_connect (vnet_connect_args_t * a)
581 {
582   session_endpoint_t *sep = &a->sep;
583   int rv;
584
585   if ((rv = application_connect (a->app_index, a->api_context, sep)))
586     return clib_error_return_code (0, rv, 0, "connect failed");
587   return 0;
588 }
589
590 /*
591  * fd.io coding-style-patch-verification: ON
592  *
593  * Local Variables:
594  * eval: (c-set-style "gnu")
595  * End:
596  */