blob: 74957a6f0f6e9e3f58435a56a2d001f8cbd8d056 [file] [log] [blame]
Damjan Marion7cd468a2016-12-19 23:05:39 +01001/*
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 Sekera58eb8662017-06-09 06:06:49 +020023#include <stddef.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010024#include <vppinfra/error.h>
25#include <svm/svm.h>
Florin Corase86a8ed2018-01-05 03:20:25 -080026#include <svm/queue.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010027#include <vlib/vlib.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010028#include <vlib/unix/unix.h>
Klement Sekera58eb8662017-06-09 06:06:49 +020029#include <vlibapi/api_common.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010030
Florin Corase86a8ed2018-01-05 03:20:25 -080031typedef CLIB_PACKED ( struct {
Damjan Marion7cd468a2016-12-19 23:05:39 +010032 u32 nitems;
Ole Troanedfe2c02019-07-30 15:38:13 +020033 u32 msgtbl_size;
34 u8 wrapped;
Damjan Marion7cd468a2016-12-19 23:05:39 +010035}) vl_api_trace_file_header_t;
Damjan Marion7cd468a2016-12-19 23:05:39 +010036
Filip Tehlar36217e32021-07-23 08:51:10 +000037int vl_msg_api_trace_save (api_main_t *am, vl_api_trace_which_t which,
38 FILE *fp, u8 is_json);
Damjan Marion7cd468a2016-12-19 23:05:39 +010039
40#define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
41
Dave Baracha1a093d2017-03-02 13:13:23 -050042/* Call given init function: used for init function dependencies. */
43#define vlib_call_api_init_function(vm, x) \
44 ({ \
45 extern vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
46 vlib_init_function_t * _f = _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
47 clib_error_t * _error = 0; \
48 if (! hash_get (vm->init_functions_called, _f)) \
49 { \
50 hash_set1 (vm->init_functions_called, _f); \
51 _error = _f (vm); \
52 } \
53 _error; \
54 })
55
Dave Barachb64e4e22017-03-14 09:10:56 -040056#define _VL_MSG_API_FUNCTION_SYMBOL(x, type) \
57 _vl_msg_api_##type##_function_##x
58
59#define VL_MSG_API_FUNCTION_SYMBOL(x) \
60 _VL_MSG_API_FUNCTION_SYMBOL(x, reaper)
61
62#define VLIB_DECLARE_REAPER_FUNCTION(x, tag) \
63vl_msg_api_init_function_t * _VL_MSG_API_FUNCTION_SYMBOL (x, tag) = x; \
64static void __vl_msg_api_add_##tag##_function_##x (void) \
65 __attribute__((__constructor__)) ; \
66 \
67static void __vl_msg_api_add_##tag##_function_##x (void) \
68{ \
Dave Barach39d69112019-11-27 11:42:13 -050069 api_main_t * am = vlibapi_get_main(); \
Dave Barachb64e4e22017-03-14 09:10:56 -040070 static _vl_msg_api_function_list_elt_t _vl_msg_api_function; \
71 _vl_msg_api_function.next_init_function \
72 = am->tag##_function_registrations; \
73 am->tag##_function_registrations = &_vl_msg_api_function; \
74 _vl_msg_api_function.f = &x; \
75}
76
77#define VL_MSG_API_REAPER_FUNCTION(x) VLIB_DECLARE_REAPER_FUNCTION(x,reaper)
78
79/* Call reaper function with client index */
80#define vl_msg_api_call_reaper_function(ci) \
81 ({ \
82 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (reaper); \
83 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (reaper); \
84 clib_error_t * _error = 0; \
85 _error = _f (ci); \
86 })
87
Dave Barachbfd92272017-05-12 11:59:25 -040088static inline u32
89vl_msg_api_get_msg_length_inline (void *msg_arg)
90{
91 u8 *msg = (u8 *) msg_arg;
92
93 msgbuf_t *header = (msgbuf_t *) (msg - offsetof (msgbuf_t, data));
94
95 return clib_net_to_host_u32 (header->data_len);
96}
Damjan Marion7cd468a2016-12-19 23:05:39 +010097
Klement Sekera58eb8662017-06-09 06:06:49 +020098int vl_msg_api_rx_trace_enabled (api_main_t * am);
99int vl_msg_api_tx_trace_enabled (api_main_t * am);
100void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg);
101int vl_msg_api_trace_onoff (api_main_t * am, vl_api_trace_which_t which,
102 int onoff);
103int vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which);
104int vl_msg_api_trace_configure (api_main_t * am, vl_api_trace_which_t which,
105 u32 nitems);
Dave Barach77841402020-04-29 17:04:10 -0400106u32 vl_msg_api_max_length (void *mp);
Klement Sekera58eb8662017-06-09 06:06:49 +0200107vl_api_trace_t *vl_msg_api_trace_get (api_main_t * am,
108 vl_api_trace_which_t which);
109void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string,
110 u32 id);
Dave Barach0d056e52017-09-28 15:11:16 -0400111void vl_msg_api_add_version (api_main_t * am, const char *string,
112 u32 major, u32 minor, u32 patch);
Klement Sekera58eb8662017-06-09 06:06:49 +0200113/* node_serialize.c prototypes */
Florin Corase86a8ed2018-01-05 03:20:25 -0800114u8 *vlib_node_serialize (vlib_main_t * vm, vlib_node_t *** node_dups,
115 u8 * vector, int include_nexts, int include_stats);
Dave Barach1ddbc012018-06-13 09:26:05 -0400116vlib_node_t ***vlib_node_unserialize (u8 * vector);
Florin Corase86a8ed2018-01-05 03:20:25 -0800117
Klement Sekera58eb8662017-06-09 06:06:49 +0200118u32 vl_msg_api_get_msg_length (void *msg_arg);
119
Filip Tehlar36217e32021-07-23 08:51:10 +0000120typedef int (*vl_msg_traverse_trace_fn) (u8 *, void *);
121
122int vl_msg_traverse_trace (vl_api_trace_t *tp, vl_msg_traverse_trace_fn fn,
123 void *ctx);
124
Damjan Marioncada9eb2022-05-18 22:16:11 +0200125always_inline void
126vl_api_increase_msg_trace_size (api_main_t *am, u32 msg_id, u32 inc)
127{
128 am->msg_data[msg_id].trace_size += inc;
129}
130
131always_inline void
132vl_api_set_msg_thread_safe (api_main_t *am, u32 msg_id, int v)
133{
134 am->msg_data[msg_id].is_mp_safe = v != 0;
135}
136
137always_inline void
138vl_api_set_msg_autoendian (api_main_t *am, u32 msg_id, int v)
139{
140 am->msg_data[msg_id].is_autoendian = v != 0;
141}
142
143always_inline void
144vl_api_allow_msg_replay (api_main_t *am, u32 msg_id, int v)
145{
146 am->msg_data[msg_id].replay_allowed = v != 0;
147}
148
Damjan Marionfe45f8f2022-05-20 16:01:22 +0200149format_function_t format_vl_api_msg_text;
150format_function_t format_vl_api_msg_json;
151
Klement Sekera58eb8662017-06-09 06:06:49 +0200152#endif /* included_api_h */
Damjan Marion7cd468a2016-12-19 23:05:39 +0100153/*
154 * fd.io coding-style-patch-verification: ON
155 *
156 * Local Variables:
157 * eval: (c-set-style "gnu")
158 * End:
159 */