Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2 | *------------------------------------------------------------------ |
| 3 | * memclnt_shared.c - API message handling, common code for both clients |
| 4 | * and the vlib process itself. |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 5 | * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 6 | * |
| 7 | * Copyright (c) 2009 Cisco and/or its affiliates. |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at: |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | *------------------------------------------------------------------ |
| 20 | */ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
Ole Troan | 6855f6c | 2016-04-09 03:16:30 +0200 | [diff] [blame] | 24 | #include <stddef.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | #include <string.h> |
| 26 | #include <unistd.h> |
| 27 | #include <signal.h> |
| 28 | #include <vppinfra/format.h> |
| 29 | #include <vppinfra/byte_order.h> |
| 30 | #include <vppinfra/error.h> |
| 31 | #include <vlib/vlib.h> |
| 32 | #include <vlib/unix/unix.h> |
| 33 | #include <vlibmemory/api.h> |
| 34 | #include <vlibmemory/unix_shared_memory_queue.h> |
| 35 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 36 | #include <vlibmemory/vl_memory_msg_enum.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 38 | #define vl_typedefs |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | #include <vlibmemory/vl_memory_api_h.h> |
| 40 | #undef vl_typedefs |
| 41 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 42 | socket_main_t socket_main; |
| 43 | |
| 44 | #define DEBUG_MESSAGE_BUFFER_OVERRUN 0 |
| 45 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 46 | static inline void * |
Dave Barach | 7737833 | 2016-10-13 17:35:09 -0400 | [diff] [blame] | 47 | vl_msg_api_alloc_internal (int nbytes, int pool, int may_return_null) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 49 | int i; |
| 50 | msgbuf_t *rv; |
| 51 | ring_alloc_t *ap; |
| 52 | unix_shared_memory_queue_t *q; |
| 53 | void *oldheap; |
| 54 | vl_shmem_hdr_t *shmem_hdr; |
| 55 | api_main_t *am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 57 | shmem_hdr = am->shmem_hdr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 59 | #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0 |
| 60 | nbytes += 4; |
| 61 | #endif |
| 62 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 63 | if (shmem_hdr == 0) |
| 64 | { |
| 65 | clib_warning ("shared memory header NULL"); |
| 66 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 69 | /* account for the msgbuf_t header */ |
| 70 | nbytes += sizeof (msgbuf_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 72 | if (shmem_hdr->vl_rings == 0) |
| 73 | { |
| 74 | clib_warning ("vl_rings NULL"); |
Dave Barach | 7737833 | 2016-10-13 17:35:09 -0400 | [diff] [blame] | 75 | ASSERT (0); |
| 76 | abort (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 79 | if (shmem_hdr->client_rings == 0) |
| 80 | { |
| 81 | clib_warning ("client_rings NULL"); |
Dave Barach | 7737833 | 2016-10-13 17:35:09 -0400 | [diff] [blame] | 82 | ASSERT (0); |
| 83 | abort (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 86 | ap = pool ? shmem_hdr->vl_rings : shmem_hdr->client_rings; |
| 87 | for (i = 0; i < vec_len (ap); i++) |
| 88 | { |
| 89 | /* Too big? */ |
| 90 | if (nbytes > ap[i].size) |
| 91 | { |
| 92 | continue; |
| 93 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 95 | q = ap[i].rp; |
| 96 | if (pool == 0) |
| 97 | { |
| 98 | pthread_mutex_lock (&q->mutex); |
| 99 | } |
| 100 | rv = (msgbuf_t *) (&q->data[0] + q->head * q->elsize); |
| 101 | /* |
| 102 | * Is this item still in use? |
| 103 | */ |
| 104 | if (rv->q) |
| 105 | { |
Dave Barach | 842b9c5 | 2017-01-09 15:54:00 -0500 | [diff] [blame] | 106 | u32 now = (u32) time (0); |
| 107 | |
| 108 | if (PREDICT_TRUE (rv->gc_mark_timestamp == 0)) |
| 109 | rv->gc_mark_timestamp = now; |
| 110 | else |
| 111 | { |
| 112 | if (now - rv->gc_mark_timestamp > 10) |
| 113 | { |
| 114 | if (CLIB_DEBUG > 0) |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 115 | { |
| 116 | u16 *msg_idp, msg_id; |
| 117 | clib_warning |
| 118 | ("garbage collect pool %d ring %d index %d", pool, i, |
| 119 | q->head); |
| 120 | msg_idp = (u16 *) (rv->data); |
| 121 | msg_id = clib_net_to_host_u16 (*msg_idp); |
| 122 | if (msg_id < vec_len (api_main.msg_names)) |
| 123 | clib_warning ("msg id %d name %s", (u32) msg_id, |
| 124 | api_main.msg_names[msg_id]); |
| 125 | } |
Dave Barach | 842b9c5 | 2017-01-09 15:54:00 -0500 | [diff] [blame] | 126 | shmem_hdr->garbage_collects++; |
| 127 | goto collected; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 132 | /* yes, loser; try next larger pool */ |
| 133 | ap[i].misses++; |
| 134 | if (pool == 0) |
| 135 | pthread_mutex_unlock (&q->mutex); |
| 136 | continue; |
| 137 | } |
Dave Barach | 842b9c5 | 2017-01-09 15:54:00 -0500 | [diff] [blame] | 138 | collected: |
| 139 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 140 | /* OK, we have a winner */ |
| 141 | ap[i].hits++; |
| 142 | /* |
| 143 | * Remember the source queue, although we |
| 144 | * don't need to know the queue to free the item. |
| 145 | */ |
| 146 | rv->q = q; |
Dave Barach | 842b9c5 | 2017-01-09 15:54:00 -0500 | [diff] [blame] | 147 | rv->gc_mark_timestamp = 0; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 148 | q->head++; |
| 149 | if (q->head == q->maxsize) |
| 150 | q->head = 0; |
| 151 | |
| 152 | if (pool == 0) |
| 153 | pthread_mutex_unlock (&q->mutex); |
| 154 | goto out; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 157 | /* |
| 158 | * Request too big, or head element of all size-compatible rings |
| 159 | * still in use. Fall back to shared-memory malloc. |
| 160 | */ |
| 161 | am->ring_misses++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 162 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 163 | pthread_mutex_lock (&am->vlib_rp->mutex); |
| 164 | oldheap = svm_push_data_heap (am->vlib_rp); |
Dave Barach | 7737833 | 2016-10-13 17:35:09 -0400 | [diff] [blame] | 165 | if (may_return_null) |
| 166 | { |
| 167 | rv = clib_mem_alloc_or_null (nbytes); |
| 168 | if (PREDICT_FALSE (rv == 0)) |
| 169 | { |
| 170 | svm_pop_heap (oldheap); |
| 171 | pthread_mutex_unlock (&am->vlib_rp->mutex); |
| 172 | return 0; |
| 173 | } |
| 174 | } |
| 175 | else |
| 176 | rv = clib_mem_alloc (nbytes); |
| 177 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 178 | rv->q = 0; |
| 179 | svm_pop_heap (oldheap); |
| 180 | pthread_mutex_unlock (&am->vlib_rp->mutex); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 182 | out: |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 183 | #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0 |
| 184 | { |
| 185 | nbytes -= 4; |
| 186 | u32 *overrun; |
| 187 | overrun = (u32 *) (rv->data + nbytes - sizeof (msgbuf_t)); |
| 188 | *overrun = 0x1badbabe; |
| 189 | } |
| 190 | #endif |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 191 | rv->data_len = htonl (nbytes - sizeof (msgbuf_t)); |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 192 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 193 | return (rv->data); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 196 | void * |
| 197 | vl_msg_api_alloc (int nbytes) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 199 | int pool; |
| 200 | api_main_t *am = &api_main; |
| 201 | vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 202 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 203 | /* |
| 204 | * Clients use pool-0, vlib proc uses pool 1 |
| 205 | */ |
| 206 | pool = (am->our_pid == shmem_hdr->vl_pid); |
Dave Barach | 7737833 | 2016-10-13 17:35:09 -0400 | [diff] [blame] | 207 | return vl_msg_api_alloc_internal (nbytes, pool, 0 /* may_return_null */ ); |
| 208 | } |
| 209 | |
| 210 | void * |
| 211 | vl_msg_api_alloc_or_null (int nbytes) |
| 212 | { |
| 213 | int pool; |
| 214 | api_main_t *am = &api_main; |
| 215 | vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; |
| 216 | |
| 217 | pool = (am->our_pid == shmem_hdr->vl_pid); |
| 218 | return vl_msg_api_alloc_internal (nbytes, pool, 1 /* may_return_null */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 221 | void * |
| 222 | vl_msg_api_alloc_as_if_client (int nbytes) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 223 | { |
Dave Barach | 7737833 | 2016-10-13 17:35:09 -0400 | [diff] [blame] | 224 | return vl_msg_api_alloc_internal (nbytes, 0, 0 /* may_return_null */ ); |
| 225 | } |
| 226 | |
| 227 | void * |
| 228 | vl_msg_api_alloc_as_if_client_or_null (int nbytes) |
| 229 | { |
| 230 | return vl_msg_api_alloc_internal (nbytes, 0, 1 /* may_return_null */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 233 | void |
| 234 | vl_msg_api_free (void *a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 236 | msgbuf_t *rv; |
| 237 | void *oldheap; |
| 238 | api_main_t *am = &api_main; |
Ole Troan | 6855f6c | 2016-04-09 03:16:30 +0200 | [diff] [blame] | 239 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 240 | rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data)); |
| 241 | |
| 242 | /* |
| 243 | * Here's the beauty of the scheme. Only one proc/thread has |
| 244 | * control of a given message buffer. To free a buffer, we just clear the |
| 245 | * queue field, and leave. No locks, no hits, no errors... |
| 246 | */ |
| 247 | if (rv->q) |
| 248 | { |
| 249 | rv->q = 0; |
Dave Barach | 842b9c5 | 2017-01-09 15:54:00 -0500 | [diff] [blame] | 250 | rv->gc_mark_timestamp = 0; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 251 | #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0 |
| 252 | { |
| 253 | u32 *overrun; |
| 254 | overrun = (u32 *) (rv->data + ntohl (rv->data_len)); |
| 255 | ASSERT (*overrun == 0x1badbabe); |
| 256 | } |
| 257 | #endif |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 258 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 261 | pthread_mutex_lock (&am->vlib_rp->mutex); |
| 262 | oldheap = svm_push_data_heap (am->vlib_rp); |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 263 | |
| 264 | #if DEBUG_MESSAGE_BUFFER_OVERRUN > 0 |
| 265 | { |
| 266 | u32 *overrun; |
| 267 | overrun = (u32 *) (rv->data + ntohl (rv->data_len)); |
| 268 | ASSERT (*overrun == 0x1badbabe); |
| 269 | } |
| 270 | #endif |
| 271 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 272 | clib_mem_free (rv); |
| 273 | svm_pop_heap (oldheap); |
| 274 | pthread_mutex_unlock (&am->vlib_rp->mutex); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 277 | static void |
| 278 | vl_msg_api_free_nolock (void *a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 279 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 280 | msgbuf_t *rv; |
| 281 | void *oldheap; |
| 282 | api_main_t *am = &api_main; |
| 283 | |
| 284 | rv = (msgbuf_t *) (((u8 *) a) - offsetof (msgbuf_t, data)); |
| 285 | /* |
| 286 | * Here's the beauty of the scheme. Only one proc/thread has |
| 287 | * control of a given message buffer. To free a buffer, we just clear the |
| 288 | * queue field, and leave. No locks, no hits, no errors... |
| 289 | */ |
| 290 | if (rv->q) |
| 291 | { |
| 292 | rv->q = 0; |
| 293 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 296 | oldheap = svm_push_data_heap (am->vlib_rp); |
| 297 | clib_mem_free (rv); |
| 298 | svm_pop_heap (oldheap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 301 | void |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 302 | vl_set_memory_root_path (const char *name) |
Dave Barach | 309bef2 | 2016-01-22 16:09:52 -0500 | [diff] [blame] | 303 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 304 | api_main_t *am = &api_main; |
Dave Barach | 309bef2 | 2016-01-22 16:09:52 -0500 | [diff] [blame] | 305 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 306 | am->root_path = name; |
Dave Barach | 309bef2 | 2016-01-22 16:09:52 -0500 | [diff] [blame] | 307 | } |
| 308 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 309 | void |
| 310 | vl_set_memory_uid (int uid) |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 311 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 312 | api_main_t *am = &api_main; |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 313 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 314 | am->api_uid = uid; |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 315 | } |
| 316 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 317 | void |
| 318 | vl_set_memory_gid (int gid) |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 319 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 320 | api_main_t *am = &api_main; |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 321 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 322 | am->api_gid = gid; |
Dave Barach | 16c75df | 2016-05-31 14:05:46 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 325 | void |
| 326 | vl_set_global_memory_baseva (u64 baseva) |
| 327 | { |
| 328 | api_main_t *am = &api_main; |
| 329 | |
| 330 | am->global_baseva = baseva; |
| 331 | } |
| 332 | |
| 333 | void |
| 334 | vl_set_global_memory_size (u64 size) |
| 335 | { |
| 336 | api_main_t *am = &api_main; |
| 337 | |
| 338 | am->global_size = size; |
| 339 | } |
| 340 | |
| 341 | void |
| 342 | vl_set_api_memory_size (u64 size) |
| 343 | { |
| 344 | api_main_t *am = &api_main; |
| 345 | |
| 346 | am->api_size = size; |
| 347 | } |
| 348 | |
| 349 | void |
| 350 | vl_set_global_pvt_heap_size (u64 size) |
| 351 | { |
| 352 | api_main_t *am = &api_main; |
| 353 | |
| 354 | am->global_pvt_heap_size = size; |
| 355 | } |
| 356 | |
| 357 | void |
| 358 | vl_set_api_pvt_heap_size (u64 size) |
| 359 | { |
| 360 | api_main_t *am = &api_main; |
| 361 | |
| 362 | am->api_pvt_heap_size = size; |
| 363 | } |
| 364 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 365 | void |
| 366 | vl_init_shmem (svm_region_t * vlib_rp, int is_vlib, int is_private_region) |
| 367 | { |
| 368 | api_main_t *am = &api_main; |
| 369 | vl_shmem_hdr_t *shmem_hdr = 0; |
| 370 | u32 vlib_input_queue_length; |
| 371 | void *oldheap; |
| 372 | ASSERT (vlib_rp); |
| 373 | |
| 374 | /* $$$$ need private region config parameters */ |
| 375 | |
| 376 | oldheap = svm_push_data_heap (vlib_rp); |
| 377 | |
| 378 | vec_validate (shmem_hdr, 0); |
| 379 | shmem_hdr->version = VL_SHM_VERSION; |
| 380 | |
| 381 | /* vlib main input queue */ |
| 382 | vlib_input_queue_length = 1024; |
| 383 | if (am->vlib_input_queue_length) |
| 384 | vlib_input_queue_length = am->vlib_input_queue_length; |
| 385 | |
| 386 | shmem_hdr->vl_input_queue = |
| 387 | unix_shared_memory_queue_init (vlib_input_queue_length, sizeof (uword), |
| 388 | getpid (), am->vlib_signal); |
| 389 | |
| 390 | /* Set up the msg ring allocator */ |
| 391 | #define _(sz,n) \ |
| 392 | do { \ |
| 393 | ring_alloc_t _rp; \ |
| 394 | _rp.rp = unix_shared_memory_queue_init ((n), (sz), 0, 0); \ |
| 395 | _rp.size = (sz); \ |
| 396 | _rp.nitems = n; \ |
| 397 | _rp.hits = 0; \ |
| 398 | _rp.misses = 0; \ |
| 399 | vec_add1(shmem_hdr->vl_rings, _rp); \ |
| 400 | } while (0); |
| 401 | |
| 402 | foreach_vl_aring_size; |
| 403 | #undef _ |
| 404 | |
| 405 | #define _(sz,n) \ |
| 406 | do { \ |
| 407 | ring_alloc_t _rp; \ |
| 408 | _rp.rp = unix_shared_memory_queue_init ((n), (sz), 0, 0); \ |
| 409 | _rp.size = (sz); \ |
| 410 | _rp.nitems = n; \ |
| 411 | _rp.hits = 0; \ |
| 412 | _rp.misses = 0; \ |
| 413 | vec_add1(shmem_hdr->client_rings, _rp); \ |
| 414 | } while (0); |
| 415 | |
| 416 | foreach_clnt_aring_size; |
| 417 | #undef _ |
| 418 | |
| 419 | if (is_private_region == 0) |
| 420 | { |
| 421 | am->shmem_hdr = shmem_hdr; |
| 422 | am->vlib_rp = vlib_rp; |
| 423 | am->our_pid = getpid (); |
| 424 | if (is_vlib) |
| 425 | am->shmem_hdr->vl_pid = am->our_pid; |
| 426 | } |
| 427 | else |
| 428 | shmem_hdr->vl_pid = am->our_pid; |
| 429 | |
| 430 | svm_pop_heap (oldheap); |
| 431 | |
| 432 | /* |
| 433 | * After absolutely everything that a client might see is set up, |
| 434 | * declare the shmem region valid |
| 435 | */ |
| 436 | vlib_rp->user_ctx = shmem_hdr; |
| 437 | |
| 438 | pthread_mutex_unlock (&vlib_rp->mutex); |
| 439 | } |
| 440 | |
| 441 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 442 | int |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 443 | vl_map_shmem (const char *region_name, int is_vlib) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 445 | svm_map_region_args_t _a, *a = &_a; |
| 446 | svm_region_t *vlib_rp, *root_rp; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 447 | api_main_t *am = &api_main; |
Ole Troan | 3cdc25f | 2017-08-17 11:07:33 +0200 | [diff] [blame] | 448 | int i, rv; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 449 | struct timespec ts, tsrem; |
Dave Wallace | cfc997e | 2017-08-22 18:32:34 -0400 | [diff] [blame] | 450 | char *vpe_api_region_suffix = "-vpe-api"; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 451 | |
Jan Srnicek | 5beec81 | 2017-03-24 10:18:11 +0100 | [diff] [blame] | 452 | memset (a, 0, sizeof (*a)); |
| 453 | |
Dave Wallace | cfc997e | 2017-08-22 18:32:34 -0400 | [diff] [blame] | 454 | if (strstr (region_name, vpe_api_region_suffix)) |
Jan Srnicek | 5beec81 | 2017-03-24 10:18:11 +0100 | [diff] [blame] | 455 | { |
Dave Wallace | cfc997e | 2017-08-22 18:32:34 -0400 | [diff] [blame] | 456 | u8 *root_path = format (0, "%s", region_name); |
| 457 | _vec_len (root_path) = (vec_len (root_path) - |
| 458 | strlen (vpe_api_region_suffix)); |
| 459 | vec_terminate_c_string (root_path); |
| 460 | a->root_path = (const char *) root_path; |
| 461 | am->root_path = (const char *) root_path; |
Jan Srnicek | 5beec81 | 2017-03-24 10:18:11 +0100 | [diff] [blame] | 462 | } |
| 463 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 464 | if (is_vlib == 0) |
Ole Troan | 3cdc25f | 2017-08-17 11:07:33 +0200 | [diff] [blame] | 465 | { |
| 466 | rv = svm_region_init_chroot (am->root_path); |
| 467 | if (rv) |
| 468 | return rv; |
| 469 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 470 | |
Jan Srnicek | 5beec81 | 2017-03-24 10:18:11 +0100 | [diff] [blame] | 471 | if (a->root_path != NULL) |
| 472 | { |
| 473 | a->name = "/vpe-api"; |
| 474 | } |
| 475 | else |
| 476 | a->name = region_name; |
Dave Barach | c379999 | 2016-08-15 11:12:27 -0400 | [diff] [blame] | 477 | a->size = am->api_size ? am->api_size : (16 << 20); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 478 | a->flags = SVM_FLAGS_MHEAP; |
| 479 | a->uid = am->api_uid; |
| 480 | a->gid = am->api_gid; |
Dave Barach | b3d93da | 2016-08-03 14:34:38 -0400 | [diff] [blame] | 481 | a->pvt_heap_size = am->api_pvt_heap_size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 482 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 483 | vlib_rp = svm_region_find_or_create (a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 484 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 485 | if (vlib_rp == 0) |
| 486 | return (-2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 487 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 488 | pthread_mutex_lock (&vlib_rp->mutex); |
| 489 | /* Has someone else set up the shared-memory variable table? */ |
| 490 | if (vlib_rp->user_ctx) |
| 491 | { |
| 492 | am->shmem_hdr = (void *) vlib_rp->user_ctx; |
| 493 | am->our_pid = getpid (); |
| 494 | if (is_vlib) |
| 495 | { |
| 496 | unix_shared_memory_queue_t *q; |
| 497 | uword old_msg; |
| 498 | /* |
| 499 | * application restart. Reset cached pids, API message |
| 500 | * rings, list of clients; otherwise, various things |
| 501 | * fail. (e.g. queue non-empty notification) |
| 502 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 503 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 504 | /* ghosts keep the region from disappearing properly */ |
| 505 | svm_client_scan_this_region_nolock (vlib_rp); |
| 506 | am->shmem_hdr->application_restarts++; |
| 507 | q = am->shmem_hdr->vl_input_queue; |
| 508 | am->shmem_hdr->vl_pid = getpid (); |
| 509 | q->consumer_pid = am->shmem_hdr->vl_pid; |
| 510 | /* Drain the input queue, freeing msgs */ |
| 511 | for (i = 0; i < 10; i++) |
| 512 | { |
| 513 | if (pthread_mutex_trylock (&q->mutex) == 0) |
| 514 | { |
| 515 | pthread_mutex_unlock (&q->mutex); |
| 516 | goto mutex_ok; |
| 517 | } |
| 518 | ts.tv_sec = 0; |
| 519 | ts.tv_nsec = 10000 * 1000; /* 10 ms */ |
| 520 | while (nanosleep (&ts, &tsrem) < 0) |
| 521 | ts = tsrem; |
| 522 | } |
| 523 | /* Mutex buggered, "fix" it */ |
| 524 | memset (&q->mutex, 0, sizeof (q->mutex)); |
| 525 | clib_warning ("forcibly release main input queue mutex"); |
| 526 | |
| 527 | mutex_ok: |
| 528 | am->vlib_rp = vlib_rp; |
| 529 | while (unix_shared_memory_queue_sub (q, |
| 530 | (u8 *) & old_msg, |
| 531 | 1 /* nowait */ ) |
| 532 | != -2 /* queue underflow */ ) |
| 533 | { |
| 534 | vl_msg_api_free_nolock ((void *) old_msg); |
| 535 | am->shmem_hdr->restart_reclaims++; |
| 536 | } |
| 537 | pthread_mutex_unlock (&vlib_rp->mutex); |
| 538 | root_rp = svm_get_root_rp (); |
| 539 | ASSERT (root_rp); |
| 540 | /* Clean up the root region client list */ |
| 541 | pthread_mutex_lock (&root_rp->mutex); |
| 542 | svm_client_scan_this_region_nolock (root_rp); |
| 543 | pthread_mutex_unlock (&root_rp->mutex); |
| 544 | } |
| 545 | else |
| 546 | { |
| 547 | pthread_mutex_unlock (&vlib_rp->mutex); |
| 548 | } |
| 549 | am->vlib_rp = vlib_rp; |
| 550 | vec_add1 (am->mapped_shmem_regions, vlib_rp); |
| 551 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 552 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 553 | /* Clients simply have to wait... */ |
| 554 | if (!is_vlib) |
| 555 | { |
| 556 | pthread_mutex_unlock (&vlib_rp->mutex); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 557 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 558 | /* Wait up to 100 seconds... */ |
| 559 | for (i = 0; i < 10000; i++) |
| 560 | { |
| 561 | ts.tv_sec = 0; |
| 562 | ts.tv_nsec = 10000 * 1000; /* 10 ms */ |
| 563 | while (nanosleep (&ts, &tsrem) < 0) |
| 564 | ts = tsrem; |
| 565 | if (vlib_rp->user_ctx) |
| 566 | goto ready; |
| 567 | } |
| 568 | /* Clean up and leave... */ |
| 569 | svm_region_unmap (vlib_rp); |
| 570 | clib_warning ("region init fail"); |
| 571 | return (-2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 572 | |
| 573 | ready: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 574 | am->shmem_hdr = (void *) vlib_rp->user_ctx; |
| 575 | am->our_pid = getpid (); |
| 576 | am->vlib_rp = vlib_rp; |
| 577 | vec_add1 (am->mapped_shmem_regions, vlib_rp); |
| 578 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 581 | /* Nope, it's our problem... */ |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 582 | vl_init_shmem (vlib_rp, 1 /* is vlib */ , 0 /* is_private_region */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 583 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 584 | vec_add1 (am->mapped_shmem_regions, vlib_rp); |
| 585 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 588 | void |
| 589 | vl_register_mapped_shmem_region (svm_region_t * rp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 590 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 591 | api_main_t *am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 592 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 593 | vec_add1 (am->mapped_shmem_regions, rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 596 | void |
| 597 | vl_unmap_shmem (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 598 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 599 | svm_region_t *rp; |
| 600 | int i; |
| 601 | api_main_t *am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 602 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 603 | if (!svm_get_root_rp ()) |
| 604 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 605 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 606 | for (i = 0; i < vec_len (am->mapped_shmem_regions); i++) |
| 607 | { |
| 608 | rp = am->mapped_shmem_regions[i]; |
| 609 | svm_region_unmap (rp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 612 | vec_free (am->mapped_shmem_regions); |
| 613 | am->shmem_hdr = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 614 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 615 | svm_region_exit (); |
| 616 | /* $$$ more careful cleanup, valgrind run... */ |
| 617 | vec_free (am->msg_handlers); |
| 618 | vec_free (am->msg_endian_handlers); |
| 619 | vec_free (am->msg_print_handlers); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 622 | void |
| 623 | vl_msg_api_send_shmem (unix_shared_memory_queue_t * q, u8 * elem) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 624 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 625 | api_main_t *am = &api_main; |
| 626 | uword *trace = (uword *) elem; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 627 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 628 | if (am->tx_trace && am->tx_trace->enabled) |
| 629 | vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 630 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 631 | (void) unix_shared_memory_queue_add (q, elem, 0 /* nowait */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 634 | void |
| 635 | vl_msg_api_send_shmem_nolock (unix_shared_memory_queue_t * q, u8 * elem) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 636 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 637 | api_main_t *am = &api_main; |
| 638 | uword *trace = (uword *) elem; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 639 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 640 | if (am->tx_trace && am->tx_trace->enabled) |
| 641 | vl_msg_api_trace (am, am->tx_trace, (void *) trace[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 642 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 643 | (void) unix_shared_memory_queue_add_nolock (q, elem); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 646 | u32 |
| 647 | vl_api_get_msg_index (u8 * name_and_crc) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 648 | { |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 649 | api_main_t *am = &api_main; |
| 650 | uword *p; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 651 | |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 652 | if (am->msg_index_by_name_and_crc) |
| 653 | { |
| 654 | p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc); |
| 655 | if (p) |
| 656 | return p[0]; |
| 657 | } |
| 658 | return ~0; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 659 | } |
| 660 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 661 | static inline vl_api_registration_t * |
| 662 | vl_api_client_index_to_registration_internal (u32 handle) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 663 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 664 | vl_api_registration_t **regpp; |
| 665 | vl_api_registration_t *regp; |
| 666 | api_main_t *am = &api_main; |
| 667 | u32 index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 668 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 669 | index = vl_msg_api_handle_get_index (handle); |
| 670 | if ((am->shmem_hdr->application_restarts & VL_API_EPOCH_MASK) |
| 671 | != vl_msg_api_handle_get_epoch (handle)) |
| 672 | { |
| 673 | vl_msg_api_increment_missing_client_counter (); |
| 674 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 677 | regpp = am->vl_clients + index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 678 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 679 | if (pool_is_free (am->vl_clients, regpp)) |
| 680 | { |
| 681 | vl_msg_api_increment_missing_client_counter (); |
| 682 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 683 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 684 | regp = *regpp; |
| 685 | return (regp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 688 | vl_api_registration_t * |
| 689 | vl_api_client_index_to_registration (u32 index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 690 | { |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 691 | if (PREDICT_FALSE (socket_main.current_rp != 0)) |
| 692 | return socket_main.current_rp; |
| 693 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 694 | return (vl_api_client_index_to_registration_internal (index)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 695 | } |
| 696 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 697 | unix_shared_memory_queue_t * |
| 698 | vl_api_client_index_to_input_queue (u32 index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 699 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 700 | vl_api_registration_t *regp; |
Dave Barach | fc262a0 | 2016-12-14 14:49:55 -0500 | [diff] [blame] | 701 | api_main_t *am = &api_main; |
| 702 | |
| 703 | /* Special case: vlib trying to send itself a message */ |
| 704 | if (index == (u32) ~ 0) |
| 705 | return (am->shmem_hdr->vl_input_queue); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 706 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 707 | regp = vl_api_client_index_to_registration_internal (index); |
| 708 | if (!regp) |
| 709 | return 0; |
| 710 | return (regp->vl_input_queue); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 713 | /* |
| 714 | * fd.io coding-style-patch-verification: ON |
| 715 | * |
| 716 | * Local Variables: |
| 717 | * eval: (c-set-style "gnu") |
| 718 | * End: |
| 719 | */ |