FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
api.h
Go to the documentation of this file.
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 
23 #include <stddef.h>
24 #include <vppinfra/error.h>
25 #include <svm/svm.h>
26 #include <svm/queue.h>
27 #include <vlib/vlib.h>
28 #include <vlib/unix/unix.h>
29 #include <vlibapi/api_common.h>
30 
31 /* *INDENT-OFF* */
32 typedef CLIB_PACKED ( struct {
33  u32 nitems;
34  u32 msgtbl_size;
35  u8 wrapped;
36 }) vl_api_trace_file_header_t;
37 /* *INDENT-ON* */
38 
40  vl_api_trace_which_t which, FILE * fp);
41 
42 #define VLIB_API_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,api_init)
43 
44 /* Call given init function: used for init function dependencies. */
45 #define vlib_call_api_init_function(vm, x) \
46  ({ \
47  extern vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
48  vlib_init_function_t * _f = _VLIB_INIT_FUNCTION_SYMBOL (x,api_init); \
49  clib_error_t * _error = 0; \
50  if (! hash_get (vm->init_functions_called, _f)) \
51  { \
52  hash_set1 (vm->init_functions_called, _f); \
53  _error = _f (vm); \
54  } \
55  _error; \
56  })
57 
58 #define _VL_MSG_API_FUNCTION_SYMBOL(x, type) \
59  _vl_msg_api_##type##_function_##x
60 
61 #define VL_MSG_API_FUNCTION_SYMBOL(x) \
62  _VL_MSG_API_FUNCTION_SYMBOL(x, reaper)
63 
64 #define VLIB_DECLARE_REAPER_FUNCTION(x, tag) \
65 vl_msg_api_init_function_t * _VL_MSG_API_FUNCTION_SYMBOL (x, tag) = x; \
66 static void __vl_msg_api_add_##tag##_function_##x (void) \
67  __attribute__((__constructor__)) ; \
68  \
69 static void __vl_msg_api_add_##tag##_function_##x (void) \
70 { \
71  api_main_t * am = vlibapi_get_main(); \
72  static _vl_msg_api_function_list_elt_t _vl_msg_api_function; \
73  _vl_msg_api_function.next_init_function \
74  = am->tag##_function_registrations; \
75  am->tag##_function_registrations = &_vl_msg_api_function; \
76  _vl_msg_api_function.f = &x; \
77 }
78 
79 #define VL_MSG_API_REAPER_FUNCTION(x) VLIB_DECLARE_REAPER_FUNCTION(x,reaper)
80 
81 /* Call reaper function with client index */
82 #define vl_msg_api_call_reaper_function(ci) \
83  ({ \
84  extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (reaper); \
85  vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (reaper); \
86  clib_error_t * _error = 0; \
87  _error = _f (ci); \
88  })
89 
90 static inline u32
92 {
93  u8 *msg = (u8 *) msg_arg;
94 
95  msgbuf_t *header = (msgbuf_t *) (msg - offsetof (msgbuf_t, data));
96 
97  return clib_net_to_host_u32 (header->data_len);
98 }
99 
102 void vl_msg_api_trace (api_main_t * am, vl_api_trace_t * tp, void *msg);
104  int onoff);
107  u32 nitems);
109  void *the_msg, vlib_main_t * vm,
111  u8 is_private);
112 u32 vl_msg_api_max_length (void *mp);
115 void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string,
116  u32 id);
117 void vl_msg_api_add_version (api_main_t * am, const char *string,
118  u32 major, u32 minor, u32 patch);
119 /* node_serialize.c prototypes */
120 u8 *vlib_node_serialize (vlib_main_t * vm, vlib_node_t *** node_dups,
121  u8 * vector, int include_nexts, int include_stats);
122 vlib_node_t ***vlib_node_unserialize (u8 * vector);
123 
124 u32 vl_msg_api_get_msg_length (void *msg_arg);
125 
126 #endif /* included_api_h */
127 /*
128  * fd.io coding-style-patch-verification: ON
129  *
130  * Local Variables:
131  * eval: (c-set-style "gnu")
132  * End:
133  */
vlib.h
vl_msg_api_get_msg_length_inline
static u32 vl_msg_api_get_msg_length_inline(void *msg_arg)
Definition: api.h:91
vlib_node_unserialize
vlib_node_t *** vlib_node_unserialize(u8 *vector)
Definition: node_serialize.c:161
vl_msg_api_add_msg_name_crc
void vl_msg_api_add_msg_name_crc(api_main_t *am, const char *string, u32 id)
Definition: api_shared.c:1091
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
am
app_main_t * am
Definition: application.c:489
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
msgbuf_::data_len
u32 data_len
message length not including header
Definition: api_common.h:143
vl_api_trace_which_t
vl_api_trace_which_t
Trace RX / TX enum.
Definition: api_common.h:104
CLIB_PACKED
typedef CLIB_PACKED(struct { u32 nitems;u32 msgtbl_size;u8 wrapped;}) vl_api_trace_file_header_t
vl_msg_api_trace_save
int vl_msg_api_trace_save(api_main_t *am, vl_api_trace_which_t which, FILE *fp)
Definition: api_shared.c:227
which
int which
Definition: cJSON.h:234
vl_msg_api_trace_configure
int vl_msg_api_trace_configure(api_main_t *am, vl_api_trace_which_t which, u32 nitems)
Definition: api_shared.c:366
vl_msg_api_get_msg_length
u32 vl_msg_api_get_msg_length(void *msg_arg)
Definition: api_shared.c:791
error.h
svm.h
patch
u32 patch
Definition: memclnt.api:120
queue.h
vl_msg_api_tx_trace_enabled
int vl_msg_api_tx_trace_enabled(api_main_t *am)
Definition: api_shared.c:68
vl_api_trace_t
API trace state.
Definition: api_common.h:92
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
data
u8 data[128]
Definition: ipsec_types.api:92
vl_msg_api_max_length
u32 vl_msg_api_max_length(void *mp)
Definition: api_shared.c:926
minor
u32 minor
Definition: memclnt.api:119
vl_msg_api_trace_free
int vl_msg_api_trace_free(api_main_t *am, vl_api_trace_which_t which)
Definition: api_shared.c:167
vl_msg_api_rx_trace_enabled
int vl_msg_api_rx_trace_enabled(api_main_t *am)
Definition: api_shared.c:62
u32
unsigned int u32
Definition: types.h:88
msgbuf_
Message header structure.
Definition: api_common.h:140
vl_msg_api_add_version
void vl_msg_api_add_version(api_main_t *am, const char *string, u32 major, u32 minor, u32 patch)
Definition: api_shared.c:1109
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
svm_region_
Definition: svm_common.h:35
u8
unsigned char u8
Definition: types.h:56
unix.h
vl_msg_api_trace
void vl_msg_api_trace(api_main_t *am, vl_api_trace_t *tp, void *msg)
Definition: api_shared.c:77
api_common.h
vlib_node_runtime_t
Definition: node.h:454
vl_msg_api_trace_get
vl_api_trace_t * vl_msg_api_trace_get(api_main_t *am, vl_api_trace_which_t which)
Definition: api_shared.c:941
vl_msg_api_trace_onoff
int vl_msg_api_trace_onoff(api_main_t *am, vl_api_trace_which_t which, int onoff)
Definition: api_shared.c:125
vl_msg_api_handler_with_vm_node
void vl_msg_api_handler_with_vm_node(api_main_t *am, svm_region_t *vlib_rp, void *the_msg, vlib_main_t *vm, vlib_node_runtime_t *node, u8 is_private)
Definition: api_shared.c:557
vlib_node_serialize
u8 * vlib_node_serialize(vlib_main_t *vm, vlib_node_t ***node_dups, u8 *vector, int include_nexts, int include_stats)
Definition: node_serialize.c:51