Hi Dear VPP I wrote an API client sample application to connect to VPP. Although this sample work with VPP 18.07 without any problem, it has "segmentation fault" with VPP 18.10. it would be appreciated if you help me to fix this problem due to latest changes in VPP 18.10. This sample API client source is attached. Also the problem that was observed with GDB back trace is as follows:
Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7137451 in vlib_get_main () at /home/soroosh/amnafzar/ngfw-vpp/src/vlib/global_funcs.h:26 26 vm = vlib_mains[vlib_get_thread_index ()]; (gdb) bt #0 0x00007ffff7137451 in vlib_get_main () at /home/soroosh/amnafzar/ngfw-vpp/src/vlib/global_funcs.h:26 #1 __vlib_cli_command_registration_show_buffers_command () at /home/soroosh/amnafzar/ngfw-vpp/src/vlib/buffer.c:975 #2 0x00007ffff7dea9ba in call_init (l=<optimized out>, argc=argc@entry=1, argv=argv@entry=0x7fffffffe978, env=env@entry=0x7fffffffe988) at dl-init.c:78 #3 0x00007ffff7deaaa3 in call_init (env=0x7fffffffe988, argv=0x7fffffffe978, argc=1, l=<optimized out>) at dl-init.c:36 #4 _dl_init (main_map=0x7ffff7ffe1a8, argc=1, argv=0x7fffffffe978, env=0x7fffffffe988) at dl-init.c:126 #5 0x00007ffff7ddd1ca in _dl_start_user () from /lib64/ld-linux-x86-64.so.2 #6 0x0000000000000001 in ?? () #7 0x00007fffffffebfb in ?? () #8 0x0000000000000000 in ?? ()
#include <stdio.h> #include <stdlib.h> #include <vat/vat.h> #include <vlibapi/api.h> #include <vpp/api/vpe_msg_enum.h> #include<string.h> #define f64_endian(a) #define f64_print(a,b) /* define message structures */ #define vl_typedefs #include <vpp/api/vpe_all_api_h.h> #undef vl_typedefs /* declare message handlers for each api */ #define vl_endianfun /* define message structures */ #include <vpp/api/vpe_all_api_h.h> #undef vl_endianfun /* instantiate all the print functions we know about */ #define vl_print(handle, ...) #define vl_printfun #include <vpp/api/vpe_all_api_h.h> #undef vl_printfun vl_shmem_hdr_t *shmem_hdr; vlib_main_t vlib_global_main; vlib_main_t **vlib_mains; typedef struct { int link_events_on; int stats_on; int oam_events_on; /* convenience */ unix_shared_memory_queue_t *vl_input_queue; u32 my_client_index; } test_main_t; test_main_t test_main; /* define api macros */ #define INIT_MP(tm, mp, msg_id, n) \ mp = vl_msg_api_alloc(sizeof(*mp)+(n));\ memset(mp, 0, sizeof(*mp));\ mp->_vl_msg_id = ntohs(msg_id);\ mp->client_index = tm->my_client_index; static void noop_handler (void *notused){}; #include <vpp/api/vpe_msg_enum.h> vl_api_control_ping_reply_t _control_ping_reply_; static void vl_api_control_ping_reply_t_handler(vl_api_control_ping_reply_t *mp) { memcpy(&_control_ping_reply_, mp, sizeof(*mp)); } static void vl_api_sw_interface_details_t_handler (vl_api_sw_interface_details_t *mp) { printf("%s\n", mp->interface_name); } void vlib_cli_output (struct vlib_main_t *vm, char *fmt, ...) { clib_warning ("vlib_cli_output callled..."); } #define foreach_api_msg \ _(CONTROL_PING_REPLY, control_ping_reply) \ _(SW_INTERFACE_DETAILS, sw_interface_details) void api_init() { #define _(N,n) \ vl_msg_api_set_handlers(VL_API_##N, #n, \ vl_api_##n##_t_handler, \ noop_handler, \ vl_api_##n##_t_endian, \ vl_api_##n##_t_print, \ sizeof(vl_api_##n##_t), 1); foreach_api_msg; #undef _ } void * api_connect(char* name) { api_main_t *am = &api_main; test_main_t *tm = &test_main; int rv = connect_to_vpe(name); if(rv < 0) return 0; tm->vl_input_queue = shmem_hdr->vl_input_queue; tm->my_client_index = am->my_client_index; return (void *)tm; } void api_disconnect() { disconnect_from_vpe (); } int connect_to_vpe (char *name) { int rv = 0; rv = vl_client_connect_to_vlib ("/vpe-api", name, 32); if(rv < 0) return rv; api_init(); shmem_hdr = api_main.shmem_hdr; return rv; } disconnect_from_vpe (void) { vl_client_disconnect_from_vlib (); return 0; } int dump_sw_interface (void * tm) { char *filter = ""; vl_api_sw_interface_dump_t *mp; test_main_t* tmt = (test_main_t*)tm; INIT_MP(tmt, mp, VL_API_SW_INTERFACE_DUMP,0) mp->name_filter_valid = 1; strncpy ((char *) mp->name_filter, filter, sizeof (mp->name_filter) - 1); vl_msg_api_send_shmem (tmt->vl_input_queue, (u8 *) & mp); //control ping vl_api_control_ping_t *mpc; INIT_MP(tmt, mpc, VL_API_CONTROL_PING, 0) vl_msg_api_send_shmem (tmt->vl_input_queue, (u8 *) & mpc); sleep(5); return ntohl(_control_ping_reply_.retval); } #undef vl_api_version #define vl_api_version(n,v) static u32 vpe_api_version = v; #include <vpp/api/vpe.api.h> #undef vl_api_version void vl_client_add_api_signatures (vl_api_memclnt_create_t * mp) { /* * Send the main API signature in slot 0. This bit of code must * match the checks in ../vpe/api/api.c: vl_msg_api_version_check(). */ mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version); } int main(void) { //api connect void* tm = api_connect((char *)"sample"); dump_sw_interface (tm); api_disconnect(); }
Makefile
Description: Binary data
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#11116): https://lists.fd.io/g/vpp-dev/message/11116 Mute This Topic: https://lists.fd.io/mt/27868261/21656 Group Owner: vpp-dev+ow...@lists.fd.io Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-