Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1 | /* |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this |
| 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 <stdio.h> |
| 17 | #include <stdlib.h> |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 18 | #include <svm/svm_fifo_segment.h> |
Dave Wallace | 5c7cf1c | 2017-10-24 04:12:18 -0400 | [diff] [blame] | 19 | #include <vcl/vppcom.h> |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 20 | #include <vcl/vcl_event.h> |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 21 | #include <vcl/vcl_debug.h> |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 22 | #include <vcl/vcl_private.h> |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 23 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 24 | static const char * |
| 25 | vppcom_app_state_str (app_state_t state) |
| 26 | { |
| 27 | char *st; |
| 28 | |
| 29 | switch (state) |
| 30 | { |
| 31 | case STATE_APP_START: |
| 32 | st = "STATE_APP_START"; |
| 33 | break; |
| 34 | |
| 35 | case STATE_APP_CONN_VPP: |
| 36 | st = "STATE_APP_CONN_VPP"; |
| 37 | break; |
| 38 | |
| 39 | case STATE_APP_ENABLED: |
| 40 | st = "STATE_APP_ENABLED"; |
| 41 | break; |
| 42 | |
| 43 | case STATE_APP_ATTACHED: |
| 44 | st = "STATE_APP_ATTACHED"; |
| 45 | break; |
| 46 | |
| 47 | default: |
| 48 | st = "UNKNOWN_APP_STATE"; |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | return st; |
| 53 | } |
| 54 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 55 | const char * |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 56 | vppcom_session_state_str (session_state_t state) |
| 57 | { |
| 58 | char *st; |
| 59 | |
| 60 | switch (state) |
| 61 | { |
| 62 | case STATE_START: |
| 63 | st = "STATE_START"; |
| 64 | break; |
| 65 | |
| 66 | case STATE_CONNECT: |
| 67 | st = "STATE_CONNECT"; |
| 68 | break; |
| 69 | |
| 70 | case STATE_LISTEN: |
| 71 | st = "STATE_LISTEN"; |
| 72 | break; |
| 73 | |
| 74 | case STATE_ACCEPT: |
| 75 | st = "STATE_ACCEPT"; |
| 76 | break; |
| 77 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 78 | case STATE_CLOSE_ON_EMPTY: |
| 79 | st = "STATE_CLOSE_ON_EMPTY"; |
| 80 | break; |
| 81 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 82 | case STATE_DISCONNECT: |
| 83 | st = "STATE_DISCONNECT"; |
| 84 | break; |
| 85 | |
| 86 | case STATE_FAILED: |
| 87 | st = "STATE_FAILED"; |
| 88 | break; |
| 89 | |
| 90 | default: |
| 91 | st = "UNKNOWN_STATE"; |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | return st; |
| 96 | } |
| 97 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 98 | u8 * |
| 99 | format_ip4_address (u8 * s, va_list * args) |
| 100 | { |
| 101 | u8 *a = va_arg (*args, u8 *); |
| 102 | return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); |
| 103 | } |
| 104 | |
| 105 | u8 * |
| 106 | format_ip6_address (u8 * s, va_list * args) |
| 107 | { |
| 108 | ip6_address_t *a = va_arg (*args, ip6_address_t *); |
| 109 | u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon; |
| 110 | |
| 111 | i_max_n_zero = ARRAY_LEN (a->as_u16); |
| 112 | max_n_zeros = 0; |
| 113 | i_first_zero = i_max_n_zero; |
| 114 | n_zeros = 0; |
| 115 | for (i = 0; i < ARRAY_LEN (a->as_u16); i++) |
| 116 | { |
| 117 | u32 is_zero = a->as_u16[i] == 0; |
| 118 | if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16)) |
| 119 | { |
| 120 | i_first_zero = i; |
| 121 | n_zeros = 0; |
| 122 | } |
| 123 | n_zeros += is_zero; |
| 124 | if ((!is_zero && n_zeros > max_n_zeros) |
| 125 | || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros)) |
| 126 | { |
| 127 | i_max_n_zero = i_first_zero; |
| 128 | max_n_zeros = n_zeros; |
| 129 | i_first_zero = ARRAY_LEN (a->as_u16); |
| 130 | n_zeros = 0; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | last_double_colon = 0; |
| 135 | for (i = 0; i < ARRAY_LEN (a->as_u16); i++) |
| 136 | { |
| 137 | if (i == i_max_n_zero && max_n_zeros > 1) |
| 138 | { |
| 139 | s = format (s, "::"); |
| 140 | i += max_n_zeros - 1; |
| 141 | last_double_colon = 1; |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | s = format (s, "%s%x", |
| 146 | (last_double_colon || i == 0) ? "" : ":", |
| 147 | clib_net_to_host_u16 (a->as_u16[i])); |
| 148 | last_double_colon = 0; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return s; |
| 153 | } |
| 154 | |
| 155 | /* Format an IP46 address. */ |
| 156 | u8 * |
| 157 | format_ip46_address (u8 * s, va_list * args) |
| 158 | { |
| 159 | ip46_address_t *ip46 = va_arg (*args, ip46_address_t *); |
| 160 | ip46_type_t type = va_arg (*args, ip46_type_t); |
| 161 | int is_ip4 = 1; |
| 162 | |
| 163 | switch (type) |
| 164 | { |
| 165 | case IP46_TYPE_ANY: |
| 166 | is_ip4 = ip46_address_is_ip4 (ip46); |
| 167 | break; |
| 168 | case IP46_TYPE_IP4: |
| 169 | is_ip4 = 1; |
| 170 | break; |
| 171 | case IP46_TYPE_IP6: |
| 172 | is_ip4 = 0; |
| 173 | break; |
| 174 | } |
| 175 | |
| 176 | return is_ip4 ? |
| 177 | format (s, "%U", format_ip4_address, &ip46->ip4) : |
| 178 | format (s, "%U", format_ip6_address, &ip46->ip6); |
| 179 | } |
| 180 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 181 | /* |
| 182 | * VPPCOM Utility Functions |
| 183 | */ |
| 184 | |
| 185 | static inline void |
| 186 | vppcom_session_table_del_listener (u64 listener_handle) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 187 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 188 | listener_handle |= 1ULL << 63; |
| 189 | hash_unset (vcm->session_index_by_vpp_handles, listener_handle); |
| 190 | } |
| 191 | |
| 192 | static inline int |
| 193 | vppcom_wait_for_app_state_change (app_state_t app_state) |
| 194 | { |
| 195 | f64 timeout = clib_time_now (&vcm->clib_time) + vcm->cfg.app_timeout; |
| 196 | |
| 197 | while (clib_time_now (&vcm->clib_time) < timeout) |
| 198 | { |
| 199 | if (vcm->app_state == app_state) |
| 200 | return VPPCOM_OK; |
| 201 | } |
| 202 | VDBG (0, "VCL<%d>: timeout waiting for state %s (%d)", getpid (), |
| 203 | vppcom_app_state_str (app_state), app_state); |
| 204 | vcl_evt (VCL_EVT_SESSION_TIMEOUT, vcm, app_state); |
| 205 | |
| 206 | return VPPCOM_ETIMEDOUT; |
| 207 | } |
| 208 | |
| 209 | static inline int |
| 210 | vppcom_wait_for_session_state_change (u32 session_index, |
| 211 | session_state_t state, |
| 212 | f64 wait_for_time) |
| 213 | { |
| 214 | f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time; |
| 215 | vcl_session_t *volatile session; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 216 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 217 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 218 | do |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 219 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 220 | VCL_SESSION_LOCK (); |
| 221 | rv = vppcom_session_at_index (session_index, &session); |
| 222 | if (PREDICT_FALSE (rv)) |
| 223 | { |
| 224 | VCL_SESSION_UNLOCK (); |
| 225 | return rv; |
| 226 | } |
| 227 | if (session->session_state & state) |
| 228 | { |
| 229 | VCL_SESSION_UNLOCK (); |
| 230 | return VPPCOM_OK; |
| 231 | } |
| 232 | if (session->session_state & STATE_FAILED) |
| 233 | { |
| 234 | VCL_SESSION_UNLOCK (); |
| 235 | return VPPCOM_ECONNREFUSED; |
| 236 | } |
| 237 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 238 | VCL_SESSION_UNLOCK (); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 239 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 240 | while (clib_time_now (&vcm->clib_time) < timeout); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 241 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 242 | VDBG (0, "VCL<%d>: timeout waiting for state 0x%x (%s)", getpid (), state, |
| 243 | vppcom_session_state_str (state)); |
| 244 | vcl_evt (VCL_EVT_SESSION_TIMEOUT, session, session_state); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 245 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 246 | return VPPCOM_ETIMEDOUT; |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 247 | } |
| 248 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 249 | static int |
| 250 | vppcom_app_session_enable (void) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 251 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 252 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 253 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 254 | if (vcm->app_state != STATE_APP_ENABLED) |
| 255 | { |
| 256 | vppcom_send_session_enable_disable (1 /* is_enabled == TRUE */ ); |
| 257 | rv = vppcom_wait_for_app_state_change (STATE_APP_ENABLED); |
| 258 | if (PREDICT_FALSE (rv)) |
| 259 | { |
| 260 | VDBG (0, "VCL<%d>: application session enable timed out! " |
| 261 | "returning %d (%s)", getpid (), rv, vppcom_retval_str (rv)); |
| 262 | return rv; |
| 263 | } |
| 264 | } |
| 265 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 266 | } |
| 267 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 268 | static int |
| 269 | vppcom_app_attach (void) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 270 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 271 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 272 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 273 | vppcom_app_send_attach (); |
| 274 | rv = vppcom_wait_for_app_state_change (STATE_APP_ATTACHED); |
| 275 | if (PREDICT_FALSE (rv)) |
| 276 | { |
| 277 | VDBG (0, "VCL<%d>: application attach timed out! returning %d (%s)", |
| 278 | getpid (), rv, vppcom_retval_str (rv)); |
| 279 | return rv; |
| 280 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 281 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 282 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static int |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 286 | vppcom_session_unbind (u32 session_index) |
| 287 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 288 | vcl_session_t *session = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 289 | int rv; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 290 | u64 vpp_handle; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 291 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 292 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 293 | |
| 294 | vpp_handle = session->vpp_handle; |
| 295 | vppcom_session_table_del_listener (vpp_handle); |
| 296 | session->vpp_handle = ~0; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 297 | session->session_state = STATE_DISCONNECT; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 298 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 299 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 300 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 301 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending unbind msg! new state" |
| 302 | " 0x%x (%s)", getpid (), vpp_handle, session_index, STATE_DISCONNECT, |
| 303 | vppcom_session_state_str (STATE_DISCONNECT)); |
| 304 | vcl_evt (VCL_EVT_UNBIND, session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 305 | vppcom_send_unbind_sock (vpp_handle); |
| 306 | |
| 307 | done: |
| 308 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 309 | } |
| 310 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 311 | static int |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 312 | vppcom_session_disconnect (u32 session_index) |
| 313 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 314 | int rv; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 315 | vcl_session_t *session; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 316 | u64 vpp_handle; |
| 317 | session_state_t state; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 318 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 319 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 320 | |
| 321 | vpp_handle = session->vpp_handle; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 322 | state = session->session_state; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 323 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 324 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 325 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u state 0x%x (%s)", getpid (), |
| 326 | vpp_handle, session_index, state, vppcom_session_state_str (state)); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 327 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 328 | if (PREDICT_FALSE (state & STATE_LISTEN)) |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 329 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 330 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 331 | "Cannot disconnect a listen socket!", |
| 332 | getpid (), vpp_handle, session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 333 | rv = VPPCOM_EBADFD; |
| 334 | goto done; |
| 335 | } |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 336 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 337 | /* The peer has already initiated the close, |
| 338 | * so send the disconnect session reply. |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 339 | */ |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 340 | if (state & STATE_CLOSE_ON_EMPTY) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 341 | { |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 342 | //XXX alagalah - Check and drain here? |
| 343 | vppcom_send_disconnect_session_reply (vpp_handle, |
| 344 | session_index, 0 /* rv */ ); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 345 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect " |
| 346 | "REPLY...", getpid (), vpp_handle, session_index); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 347 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 348 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 349 | /* Otherwise, send a disconnect session msg... |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 350 | */ |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 351 | else |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 352 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 353 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect...", |
| 354 | getpid (), vpp_handle, session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 355 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 356 | vppcom_send_disconnect_session (vpp_handle, session_index); |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 357 | } |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 358 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 359 | done: |
| 360 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 361 | } |
| 362 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 363 | /* |
| 364 | * VPPCOM Public API functions |
| 365 | */ |
| 366 | int |
| 367 | vppcom_app_create (char *app_name) |
| 368 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 369 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
| 370 | u8 *heap; |
| 371 | mheap_t *h; |
| 372 | int rv; |
| 373 | |
| 374 | if (!vcm->init) |
| 375 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 376 | vcm->init = 1; |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 377 | clib_spinlock_init (&vcm->session_fifo_lockp); |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 378 | clib_fifo_validate (vcm->client_session_index_fifo, |
| 379 | vcm->cfg.listen_queue_size); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 380 | clib_spinlock_init (&vcm->sessions_lockp); |
Dave Wallace | b5a86ee | 2018-02-16 18:26:11 -0500 | [diff] [blame] | 381 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 382 | vppcom_cfg (&vcm->cfg); |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 383 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 384 | vcm->main_cpu = os_get_thread_index (); |
| 385 | heap = clib_mem_get_per_cpu_heap (); |
| 386 | h = mheap_header (heap); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 387 | /* make the main heap thread-safe */ |
| 388 | h->flags |= MHEAP_FLAG_THREAD_SAFE; |
| 389 | |
| 390 | vcm->session_index_by_vpp_handles = hash_create (0, sizeof (uword)); |
| 391 | |
| 392 | clib_time_init (&vcm->clib_time); |
| 393 | vppcom_init_error_string_table (); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 394 | svm_fifo_segment_main_init (vcl_cfg->segment_baseva, |
| 395 | 20 /* timeout in secs */ ); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | if (vcm->my_client_index == ~0) |
| 399 | { |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 400 | /* API hookup and connect to VPP */ |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 401 | vppcom_api_hookup (); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 402 | vcl_elog_init (vcm); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 403 | vcm->app_state = STATE_APP_START; |
| 404 | rv = vppcom_connect_to_vpp (app_name); |
| 405 | if (rv) |
| 406 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 407 | clib_warning ("VCL<%d>: ERROR: couldn't connect to VPP!", |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 408 | getpid ()); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 409 | return rv; |
| 410 | } |
| 411 | |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 412 | /* State event handling thread */ |
| 413 | |
| 414 | rv = vce_start_event_thread (&(vcm->event_thread), 20); |
| 415 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 416 | VDBG (0, "VCL<%d>: sending session enable", getpid ()); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 417 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 418 | rv = vppcom_app_session_enable (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 419 | if (rv) |
| 420 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 421 | clib_warning ("VCL<%d>: ERROR: vppcom_app_session_enable() " |
| 422 | "failed!", getpid ()); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 423 | return rv; |
| 424 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 425 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 426 | VDBG (0, "VCL<%d>: sending app attach", getpid ()); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 427 | |
| 428 | rv = vppcom_app_attach (); |
| 429 | if (rv) |
| 430 | { |
| 431 | clib_warning ("VCL<%d>: ERROR: vppcom_app_attach() failed!", |
| 432 | getpid ()); |
| 433 | return rv; |
| 434 | } |
| 435 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 436 | VDBG (0, "VCL<%d>: app_name '%s', my_client_index %d (0x%x)", |
| 437 | getpid (), app_name, vcm->my_client_index, vcm->my_client_index); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 438 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 439 | |
| 440 | return VPPCOM_OK; |
| 441 | } |
| 442 | |
| 443 | void |
| 444 | vppcom_app_destroy (void) |
| 445 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 446 | int rv; |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 447 | f64 orig_app_timeout; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 448 | |
| 449 | if (vcm->my_client_index == ~0) |
| 450 | return; |
| 451 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 452 | VDBG (0, "VCL<%d>: detaching from VPP, my_client_index %d (0x%x)", |
| 453 | getpid (), vcm->my_client_index, vcm->my_client_index); |
| 454 | vcl_evt (VCL_EVT_DETACH, vcm); |
Keith Burns (alagalah) | 8aa9aaf | 2018-01-05 12:16:22 -0800 | [diff] [blame] | 455 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 456 | vppcom_app_send_detach (); |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 457 | orig_app_timeout = vcm->cfg.app_timeout; |
| 458 | vcm->cfg.app_timeout = 2.0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 459 | rv = vppcom_wait_for_app_state_change (STATE_APP_ENABLED); |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 460 | vcm->cfg.app_timeout = orig_app_timeout; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 461 | if (PREDICT_FALSE (rv)) |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 462 | VDBG (0, "VCL<%d>: application detach timed out! returning %d (%s)", |
| 463 | getpid (), rv, vppcom_retval_str (rv)); |
Keith Burns (alagalah) | 8aa9aaf | 2018-01-05 12:16:22 -0800 | [diff] [blame] | 464 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 465 | vcl_elog_stop (vcm); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 466 | vl_client_disconnect_from_vlib (); |
| 467 | vcm->my_client_index = ~0; |
| 468 | vcm->app_state = STATE_APP_START; |
| 469 | } |
| 470 | |
| 471 | int |
Dave Wallace | c04cbf1 | 2018-02-07 18:14:02 -0500 | [diff] [blame] | 472 | vppcom_session_create (u8 proto, u8 is_nonblocking) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 473 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 474 | vcl_session_t *session; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 475 | u32 session_index; |
| 476 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 477 | VCL_SESSION_LOCK (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 478 | pool_get (vcm->sessions, session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 479 | memset (session, 0, sizeof (*session)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 480 | session_index = session - vcm->sessions; |
| 481 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 482 | session->session_type = proto; |
| 483 | session->session_state = STATE_START; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 484 | session->vpp_handle = ~0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 485 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 486 | if (is_nonblocking) |
| 487 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 488 | else |
| 489 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_NONBLOCK); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 490 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 491 | vcl_evt (VCL_EVT_CREATE, session, session_type, session->session_state, |
| 492 | is_nonblocking, session_index); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 493 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 494 | VCL_SESSION_UNLOCK (); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 495 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 496 | VDBG (0, "VCL<%d>: sid %u", getpid (), session_index); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 497 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 498 | return (int) session_index; |
| 499 | } |
| 500 | |
| 501 | int |
| 502 | vppcom_session_close (uint32_t session_index) |
| 503 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 504 | vcl_session_t *session = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 505 | int rv; |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 506 | u8 is_vep; |
| 507 | u8 is_vep_session; |
| 508 | u32 next_sid; |
| 509 | u32 vep_idx; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 510 | u64 vpp_handle; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 511 | uword *p; |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 512 | session_state_t state; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 513 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 514 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 515 | is_vep = session->is_vep; |
| 516 | is_vep_session = session->is_vep_session; |
| 517 | next_sid = session->vep.next_sid; |
| 518 | vep_idx = session->vep.vep_idx; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 519 | state = session->session_state; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 520 | vpp_handle = session->vpp_handle; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 521 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 522 | |
| 523 | if (VPPCOM_DEBUG > 0) |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 524 | { |
| 525 | if (is_vep) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 526 | clib_warning ("VCL<%d>: vep_idx %u / sid %u: " |
| 527 | "closing epoll session...", |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 528 | getpid (), session_index, session_index); |
| 529 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 530 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %d: " |
| 531 | "closing session...", |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 532 | getpid (), vpp_handle, session_index); |
| 533 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 534 | |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 535 | if (is_vep) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 536 | { |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 537 | while (next_sid != ~0) |
Dave Wallace | 1948161 | 2017-09-15 18:47:44 -0400 | [diff] [blame] | 538 | { |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 539 | rv = vppcom_epoll_ctl (session_index, EPOLL_CTL_DEL, next_sid, 0); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 540 | if (PREDICT_FALSE (rv < 0)) |
| 541 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: EPOLL_CTL_DEL " |
| 542 | "vep_idx %u failed! rv %d (%s)", |
| 543 | getpid (), vpp_handle, next_sid, vep_idx, |
| 544 | rv, vppcom_retval_str (rv)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 545 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 546 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 547 | next_sid = session->vep.next_sid; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 548 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | else |
| 552 | { |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 553 | if (is_vep_session) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 554 | { |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 555 | rv = vppcom_epoll_ctl (vep_idx, EPOLL_CTL_DEL, session_index, 0); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 556 | if (rv < 0) |
| 557 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: EPOLL_CTL_DEL " |
| 558 | "vep_idx %u failed! rv %d (%s)", |
| 559 | getpid (), vpp_handle, session_index, |
| 560 | vep_idx, rv, vppcom_retval_str (rv)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 561 | } |
| 562 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 563 | if (state & STATE_LISTEN) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 564 | { |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 565 | rv = vppcom_session_unbind (session_index); |
| 566 | if (PREDICT_FALSE (rv < 0)) |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 567 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: listener unbind " |
| 568 | "failed! rv %d (%s)", |
| 569 | getpid (), vpp_handle, session_index, |
| 570 | rv, vppcom_retval_str (rv)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 571 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 572 | |
| 573 | else if (state & (CLIENT_STATE_OPEN | SERVER_STATE_OPEN)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 574 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 575 | rv = vppcom_session_disconnect (session_index); |
| 576 | if (PREDICT_FALSE (rv < 0)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 577 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 578 | "session disconnect failed! rv %d (%s)", |
| 579 | getpid (), vpp_handle, session_index, |
| 580 | rv, vppcom_retval_str (rv)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 581 | } |
Dave Wallace | 1948161 | 2017-09-15 18:47:44 -0400 | [diff] [blame] | 582 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 583 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 584 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 585 | vpp_handle = session->vpp_handle; |
| 586 | if (vpp_handle != ~0) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 587 | { |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 588 | p = hash_get (vcm->session_index_by_vpp_handles, vpp_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 589 | if (p) |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 590 | hash_unset (vcm->session_index_by_vpp_handles, vpp_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 591 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 592 | pool_put_index (vcm->sessions, session_index); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 593 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 594 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 595 | |
| 596 | if (VPPCOM_DEBUG > 0) |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 597 | { |
| 598 | if (is_vep) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 599 | clib_warning ("VCL<%d>: vep_idx %u / sid %u: epoll session removed.", |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 600 | getpid (), session_index, session_index); |
| 601 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 602 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: session removed.", |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 603 | getpid (), vpp_handle, session_index); |
| 604 | } |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 605 | done: |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 606 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 607 | vcl_evt (VCL_EVT_CLOSE, session, rv); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 608 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 609 | return rv; |
| 610 | } |
| 611 | |
| 612 | int |
| 613 | vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep) |
| 614 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 615 | vcl_session_t *session = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 616 | int rv; |
| 617 | |
| 618 | if (!ep || !ep->ip) |
| 619 | return VPPCOM_EINVAL; |
| 620 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 621 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 622 | |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 623 | if (session->is_vep) |
| 624 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 625 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 626 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot " |
| 627 | "bind to an epoll session!", getpid (), session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 628 | rv = VPPCOM_EBADFD; |
| 629 | goto done; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 632 | session->transport.is_ip4 = ep->is_ip4; |
| 633 | session->transport.lcl_ip = to_ip46 (ep->is_ip4 ? IP46_TYPE_IP4 : |
| 634 | IP46_TYPE_IP6, ep->ip); |
| 635 | session->transport.lcl_port = ep->port; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 636 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 637 | VDBG (0, "VCL<%d>: sid %u: binding to local %s address %U port %u, " |
| 638 | "proto %s", getpid (), session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 639 | session->transport.is_ip4 ? "IPv4" : "IPv6", |
| 640 | format_ip46_address, &session->transport.lcl_ip, |
| 641 | session->transport.is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 642 | clib_net_to_host_u16 (session->transport.lcl_port), |
| 643 | session->session_type ? "UDP" : "TCP"); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 644 | vcl_evt (VCL_EVT_BIND, session); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 645 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 646 | done: |
| 647 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | int |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 651 | vppcom_session_listen (uint32_t listen_session_index, uint32_t q_len) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 652 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 653 | vcl_session_t *listen_session = 0; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 654 | u64 listen_vpp_handle; |
| 655 | int rv, retval; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 656 | |
Keith Burns (alagalah) | aba98de | 2018-02-22 03:23:40 -0800 | [diff] [blame] | 657 | if (q_len == 0 || q_len == ~0) |
| 658 | q_len = vcm->cfg.listen_queue_size; |
| 659 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 660 | VCL_SESSION_LOCK_AND_GET (listen_session_index, &listen_session); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 661 | |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 662 | if (listen_session->is_vep) |
| 663 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 664 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 665 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot listen on an " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 666 | "epoll session!", getpid (), listen_session_index); |
| 667 | rv = VPPCOM_EBADFD; |
| 668 | goto done; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 669 | } |
| 670 | |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 671 | listen_vpp_handle = listen_session->vpp_handle; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 672 | if (listen_session->session_state & STATE_LISTEN) |
Dave Wallace | e695cb4 | 2017-11-02 22:04:42 -0400 | [diff] [blame] | 673 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 674 | VCL_SESSION_UNLOCK (); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 675 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: already in listen state!", |
| 676 | getpid (), listen_vpp_handle, listen_session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 677 | rv = VPPCOM_OK; |
| 678 | goto done; |
Dave Wallace | e695cb4 | 2017-11-02 22:04:42 -0400 | [diff] [blame] | 679 | } |
| 680 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 681 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: sending VPP bind+listen " |
| 682 | "request...", getpid (), listen_vpp_handle, listen_session_index); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 683 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 684 | vppcom_send_bind_sock (listen_session, listen_session_index); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 685 | VCL_SESSION_UNLOCK (); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 686 | retval = |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 687 | vppcom_wait_for_session_state_change (listen_session_index, STATE_LISTEN, |
| 688 | vcm->cfg.session_timeout); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 689 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 690 | VCL_SESSION_LOCK_AND_GET (listen_session_index, &listen_session); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 691 | if (PREDICT_FALSE (retval)) |
| 692 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 693 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: bind+listen failed! " |
| 694 | "returning %d (%s)", getpid (), listen_session->vpp_handle, |
| 695 | listen_session_index, retval, vppcom_retval_str (retval)); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 696 | VCL_SESSION_UNLOCK (); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 697 | rv = retval; |
| 698 | goto done; |
| 699 | } |
| 700 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 701 | VCL_ACCEPT_FIFO_LOCK (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 702 | clib_fifo_validate (vcm->client_session_index_fifo, q_len); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 703 | VCL_ACCEPT_FIFO_UNLOCK (); |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 704 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 705 | VCL_SESSION_UNLOCK (); |
Keith Burns (alagalah) | 0d2b0d5 | 2018-03-06 15:55:22 -0800 | [diff] [blame] | 706 | |
| 707 | done: |
| 708 | return rv; |
| 709 | } |
| 710 | |
| 711 | int |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 712 | validate_args_session_accept_ (vcl_session_t * listen_session) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 713 | { |
| 714 | u32 listen_session_index = listen_session - vcm->sessions; |
| 715 | |
| 716 | /* Input validation - expects spinlock on sessions_lockp */ |
| 717 | if (listen_session->is_vep) |
| 718 | { |
| 719 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot accept on an " |
| 720 | "epoll session!", getpid (), listen_session_index); |
| 721 | return VPPCOM_EBADFD; |
| 722 | } |
| 723 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 724 | if (listen_session->session_state != STATE_LISTEN) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 725 | { |
| 726 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
| 727 | "not in listen state! state 0x%x (%s)", getpid (), |
| 728 | listen_session->vpp_handle, listen_session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 729 | listen_session->session_state, |
| 730 | vppcom_session_state_str (listen_session->session_state)); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 731 | return VPPCOM_EBADFD; |
| 732 | } |
| 733 | return VPPCOM_OK; |
| 734 | } |
| 735 | |
| 736 | int |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 737 | vppcom_session_accept (uint32_t listen_session_index, vppcom_endpt_t * ep, |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 738 | uint32_t flags) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 739 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 740 | vcl_session_t *listen_session = 0; |
| 741 | vcl_session_t *client_session = 0; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 742 | u32 client_session_index = ~0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 743 | int rv; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 744 | u64 listen_vpp_handle; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 745 | vce_event_handler_reg_t *reg; |
| 746 | vce_event_t *ev; |
| 747 | vce_event_connect_request_t *result; |
| 748 | struct timespec ts; |
| 749 | struct timeval tv; |
| 750 | int millisecond_timeout = 1; |
| 751 | int hours_timeout = 20 * 60 * 60; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 752 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 753 | VCL_SESSION_LOCK_AND_GET (listen_session_index, &listen_session); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 754 | listen_vpp_handle = listen_session->vpp_handle; // For debugging |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 755 | |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 756 | rv = validate_args_session_accept_ (listen_session); |
| 757 | if (rv) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 758 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 759 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 760 | goto done; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 761 | } |
| 762 | |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 763 | /* Using an aggressive timer of 1ms and a generous timer of |
| 764 | * 20 hours, we can implement a blocking and non-blocking listener |
| 765 | * as both event and time driven */ |
| 766 | gettimeofday (&tv, NULL); |
| 767 | ts.tv_nsec = (tv.tv_usec * 1000) + (1000 * millisecond_timeout); |
| 768 | ts.tv_sec = tv.tv_sec; |
| 769 | |
| 770 | /* Predict that the Listener is blocking more often than not */ |
| 771 | if (PREDICT_TRUE (!VCL_SESS_ATTR_TEST (listen_session->attr, |
| 772 | VCL_SESS_ATTR_NONBLOCK))) |
| 773 | ts.tv_sec += hours_timeout; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 774 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 775 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 776 | |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 777 | /* Register handler for connect_request event on listen_session_index */ |
| 778 | vce_event_key_t evk; |
| 779 | evk.session_index = listen_session_index; |
| 780 | evk.eid = VCL_EVENT_CONNECT_REQ_ACCEPTED; |
| 781 | reg = vce_register_handler (&vcm->event_thread, &evk, |
Keith Burns (alagalah) | 0d2b0d5 | 2018-03-06 15:55:22 -0800 | [diff] [blame] | 782 | vce_connect_request_handler_fn, 0); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 783 | VCL_EVENTS_LOCK (); |
Keith Burns (alagalah) | 7cf80e0 | 2018-03-08 16:46:25 -0800 | [diff] [blame] | 784 | ev = vce_get_event_from_index (&vcm->event_thread, reg->ev_idx); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 785 | pthread_mutex_lock (®->handler_lock); |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 786 | while (!ev) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 787 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 788 | VCL_EVENTS_UNLOCK (); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 789 | rv = pthread_cond_timedwait (®->handler_cond, |
| 790 | ®->handler_lock, &ts); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 791 | if (rv == ETIMEDOUT) |
| 792 | { |
| 793 | rv = VPPCOM_EAGAIN; |
| 794 | goto cleanup; |
| 795 | } |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 796 | VCL_EVENTS_LOCK (); |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 797 | ev = vce_get_event_from_index (&vcm->event_thread, reg->ev_idx); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 798 | } |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 799 | result = vce_get_event_data (ev, sizeof (*result)); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 800 | client_session_index = result->accepted_session_index; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 801 | VCL_EVENTS_UNLOCK (); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 802 | |
| 803 | /* Remove from the FIFO used to service epoll */ |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 804 | VCL_ACCEPT_FIFO_LOCK (); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 805 | if (clib_fifo_elts (vcm->client_session_index_fifo)) |
| 806 | { |
| 807 | u32 tmp_client_session_index; |
| 808 | clib_fifo_sub1 (vcm->client_session_index_fifo, |
| 809 | tmp_client_session_index); |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 810 | /* It wasn't ours... put it back ... */ |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 811 | if (tmp_client_session_index != client_session_index) |
| 812 | clib_fifo_add1 (vcm->client_session_index_fifo, |
| 813 | tmp_client_session_index); |
| 814 | } |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 815 | VCL_ACCEPT_FIFO_UNLOCK (); |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 816 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 817 | VCL_SESSION_LOCK (); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 818 | |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 819 | rv = vppcom_session_at_index (client_session_index, &client_session); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 820 | if (PREDICT_FALSE (rv)) |
| 821 | { |
| 822 | rv = VPPCOM_ECONNABORTED; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 823 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: client sid %u " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 824 | "lookup failed! returning %d (%s)", getpid (), |
| 825 | listen_vpp_handle, listen_session_index, |
| 826 | client_session_index, rv, vppcom_retval_str (rv)); |
Dave Wallace | e535644 | 2018-03-19 10:38:00 -0400 | [diff] [blame] | 827 | goto cleanup; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 828 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 829 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 830 | if (flags & O_NONBLOCK) |
| 831 | VCL_SESS_ATTR_SET (client_session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 832 | else |
| 833 | VCL_SESS_ATTR_CLR (client_session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 834 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 835 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: Got a client request! " |
| 836 | "vpp handle 0x%llx, sid %u, flags %d, is_nonblocking %u", |
| 837 | getpid (), listen_vpp_handle, listen_session_index, |
| 838 | client_session->vpp_handle, client_session_index, |
| 839 | flags, VCL_SESS_ATTR_TEST (client_session->attr, |
| 840 | VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 841 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 842 | if (ep) |
| 843 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 844 | ep->is_ip4 = client_session->transport.is_ip4; |
| 845 | ep->port = client_session->transport.rmt_port; |
| 846 | if (client_session->transport.is_ip4) |
| 847 | clib_memcpy (ep->ip, &client_session->transport.rmt_ip.ip4, |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 848 | sizeof (ip4_address_t)); |
| 849 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 850 | clib_memcpy (ep->ip, &client_session->transport.rmt_ip.ip6, |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 851 | sizeof (ip6_address_t)); |
| 852 | } |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 853 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 854 | vppcom_send_accept_session_reply (client_session->vpp_handle, |
| 855 | client_session->client_context, |
| 856 | 0 /* retval OK */ ); |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 857 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 858 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: accepted vpp handle 0x%llx," |
| 859 | " sid %u connection from peer %s address %U port %u to local %s address" |
| 860 | " %U port %u", |
| 861 | getpid (), listen_vpp_handle, |
| 862 | listen_session_index, client_session->vpp_handle, |
| 863 | client_session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 864 | client_session->transport.is_ip4 ? "IPv4" : "IPv6", |
| 865 | format_ip46_address, &client_session->transport.rmt_ip, |
| 866 | client_session->transport.is_ip4 ? |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 867 | IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 868 | clib_net_to_host_u16 (client_session->transport.rmt_port), |
| 869 | client_session->transport.is_ip4 ? "IPv4" : "IPv6", |
| 870 | format_ip46_address, &client_session->transport.lcl_ip, |
| 871 | client_session->transport.is_ip4 ? |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 872 | IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 873 | clib_net_to_host_u16 (client_session->transport.lcl_port)); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 874 | vcl_evt (VCL_EVT_ACCEPT, client_session, listen_session, |
| 875 | client_session_index); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 876 | VCL_SESSION_UNLOCK (); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 877 | |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 878 | rv = (int) client_session_index; |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 879 | vce_clear_event (&vcm->event_thread, reg->ev_idx); |
| 880 | if (vcm->session_io_thread.io_sessions_lockp) |
| 881 | { |
| 882 | /* Throw this new accepted session index into the rx poll thread pool */ |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 883 | VCL_IO_SESSIONS_LOCK (); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 884 | u32 *active_session_index; |
| 885 | pool_get (vcm->session_io_thread.active_session_indexes, |
| 886 | active_session_index); |
| 887 | *active_session_index = client_session_index; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 888 | VCL_IO_SESSIONS_UNLOCK (); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 889 | } |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 890 | cleanup: |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 891 | vce_unregister_handler (&vcm->event_thread, reg); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 892 | pthread_mutex_unlock (®->handler_lock); |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 893 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 894 | done: |
| 895 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | int |
| 899 | vppcom_session_connect (uint32_t session_index, vppcom_endpt_t * server_ep) |
| 900 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 901 | vcl_session_t *session = 0; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 902 | u64 vpp_handle = 0; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 903 | int rv, retval = VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 904 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 905 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 906 | |
| 907 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 908 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 909 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 910 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot " |
| 911 | "connect on an epoll session!", getpid (), session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 912 | rv = VPPCOM_EBADFD; |
| 913 | goto done; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 914 | } |
| 915 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 916 | if (PREDICT_FALSE (session->session_state & CLIENT_STATE_OPEN)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 917 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 918 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: session already " |
| 919 | "connected to %s %U port %d proto %s, state 0x%x (%s)", |
| 920 | getpid (), session->vpp_handle, session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 921 | session->transport.is_ip4 ? "IPv4" : "IPv6", |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 922 | format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 923 | &session->transport.rmt_ip, session->transport.is_ip4 ? |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 924 | IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 925 | clib_net_to_host_u16 (session->transport.rmt_port), |
| 926 | session->session_type ? "UDP" : "TCP", session->session_state, |
| 927 | vppcom_session_state_str (session->session_state)); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 928 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 929 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 930 | goto done; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 931 | } |
| 932 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 933 | session->transport.is_ip4 = server_ep->is_ip4; |
| 934 | if (session->transport.is_ip4) |
| 935 | clib_memcpy (&session->transport.rmt_ip.ip4, server_ep->ip, |
Dave Wallace | d239f8d | 2018-06-19 13:37:30 -0400 | [diff] [blame] | 936 | sizeof (ip4_address_t)); |
| 937 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 938 | clib_memcpy (&session->transport.rmt_ip.ip6, server_ep->ip, |
Dave Wallace | d239f8d | 2018-06-19 13:37:30 -0400 | [diff] [blame] | 939 | sizeof (ip6_address_t)); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 940 | session->transport.rmt_port = server_ep->port; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 941 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 942 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: connecting to server %s %U " |
| 943 | "port %d proto %s", |
| 944 | getpid (), session->vpp_handle, session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 945 | session->transport.is_ip4 ? "IPv4" : "IPv6", |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 946 | format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 947 | &session->transport.rmt_ip, session->transport.is_ip4 ? |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 948 | IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 949 | clib_net_to_host_u16 (session->transport.rmt_port), |
| 950 | session->session_type ? "UDP" : "TCP"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 951 | |
| 952 | vppcom_send_connect_sock (session, session_index); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 953 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 954 | |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 955 | retval = |
| 956 | vppcom_wait_for_session_state_change (session_index, STATE_CONNECT, |
| 957 | vcm->cfg.session_timeout); |
| 958 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 959 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 960 | vpp_handle = session->vpp_handle; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 961 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 962 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 963 | done: |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 964 | if (PREDICT_FALSE (retval)) |
| 965 | { |
| 966 | rv = retval; |
| 967 | if (VPPCOM_DEBUG > 0) |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 968 | { |
| 969 | if (session) |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 970 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: connect " |
| 971 | "failed! returning %d (%s)", getpid (), vpp_handle, |
| 972 | session_index, rv, vppcom_retval_str (rv)); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 973 | else |
| 974 | clib_warning ("VCL<%d>: no session for sid %u: connect failed! " |
| 975 | "returning %d (%s)", getpid (), |
| 976 | session_index, rv, vppcom_retval_str (rv)); |
| 977 | } |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 978 | } |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 979 | else |
| 980 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: connected!", |
| 981 | getpid (), vpp_handle, session_index); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 982 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 983 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 984 | } |
| 985 | |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 986 | static inline int |
| 987 | vppcom_session_read_internal (uint32_t session_index, void *buf, int n, |
| 988 | u8 peek) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 989 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 990 | vcl_session_t *session = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 991 | svm_fifo_t *rx_fifo; |
| 992 | int n_read = 0; |
| 993 | int rv; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 994 | int is_nonblocking; |
| 995 | |
| 996 | u64 vpp_handle; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 997 | u32 poll_et; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 998 | session_state_t state; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 999 | |
| 1000 | ASSERT (buf); |
| 1001 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1002 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1003 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1004 | is_nonblocking = VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 1005 | rx_fifo = session->rx_fifo; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1006 | state = session->session_state; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1007 | vpp_handle = session->vpp_handle; |
| 1008 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1009 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1010 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1011 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1012 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot " |
| 1013 | "read from an epoll session!", getpid (), session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1014 | rv = VPPCOM_EBADFD; |
| 1015 | goto done; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1018 | if (PREDICT_FALSE (!(state & (SERVER_STATE_OPEN | CLIENT_STATE_OPEN)))) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1019 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1020 | VCL_SESSION_UNLOCK (); |
Keith Burns (alagalah) | 56a0d06 | 2018-02-15 07:52:50 -0800 | [diff] [blame] | 1021 | rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1022 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1023 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: %s session is not open! " |
| 1024 | "state 0x%x (%s), returning %d (%s)", |
| 1025 | getpid (), vpp_handle, session_index, state, |
| 1026 | vppcom_session_state_str (state), rv, vppcom_retval_str (rv)); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1027 | goto done; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1028 | } |
| 1029 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1030 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1031 | |
| 1032 | do |
| 1033 | { |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1034 | if (peek) |
| 1035 | n_read = svm_fifo_peek (rx_fifo, 0, n, buf); |
| 1036 | else |
| 1037 | n_read = svm_fifo_dequeue_nowait (rx_fifo, n, buf); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1038 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1039 | while (!is_nonblocking && (n_read <= 0)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1040 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1041 | if (n_read <= 0) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1042 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1043 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1044 | |
| 1045 | poll_et = (((EPOLLET | EPOLLIN) & session->vep.ev.events) == |
| 1046 | (EPOLLET | EPOLLIN)); |
| 1047 | if (poll_et) |
| 1048 | session->vep.et_mask |= EPOLLIN; |
| 1049 | |
Keith Burns (alagalah) | 56a0d06 | 2018-02-15 07:52:50 -0800 | [diff] [blame] | 1050 | if (state & STATE_CLOSE_ON_EMPTY) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1051 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1052 | rv = VPPCOM_ECONNRESET; |
| 1053 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1054 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: Empty fifo with " |
| 1055 | "session state 0x%x (%s)! Setting state to 0x%x (%s), " |
| 1056 | "returning %d (%s)", |
| 1057 | getpid (), session->vpp_handle, session_index, |
| 1058 | state, vppcom_session_state_str (state), |
| 1059 | STATE_DISCONNECT, |
| 1060 | vppcom_session_state_str (STATE_DISCONNECT), rv, |
| 1061 | vppcom_retval_str (rv)); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1062 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1063 | session->session_state = STATE_DISCONNECT; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1064 | } |
| 1065 | else |
| 1066 | rv = VPPCOM_EAGAIN; |
| 1067 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1068 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1069 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1070 | else |
| 1071 | rv = n_read; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1072 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1073 | if (VPPCOM_DEBUG > 2) |
| 1074 | { |
| 1075 | if (rv > 0) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1076 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: read %d bytes " |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1077 | "from (%p)", getpid (), vpp_handle, |
| 1078 | session_index, n_read, rx_fifo); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1079 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1080 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: nothing read! " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1081 | "returning %d (%s)", getpid (), vpp_handle, |
| 1082 | session_index, rv, vppcom_retval_str (rv)); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1083 | } |
| 1084 | done: |
| 1085 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1088 | int |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1089 | vppcom_session_read (uint32_t session_index, void *buf, size_t n) |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1090 | { |
| 1091 | return (vppcom_session_read_internal (session_index, buf, n, 0)); |
| 1092 | } |
| 1093 | |
| 1094 | static int |
| 1095 | vppcom_session_peek (uint32_t session_index, void *buf, int n) |
| 1096 | { |
| 1097 | return (vppcom_session_read_internal (session_index, buf, n, 1)); |
| 1098 | } |
| 1099 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1100 | static inline int |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1101 | vppcom_session_read_ready (vcl_session_t * session, u32 session_index) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1102 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1103 | int ready = 0; |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1104 | u32 poll_et; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1105 | int rv; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1106 | session_state_t state = session->session_state; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1107 | u64 vpp_handle = session->vpp_handle; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1108 | |
| 1109 | /* Assumes caller has acquired spinlock: vcm->sessions_lockp */ |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1110 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1111 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1112 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot read from an " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1113 | "epoll session!", getpid (), session_index); |
| 1114 | rv = VPPCOM_EBADFD; |
| 1115 | goto done; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1116 | } |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1117 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1118 | if (session->session_state & STATE_LISTEN) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1119 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1120 | VCL_ACCEPT_FIFO_LOCK (); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1121 | ready = clib_fifo_elts (vcm->client_session_index_fifo); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1122 | VCL_ACCEPT_FIFO_UNLOCK (); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1123 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1124 | else |
| 1125 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1126 | if (!(state & (SERVER_STATE_OPEN | CLIENT_STATE_OPEN | STATE_LISTEN))) |
| 1127 | { |
Keith Burns (alagalah) | 56a0d06 | 2018-02-15 07:52:50 -0800 | [diff] [blame] | 1128 | rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1129 | VPPCOM_ENOTCONN); |
| 1130 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1131 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session is not open!" |
| 1132 | " state 0x%x (%s), returning %d (%s)", |
| 1133 | getpid (), vpp_handle, session_index, |
| 1134 | state, vppcom_session_state_str (state), |
| 1135 | rv, vppcom_retval_str (rv)); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1136 | goto done; |
| 1137 | } |
| 1138 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1139 | ready = svm_fifo_max_dequeue (session->rx_fifo); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1140 | } |
| 1141 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1142 | if (ready == 0) |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1143 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1144 | poll_et = |
| 1145 | ((EPOLLET | EPOLLIN) & session->vep.ev.events) == (EPOLLET | EPOLLIN); |
| 1146 | if (poll_et) |
| 1147 | session->vep.et_mask |= EPOLLIN; |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1148 | |
Keith Burns (alagalah) | 56a0d06 | 2018-02-15 07:52:50 -0800 | [diff] [blame] | 1149 | if (state & STATE_CLOSE_ON_EMPTY) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1150 | { |
| 1151 | rv = VPPCOM_ECONNRESET; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1152 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1153 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: Empty fifo with " |
| 1154 | "session state 0x%x (%s)! Setting state to 0x%x (%s), " |
| 1155 | "returning %d (%s)", |
| 1156 | getpid (), session_index, vpp_handle, |
| 1157 | state, vppcom_session_state_str (state), |
| 1158 | STATE_DISCONNECT, |
| 1159 | vppcom_session_state_str (STATE_DISCONNECT), rv, |
| 1160 | vppcom_retval_str (rv)); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1161 | session->session_state = STATE_DISCONNECT; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1162 | goto done; |
| 1163 | } |
| 1164 | } |
| 1165 | rv = ready; |
Dave Wallace | 16cb408 | 2017-11-29 03:24:06 -0500 | [diff] [blame] | 1166 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1167 | if (!svm_msg_q_is_empty (vcm->app_event_queue) && |
| 1168 | !pthread_mutex_trylock (&vcm->app_event_queue->q->mutex)) |
Dave Wallace | 16cb408 | 2017-11-29 03:24:06 -0500 | [diff] [blame] | 1169 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1170 | u32 i, n_to_dequeue = vcm->app_event_queue->q->cursize; |
| 1171 | svm_msg_q_msg_t msg; |
Dave Wallace | 16cb408 | 2017-11-29 03:24:06 -0500 | [diff] [blame] | 1172 | |
| 1173 | for (i = 0; i < n_to_dequeue; i++) |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1174 | { |
| 1175 | svm_queue_sub_raw (vcm->app_event_queue->q, (u8 *) & msg); |
| 1176 | svm_msg_q_free_msg (vcm->app_event_queue, &msg); |
| 1177 | } |
Dave Wallace | 16cb408 | 2017-11-29 03:24:06 -0500 | [diff] [blame] | 1178 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1179 | pthread_mutex_unlock (&vcm->app_event_queue->q->mutex); |
Dave Wallace | 16cb408 | 2017-11-29 03:24:06 -0500 | [diff] [blame] | 1180 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1181 | done: |
| 1182 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | int |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1186 | vppcom_session_write (uint32_t session_index, void *buf, size_t n) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1187 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1188 | vcl_session_t *session = 0; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1189 | svm_fifo_t *tx_fifo = 0; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1190 | svm_msg_q_t *mq; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1191 | session_state_t state; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1192 | int rv, n_write, is_nonblocking; |
| 1193 | u32 poll_et; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1194 | u64 vpp_handle; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1195 | |
| 1196 | ASSERT (buf); |
| 1197 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1198 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1199 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1200 | tx_fifo = session->tx_fifo; |
| 1201 | is_nonblocking = VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 1202 | vpp_handle = session->vpp_handle; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1203 | state = session->session_state; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1204 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1205 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1206 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1207 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1208 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1209 | "cannot write to an epoll session!", |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1210 | getpid (), vpp_handle, session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1211 | |
| 1212 | rv = VPPCOM_EBADFD; |
| 1213 | goto done; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1214 | } |
| 1215 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1216 | if (!(session->session_state & (SERVER_STATE_OPEN | CLIENT_STATE_OPEN))) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1217 | { |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1218 | rv = |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1219 | ((session->session_state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1220 | VPPCOM_ENOTCONN); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1221 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1222 | VCL_SESSION_UNLOCK (); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1223 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session is not open! " |
| 1224 | "state 0x%x (%s)", |
| 1225 | getpid (), vpp_handle, session_index, |
| 1226 | state, vppcom_session_state_str (state)); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1227 | goto done; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1228 | } |
| 1229 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1230 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1231 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1232 | do |
| 1233 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1234 | n_write = svm_fifo_enqueue_nowait (tx_fifo, n, (void *) buf); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1235 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1236 | while (!is_nonblocking && (n_write <= 0)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1237 | |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 1238 | /* If event wasn't set, add one |
| 1239 | * |
| 1240 | * To reduce context switching, can check if an |
| 1241 | * event is already there for this event_key, but for now |
| 1242 | * this will suffice. */ |
| 1243 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1244 | if ((n_write > 0) && svm_fifo_set_event (tx_fifo)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1245 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1246 | /* Send TX event to vpp */ |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1247 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1248 | mq = session->vpp_evt_q; |
| 1249 | ASSERT (mq); |
| 1250 | app_send_io_evt_to_vpp (mq, tx_fifo, FIFO_EVENT_APP_TX, SVM_Q_WAIT); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1251 | VCL_SESSION_UNLOCK (); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1252 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: added FIFO_EVENT_APP_TX " |
| 1253 | "to vpp_event_q %p, n_write %d", getpid (), |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1254 | vpp_handle, session_index, mq, n_write); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1255 | } |
| 1256 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1257 | if (n_write <= 0) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1258 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1259 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1260 | |
| 1261 | poll_et = (((EPOLLET | EPOLLOUT) & session->vep.ev.events) == |
| 1262 | (EPOLLET | EPOLLOUT)); |
| 1263 | if (poll_et) |
| 1264 | session->vep.et_mask |= EPOLLOUT; |
| 1265 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1266 | if (session->session_state & STATE_CLOSE_ON_EMPTY) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1267 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1268 | rv = VPPCOM_ECONNRESET; |
| 1269 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1270 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: Empty fifo with " |
| 1271 | "session state 0x%x (%s)! Setting state to 0x%x (%s), " |
| 1272 | "returning %d (%s)", |
| 1273 | getpid (), session->vpp_handle, session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1274 | session->session_state, |
| 1275 | vppcom_session_state_str (session->session_state), |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1276 | STATE_DISCONNECT, |
| 1277 | vppcom_session_state_str (STATE_DISCONNECT), rv, |
| 1278 | vppcom_retval_str (rv)); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1279 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1280 | session->session_state = STATE_DISCONNECT; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1281 | } |
| 1282 | else |
| 1283 | rv = VPPCOM_EAGAIN; |
| 1284 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1285 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1286 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1287 | else |
| 1288 | rv = n_write; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1289 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1290 | if (VPPCOM_DEBUG > 2) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1291 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1292 | if (n_write <= 0) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1293 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: " |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1294 | "FIFO-FULL (%p)", getpid (), vpp_handle, |
| 1295 | session_index, tx_fifo); |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1296 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1297 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: " |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1298 | "wrote %d bytes tx-fifo: (%p)", getpid (), |
| 1299 | vpp_handle, session_index, n_write, tx_fifo); |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1300 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1301 | done: |
| 1302 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | static inline int |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1306 | vppcom_session_write_ready (vcl_session_t * session, u32 session_index) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1307 | { |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1308 | int ready; |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1309 | u32 poll_et; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1310 | int rv; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1311 | |
| 1312 | ASSERT (session); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1313 | |
| 1314 | /* Assumes caller has acquired spinlock: vcm->sessions_lockp */ |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1315 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1316 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1317 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1318 | "cannot write to an epoll session!", |
| 1319 | getpid (), session->vpp_handle, session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1320 | rv = VPPCOM_EBADFD; |
| 1321 | goto done; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1322 | } |
| 1323 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1324 | if (PREDICT_FALSE (session->session_state & STATE_LISTEN)) |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1325 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1326 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1327 | "cannot write to a listen session!", |
| 1328 | getpid (), session->vpp_handle, session_index); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1329 | rv = VPPCOM_EBADFD; |
| 1330 | goto done; |
| 1331 | } |
| 1332 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1333 | if (!(session->session_state & (SERVER_STATE_OPEN | CLIENT_STATE_OPEN))) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1334 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1335 | session_state_t state = session->session_state; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1336 | |
Keith Burns (alagalah) | 56a0d06 | 2018-02-15 07:52:50 -0800 | [diff] [blame] | 1337 | rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1338 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1339 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1340 | "session is not open! state 0x%x (%s), " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1341 | "returning %d (%s)", getpid (), session->vpp_handle, |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1342 | session_index, |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1343 | state, vppcom_session_state_str (state), |
| 1344 | rv, vppcom_retval_str (rv)); |
| 1345 | goto done; |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1348 | ready = svm_fifo_max_enqueue (session->tx_fifo); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1349 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1350 | VDBG (3, "VCL<%d>: vpp handle 0x%llx, sid %u: peek %s (%p), ready = %d", |
| 1351 | getpid (), session->vpp_handle, session_index, session->tx_fifo, |
| 1352 | ready); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1353 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1354 | if (ready == 0) |
| 1355 | { |
| 1356 | poll_et = (((EPOLLET | EPOLLOUT) & session->vep.ev.events) == |
| 1357 | (EPOLLET | EPOLLOUT)); |
| 1358 | if (poll_et) |
| 1359 | session->vep.et_mask |= EPOLLOUT; |
| 1360 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1361 | if (session->session_state & STATE_CLOSE_ON_EMPTY) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1362 | { |
| 1363 | rv = VPPCOM_ECONNRESET; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1364 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1365 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: Empty fifo with " |
| 1366 | "session state 0x%x (%s)! Setting state to 0x%x (%s), " |
| 1367 | "returning %d (%s)", getpid (), |
| 1368 | session->vpp_handle, session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1369 | session->session_state, |
| 1370 | vppcom_session_state_str (session->session_state), |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1371 | STATE_DISCONNECT, |
| 1372 | vppcom_session_state_str (STATE_DISCONNECT), rv, |
| 1373 | vppcom_retval_str (rv)); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1374 | session->session_state = STATE_DISCONNECT; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1375 | goto done; |
| 1376 | } |
| 1377 | } |
| 1378 | rv = ready; |
| 1379 | done: |
| 1380 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | int |
| 1384 | vppcom_select (unsigned long n_bits, unsigned long *read_map, |
| 1385 | unsigned long *write_map, unsigned long *except_map, |
| 1386 | double time_to_wait) |
| 1387 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1388 | u32 session_index; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1389 | vcl_session_t *session = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1390 | int rv, bits_set = 0; |
| 1391 | f64 timeout = clib_time_now (&vcm->clib_time) + time_to_wait; |
| 1392 | u32 minbits = clib_max (n_bits, BITS (uword)); |
| 1393 | |
| 1394 | ASSERT (sizeof (clib_bitmap_t) == sizeof (long int)); |
| 1395 | |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 1396 | if (n_bits && read_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1397 | { |
| 1398 | clib_bitmap_validate (vcm->rd_bitmap, minbits); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1399 | clib_memcpy (vcm->rd_bitmap, read_map, |
| 1400 | vec_len (vcm->rd_bitmap) * sizeof (clib_bitmap_t)); |
| 1401 | memset (read_map, 0, vec_len (vcm->rd_bitmap) * sizeof (clib_bitmap_t)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1402 | } |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 1403 | if (n_bits && write_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1404 | { |
| 1405 | clib_bitmap_validate (vcm->wr_bitmap, minbits); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1406 | clib_memcpy (vcm->wr_bitmap, write_map, |
| 1407 | vec_len (vcm->wr_bitmap) * sizeof (clib_bitmap_t)); |
| 1408 | memset (write_map, 0, |
| 1409 | vec_len (vcm->wr_bitmap) * sizeof (clib_bitmap_t)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1410 | } |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 1411 | if (n_bits && except_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1412 | { |
| 1413 | clib_bitmap_validate (vcm->ex_bitmap, minbits); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1414 | clib_memcpy (vcm->ex_bitmap, except_map, |
| 1415 | vec_len (vcm->ex_bitmap) * sizeof (clib_bitmap_t)); |
| 1416 | memset (except_map, 0, |
| 1417 | vec_len (vcm->ex_bitmap) * sizeof (clib_bitmap_t)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | do |
| 1421 | { |
| 1422 | /* *INDENT-OFF* */ |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1423 | if (n_bits) |
| 1424 | { |
| 1425 | if (read_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1426 | { |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1427 | clib_bitmap_foreach (session_index, vcm->rd_bitmap, |
| 1428 | ({ |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1429 | VCL_SESSION_LOCK(); |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1430 | rv = vppcom_session_at_index (session_index, &session); |
| 1431 | if (rv < 0) |
| 1432 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1433 | VCL_SESSION_UNLOCK(); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1434 | VDBG (1, "VCL<%d>: session %d specified in read_map is" |
| 1435 | " closed.", getpid (), |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1436 | session_index); |
| 1437 | bits_set = VPPCOM_EBADFD; |
| 1438 | goto select_done; |
| 1439 | } |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1440 | if (session->session_state & STATE_LISTEN) |
Dave Wallace | 8d73e85 | 2018-03-08 16:39:28 -0500 | [diff] [blame] | 1441 | { |
| 1442 | vce_event_handler_reg_t *reg = 0; |
| 1443 | vce_event_key_t evk; |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1444 | |
Dave Wallace | 8d73e85 | 2018-03-08 16:39:28 -0500 | [diff] [blame] | 1445 | /* Check if handler already registered for this |
| 1446 | * event. |
| 1447 | * If not, register handler for connect_request event |
| 1448 | * on listen_session_index |
| 1449 | */ |
| 1450 | evk.session_index = session_index; |
| 1451 | evk.eid = VCL_EVENT_CONNECT_REQ_ACCEPTED; |
| 1452 | reg = vce_get_event_handler (&vcm->event_thread, &evk); |
| 1453 | if (!reg) |
| 1454 | reg = vce_register_handler (&vcm->event_thread, &evk, |
Keith Burns (alagalah) | 0d2b0d5 | 2018-03-06 15:55:22 -0800 | [diff] [blame] | 1455 | vce_poll_wait_connect_request_handler_fn, |
| 1456 | 0 /* No callback args */); |
Dave Wallace | 8d73e85 | 2018-03-08 16:39:28 -0500 | [diff] [blame] | 1457 | rv = vppcom_session_read_ready (session, session_index); |
| 1458 | if (rv > 0) |
| 1459 | { |
| 1460 | vce_unregister_handler (&vcm->event_thread, reg); |
| 1461 | } |
| 1462 | } |
| 1463 | else |
| 1464 | rv = vppcom_session_read_ready (session, session_index); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1465 | VCL_SESSION_UNLOCK(); |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1466 | if (except_map && vcm->ex_bitmap && |
| 1467 | clib_bitmap_get (vcm->ex_bitmap, session_index) && |
| 1468 | (rv < 0)) |
| 1469 | { |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1470 | clib_bitmap_set_no_check (except_map, session_index, 1); |
| 1471 | bits_set++; |
| 1472 | } |
| 1473 | else if (rv > 0) |
| 1474 | { |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1475 | clib_bitmap_set_no_check (read_map, session_index, 1); |
| 1476 | bits_set++; |
| 1477 | } |
| 1478 | })); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1479 | } |
| 1480 | |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1481 | if (write_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1482 | { |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1483 | clib_bitmap_foreach (session_index, vcm->wr_bitmap, |
| 1484 | ({ |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1485 | VCL_SESSION_LOCK(); |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1486 | rv = vppcom_session_at_index (session_index, &session); |
| 1487 | if (rv < 0) |
| 1488 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1489 | VCL_SESSION_UNLOCK(); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1490 | VDBG (0, "VCL<%d>: session %d specified in " |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 1491 | "write_map is closed.", getpid (), |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1492 | session_index); |
| 1493 | bits_set = VPPCOM_EBADFD; |
| 1494 | goto select_done; |
| 1495 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1496 | |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1497 | rv = vppcom_session_write_ready (session, session_index); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1498 | VCL_SESSION_UNLOCK(); |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1499 | if (write_map && (rv > 0)) |
| 1500 | { |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1501 | clib_bitmap_set_no_check (write_map, session_index, 1); |
| 1502 | bits_set++; |
| 1503 | } |
| 1504 | })); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1505 | } |
| 1506 | |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1507 | if (except_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1508 | { |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1509 | clib_bitmap_foreach (session_index, vcm->ex_bitmap, |
| 1510 | ({ |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1511 | VCL_SESSION_LOCK(); |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1512 | rv = vppcom_session_at_index (session_index, &session); |
| 1513 | if (rv < 0) |
| 1514 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1515 | VCL_SESSION_UNLOCK(); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1516 | VDBG (1, "VCL<%d>: session %d specified in except_map " |
| 1517 | "is closed.", getpid (), |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1518 | session_index); |
| 1519 | bits_set = VPPCOM_EBADFD; |
| 1520 | goto select_done; |
| 1521 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1522 | |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1523 | rv = vppcom_session_read_ready (session, session_index); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1524 | VCL_SESSION_UNLOCK(); |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1525 | if (rv < 0) |
| 1526 | { |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1527 | clib_bitmap_set_no_check (except_map, session_index, 1); |
| 1528 | bits_set++; |
| 1529 | } |
| 1530 | })); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1531 | } |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 1532 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1533 | /* *INDENT-ON* */ |
| 1534 | } |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1535 | while ((time_to_wait == -1) || (clib_time_now (&vcm->clib_time) < timeout)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1536 | |
| 1537 | select_done: |
| 1538 | return (bits_set); |
| 1539 | } |
| 1540 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1541 | static inline void |
| 1542 | vep_verify_epoll_chain (u32 vep_idx) |
| 1543 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1544 | vcl_session_t *session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1545 | vppcom_epoll_t *vep; |
| 1546 | int rv; |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1547 | u32 sid = vep_idx; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1548 | |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1549 | if (VPPCOM_DEBUG <= 1) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1550 | return; |
| 1551 | |
| 1552 | /* Assumes caller has acquired spinlock: vcm->sessions_lockp */ |
| 1553 | rv = vppcom_session_at_index (vep_idx, &session); |
| 1554 | if (PREDICT_FALSE (rv)) |
| 1555 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1556 | clib_warning ("VCL<%d>: ERROR: Invalid vep_idx (%u)!", |
| 1557 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1558 | goto done; |
| 1559 | } |
| 1560 | if (PREDICT_FALSE (!session->is_vep)) |
| 1561 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1562 | clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!", |
| 1563 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1564 | goto done; |
| 1565 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1566 | vep = &session->vep; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1567 | clib_warning ("VCL<%d>: vep_idx (%u): Dumping epoll chain\n" |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1568 | "{\n" |
| 1569 | " is_vep = %u\n" |
| 1570 | " is_vep_session = %u\n" |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1571 | " next_sid = 0x%x (%u)\n" |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1572 | " wait_cont_idx = 0x%x (%u)\n" |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1573 | "}\n", getpid (), vep_idx, |
| 1574 | session->is_vep, session->is_vep_session, |
| 1575 | vep->next_sid, vep->next_sid, |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1576 | session->wait_cont_idx, session->wait_cont_idx); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1577 | |
| 1578 | for (sid = vep->next_sid; sid != ~0; sid = vep->next_sid) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1579 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1580 | rv = vppcom_session_at_index (sid, &session); |
| 1581 | if (PREDICT_FALSE (rv)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1582 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1583 | clib_warning ("VCL<%d>: ERROR: Invalid sid (%u)!", getpid (), sid); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1584 | goto done; |
| 1585 | } |
| 1586 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1587 | clib_warning ("VCL<%d>: ERROR: sid (%u) is a vep!", |
| 1588 | getpid (), vep_idx); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1589 | else if (PREDICT_FALSE (!session->is_vep_session)) |
| 1590 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1591 | clib_warning ("VCL<%d>: ERROR: session (%u) " |
| 1592 | "is not a vep session!", getpid (), sid); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1593 | goto done; |
| 1594 | } |
| 1595 | vep = &session->vep; |
| 1596 | if (PREDICT_FALSE (vep->vep_idx != vep_idx)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1597 | clib_warning ("VCL<%d>: ERROR: session (%u) vep_idx (%u) != " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1598 | "vep_idx (%u)!", getpid (), |
| 1599 | sid, session->vep.vep_idx, vep_idx); |
| 1600 | if (session->is_vep_session) |
| 1601 | { |
| 1602 | clib_warning ("vep_idx[%u]: sid 0x%x (%u)\n" |
| 1603 | "{\n" |
| 1604 | " next_sid = 0x%x (%u)\n" |
| 1605 | " prev_sid = 0x%x (%u)\n" |
| 1606 | " vep_idx = 0x%x (%u)\n" |
| 1607 | " ev.events = 0x%x\n" |
| 1608 | " ev.data.u64 = 0x%llx\n" |
| 1609 | " et_mask = 0x%x\n" |
| 1610 | "}\n", |
| 1611 | vep_idx, sid, sid, |
| 1612 | vep->next_sid, vep->next_sid, |
| 1613 | vep->prev_sid, vep->prev_sid, |
| 1614 | vep->vep_idx, vep->vep_idx, |
| 1615 | vep->ev.events, vep->ev.data.u64, vep->et_mask); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1616 | } |
| 1617 | } |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1618 | |
| 1619 | done: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1620 | clib_warning ("VCL<%d>: vep_idx (%u): Dump complete!\n", |
| 1621 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | int |
| 1625 | vppcom_epoll_create (void) |
| 1626 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1627 | vcl_session_t *vep_session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1628 | u32 vep_idx; |
| 1629 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1630 | VCL_SESSION_LOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1631 | pool_get (vcm->sessions, vep_session); |
| 1632 | memset (vep_session, 0, sizeof (*vep_session)); |
| 1633 | vep_idx = vep_session - vcm->sessions; |
| 1634 | |
| 1635 | vep_session->is_vep = 1; |
| 1636 | vep_session->vep.vep_idx = ~0; |
| 1637 | vep_session->vep.next_sid = ~0; |
| 1638 | vep_session->vep.prev_sid = ~0; |
| 1639 | vep_session->wait_cont_idx = ~0; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1640 | vep_session->vpp_handle = ~0; |
Keith Burns (alagalah) | 1275651 | 2018-03-06 05:55:27 -0800 | [diff] [blame] | 1641 | vep_session->poll_reg = 0; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1642 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1643 | vcl_evt (VCL_EVT_EPOLL_CREATE, vep_session, vep_idx); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1644 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1645 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1646 | VDBG (0, "VCL<%d>: Created vep_idx %u / sid %u!", |
| 1647 | getpid (), vep_idx, vep_idx); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 1648 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1649 | return (vep_idx); |
| 1650 | } |
| 1651 | |
| 1652 | int |
| 1653 | vppcom_epoll_ctl (uint32_t vep_idx, int op, uint32_t session_index, |
| 1654 | struct epoll_event *event) |
| 1655 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1656 | vcl_session_t *vep_session; |
| 1657 | vcl_session_t *session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1658 | int rv; |
| 1659 | |
| 1660 | if (vep_idx == session_index) |
| 1661 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1662 | clib_warning ("VCL<%d>: ERROR: vep_idx == session_index (%u)!", |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1663 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1664 | return VPPCOM_EINVAL; |
| 1665 | } |
| 1666 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1667 | VCL_SESSION_LOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1668 | rv = vppcom_session_at_index (vep_idx, &vep_session); |
| 1669 | if (PREDICT_FALSE (rv)) |
| 1670 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1671 | clib_warning ("VCL<%d>: ERROR: Invalid vep_idx (%u)!", vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1672 | goto done; |
| 1673 | } |
| 1674 | if (PREDICT_FALSE (!vep_session->is_vep)) |
| 1675 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1676 | clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!", |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1677 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1678 | rv = VPPCOM_EINVAL; |
| 1679 | goto done; |
| 1680 | } |
| 1681 | |
| 1682 | ASSERT (vep_session->vep.vep_idx == ~0); |
| 1683 | ASSERT (vep_session->vep.prev_sid == ~0); |
| 1684 | |
| 1685 | rv = vppcom_session_at_index (session_index, &session); |
| 1686 | if (PREDICT_FALSE (rv)) |
| 1687 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1688 | VDBG (0, "VCL<%d>: ERROR: Invalid session_index (%u)!", |
| 1689 | getpid (), session_index); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1690 | goto done; |
| 1691 | } |
| 1692 | if (PREDICT_FALSE (session->is_vep)) |
| 1693 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1694 | clib_warning ("ERROR: session_index (%u) is a vep!", vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1695 | rv = VPPCOM_EINVAL; |
| 1696 | goto done; |
| 1697 | } |
| 1698 | |
| 1699 | switch (op) |
| 1700 | { |
| 1701 | case EPOLL_CTL_ADD: |
| 1702 | if (PREDICT_FALSE (!event)) |
| 1703 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1704 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_ADD: NULL pointer to " |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 1705 | "epoll_event structure!", getpid ()); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1706 | rv = VPPCOM_EINVAL; |
| 1707 | goto done; |
| 1708 | } |
| 1709 | if (vep_session->vep.next_sid != ~0) |
| 1710 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1711 | vcl_session_t *next_session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1712 | rv = vppcom_session_at_index (vep_session->vep.next_sid, |
| 1713 | &next_session); |
| 1714 | if (PREDICT_FALSE (rv)) |
| 1715 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1716 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_ADD: Invalid " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1717 | "vep.next_sid (%u) on vep_idx (%u)!", |
| 1718 | getpid (), vep_session->vep.next_sid, vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1719 | goto done; |
| 1720 | } |
| 1721 | ASSERT (next_session->vep.prev_sid == vep_idx); |
| 1722 | next_session->vep.prev_sid = session_index; |
| 1723 | } |
| 1724 | session->vep.next_sid = vep_session->vep.next_sid; |
| 1725 | session->vep.prev_sid = vep_idx; |
| 1726 | session->vep.vep_idx = vep_idx; |
| 1727 | session->vep.et_mask = VEP_DEFAULT_ET_MASK; |
| 1728 | session->vep.ev = *event; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1729 | session->is_vep = 0; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1730 | session->is_vep_session = 1; |
| 1731 | vep_session->vep.next_sid = session_index; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1732 | |
| 1733 | /* VCL Event Register handler */ |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1734 | if (session->session_state & STATE_LISTEN) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1735 | { |
| 1736 | /* Register handler for connect_request event on listen_session_index */ |
| 1737 | vce_event_key_t evk; |
| 1738 | evk.session_index = session_index; |
| 1739 | evk.eid = VCL_EVENT_CONNECT_REQ_ACCEPTED; |
Keith Burns (alagalah) | 1275651 | 2018-03-06 05:55:27 -0800 | [diff] [blame] | 1740 | vep_session->poll_reg = |
| 1741 | vce_register_handler (&vcm->event_thread, &evk, |
Keith Burns (alagalah) | 0d2b0d5 | 2018-03-06 15:55:22 -0800 | [diff] [blame] | 1742 | vce_poll_wait_connect_request_handler_fn, |
| 1743 | 0 /* No callback args */ ); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1744 | } |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1745 | VDBG (1, "VCL<%d>: EPOLL_CTL_ADD: vep_idx %u, " |
| 1746 | "sid %u, events 0x%x, data 0x%llx!", |
| 1747 | getpid (), vep_idx, session_index, |
| 1748 | event->events, event->data.u64); |
| 1749 | vcl_evt (VCL_EVT_EPOLL_CTLADD, session, event->events, event->data.u64); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1750 | break; |
| 1751 | |
| 1752 | case EPOLL_CTL_MOD: |
| 1753 | if (PREDICT_FALSE (!event)) |
| 1754 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1755 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_MOD: NULL pointer to " |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 1756 | "epoll_event structure!", getpid ()); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1757 | rv = VPPCOM_EINVAL; |
| 1758 | goto done; |
| 1759 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1760 | else if (PREDICT_FALSE (!session->is_vep_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1761 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1762 | clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_MOD: " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1763 | "not a vep session!", getpid (), session_index); |
| 1764 | rv = VPPCOM_EINVAL; |
| 1765 | goto done; |
| 1766 | } |
| 1767 | else if (PREDICT_FALSE (session->vep.vep_idx != vep_idx)) |
| 1768 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1769 | clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_MOD: " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1770 | "vep_idx (%u) != vep_idx (%u)!", |
| 1771 | getpid (), session_index, |
| 1772 | session->vep.vep_idx, vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1773 | rv = VPPCOM_EINVAL; |
| 1774 | goto done; |
| 1775 | } |
| 1776 | session->vep.et_mask = VEP_DEFAULT_ET_MASK; |
| 1777 | session->vep.ev = *event; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1778 | VDBG (1, "VCL<%d>: EPOLL_CTL_MOD: vep_idx %u, sid %u, events 0x%x," |
| 1779 | " data 0x%llx!", getpid (), vep_idx, session_index, event->events, |
| 1780 | event->data.u64); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1781 | break; |
| 1782 | |
| 1783 | case EPOLL_CTL_DEL: |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1784 | if (PREDICT_FALSE (!session->is_vep_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1785 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1786 | clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_DEL: " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1787 | "not a vep session!", getpid (), session_index); |
| 1788 | rv = VPPCOM_EINVAL; |
| 1789 | goto done; |
| 1790 | } |
| 1791 | else if (PREDICT_FALSE (session->vep.vep_idx != vep_idx)) |
| 1792 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1793 | clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_DEL: " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1794 | "vep_idx (%u) != vep_idx (%u)!", |
| 1795 | getpid (), session_index, |
| 1796 | session->vep.vep_idx, vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1797 | rv = VPPCOM_EINVAL; |
| 1798 | goto done; |
| 1799 | } |
| 1800 | |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1801 | /* VCL Event Un-register handler */ |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1802 | if ((session->session_state & STATE_LISTEN) && vep_session->poll_reg) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1803 | { |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 1804 | (void) vce_unregister_handler (&vcm->event_thread, |
| 1805 | vep_session->poll_reg); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1806 | } |
| 1807 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1808 | vep_session->wait_cont_idx = |
| 1809 | (vep_session->wait_cont_idx == session_index) ? |
| 1810 | session->vep.next_sid : vep_session->wait_cont_idx; |
| 1811 | |
| 1812 | if (session->vep.prev_sid == vep_idx) |
| 1813 | vep_session->vep.next_sid = session->vep.next_sid; |
| 1814 | else |
| 1815 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1816 | vcl_session_t *prev_session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1817 | rv = vppcom_session_at_index (session->vep.prev_sid, &prev_session); |
| 1818 | if (PREDICT_FALSE (rv)) |
| 1819 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1820 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_DEL: Invalid " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1821 | "vep.prev_sid (%u) on sid (%u)!", |
| 1822 | getpid (), session->vep.prev_sid, session_index); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1823 | goto done; |
| 1824 | } |
| 1825 | ASSERT (prev_session->vep.next_sid == session_index); |
| 1826 | prev_session->vep.next_sid = session->vep.next_sid; |
| 1827 | } |
| 1828 | if (session->vep.next_sid != ~0) |
| 1829 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1830 | vcl_session_t *next_session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1831 | rv = vppcom_session_at_index (session->vep.next_sid, &next_session); |
| 1832 | if (PREDICT_FALSE (rv)) |
| 1833 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1834 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_DEL: Invalid " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1835 | "vep.next_sid (%u) on sid (%u)!", |
| 1836 | getpid (), session->vep.next_sid, session_index); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1837 | goto done; |
| 1838 | } |
| 1839 | ASSERT (next_session->vep.prev_sid == session_index); |
| 1840 | next_session->vep.prev_sid = session->vep.prev_sid; |
| 1841 | } |
| 1842 | |
| 1843 | memset (&session->vep, 0, sizeof (session->vep)); |
| 1844 | session->vep.next_sid = ~0; |
| 1845 | session->vep.prev_sid = ~0; |
| 1846 | session->vep.vep_idx = ~0; |
| 1847 | session->is_vep_session = 0; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1848 | VDBG (1, "VCL<%d>: EPOLL_CTL_DEL: vep_idx %u, sid %u!", |
| 1849 | getpid (), vep_idx, session_index); |
| 1850 | vcl_evt (VCL_EVT_EPOLL_CTLDEL, session, vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1851 | break; |
| 1852 | |
| 1853 | default: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1854 | clib_warning ("VCL<%d>: ERROR: Invalid operation (%d)!", getpid (), op); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1855 | rv = VPPCOM_EINVAL; |
| 1856 | } |
| 1857 | |
| 1858 | vep_verify_epoll_chain (vep_idx); |
| 1859 | |
| 1860 | done: |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1861 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1862 | return rv; |
| 1863 | } |
| 1864 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1865 | int |
| 1866 | vppcom_epoll_wait (uint32_t vep_idx, struct epoll_event *events, |
| 1867 | int maxevents, double wait_for_time) |
| 1868 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1869 | vcl_session_t *vep_session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1870 | int rv; |
| 1871 | f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time; |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 1872 | u32 keep_trying = 1; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1873 | int num_ev = 0; |
| 1874 | u32 vep_next_sid, wait_cont_idx; |
| 1875 | u8 is_vep; |
| 1876 | |
| 1877 | if (PREDICT_FALSE (maxevents <= 0)) |
| 1878 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1879 | clib_warning ("VCL<%d>: ERROR: Invalid maxevents (%d)!", |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1880 | getpid (), maxevents); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1881 | return VPPCOM_EINVAL; |
| 1882 | } |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1883 | memset (events, 0, sizeof (*events) * maxevents); |
| 1884 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1885 | VCL_SESSION_LOCK_AND_GET (vep_idx, &vep_session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1886 | vep_next_sid = vep_session->vep.next_sid; |
| 1887 | is_vep = vep_session->is_vep; |
| 1888 | wait_cont_idx = vep_session->wait_cont_idx; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1889 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1890 | |
| 1891 | if (PREDICT_FALSE (!is_vep)) |
| 1892 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1893 | clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!", |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1894 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1895 | rv = VPPCOM_EINVAL; |
| 1896 | goto done; |
| 1897 | } |
Dave Wallace | e695cb4 | 2017-11-02 22:04:42 -0400 | [diff] [blame] | 1898 | if (PREDICT_FALSE (vep_next_sid == ~0)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1899 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1900 | VDBG (1, "VCL<%d>: WARNING: vep_idx (%u) is empty!", |
| 1901 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1902 | goto done; |
| 1903 | } |
| 1904 | |
| 1905 | do |
| 1906 | { |
| 1907 | u32 sid; |
| 1908 | u32 next_sid = ~0; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1909 | vcl_session_t *session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1910 | |
| 1911 | for (sid = (wait_cont_idx == ~0) ? vep_next_sid : wait_cont_idx; |
| 1912 | sid != ~0; sid = next_sid) |
| 1913 | { |
| 1914 | u32 session_events, et_mask, clear_et_mask, session_vep_idx; |
| 1915 | u8 add_event, is_vep_session; |
| 1916 | int ready; |
| 1917 | u64 session_ev_data; |
| 1918 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1919 | VCL_SESSION_LOCK_AND_GET (sid, &session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1920 | next_sid = session->vep.next_sid; |
| 1921 | session_events = session->vep.ev.events; |
| 1922 | et_mask = session->vep.et_mask; |
| 1923 | is_vep = session->is_vep; |
| 1924 | is_vep_session = session->is_vep_session; |
| 1925 | session_vep_idx = session->vep.vep_idx; |
| 1926 | session_ev_data = session->vep.ev.data.u64; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1927 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1928 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1929 | |
| 1930 | if (PREDICT_FALSE (is_vep)) |
| 1931 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1932 | VDBG (0, "VCL<%d>: ERROR: sid (%u) is a vep!", |
| 1933 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1934 | rv = VPPCOM_EINVAL; |
| 1935 | goto done; |
| 1936 | } |
| 1937 | if (PREDICT_FALSE (!is_vep_session)) |
| 1938 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1939 | VDBG (0, "VCL<%d>: ERROR: session (%u) is not " |
| 1940 | "a vep session!", getpid (), sid); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1941 | rv = VPPCOM_EINVAL; |
| 1942 | goto done; |
| 1943 | } |
| 1944 | if (PREDICT_FALSE (session_vep_idx != vep_idx)) |
| 1945 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1946 | clib_warning ("VCL<%d>: ERROR: session (%u) " |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1947 | "vep_idx (%u) != vep_idx (%u)!", |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1948 | getpid (), sid, session_vep_idx, vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1949 | rv = VPPCOM_EINVAL; |
| 1950 | goto done; |
| 1951 | } |
| 1952 | |
| 1953 | add_event = clear_et_mask = 0; |
| 1954 | |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1955 | if (EPOLLIN & session_events) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1956 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1957 | VCL_SESSION_LOCK_AND_GET (sid, &session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1958 | ready = vppcom_session_read_ready (session, sid); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1959 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1960 | if ((ready > 0) && (EPOLLIN & et_mask)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1961 | { |
| 1962 | add_event = 1; |
| 1963 | events[num_ev].events |= EPOLLIN; |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1964 | if (((EPOLLET | EPOLLIN) & session_events) == |
| 1965 | (EPOLLET | EPOLLIN)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1966 | clear_et_mask |= EPOLLIN; |
| 1967 | } |
| 1968 | else if (ready < 0) |
| 1969 | { |
| 1970 | add_event = 1; |
| 1971 | switch (ready) |
| 1972 | { |
| 1973 | case VPPCOM_ECONNRESET: |
| 1974 | events[num_ev].events |= EPOLLHUP | EPOLLRDHUP; |
| 1975 | break; |
| 1976 | |
| 1977 | default: |
| 1978 | events[num_ev].events |= EPOLLERR; |
| 1979 | break; |
| 1980 | } |
| 1981 | } |
| 1982 | } |
| 1983 | |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1984 | if (EPOLLOUT & session_events) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1985 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1986 | VCL_SESSION_LOCK_AND_GET (sid, &session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1987 | ready = vppcom_session_write_ready (session, sid); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 1988 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1989 | if ((ready > 0) && (EPOLLOUT & et_mask)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1990 | { |
| 1991 | add_event = 1; |
| 1992 | events[num_ev].events |= EPOLLOUT; |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1993 | if (((EPOLLET | EPOLLOUT) & session_events) == |
| 1994 | (EPOLLET | EPOLLOUT)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1995 | clear_et_mask |= EPOLLOUT; |
| 1996 | } |
| 1997 | else if (ready < 0) |
| 1998 | { |
| 1999 | add_event = 1; |
| 2000 | switch (ready) |
| 2001 | { |
| 2002 | case VPPCOM_ECONNRESET: |
| 2003 | events[num_ev].events |= EPOLLHUP; |
| 2004 | break; |
| 2005 | |
| 2006 | default: |
| 2007 | events[num_ev].events |= EPOLLERR; |
| 2008 | break; |
| 2009 | } |
| 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | if (add_event) |
| 2014 | { |
| 2015 | events[num_ev].data.u64 = session_ev_data; |
| 2016 | if (EPOLLONESHOT & session_events) |
| 2017 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2018 | VCL_SESSION_LOCK_AND_GET (sid, &session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2019 | session->vep.ev.events = 0; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2020 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2021 | } |
| 2022 | num_ev++; |
| 2023 | if (num_ev == maxevents) |
| 2024 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2025 | VCL_SESSION_LOCK_AND_GET (vep_idx, &vep_session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2026 | vep_session->wait_cont_idx = next_sid; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2027 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2028 | goto done; |
| 2029 | } |
| 2030 | } |
| 2031 | if (wait_cont_idx != ~0) |
| 2032 | { |
| 2033 | if (next_sid == ~0) |
| 2034 | next_sid = vep_next_sid; |
| 2035 | else if (next_sid == wait_cont_idx) |
| 2036 | next_sid = ~0; |
| 2037 | } |
| 2038 | } |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 2039 | if (wait_for_time != -1) |
| 2040 | keep_trying = (clib_time_now (&vcm->clib_time) <= timeout) ? 1 : 0; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2041 | } |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 2042 | while ((num_ev == 0) && keep_trying); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2043 | |
| 2044 | if (wait_cont_idx != ~0) |
| 2045 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2046 | VCL_SESSION_LOCK_AND_GET (vep_idx, &vep_session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2047 | vep_session->wait_cont_idx = ~0; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2048 | VCL_SESSION_UNLOCK (); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2049 | } |
| 2050 | done: |
| 2051 | return (rv != VPPCOM_OK) ? rv : num_ev; |
| 2052 | } |
| 2053 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2054 | int |
| 2055 | vppcom_session_attr (uint32_t session_index, uint32_t op, |
| 2056 | void *buffer, uint32_t * buflen) |
| 2057 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2058 | vcl_session_t *session; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2059 | int rv = VPPCOM_OK; |
| 2060 | u32 *flags = buffer; |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2061 | vppcom_endpt_t *ep = buffer; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2062 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2063 | VCL_SESSION_LOCK_AND_GET (session_index, &session); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2064 | |
| 2065 | ASSERT (session); |
| 2066 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2067 | switch (op) |
| 2068 | { |
| 2069 | case VPPCOM_ATTR_GET_NREAD: |
| 2070 | rv = vppcom_session_read_ready (session, session_index); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2071 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_NREAD: sid %u, nread = %d", |
| 2072 | getpid (), rv); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2073 | break; |
| 2074 | |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 2075 | case VPPCOM_ATTR_GET_NWRITE: |
| 2076 | rv = vppcom_session_write_ready (session, session_index); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2077 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_NWRITE: sid %u, nwrite = %d", |
| 2078 | getpid (), session_index, rv); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2079 | break; |
| 2080 | |
| 2081 | case VPPCOM_ATTR_GET_FLAGS: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2082 | if (PREDICT_TRUE (buffer && buflen && (*buflen >= sizeof (*flags)))) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2083 | { |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2084 | *flags = O_RDWR | (VCL_SESS_ATTR_TEST (session->attr, |
| 2085 | VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2086 | *buflen = sizeof (*flags); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2087 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_FLAGS: sid %u, flags = 0x%08x, " |
| 2088 | "is_nonblocking = %u", getpid (), |
| 2089 | session_index, *flags, |
| 2090 | VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2091 | } |
| 2092 | else |
| 2093 | rv = VPPCOM_EINVAL; |
| 2094 | break; |
| 2095 | |
| 2096 | case VPPCOM_ATTR_SET_FLAGS: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2097 | if (PREDICT_TRUE (buffer && buflen && (*buflen == sizeof (*flags)))) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2098 | { |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2099 | if (*flags & O_NONBLOCK) |
| 2100 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 2101 | else |
| 2102 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 2103 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2104 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_FLAGS: sid %u, flags = 0x%08x," |
| 2105 | " is_nonblocking = %u", |
| 2106 | getpid (), session_index, *flags, |
| 2107 | VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2108 | } |
| 2109 | else |
| 2110 | rv = VPPCOM_EINVAL; |
| 2111 | break; |
| 2112 | |
| 2113 | case VPPCOM_ATTR_GET_PEER_ADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2114 | if (PREDICT_TRUE (buffer && buflen && |
| 2115 | (*buflen >= sizeof (*ep)) && ep->ip)) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2116 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2117 | ep->is_ip4 = session->transport.is_ip4; |
| 2118 | ep->port = session->transport.rmt_port; |
| 2119 | if (session->transport.is_ip4) |
| 2120 | clib_memcpy (ep->ip, &session->transport.rmt_ip.ip4, |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2121 | sizeof (ip4_address_t)); |
| 2122 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2123 | clib_memcpy (ep->ip, &session->transport.rmt_ip.ip6, |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2124 | sizeof (ip6_address_t)); |
| 2125 | *buflen = sizeof (*ep); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2126 | VDBG (1, "VCL<%d>: VPPCOM_ATTR_GET_PEER_ADDR: sid %u, is_ip4 = %u, " |
| 2127 | "addr = %U, port %u", getpid (), |
| 2128 | session_index, ep->is_ip4, format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2129 | &session->transport.rmt_ip, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2130 | ep->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 2131 | clib_net_to_host_u16 (ep->port)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2132 | } |
| 2133 | else |
| 2134 | rv = VPPCOM_EINVAL; |
| 2135 | break; |
| 2136 | |
| 2137 | case VPPCOM_ATTR_GET_LCL_ADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2138 | if (PREDICT_TRUE (buffer && buflen && |
| 2139 | (*buflen >= sizeof (*ep)) && ep->ip)) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2140 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2141 | ep->is_ip4 = session->transport.is_ip4; |
| 2142 | ep->port = session->transport.lcl_port; |
| 2143 | if (session->transport.is_ip4) |
| 2144 | clib_memcpy (ep->ip, &session->transport.lcl_ip.ip4, |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2145 | sizeof (ip4_address_t)); |
| 2146 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2147 | clib_memcpy (ep->ip, &session->transport.lcl_ip.ip6, |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2148 | sizeof (ip6_address_t)); |
| 2149 | *buflen = sizeof (*ep); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2150 | VDBG (1, "VCL<%d>: VPPCOM_ATTR_GET_LCL_ADDR: sid %u, is_ip4 = %u," |
| 2151 | " addr = %U port %d", getpid (), |
| 2152 | session_index, ep->is_ip4, format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2153 | &session->transport.lcl_ip, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2154 | ep->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 2155 | clib_net_to_host_u16 (ep->port)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2156 | } |
| 2157 | else |
| 2158 | rv = VPPCOM_EINVAL; |
| 2159 | break; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2160 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2161 | case VPPCOM_ATTR_GET_LIBC_EPFD: |
| 2162 | rv = session->libc_epfd; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2163 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_LIBC_EPFD: libc_epfd %d", |
| 2164 | getpid (), rv); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2165 | break; |
| 2166 | |
| 2167 | case VPPCOM_ATTR_SET_LIBC_EPFD: |
| 2168 | if (PREDICT_TRUE (buffer && buflen && |
| 2169 | (*buflen == sizeof (session->libc_epfd)))) |
| 2170 | { |
| 2171 | session->libc_epfd = *(int *) buffer; |
| 2172 | *buflen = sizeof (session->libc_epfd); |
| 2173 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2174 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_LIBC_EPFD: libc_epfd %d, " |
| 2175 | "buflen %d", getpid (), session->libc_epfd, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2176 | } |
| 2177 | else |
| 2178 | rv = VPPCOM_EINVAL; |
| 2179 | break; |
| 2180 | |
| 2181 | case VPPCOM_ATTR_GET_PROTOCOL: |
| 2182 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2183 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2184 | *(int *) buffer = session->session_type; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2185 | *buflen = sizeof (int); |
| 2186 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2187 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_PROTOCOL: %d (%s), buflen %d", |
| 2188 | getpid (), *(int *) buffer, *(int *) buffer ? "UDP" : "TCP", |
| 2189 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2190 | } |
| 2191 | else |
| 2192 | rv = VPPCOM_EINVAL; |
| 2193 | break; |
| 2194 | |
| 2195 | case VPPCOM_ATTR_GET_LISTEN: |
| 2196 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2197 | { |
| 2198 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2199 | VCL_SESS_ATTR_LISTEN); |
| 2200 | *buflen = sizeof (int); |
| 2201 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2202 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_LISTEN: %d, buflen %d", |
| 2203 | getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2204 | } |
| 2205 | else |
| 2206 | rv = VPPCOM_EINVAL; |
| 2207 | break; |
| 2208 | |
| 2209 | case VPPCOM_ATTR_GET_ERROR: |
| 2210 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2211 | { |
| 2212 | *(int *) buffer = 0; |
| 2213 | *buflen = sizeof (int); |
| 2214 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2215 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_ERROR: %d, buflen %d, #VPP-TBD#", |
| 2216 | getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2217 | } |
| 2218 | else |
| 2219 | rv = VPPCOM_EINVAL; |
| 2220 | break; |
| 2221 | |
| 2222 | case VPPCOM_ATTR_GET_TX_FIFO_LEN: |
| 2223 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 2224 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2225 | |
| 2226 | /* VPP-TBD */ |
| 2227 | *(size_t *) buffer = (session->sndbuf_size ? session->sndbuf_size : |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2228 | session->tx_fifo ? session->tx_fifo->nitems : |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2229 | vcm->cfg.tx_fifo_size); |
| 2230 | *buflen = sizeof (u32); |
| 2231 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2232 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TX_FIFO_LEN: %u (0x%x), " |
| 2233 | "buflen %d, #VPP-TBD#", getpid (), |
| 2234 | *(size_t *) buffer, *(size_t *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2235 | } |
| 2236 | else |
| 2237 | rv = VPPCOM_EINVAL; |
| 2238 | break; |
| 2239 | |
| 2240 | case VPPCOM_ATTR_SET_TX_FIFO_LEN: |
| 2241 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 2242 | { |
| 2243 | /* VPP-TBD */ |
| 2244 | session->sndbuf_size = *(u32 *) buffer; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2245 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TX_FIFO_LEN: %u (0x%x), " |
| 2246 | "buflen %d, #VPP-TBD#", getpid (), |
| 2247 | session->sndbuf_size, session->sndbuf_size, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2248 | } |
| 2249 | else |
| 2250 | rv = VPPCOM_EINVAL; |
| 2251 | break; |
| 2252 | |
| 2253 | case VPPCOM_ATTR_GET_RX_FIFO_LEN: |
| 2254 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 2255 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2256 | |
| 2257 | /* VPP-TBD */ |
| 2258 | *(size_t *) buffer = (session->rcvbuf_size ? session->rcvbuf_size : |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2259 | session->rx_fifo ? session->rx_fifo->nitems : |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2260 | vcm->cfg.rx_fifo_size); |
| 2261 | *buflen = sizeof (u32); |
| 2262 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2263 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_RX_FIFO_LEN: %u (0x%x), " |
| 2264 | "buflen %d, #VPP-TBD#", getpid (), |
| 2265 | *(size_t *) buffer, *(size_t *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2266 | } |
| 2267 | else |
| 2268 | rv = VPPCOM_EINVAL; |
| 2269 | break; |
| 2270 | |
| 2271 | case VPPCOM_ATTR_SET_RX_FIFO_LEN: |
| 2272 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 2273 | { |
| 2274 | /* VPP-TBD */ |
| 2275 | session->rcvbuf_size = *(u32 *) buffer; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2276 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_RX_FIFO_LEN: %u (0x%x), " |
| 2277 | "buflen %d, #VPP-TBD#", getpid (), |
| 2278 | session->sndbuf_size, session->sndbuf_size, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2279 | } |
| 2280 | else |
| 2281 | rv = VPPCOM_EINVAL; |
| 2282 | break; |
| 2283 | |
| 2284 | case VPPCOM_ATTR_GET_REUSEADDR: |
| 2285 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2286 | { |
| 2287 | /* VPP-TBD */ |
| 2288 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2289 | VCL_SESS_ATTR_REUSEADDR); |
| 2290 | *buflen = sizeof (int); |
| 2291 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2292 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_REUSEADDR: %d, " |
| 2293 | "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2294 | } |
| 2295 | else |
| 2296 | rv = VPPCOM_EINVAL; |
| 2297 | break; |
| 2298 | |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2299 | case VPPCOM_ATTR_SET_REUSEADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2300 | if (buffer && buflen && (*buflen == sizeof (int)) && |
| 2301 | !VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_LISTEN)) |
| 2302 | { |
| 2303 | /* VPP-TBD */ |
| 2304 | if (*(int *) buffer) |
| 2305 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_REUSEADDR); |
| 2306 | else |
| 2307 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_REUSEADDR); |
| 2308 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2309 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_REUSEADDR: %d, buflen %d," |
| 2310 | " #VPP-TBD#", getpid (), |
| 2311 | VCL_SESS_ATTR_TEST (session->attr, |
| 2312 | VCL_SESS_ATTR_REUSEADDR), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2313 | } |
| 2314 | else |
| 2315 | rv = VPPCOM_EINVAL; |
| 2316 | break; |
| 2317 | |
| 2318 | case VPPCOM_ATTR_GET_REUSEPORT: |
| 2319 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2320 | { |
| 2321 | /* VPP-TBD */ |
| 2322 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2323 | VCL_SESS_ATTR_REUSEPORT); |
| 2324 | *buflen = sizeof (int); |
| 2325 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2326 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_REUSEPORT: %d, buflen %d," |
| 2327 | " #VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2328 | } |
| 2329 | else |
| 2330 | rv = VPPCOM_EINVAL; |
| 2331 | break; |
| 2332 | |
| 2333 | case VPPCOM_ATTR_SET_REUSEPORT: |
| 2334 | if (buffer && buflen && (*buflen == sizeof (int)) && |
| 2335 | !VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_LISTEN)) |
| 2336 | { |
| 2337 | /* VPP-TBD */ |
| 2338 | if (*(int *) buffer) |
| 2339 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_REUSEPORT); |
| 2340 | else |
| 2341 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_REUSEPORT); |
| 2342 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2343 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_REUSEPORT: %d, buflen %d," |
| 2344 | " #VPP-TBD#", getpid (), |
| 2345 | VCL_SESS_ATTR_TEST (session->attr, |
| 2346 | VCL_SESS_ATTR_REUSEPORT), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2347 | } |
| 2348 | else |
| 2349 | rv = VPPCOM_EINVAL; |
| 2350 | break; |
| 2351 | |
| 2352 | case VPPCOM_ATTR_GET_BROADCAST: |
| 2353 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2354 | { |
| 2355 | /* VPP-TBD */ |
| 2356 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2357 | VCL_SESS_ATTR_BROADCAST); |
| 2358 | *buflen = sizeof (int); |
| 2359 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2360 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_BROADCAST: %d, buflen %d," |
| 2361 | " #VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2362 | } |
| 2363 | else |
| 2364 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2365 | break; |
| 2366 | |
| 2367 | case VPPCOM_ATTR_SET_BROADCAST: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2368 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2369 | { |
| 2370 | /* VPP-TBD */ |
| 2371 | if (*(int *) buffer) |
| 2372 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_BROADCAST); |
| 2373 | else |
| 2374 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_BROADCAST); |
| 2375 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2376 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_BROADCAST: %d, buflen %d, " |
| 2377 | "#VPP-TBD#", getpid (), |
| 2378 | VCL_SESS_ATTR_TEST (session->attr, |
| 2379 | VCL_SESS_ATTR_BROADCAST), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2380 | } |
| 2381 | else |
| 2382 | rv = VPPCOM_EINVAL; |
| 2383 | break; |
| 2384 | |
| 2385 | case VPPCOM_ATTR_GET_V6ONLY: |
| 2386 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2387 | { |
| 2388 | /* VPP-TBD */ |
| 2389 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2390 | VCL_SESS_ATTR_V6ONLY); |
| 2391 | *buflen = sizeof (int); |
| 2392 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2393 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_V6ONLY: %d, buflen %d, " |
| 2394 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2395 | } |
| 2396 | else |
| 2397 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2398 | break; |
| 2399 | |
| 2400 | case VPPCOM_ATTR_SET_V6ONLY: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2401 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2402 | { |
| 2403 | /* VPP-TBD */ |
| 2404 | if (*(int *) buffer) |
| 2405 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_V6ONLY); |
| 2406 | else |
| 2407 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_V6ONLY); |
| 2408 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2409 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_V6ONLY: %d, buflen %d, " |
| 2410 | "#VPP-TBD#", getpid (), |
| 2411 | VCL_SESS_ATTR_TEST (session->attr, |
| 2412 | VCL_SESS_ATTR_V6ONLY), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2413 | } |
| 2414 | else |
| 2415 | rv = VPPCOM_EINVAL; |
| 2416 | break; |
| 2417 | |
| 2418 | case VPPCOM_ATTR_GET_KEEPALIVE: |
| 2419 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2420 | { |
| 2421 | /* VPP-TBD */ |
| 2422 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2423 | VCL_SESS_ATTR_KEEPALIVE); |
| 2424 | *buflen = sizeof (int); |
| 2425 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2426 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_KEEPALIVE: %d, buflen %d, " |
| 2427 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2428 | } |
| 2429 | else |
| 2430 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2431 | break; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 2432 | |
| 2433 | case VPPCOM_ATTR_SET_KEEPALIVE: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2434 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2435 | { |
| 2436 | /* VPP-TBD */ |
| 2437 | if (*(int *) buffer) |
| 2438 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_KEEPALIVE); |
| 2439 | else |
| 2440 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_KEEPALIVE); |
| 2441 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2442 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_KEEPALIVE: %d, buflen %d, " |
| 2443 | "#VPP-TBD#", getpid (), |
| 2444 | VCL_SESS_ATTR_TEST (session->attr, |
| 2445 | VCL_SESS_ATTR_KEEPALIVE), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2446 | } |
| 2447 | else |
| 2448 | rv = VPPCOM_EINVAL; |
| 2449 | break; |
| 2450 | |
| 2451 | case VPPCOM_ATTR_GET_TCP_NODELAY: |
| 2452 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2453 | { |
| 2454 | /* VPP-TBD */ |
| 2455 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2456 | VCL_SESS_ATTR_TCP_NODELAY); |
| 2457 | *buflen = sizeof (int); |
| 2458 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2459 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TCP_NODELAY: %d, buflen %d, " |
| 2460 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2461 | } |
| 2462 | else |
| 2463 | rv = VPPCOM_EINVAL; |
| 2464 | break; |
| 2465 | |
| 2466 | case VPPCOM_ATTR_SET_TCP_NODELAY: |
| 2467 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2468 | { |
| 2469 | /* VPP-TBD */ |
| 2470 | if (*(int *) buffer) |
| 2471 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_NODELAY); |
| 2472 | else |
| 2473 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_NODELAY); |
| 2474 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2475 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TCP_NODELAY: %d, buflen %d, " |
| 2476 | "#VPP-TBD#", getpid (), |
| 2477 | VCL_SESS_ATTR_TEST (session->attr, |
| 2478 | VCL_SESS_ATTR_TCP_NODELAY), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2479 | } |
| 2480 | else |
| 2481 | rv = VPPCOM_EINVAL; |
| 2482 | break; |
| 2483 | |
| 2484 | case VPPCOM_ATTR_GET_TCP_KEEPIDLE: |
| 2485 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2486 | { |
| 2487 | /* VPP-TBD */ |
| 2488 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2489 | VCL_SESS_ATTR_TCP_KEEPIDLE); |
| 2490 | *buflen = sizeof (int); |
| 2491 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2492 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TCP_KEEPIDLE: %d, buflen %d, " |
| 2493 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2494 | } |
| 2495 | else |
| 2496 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 2497 | break; |
| 2498 | |
| 2499 | case VPPCOM_ATTR_SET_TCP_KEEPIDLE: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2500 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2501 | { |
| 2502 | /* VPP-TBD */ |
| 2503 | if (*(int *) buffer) |
| 2504 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_KEEPIDLE); |
| 2505 | else |
| 2506 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_KEEPIDLE); |
| 2507 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2508 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TCP_KEEPIDLE: %d, buflen %d, " |
| 2509 | "#VPP-TBD#", getpid (), |
| 2510 | VCL_SESS_ATTR_TEST (session->attr, |
| 2511 | VCL_SESS_ATTR_TCP_KEEPIDLE), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2512 | } |
| 2513 | else |
| 2514 | rv = VPPCOM_EINVAL; |
| 2515 | break; |
| 2516 | |
| 2517 | case VPPCOM_ATTR_GET_TCP_KEEPINTVL: |
| 2518 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2519 | { |
| 2520 | /* VPP-TBD */ |
| 2521 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2522 | VCL_SESS_ATTR_TCP_KEEPINTVL); |
| 2523 | *buflen = sizeof (int); |
| 2524 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2525 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TCP_KEEPINTVL: %d, buflen %d, " |
| 2526 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2527 | } |
| 2528 | else |
| 2529 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 2530 | break; |
| 2531 | |
| 2532 | case VPPCOM_ATTR_SET_TCP_KEEPINTVL: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2533 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2534 | { |
| 2535 | /* VPP-TBD */ |
| 2536 | if (*(int *) buffer) |
| 2537 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_KEEPINTVL); |
| 2538 | else |
| 2539 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_KEEPINTVL); |
| 2540 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2541 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TCP_KEEPINTVL: %d, buflen %d, " |
| 2542 | "#VPP-TBD#", getpid (), |
| 2543 | VCL_SESS_ATTR_TEST (session->attr, |
| 2544 | VCL_SESS_ATTR_TCP_KEEPINTVL), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2545 | } |
| 2546 | else |
| 2547 | rv = VPPCOM_EINVAL; |
| 2548 | break; |
| 2549 | |
| 2550 | case VPPCOM_ATTR_GET_TCP_USER_MSS: |
| 2551 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 2552 | { |
| 2553 | /* VPP-TBD */ |
| 2554 | *(u32 *) buffer = session->user_mss; |
| 2555 | *buflen = sizeof (int); |
| 2556 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2557 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TCP_USER_MSS: %d, buflen %d," |
| 2558 | " #VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2559 | } |
| 2560 | else |
| 2561 | rv = VPPCOM_EINVAL; |
| 2562 | break; |
| 2563 | |
| 2564 | case VPPCOM_ATTR_SET_TCP_USER_MSS: |
| 2565 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 2566 | { |
| 2567 | /* VPP-TBD */ |
| 2568 | session->user_mss = *(u32 *) buffer; |
| 2569 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2570 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TCP_USER_MSS: %u, buflen %d, " |
| 2571 | "#VPP-TBD#", getpid (), session->user_mss, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2572 | } |
| 2573 | else |
| 2574 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 2575 | break; |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 2576 | |
| 2577 | default: |
| 2578 | rv = VPPCOM_EINVAL; |
| 2579 | break; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | done: |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2583 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2584 | return rv; |
| 2585 | } |
| 2586 | |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2587 | int |
| 2588 | vppcom_session_recvfrom (uint32_t session_index, void *buffer, |
| 2589 | uint32_t buflen, int flags, vppcom_endpt_t * ep) |
| 2590 | { |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2591 | int rv = VPPCOM_OK; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2592 | vcl_session_t *session = 0; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2593 | |
| 2594 | if (ep) |
| 2595 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2596 | VCL_SESSION_LOCK (); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2597 | rv = vppcom_session_at_index (session_index, &session); |
| 2598 | if (PREDICT_FALSE (rv)) |
| 2599 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2600 | VCL_SESSION_UNLOCK (); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2601 | VDBG (0, "VCL<%d>: invalid session, sid (%u) has been closed!", |
| 2602 | getpid (), session_index); |
Dave Wallace | faf9d77 | 2017-10-26 16:12:04 -0400 | [diff] [blame] | 2603 | rv = VPPCOM_EBADFD; |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2604 | VCL_SESSION_UNLOCK (); |
Dave Wallace | faf9d77 | 2017-10-26 16:12:04 -0400 | [diff] [blame] | 2605 | goto done; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2606 | } |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2607 | ep->is_ip4 = session->transport.is_ip4; |
| 2608 | ep->port = session->transport.rmt_port; |
| 2609 | if (session->transport.is_ip4) |
| 2610 | clib_memcpy (ep->ip, &session->transport.rmt_ip.ip4, |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2611 | sizeof (ip4_address_t)); |
| 2612 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2613 | clib_memcpy (ep->ip, &session->transport.rmt_ip.ip6, |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2614 | sizeof (ip6_address_t)); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2615 | VCL_SESSION_UNLOCK (); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2616 | } |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 2617 | |
| 2618 | if (flags == 0) |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2619 | rv = vppcom_session_read (session_index, buffer, buflen); |
| 2620 | else if (flags & MSG_PEEK) |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 2621 | rv = vppcom_session_peek (session_index, buffer, buflen); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2622 | else |
| 2623 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2624 | clib_warning ("VCL<%d>: Unsupport flags for recvfrom %d", |
| 2625 | getpid (), flags); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2626 | rv = VPPCOM_EAFNOSUPPORT; |
| 2627 | } |
| 2628 | |
Dave Wallace | faf9d77 | 2017-10-26 16:12:04 -0400 | [diff] [blame] | 2629 | done: |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2630 | return rv; |
| 2631 | } |
| 2632 | |
| 2633 | int |
| 2634 | vppcom_session_sendto (uint32_t session_index, void *buffer, |
| 2635 | uint32_t buflen, int flags, vppcom_endpt_t * ep) |
| 2636 | { |
Dave Wallace | 617dffa | 2017-10-26 14:47:06 -0400 | [diff] [blame] | 2637 | if (!buffer) |
| 2638 | return VPPCOM_EINVAL; |
| 2639 | |
| 2640 | if (ep) |
| 2641 | { |
| 2642 | // TBD |
| 2643 | return VPPCOM_EINVAL; |
| 2644 | } |
| 2645 | |
| 2646 | if (flags) |
| 2647 | { |
| 2648 | // TBD check the flags and do the right thing |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2649 | VDBG (2, "VCL<%d>: handling flags 0x%u (%d) not implemented yet.", |
| 2650 | getpid (), flags, flags); |
Dave Wallace | 617dffa | 2017-10-26 14:47:06 -0400 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | return (vppcom_session_write (session_index, buffer, buflen)); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2656 | int |
| 2657 | vppcom_poll (vcl_poll_t * vp, uint32_t n_sids, double wait_for_time) |
| 2658 | { |
| 2659 | f64 timeout = clib_time_now (&vcm->clib_time) + wait_for_time; |
| 2660 | u32 i, keep_trying = 1; |
| 2661 | int rv, num_ev = 0; |
| 2662 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2663 | VDBG (3, "VCL<%d>: vp %p, nsids %u, wait_for_time %f", |
| 2664 | getpid (), vp, n_sids, wait_for_time); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2665 | |
| 2666 | if (!vp) |
| 2667 | return VPPCOM_EFAULT; |
| 2668 | |
| 2669 | do |
| 2670 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2671 | vcl_session_t *session; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2672 | |
| 2673 | for (i = 0; i < n_sids; i++) |
| 2674 | { |
| 2675 | ASSERT (vp[i].revents); |
| 2676 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2677 | VCL_SESSION_LOCK_AND_GET (vp[i].sid, &session); |
| 2678 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2679 | |
| 2680 | if (*vp[i].revents) |
| 2681 | *vp[i].revents = 0; |
| 2682 | |
| 2683 | if (POLLIN & vp[i].events) |
| 2684 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2685 | VCL_SESSION_LOCK_AND_GET (vp[i].sid, &session); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2686 | rv = vppcom_session_read_ready (session, vp[i].sid); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2687 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2688 | if (rv > 0) |
| 2689 | { |
| 2690 | *vp[i].revents |= POLLIN; |
| 2691 | num_ev++; |
| 2692 | } |
| 2693 | else if (rv < 0) |
| 2694 | { |
| 2695 | switch (rv) |
| 2696 | { |
| 2697 | case VPPCOM_ECONNRESET: |
| 2698 | *vp[i].revents = POLLHUP; |
| 2699 | break; |
| 2700 | |
| 2701 | default: |
| 2702 | *vp[i].revents = POLLERR; |
| 2703 | break; |
| 2704 | } |
| 2705 | num_ev++; |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | if (POLLOUT & vp[i].events) |
| 2710 | { |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2711 | VCL_SESSION_LOCK_AND_GET (vp[i].sid, &session); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2712 | rv = vppcom_session_write_ready (session, vp[i].sid); |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2713 | VCL_SESSION_UNLOCK (); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2714 | if (rv > 0) |
| 2715 | { |
| 2716 | *vp[i].revents |= POLLOUT; |
| 2717 | num_ev++; |
| 2718 | } |
| 2719 | else if (rv < 0) |
| 2720 | { |
| 2721 | switch (rv) |
| 2722 | { |
| 2723 | case VPPCOM_ECONNRESET: |
| 2724 | *vp[i].revents = POLLHUP; |
| 2725 | break; |
| 2726 | |
| 2727 | default: |
| 2728 | *vp[i].revents = POLLERR; |
| 2729 | break; |
| 2730 | } |
| 2731 | num_ev++; |
| 2732 | } |
| 2733 | } |
| 2734 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 2735 | if (0) // Note "done:" label used by VCL_SESSION_LOCK_AND_GET() |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2736 | { |
| 2737 | done: |
| 2738 | *vp[i].revents = POLLNVAL; |
| 2739 | num_ev++; |
| 2740 | } |
| 2741 | } |
| 2742 | if (wait_for_time != -1) |
| 2743 | keep_trying = (clib_time_now (&vcm->clib_time) <= timeout) ? 1 : 0; |
| 2744 | } |
| 2745 | while ((num_ev == 0) && keep_trying); |
| 2746 | |
| 2747 | if (VPPCOM_DEBUG > 3) |
| 2748 | { |
| 2749 | clib_warning ("VCL<%d>: returning %d", getpid (), num_ev); |
| 2750 | for (i = 0; i < n_sids; i++) |
| 2751 | { |
| 2752 | clib_warning ("VCL<%d>: vp[%d].sid %d (0x%x), .events 0x%x, " |
| 2753 | ".revents 0x%x", getpid (), i, vp[i].sid, vp[i].sid, |
| 2754 | vp[i].events, *vp[i].revents); |
| 2755 | } |
| 2756 | } |
| 2757 | return num_ev; |
| 2758 | } |
| 2759 | |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 2760 | /* |
| 2761 | * fd.io coding-style-patch-verification: ON |
| 2762 | * |
| 2763 | * Local Variables: |
| 2764 | * eval: (c-set-style "gnu") |
| 2765 | * End: |
| 2766 | */ |