X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fipfix-export%2Fflow_api.c;h=84babe7dcdcc8e0be3a7c44db485a1d883739d25;hb=59f71132e;hp=5df968414c8c51f25fc8027dcc50517728d7e7d6;hpb=b7b929931a07fbb27b43d5cd105f366c3e29807e;p=vpp.git diff --git a/src/vnet/ipfix-export/flow_api.c b/src/vnet/ipfix-export/flow_api.c index 5df968414c8..84babe7dcdc 100644 --- a/src/vnet/ipfix-export/flow_api.c +++ b/src/vnet/ipfix-export/flow_api.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -51,13 +52,15 @@ _(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \ _(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \ _(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \ _(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \ -_(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) +_(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \ +_(IPFIX_FLUSH, ipfix_flush) static void vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp) { vlib_main_t *vm = vlib_get_main (); flow_report_main_t *frm = &flow_report_main; + vl_api_registration_t *reg; vl_api_set_ipfix_exporter_reply_t *rmp; ip4_address_t collector, src; u16 collector_port = UDP_DST_PORT_ipfix; @@ -68,11 +71,22 @@ vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp) u32 fib_index = ~0; int rv = 0; - memcpy (collector.data, mp->collector_address, sizeof (collector.data)); + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (mp->src_address.af == ADDRESS_IP6 + || mp->collector_address.af == ADDRESS_IP6) + { + rv = VNET_API_ERROR_UNIMPLEMENTED; + goto out; + } + + ip4_address_decode (mp->collector_address.un.ip4, &collector); collector_port = ntohs (mp->collector_port); if (collector_port == (u16) ~ 0) collector_port = UDP_DST_PORT_ipfix; - memcpy (src.data, mp->src_address, sizeof (src.data)); + ip4_address_decode (mp->src_address.un.ip4, &src); fib_id = ntohl (mp->vrf_id); ip4_main_t *im = &ip4_main; @@ -151,21 +165,27 @@ vl_api_ipfix_exporter_dump_t_handler (vl_api_ipfix_exporter_dump_t * mp) vl_api_registration_t *reg; vl_api_ipfix_exporter_details_t *rmp; ip4_main_t *im = &ip4_main; + ip46_address_t collector = {.as_u64[0] = 0,.as_u64[1] = 0 }; + ip46_address_t src = {.as_u64[0] = 0,.as_u64[1] = 0 }; u32 vrf_id; reg = vl_api_client_index_to_registration (mp->client_index); if (!reg) - return;; + return; rmp = vl_msg_api_alloc (sizeof (*rmp)); clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_IPFIX_EXPORTER_DETAILS); rmp->context = mp->context; - memcpy (rmp->collector_address, frm->ipfix_collector.data, - sizeof (frm->ipfix_collector.data)); + + memcpy (&collector.ip4, &frm->ipfix_collector, sizeof (ip4_address_t)); + ip_address_encode (&collector, IP46_TYPE_IP4, &rmp->collector_address); + rmp->collector_port = htons (frm->collector_port); - memcpy (rmp->src_address, frm->src_address.data, - sizeof (frm->src_address.data)); + + memcpy (&src.ip4, &frm->src_address, sizeof (ip4_address_t)); + ip_address_encode (&src, IP46_TYPE_IP4, &rmp->src_address); + if (frm->fib_index == ~0) vrf_id = ~0; else @@ -233,6 +253,7 @@ static void (vl_api_ipfix_classify_table_add_del_t * mp) { vl_api_ipfix_classify_table_add_del_reply_t *rmp; + vl_api_registration_t *reg; flow_report_classify_main_t *fcm = &flow_report_classify_main; flow_report_main_t *frm = &flow_report_main; vnet_flow_report_add_del_args_t args; @@ -243,9 +264,13 @@ static void u8 transport_protocol; int rv = 0; + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + classify_table_index = ntohl (mp->table_id); - ip_version = mp->ip_version; - transport_protocol = mp->transport_protocol; + ip_version = ntohl (mp->ip_version); + transport_protocol = ntohl (mp->transport_protocol); is_add = mp->is_add; if (fcm->src_port == 0) @@ -320,8 +345,8 @@ send_ipfix_classify_table_details (u32 table_index, mp->_vl_msg_id = ntohs (VL_API_IPFIX_CLASSIFY_TABLE_DETAILS); mp->context = context; mp->table_id = htonl (table->classify_table_index); - mp->ip_version = table->ip_version; - mp->transport_protocol = table->transport_protocol; + mp->ip_version = htonl (table->ip_version); + mp->transport_protocol = htonl (table->transport_protocol); vl_api_send_msg (reg, (u8 *) mp); } @@ -343,10 +368,29 @@ static void send_ipfix_classify_table_details (i, reg, mp->context); } +static void +vl_api_ipfix_flush_t_handler (vl_api_ipfix_flush_t * mp) +{ + vl_api_ipfix_flush_reply_t *rmp; + vl_api_registration_t *reg; + vlib_main_t *vm = vlib_get_main (); + int rv = 0; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + /* poke the flow reporting process */ + vlib_process_signal_event (vm, flow_report_process_node.index, + 1 /* type_opaque */ , 0 /* data */ ); + + REPLY_MACRO (VL_API_IPFIX_FLUSH_REPLY); +} + /* * flow_api_hookup * Add vpe's API message handlers to the table. - * vlib has alread mapped shared memory and + * vlib has already mapped shared memory and * added the client registration handlers. * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() */ @@ -365,7 +409,7 @@ setup_message_id_table (api_main_t * am) static clib_error_t * flow_api_hookup (vlib_main_t * vm) { - api_main_t *am = &api_main; + api_main_t *am = vlibapi_get_main (); #define _(N,n) \ vl_msg_api_set_handlers(VL_API_##N, #n, \