IP reassembly parses IP frag related configuration items

This commit is contained in:
luwenpeng
2024-08-29 18:03:14 +08:00
parent 338dcf93e5
commit 8935e5408b
10 changed files with 253 additions and 225 deletions

View File

@@ -42,10 +42,9 @@ struct stellar_thread
pthread_t tid;
uint16_t idx;
uint64_t is_runing;
uint64_t last_free_expired_ip_frag_timestamp;
uint64_t last_merge_thread_stat_timestamp;
struct snowflake *snowflake;
struct ip_reassembly *ip_mgr;
struct ip_reassembly *ip_reass;
struct session_manager *sess_mgr;
struct stellar *st;
};
@@ -60,6 +59,7 @@ struct stellar_runtime
struct plugin_manager_schema *plug_mgr;
struct stellar_thread threads[MAX_THREAD_NUM];
struct session_manager_config *sess_mgr_cfg;
struct ip_reassembly_config *ip_reass_cfg;
};
struct stellar
@@ -130,7 +130,7 @@ static void *worker_thread(void *arg)
struct packet packets[RX_BURST_MAX];
struct session *sess = NULL;
struct stellar_thread *thread = (struct stellar_thread *)arg;
struct ip_reassembly *ip_reass = thread->ip_mgr;
struct ip_reassembly *ip_reass = thread->ip_reass;
struct session_manager *sess_mgr = thread->sess_mgr;
struct session_manager_stat *sess_stat = session_manager_stat(sess_mgr);
struct stellar *st = thread->st;
@@ -144,8 +144,6 @@ static void *worker_thread(void *arg)
.session_mgr = session_manager_stat(sess_mgr),
};
uint64_t free_expired_ip_frag_interval = config->sched_opts.free_expired_ip_frag_interval;
uint64_t free_expired_ip_frag_batch = config->sched_opts.free_expired_ip_frag_batch;
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;
@@ -290,6 +288,7 @@ static void *worker_thread(void *arg)
idle_tasks:
clean_session(sess_mgr, now_ms);
ip_reassembly_expire(ip_reass, now_ms);
plugin_manager_on_polling(plug_mgr);
// per merge_stat_interval merge thread stat
@@ -299,13 +298,6 @@ static void *worker_thread(void *arg)
thread->last_merge_thread_stat_timestamp = now_ms;
}
// per free_expired_ip_frag_interval MAX free_expired_ip_frag_batch ip fragments are released
if (now_ms - thread->last_free_expired_ip_frag_timestamp >= free_expired_ip_frag_interval)
{
ip_reassembly_expire(ip_reass, free_expired_ip_frag_batch, now_ms);
thread->last_free_expired_ip_frag_timestamp = now_ms;
}
if (nr_pkt_received == 0)
{
packet_io_yield(packet_io, thr_idx, packet_io_yield_interval);
@@ -359,7 +351,6 @@ static int stellar_thread_init(struct stellar *st)
thread->idx = i;
thread->is_runing = 0;
thread->last_free_expired_ip_frag_timestamp = now_ms;
thread->last_merge_thread_stat_timestamp = now_ms;
thread->snowflake = snowflake_new(i, config->snowflake_opts.snowflake_base, config->snowflake_opts.snowflake_offset);
@@ -368,6 +359,7 @@ static int stellar_thread_init(struct stellar *st)
CORE_LOG_ERROR("unable to create snowflake id generator");
return -1;
}
thread->sess_mgr = session_manager_new(runtime->sess_mgr_cfg, now_ms);
if (thread->sess_mgr == NULL)
{
@@ -375,8 +367,9 @@ static int stellar_thread_init(struct stellar *st)
return -1;
}
session_manager_set_session_id_generator(thread->sess_mgr, stellar_generate_session_id);
thread->ip_mgr = ip_reassembly_new(&config->ip_reass_opts);
if (thread->ip_mgr == NULL)
thread->ip_reass = ip_reassembly_new(runtime->ip_reass_cfg, now_ms);
if (thread->ip_reass == NULL)
{
CORE_LOG_ERROR("unable to create ip reassemble manager");
return -1;
@@ -398,7 +391,7 @@ static void stellar_thread_clean(struct stellar *st)
struct stellar_thread *thread = &runtime->threads[i];
if (ATOMIC_READ(&thread->is_runing) == 0)
{
ip_reassembly_free(thread->ip_mgr);
ip_reassembly_free(thread->ip_reass);
session_manager_free(thread->sess_mgr);
snowflake_free(thread->snowflake);
}
@@ -490,8 +483,15 @@ struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg
CORE_LOG_ERROR("unable to create session manager config");
goto error_out;
}
session_manager_config_print(runtime->sess_mgr_cfg);
runtime->ip_reass_cfg = ip_reassembly_config_new(st->stellar_cfg_file);
if (runtime->ip_reass_cfg == NULL)
{
CORE_LOG_ERROR("unable to create ip reassembly config");
goto error_out;
}
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)
{
CORE_LOG_ERROR("unable to load config file");
@@ -587,6 +587,7 @@ void stellar_free(struct stellar *st)
packet_io_free(runtime->packet_io);
plugin_manager_exit(runtime->plug_mgr);
stellar_stat_free(runtime->stat);
ip_reassembly_config_free(runtime->ip_reass_cfg);
session_manager_config_free(runtime->sess_mgr_cfg);
CORE_LOG_FATAL("stellar exit\n");
log_free(runtime->logger);