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> |
Tom Seidenberg | 6c81f5a | 2020-07-10 15:49:03 +0000 | [diff] [blame] | 33 | #include <vppinfra/callback.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 34 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 35 | /* *INDENT-OFF* */ |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 36 | api_main_t api_global_main = |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 37 | { |
| 38 | .region_name = "/unset", |
| 39 | .api_uid = -1, |
| 40 | .api_gid = -1, |
| 41 | }; |
| 42 | /* *INDENT-ON* */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 43 | |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 44 | /* Please use vlibapi_get_main() to access my_api_main */ |
| 45 | __thread api_main_t *my_api_main = &api_global_main; |
| 46 | |
| 47 | void |
| 48 | vl_msg_api_set_global_main (void *am_arg) |
| 49 | { |
| 50 | ASSERT (am_arg); |
| 51 | my_api_main = (api_main_t *) am_arg; |
| 52 | } |
| 53 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 54 | void |
| 55 | vl_msg_api_increment_missing_client_counter (void) |
| 56 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 57 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 58 | am->missing_clients++; |
| 59 | } |
| 60 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 61 | int |
| 62 | vl_msg_api_rx_trace_enabled (api_main_t * am) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 64 | return (am->rx_trace && am->rx_trace->enabled); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 67 | int |
| 68 | vl_msg_api_tx_trace_enabled (api_main_t * am) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 70 | return (am->tx_trace && am->tx_trace->enabled); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* |
| 74 | * vl_msg_api_trace |
| 75 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 76 | void |
| 77 | 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] | 78 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 79 | u8 **this_trace; |
| 80 | u8 **old_trace; |
| 81 | u8 *msg_copy; |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 82 | u32 length; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 83 | trace_cfg_t *cfgp; |
Dave Barach | 9683c1e | 2019-07-01 09:42:41 -0400 | [diff] [blame] | 84 | u16 msg_id = clib_net_to_host_u16 (*((u16 *) msg)); |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 85 | msgbuf_t *header = (msgbuf_t *) (((u8 *) msg) - offsetof (msgbuf_t, data)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 87 | cfgp = am->api_trace_cfg + msg_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 89 | if (!cfgp || !cfgp->trace_enable) |
| 90 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 92 | msg_copy = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 94 | if (tp->nitems == 0) |
| 95 | { |
| 96 | clib_warning ("tp->nitems is 0"); |
| 97 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 100 | if (vec_len (tp->traces) < tp->nitems) |
| 101 | { |
| 102 | vec_add1 (tp->traces, 0); |
| 103 | this_trace = tp->traces + vec_len (tp->traces) - 1; |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | tp->wrapped = 1; |
| 108 | old_trace = tp->traces + tp->curindex++; |
| 109 | if (tp->curindex == tp->nitems) |
| 110 | tp->curindex = 0; |
Dave Barach | f35a072 | 2019-06-12 16:50:38 -0400 | [diff] [blame] | 111 | /* Reuse the trace record, may save some memory allocator traffic */ |
| 112 | msg_copy = *old_trace; |
| 113 | vec_reset_length (msg_copy); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 114 | this_trace = old_trace; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Dave Barach | 072f8de | 2016-12-02 13:31:25 -0500 | [diff] [blame] | 117 | length = clib_net_to_host_u32 (header->data_len); |
| 118 | |
| 119 | vec_validate (msg_copy, length - 1); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 120 | clib_memcpy_fast (msg_copy, msg, length); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 121 | *this_trace = msg_copy; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 124 | int |
| 125 | vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which, |
| 126 | int onoff) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 127 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 128 | vl_api_trace_t *tp; |
| 129 | int rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 131 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 132 | { |
| 133 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 134 | tp = am->tx_trace; |
| 135 | if (tp == 0) |
| 136 | { |
| 137 | vl_msg_api_trace_configure (am, which, 1024); |
| 138 | tp = am->tx_trace; |
| 139 | } |
| 140 | break; |
| 141 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | case VL_API_TRACE_RX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 143 | tp = am->rx_trace; |
| 144 | if (tp == 0) |
| 145 | { |
| 146 | vl_msg_api_trace_configure (am, which, 1024); |
| 147 | tp = am->rx_trace; |
| 148 | } |
| 149 | break; |
| 150 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 152 | /* duh? */ |
| 153 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 156 | /* Configured? */ |
| 157 | if (tp == 0 || tp->nitems == 0) |
| 158 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 160 | rv = tp->enabled; |
| 161 | tp->enabled = onoff; |
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 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 166 | int |
| 167 | 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] | 168 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 169 | vl_api_trace_t *tp; |
| 170 | int i; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 171 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 172 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 173 | { |
| 174 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 175 | tp = am->tx_trace; |
| 176 | break; |
| 177 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 178 | case VL_API_TRACE_RX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 179 | tp = am->rx_trace; |
| 180 | break; |
| 181 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 182 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 183 | /* duh? */ |
| 184 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 187 | /* Configured? */ |
| 188 | if (!tp || tp->nitems == 0) |
| 189 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 190 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 191 | tp->curindex = 0; |
| 192 | tp->wrapped = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 194 | for (i = 0; i < vec_len (tp->traces); i++) |
| 195 | { |
| 196 | vec_free (tp->traces[i]); |
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 | vec_free (tp->traces); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 199 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 200 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Ole Troan | edfe2c0 | 2019-07-30 15:38:13 +0200 | [diff] [blame] | 203 | u8 * |
| 204 | vl_api_serialize_message_table (api_main_t * am, u8 * vector) |
| 205 | { |
| 206 | serialize_main_t _sm, *sm = &_sm; |
| 207 | hash_pair_t *hp; |
| 208 | u32 nmsg = hash_elts (am->msg_index_by_name_and_crc); |
| 209 | |
| 210 | serialize_open_vector (sm, vector); |
| 211 | |
| 212 | /* serialize the count */ |
| 213 | serialize_integer (sm, nmsg, sizeof (u32)); |
| 214 | |
| 215 | /* *INDENT-OFF* */ |
| 216 | hash_foreach_pair (hp, am->msg_index_by_name_and_crc, |
| 217 | ({ |
| 218 | serialize_likely_small_unsigned_integer (sm, hp->value[0]); |
| 219 | serialize_cstring (sm, (char *) hp->key); |
| 220 | })); |
| 221 | /* *INDENT-ON* */ |
| 222 | |
| 223 | return serialize_close_vector (sm); |
| 224 | } |
| 225 | |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 226 | static int |
| 227 | vl_msg_api_trace_write_one (api_main_t *am, u8 *msg, FILE *fp) |
| 228 | { |
| 229 | u8 *tmpmem = 0; |
| 230 | int tlen, slen; |
| 231 | cJSON *(*tojson_fn) (void *); |
| 232 | |
| 233 | u32 msg_length = vec_len (msg); |
| 234 | vec_validate (tmpmem, msg_length - 1); |
| 235 | clib_memcpy_fast (tmpmem, msg, msg_length); |
| 236 | u16 id = clib_net_to_host_u16 (*((u16 *) msg)); |
| 237 | |
| 238 | void (*endian_fp) (void *); |
| 239 | endian_fp = am->msg_endian_handlers[id]; |
| 240 | (*endian_fp) (tmpmem); |
| 241 | |
| 242 | if (id < vec_len (am->msg_tojson_handlers) && am->msg_tojson_handlers[id]) |
| 243 | { |
| 244 | tojson_fn = am->msg_tojson_handlers[id]; |
| 245 | cJSON *o = tojson_fn (tmpmem); |
| 246 | char *s = cJSON_Print (o); |
| 247 | slen = strlen (s); |
| 248 | tlen = fwrite (s, 1, slen, fp); |
| 249 | cJSON_free (s); |
| 250 | cJSON_Delete (o); |
| 251 | vec_free (tmpmem); |
| 252 | if (tlen != slen) |
| 253 | { |
| 254 | fformat (stderr, "writing to file error\n"); |
| 255 | return -11; |
| 256 | } |
| 257 | } |
| 258 | else |
| 259 | fformat (stderr, " [no registered tojson fn]\n"); |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | #define vl_msg_fwrite(_s, _f) fwrite (_s, 1, sizeof (_s) - 1, _f) |
| 265 | |
| 266 | typedef struct |
| 267 | { |
| 268 | FILE *fp; |
| 269 | u32 n_traces; |
| 270 | u32 i; |
| 271 | } vl_msg_write_json_args_t; |
| 272 | |
| 273 | static int |
| 274 | vl_msg_write_json_fn (u8 *msg, void *ctx) |
| 275 | { |
| 276 | vl_msg_write_json_args_t *arg = ctx; |
| 277 | FILE *fp = arg->fp; |
| 278 | api_main_t *am = vlibapi_get_main (); |
| 279 | int rc = vl_msg_api_trace_write_one (am, msg, fp); |
| 280 | if (rc < 0) |
| 281 | return rc; |
| 282 | |
| 283 | if (arg->i < arg->n_traces - 1) |
| 284 | vl_msg_fwrite (",\n", fp); |
| 285 | arg->i++; |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int |
| 290 | vl_msg_api_trace_write_json (api_main_t *am, vl_api_trace_t *tp, FILE *fp) |
| 291 | { |
| 292 | vl_msg_write_json_args_t args; |
| 293 | clib_memset (&args, 0, sizeof (args)); |
| 294 | args.fp = fp; |
| 295 | args.n_traces = vec_len (tp->traces); |
| 296 | vl_msg_fwrite ("[\n", fp); |
| 297 | |
| 298 | int rv = vl_msg_traverse_trace (tp, vl_msg_write_json_fn, &args); |
| 299 | if (rv < 0) |
| 300 | return rv; |
| 301 | |
| 302 | vl_msg_fwrite ("]", fp); |
| 303 | return 0; |
| 304 | } |
| 305 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 306 | int |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 307 | vl_msg_traverse_trace (vl_api_trace_t *tp, vl_msg_traverse_trace_fn fn, |
| 308 | void *ctx) |
| 309 | { |
| 310 | int i; |
| 311 | u8 *msg; |
| 312 | int rv = 0; |
| 313 | |
| 314 | /* No-wrap case */ |
| 315 | if (tp->wrapped == 0) |
| 316 | { |
| 317 | for (i = 0; i < vec_len (tp->traces); i++) |
| 318 | { |
| 319 | /*sa_ignore NO_NULL_CHK */ |
| 320 | msg = tp->traces[i]; |
| 321 | if (!msg) |
| 322 | continue; |
| 323 | |
| 324 | rv = fn (msg, ctx); |
| 325 | if (rv < 0) |
| 326 | return rv; |
| 327 | } |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | /* Wrap case: write oldest -> end of buffer */ |
| 332 | for (i = tp->curindex; i < vec_len (tp->traces); i++) |
| 333 | { |
| 334 | msg = tp->traces[i]; |
| 335 | if (!msg) |
| 336 | continue; |
| 337 | |
| 338 | rv = fn (msg, ctx); |
| 339 | if (rv < 0) |
| 340 | return rv; |
| 341 | } |
| 342 | /* write beginning of buffer -> oldest-1 */ |
| 343 | for (i = 0; i < tp->curindex; i++) |
| 344 | { |
| 345 | /*sa_ignore NO_NULL_CHK */ |
| 346 | msg = tp->traces[i]; |
| 347 | if (!msg) |
| 348 | continue; |
| 349 | |
| 350 | rv = fn (msg, ctx); |
| 351 | if (rv < 0) |
| 352 | return rv; |
| 353 | } |
| 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static int |
| 359 | vl_api_msg_write_fn (u8 *msg, void *ctx) |
| 360 | { |
| 361 | FILE *fp = ctx; |
| 362 | u32 msg_length = clib_host_to_net_u32 (vec_len (msg)); |
| 363 | if (fwrite (&msg_length, 1, sizeof (msg_length), fp) != sizeof (msg_length)) |
| 364 | { |
| 365 | return (-14); |
| 366 | } |
| 367 | if (fwrite (msg, 1, vec_len (msg), fp) != vec_len (msg)) |
| 368 | { |
| 369 | return (-14); |
| 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | int |
| 375 | vl_msg_api_trace_save (api_main_t *am, vl_api_trace_which_t which, FILE *fp, |
| 376 | u8 is_json) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 377 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 378 | vl_api_trace_t *tp; |
| 379 | vl_api_trace_file_header_t fh; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 381 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | { |
| 383 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 384 | tp = am->tx_trace; |
| 385 | break; |
| 386 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 387 | case VL_API_TRACE_RX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 388 | tp = am->rx_trace; |
| 389 | break; |
| 390 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 392 | /* duh? */ |
| 393 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 396 | /* Configured, data present? */ |
| 397 | if (tp == 0 || tp->nitems == 0 || vec_len (tp->traces) == 0) |
| 398 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 399 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 400 | /* "Dare to be stupid" check */ |
| 401 | if (fp == 0) |
| 402 | { |
| 403 | return -2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 406 | if (is_json) |
| 407 | return vl_msg_api_trace_write_json (am, tp, fp); |
| 408 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 409 | /* Write the file header */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 410 | fh.wrapped = tp->wrapped; |
Ole Troan | edfe2c0 | 2019-07-30 15:38:13 +0200 | [diff] [blame] | 411 | fh.nitems = clib_host_to_net_u32 (vec_len (tp->traces)); |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 412 | |
Ole Troan | edfe2c0 | 2019-07-30 15:38:13 +0200 | [diff] [blame] | 413 | u8 *m = vl_api_serialize_message_table (am, 0); |
Ole Troan | edfe2c0 | 2019-07-30 15:38:13 +0200 | [diff] [blame] | 414 | fh.msgtbl_size = clib_host_to_net_u32 (vec_len (m)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 415 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 416 | if (fwrite (&fh, sizeof (fh), 1, fp) != 1) |
| 417 | { |
| 418 | return (-10); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Ole Troan | edfe2c0 | 2019-07-30 15:38:13 +0200 | [diff] [blame] | 421 | /* Write the message table */ |
| 422 | if (fwrite (m, vec_len (m), 1, fp) != 1) |
| 423 | { |
| 424 | return (-14); |
| 425 | } |
| 426 | vec_free (m); |
| 427 | |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 428 | return vl_msg_traverse_trace (tp, vl_api_msg_write_fn, fp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 431 | int |
| 432 | vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which, |
| 433 | u32 nitems) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 435 | vl_api_trace_t *tp; |
| 436 | int was_on = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 438 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 439 | { |
| 440 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 441 | tp = am->tx_trace; |
| 442 | if (tp == 0) |
| 443 | { |
| 444 | vec_validate (am->tx_trace, 0); |
| 445 | tp = am->tx_trace; |
| 446 | } |
| 447 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 448 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 449 | case VL_API_TRACE_RX: |
| 450 | tp = am->rx_trace; |
| 451 | if (tp == 0) |
| 452 | { |
| 453 | vec_validate (am->rx_trace, 0); |
| 454 | tp = am->rx_trace; |
| 455 | } |
| 456 | |
| 457 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 458 | |
| 459 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 460 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 461 | |
| 462 | } |
| 463 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 464 | if (tp->enabled) |
| 465 | { |
| 466 | was_on = vl_msg_api_trace_onoff (am, which, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 467 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 468 | if (tp->traces) |
| 469 | { |
| 470 | vl_msg_api_trace_free (am, which); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 473 | clib_memset (tp, 0, sizeof (*tp)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 474 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 475 | if (clib_arch_is_big_endian) |
| 476 | { |
| 477 | tp->endian = VL_API_BIG_ENDIAN; |
| 478 | } |
| 479 | else |
| 480 | { |
| 481 | tp->endian = VL_API_LITTLE_ENDIAN; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 484 | tp->nitems = nitems; |
| 485 | if (was_on) |
| 486 | { |
| 487 | (void) vl_msg_api_trace_onoff (am, which, was_on); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 488 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 489 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 492 | void |
| 493 | vl_msg_api_barrier_sync (void) |
| 494 | { |
| 495 | } |
| 496 | |
| 497 | void |
| 498 | vl_msg_api_barrier_release (void) |
| 499 | { |
| 500 | } |
| 501 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 502 | always_inline void |
| 503 | msg_handler_internal (api_main_t * am, |
| 504 | void *the_msg, int trace_it, int do_it, int free_it) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 505 | { |
Dave Barach | 9683c1e | 2019-07-01 09:42:41 -0400 | [diff] [blame] | 506 | u16 id = clib_net_to_host_u16 (*((u16 *) the_msg)); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 507 | u8 *(*print_fp) (void *, void *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 508 | |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 509 | if (PREDICT_FALSE (am->elog_trace_api_messages)) |
| 510 | { |
| 511 | /* *INDENT-OFF* */ |
| 512 | ELOG_TYPE_DECLARE (e) = |
| 513 | { |
| 514 | .format = "api-msg: %s", |
| 515 | .format_args = "T4", |
| 516 | }; |
| 517 | /* *INDENT-ON* */ |
| 518 | struct |
| 519 | { |
| 520 | u32 c; |
| 521 | } *ed; |
| 522 | ed = ELOG_DATA (am->elog_main, e); |
Andrew Yourtchenko | f48de88 | 2021-02-06 12:28:52 +0000 | [diff] [blame] | 523 | if (id < vec_len (am->msg_names) && am->msg_names[id]) |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 524 | ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]); |
| 525 | else |
| 526 | ed->c = elog_string (am->elog_main, "BOGUS"); |
| 527 | } |
| 528 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 529 | if (id < vec_len (am->msg_handlers) && am->msg_handlers[id]) |
| 530 | { |
| 531 | if (trace_it) |
| 532 | vl_msg_api_trace (am, am->rx_trace, the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 533 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 534 | if (am->msg_print_flag) |
| 535 | { |
| 536 | fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]); |
| 537 | print_fp = (void *) am->msg_print_handlers[id]; |
| 538 | if (print_fp == 0) |
| 539 | { |
| 540 | fformat (stdout, " [no registered print fn]\n"); |
| 541 | } |
| 542 | else |
| 543 | { |
| 544 | (*print_fp) (the_msg, stdout); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | if (do_it) |
| 549 | { |
| 550 | if (!am->is_mp_safe[id]) |
Colin Tregenza Dancer | eb1ac17 | 2017-09-06 20:23:24 +0100 | [diff] [blame] | 551 | { |
| 552 | vl_msg_api_barrier_trace_context (am->msg_names[id]); |
| 553 | vl_msg_api_barrier_sync (); |
| 554 | } |
Ole Troan | e796a18 | 2020-05-18 11:14:05 +0200 | [diff] [blame] | 555 | |
| 556 | if (am->is_autoendian[id]) |
| 557 | { |
| 558 | void (*endian_fp) (void *); |
| 559 | endian_fp = am->msg_endian_handlers[id]; |
| 560 | (*endian_fp) (the_msg); |
| 561 | } |
| 562 | |
Tom Seidenberg | 6c81f5a | 2020-07-10 15:49:03 +0000 | [diff] [blame] | 563 | if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0)) |
| 564 | clib_call_callbacks (am->perf_counter_cbs, am, id, |
| 565 | 0 /* before */ ); |
| 566 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 567 | (*am->msg_handlers[id]) (the_msg); |
Tom Seidenberg | 6c81f5a | 2020-07-10 15:49:03 +0000 | [diff] [blame] | 568 | |
| 569 | if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0)) |
| 570 | clib_call_callbacks (am->perf_counter_cbs, am, id, |
| 571 | 1 /* after */ ); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 572 | if (!am->is_mp_safe[id]) |
| 573 | vl_msg_api_barrier_release (); |
| 574 | } |
| 575 | } |
| 576 | else |
| 577 | { |
| 578 | clib_warning ("no handler for msg id %d", id); |
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 | if (free_it) |
| 582 | vl_msg_api_free (the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 583 | |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 584 | if (PREDICT_FALSE (am->elog_trace_api_messages)) |
| 585 | { |
| 586 | /* *INDENT-OFF* */ |
| 587 | ELOG_TYPE_DECLARE (e) = |
| 588 | { |
| 589 | .format = "api-msg-done(%s): %s", |
| 590 | .format_args = "t4T4", |
| 591 | .n_enum_strings = 2, |
| 592 | .enum_strings = |
| 593 | { |
| 594 | "barrier", |
| 595 | "mp-safe", |
| 596 | } |
| 597 | }; |
| 598 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 599 | |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 600 | struct |
| 601 | { |
| 602 | u32 barrier; |
| 603 | u32 c; |
| 604 | } *ed; |
| 605 | ed = ELOG_DATA (am->elog_main, e); |
Andrew Yourtchenko | f48de88 | 2021-02-06 12:28:52 +0000 | [diff] [blame] | 606 | if (id < vec_len (am->msg_names) && am->msg_names[id]) |
Dave Barach | 6794787 | 2019-07-19 09:31:29 -0400 | [diff] [blame] | 607 | { |
| 608 | ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]); |
| 609 | ed->barrier = !am->is_mp_safe[id]; |
| 610 | } |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 611 | else |
Dave Barach | 6794787 | 2019-07-19 09:31:29 -0400 | [diff] [blame] | 612 | { |
| 613 | ed->c = elog_string (am->elog_main, "BOGUS"); |
| 614 | ed->barrier = 0; |
| 615 | } |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 616 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 617 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 618 | |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 619 | void (*vl_msg_api_fuzz_hook) (u16, void *); |
| 620 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 621 | /* This is only to be called from a vlib/vnet app */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 622 | void |
Florin Coras | 8d82085 | 2019-11-27 09:15:25 -0800 | [diff] [blame] | 623 | vl_msg_api_handler_with_vm_node (api_main_t * am, svm_region_t * vlib_rp, |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 624 | void *the_msg, vlib_main_t * vm, |
Florin Coras | 8d82085 | 2019-11-27 09:15:25 -0800 | [diff] [blame] | 625 | vlib_node_runtime_t * node, u8 is_private) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 626 | { |
Dave Barach | 9683c1e | 2019-07-01 09:42:41 -0400 | [diff] [blame] | 627 | u16 id = clib_net_to_host_u16 (*((u16 *) the_msg)); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 628 | u8 *(*handler) (void *, void *, void *); |
ezkexma | 75f9fb6 | 2019-03-21 07:38:19 -0400 | [diff] [blame] | 629 | u8 *(*print_fp) (void *, void *); |
Florin Coras | 8d82085 | 2019-11-27 09:15:25 -0800 | [diff] [blame] | 630 | svm_region_t *old_vlib_rp; |
| 631 | void *save_shmem_hdr; |
Dave Barach | c898a4f | 2019-06-14 17:29:55 -0400 | [diff] [blame] | 632 | int is_mp_safe = 1; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 633 | |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 634 | if (PREDICT_FALSE (am->elog_trace_api_messages)) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 635 | { |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 636 | /* *INDENT-OFF* */ |
| 637 | ELOG_TYPE_DECLARE (e) = |
| 638 | { |
| 639 | .format = "api-msg: %s", |
| 640 | .format_args = "T4", |
| 641 | }; |
| 642 | /* *INDENT-ON* */ |
| 643 | struct |
| 644 | { |
| 645 | u32 c; |
| 646 | } *ed; |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 647 | ed = ELOG_DATA (am->elog_main, e); |
Andrew Yourtchenko | f48de88 | 2021-02-06 12:28:52 +0000 | [diff] [blame] | 648 | if (id < vec_len (am->msg_names) && am->msg_names[id]) |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 649 | ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]); |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 650 | else |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 651 | ed->c = elog_string (am->elog_main, "BOGUS"); |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 652 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 653 | |
| 654 | if (id < vec_len (am->msg_handlers) && am->msg_handlers[id]) |
| 655 | { |
| 656 | handler = (void *) am->msg_handlers[id]; |
| 657 | |
ezkexma | 75f9fb6 | 2019-03-21 07:38:19 -0400 | [diff] [blame] | 658 | if (PREDICT_FALSE (am->rx_trace && am->rx_trace->enabled)) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 659 | vl_msg_api_trace (am, am->rx_trace, the_msg); |
| 660 | |
ezkexma | 75f9fb6 | 2019-03-21 07:38:19 -0400 | [diff] [blame] | 661 | if (PREDICT_FALSE (am->msg_print_flag)) |
| 662 | { |
| 663 | fformat (stdout, "[%d]: %s\n", id, am->msg_names[id]); |
| 664 | print_fp = (void *) am->msg_print_handlers[id]; |
| 665 | if (print_fp == 0) |
| 666 | { |
| 667 | fformat (stdout, " [no registered print fn for msg %d]\n", id); |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | (*print_fp) (the_msg, vm); |
| 672 | } |
| 673 | } |
Dave Barach | c898a4f | 2019-06-14 17:29:55 -0400 | [diff] [blame] | 674 | is_mp_safe = am->is_mp_safe[id]; |
ezkexma | 75f9fb6 | 2019-03-21 07:38:19 -0400 | [diff] [blame] | 675 | |
Dave Barach | c898a4f | 2019-06-14 17:29:55 -0400 | [diff] [blame] | 676 | if (!is_mp_safe) |
Colin Tregenza Dancer | eb1ac17 | 2017-09-06 20:23:24 +0100 | [diff] [blame] | 677 | { |
| 678 | vl_msg_api_barrier_trace_context (am->msg_names[id]); |
| 679 | vl_msg_api_barrier_sync (); |
| 680 | } |
Florin Coras | 8d82085 | 2019-11-27 09:15:25 -0800 | [diff] [blame] | 681 | if (is_private) |
| 682 | { |
| 683 | old_vlib_rp = am->vlib_rp; |
| 684 | save_shmem_hdr = am->shmem_hdr; |
| 685 | am->vlib_rp = vlib_rp; |
| 686 | am->shmem_hdr = (void *) vlib_rp->user_ctx; |
| 687 | } |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 688 | |
| 689 | if (PREDICT_FALSE (vl_msg_api_fuzz_hook != 0)) |
| 690 | (*vl_msg_api_fuzz_hook) (id, the_msg); |
| 691 | |
Ole Troan | e796a18 | 2020-05-18 11:14:05 +0200 | [diff] [blame] | 692 | if (am->is_autoendian[id]) |
| 693 | { |
| 694 | void (*endian_fp) (void *); |
| 695 | endian_fp = am->msg_endian_handlers[id]; |
| 696 | (*endian_fp) (the_msg); |
| 697 | } |
Tom Seidenberg | 6c81f5a | 2020-07-10 15:49:03 +0000 | [diff] [blame] | 698 | if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0)) |
| 699 | clib_call_callbacks (am->perf_counter_cbs, am, id, 0 /* before */ ); |
Ole Troan | e796a18 | 2020-05-18 11:14:05 +0200 | [diff] [blame] | 700 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 701 | (*handler) (the_msg, vm, node); |
Tom Seidenberg | 6c81f5a | 2020-07-10 15:49:03 +0000 | [diff] [blame] | 702 | |
| 703 | if (PREDICT_FALSE (vec_len (am->perf_counter_cbs) != 0)) |
| 704 | clib_call_callbacks (am->perf_counter_cbs, am, id, 1 /* after */ ); |
Florin Coras | 8d82085 | 2019-11-27 09:15:25 -0800 | [diff] [blame] | 705 | if (is_private) |
| 706 | { |
| 707 | am->vlib_rp = old_vlib_rp; |
| 708 | am->shmem_hdr = save_shmem_hdr; |
| 709 | } |
Dave Barach | c898a4f | 2019-06-14 17:29:55 -0400 | [diff] [blame] | 710 | if (!is_mp_safe) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 711 | vl_msg_api_barrier_release (); |
| 712 | } |
| 713 | else |
| 714 | { |
Jon Loeliger | f95b37e | 2017-02-13 15:21:12 -0600 | [diff] [blame] | 715 | clib_warning ("no handler for msg id %d", id); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 719 | * Special-case, so we can e.g. bounce messages off the vnet |
| 720 | * main thread without copying them... |
| 721 | */ |
Benoît Ganne | ff13e46 | 2020-01-21 18:33:14 +0100 | [diff] [blame] | 722 | if (id >= vec_len (am->message_bounce) || !(am->message_bounce[id])) |
wanghanlin | 9f42fff | 2021-05-08 11:39:53 +0800 | [diff] [blame] | 723 | { |
| 724 | if (is_private) |
| 725 | { |
| 726 | old_vlib_rp = am->vlib_rp; |
| 727 | save_shmem_hdr = am->shmem_hdr; |
| 728 | am->vlib_rp = vlib_rp; |
| 729 | am->shmem_hdr = (void *) vlib_rp->user_ctx; |
| 730 | } |
| 731 | vl_msg_api_free (the_msg); |
| 732 | if (is_private) |
| 733 | { |
| 734 | am->vlib_rp = old_vlib_rp; |
| 735 | am->shmem_hdr = save_shmem_hdr; |
| 736 | } |
| 737 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 738 | |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 739 | if (PREDICT_FALSE (am->elog_trace_api_messages)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 740 | { |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 741 | /* *INDENT-OFF* */ |
Dave Barach | c898a4f | 2019-06-14 17:29:55 -0400 | [diff] [blame] | 742 | ELOG_TYPE_DECLARE (e) = |
| 743 | { |
| 744 | .format = "api-msg-done(%s): %s", |
| 745 | .format_args = "t4T4", |
| 746 | .n_enum_strings = 2, |
| 747 | .enum_strings = |
| 748 | { |
| 749 | "barrier", |
| 750 | "mp-safe", |
| 751 | } |
| 752 | }; |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 753 | /* *INDENT-ON* */ |
| 754 | |
| 755 | struct |
| 756 | { |
Dave Barach | c898a4f | 2019-06-14 17:29:55 -0400 | [diff] [blame] | 757 | u32 barrier; |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 758 | u32 c; |
| 759 | } *ed; |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 760 | ed = ELOG_DATA (am->elog_main, e); |
Andrew Yourtchenko | f48de88 | 2021-02-06 12:28:52 +0000 | [diff] [blame] | 761 | if (id < vec_len (am->msg_names) && am->msg_names[id]) |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 762 | ed->c = elog_string (am->elog_main, (char *) am->msg_names[id]); |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 763 | else |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 764 | ed->c = elog_string (am->elog_main, "BOGUS"); |
Dave Barach | c898a4f | 2019-06-14 17:29:55 -0400 | [diff] [blame] | 765 | ed->barrier = is_mp_safe; |
Dave Barach | c3a0655 | 2018-10-01 09:25:32 -0400 | [diff] [blame] | 766 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 769 | void |
| 770 | vl_msg_api_handler (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 771 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 772 | api_main_t *am = vlibapi_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 773 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 774 | msg_handler_internal (am, the_msg, |
| 775 | (am->rx_trace |
| 776 | && am->rx_trace->enabled) /* trace_it */ , |
| 777 | 1 /* do_it */ , 1 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 780 | void |
| 781 | vl_msg_api_handler_no_free (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 782 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 783 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 784 | msg_handler_internal (am, the_msg, |
| 785 | (am->rx_trace |
| 786 | && am->rx_trace->enabled) /* trace_it */ , |
| 787 | 1 /* do_it */ , 0 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 790 | void |
| 791 | vl_msg_api_handler_no_trace_no_free (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 792 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 793 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 794 | msg_handler_internal (am, the_msg, 0 /* trace_it */ , 1 /* do_it */ , |
| 795 | 0 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* |
| 799 | * Add a trace record to the API message trace buffer, if |
| 800 | * API message tracing is enabled. Handy for adding sufficient |
| 801 | * data to the trace to reproduce autonomous state, as opposed to |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 802 | * state downloaded via control-plane API messages. Example: the NAT |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 803 | * application creates database entries based on packet traffic, not |
| 804 | * control-plane messages. |
| 805 | * |
| 806 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 807 | void |
| 808 | vl_msg_api_trace_only (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 809 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 810 | api_main_t *am = vlibapi_get_main (); |
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 | msg_handler_internal (am, the_msg, |
| 813 | (am->rx_trace |
| 814 | && am->rx_trace->enabled) /* trace_it */ , |
| 815 | 0 /* do_it */ , 0 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 818 | void |
| 819 | vl_msg_api_cleanup_handler (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 820 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 821 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | 9683c1e | 2019-07-01 09:42:41 -0400 | [diff] [blame] | 822 | u16 id = clib_net_to_host_u16 (*((u16 *) the_msg)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 823 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 824 | if (PREDICT_FALSE (id >= vec_len (am->msg_cleanup_handlers))) |
| 825 | { |
| 826 | clib_warning ("_vl_msg_id too large: %d\n", id); |
| 827 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 828 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 829 | if (am->msg_cleanup_handlers[id]) |
| 830 | (*am->msg_cleanup_handlers[id]) (the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 831 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 832 | vl_msg_api_free (the_msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | /* |
| 836 | * vl_msg_api_replay_handler |
| 837 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 838 | void |
| 839 | vl_msg_api_replay_handler (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 840 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 841 | api_main_t *am = vlibapi_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 842 | |
Dave Barach | 9683c1e | 2019-07-01 09:42:41 -0400 | [diff] [blame] | 843 | u16 id = clib_net_to_host_u16 (*((u16 *) the_msg)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 844 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 845 | if (PREDICT_FALSE (id >= vec_len (am->msg_handlers))) |
| 846 | { |
| 847 | clib_warning ("_vl_msg_id too large: %d\n", id); |
| 848 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 849 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 850 | /* do NOT trace the message... */ |
| 851 | if (am->msg_handlers[id]) |
| 852 | (*am->msg_handlers[id]) (the_msg); |
| 853 | /* do NOT free the message buffer... */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 854 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 855 | |
Dave Barach | bfd9227 | 2017-05-12 11:59:25 -0400 | [diff] [blame] | 856 | u32 |
| 857 | vl_msg_api_get_msg_length (void *msg_arg) |
| 858 | { |
| 859 | return vl_msg_api_get_msg_length_inline (msg_arg); |
| 860 | } |
| 861 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 862 | /* |
| 863 | * vl_msg_api_socket_handler |
| 864 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 865 | void |
| 866 | vl_msg_api_socket_handler (void *the_msg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 867 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 868 | api_main_t *am = vlibapi_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 869 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 870 | msg_handler_internal (am, the_msg, |
| 871 | (am->rx_trace |
| 872 | && am->rx_trace->enabled) /* trace_it */ , |
| 873 | 1 /* do_it */ , 0 /* free_it */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 876 | #define foreach_msg_api_vector \ |
| 877 | _ (msg_names) \ |
| 878 | _ (msg_handlers) \ |
| 879 | _ (msg_cleanup_handlers) \ |
| 880 | _ (msg_endian_handlers) \ |
| 881 | _ (msg_print_handlers) \ |
| 882 | _ (msg_print_json_handlers) \ |
| 883 | _ (msg_tojson_handlers) \ |
| 884 | _ (msg_fromjson_handlers) \ |
| 885 | _ (api_trace_cfg) \ |
| 886 | _ (message_bounce) \ |
| 887 | _ (is_mp_safe) \ |
| 888 | _ (is_autoendian) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 889 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 890 | void |
| 891 | vl_msg_api_config (vl_msg_api_msg_config_t * c) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 892 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 893 | api_main_t *am = vlibapi_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 894 | |
Dave Barach | 6545716 | 2017-10-10 17:53:14 -0400 | [diff] [blame] | 895 | /* |
| 896 | * This happens during the java core tests if the message |
| 897 | * dictionary is missing newly added xxx_reply_t messages. |
| 898 | * Should never happen, but since I shot myself in the foot once |
| 899 | * this way, I thought I'd make it easy to debug if I ever do |
| 900 | * it again... (;-)... |
| 901 | */ |
| 902 | if (c->id == 0) |
| 903 | { |
| 904 | if (c->name) |
| 905 | clib_warning ("Trying to register %s with a NULL msg id!", c->name); |
| 906 | else |
| 907 | clib_warning ("Trying to register a NULL msg with a NULL msg id!"); |
| 908 | clib_warning ("Did you forget to call setup_message_id_table?"); |
| 909 | return; |
| 910 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 911 | |
| 912 | #define _(a) vec_validate (am->a, c->id); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 913 | foreach_msg_api_vector; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 914 | #undef _ |
| 915 | |
Dave Barach | 392206e | 2017-09-20 08:40:16 -0400 | [diff] [blame] | 916 | if (am->msg_handlers[c->id] && am->msg_handlers[c->id] != c->handler) |
| 917 | clib_warning |
| 918 | ("BUG: re-registering 'vl_api_%s_t_handler'." |
| 919 | "Handler was %llx, replaced by %llx", |
| 920 | c->name, am->msg_handlers[c->id], c->handler); |
Dave Barach | a1a093d | 2017-03-02 13:13:23 -0500 | [diff] [blame] | 921 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 922 | am->msg_names[c->id] = c->name; |
| 923 | am->msg_handlers[c->id] = c->handler; |
| 924 | am->msg_cleanup_handlers[c->id] = c->cleanup; |
| 925 | am->msg_endian_handlers[c->id] = c->endian; |
| 926 | am->msg_print_handlers[c->id] = c->print; |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 927 | am->msg_print_json_handlers[c->id] = c->print_json; |
| 928 | am->msg_tojson_handlers[c->id] = c->tojson; |
| 929 | am->msg_fromjson_handlers[c->id] = c->fromjson; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 930 | am->message_bounce[c->id] = c->message_bounce; |
| 931 | am->is_mp_safe[c->id] = c->is_mp_safe; |
Ole Troan | e796a18 | 2020-05-18 11:14:05 +0200 | [diff] [blame] | 932 | am->is_autoendian[c->id] = c->is_autoendian; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 933 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 934 | am->api_trace_cfg[c->id].size = c->size; |
| 935 | am->api_trace_cfg[c->id].trace_enable = c->traced; |
| 936 | am->api_trace_cfg[c->id].replay_enable = c->replay; |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 937 | |
| 938 | if (!am->msg_id_by_name) |
| 939 | am->msg_id_by_name = hash_create_string (0, sizeof (uword)); |
| 940 | |
| 941 | hash_set_mem (am->msg_id_by_name, c->name, c->id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 944 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 945 | * vl_msg_api_set_handlers |
| 946 | * preserve the old API for a while |
| 947 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 948 | void |
| 949 | vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup, |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 950 | void *endian, void *print, int size, int traced, |
| 951 | void *print_json, void *tojson, void *fromjson) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 952 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 953 | vl_msg_api_msg_config_t cfg; |
| 954 | vl_msg_api_msg_config_t *c = &cfg; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 955 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 956 | clib_memset (c, 0, sizeof (*c)); |
Dave Barach | 0691d6e | 2017-01-05 10:08:52 -0500 | [diff] [blame] | 957 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 958 | c->id = id; |
| 959 | c->name = name; |
| 960 | c->handler = handler; |
| 961 | c->cleanup = cleanup; |
| 962 | c->endian = endian; |
| 963 | c->print = print; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 964 | c->traced = traced; |
| 965 | c->replay = 1; |
| 966 | c->message_bounce = 0; |
| 967 | c->is_mp_safe = 0; |
Ole Troan | e796a18 | 2020-05-18 11:14:05 +0200 | [diff] [blame] | 968 | c->is_autoendian = 0; |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 969 | c->tojson = tojson; |
| 970 | c->fromjson = fromjson; |
| 971 | c->print_json = print_json; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 972 | vl_msg_api_config (c); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 975 | void |
Matej Perina | 75a17ec | 2017-09-21 17:03:27 +0200 | [diff] [blame] | 976 | vl_msg_api_clean_handlers (int msg_id) |
| 977 | { |
| 978 | vl_msg_api_msg_config_t cfg; |
| 979 | vl_msg_api_msg_config_t *c = &cfg; |
| 980 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 981 | clib_memset (c, 0, sizeof (*c)); |
Matej Perina | 75a17ec | 2017-09-21 17:03:27 +0200 | [diff] [blame] | 982 | |
| 983 | c->id = msg_id; |
| 984 | vl_msg_api_config (c); |
| 985 | } |
| 986 | |
| 987 | void |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 988 | vl_msg_api_set_cleanup_handler (int msg_id, void *fp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 989 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 990 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 991 | ASSERT (msg_id > 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 992 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 993 | vec_validate (am->msg_cleanup_handlers, msg_id); |
| 994 | am->msg_cleanup_handlers[msg_id] = fp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 997 | void |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 998 | vl_msg_api_queue_handler (svm_queue_t * q) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 999 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1000 | uword msg; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1001 | |
Mohsin Kazmi | 3fca567 | 2018-01-04 18:57:26 +0100 | [diff] [blame] | 1002 | while (!svm_queue_sub (q, (u8 *) & msg, SVM_Q_WAIT, 0)) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1003 | vl_msg_api_handler ((void *) msg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 1006 | u32 |
| 1007 | vl_msg_api_max_length (void *mp) |
| 1008 | { |
| 1009 | msgbuf_t *mb; |
| 1010 | u32 data_len = ~0; |
| 1011 | |
| 1012 | /* Work out the maximum sane message length, and return it */ |
| 1013 | if (PREDICT_TRUE (mp != 0)) |
| 1014 | { |
| 1015 | mb = (msgbuf_t *) (((u8 *) mp) - offsetof (msgbuf_t, data)); |
| 1016 | data_len = clib_net_to_host_u32 (mb->data_len); |
| 1017 | } |
| 1018 | return data_len; |
| 1019 | } |
| 1020 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1021 | vl_api_trace_t * |
| 1022 | 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] | 1023 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1024 | switch (which) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1025 | { |
| 1026 | case VL_API_TRACE_RX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1027 | return am->rx_trace; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1028 | case VL_API_TRACE_TX: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1029 | return am->tx_trace; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1030 | default: |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1031 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1035 | void |
| 1036 | vl_noop_handler (void *mp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1037 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1040 | |
| 1041 | static u8 post_mortem_dump_enabled; |
| 1042 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 1043 | void |
| 1044 | vl_msg_api_post_mortem_dump_enable_disable (int enable) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1045 | { |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 1046 | post_mortem_dump_enabled = enable; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1049 | void |
| 1050 | vl_msg_api_post_mortem_dump (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1051 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1052 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1053 | FILE *fp; |
| 1054 | char filename[64]; |
| 1055 | int rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1056 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1057 | if (post_mortem_dump_enabled == 0) |
| 1058 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1059 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1060 | snprintf (filename, sizeof (filename), "/tmp/api_post_mortem.%d", |
| 1061 | getpid ()); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1062 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1063 | fp = fopen (filename, "w"); |
| 1064 | if (fp == NULL) |
| 1065 | { |
| 1066 | rv = write (2, "Couldn't create ", 16); |
| 1067 | rv = write (2, filename, strlen (filename)); |
| 1068 | rv = write (2, "\n", 1); |
| 1069 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1070 | } |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 1071 | rv = vl_msg_api_trace_save (am, VL_API_TRACE_RX, fp, 0); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1072 | fclose (fp); |
| 1073 | if (rv < 0) |
| 1074 | { |
| 1075 | rv = write (2, "Failed to save post-mortem API trace to ", 40); |
| 1076 | rv = write (2, filename, strlen (filename)); |
| 1077 | rv = write (2, "\n", 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1078 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1079 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /* Layered message handling support */ |
| 1083 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1084 | void |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1085 | vl_msg_api_set_first_available_msg_id (u16 first_avail) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1086 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1087 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1088 | |
| 1089 | am->first_available_msg_id = first_avail; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1092 | u16 |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 1093 | vl_msg_api_get_msg_ids (const char *name, int n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1094 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1095 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1096 | u8 *name_copy; |
| 1097 | vl_api_msg_range_t *rp; |
| 1098 | uword *p; |
| 1099 | u16 rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1100 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1101 | if (am->msg_range_by_name == 0) |
| 1102 | am->msg_range_by_name = hash_create_string (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1103 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1104 | name_copy = format (0, "%s%c", name, 0); |
| 1105 | |
| 1106 | p = hash_get_mem (am->msg_range_by_name, name_copy); |
| 1107 | if (p) |
| 1108 | { |
| 1109 | clib_warning ("WARNING: duplicate message range registration for '%s'", |
| 1110 | name_copy); |
| 1111 | vec_free (name_copy); |
| 1112 | return ((u16) ~ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1115 | if (n < 0 || n > 1024) |
| 1116 | { |
| 1117 | clib_warning |
| 1118 | ("WARNING: bad number of message-IDs (%d) requested by '%s'", |
| 1119 | n, name_copy); |
| 1120 | vec_free (name_copy); |
| 1121 | return ((u16) ~ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1124 | vec_add2 (am->msg_ranges, rp, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1125 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1126 | rv = rp->first_msg_id = am->first_available_msg_id; |
| 1127 | am->first_available_msg_id += n; |
| 1128 | rp->last_msg_id = am->first_available_msg_id - 1; |
| 1129 | rp->name = name_copy; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1130 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1131 | 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] | 1132 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1133 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1134 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1135 | |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 1136 | void |
Neale Ranns | e72be39 | 2017-04-26 13:59:20 -0700 | [diff] [blame] | 1137 | 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] | 1138 | { |
| 1139 | uword *p; |
| 1140 | |
| 1141 | if (am->msg_index_by_name_and_crc == 0) |
| 1142 | am->msg_index_by_name_and_crc = hash_create_string (0, sizeof (uword)); |
| 1143 | |
| 1144 | p = hash_get_mem (am->msg_index_by_name_and_crc, string); |
| 1145 | if (p) |
| 1146 | { |
| 1147 | clib_warning ("attempt to redefine '%s' ignored...", string); |
| 1148 | return; |
| 1149 | } |
| 1150 | |
| 1151 | hash_set_mem (am->msg_index_by_name_and_crc, string, id); |
| 1152 | } |
| 1153 | |
Dave Barach | 0d056e5 | 2017-09-28 15:11:16 -0400 | [diff] [blame] | 1154 | void |
| 1155 | vl_msg_api_add_version (api_main_t * am, const char *string, |
| 1156 | u32 major, u32 minor, u32 patch) |
| 1157 | { |
| 1158 | api_version_t version = {.major = major,.minor = minor,.patch = patch }; |
| 1159 | ASSERT (strlen (string) < 64); |
Ole Troan | 7504e99 | 2017-10-10 08:43:35 +0200 | [diff] [blame] | 1160 | strncpy (version.name, string, 64 - 1); |
Dave Barach | 0d056e5 | 2017-09-28 15:11:16 -0400 | [diff] [blame] | 1161 | vec_add1 (am->api_version_list, version); |
| 1162 | } |
Dave Barach | 557d128 | 2016-11-10 14:22:49 -0500 | [diff] [blame] | 1163 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 1164 | u32 |
| 1165 | vl_msg_api_get_msg_index (u8 * name_and_crc) |
| 1166 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1167 | api_main_t *am = vlibapi_get_main (); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 1168 | uword *p; |
| 1169 | |
| 1170 | if (am->msg_index_by_name_and_crc) |
| 1171 | { |
| 1172 | p = hash_get_mem (am->msg_index_by_name_and_crc, name_and_crc); |
| 1173 | if (p) |
| 1174 | return p[0]; |
| 1175 | } |
| 1176 | return ~0; |
| 1177 | } |
| 1178 | |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 1179 | void * |
Nathan Skrzypczak | 0aa4013 | 2019-11-25 16:29:38 +0100 | [diff] [blame] | 1180 | vl_msg_push_heap_w_region (svm_region_t * vlib_rp) |
| 1181 | { |
| 1182 | pthread_mutex_lock (&vlib_rp->mutex); |
| 1183 | return svm_push_data_heap (vlib_rp); |
| 1184 | } |
| 1185 | |
| 1186 | void * |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 1187 | vl_msg_push_heap (void) |
| 1188 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1189 | api_main_t *am = vlibapi_get_main (); |
Nathan Skrzypczak | 0aa4013 | 2019-11-25 16:29:38 +0100 | [diff] [blame] | 1190 | return vl_msg_push_heap_w_region (am->vlib_rp); |
| 1191 | } |
| 1192 | |
| 1193 | void |
| 1194 | vl_msg_pop_heap_w_region (svm_region_t * vlib_rp, void *oldheap) |
| 1195 | { |
| 1196 | svm_pop_heap (oldheap); |
| 1197 | pthread_mutex_unlock (&vlib_rp->mutex); |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | void |
| 1201 | vl_msg_pop_heap (void *oldheap) |
| 1202 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1203 | api_main_t *am = vlibapi_get_main (); |
Nathan Skrzypczak | 0aa4013 | 2019-11-25 16:29:38 +0100 | [diff] [blame] | 1204 | vl_msg_pop_heap_w_region (am->vlib_rp, oldheap); |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
Jakub Grajciar | 2dbee93 | 2020-02-07 11:30:26 +0100 | [diff] [blame] | 1207 | /* Must be nul terminated */ |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1208 | int |
Jakub Grajciar | 2dbee93 | 2020-02-07 11:30:26 +0100 | [diff] [blame] | 1209 | vl_api_c_string_to_api_string (const char *buf, vl_api_string_t * str) |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1210 | { |
Jakub Grajciar | 2dbee93 | 2020-02-07 11:30:26 +0100 | [diff] [blame] | 1211 | /* copy without nul terminator */ |
| 1212 | u32 len = strlen (buf); |
| 1213 | if (len > 0) |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 1214 | clib_memcpy_fast (str->buf, buf, len); |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1215 | str->length = htonl (len); |
| 1216 | return len + sizeof (u32); |
| 1217 | } |
| 1218 | |
Jakub Grajciar | 2dbee93 | 2020-02-07 11:30:26 +0100 | [diff] [blame] | 1219 | /* Must NOT be nul terminated */ |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1220 | int |
| 1221 | vl_api_vec_to_api_string (const u8 * vec, vl_api_string_t * str) |
| 1222 | { |
| 1223 | u32 len = vec_len (vec); |
| 1224 | clib_memcpy (str->buf, vec, len); |
| 1225 | str->length = htonl (len); |
| 1226 | return len + sizeof (u32); |
| 1227 | } |
| 1228 | |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1229 | u32 |
| 1230 | vl_api_string_len (vl_api_string_t * astr) |
| 1231 | { |
Dave Barach | 9683c1e | 2019-07-01 09:42:41 -0400 | [diff] [blame] | 1232 | return clib_net_to_host_u32 (astr->length); |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
Ole Troan | 33a5817 | 2019-09-04 09:12:29 +0200 | [diff] [blame] | 1235 | u8 * |
| 1236 | vl_api_format_string (u8 * s, va_list * args) |
| 1237 | { |
| 1238 | vl_api_string_t *a = va_arg (*args, vl_api_string_t *); |
| 1239 | vec_add (s, a->buf, clib_net_to_host_u32 (a->length)); |
| 1240 | return s; |
| 1241 | } |
| 1242 | |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1243 | /* |
| 1244 | * Returns a new vector. Remember to free it after use. |
Jakub Grajciar | 2dbee93 | 2020-02-07 11:30:26 +0100 | [diff] [blame] | 1245 | * NOT nul terminated. |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1246 | */ |
| 1247 | u8 * |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 1248 | vl_api_from_api_to_new_vec (void *mp, vl_api_string_t * astr) |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1249 | { |
| 1250 | u8 *v = 0; |
Dave Barach | 7784140 | 2020-04-29 17:04:10 -0400 | [diff] [blame] | 1251 | |
| 1252 | if (vl_msg_api_max_length (mp) < clib_net_to_host_u32 (astr->length)) |
| 1253 | return format (0, "insane astr->length %u%c", |
| 1254 | clib_net_to_host_u32 (astr->length), 0); |
Dave Barach | 9683c1e | 2019-07-01 09:42:41 -0400 | [diff] [blame] | 1255 | vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length)); |
Neale Ranns | 377860a | 2019-06-21 07:57:18 -0700 | [diff] [blame] | 1256 | return v; |
| 1257 | } |
Ole Troan | 73710c7 | 2018-06-04 22:27:49 +0200 | [diff] [blame] | 1258 | |
Jakub Grajciar | 2dbee93 | 2020-02-07 11:30:26 +0100 | [diff] [blame] | 1259 | /* |
| 1260 | * Returns a new vector. Remember to free it after use. |
| 1261 | * Nul terminated. |
| 1262 | */ |
| 1263 | char * |
| 1264 | vl_api_from_api_to_new_c_string (vl_api_string_t * astr) |
| 1265 | { |
| 1266 | char *v = 0; |
| 1267 | if (clib_net_to_host_u32 (astr->length) > 0) |
| 1268 | { |
| 1269 | vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length)); |
| 1270 | vec_add1 (v, 0); |
| 1271 | } |
| 1272 | return v; |
| 1273 | } |
| 1274 | |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 1275 | void |
| 1276 | vl_api_set_elog_main (elog_main_t * m) |
| 1277 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1278 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 1279 | am->elog_main = m; |
| 1280 | } |
| 1281 | |
| 1282 | int |
| 1283 | vl_api_set_elog_trace_api_messages (int enable) |
| 1284 | { |
| 1285 | int rv; |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1286 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 1287 | |
| 1288 | rv = am->elog_trace_api_messages; |
| 1289 | am->elog_trace_api_messages = enable; |
| 1290 | return rv; |
| 1291 | } |
| 1292 | |
| 1293 | int |
| 1294 | vl_api_get_elog_trace_api_messages (void) |
| 1295 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 1296 | api_main_t *am = vlibapi_get_main (); |
Dave Barach | b09f4d0 | 2019-07-15 16:00:03 -0400 | [diff] [blame] | 1297 | |
| 1298 | return am->elog_trace_api_messages; |
| 1299 | } |
| 1300 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 1301 | /* |
| 1302 | * fd.io coding-style-patch-verification: ON |
| 1303 | * |
| 1304 | * Local Variables: |
| 1305 | * eval: (c-set-style "gnu") |
| 1306 | * End: |
| 1307 | */ |