Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 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> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 20 | |
| 21 | /** @file |
| 22 | VPP's application/session API bind/unbind/connect/disconnect calls |
| 23 | */ |
| 24 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 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 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 80 | static u8 |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 81 | session_endpoint_is_local (session_endpoint_t * sep) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 82 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 83 | return (ip_is_zero (&sep->ip, sep->is_ip4) |
| 84 | || ip_is_local_host (&sep->ip, sep->is_ip4)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static u8 |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 88 | session_endpoint_is_zero (session_endpoint_t * sep) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 89 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 90 | return ip_is_zero (&sep->ip, sep->is_ip4); |
| 91 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 92 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 99 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 104 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 105 | return (is_zero || ip_is_local (sep->fib_index, &sep->ip, sep->is_ip4)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 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 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 148 | { |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 149 | u64 lh, ll_handle = SESSION_INVALID_HANDLE; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 150 | application_t *app; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 151 | u32 table_index; |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 152 | int rv; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 153 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 154 | app = application_get_if_valid (app_index); |
| 155 | if (!app) |
| 156 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 157 | SESSION_DBG ("app not attached"); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 158 | return VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 159 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 160 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 161 | session_endpoint_update_for_app (sep, app); |
| 162 | if (!session_endpoint_in_ns (sep)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 163 | return VNET_API_ERROR_INVALID_VALUE_2; |
| 164 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 165 | table_index = application_session_table (app, |
| 166 | session_endpoint_fib_proto (sep)); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 167 | lh = session_lookup_endpoint_listener (table_index, sep, 1); |
| 168 | if (lh != SESSION_INVALID_HANDLE) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 177 | if ((rv = application_start_local_listen (app, sep, handle))) |
| 178 | return rv; |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 179 | ll_handle = *handle; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | if (!application_has_global_scope (app)) |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 183 | return (ll_handle == SESSION_INVALID_HANDLE ? -1 : 0); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * Add session endpoint to global session table |
| 187 | */ |
| 188 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 189 | /* Setup listen path down to transport */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 190 | rv = application_start_listen (app, sep, handle); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 191 | if (rv && ll_handle != SESSION_INVALID_HANDLE) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 192 | session_lookup_del_session_endpoint (table_index, sep); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 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 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 207 | return rv; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | int |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 211 | vnet_unbind_i (u32 app_index, session_handle_t handle) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 212 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 213 | application_t *app; |
| 214 | int rv; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 215 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 216 | if (!(app = application_get_if_valid (app_index))) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 217 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 218 | SESSION_DBG ("app (%d) not attached", app_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 219 | return VNET_API_ERROR_APPLICATION_NOT_ATTACHED; |
| 220 | } |
| 221 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 222 | if (application_has_local_scope (app)) |
| 223 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 224 | if ((rv = application_stop_local_listen (app, handle))) |
| 225 | return rv; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 236 | int |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 237 | application_connect (u32 client_index, u32 api_context, |
| 238 | session_endpoint_t * sep) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 239 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 240 | application_t *server, *client; |
| 241 | u32 table_index, server_index, li; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 242 | stream_session_t *listener; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 243 | local_session_t *ll; |
| 244 | u64 lh; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 245 | |
| 246 | if (session_endpoint_is_zero (sep)) |
| 247 | return VNET_API_ERROR_INVALID_VALUE; |
| 248 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 249 | client = application_get (client_index); |
| 250 | session_endpoint_update_for_app (sep, client); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 251 | |
| 252 | /* |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 253 | * First check the local scope for locally attached destinations. |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 256 | */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 257 | if (application_has_local_scope (client)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 258 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 259 | table_index = application_local_session_table (client); |
| 260 | lh = session_lookup_local_endpoint (table_index, sep); |
| 261 | if (lh == SESSION_DROP_HANDLE) |
Florin Coras | a2ff7b8 | 2017-11-08 17:55:03 -0800 | [diff] [blame] | 262 | return VNET_API_ERROR_APP_CONNECT_FILTERED; |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 263 | |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 264 | if (lh == SESSION_INVALID_HANDLE) |
| 265 | goto global_scope; |
| 266 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 267 | local_session_parse_handle (lh, &server_index, &li); |
| 268 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 269 | /* |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 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. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 273 | */ |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 274 | if (server_index != client_index) |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 275 | { |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 276 | server = application_get (server_index); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 277 | ll = application_get_local_listen_session (server, li); |
| 278 | return application_local_session_connect (table_index, client, |
| 279 | server, ll, api_context); |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 280 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 281 | } |
| 282 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 283 | /* |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 284 | * If nothing found, check the global scope for locally attached |
| 285 | * destinations. Make sure first that we're allowed to. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 286 | */ |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 287 | |
| 288 | global_scope: |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 289 | if (session_endpoint_is_local (sep)) |
| 290 | return VNET_API_ERROR_SESSION_CONNECT; |
| 291 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 292 | if (!application_has_global_scope (client)) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 293 | return VNET_API_ERROR_APP_CONNECT_SCOPE; |
| 294 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 295 | table_index = application_session_table (client, |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 296 | session_endpoint_fib_proto (sep)); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 297 | listener = session_lookup_listener (table_index, sep); |
| 298 | if (listener) |
| 299 | { |
| 300 | server = application_get (listener->app_index); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 301 | if (server) |
| 302 | return application_local_session_connect (table_index, client, server, |
| 303 | (local_session_t *) |
| 304 | listener, api_context); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 305 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 306 | |
| 307 | /* |
| 308 | * Not connecting to a local server, propagate to transport |
| 309 | */ |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 310 | if (application_open_session (client, sep, api_context)) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 311 | return VNET_API_ERROR_SESSION_CONNECT; |
| 312 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /** |
| 316 | * unformat a vnet URI |
| 317 | * |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 318 | * transport-proto://ip46-addr:port |
| 319 | * eg. tcp://ip46-addr:port |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 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 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 334 | session_endpoint_t *sep = va_arg (*args, session_endpoint_t *); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 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)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 340 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 341 | sep->transport_proto = transport_proto; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 342 | sep->port = clib_host_to_net_u16 (port); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 343 | sep->is_ip4 = 1; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 344 | return 1; |
| 345 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 346 | else if (unformat (input, "%U://%U/%d", unformat_transport_proto, |
| 347 | &transport_proto, unformat_ip6_address, &sep->ip.ip6, |
| 348 | &port)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 349 | { |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 350 | sep->transport_proto = transport_proto; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 351 | sep->port = clib_host_to_net_u16 (port); |
Marco Varlese | 191a594 | 2017-10-30 18:17:21 +0100 | [diff] [blame] | 352 | sep->is_ip4 = 0; |
| 353 | return 1; |
| 354 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 355 | return 0; |
| 356 | } |
| 357 | |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 358 | static u8 *cache_uri; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 359 | static session_endpoint_t *cache_sep; |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 360 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 361 | int |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 362 | parse_uri (char *uri, session_endpoint_t * sep) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 363 | { |
| 364 | unformat_input_t _input, *input = &_input; |
| 365 | |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 366 | if (cache_uri && !strncmp (uri, (char *) cache_uri, vec_len (cache_uri))) |
| 367 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 368 | *sep = *cache_sep; |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 372 | /* Make sure */ |
| 373 | uri = (char *) format (0, "%s%c", uri, 0); |
| 374 | |
| 375 | /* Parse uri */ |
| 376 | unformat_init_string (input, uri, strlen (uri)); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 377 | if (!unformat (input, "%U", unformat_vnet_uri, sep)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 378 | { |
| 379 | unformat_free (input); |
| 380 | return VNET_API_ERROR_INVALID_VALUE; |
| 381 | } |
| 382 | unformat_free (input); |
| 383 | |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 384 | vec_free (cache_uri); |
| 385 | cache_uri = (u8 *) uri; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 386 | if (cache_sep) |
| 387 | clib_mem_free (cache_sep); |
| 388 | cache_sep = clib_mem_alloc (sizeof (*sep)); |
| 389 | *cache_sep = *sep; |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 390 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 391 | return 0; |
| 392 | } |
| 393 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 416 | /** |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 417 | * Attach application to vpp |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 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 | */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 423 | clib_error_t * |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 424 | vnet_application_attach (vnet_app_attach_args_t * a) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 425 | { |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 426 | svm_fifo_segment_private_t *fs; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 427 | application_t *app = 0; |
| 428 | segment_manager_t *sm; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 429 | u32 app_ns_index = 0; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 430 | u64 secret; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 431 | int rv; |
| 432 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 443 | app = application_new (); |
| 444 | if ((rv = application_init (app, a->api_client_index, a->options, |
| 445 | a->session_cb_vft))) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 446 | return clib_error_return_code (0, rv, 0, "app init: %d", rv); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 447 | |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 448 | a->app_event_queue_address = pointer_to_uword (app->event_queue); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 449 | sm = segment_manager_get (app->first_segment_manager); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 450 | fs = segment_manager_get_segment_w_lock (sm, 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 451 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 452 | if (application_is_proxy (app)) |
| 453 | application_setup_proxy (app); |
| 454 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 455 | ASSERT (vec_len (fs->ssvm.name) <= 128); |
| 456 | a->segment = &fs->ssvm; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 457 | a->app_index = app->index; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 458 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 459 | segment_manager_segment_reader_unlock (sm); |
| 460 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 461 | return 0; |
| 462 | } |
| 463 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 464 | /** |
| 465 | * Detach application from vpp |
| 466 | */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 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); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 480 | return 0; |
| 481 | } |
| 482 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 483 | int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 484 | vnet_bind_uri (vnet_bind_args_t * a) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 485 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 486 | session_endpoint_t sep = SESSION_ENDPOINT_NULL; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 487 | int rv; |
| 488 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 489 | rv = parse_uri (a->uri, &sep); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 490 | if (rv) |
| 491 | return rv; |
| 492 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 493 | return vnet_bind_i (a->app_index, &sep, &a->handle); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | int |
| 497 | vnet_unbind_uri (vnet_unbind_args_t * a) |
| 498 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 499 | session_endpoint_t sep = SESSION_ENDPOINT_NULL; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 500 | stream_session_t *listener; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 501 | int rv; |
| 502 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 503 | rv = parse_uri (a->uri, &sep); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 504 | if (rv) |
| 505 | return rv; |
| 506 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 507 | /* NOTE: only default table supported for uri */ |
| 508 | listener = session_lookup_listener (0, &sep); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 509 | if (!listener) |
| 510 | return VNET_API_ERROR_ADDRESS_NOT_IN_USE; |
| 511 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 512 | return vnet_unbind_i (a->app_index, listen_session_get_handle (listener)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 515 | clib_error_t * |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 516 | vnet_connect_uri (vnet_connect_args_t * a) |
| 517 | { |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 518 | session_endpoint_t sep = SESSION_ENDPOINT_NULL; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 519 | int rv; |
| 520 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 521 | /* Parse uri */ |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 522 | rv = parse_uri (a->uri, &sep); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 523 | if (rv) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 524 | return clib_error_return_code (0, rv, 0, "app init: %d", rv); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 525 | |
| 526 | if ((rv = application_connect (a->app_index, a->api_context, &sep))) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 527 | return clib_error_return_code (0, rv, 0, "connect failed"); |
| 528 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | int |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 532 | vnet_disconnect_session (vnet_disconnect_args_t * a) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 533 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 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; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 552 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 553 | /* We're peeking into another's thread pool. Make sure */ |
| 554 | ASSERT (s->session_index == session_index_from_handle (a->handle)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 555 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 556 | stream_session_disconnect (s); |
| 557 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 561 | clib_error_t * |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 562 | vnet_bind (vnet_bind_args_t * a) |
| 563 | { |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 564 | int rv; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 565 | if ((rv = vnet_bind_i (a->app_index, &a->sep, &a->handle))) |
| 566 | return clib_error_return_code (0, rv, 0, "bind failed"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 570 | clib_error_t * |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 571 | vnet_unbind (vnet_unbind_args_t * a) |
| 572 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 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; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 577 | } |
| 578 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 579 | clib_error_t * |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 580 | vnet_connect (vnet_connect_args_t * a) |
| 581 | { |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 582 | session_endpoint_t *sep = &a->sep; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 583 | int rv; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame^] | 584 | |
| 585 | if ((rv = application_connect (a->app_index, a->api_context, sep))) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 586 | return clib_error_return_code (0, rv, 0, "connect failed"); |
| 587 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 588 | } |
| 589 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 590 | /* |
| 591 | * fd.io coding-style-patch-verification: ON |
| 592 | * |
| 593 | * Local Variables: |
| 594 | * eval: (c-set-style "gnu") |
| 595 | * End: |
| 596 | */ |