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 | * api_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> |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 24 | #include <stddef.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | #include <string.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | #include <vppinfra/format.h> |
| 27 | #include <vppinfra/byte_order.h> |
| 28 | #include <vppinfra/error.h> |
| 29 | #include <vlib/vlib.h> |
| 30 | #include <vlib/unix/unix.h> |
| 31 | #include <vlibapi/api.h> |
| 32 | #include <vppinfra/elog.h> |
| 33 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 34 | /* *INDENT-OFF* */ |
| 35 | api_main_t api_main = |
| 36 | { |
| 37 | .region_name = "/unset", |
| 38 | .api_uid = -1, |
| 39 | .api_gid = -1, |
| 40 | }; |
| 41 | /* *INDENT-ON* */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 42 | |
| 43 | void |
| 44 | vl_msg_api_increment_missing_client_counter (void) |
| 45 | { |
| 46 | api_main_t *am = &api_main; |
| 47 | am->missing_clients++; |
| 48 | } |
| 49 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 50 | int |
| 51 | vl_msg_api_rx_trace_enabled (api_main_t * am) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 53 | return (am->rx_trace && am->rx_trace->enabled); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 56 | int |
| 57 | vl_msg_api_tx_trace_enabled (api_main_t * am) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 59 | return (am->tx_trace && am->tx_trace->enabled); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /* |
| 63 | * vl_msg_api_trace |
| 64 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 65 | void |
| 66 | vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 68 | u8 **this_trace; |
| 69 | u8 **old_trace; |
| 70 | u8 *msg_copy; |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 71 | u32 length; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 72 | trace_cfg_t *cfgp; |
| 73 | u16 msg_id = ntohs (*((u16 *) msg)); |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 74 | msgbuf_t *header = (msgbuf_t *) (((u8 *) msg) - offsetof (msgbuf_t, data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 76 | cfgp = am->api_trace_cfg + msg_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 78 | if (!cfgp || !cfgp->trace_enable) |
| 79 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 81 | msg_copy = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 83 | if (tp->nitems == 0) |
| 84 | { |
| 85 | clib_warning ("tp->nitems is 0"); |
| 86 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 89 | if (vec_len (tp->traces) < tp->nitems) |
| 90 | { |
| 91 | vec_add1 (tp->traces, 0); |
| 92 | this_trace = tp->traces + vec_len (tp->traces) - 1; |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | tp->wrapped = 1; |
| 97 | old_trace = tp->traces + tp->curindex++; |
| 98 | if (tp->curindex == tp->nitems) |
| 99 | tp->curindex = 0; |
| 100 | vec_free (*old_trace); |
| 101 | this_trace = old_trace; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 104 | length = clib_net_to_host_u32 (header->data_len); |
| 105 | |
| 106 | vec_validate (msg_copy, length - 1); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 107 | clib_memcpy_fast (msg_copy, msg, length); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 108 | *this_trace = msg_copy; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 111 | int |
| 112 | vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which, |
| 113 | int onoff) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 115 | vl_api_trace_t *tp; |
| 116 | int rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 117 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 118 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | { |
| 120 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 121 | tp = am->tx_trace; |
| 122 | if (tp == 0) |
| 123 | { |
| 124 | vl_msg_api_trace_configure (am, which, 1024); |
| 125 | tp = am->tx_trace; |
| 126 | } |
| 127 | break; |
| 128 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 129 | case VL_API_TRACE_RX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 130 | tp = am->rx_trace; |
| 131 | if (tp == 0) |
| 132 | { |
| 133 | vl_msg_api_trace_configure (am, which, 1024); |
| 134 | tp = am->rx_trace; |
| 135 | } |
| 136 | break; |
| 137 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 139 | /* duh? */ |
| 140 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 143 | /* Configured? */ |
| 144 | if (tp == 0 || tp->nitems == 0) |
| 145 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 147 | rv = tp->enabled; |
| 148 | tp->enabled = onoff; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 150 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 153 | int |
| 154 | vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 155 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 156 | vl_api_trace_t *tp; |
| 157 | int i; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 159 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 160 | { |
| 161 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 162 | tp = am->tx_trace; |
| 163 | break; |
| 164 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 165 | case VL_API_TRACE_RX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 166 | tp = am->rx_trace; |
| 167 | break; |
| 168 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 170 | /* duh? */ |
| 171 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 174 | /* Configured? */ |
| 175 | if (!tp || tp->nitems == 0) |
| 176 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 178 | tp->curindex = 0; |
| 179 | tp->wrapped = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 181 | for (i = 0; i < vec_len (tp->traces); i++) |
| 182 | { |
| 183 | vec_free (tp->traces[i]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 184 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 185 | vec_free (tp->traces); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 187 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 190 | int |
| 191 | vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 192 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 193 | vl_api_trace_t *tp; |
| 194 | vl_api_trace_file_header_t fh; |
| 195 | int i; |
| 196 | u8 *msg; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 197 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 198 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 199 | { |
| 200 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 201 | tp = am->tx_trace; |
| 202 | break; |
| 203 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 204 | case VL_API_TRACE_RX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 205 | tp = am->rx_trace; |
| 206 | break; |
| 207 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 208 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 209 | /* duh? */ |
| 210 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 213 | /* Configured, data present? */ |
| 214 | if (tp == 0 || tp->nitems == 0 || vec_len (tp->traces) == 0) |
| 215 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 216 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 217 | /* "Dare to be stupid" check */ |
| 218 | if (fp == 0) |
| 219 | { |
| 220 | return -2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 223 | /* Write the file header */ |
| 224 | fh.nitems = vec_len (tp->traces); |
| 225 | fh.endian = tp->endian; |
| 226 | fh.wrapped = tp->wrapped; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 227 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 228 | if (fwrite (&fh, sizeof (fh), 1, fp) != 1) |
| 229 | { |
| 230 | return (-10); |
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 | /* No-wrap case */ |
| 234 | if (tp->wrapped == 0) |
| 235 | { |
| 236 | /* |
| 237 | * Note: vec_len return 0 when fed a NULL pointer. |
| 238 | * Unfortunately, the static analysis tool doesn't |
| 239 | * figure it out, hence the suppressed warnings. |
| 240 | * What a great use of my time. |
| 241 | */ |
| 242 | for (i = 0; i < vec_len (tp->traces); i++) |
| 243 | { |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 244 | u32 msg_length; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 245 | /*sa_ignore NO_NULL_CHK */ |
| 246 | msg = tp->traces[i]; |
| 247 | /* |
| 248 | * This retarded check required to pass |
| 249 | * [sic] SA-checking. |
| 250 | */ |
| 251 | if (!msg) |
| 252 | continue; |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 253 | |
| 254 | msg_length = clib_host_to_net_u32 (vec_len (msg)); |
| 255 | if (fwrite (&msg_length, 1, sizeof (msg_length), fp) |
| 256 | != sizeof (msg_length)) |
| 257 | { |
| 258 | return (-14); |
| 259 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 260 | if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg)) |
| 261 | { |
| 262 | return (-11); |
| 263 | } |
| 264 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 266 | else |
| 267 | { |
| 268 | /* Wrap case: write oldest -> end of buffer */ |
| 269 | for (i = tp->curindex; i < vec_len (tp->traces); i++) |
| 270 | { |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 271 | u32 msg_length; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 272 | msg = tp->traces[i]; |
| 273 | /* |
| 274 | * This retarded check required to pass |
| 275 | * [sic] SA-checking |
| 276 | */ |
| 277 | if (!msg) |
| 278 | continue; |
| 279 | |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 280 | msg_length = clib_host_to_net_u32 (vec_len (msg)); |
| 281 | if (fwrite (&msg_length, 1, sizeof (msg_length), fp) |
| 282 | != sizeof (msg_length)) |
| 283 | { |
| 284 | return (-14); |
| 285 | } |
| 286 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 287 | if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg)) |
| 288 | { |
| 289 | return (-12); |
| 290 | } |
| 291 | } |
| 292 | /* write beginning of buffer -> oldest-1 */ |
| 293 | for (i = 0; i < tp->curindex; i++) |
| 294 | { |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 295 | u32 msg_length; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 296 | /*sa_ignore NO_NULL_CHK */ |
| 297 | msg = tp->traces[i]; |
| 298 | /* |
| 299 | * This retarded check required to pass |
| 300 | * [sic] SA-checking |
| 301 | */ |
| 302 | if (!msg) |
| 303 | continue; |
| 304 | |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 305 | msg_length = clib_host_to_net_u32 (vec_len (msg)); |
| 306 | if (fwrite (&msg_length, 1, sizeof (msg_length), fp) |
| 307 | != sizeof (msg_length)) |
| 308 | { |
| 309 | return (-14); |
| 310 | } |
| 311 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 312 | if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg)) |
| 313 | { |
| 314 | return (-13); |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 321 | int |
| 322 | vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which, |
| 323 | u32 nitems) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 324 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 325 | vl_api_trace_t *tp; |
| 326 | int was_on = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 327 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 328 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | { |
| 330 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 331 | tp = am->tx_trace; |
| 332 | if (tp == 0) |
| 333 | { |
| 334 | vec_validate (am->tx_trace, 0); |
| 335 | tp = am->tx_trace; |
| 336 | } |
| 337 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 338 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 339 | case VL_API_TRACE_RX: |
| 340 | tp = am->rx_trace; |
| 341 | if (tp == 0) |
| 342 | { |
| 343 | vec_validate (am->rx_trace, 0); |
| 344 | tp = am->rx_trace; |
| 345 | } |
| 346 | |
| 347 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 348 | |
| 349 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 350 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 351 | |
| 352 | } |
| 353 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 354 | if (tp->enabled) |
| 355 | { |
| 356 | was_on = vl_msg_api_trace_onoff (am, which, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 357 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 358 | if (tp->traces) |
| 359 | { |
| 360 | vl_msg_api_trace_free (am, which); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 363 | clib_memset (tp, 0, sizeof (*tp)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 364 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 365 | if (clib_arch_is_big_endian) |
| 366 | { |
| 367 | tp->endian = VL_API_BIG_ENDIAN; |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | tp->endian = VL_API_LITTLE_ENDIAN; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 374 | tp->nitems = nitems; |
| 375 | if (was_on) |
| 376 | { |
| 377 | (void) vl_msg_api_trace_onoff (am, which, was_on); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 378 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 379 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 382 | void |
| 383 | vl_msg_api_barrier_sync (void) |
| 384 | { |
| 385 | } |
| 386 | |
| 387 | void |
| 388 | vl_msg_api_barrier_release (void) |
| 389 | { |
| 390 | } |
| 391 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 392 | always_inline void |
| 393 | msg_handler_internal (api_main_t * am, |
| 394 | void *the_msg, int trace_it, int do_it, int free_it) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 395 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 396 | u16 id = ntohs (*((u16 *) the_msg)); |
| 397 | u8 *(*print_fp) (void *, void *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 398 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 399 | if (id < vec_len (am->msg_handlers) && am->msg_handlers[id]) |
| 400 | { |
| 401 | if (trace_it) |
| 402 | vl_msg_api_trace (am, am->rx_trace, the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 404 | if (am->msg_print_flag) |
| 405 | { |
| 406 | fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]); |
| 407 | print_fp = (void *) am->msg_print_handlers[id]; |
| 408 | if (print_fp == 0) |
| 409 | { |
| 410 | fformat (stdout, " [no registered print fn]\n"); |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | (*print_fp) (the_msg, stdout); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | if (do_it) |
| 419 | { |
| 420 | if (!am->is_mp_safe[id]) |
Colin Tregenza Dancer | eb1ac17 | 2017-09-06 20:23:24 +0100 | [diff] [blame] | 421 | { |
| 422 | vl_msg_api_barrier_trace_context (am->msg_names[id]); |
| 423 | vl_msg_api_barrier_sync (); |
| 424 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 425 | (*am->msg_handlers[id]) (the_msg); |
| 426 | if (!am->is_mp_safe[id]) |
| 427 | vl_msg_api_barrier_release (); |
| 428 | } |
| 429 | } |
| 430 | else |
| 431 | { |
| 432 | clib_warning ("no handler for msg id %d", id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 435 | if (free_it) |
| 436 | vl_msg_api_free (the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 439 | static u32 |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 440 | elog_id_for_msg_name (vlib_main_t * vm, const char *msg_name) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 441 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 442 | uword *p, r; |
| 443 | static uword *h; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | u8 *name_copy; |
| 445 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 446 | if (!h) |
| 447 | h = hash_create_string (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 448 | |
| 449 | p = hash_get_mem (h, msg_name); |
| 450 | if (p) |
| 451 | return p[0]; |
| 452 | r = elog_string (&vm->elog_main, "%s", msg_name); |
| 453 | |
| 454 | name_copy = format (0, "%s%c", msg_name, 0); |
| 455 | |
| 456 | hash_set_mem (h, name_copy, r); |
| 457 | |
| 458 | return r; |
| 459 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | |
| 461 | /* This is only to be called from a vlib/vnet app */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 462 | void |
| 463 | vl_msg_api_handler_with_vm_node (api_main_t * am, |
| 464 | void *the_msg, vlib_main_t * vm, |
| 465 | vlib_node_runtime_t * node) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 466 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 467 | u16 id = ntohs (*((u16 *) the_msg)); |
| 468 | u8 *(*handler) (void *, void *, void *); |
ezkexma | 75f9fb6 | 2019-03-21 07:38:19 -0400 | [diff] [blame] | 469 | u8 *(*print_fp) (void *, void *); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 470 | |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 471 | if (PREDICT_FALSE (vm->elog_trace_api_messages)) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 472 | { |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 473 | /* *INDENT-OFF* */ |
| 474 | ELOG_TYPE_DECLARE (e) = |
| 475 | { |
| 476 | .format = "api-msg: %s", |
| 477 | .format_args = "T4", |
| 478 | }; |
| 479 | /* *INDENT-ON* */ |
| 480 | struct |
| 481 | { |
| 482 | u32 c; |
| 483 | } *ed; |
| 484 | ed = ELOG_DATA (&vm->elog_main, e); |
| 485 | if (id < vec_len (am->msg_names)) |
| 486 | ed->c = elog_id_for_msg_name (vm, (const char *) am->msg_names[id]); |
| 487 | else |
| 488 | ed->c = elog_id_for_msg_name (vm, "BOGUS"); |
| 489 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 490 | |
| 491 | if (id < vec_len (am->msg_handlers) && am->msg_handlers[id]) |
| 492 | { |
| 493 | handler = (void *) am->msg_handlers[id]; |
| 494 | |
ezkexma | 75f9fb6 | 2019-03-21 07:38:19 -0400 | [diff] [blame] | 495 | if (PREDICT_FALSE (am->rx_trace && am->rx_trace->enabled)) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 496 | vl_msg_api_trace (am, am->rx_trace, the_msg); |
| 497 | |
ezkexma | 75f9fb6 | 2019-03-21 07:38:19 -0400 | [diff] [blame] | 498 | if (PREDICT_FALSE (am->msg_print_flag)) |
| 499 | { |
| 500 | fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]); |
| 501 | print_fp = (void *) am->msg_print_handlers[id]; |
| 502 | if (print_fp == 0) |
| 503 | { |
| 504 | fformat (stdout, " [no registered print fn for msg %d]\n", id); |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | (*print_fp) (the_msg, vm); |
| 509 | } |
| 510 | } |
| 511 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 512 | if (!am->is_mp_safe[id]) |
Colin Tregenza Dancer | eb1ac17 | 2017-09-06 20:23:24 +0100 | [diff] [blame] | 513 | { |
| 514 | vl_msg_api_barrier_trace_context (am->msg_names[id]); |
| 515 | vl_msg_api_barrier_sync (); |
| 516 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 517 | (*handler) (the_msg, vm, node); |
| 518 | if (!am->is_mp_safe[id]) |
| 519 | vl_msg_api_barrier_release (); |
| 520 | } |
| 521 | else |
| 522 | { |
Jon Loeliger | f95b37e | 2017-02-13 15:21:12 -0600 | [diff] [blame] | 523 | clib_warning ("no handler for msg id %d", id); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 527 | * Special-case, so we can e.g. bounce messages off the vnet |
| 528 | * main thread without copying them... |
| 529 | */ |
| 530 | if (!(am->message_bounce[id])) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 531 | vl_msg_api_free (the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 532 | |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 533 | if (PREDICT_FALSE (vm->elog_trace_api_messages)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 534 | { |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 535 | /* *INDENT-OFF* */ |
| 536 | ELOG_TYPE_DECLARE (e) = { |
| 537 | .format = "api-msg-done: %s", |
| 538 | .format_args = "T4", |
| 539 | }; |
| 540 | /* *INDENT-ON* */ |
| 541 | |
| 542 | struct |
| 543 | { |
| 544 | u32 c; |
| 545 | } *ed; |
| 546 | ed = ELOG_DATA (&vm->elog_main, e); |
| 547 | if (id < vec_len (am->msg_names)) |
| 548 | ed->c = elog_id_for_msg_name (vm, (const char *) am->msg_names[id]); |
| 549 | else |
| 550 | ed->c = elog_id_for_msg_name (vm, "BOGUS"); |
| 551 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 554 | void |
| 555 | vl_msg_api_handler (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 556 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 557 | api_main_t *am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 558 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 559 | msg_handler_internal (am, the_msg, |
| 560 | (am->rx_trace |
| 561 | && am->rx_trace->enabled) /* trace_it */ , |
| 562 | 1 /* do_it */ , 1 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 565 | void |
| 566 | vl_msg_api_handler_no_free (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 567 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 568 | api_main_t *am = &api_main; |
| 569 | msg_handler_internal (am, the_msg, |
| 570 | (am->rx_trace |
| 571 | && am->rx_trace->enabled) /* trace_it */ , |
| 572 | 1 /* do_it */ , 0 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 575 | void |
| 576 | vl_msg_api_handler_no_trace_no_free (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 578 | api_main_t *am = &api_main; |
| 579 | msg_handler_internal (am, the_msg, 0 /* trace_it */ , 1 /* do_it */ , |
| 580 | 0 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | /* |
| 584 | * Add a trace record to the API message trace buffer, if |
| 585 | * API message tracing is enabled. Handy for adding sufficient |
| 586 | * data to the trace to reproduce autonomous state, as opposed to |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 587 | * state downloaded via control-plane API messages. Example: the NAT |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 588 | * application creates database entries based on packet traffic, not |
| 589 | * control-plane messages. |
| 590 | * |
| 591 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 592 | void |
| 593 | vl_msg_api_trace_only (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 594 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 595 | api_main_t *am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 596 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 597 | msg_handler_internal (am, the_msg, |
| 598 | (am->rx_trace |
| 599 | && am->rx_trace->enabled) /* trace_it */ , |
| 600 | 0 /* do_it */ , 0 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 603 | void |
| 604 | vl_msg_api_cleanup_handler (void *the_msg) |
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 | api_main_t *am = &api_main; |
| 607 | u16 id = ntohs (*((u16 *) the_msg)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 608 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 609 | if (PREDICT_FALSE (id >= vec_len (am->msg_cleanup_handlers))) |
| 610 | { |
| 611 | clib_warning ("_vl_msg_id too large: %d\n", id); |
| 612 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 613 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 614 | if (am->msg_cleanup_handlers[id]) |
| 615 | (*am->msg_cleanup_handlers[id]) (the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 616 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 617 | vl_msg_api_free (the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | /* |
| 621 | * vl_msg_api_replay_handler |
| 622 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 623 | void |
| 624 | vl_msg_api_replay_handler (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 625 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 626 | api_main_t *am = &api_main; |
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 | u16 id = ntohs (*((u16 *) the_msg)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 629 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 630 | if (PREDICT_FALSE (id >= vec_len (am->msg_handlers))) |
| 631 | { |
| 632 | clib_warning ("_vl_msg_id too large: %d\n", id); |
| 633 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 634 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 635 | /* do NOT trace the message... */ |
| 636 | if (am->msg_handlers[id]) |
| 637 | (*am->msg_handlers[id]) (the_msg); |
| 638 | /* do NOT free the message buffer... */ |
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 | |
Dave Barach | bfd9227 | 2017-05-12 11:59:25 -0400 | [diff] [blame] | 641 | u32 |
| 642 | vl_msg_api_get_msg_length (void *msg_arg) |
| 643 | { |
| 644 | return vl_msg_api_get_msg_length_inline (msg_arg); |
| 645 | } |
| 646 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 647 | /* |
| 648 | * vl_msg_api_socket_handler |
| 649 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 650 | void |
| 651 | vl_msg_api_socket_handler (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 652 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 653 | api_main_t *am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 654 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 655 | msg_handler_internal (am, the_msg, |
| 656 | (am->rx_trace |
| 657 | && am->rx_trace->enabled) /* trace_it */ , |
| 658 | 1 /* do_it */ , 0 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | #define foreach_msg_api_vector \ |
| 662 | _(msg_names) \ |
| 663 | _(msg_handlers) \ |
| 664 | _(msg_cleanup_handlers) \ |
| 665 | _(msg_endian_handlers) \ |
| 666 | _(msg_print_handlers) \ |
| 667 | _(api_trace_cfg) \ |
| 668 | _(message_bounce) \ |
| 669 | _(is_mp_safe) |
| 670 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 671 | void |
| 672 | vl_msg_api_config (vl_msg_api_msg_config_t * c) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 673 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 674 | api_main_t *am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 675 | |
Dave Barach | 6545716 | 2017-10-10 17:53:14 -0400 | [diff] [blame] | 676 | /* |
| 677 | * This happens during the java core tests if the message |
| 678 | * dictionary is missing newly added xxx_reply_t messages. |
| 679 | * Should never happen, but since I shot myself in the foot once |
| 680 | * this way, I thought I'd make it easy to debug if I ever do |
| 681 | * it again... (;-)... |
| 682 | */ |
| 683 | if (c->id == 0) |
| 684 | { |
| 685 | if (c->name) |
| 686 | clib_warning ("Trying to register %s with a NULL msg id!", c->name); |
| 687 | else |
| 688 | clib_warning ("Trying to register a NULL msg with a NULL msg id!"); |
| 689 | clib_warning ("Did you forget to call setup_message_id_table?"); |
| 690 | return; |
| 691 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 692 | |
| 693 | #define _(a) vec_validate (am->a, c->id); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 694 | foreach_msg_api_vector; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 695 | #undef _ |
| 696 | |
Dave Barach | 392206e | 2017-09-20 08:40:16 -0400 | [diff] [blame] | 697 | if (am->msg_handlers[c->id] && am->msg_handlers[c->id] != c->handler) |
| 698 | clib_warning |
| 699 | ("BUG: re-registering 'vl_api_%s_t_handler'." |
| 700 | "Handler was %llx, replaced by %llx", |
| 701 | c->name, am->msg_handlers[c->id], c->handler); |
Dave Barach | a1a093d | 2017-03-02 13:13:23 -0500 | [diff] [blame] | 702 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 703 | am->msg_names[c->id] = c->name; |
| 704 | am->msg_handlers[c->id] = c->handler; |
| 705 | am->msg_cleanup_handlers[c->id] = c->cleanup; |
| 706 | am->msg_endian_handlers[c->id] = c->endian; |
| 707 | am->msg_print_handlers[c->id] = c->print; |
| 708 | am->message_bounce[c->id] = c->message_bounce; |
| 709 | am->is_mp_safe[c->id] = c->is_mp_safe; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 710 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 711 | am->api_trace_cfg[c->id].size = c->size; |
| 712 | am->api_trace_cfg[c->id].trace_enable = c->traced; |
| 713 | am->api_trace_cfg[c->id].replay_enable = c->replay; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 716 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 717 | * vl_msg_api_set_handlers |
| 718 | * preserve the old API for a while |
| 719 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 720 | void |
| 721 | vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup, |
| 722 | void *endian, void *print, int size, int traced) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 723 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 724 | vl_msg_api_msg_config_t cfg; |
| 725 | vl_msg_api_msg_config_t *c = &cfg; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 726 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 727 | clib_memset (c, 0, sizeof (*c)); |
Dave Barach | 0691d6e | 2017-01-05 10:08:52 -0500 | [diff] [blame] | 728 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 729 | c->id = id; |
| 730 | c->name = name; |
| 731 | c->handler = handler; |
| 732 | c->cleanup = cleanup; |
| 733 | c->endian = endian; |
| 734 | c->print = print; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 735 | c->traced = traced; |
| 736 | c->replay = 1; |
| 737 | c->message_bounce = 0; |
| 738 | c->is_mp_safe = 0; |
| 739 | vl_msg_api_config (c); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 742 | void |
Matej Perina | 75a17ec | 2017-09-21 17:03:27 +0200 | [diff] [blame] | 743 | vl_msg_api_clean_handlers (int msg_id) |
| 744 | { |
| 745 | vl_msg_api_msg_config_t cfg; |
| 746 | vl_msg_api_msg_config_t *c = &cfg; |
| 747 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 748 | clib_memset (c, 0, sizeof (*c)); |
Matej Perina | 75a17ec | 2017-09-21 17:03:27 +0200 | [diff] [blame] | 749 | |
| 750 | c->id = msg_id; |
| 751 | vl_msg_api_config (c); |
| 752 | } |
| 753 | |
| 754 | void |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 755 | vl_msg_api_set_cleanup_handler (int msg_id, void *fp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 757 | api_main_t *am = &api_main; |
| 758 | ASSERT (msg_id > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 759 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 760 | vec_validate (am->msg_cleanup_handlers, msg_id); |
| 761 | am->msg_cleanup_handlers[msg_id] = fp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 764 | void |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 765 | vl_msg_api_queue_handler (svm_queue_t * q) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 766 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 767 | uword msg; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 768 | |
Mohsin Kazmi | 3fca567 | 2018-01-04 18:57:26 +0100 | [diff] [blame] | 769 | while (!svm_queue_sub (q, (u8 *) & msg, SVM_Q_WAIT, 0)) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 770 | vl_msg_api_handler ((void *) msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 773 | vl_api_trace_t * |
| 774 | vl_msg_api_trace_get (api_main_t * am, vl_api_trace_which_t which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 775 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 776 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 777 | { |
| 778 | case VL_API_TRACE_RX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 779 | return am->rx_trace; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 780 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 781 | return am->tx_trace; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 782 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 783 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 787 | void |
| 788 | vl_noop_handler (void *mp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 789 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 792 | |
| 793 | static u8 post_mortem_dump_enabled; |
| 794 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 795 | void |
| 796 | vl_msg_api_post_mortem_dump_enable_disable (int enable) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 797 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 798 | post_mortem_dump_enabled = enable; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 801 | void |
| 802 | vl_msg_api_post_mortem_dump (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 803 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 804 | api_main_t *am = &api_main; |
| 805 | FILE *fp; |
| 806 | char filename[64]; |
| 807 | int rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 808 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 809 | if (post_mortem_dump_enabled == 0) |
| 810 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 811 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 812 | snprintf (filename, sizeof (filename), "/tmp/api_post_mortem.%d", |
| 813 | getpid ()); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 814 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 815 | fp = fopen (filename, "w"); |
| 816 | if (fp == NULL) |
| 817 | { |
| 818 | rv = write (2, "Couldn't create ", 16); |
| 819 | rv = write (2, filename, strlen (filename)); |
| 820 | rv = write (2, "\n", 1); |
| 821 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 822 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 823 | rv = vl_msg_api_trace_save (am, VL_API_TRACE_RX, fp); |
| 824 | fclose (fp); |
| 825 | if (rv < 0) |
| 826 | { |
| 827 | rv = write (2, "Failed to save post-mortem API trace to ", 40); |
| 828 | rv = write (2, filename, strlen (filename)); |
| 829 | rv = write (2, "\n", 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 830 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 831 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | /* Layered message handling support */ |
| 835 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 836 | void |
| 837 | vl_msg_api_register_pd_handler (void *fp, u16 msg_id_host_byte_order) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 838 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 839 | api_main_t *am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 840 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 841 | /* Mild idiot proofing */ |
| 842 | if (msg_id_host_byte_order > 10000) |
| 843 | clib_warning ("msg_id_host_byte_order endian issue? %d arg vs %d", |
| 844 | msg_id_host_byte_order, |
| 845 | clib_net_to_host_u16 (msg_id_host_byte_order)); |
| 846 | vec_validate (am->pd_msg_handlers, msg_id_host_byte_order); |
| 847 | am->pd_msg_handlers[msg_id_host_byte_order] = fp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 850 | int |
| 851 | vl_msg_api_pd_handler (void *mp, int rv) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 852 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 853 | api_main_t *am = &api_main; |
| 854 | int (*fp) (void *, int); |
| 855 | u16 msg_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 856 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 857 | if (clib_arch_is_little_endian) |
| 858 | msg_id = clib_net_to_host_u16 (*((u16 *) mp)); |
| 859 | else |
| 860 | msg_id = *((u16 *) mp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 861 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 862 | if (msg_id >= vec_len (am->pd_msg_handlers) |
| 863 | || am->pd_msg_handlers[msg_id] == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 864 | return rv; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 865 | |
| 866 | fp = am->pd_msg_handlers[msg_id]; |
| 867 | rv = (*fp) (mp, rv); |
| 868 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 871 | void |
| 872 | vl_msg_api_set_first_available_msg_id (u16 first_avail) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 873 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 874 | api_main_t *am = &api_main; |
| 875 | |
| 876 | am->first_available_msg_id = first_avail; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 879 | u16 |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 880 | vl_msg_api_get_msg_ids (const char *name, int n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 881 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 882 | api_main_t *am = &api_main; |
| 883 | u8 *name_copy; |
| 884 | vl_api_msg_range_t *rp; |
| 885 | uword *p; |
| 886 | u16 rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 887 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 888 | if (am->msg_range_by_name == 0) |
| 889 | am->msg_range_by_name = hash_create_string (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 890 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 891 | name_copy = format (0, "%s%c", name, 0); |
| 892 | |
| 893 | p = hash_get_mem (am->msg_range_by_name, name_copy); |
| 894 | if (p) |
| 895 | { |
| 896 | clib_warning ("WARNING: duplicate message range registration for '%s'", |
| 897 | name_copy); |
| 898 | vec_free (name_copy); |
| 899 | return ((u16) ~ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 902 | if (n < 0 || n > 1024) |
| 903 | { |
| 904 | clib_warning |
| 905 | ("WARNING: bad number of message-IDs (%d) requested by '%s'", |
| 906 | n, name_copy); |
| 907 | vec_free (name_copy); |
| 908 | return ((u16) ~ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 911 | vec_add2 (am->msg_ranges, rp, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 912 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 913 | rv = rp->first_msg_id = am->first_available_msg_id; |
| 914 | am->first_available_msg_id += n; |
| 915 | rp->last_msg_id = am->first_available_msg_id - 1; |
| 916 | rp->name = name_copy; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 917 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 918 | hash_set_mem (am->msg_range_by_name, name_copy, rp - am->msg_ranges); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 919 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 920 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 921 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 922 | |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 923 | void |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 924 | vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, u32 id) |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 925 | { |
| 926 | uword *p; |
| 927 | |
| 928 | if (am->msg_index_by_name_and_crc == 0) |
| 929 | am->msg_index_by_name_and_crc = hash_create_string (0, sizeof (uword)); |
| 930 | |
| 931 | p = hash_get_mem (am->msg_index_by_name_and_crc, string); |
| 932 | if (p) |
| 933 | { |
| 934 | clib_warning ("attempt to redefine '%s' ignored...", string); |
| 935 | return; |
| 936 | } |
| 937 | |
| 938 | hash_set_mem (am->msg_index_by_name_and_crc, string, id); |
| 939 | } |
| 940 | |
Dave Barach | 0d056e5 | 2017-09-28 15:11:16 -0400 | [diff] [blame] | 941 | void |
| 942 | vl_msg_api_add_version (api_main_t * am, const char *string, |
| 943 | u32 major, u32 minor, u32 patch) |
| 944 | { |
| 945 | api_version_t version = {.major = major,.minor = minor,.patch = patch }; |
| 946 | ASSERT (strlen (string) < 64); |
Ole Troan | 7504e99 | 2017-10-10 08:43:35 +0200 | [diff] [blame] | 947 | strncpy (version.name, string, 64 - 1); |
Dave Barach | 0d056e5 | 2017-09-28 15:11:16 -0400 | [diff] [blame] | 948 | vec_add1 (am->api_version_list, version); |
| 949 | } |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 950 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 951 | u32 |
| 952 | vl_msg_api_get_msg_index (u8 * name_and_crc) |
| 953 | { |
| 954 | api_main_t *am = &api_main; |
| 955 | uword *p; |
| 956 | |
| 957 | if (am->msg_index_by_name_and_crc) |
| 958 | { |
| 959 | p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc); |
| 960 | if (p) |
| 961 | return p[0]; |
| 962 | } |
| 963 | return ~0; |
| 964 | } |
| 965 | |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 966 | void * |
| 967 | vl_msg_push_heap (void) |
| 968 | { |
| 969 | api_main_t *am = &api_main; |
| 970 | pthread_mutex_lock (&am->vlib_rp->mutex); |
| 971 | return svm_push_data_heap (am->vlib_rp); |
| 972 | } |
| 973 | |
| 974 | void |
| 975 | vl_msg_pop_heap (void *oldheap) |
| 976 | { |
| 977 | api_main_t *am = &api_main; |
| 978 | svm_pop_heap (oldheap); |
| 979 | pthread_mutex_unlock (&am->vlib_rp->mutex); |
| 980 | } |
| 981 | |
| 982 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 983 | /* |
| 984 | * fd.io coding-style-patch-verification: ON |
| 985 | * |
| 986 | * Local Variables: |
| 987 | * eval: (c-set-style "gnu") |
| 988 | * End: |
| 989 | */ |