fix compile error
This commit is contained in:
10
deps/dablooms/dablooms.h
vendored
10
deps/dablooms/dablooms.h
vendored
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
#ifndef __BLOOM_H__
|
#ifndef __BLOOM_H__
|
||||||
#define __BLOOM_H__
|
#define __BLOOM_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -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_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);
|
int expiry_dablooms_search(struct expiry_dablooms_handle *handle, const char *key, size_t len, time_t cur_time);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
9
deps/interval_tree/interval_tree.h
vendored
9
deps/interval_tree/interval_tree.h
vendored
@@ -2,6 +2,11 @@
|
|||||||
#ifndef _LINUX_INTERVAL_TREE_H
|
#ifndef _LINUX_INTERVAL_TREE_H
|
||||||
#define _LINUX_INTERVAL_TREE_H
|
#define _LINUX_INTERVAL_TREE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "rbtree.h"
|
#include "rbtree.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -30,4 +35,8 @@ extern struct interval_tree_node *
|
|||||||
interval_tree_iter_next(struct interval_tree_node *node,
|
interval_tree_iter_next(struct interval_tree_node *node,
|
||||||
uint64_t start, uint64_t last);
|
uint64_t start, uint64_t last);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _LINUX_INTERVAL_TREE_H */
|
#endif /* _LINUX_INTERVAL_TREE_H */
|
||||||
|
|||||||
9
deps/interval_tree/interval_tree_generic.h
vendored
9
deps/interval_tree/interval_tree_generic.h
vendored
@@ -7,6 +7,11 @@
|
|||||||
include/linux/interval_tree_generic.h
|
include/linux/interval_tree_generic.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "rbtree_augmented.h"
|
#include "rbtree_augmented.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -195,3 +200,7 @@
|
|||||||
return node; \
|
return node; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
9
deps/rbtree/rbtree.h
vendored
9
deps/rbtree/rbtree.h
vendored
@@ -17,6 +17,11 @@
|
|||||||
#ifndef _LINUX_RBTREE_H
|
#ifndef _LINUX_RBTREE_H
|
||||||
#define _LINUX_RBTREE_H
|
#define _LINUX_RBTREE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct rb_node
|
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)); \
|
for ((node) = rb_find_first((key), (tree), (cmp)); \
|
||||||
(node); (node) = rb_next_match((key), (node), (cmp)))
|
(node); (node) = rb_next_match((key), (node), (cmp)))
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _LINUX_RBTREE_H */
|
#endif /* _LINUX_RBTREE_H */
|
||||||
|
|||||||
9
deps/rbtree/rbtree_augmented.h
vendored
9
deps/rbtree/rbtree_augmented.h
vendored
@@ -12,6 +12,11 @@
|
|||||||
#ifndef _LINUX_RBTREE_AUGMENTED_H
|
#ifndef _LINUX_RBTREE_AUGMENTED_H
|
||||||
#define _LINUX_RBTREE_AUGMENTED_H
|
#define _LINUX_RBTREE_AUGMENTED_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "rbtree.h"
|
#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);
|
rb_erase_augmented(node, &root->rb_root, augment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _LINUX_RBTREE_AUGMENTED_H */
|
#endif /* _LINUX_RBTREE_AUGMENTED_H */
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ enum log_level
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct logger;
|
struct logger;
|
||||||
struct logger *stellar_get_logger(struct stellar *st);
|
|
||||||
|
|
||||||
int log_check_level(struct logger *logger, enum log_level level);
|
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, ...);
|
void log_print(struct logger *logger, enum log_level level, const char *module, const char *fmt, ...);
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ extern "C"
|
|||||||
#include <linux/if_ether.h>
|
#include <linux/if_ether.h>
|
||||||
#include <linux/mpls.h>
|
#include <linux/mpls.h>
|
||||||
|
|
||||||
|
struct packet;
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* layer
|
* layer
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ void stellar_run(struct stellar *st);
|
|||||||
void stellar_free(struct stellar *st);
|
void stellar_free(struct stellar *st);
|
||||||
void stellar_loopbreak(struct stellar *st);
|
void stellar_loopbreak(struct stellar *st);
|
||||||
void stellar_reload_log_level(struct stellar *st);
|
void stellar_reload_log_level(struct stellar *st);
|
||||||
|
struct logger *stellar_get_logger(struct stellar *st);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ struct stellar
|
|||||||
struct stellar_config config;
|
struct stellar_config config;
|
||||||
};
|
};
|
||||||
|
|
||||||
static thread_local uint16_t __current_thread_idx = UINT16_MAX;
|
static __thread uint16_t __current_thread_idx = UINT16_MAX;
|
||||||
static thread_local struct snowflake *__current_thread_snowflake = NULL;
|
static __thread struct snowflake *__current_thread_snowflake = NULL;
|
||||||
|
|
||||||
uint64_t stellar_generate_session_id(uint64_t now_sec);
|
uint64_t stellar_generate_session_id(uint64_t now_sec);
|
||||||
|
|
||||||
|
|||||||
@@ -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 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"};
|
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
|
* Private API
|
||||||
@@ -163,7 +163,7 @@ static int config_parse(struct log_config *config, const char *config_file)
|
|||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
config->level = (enum log_level)str_to_level(ptr_level);
|
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);
|
fprintf(stderr, "config file %s invalid log.level\n", config_file);
|
||||||
goto error_out;
|
goto error_out;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ extern "C"
|
|||||||
|
|
||||||
#include "stellar/log.h"
|
#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);
|
struct logger *log_new(const char *config_file);
|
||||||
void log_free(struct logger *logger);
|
void log_free(struct logger *logger);
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ struct packet_io_options
|
|||||||
uint16_t cpu_mask[MAX_THREAD_NUM];
|
uint16_t cpu_mask[MAX_THREAD_NUM];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct packet;
|
||||||
struct packet_io;
|
struct packet_io;
|
||||||
struct packet_io *packet_io_new(struct packet_io_options *opts);
|
struct packet_io *packet_io_new(struct packet_io_options *opts);
|
||||||
void packet_io_free(struct packet_io *packet_io);
|
void packet_io_free(struct packet_io *packet_io);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include "checksum.h"
|
#include "checksum.h"
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
|
|
||||||
uint16_t checksum(const void *data, int len)
|
uint16_t checksum(const void *data, int len)
|
||||||
{
|
{
|
||||||
uint16_t *ptr = (uint16_t *)data;
|
uint16_t *ptr = (uint16_t *)data;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
uint16_t checksum(const void *data, int len);
|
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);
|
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);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct packet;
|
||||||
|
|
||||||
// return 0: success
|
// return 0: success
|
||||||
// return -1: failed
|
// return -1: failed
|
||||||
int packet_dump_pcap(const struct packet *pkt, const char *file);
|
int packet_dump_pcap(const struct packet *pkt, const char *file);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct packet;
|
||||||
|
|
||||||
// Duplicated Packet Filter for IPv4 Packet
|
// Duplicated Packet Filter for IPv4 Packet
|
||||||
struct packet_filter;
|
struct packet_filter;
|
||||||
struct packet_filter *packet_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now);
|
struct packet_filter *packet_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ extern "C"
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <linux/if_ether.h>
|
#include <linux/if_ether.h>
|
||||||
#include <netinet/ip.h>
|
#include <netinet/ip.h>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "packet_private.h"
|
#include "packet_private.h"
|
||||||
#include "packet_parser.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_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__)
|
#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 hdr_len = 0;
|
||||||
uint16_t next_proto = 0;
|
uint16_t next_proto = 0;
|
||||||
|
struct layer_private *layer = NULL;
|
||||||
|
|
||||||
// ppp header 1 byte
|
// ppp header 1 byte
|
||||||
next_proto = *((uint8_t *)data);
|
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;
|
hdr_len = 4;
|
||||||
|
|
||||||
success:
|
success:
|
||||||
struct layer_private *layer = get_free_layer(pkt);
|
layer = get_free_layer(pkt);
|
||||||
if (unlikely(layer == NULL))
|
if (unlikely(layer == NULL))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "tuple.h"
|
||||||
#include "stellar/packet.h"
|
#include "stellar/packet.h"
|
||||||
|
|
||||||
#define PACKET_MAX_LAYERS 32
|
#define PACKET_MAX_LAYERS 32
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "tuple.h"
|
#include "tuple.h"
|
||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log_private.h"
|
#include "log_private.h"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct tcp_segment
|
struct tcp_segment
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,13 +7,12 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "packet_dump.h"
|
#include "packet_dump.h"
|
||||||
#include "session_private.h"
|
#include "session_private.h"
|
||||||
#include "stellar/log.h"
|
|
||||||
#include "stellar/stellar_mq.h"
|
#include "stellar/stellar_mq.h"
|
||||||
#include "stellar/stellar_exdata.h"
|
#include "stellar/stellar_exdata.h"
|
||||||
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
#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 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"};
|
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 plugin_ctx
|
||||||
{
|
{
|
||||||
struct stellar *st;
|
struct stellar *st;
|
||||||
struct logger *logger;
|
|
||||||
int sess_exdata_idx;
|
int sess_exdata_idx;
|
||||||
int sess_plug_id;
|
int sess_plug_id;
|
||||||
int tcp_topic_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));
|
memset(buff, 0, sizeof(buff));
|
||||||
session_to_str(sess, 1, buff, sizeof(buff) - 1);
|
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;
|
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));
|
memset(buff, 0, sizeof(buff));
|
||||||
session_to_str(sess, 0, buff, sizeof(buff) - 1);
|
session_to_str(sess, 0, buff, sizeof(buff) - 1);
|
||||||
log_print(ctx->fd, "debug plugin", "sess free: %s", buff);
|
debug_plugin_log(ctx->fd, "debug plugin", "sess free: %s", buff);
|
||||||
log_print(ctx->fd, "debug plugin", "session %lu %s stat:\n"
|
debug_plugin_log(ctx->fd, "debug plugin", "session %lu %s stat:\n"
|
||||||
"C2S rx packets: %6lu, C2S rx bytes: %6lu\n"
|
"C2S rx packets: %6lu, C2S rx bytes: %6lu\n"
|
||||||
"S2C rx packets: %6lu, S2C rx bytes: %6lu\n"
|
"S2C rx packets: %6lu, S2C rx bytes: %6lu\n"
|
||||||
"C2S rx TCP segments: %6lu, C2S rx TCP 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",
|
"S2C rx TCP segments: %6lu, S2C rx TCP bytes: %6lu\n",
|
||||||
session_get_id(sess), session_get0_readable_addr(sess),
|
session_get_id(sess), session_get0_readable_addr(sess),
|
||||||
exdata->c2s_rx_pkts, exdata->c2s_rx_bytes,
|
exdata->c2s_rx_pkts, exdata->c2s_rx_bytes,
|
||||||
exdata->s2c_rx_pkts, exdata->s2c_rx_bytes,
|
exdata->s2c_rx_pkts, exdata->s2c_rx_bytes,
|
||||||
exdata->c2s_rx_tcp_seg, exdata->c2s_rx_tcp_bytes,
|
exdata->c2s_rx_tcp_seg, exdata->c2s_rx_tcp_bytes,
|
||||||
exdata->s2c_rx_tcp_seg, exdata->s2c_rx_tcp_bytes);
|
exdata->s2c_rx_tcp_seg, exdata->s2c_rx_tcp_bytes);
|
||||||
if (exdata->c2s_tcp_seg_hexdump_fd > 0)
|
if (exdata->c2s_tcp_seg_hexdump_fd > 0)
|
||||||
{
|
{
|
||||||
close(exdata->c2s_tcp_seg_hexdump_fd);
|
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));
|
memset(buff, 0, sizeof(buff));
|
||||||
session_to_str(sess, 1, buff, sizeof(buff) - 1);
|
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));
|
memset(buff, 0, sizeof(buff));
|
||||||
packet_dump_str(pkt, buff, sizeof(buff) - 1);
|
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);
|
pthread_spin_lock(&ctx->lock);
|
||||||
packet_dump_hex(pkt, ctx->fd);
|
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));
|
memset(buff, 0, sizeof(buff));
|
||||||
session_to_str(sess, 1, buff, sizeof(buff) - 1);
|
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));
|
memset(buff, 0, sizeof(buff));
|
||||||
packet_dump_str(pkt, buff, sizeof(buff) - 1);
|
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);
|
pthread_spin_lock(&ctx->lock);
|
||||||
packet_dump_hex(pkt, ctx->fd);
|
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));
|
memset(buff, 0, sizeof(buff));
|
||||||
session_to_str(sess, 1, buff, sizeof(buff) - 1);
|
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);
|
pthread_spin_lock(&ctx->lock);
|
||||||
if (session_get_current_flow_direction(sess) == FLOW_DIRECTION_C2S)
|
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->fd, exdata->c2s_rx_tcp_bytes, data, len);
|
||||||
hexdump_to_fd(ctx->c2s_tcp_seg_hexdump_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
|
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->fd, exdata->s2c_rx_tcp_bytes, data, len);
|
||||||
hexdump_to_fd(ctx->s2c_tcp_seg_hexdump_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
|
* 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));
|
return NULL;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
printf("[debug plugin] open log file failed: %s\n", strerror(errno));
|
||||||
if (ctx)
|
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");
|
close(ctx->fd);
|
||||||
log_print(ctx->fd, "debug plugin", "exit");
|
|
||||||
if (ctx->fd > 0)
|
|
||||||
{
|
|
||||||
close(ctx->fd);
|
|
||||||
}
|
|
||||||
pthread_spin_destroy(&ctx->lock);
|
|
||||||
free(ctx);
|
|
||||||
}
|
}
|
||||||
|
pthread_spin_destroy(&ctx->lock);
|
||||||
|
free(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -536,45 +536,42 @@ static void on_sess_msg(struct session *sess, int topic_id, const void *msg, voi
|
|||||||
* Plugin API
|
* 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));
|
return NULL;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
INJTECT_PLUGIN_LOG_ERROR(ctx->logger, "load config failed");
|
||||||
if (ctx)
|
free(ctx);
|
||||||
{
|
return NULL;
|
||||||
INJTECT_PLUGIN_LOG_INFO(ctx->logger, "packet inject plugin exit");
|
}
|
||||||
free(ctx);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user