Skip to content

Commit 20e713d

Browse files
committed
api: format, size and byte order of messages using the descriptors
Create the text of a message, check its size and convert it to and from network byte order by interpreting its API descriptor, instead of the functions vppapigen generated for every message. The wire format is unchanged. vppapigen does not generate these functions any more, which makes vpp, its plugins and the API clients smaller. Type: improvement Change-Id: I74957ec0cbe1a6c48488ade31a9af2278b9daee5 Signed-off-by: Damjan Marion <dmarion@0xa5.net>
1 parent 50b63df commit 20e713d

57 files changed

Lines changed: 1236 additions & 972 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/interfacing/binapi/api_descriptors.rst‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ The descriptors are declared in ``src/vlibapi/api_desc.h``.
3737
``vl_api_desc_find_msg (am, msg_id)`` returns the descriptor of a registered
3838
message and ``am->desc_files`` has the descriptors of all the files.
3939

40+
What uses them
41+
--------------
42+
43+
* ``vl_api_desc_msg_format ()`` creates the text of a message, which is what
44+
``format_vl_api_msg_text ()`` and the text output of ``api trace dump``
45+
print. VPP does not register the generated ``vl_api_<msg>_t_format``
46+
functions any more.
47+
48+
* ``vl_api_desc_msg_calc_size ()`` calculates the size of a received message
49+
from the lengths in its fields. The message handler drops a message which
50+
is smaller than that, as such a message could make the byte order
51+
conversion or the handler read past its end. VPP does not register the
52+
generated ``vl_api_<msg>_t_calc_size`` functions any more, and a message
53+
which has no descriptor is not checked.
54+
55+
* ``vl_api_msg_endian (am, msg_id, msg, to_net)`` converts a message to or from
56+
network byte order, which is big endian, by interpreting its descriptor.
57+
VPP does not register the generated ``vl_api_<msg>_t_endian`` functions any
58+
more, a message which has no descriptor is still converted by the handler it
59+
was registered with. The descriptor tells which fields are tags of unions
60+
and which are lengths, the conversion reads them before it converts them. The
61+
steps of a message are worked out when it is first used, and kept.
62+
4063
Showing the descriptors
4164
-----------------------
4265

‎extras/strongswan/vpp_sswan/kernel_vpp_ipsec.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <vpp-api/client/stat_client.h>
2626

2727
#define vl_typedefs
28-
#define vl_endianfun
2928
/* Include the (first) vlib-api API definition layer */
3029
#include <vlibmemory/vl_memory_api_h.h>
3130
/* Include the current layer (third) vpp API definition layer */
@@ -39,7 +38,6 @@
3938
#include <vnet/interface.api_enum.h>
4039
#include <vnet/interface.api_types.h>
4140
#undef vl_typedefs
42-
#undef vl_endianfun
4341

4442
#include "kernel_vpp_ipsec.h"
4543
#include "kernel_vpp_shared.h"

‎extras/strongswan/vpp_sswan/kernel_vpp_net.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <threading/mutex.h>
2121

2222
#define vl_typedefs
23-
#define vl_endianfun
2423
/* Include the (first) vlib-api API definition layer */
2524
#include <vlibmemory/vl_memory_api_h.h>
2625
/* Include the current layer (third) vpp API definition layer */
@@ -34,7 +33,6 @@
3433
#include <vnet/interface.api_enum.h>
3534
#include <vnet/interface.api_types.h>
3635
#undef vl_typedefs
37-
#undef vl_endianfun
3836

3937
#include "kernel_vpp_net.h"
4038
#include "kernel_vpp_shared.h"

‎extras/strongswan/vpp_sswan/kernel_vpp_plugin.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@
1818
#include <vlibmemory/api.h>
1919

2020
#define vl_typedefs
21-
#define vl_endianfun
2221
/* Include the (first) vlib-api API definition layer */
2322
#include <vlibmemory/vl_memory_api_h.h>
2423
/* Include the current layer (third) vpp API definition layer */
2524
#include <vpp/api/vpe_types.api.h>
2625
#include <vpp/api/vpe.api.h>
2726
#undef vl_typedefs
28-
#undef vl_endianfun
2927

3028
#include "kernel_vpp_plugin.h"
3129
#include "kernel_vpp_shared.h"

‎extras/strongswan/vpp_sswan/kernel_vpp_shared.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@
2828
#include "kernel_vpp_shared.h"
2929

3030
#define vl_typedefs
31-
#define vl_endianfun
3231
/* Include the (first) vlib-api API definition layer */
3332
#include <vlibmemory/vl_memory_api_h.h>
3433
/* Include the current layer (third) vpp API definition layer */
3534
#include <vpp/api/vpe_types.api.h>
3635
#include <vpp/api/vpe.api.h>
3736
#undef vl_typedefs
38-
#undef vl_endianfun
3937

4038
typedef struct private_vac_t private_vac_t;
4139
typedef struct vl_api_header_t vl_api_header_t;

‎src/cmake/api.cmake‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,15 @@ function(vpp_add_api_files name dir component)
178178
set(target ${name}_api_headers)
179179
file(RELATIVE_PATH rpath ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
180180
foreach(file ${ARGN})
181-
vpp_generate_api_header (${file} ${dir} ${component})
181+
# a file can be listed by more than one library, which compile its
182+
# generated code, but it is generated only once
183+
get_filename_component(abs_file ${file} ABSOLUTE)
184+
set(generated "vpp_api_generated:${abs_file}")
185+
get_property(done GLOBAL PROPERTY "${generated}")
186+
if(NOT done)
187+
vpp_generate_api_header (${file} ${dir} ${component})
188+
set_property(GLOBAL PROPERTY "${generated}" TRUE)
189+
endif()
182190
# Basic api headers get installed in a subdirectory according to
183191
# their component name, but vapi is expected to be found directly under
184192
# "vapi". Both by in-source components (e.g. vpp-api/vapi/vapi.c), and

‎src/cmake/library.cmake‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ macro(add_vpp_library lib)
2222
# the API descriptors of the files
2323
set(api_sources)
2424
foreach(file ${ARG_API_FILES})
25-
list(APPEND api_sources ${CMAKE_CURRENT_BINARY_DIR}/${file}_desc.c)
25+
get_filename_component(desc ${CMAKE_CURRENT_BINARY_DIR}/${file}_desc.c ABSOLUTE)
26+
list(APPEND api_sources ${desc})
2627
endforeach()
28+
# a file of another directory is generated there, GENERATED is not visible
29+
# in other directories
30+
set_source_files_properties(${api_sources} PROPERTIES GENERATED TRUE)
2731

2832
set (lo ${lib}_objs)
2933
add_library(${lo} OBJECT ${ARG_SOURCES} ${api_sources})
@@ -91,6 +95,15 @@ macro(add_vpp_library lib)
9195
vpp_add_api_files(${lib} core vpp ${ARG_API_FILES})
9296
foreach(file ${ARG_API_FILES})
9397
get_filename_component(dir ${file} DIRECTORY)
98+
# the headers of a file which more than one library lists are
99+
# installed with the first one
100+
get_filename_component(abs_file ${file} ABSOLUTE)
101+
set(api_installed "vpp_api_installed:${abs_file}")
102+
get_property(api_installed_done GLOBAL PROPERTY "${api_installed}")
103+
if(api_installed_done)
104+
continue()
105+
endif()
106+
set_property(GLOBAL PROPERTY "${api_installed}" TRUE)
94107
install(
95108
FILES ${file} ${CMAKE_CURRENT_BINARY_DIR}/${file}.h
96109
${CMAKE_CURRENT_BINARY_DIR}/${file}_enum.h

‎src/plugins/acl/acl_test.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
2929
/* Declare message IDs */
3030
#include <acl/acl.api_enum.h>
3131
#include <acl/acl.api_types.h>
32-
#define vl_endianfun /* define message structures */
33-
#include <acl/acl.api.h>
34-
#undef vl_endianfun
32+
#include <vlibapi/api_desc.h>
3533

34+
/* the API descriptors of the file, compiled into the plugin */
35+
extern const vl_api_desc_file_t acl_api_desc __attribute__ ((visibility ("hidden")));
3636
typedef struct {
3737
/* API message ID base */
3838
u16 msg_id_base;
@@ -105,7 +105,8 @@ static void vl_api_acl_interface_list_details_t_handler
105105
int i;
106106
vat_main_t * vam = acl_test_main.vat_main;
107107
u8 *out = 0;
108-
vl_api_acl_interface_list_details_t_endian (mp, 0 /* from network */);
108+
vl_api_desc_file_endian (&acl_api_desc, "acl_interface_list_details", mp,
109+
0 /* from network */);
109110
out = format(out, "sw_if_index: %d, count: %d, n_input: %d\n", mp->sw_if_index, mp->count, mp->n_input);
110111
out = format(out, " input ");
111112
for(i=0; i<mp->count; i++) {
@@ -132,8 +133,8 @@ static void vl_api_acl_interface_etype_whitelist_details_t_handler
132133
int i;
133134
vat_main_t * vam = acl_test_main.vat_main;
134135
u8 *out = 0;
135-
vl_api_acl_interface_etype_whitelist_details_t_endian (
136-
mp, 0 /* from network */);
136+
vl_api_desc_file_endian (&acl_api_desc, "acl_interface_etype_whitelist_details", mp,
137+
0 /* from network */);
137138
out = format(out, "sw_if_index: %d, count: %d, n_input: %d\n", mp->sw_if_index, mp->count, mp->n_input);
138139
out = format(out, " input ");
139140
for(i=0; i<mp->count; i++) {
@@ -183,7 +184,7 @@ static void vl_api_acl_details_t_handler
183184
{
184185
int i;
185186
vat_main_t * vam = acl_test_main.vat_main;
186-
vl_api_acl_details_t_endian (mp, 0 /* from network */);
187+
vl_api_desc_file_endian (&acl_api_desc, "acl_details", mp, 0 /* from network */);
187188
u8 *out = 0;
188189
out = format (0, "acl_index: %d, count: %d\n tag {%s}\n",
189190
mp->acl_index, mp->count, mp->tag);
@@ -218,7 +219,7 @@ static void vl_api_macip_acl_details_t_handler
218219
{
219220
int i;
220221
vat_main_t * vam = acl_test_main.vat_main;
221-
vl_api_macip_acl_details_t_endian (mp, 0 /* from network */);
222+
vl_api_desc_file_endian (&acl_api_desc, "macip_acl_details", mp, 0 /* from network */);
222223
u8 *out = format (0, "MACIP acl_index: %d, count: %d\n tag {%s}\n",
223224
mp->acl_index, mp->count, mp->tag);
224225
for(i=0; i<mp->count; i++) {

‎src/plugins/hs_apps/sapi/vpp_echo_bapi.c‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,6 @@ _(APPLICATION_DETACH_REPLY, application_detach_reply) \
564564
_(APP_ADD_CERT_KEY_PAIR_REPLY, app_add_cert_key_pair_reply) \
565565
_(APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply)
566566

567-
#define vl_endianfun
568-
#include <vnet/session/session.api.h>
569-
#undef vl_endianfun
570-
571-
#define vl_calcsizefun
572-
#include <vnet/session/session.api.h>
573-
#undef vl_calcsizefun
574-
575567
#define vl_printfun
576568
#include <vnet/session/session.api.h>
577569
#undef vl_printfun
@@ -580,6 +572,10 @@ _(APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply)
580572
#include <vnet/session/session.api.h>
581573
#undef vl_api_version
582574

575+
/* the API descriptors of the file, to check the size of the messages */
576+
#include <vlibapi/api_desc.h>
577+
#include <vnet/session/session.api_desc.c>
578+
583579
void
584580
echo_api_hookup (echo_main_t * em)
585581
{
@@ -597,14 +593,13 @@ echo_api_hookup (echo_main_t * em)
597593
.id = REPLY_MSG_ID_BASE + VL_API_##N, \
598594
.name = #n, \
599595
.handler = vl_api_##n##_t_handler, \
600-
.endian = vl_api_##n##_t_endian, \
601-
.format_fn = vl_api_##n##_t_format, \
602596
.size = sizeof (vl_api_##n##_t), \
603597
.traced = 1, \
604598
.tojson = vl_api_##n##_t_tojson, \
605599
.fromjson = vl_api_##n##_t_fromjson, \
606-
.calc_size = vl_api_##n##_t_calc_size, \
607600
});
608601
foreach_quic_echo_msg;
609602
#undef _
603+
604+
vl_api_desc_register (vlibapi_get_main (), &session_api_desc, REPLY_MSG_ID_BASE);
610605
}

‎src/plugins/ikev2/ikev2.api‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ define ikev2_get_sleep_interval_reply {
7878
@param client_index - opaque cookie to identify the sender
7979
@param context - sender context, to match reply w/ request
8080
*/
81-
define ikev2_profile_dump
81+
autoendian define ikev2_profile_dump
8282
{
8383
u32 client_index;
8484
u32 context;
@@ -100,7 +100,7 @@ define ikev2_profile_details
100100
@param client_index - opaque cookie to identify the sender
101101
@param context - sender context, to match reply w/ request
102102
*/
103-
define ikev2_sa_dump
103+
autoendian define ikev2_sa_dump
104104
{
105105
u32 client_index;
106106
u32 context;
@@ -110,7 +110,7 @@ define ikev2_sa_dump
110110
@param client_index - opaque cookie to identify the sender
111111
@param context - sender context, to match reply w/ request
112112
*/
113-
define ikev2_sa_v2_dump
113+
autoendian define ikev2_sa_v2_dump
114114
{
115115
u32 client_index;
116116
u32 context;
@@ -120,7 +120,7 @@ define ikev2_sa_v2_dump
120120
@param client_index - opaque cookie to identify the sender
121121
@param context - sender context, to match reply w/ request
122122
*/
123-
define ikev2_sa_v3_dump
123+
autoendian define ikev2_sa_v3_dump
124124
{
125125
u32 client_index;
126126
u32 context;
@@ -172,7 +172,7 @@ define ikev2_sa_v3_details
172172
@param context - sender context, to match reply w/ request
173173
@param sa_index - index of specific sa
174174
*/
175-
define ikev2_child_sa_dump
175+
autoendian define ikev2_child_sa_dump
176176
{
177177
u32 client_index;
178178
u32 context;
@@ -199,7 +199,7 @@ define ikev2_child_sa_details
199199
@param context - sender context, to match reply w/ request
200200
@param sa_index - index of specific sa
201201
*/
202-
define ikev2_child_sa_v2_dump
202+
autoendian define ikev2_child_sa_v2_dump
203203
{
204204
u32 client_index;
205205
u32 context;
@@ -265,7 +265,7 @@ define ikev2_nonce_get_reply
265265
@param child_sa_index - index of specific sa child of specific sa
266266
*/
267267

268-
define ikev2_traffic_selector_dump
268+
autoendian define ikev2_traffic_selector_dump
269269
{
270270
u32 client_index;
271271
u32 context;

0 commit comments

Comments
 (0)