Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * api.h |
| 4 | * |
| 5 | * Copyright (c) 2009-2015 Cisco and/or its affiliates. |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | *------------------------------------------------------------------ |
| 18 | */ |
| 19 | |
| 20 | #ifndef included_api_h |
| 21 | #define included_api_h |
| 22 | |
Klement Sekera | 58eb866 | 2017-06-09 06:06:49 +0200 | [diff] [blame] | 23 | #include <stddef.h> |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 24 | #include <vppinfra/error.h> |
| 25 | #include <svm/svm.h> |
| 26 | #include <vlib/vlib.h> |
| 27 | #include <vlibmemory/unix_shared_memory_queue.h> |
| 28 | #include <vlib/unix/unix.h> |
Klement Sekera | 58eb866 | 2017-06-09 06:06:49 +0200 | [diff] [blame] | 29 | #include <vlibapi/api_common.h> |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 30 | |
| 31 | /* *INDENT-OFF* */ |
| 32 | typedef CLIB_PACKED |
| 33 | (struct |
| 34 | { |
| 35 | u8 endian; u8 wrapped; |
| 36 | u32 nitems; |
| 37 | }) vl_api_trace_file_header_t; |
| 38 | /* *INDENT-ON* */ |
| 39 | |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 40 | int vl_msg_api_trace_save (api_main_t * am, |
| 41 | vl_api_trace_which_t which, FILE * fp); |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 42 | |
| 43 | #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init) |
| 44 | |
Dave Barach | a1a093d | 2017-03-02 13:13:23 -0500 | [diff] [blame] | 45 | /* Call given init function: used for init function dependencies. */ |
| 46 | #define vlib_call_api_init_function(vm, x) \ |
| 47 | ({ \ |
| 48 | extern vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \ |
| 49 | vlib_init_function_t * _f = _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \ |
| 50 | clib_error_t * _error = 0; \ |
| 51 | if (! hash_get (vm->init_functions_called, _f)) \ |
| 52 | { \ |
| 53 | hash_set1 (vm->init_functions_called, _f); \ |
| 54 | _error = _f (vm); \ |
| 55 | } \ |
| 56 | _error; \ |
| 57 | }) |
| 58 | |
| 59 | |
Dave Barach | b64e4e2 | 2017-03-14 09:10:56 -0400 | [diff] [blame] | 60 | #define _VL_MSG_API_FUNCTION_SYMBOL(x, type) \ |
| 61 | _vl_msg_api_##type##_function_##x |
| 62 | |
| 63 | #define VL_MSG_API_FUNCTION_SYMBOL(x) \ |
| 64 | _VL_MSG_API_FUNCTION_SYMBOL(x, reaper) |
| 65 | |
| 66 | #define VLIB_DECLARE_REAPER_FUNCTION(x, tag) \ |
| 67 | vl_msg_api_init_function_t * _VL_MSG_API_FUNCTION_SYMBOL (x, tag) = x; \ |
| 68 | static void __vl_msg_api_add_##tag##_function_##x (void) \ |
| 69 | __attribute__((__constructor__)) ; \ |
| 70 | \ |
| 71 | static void __vl_msg_api_add_##tag##_function_##x (void) \ |
| 72 | { \ |
| 73 | api_main_t * am = &api_main; \ |
| 74 | static _vl_msg_api_function_list_elt_t _vl_msg_api_function; \ |
| 75 | _vl_msg_api_function.next_init_function \ |
| 76 | = am->tag##_function_registrations; \ |
| 77 | am->tag##_function_registrations = &_vl_msg_api_function; \ |
| 78 | _vl_msg_api_function.f = &x; \ |
| 79 | } |
| 80 | |
| 81 | #define VL_MSG_API_REAPER_FUNCTION(x) VLIB_DECLARE_REAPER_FUNCTION(x,reaper) |
| 82 | |
| 83 | /* Call reaper function with client index */ |
| 84 | #define vl_msg_api_call_reaper_function(ci) \ |
| 85 | ({ \ |
| 86 | extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (reaper); \ |
| 87 | vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (reaper); \ |
| 88 | clib_error_t * _error = 0; \ |
| 89 | _error = _f (ci); \ |
| 90 | }) |
| 91 | |
Dave Barach | bfd9227 | 2017-05-12 11:59:25 -0400 | [diff] [blame] | 92 | static inline u32 |
| 93 | vl_msg_api_get_msg_length_inline (void *msg_arg) |
| 94 | { |
| 95 | u8 *msg = (u8 *) msg_arg; |
| 96 | |
| 97 | msgbuf_t *header = (msgbuf_t *) (msg - offsetof (msgbuf_t, data)); |
| 98 | |
| 99 | return clib_net_to_host_u32 (header->data_len); |
| 100 | } |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 101 | |
Klement Sekera | 58eb866 | 2017-06-09 06:06:49 +0200 | [diff] [blame] | 102 | int vl_msg_api_rx_trace_enabled (api_main_t * am); |
| 103 | int vl_msg_api_tx_trace_enabled (api_main_t * am); |
| 104 | void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg); |
| 105 | int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which, |
| 106 | int onoff); |
| 107 | int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which); |
| 108 | int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which, |
| 109 | u32 nitems); |
| 110 | void vl_msg_api_handler_with_vm_node (api_main_t * am, |
| 111 | void *the_msg, vlib_main_t * vm, |
| 112 | vlib_node_runtime_t * node); |
| 113 | vl_api_trace_t *vl_msg_api_trace_get (api_main_t * am, |
| 114 | vl_api_trace_which_t which); |
| 115 | void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string, |
| 116 | u32 id); |
Dave Barach | 0d056e5 | 2017-09-28 15:11:16 -0400 | [diff] [blame] | 117 | void vl_msg_api_add_version (api_main_t * am, const char *string, |
| 118 | u32 major, u32 minor, u32 patch); |
Klement Sekera | 58eb866 | 2017-06-09 06:06:49 +0200 | [diff] [blame] | 119 | /* node_serialize.c prototypes */ |
| 120 | u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector, |
| 121 | u32 max_threads, int include_nexts, |
| 122 | int include_stats); |
| 123 | vlib_node_t **vlib_node_unserialize (u8 * vector); |
| 124 | u32 vl_msg_api_get_msg_length (void *msg_arg); |
| 125 | |
| 126 | #endif /* included_api_h */ |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 127 | /* |
| 128 | * fd.io coding-style-patch-verification: ON |
| 129 | * |
| 130 | * Local Variables: |
| 131 | * eval: (c-set-style "gnu") |
| 132 | * End: |
| 133 | */ |