refactor packet IO, rename dumpfile mode to pcap mode, modify related configuration
This commit is contained in:
@@ -60,6 +60,7 @@ struct stellar_runtime
|
||||
struct stellar_thread threads[MAX_THREAD_NUM];
|
||||
struct session_manager_config *sess_mgr_cfg;
|
||||
struct ip_reassembly_config *ip_reass_cfg;
|
||||
struct packet_io_config *pkt_io_cfg;
|
||||
};
|
||||
|
||||
struct stellar
|
||||
@@ -145,7 +146,6 @@ static void *worker_thread(void *arg)
|
||||
};
|
||||
|
||||
uint64_t merge_stat_interval = config->sched_opts.merge_stat_interval;
|
||||
uint64_t packet_io_yield_interval = config->sched_opts.packet_io_yield_interval;
|
||||
uint16_t thr_idx = thread->idx;
|
||||
|
||||
__current_thread_idx = thr_idx;
|
||||
@@ -300,7 +300,7 @@ static void *worker_thread(void *arg)
|
||||
|
||||
if (nr_pkt_received == 0)
|
||||
{
|
||||
packet_io_yield(packet_io, thr_idx, packet_io_yield_interval);
|
||||
packet_io_yield(packet_io, thr_idx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ static int stellar_thread_init(struct stellar *st)
|
||||
struct stellar_config *config = &st->config;
|
||||
|
||||
uint64_t now_ms = clock_get_real_time_ms();
|
||||
for (uint16_t i = 0; i < config->pkt_io_opts.nr_worker_thread; i++)
|
||||
for (uint16_t i = 0; i < runtime->pkt_io_cfg->nr_worker_thread; i++)
|
||||
{
|
||||
struct stellar_thread *thread = &runtime->threads[i];
|
||||
thread->idx = i;
|
||||
@@ -383,10 +383,9 @@ static int stellar_thread_init(struct stellar *st)
|
||||
static void stellar_thread_clean(struct stellar *st)
|
||||
{
|
||||
struct stellar_runtime *runtime = &st->runtime;
|
||||
struct stellar_config *config = &st->config;
|
||||
|
||||
CORE_LOG_FATAL("cleaning worker thread context ...");
|
||||
for (uint16_t i = 0; i < config->pkt_io_opts.nr_worker_thread; i++)
|
||||
for (uint16_t i = 0; i < runtime->pkt_io_cfg->nr_worker_thread; i++)
|
||||
{
|
||||
struct stellar_thread *thread = &runtime->threads[i];
|
||||
if (ATOMIC_READ(&thread->is_runing) == 0)
|
||||
@@ -402,9 +401,8 @@ static void stellar_thread_clean(struct stellar *st)
|
||||
static int stellar_thread_run(struct stellar *st)
|
||||
{
|
||||
struct stellar_runtime *runtime = &st->runtime;
|
||||
struct stellar_config *config = &st->config;
|
||||
|
||||
for (uint16_t i = 0; i < config->pkt_io_opts.nr_worker_thread; i++)
|
||||
for (uint16_t i = 0; i < runtime->pkt_io_cfg->nr_worker_thread; i++)
|
||||
{
|
||||
struct stellar_thread *thread = &runtime->threads[i];
|
||||
if (pthread_create(&thread->tid, NULL, worker_thread, (void *)thread) < 0)
|
||||
@@ -420,10 +418,9 @@ static int stellar_thread_run(struct stellar *st)
|
||||
static void stellar_thread_join(struct stellar *st)
|
||||
{
|
||||
struct stellar_runtime *runtime = &st->runtime;
|
||||
struct stellar_config *config = &st->config;
|
||||
|
||||
CORE_LOG_FATAL("waiting worker thread stop ...");
|
||||
for (uint16_t i = 0; i < config->pkt_io_opts.nr_worker_thread; i++)
|
||||
for (uint16_t i = 0; i < runtime->pkt_io_cfg->nr_worker_thread; i++)
|
||||
{
|
||||
struct stellar_thread *thread = &runtime->threads[i];
|
||||
while (ATOMIC_READ(&thread->is_runing) == 1)
|
||||
@@ -489,7 +486,14 @@ struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg
|
||||
CORE_LOG_ERROR("unable to create ip reassembly config");
|
||||
goto error_out;
|
||||
}
|
||||
runtime->pkt_io_cfg = packet_io_config_new(st->stellar_cfg_file);
|
||||
if (runtime->pkt_io_cfg == NULL)
|
||||
{
|
||||
CORE_LOG_ERROR("unable to create packet io config");
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
packet_io_config_print(runtime->pkt_io_cfg);
|
||||
session_manager_config_print(runtime->sess_mgr_cfg);
|
||||
ip_reassembly_config_print(runtime->ip_reass_cfg);
|
||||
if (stellar_config_load(config, st->stellar_cfg_file) != 0)
|
||||
@@ -499,7 +503,7 @@ struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg
|
||||
}
|
||||
stellar_config_print(config);
|
||||
|
||||
runtime->stat = stellar_stat_new(config->pkt_io_opts.nr_worker_thread);
|
||||
runtime->stat = stellar_stat_new(runtime->pkt_io_cfg->nr_worker_thread);
|
||||
if (runtime->stat == NULL)
|
||||
{
|
||||
CORE_LOG_ERROR("unable to create stellar stat");
|
||||
@@ -512,7 +516,7 @@ struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
runtime->packet_io = packet_io_new(&config->pkt_io_opts);
|
||||
runtime->packet_io = packet_io_new(runtime->pkt_io_cfg);
|
||||
if (runtime->packet_io == NULL)
|
||||
{
|
||||
CORE_LOG_ERROR("unable to create packet io");
|
||||
@@ -563,7 +567,7 @@ void stellar_run(struct stellar *st)
|
||||
}
|
||||
usleep(1000); // 1ms
|
||||
|
||||
// only available in dumpfile mode
|
||||
// only available in pcap mode
|
||||
if (packet_io_isbreak(runtime->packet_io))
|
||||
{
|
||||
ATOMIC_SET(&runtime->need_exit, 1);
|
||||
@@ -587,6 +591,7 @@ void stellar_free(struct stellar *st)
|
||||
packet_io_free(runtime->packet_io);
|
||||
plugin_manager_exit(runtime->plug_mgr);
|
||||
stellar_stat_free(runtime->stat);
|
||||
packet_io_config_free(runtime->pkt_io_cfg);
|
||||
ip_reassembly_config_free(runtime->ip_reass_cfg);
|
||||
session_manager_config_free(runtime->sess_mgr_cfg);
|
||||
CORE_LOG_FATAL("stellar exit\n");
|
||||
@@ -675,7 +680,7 @@ void stellar_send_build_packet(struct stellar *st, struct packet *pkt)
|
||||
|
||||
int stellar_get_worker_thread_num(struct stellar *st)
|
||||
{
|
||||
return st->config.pkt_io_opts.nr_worker_thread;
|
||||
return st->runtime.pkt_io_cfg->nr_worker_thread;
|
||||
}
|
||||
|
||||
struct logger *stellar_get_logger(struct stellar *st)
|
||||
|
||||
Reference in New Issue
Block a user