fix compile error

This commit is contained in:
luwenpeng
2024-08-28 19:00:32 +08:00
parent 3e6b837318
commit 283d591e6b
24 changed files with 159 additions and 113 deletions

View File

@@ -2,6 +2,12 @@
#ifndef __BLOOM_H__
#define __BLOOM_H__
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.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_search(struct expiry_dablooms_handle *handle, const char *key, size_t len, time_t cur_time);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -2,6 +2,11 @@
#ifndef _LINUX_INTERVAL_TREE_H
#define _LINUX_INTERVAL_TREE_H
#ifdef __cplusplus
extern "C"
{
#endif
#include "rbtree.h"
#include <stdint.h>
@@ -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 */

View File

@@ -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

View File

@@ -17,6 +17,11 @@
#ifndef _LINUX_RBTREE_H
#define _LINUX_RBTREE_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdlib.h>
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 */

View File

@@ -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 */

View File

@@ -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, ...);

View File

@@ -16,6 +16,7 @@ extern "C"
#include <linux/if_ether.h>
#include <linux/mpls.h>
struct packet;
/******************************************************************************
* layer
******************************************************************************/

View File

@@ -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
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -1,7 +1,5 @@
#include "checksum.h"
#include <arpa/inet.h>
uint16_t checksum(const void *data, int len)
{
uint16_t *ptr = (uint16_t *)data;

View File

@@ -6,6 +6,7 @@ extern "C"
#endif
#include <stdint.h>
#include <arpa/inet.h>
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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -8,6 +8,7 @@ extern "C"
#include "utils.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <arpa/inet.h>
#include <linux/if_ether.h>
#include <netinet/ip.h>

View File

@@ -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;

View File

@@ -5,6 +5,7 @@ extern "C"
{
#endif
#include "tuple.h"
#include "stellar/packet.h"
#define PACKET_MAX_LAYERS 32

View File

@@ -5,6 +5,8 @@ extern "C"
{
#endif
#include <stdbool.h>
#include "list.h"
#include "tuple.h"
#include "uthash.h"

View File

@@ -1,4 +1,5 @@
#include <string.h>
#include <stdbool.h>
#include "list.h"
#include "log_private.h"

View File

@@ -6,6 +6,7 @@ extern "C"
#endif
#include <stdint.h>
#include <stdbool.h>
struct tcp_segment
{

View File

@@ -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,8 +113,8 @@ 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"
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"
@@ -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,10 +250,8 @@ 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)
{
@@ -273,7 +269,6 @@ extern "C"
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);
@@ -284,19 +279,17 @@ extern "C"
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");
debug_plugin_log(ctx->fd, "debug plugin", "init");
return ctx;
}
}
void debug_plugin_exit(void *plugin_ctx)
{
void debug_plugin_exit(void *plugin_ctx)
{
struct plugin_ctx *ctx = (struct plugin_ctx *)plugin_ctx;
if (ctx)
{
STELLAR_LOG_FATAL(ctx->logger, "debug plugin", "exit");
log_print(ctx->fd, "debug plugin", "exit");
debug_plugin_log(ctx->fd, "debug plugin", "exit");
if (ctx->fd > 0)
{
close(ctx->fd);
@@ -304,5 +297,4 @@ extern "C"
pthread_spin_destroy(&ctx->lock);
free(ctx);
}
}
}

View File

@@ -536,10 +536,8 @@ 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)
{
@@ -566,15 +564,14 @@ extern "C"
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)
{
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);
}
}
}