4545#include <pthread.h>
4646#include <errno.h>
4747#include <signal.h>
48+ #include <sys/time.h>
4849#if defined(__OpenBSD__ ) || defined(__FreeBSD__ )
4950#include <pthread_np.h>
5051#else
5859#include "fpipe.h"
5960#include "ring.h"
6061#include "message_ipfix.h"
62+ #include "message_periodic.h"
6163#include "configurator/cpipe.h"
6264
6365/** Identification of this component (for log) */
@@ -191,7 +193,7 @@ ipx_ctx_create(const char *name, const struct ipx_ctx_callbacks *callbacks)
191193 ctx -> cfg_system .vlevel = ipx_verb_level_get ();
192194 ctx -> cfg_system .rec_size = IPX_MSG_IPFIX_BASE_REC_SIZE ;
193195 ctx -> cfg_system .msg_mask_selected = 0 ; // No messages to process selected
194- ctx -> cfg_system .msg_mask_allowed = IPX_MSG_IPFIX | IPX_MSG_SESSION ;
196+ ctx -> cfg_system .msg_mask_allowed = IPX_MSG_IPFIX | IPX_MSG_SESSION | IPX_MSG_PERIODIC ;
195197 ctx -> cfg_system .term_msg_cnt = 1 ; // By default, wait for 1 termination message
196198
197199 ctx -> cfg_extension .items = NULL ;
@@ -816,14 +818,14 @@ thread_handle_rc(struct ipx_ctx *ctx, int rc)
816818 // No more data -> stop the collector
817819 IPX_CTX_DEBUG (ctx , "The instance has signalized end-of-file/stream." , '\0' );
818820 ipx_ctx_processing_set (ctx , false);
819- ipx_cpipe_send_term (ctx , IPX_CPIPE_TYPE_TERM_SLOW );
821+ ipx_cpipe_send (ctx , IPX_CPIPE_TYPE_TERM_SLOW );
820822 break ;
821823 case IPX_ERR_DENIED :
822824 // Fatal error -> stop the collector as fast as possible
823825 IPX_CTX_ERROR (ctx , "ipx_plugin_get()/ipx_plugin_process() failed! The collector cannot "
824826 "work properly anymore!" , '\0' );
825827 ipx_ctx_processing_set (ctx , false);
826- ipx_cpipe_send_term (ctx , IPX_CPIPE_TYPE_TERM_FAST );
828+ ipx_cpipe_send (ctx , IPX_CPIPE_TYPE_TERM_FAST );
827829 break ;
828830 default :
829831 IPX_CTX_ERROR (ctx , "ipx_plugin_get()/ipx_plugin_process() returned unexpected return "
@@ -876,6 +878,13 @@ thread_input_process_pipe(struct ipx_ctx *ctx)
876878 return IPX_OK ;
877879 }
878880
881+ if (msg_type == IPX_MSG_PERIODIC ) {
882+ ipx_msg_periodic_t * periodic_message = ipx_msg_base2periodic (msg_ptr );
883+ ipx_msg_periodic_update_last_processed (periodic_message );
884+ ipx_ctx_msg_pass (ctx , msg_ptr );
885+ return IPX_OK ;
886+ }
887+
879888 if (msg_type == IPX_MSG_TERMINATE ) {
880889 // Destroy the instance (usually produce garbage messages, etc)
881890 const char * plugin_name = ctx -> plugin_cbs -> info -> name ;
@@ -954,6 +963,8 @@ thread_intermediate(void *arg)
954963 ipx_msg_t * msg_ptr ;
955964 enum ipx_msg_type msg_type ;
956965
966+ uint64_t waiting_for_seq = 0 ;
967+
957968 bool terminate = false;
958969 while (!terminate ) {
959970 // Get a new message for the buffer
@@ -978,6 +989,16 @@ thread_intermediate(void *arg)
978989 }
979990 }
980991
992+ if (msg_type == IPX_MSG_PERIODIC ) {
993+ ipx_msg_periodic_t * periodic_message = ipx_msg_base2periodic (msg_ptr );
994+ if (ipx_msg_periodic_get_seq_num (periodic_message ) != waiting_for_seq ) {
995+ ipx_msg_periodic_destroy (periodic_message );
996+ continue ;
997+ }
998+ waiting_for_seq ++ ;
999+ ipx_msg_periodic_update_last_processed (periodic_message );
1000+ }
1001+
9811002 if (!ipx_ctx_processing_get (ctx )
9821003 && (msg_type == IPX_MSG_IPFIX || msg_type == IPX_MSG_SESSION )) {
9831004 // Data processing is disabled -> drop IPFIX and Session messages
@@ -1048,6 +1069,11 @@ thread_output(void *arg)
10481069 thread_handle_rc (ctx , rc );
10491070 }
10501071
1072+ if (msg_type == IPX_MSG_PERIODIC ) {
1073+ ipx_msg_periodic_t * periodic_message = ipx_msg_base2periodic (msg_ptr );
1074+ ipx_msg_periodic_update_last_processed (periodic_message );
1075+ }
1076+
10511077 if (msg_type == IPX_MSG_TERMINATE ) {
10521078 ipx_msg_terminate_t * terminate_msg = ipx_msg_base2terminate (msg_ptr );
10531079 enum ipx_msg_terminate_type type = ipx_msg_terminate_get_type (terminate_msg );
0 commit comments