diff --git a/deps/dablooms/dablooms.h b/deps/dablooms/dablooms.h index bf5c654..f64cd6e 100644 --- a/deps/dablooms/dablooms.h +++ b/deps/dablooms/dablooms.h @@ -2,6 +2,12 @@ #ifndef __BLOOM_H__ #define __BLOOM_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + #include #include @@ -97,4 +103,8 @@ int expiry_dablooms_element_count_get(struct expiry_dablooms_handle *handle, uin int expiry_dablooms_add(struct expiry_dablooms_handle *handle, const char *key, size_t len, time_t cur_time); int expiry_dablooms_search(struct expiry_dablooms_handle *handle, const char *key, size_t len, time_t cur_time); +#ifdef __cplusplus +} +#endif + #endif diff --git a/deps/interval_tree/interval_tree.h b/deps/interval_tree/interval_tree.h index 0b3d169..c446a25 100644 --- a/deps/interval_tree/interval_tree.h +++ b/deps/interval_tree/interval_tree.h @@ -2,6 +2,11 @@ #ifndef _LINUX_INTERVAL_TREE_H #define _LINUX_INTERVAL_TREE_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include "rbtree.h" #include @@ -30,4 +35,8 @@ extern struct interval_tree_node * interval_tree_iter_next(struct interval_tree_node *node, uint64_t start, uint64_t last); +#ifdef __cplusplus +} +#endif + #endif /* _LINUX_INTERVAL_TREE_H */ diff --git a/deps/interval_tree/interval_tree_generic.h b/deps/interval_tree/interval_tree_generic.h index 872c264..bf452c8 100644 --- a/deps/interval_tree/interval_tree_generic.h +++ b/deps/interval_tree/interval_tree_generic.h @@ -7,6 +7,11 @@ include/linux/interval_tree_generic.h */ +#ifdef __cplusplus +extern "C" +{ +#endif + #include "rbtree_augmented.h" /* @@ -195,3 +200,7 @@ return node; \ } \ } + +#ifdef __cplusplus +} +#endif diff --git a/deps/rbtree/rbtree.h b/deps/rbtree/rbtree.h index c7ab471..3f9b49a 100644 --- a/deps/rbtree/rbtree.h +++ b/deps/rbtree/rbtree.h @@ -17,6 +17,11 @@ #ifndef _LINUX_RBTREE_H #define _LINUX_RBTREE_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include struct rb_node @@ -380,4 +385,8 @@ rb_next_match(const void *key, struct rb_node *node, for ((node) = rb_find_first((key), (tree), (cmp)); \ (node); (node) = rb_next_match((key), (node), (cmp))) +#ifdef __cplusplus +} +#endif + #endif /* _LINUX_RBTREE_H */ diff --git a/deps/rbtree/rbtree_augmented.h b/deps/rbtree/rbtree_augmented.h index add1ee5..48214a8 100644 --- a/deps/rbtree/rbtree_augmented.h +++ b/deps/rbtree/rbtree_augmented.h @@ -12,6 +12,11 @@ #ifndef _LINUX_RBTREE_AUGMENTED_H #define _LINUX_RBTREE_AUGMENTED_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include "rbtree.h" /* @@ -317,4 +322,8 @@ rb_erase_augmented_cached(struct rb_node *node, struct rb_root_cached *root, rb_erase_augmented(node, &root->rb_root, augment); } +#ifdef __cplusplus +} +#endif + #endif /* _LINUX_RBTREE_AUGMENTED_H */ diff --git a/include/stellar/log.h b/include/stellar/log.h index d77fdd0..a075267 100644 --- a/include/stellar/log.h +++ b/include/stellar/log.h @@ -52,8 +52,6 @@ enum log_level } struct logger; -struct logger *stellar_get_logger(struct stellar *st); - int log_check_level(struct logger *logger, enum log_level level); void log_print(struct logger *logger, enum log_level level, const char *module, const char *fmt, ...); diff --git a/include/stellar/packet.h b/include/stellar/packet.h index 4e588b0..a9583b8 100644 --- a/include/stellar/packet.h +++ b/include/stellar/packet.h @@ -16,6 +16,7 @@ extern "C" #include #include +struct packet; /****************************************************************************** * layer ******************************************************************************/ diff --git a/include/stellar/stellar.h b/include/stellar/stellar.h index 1cb5c23..99fc74c 100644 --- a/include/stellar/stellar.h +++ b/include/stellar/stellar.h @@ -64,6 +64,7 @@ void stellar_run(struct stellar *st); void stellar_free(struct stellar *st); void stellar_loopbreak(struct stellar *st); void stellar_reload_log_level(struct stellar *st); +struct logger *stellar_get_logger(struct stellar *st); #ifdef __cplusplus } diff --git a/infra/core/stellar_core.c b/infra/core/stellar_core.c index bf4f2f6..a2558e8 100644 --- a/infra/core/stellar_core.c +++ b/infra/core/stellar_core.c @@ -72,8 +72,8 @@ struct stellar struct stellar_config config; }; -static thread_local uint16_t __current_thread_idx = UINT16_MAX; -static thread_local struct snowflake *__current_thread_snowflake = NULL; +static __thread uint16_t __current_thread_idx = UINT16_MAX; +static __thread struct snowflake *__current_thread_snowflake = NULL; uint64_t stellar_generate_session_id(uint64_t now_sec); diff --git a/infra/log/log.c b/infra/log/log.c index d627f35..3f961fe 100644 --- a/infra/log/log.c +++ b/infra/log/log.c @@ -39,7 +39,7 @@ static unsigned char level_str[6][6] = {"TRACE", "DEBUG", "INFO", "WARN", "ERROR static unsigned char weekday_str[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; -thread_local struct logger *__thread_local_logger; +__thread struct logger *__thread_local_logger; /****************************************************************************** * Private API @@ -163,7 +163,7 @@ static int config_parse(struct log_config *config, const char *config_file) goto error_out; } config->level = (enum log_level)str_to_level(ptr_level); - if (config->level == -1) + if ((int)config->level == -1) { fprintf(stderr, "config file %s invalid log.level\n", config_file); goto error_out; diff --git a/infra/log/log_private.h b/infra/log/log_private.h index dd18040..844d86b 100644 --- a/infra/log/log_private.h +++ b/infra/log/log_private.h @@ -7,7 +7,7 @@ extern "C" #include "stellar/log.h" -extern thread_local struct logger *__thread_local_logger; +extern __thread struct logger *__thread_local_logger; struct logger *log_new(const char *config_file); void log_free(struct logger *logger); diff --git a/infra/packet_io/packet_io.h b/infra/packet_io/packet_io.h index 7decb74..e48178f 100644 --- a/infra/packet_io/packet_io.h +++ b/infra/packet_io/packet_io.h @@ -68,6 +68,7 @@ struct packet_io_options uint16_t cpu_mask[MAX_THREAD_NUM]; }; +struct packet; struct packet_io; struct packet_io *packet_io_new(struct packet_io_options *opts); void packet_io_free(struct packet_io *packet_io); diff --git a/infra/packet_parser/checksum.c b/infra/packet_parser/checksum.c index a984598..c7a8266 100644 --- a/infra/packet_parser/checksum.c +++ b/infra/packet_parser/checksum.c @@ -1,7 +1,5 @@ #include "checksum.h" -#include - uint16_t checksum(const void *data, int len) { uint16_t *ptr = (uint16_t *)data; diff --git a/infra/packet_parser/checksum.h b/infra/packet_parser/checksum.h index 56c5b5e..3d762bb 100644 --- a/infra/packet_parser/checksum.h +++ b/infra/packet_parser/checksum.h @@ -6,6 +6,7 @@ extern "C" #endif #include +#include uint16_t checksum(const void *data, int len); uint16_t checksum_v4(const void *l4_hdr_ptr, uint16_t l4_total_len, uint8_t l4_proto, struct in_addr *src_addr, struct in_addr *dst_addr); diff --git a/infra/packet_parser/packet_dump.h b/infra/packet_parser/packet_dump.h index 689bfd5..75af2c6 100644 --- a/infra/packet_parser/packet_dump.h +++ b/infra/packet_parser/packet_dump.h @@ -5,6 +5,8 @@ extern "C" { #endif +struct packet; + // return 0: success // return -1: failed int packet_dump_pcap(const struct packet *pkt, const char *file); diff --git a/infra/packet_parser/packet_filter.h b/infra/packet_parser/packet_filter.h index 8cf4428..9a30f62 100644 --- a/infra/packet_parser/packet_filter.h +++ b/infra/packet_parser/packet_filter.h @@ -5,6 +5,8 @@ extern "C" { #endif +struct packet; + // Duplicated Packet Filter for IPv4 Packet struct packet_filter; struct packet_filter *packet_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now); diff --git a/infra/packet_parser/packet_helper.h b/infra/packet_parser/packet_helper.h index f4beda2..4782fb9 100644 --- a/infra/packet_parser/packet_helper.h +++ b/infra/packet_parser/packet_helper.h @@ -8,6 +8,7 @@ extern "C" #include "utils.h" #include #include +#include #include #include #include diff --git a/infra/packet_parser/packet_parser.c b/infra/packet_parser/packet_parser.c index f19c1f7..c206f19 100644 --- a/infra/packet_parser/packet_parser.c +++ b/infra/packet_parser/packet_parser.c @@ -9,7 +9,7 @@ #include "packet_private.h" #include "packet_parser.h" -#define PACKET_PARSE_LOG_DEBUG(format, ...) void(0) // STELLAR_LOG_DEBUG(__thread_local_logger, "packet parse", format, ##__VA_ARGS__) +#define PACKET_PARSE_LOG_DEBUG(format, ...) // STELLAR_LOG_DEBUG(__thread_local_logger, "packet parse", format, ##__VA_ARGS__) #define PACKET_PARSE_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "packet parse", format, ##__VA_ARGS__) #define PACKET_PARSE_LOG_WARN(format, ...) STELLAR_LOG_WARN(__thread_local_logger, "packet parse", format, ##__VA_ARGS__) @@ -214,6 +214,7 @@ static inline const char *parse_ppp(struct packet *pkt, const char *data, uint16 uint16_t hdr_len = 0; uint16_t next_proto = 0; + struct layer_private *layer = NULL; // ppp header 1 byte next_proto = *((uint8_t *)data); @@ -236,7 +237,7 @@ static inline const char *parse_ppp(struct packet *pkt, const char *data, uint16 hdr_len = 4; success: - struct layer_private *layer = get_free_layer(pkt); + layer = get_free_layer(pkt); if (unlikely(layer == NULL)) { return data; diff --git a/infra/packet_parser/packet_private.h b/infra/packet_parser/packet_private.h index ead56b3..69a2fb3 100644 --- a/infra/packet_parser/packet_private.h +++ b/infra/packet_parser/packet_private.h @@ -5,6 +5,7 @@ extern "C" { #endif +#include "tuple.h" #include "stellar/packet.h" #define PACKET_MAX_LAYERS 32 diff --git a/infra/session_manager/session_private.h b/infra/session_manager/session_private.h index c7456aa..2c1b746 100644 --- a/infra/session_manager/session_private.h +++ b/infra/session_manager/session_private.h @@ -5,6 +5,8 @@ extern "C" { #endif +#include + #include "list.h" #include "tuple.h" #include "uthash.h" diff --git a/infra/tcp_reassembly/tcp_reassembly.c b/infra/tcp_reassembly/tcp_reassembly.c index 3abbc87..962a166 100644 --- a/infra/tcp_reassembly/tcp_reassembly.c +++ b/infra/tcp_reassembly/tcp_reassembly.c @@ -1,4 +1,5 @@ #include +#include #include "list.h" #include "log_private.h" diff --git a/infra/tcp_reassembly/tcp_reassembly.h b/infra/tcp_reassembly/tcp_reassembly.h index 65a7a35..75c9c5c 100644 --- a/infra/tcp_reassembly/tcp_reassembly.h +++ b/infra/tcp_reassembly/tcp_reassembly.h @@ -6,6 +6,7 @@ extern "C" #endif #include +#include struct tcp_segment { diff --git a/test/debug_plugin/debug_plugin.c b/test/debug_plugin/debug_plugin.c index c354e5e..5456b57 100644 --- a/test/debug_plugin/debug_plugin.c +++ b/test/debug_plugin/debug_plugin.c @@ -7,13 +7,12 @@ #include "utils.h" #include "packet_dump.h" #include "session_private.h" -#include "stellar/log.h" #include "stellar/stellar_mq.h" #include "stellar/stellar_exdata.h" #pragma GCC diagnostic ignored "-Wunused-parameter" -static void log_print(int fd, const char *module, const char *fmt, ...) +static void debug_plugin_log(int fd, const char *module, const char *fmt, ...) { static unsigned char weekday_str[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; @@ -52,7 +51,6 @@ static void log_print(int fd, const char *module, const char *fmt, ...) struct plugin_ctx { struct stellar *st; - struct logger *logger; int sess_exdata_idx; int sess_plug_id; int tcp_topic_id; @@ -102,7 +100,7 @@ static void *on_sess_new(struct session *sess, void *plugin_ctx) memset(buff, 0, sizeof(buff)); session_to_str(sess, 1, buff, sizeof(buff) - 1); - log_print(ctx->fd, "debug plugin", "sess new: %s", buff); + debug_plugin_log(ctx->fd, "debug plugin", "sess new: %s", buff); return NULL; } @@ -115,17 +113,17 @@ static void on_sess_free(struct session *sess, void *sess_ctx, void *plugin_ctx) memset(buff, 0, sizeof(buff)); session_to_str(sess, 0, buff, sizeof(buff) - 1); - log_print(ctx->fd, "debug plugin", "sess free: %s", buff); - log_print(ctx->fd, "debug plugin", "session %lu %s stat:\n" - "C2S rx packets: %6lu, C2S rx bytes: %6lu\n" - "S2C rx packets: %6lu, S2C rx bytes: %6lu\n" - "C2S rx TCP segments: %6lu, C2S rx TCP bytes: %6lu\n" - "S2C rx TCP segments: %6lu, S2C rx TCP bytes: %6lu\n", - session_get_id(sess), session_get0_readable_addr(sess), - exdata->c2s_rx_pkts, exdata->c2s_rx_bytes, - exdata->s2c_rx_pkts, exdata->s2c_rx_bytes, - exdata->c2s_rx_tcp_seg, exdata->c2s_rx_tcp_bytes, - exdata->s2c_rx_tcp_seg, exdata->s2c_rx_tcp_bytes); + debug_plugin_log(ctx->fd, "debug plugin", "sess free: %s", buff); + debug_plugin_log(ctx->fd, "debug plugin", "session %lu %s stat:\n" + "C2S rx packets: %6lu, C2S rx bytes: %6lu\n" + "S2C rx packets: %6lu, S2C rx bytes: %6lu\n" + "C2S rx TCP segments: %6lu, C2S rx TCP bytes: %6lu\n" + "S2C rx TCP segments: %6lu, S2C rx TCP bytes: %6lu\n", + session_get_id(sess), session_get0_readable_addr(sess), + exdata->c2s_rx_pkts, exdata->c2s_rx_bytes, + exdata->s2c_rx_pkts, exdata->s2c_rx_bytes, + exdata->c2s_rx_tcp_seg, exdata->c2s_rx_tcp_bytes, + exdata->s2c_rx_tcp_seg, exdata->s2c_rx_tcp_bytes); if (exdata->c2s_tcp_seg_hexdump_fd > 0) { close(exdata->c2s_tcp_seg_hexdump_fd); @@ -161,11 +159,11 @@ static void on_sess_udp_msg(struct session *sess, int topic_id, const void *msg, memset(buff, 0, sizeof(buff)); session_to_str(sess, 1, buff, sizeof(buff) - 1); - log_print(ctx->fd, "debug plugin", "on UDP msg: %s", buff); + debug_plugin_log(ctx->fd, "debug plugin", "on UDP msg: %s", buff); memset(buff, 0, sizeof(buff)); packet_dump_str(pkt, buff, sizeof(buff) - 1); - log_print(ctx->fd, "debug plugin", "rx UDP packet (tv_sec: %lu, tv_usec: %lu): \n%s", tv->tv_sec, tv->tv_usec, buff); + debug_plugin_log(ctx->fd, "debug plugin", "rx UDP packet (tv_sec: %lu, tv_usec: %lu): \n%s", tv->tv_sec, tv->tv_usec, buff); pthread_spin_lock(&ctx->lock); packet_dump_hex(pkt, ctx->fd); @@ -197,11 +195,11 @@ static void on_sess_tcp_msg(struct session *sess, int topic_id, const void *msg, memset(buff, 0, sizeof(buff)); session_to_str(sess, 1, buff, sizeof(buff) - 1); - log_print(ctx->fd, "debug plugin", "on TCP msg: %s", buff); + debug_plugin_log(ctx->fd, "debug plugin", "on TCP msg: %s", buff); memset(buff, 0, sizeof(buff)); packet_dump_str(pkt, buff, sizeof(buff) - 1); - log_print(ctx->fd, "debug plugin", "rx TCP packet (tv_sec: %lu, tv_usec: %lu): \n%s", tv->tv_sec, tv->tv_usec, buff); + debug_plugin_log(ctx->fd, "debug plugin", "rx TCP packet (tv_sec: %lu, tv_usec: %lu): \n%s", tv->tv_sec, tv->tv_usec, buff); pthread_spin_lock(&ctx->lock); packet_dump_hex(pkt, ctx->fd); @@ -224,12 +222,12 @@ static void on_sess_tcp_stream_msg(struct session *sess, int topic_id, const voi memset(buff, 0, sizeof(buff)); session_to_str(sess, 1, buff, sizeof(buff) - 1); - log_print(ctx->fd, "debug plugin", "on TCP stream msg: %s", buff); + debug_plugin_log(ctx->fd, "debug plugin", "on TCP stream msg: %s", buff); pthread_spin_lock(&ctx->lock); if (session_get_current_flow_direction(sess) == FLOW_DIRECTION_C2S) { - log_print(ctx->fd, "debug plugin", "rx C2S TCP segment: len: %d, data: %p", len, data); + debug_plugin_log(ctx->fd, "debug plugin", "rx C2S TCP segment: len: %d, data: %p", len, data); hexdump_to_fd(ctx->fd, exdata->c2s_rx_tcp_bytes, data, len); hexdump_to_fd(ctx->c2s_tcp_seg_hexdump_fd, exdata->c2s_rx_tcp_bytes, data, len); @@ -238,7 +236,7 @@ static void on_sess_tcp_stream_msg(struct session *sess, int topic_id, const voi } else { - log_print(ctx->fd, "debug plugin", "rx S2C TCP segment: len: %d, data: %p", len, data); + debug_plugin_log(ctx->fd, "debug plugin", "rx S2C TCP segment: len: %d, data: %p", len, data); hexdump_to_fd(ctx->fd, exdata->s2c_rx_tcp_bytes, data, len); hexdump_to_fd(ctx->s2c_tcp_seg_hexdump_fd, exdata->s2c_rx_tcp_bytes, data, len); @@ -252,57 +250,51 @@ static void on_sess_tcp_stream_msg(struct session *sess, int topic_id, const voi * Plugin API ******************************************************************************/ -extern "C" +void *debug_plugin_init(struct stellar *st) { - void *debug_plugin_init(struct stellar *st) + struct plugin_ctx *ctx = (struct plugin_ctx *)calloc(1, sizeof(struct plugin_ctx)); + if (ctx == NULL) { - struct plugin_ctx *ctx = (struct plugin_ctx *)calloc(1, sizeof(struct plugin_ctx)); - if (ctx == NULL) - { - return NULL; - } - - ctx->fd = open("./log/debug_plugin.log", O_WRONLY | O_APPEND | O_CREAT, 0644); - if (ctx->fd == -1) - { - printf("[debug plugin] open log file failed: %s\n", strerror(errno)); - free(ctx); - return NULL; - } - - pthread_spin_init(&ctx->lock, PTHREAD_PROCESS_PRIVATE); - - ctx->st = st; - ctx->logger = stellar_get_logger(st); - ctx->sess_exdata_idx = stellar_exdata_new_index(st, "DEBUG_PLUGIN_SESS_EXDATA", stellar_exdata_free_default, NULL); - ctx->sess_plug_id = stellar_session_plugin_register(st, on_sess_new, on_sess_free, ctx); - ctx->udp_topic_id = stellar_mq_get_topic_id(st, TOPIC_UDP); - ctx->tcp_topic_id = stellar_mq_get_topic_id(st, TOPIC_TCP); - ctx->tcp_stream_topic_id = stellar_mq_get_topic_id(st, TOPIC_TCP_STREAM); - - stellar_session_mq_subscribe(st, ctx->udp_topic_id, on_sess_udp_msg, ctx->sess_plug_id); - stellar_session_mq_subscribe(st, ctx->tcp_topic_id, on_sess_tcp_msg, ctx->sess_plug_id); - stellar_session_mq_subscribe(st, ctx->tcp_stream_topic_id, on_sess_tcp_stream_msg, ctx->sess_plug_id); - - STELLAR_LOG_FATAL(ctx->logger, "debug plugin", "init"); - log_print(ctx->fd, "debug plugin", "init"); - - return ctx; + return NULL; } - void debug_plugin_exit(void *plugin_ctx) + ctx->fd = open("./log/debug_plugin.log", O_WRONLY | O_APPEND | O_CREAT, 0644); + if (ctx->fd == -1) { - struct plugin_ctx *ctx = (struct plugin_ctx *)plugin_ctx; - if (ctx) + printf("[debug plugin] open log file failed: %s\n", strerror(errno)); + free(ctx); + return NULL; + } + + pthread_spin_init(&ctx->lock, PTHREAD_PROCESS_PRIVATE); + + ctx->st = st; + ctx->sess_exdata_idx = stellar_exdata_new_index(st, "DEBUG_PLUGIN_SESS_EXDATA", stellar_exdata_free_default, NULL); + ctx->sess_plug_id = stellar_session_plugin_register(st, on_sess_new, on_sess_free, ctx); + ctx->udp_topic_id = stellar_mq_get_topic_id(st, TOPIC_UDP); + ctx->tcp_topic_id = stellar_mq_get_topic_id(st, TOPIC_TCP); + ctx->tcp_stream_topic_id = stellar_mq_get_topic_id(st, TOPIC_TCP_STREAM); + + stellar_session_mq_subscribe(st, ctx->udp_topic_id, on_sess_udp_msg, ctx->sess_plug_id); + stellar_session_mq_subscribe(st, ctx->tcp_topic_id, on_sess_tcp_msg, ctx->sess_plug_id); + stellar_session_mq_subscribe(st, ctx->tcp_stream_topic_id, on_sess_tcp_stream_msg, ctx->sess_plug_id); + + debug_plugin_log(ctx->fd, "debug plugin", "init"); + + return ctx; +} + +void debug_plugin_exit(void *plugin_ctx) +{ + struct plugin_ctx *ctx = (struct plugin_ctx *)plugin_ctx; + if (ctx) + { + debug_plugin_log(ctx->fd, "debug plugin", "exit"); + if (ctx->fd > 0) { - STELLAR_LOG_FATAL(ctx->logger, "debug plugin", "exit"); - log_print(ctx->fd, "debug plugin", "exit"); - if (ctx->fd > 0) - { - close(ctx->fd); - } - pthread_spin_destroy(&ctx->lock); - free(ctx); + close(ctx->fd); } + pthread_spin_destroy(&ctx->lock); + free(ctx); } } \ No newline at end of file diff --git a/test/packet_inject/packet_inject.c b/test/packet_inject/packet_inject.c index 0ab2ca9..8b20f7f 100644 --- a/test/packet_inject/packet_inject.c +++ b/test/packet_inject/packet_inject.c @@ -536,45 +536,42 @@ static void on_sess_msg(struct session *sess, int topic_id, const void *msg, voi * Plugin API ******************************************************************************/ -extern "C" +void *packet_inject_init(struct stellar *st) { - void *packet_inject_init(struct stellar *st) + struct inject_plugin_ctx *ctx = (struct inject_plugin_ctx *)calloc(1, sizeof(struct inject_plugin_ctx)); + if (ctx == NULL) { - struct inject_plugin_ctx *ctx = (struct inject_plugin_ctx *)calloc(1, sizeof(struct inject_plugin_ctx)); - if (ctx == NULL) - { - return NULL; - } - - ctx->st = st; - ctx->logger = stellar_get_logger(st); - INJTECT_PLUGIN_LOG_INFO(ctx->logger, "packet inject plugin init"); - - if (load_config(ctx->logger, &ctx->config, "./plugin/inject.toml") == -1) - { - INJTECT_PLUGIN_LOG_ERROR(ctx->logger, "load config failed"); - free(ctx); - return NULL; - } - print_config(ctx->logger, &ctx->config); - - ctx->sess_plug_id = stellar_session_plugin_register(st, on_sess_new, on_sess_free, ctx); - ctx->tcp_topic_id = stellar_mq_get_topic_id(st, TOPIC_TCP); - ctx->udp_topic_id = stellar_mq_get_topic_id(st, TOPIC_UDP); - - stellar_session_mq_subscribe(st, ctx->tcp_topic_id, on_sess_msg, ctx->sess_plug_id); - stellar_session_mq_subscribe(st, ctx->udp_topic_id, on_sess_msg, ctx->sess_plug_id); - - return ctx; + return NULL; } - void packet_inject_exit(void *plugin_ctx) + ctx->st = st; + ctx->logger = stellar_get_logger(st); + INJTECT_PLUGIN_LOG_INFO(ctx->logger, "packet inject plugin init"); + + if (load_config(ctx->logger, &ctx->config, "./plugin/inject.toml") == -1) { - struct inject_plugin_ctx *ctx = (struct inject_plugin_ctx *)plugin_ctx; - if (ctx) - { - INJTECT_PLUGIN_LOG_INFO(ctx->logger, "packet inject plugin exit"); - free(ctx); - } + INJTECT_PLUGIN_LOG_ERROR(ctx->logger, "load config failed"); + free(ctx); + return NULL; + } + print_config(ctx->logger, &ctx->config); + + ctx->sess_plug_id = stellar_session_plugin_register(st, on_sess_new, on_sess_free, ctx); + ctx->tcp_topic_id = stellar_mq_get_topic_id(st, TOPIC_TCP); + ctx->udp_topic_id = stellar_mq_get_topic_id(st, TOPIC_UDP); + + stellar_session_mq_subscribe(st, ctx->tcp_topic_id, on_sess_msg, ctx->sess_plug_id); + stellar_session_mq_subscribe(st, ctx->udp_topic_id, on_sess_msg, ctx->sess_plug_id); + + return ctx; +} + +void packet_inject_exit(void *plugin_ctx) +{ + struct inject_plugin_ctx *ctx = (struct inject_plugin_ctx *)plugin_ctx; + if (ctx) + { + INJTECT_PLUGIN_LOG_INFO(ctx->logger, "packet inject plugin exit"); + free(ctx); } } \ No newline at end of file