fix compile error
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user