rename config -> options

This commit is contained in:
luwenpeng
2024-03-08 14:51:21 +08:00
parent d0914483bb
commit 734f6a5135
32 changed files with 336 additions and 336 deletions

View File

@@ -7,7 +7,7 @@
// return 0: success // return 0: success
// retuun -1: failed // retuun -1: failed
static int parse_device_config(struct device_config *dev_cfg, toml_table_t *conf_file_handle) static int parse_device_options(struct device_options *dev_opts, toml_table_t *conf_file_handle)
{ {
const char *ptr; const char *ptr;
toml_table_t *device_table; toml_table_t *device_table;
@@ -25,7 +25,7 @@ static int parse_device_config(struct device_config *dev_cfg, toml_table_t *conf
CONFIG_LOG_ERROR("config file missing device.device_base"); CONFIG_LOG_ERROR("config file missing device.device_base");
return -1; return -1;
} }
dev_cfg->device_base = atoi(ptr); dev_opts->device_base = atoi(ptr);
ptr = toml_raw_in(device_table, "device_offset"); ptr = toml_raw_in(device_table, "device_offset");
if (ptr == NULL) if (ptr == NULL)
@@ -33,14 +33,14 @@ static int parse_device_config(struct device_config *dev_cfg, toml_table_t *conf
CONFIG_LOG_ERROR("config file missing device.device_offset"); CONFIG_LOG_ERROR("config file missing device.device_offset");
return -1; return -1;
} }
dev_cfg->device_offset = atoi(ptr); dev_opts->device_offset = atoi(ptr);
return 0; return 0;
} }
// return 0: success // return 0: success
// retuun -1: failed // retuun -1: failed
static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_table_t *conf_file_handle) static int parse_packet_io_options(struct packet_io_options *pkt_io_opts, toml_table_t *conf_file_handle)
{ {
const char *ptr; const char *ptr;
toml_table_t *packet_io_table; toml_table_t *packet_io_table;
@@ -61,11 +61,11 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
} }
if (strcmp(ptr, "dumpfile") == 0) if (strcmp(ptr, "dumpfile") == 0)
{ {
pkt_io_cfg->mode = PACKET_IO_DUMPFILE; pkt_io_opts->mode = PACKET_IO_DUMPFILE;
} }
else if (strcmp(ptr, "marsio") == 0) else if (strcmp(ptr, "marsio") == 0)
{ {
pkt_io_cfg->mode = PACKET_IO_MARSIO; pkt_io_opts->mode = PACKET_IO_MARSIO;
} }
else else
{ {
@@ -73,7 +73,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
return -1; return -1;
} }
if (pkt_io_cfg->mode == PACKET_IO_DUMPFILE) if (pkt_io_opts->mode == PACKET_IO_DUMPFILE)
{ {
ptr = toml_raw_in(packet_io_table, "dumpfile_dir"); ptr = toml_raw_in(packet_io_table, "dumpfile_dir");
if (ptr == NULL) if (ptr == NULL)
@@ -82,7 +82,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
return -1; return -1;
} }
// skip "" // skip ""
strncpy(pkt_io_cfg->dumpfile_dir, ptr + 1, strlen(ptr) - 2); strncpy(pkt_io_opts->dumpfile_dir, ptr + 1, strlen(ptr) - 2);
} }
else else
{ {
@@ -92,7 +92,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
CONFIG_LOG_ERROR("config file missing packet_io.app_symbol"); CONFIG_LOG_ERROR("config file missing packet_io.app_symbol");
return -1; return -1;
} }
strncpy(pkt_io_cfg->app_symbol, ptr, sizeof(pkt_io_cfg->app_symbol) - 1); strncpy(pkt_io_opts->app_symbol, ptr, sizeof(pkt_io_opts->app_symbol) - 1);
ptr = toml_raw_in(packet_io_table, "dev_symbol"); ptr = toml_raw_in(packet_io_table, "dev_symbol");
if (ptr == NULL) if (ptr == NULL)
@@ -100,7 +100,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
CONFIG_LOG_ERROR("config file missing packet_io.dev_symbol"); CONFIG_LOG_ERROR("config file missing packet_io.dev_symbol");
return -1; return -1;
} }
strncpy(pkt_io_cfg->dev_symbol, ptr, sizeof(pkt_io_cfg->dev_symbol) - 1); strncpy(pkt_io_opts->dev_symbol, ptr, sizeof(pkt_io_opts->dev_symbol) - 1);
} }
ptr = toml_raw_in(packet_io_table, "nr_threads"); ptr = toml_raw_in(packet_io_table, "nr_threads");
@@ -114,7 +114,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
CONFIG_LOG_ERROR("config file invalid packet_io.nr_threads %d, range [1, %d]", atoi(ptr), MAX_THREAD_NUM); CONFIG_LOG_ERROR("config file invalid packet_io.nr_threads %d, range [1, %d]", atoi(ptr), MAX_THREAD_NUM);
return -1; return -1;
} }
pkt_io_cfg->nr_threads = atoi(ptr); pkt_io_opts->nr_threads = atoi(ptr);
mask_array = toml_array_in(packet_io_table, "cpu_mask"); mask_array = toml_array_in(packet_io_table, "cpu_mask");
if (mask_array == NULL) if (mask_array == NULL)
@@ -122,7 +122,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
CONFIG_LOG_ERROR("config file missing packet_io.cpu_mask"); CONFIG_LOG_ERROR("config file missing packet_io.cpu_mask");
return -1; return -1;
} }
for (uint8_t i = 0; i < pkt_io_cfg->nr_threads; i++) for (uint8_t i = 0; i < pkt_io_opts->nr_threads; i++)
{ {
ptr = toml_raw_at(mask_array, i); ptr = toml_raw_at(mask_array, i);
if (ptr == NULL) if (ptr == NULL)
@@ -130,7 +130,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
CONFIG_LOG_ERROR("config file missing packet_io.cpu_mask[%d]", i); CONFIG_LOG_ERROR("config file missing packet_io.cpu_mask[%d]", i);
return -1; return -1;
} }
pkt_io_cfg->cpu_mask[i] = atoi(ptr); pkt_io_opts->cpu_mask[i] = atoi(ptr);
} }
return 0; return 0;
@@ -138,7 +138,7 @@ static int parse_packet_io_config(struct packet_io_config *pkt_io_cfg, toml_tabl
// return 0: success // return 0: success
// retuun -1: failed // retuun -1: failed
static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg, toml_table_t *conf_file_handle) static int parse_ip_reassembly_options(struct ip_reassembly_options *ip_reass_opts, toml_table_t *conf_file_handle)
{ {
const char *ptr; const char *ptr;
toml_table_t *ip_reass_table; toml_table_t *ip_reass_table;
@@ -156,7 +156,7 @@ static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg,
CONFIG_LOG_ERROR("config file missing ip_reassembly.enable"); CONFIG_LOG_ERROR("config file missing ip_reassembly.enable");
return -1; return -1;
} }
ip_reass_cfg->enable = atoi(ptr); ip_reass_opts->enable = atoi(ptr);
ptr = toml_raw_in(ip_reass_table, "timeout"); ptr = toml_raw_in(ip_reass_table, "timeout");
if (ptr == NULL) if (ptr == NULL)
@@ -164,7 +164,7 @@ static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg,
CONFIG_LOG_ERROR("config file missing ip_reassembly.timeout"); CONFIG_LOG_ERROR("config file missing ip_reassembly.timeout");
return -1; return -1;
} }
ip_reass_cfg->timeout = atoi(ptr); ip_reass_opts->timeout = atoi(ptr);
ptr = toml_raw_in(ip_reass_table, "bucket_entries"); ptr = toml_raw_in(ip_reass_table, "bucket_entries");
if (ptr == NULL) if (ptr == NULL)
@@ -172,7 +172,7 @@ static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg,
CONFIG_LOG_ERROR("config file missing ip_reassembly.bucket_entries"); CONFIG_LOG_ERROR("config file missing ip_reassembly.bucket_entries");
return -1; return -1;
} }
ip_reass_cfg->bucket_entries = atoi(ptr); ip_reass_opts->bucket_entries = atoi(ptr);
ptr = toml_raw_in(ip_reass_table, "bucket_num"); ptr = toml_raw_in(ip_reass_table, "bucket_num");
if (ptr == NULL) if (ptr == NULL)
@@ -180,14 +180,14 @@ static int parse_ip_reassembly_config(struct ip_reassembly_config *ip_reass_cfg,
CONFIG_LOG_ERROR("config file missing ip_reassembly.bucket_num"); CONFIG_LOG_ERROR("config file missing ip_reassembly.bucket_num");
return -1; return -1;
} }
ip_reass_cfg->bucket_num = atoi(ptr); ip_reass_opts->bucket_num = atoi(ptr);
return 0; return 0;
} }
// return 0: success // return 0: success
// retuun -1: failed // retuun -1: failed
static int parse_session_manager_section(struct session_manager_config *sess_mgr_cfg, toml_table_t *conf_file_handle) static int parse_session_manager_options(struct session_manager_options *sess_mgr_opts, toml_table_t *conf_file_handle)
{ {
const char *ptr; const char *ptr;
toml_table_t *sess_mgr_table; toml_table_t *sess_mgr_table;
@@ -206,7 +206,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.max_tcp_session_num"); CONFIG_LOG_ERROR("config file missing session_manager.max_tcp_session_num");
return -1; return -1;
} }
sess_mgr_cfg->max_tcp_session_num = atoll(ptr); sess_mgr_opts->max_tcp_session_num = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "max_udp_session_num"); ptr = toml_raw_in(sess_mgr_table, "max_udp_session_num");
if (ptr == NULL) if (ptr == NULL)
@@ -214,7 +214,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.max_udp_session_num"); CONFIG_LOG_ERROR("config file missing session_manager.max_udp_session_num");
return -1; return -1;
} }
sess_mgr_cfg->max_udp_session_num = atoll(ptr); sess_mgr_opts->max_udp_session_num = atoll(ptr);
// session overload (1: evict old session, 0: bypass new session) // session overload (1: evict old session, 0: bypass new session)
ptr = toml_raw_in(sess_mgr_table, "tcp_overload_evict_old_sess"); ptr = toml_raw_in(sess_mgr_table, "tcp_overload_evict_old_sess");
@@ -223,7 +223,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_overload_evict_old_sess"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_overload_evict_old_sess");
return -1; return -1;
} }
sess_mgr_cfg->tcp_overload_evict_old_sess = atoi(ptr); sess_mgr_opts->tcp_overload_evict_old_sess = atoi(ptr);
ptr = toml_raw_in(sess_mgr_table, "udp_overload_evict_old_sess"); ptr = toml_raw_in(sess_mgr_table, "udp_overload_evict_old_sess");
if (ptr == NULL) if (ptr == NULL)
@@ -231,7 +231,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.udp_overload_evict_old_sess"); CONFIG_LOG_ERROR("config file missing session_manager.udp_overload_evict_old_sess");
return -1; return -1;
} }
sess_mgr_cfg->udp_overload_evict_old_sess = atoi(ptr); sess_mgr_opts->udp_overload_evict_old_sess = atoi(ptr);
// TCP timeout // TCP timeout
ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_init"); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_init");
@@ -240,7 +240,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_init"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_init");
return -1; return -1;
} }
sess_mgr_cfg->tcp_timeout_init = atoll(ptr); sess_mgr_opts->tcp_timeout_init = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_handshake"); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_handshake");
if (ptr == NULL) if (ptr == NULL)
@@ -248,7 +248,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_handshake"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_handshake");
return -1; return -1;
} }
sess_mgr_cfg->tcp_timeout_handshake = atoll(ptr); sess_mgr_opts->tcp_timeout_handshake = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_data"); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_data");
if (ptr == NULL) if (ptr == NULL)
@@ -256,7 +256,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_data"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_data");
return -1; return -1;
} }
sess_mgr_cfg->tcp_timeout_data = atoll(ptr); sess_mgr_opts->tcp_timeout_data = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_half_closed"); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_half_closed");
if (ptr == NULL) if (ptr == NULL)
@@ -264,7 +264,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_half_closed"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_half_closed");
return -1; return -1;
} }
sess_mgr_cfg->tcp_timeout_half_closed = atoll(ptr); sess_mgr_opts->tcp_timeout_half_closed = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_time_wait"); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_time_wait");
if (ptr == NULL) if (ptr == NULL)
@@ -272,7 +272,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_time_wait"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_time_wait");
return -1; return -1;
} }
sess_mgr_cfg->tcp_timeout_time_wait = atoll(ptr); sess_mgr_opts->tcp_timeout_time_wait = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_discard"); ptr = toml_raw_in(sess_mgr_table, "tcp_timeout_discard");
if (ptr == NULL) if (ptr == NULL)
@@ -280,7 +280,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_discard"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_timeout_discard");
return -1; return -1;
} }
sess_mgr_cfg->tcp_timeout_discard = atoll(ptr); sess_mgr_opts->tcp_timeout_discard = atoll(ptr);
// UDP timeout // UDP timeout
ptr = toml_raw_in(sess_mgr_table, "udp_timeout_data"); ptr = toml_raw_in(sess_mgr_table, "udp_timeout_data");
@@ -289,7 +289,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.udp_timeout_data"); CONFIG_LOG_ERROR("config file missing session_manager.udp_timeout_data");
return -1; return -1;
} }
sess_mgr_cfg->udp_timeout_data = atoll(ptr); sess_mgr_opts->udp_timeout_data = atoll(ptr);
// TCP duplicate packet filter // TCP duplicate packet filter
ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_enable"); ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_enable");
@@ -298,7 +298,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_enable"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_enable");
return -1; return -1;
} }
sess_mgr_cfg->tcp_dupkt_filter_enable = atoi(ptr); sess_mgr_opts->tcp_dupkt_filter_enable = atoi(ptr);
ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_capacity"); ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_capacity");
if (ptr == NULL) if (ptr == NULL)
@@ -306,7 +306,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_capacity"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_capacity");
return -1; return -1;
} }
sess_mgr_cfg->tcp_dupkt_filter_capacity = atoll(ptr); sess_mgr_opts->tcp_dupkt_filter_capacity = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_timeout"); ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_timeout");
if (ptr == NULL) if (ptr == NULL)
@@ -314,7 +314,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_timeout"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_timeout");
return -1; return -1;
} }
sess_mgr_cfg->tcp_dupkt_filter_timeout = atoll(ptr); sess_mgr_opts->tcp_dupkt_filter_timeout = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_error_rate"); ptr = toml_raw_in(sess_mgr_table, "tcp_dupkt_filter_error_rate");
if (ptr == NULL) if (ptr == NULL)
@@ -322,7 +322,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_error_rate"); CONFIG_LOG_ERROR("config file missing session_manager.tcp_dupkt_filter_error_rate");
return -1; return -1;
} }
sess_mgr_cfg->tcp_dupkt_filter_error_rate = atof(ptr); sess_mgr_opts->tcp_dupkt_filter_error_rate = atof(ptr);
// UDP eviction filter // UDP eviction filter
ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_enable"); ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_enable");
@@ -331,7 +331,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_enable"); CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_enable");
return -1; return -1;
} }
sess_mgr_cfg->udp_eviction_filter_enable = atoi(ptr); sess_mgr_opts->udp_eviction_filter_enable = atoi(ptr);
ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_capacity"); ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_capacity");
if (ptr == NULL) if (ptr == NULL)
@@ -339,7 +339,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_capacity"); CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_capacity");
return -1; return -1;
} }
sess_mgr_cfg->udp_eviction_filter_capacity = atoll(ptr); sess_mgr_opts->udp_eviction_filter_capacity = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_timeout"); ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_timeout");
if (ptr == NULL) if (ptr == NULL)
@@ -347,7 +347,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_timeout"); CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_timeout");
return -1; return -1;
} }
sess_mgr_cfg->udp_eviction_filter_timeout = atoll(ptr); sess_mgr_opts->udp_eviction_filter_timeout = atoll(ptr);
ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_error_rate"); ptr = toml_raw_in(sess_mgr_table, "udp_eviction_filter_error_rate");
if (ptr == NULL) if (ptr == NULL)
@@ -355,7 +355,7 @@ static int parse_session_manager_section(struct session_manager_config *sess_mgr
CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_error_rate"); CONFIG_LOG_ERROR("config file missing session_manager.udp_eviction_filter_error_rate");
return -1; return -1;
} }
sess_mgr_cfg->udp_eviction_filter_error_rate = atof(ptr); sess_mgr_opts->udp_eviction_filter_error_rate = atof(ptr);
return 0; return 0;
} }
@@ -385,22 +385,22 @@ int config_load(struct config *cfg, const char *cfg_file)
goto error_out; goto error_out;
} }
if (parse_device_config(&cfg->dev_cfg, conf_file_handle) != 0) if (parse_device_options(&cfg->dev_opts, conf_file_handle) != 0)
{ {
goto error_out; goto error_out;
} }
if (parse_packet_io_config(&cfg->pkt_io_cfg, conf_file_handle) != 0) if (parse_packet_io_options(&cfg->pkt_io_opts, conf_file_handle) != 0)
{ {
goto error_out; goto error_out;
} }
if (parse_ip_reassembly_config(&cfg->ip_reass_cfg, conf_file_handle) != 0) if (parse_ip_reassembly_options(&cfg->ip_reass_opts, conf_file_handle) != 0)
{ {
goto error_out; goto error_out;
} }
if (parse_session_manager_section(&cfg->sess_mgr_cfg, conf_file_handle) != 0) if (parse_session_manager_options(&cfg->sess_mgr_opts, conf_file_handle) != 0)
{ {
goto error_out; goto error_out;
} }
@@ -428,61 +428,61 @@ void config_dump(struct config *cfg)
return; return;
} }
struct device_config *dev_cfg = &cfg->dev_cfg; struct device_options *dev_opts = &cfg->dev_opts;
struct packet_io_config *pkt_io_cfg = &cfg->pkt_io_cfg; struct packet_io_options *pkt_io_opts = &cfg->pkt_io_opts;
struct ip_reassembly_config *ip_reass_cfg = &cfg->ip_reass_cfg; struct ip_reassembly_options *ip_reass_opts = &cfg->ip_reass_opts;
struct session_manager_config *sess_mgr_cfg = &cfg->sess_mgr_cfg; struct session_manager_options *sess_mgr_opts = &cfg->sess_mgr_opts;
// device config // device config
CONFIG_LOG_DEBUG("device->device_base : %d", dev_cfg->device_base); CONFIG_LOG_DEBUG("device->device_base : %d", dev_opts->device_base);
CONFIG_LOG_DEBUG("device->device_offset : %d", dev_cfg->device_offset); CONFIG_LOG_DEBUG("device->device_offset : %d", dev_opts->device_offset);
// packet io config // packet io config
CONFIG_LOG_DEBUG("packet_io->mode : %s", pkt_io_cfg->mode == PACKET_IO_DUMPFILE ? "dumpfile" : "marsio"); CONFIG_LOG_DEBUG("packet_io->mode : %s", pkt_io_opts->mode == PACKET_IO_DUMPFILE ? "dumpfile" : "marsio");
if (pkt_io_cfg->mode == PACKET_IO_DUMPFILE) if (pkt_io_opts->mode == PACKET_IO_DUMPFILE)
{ {
CONFIG_LOG_DEBUG("packet_io->dumpfile_dir : %s", pkt_io_cfg->dumpfile_dir); CONFIG_LOG_DEBUG("packet_io->dumpfile_dir : %s", pkt_io_opts->dumpfile_dir);
} }
else else
{ {
CONFIG_LOG_DEBUG("packet_io->app_symbol : %s", pkt_io_cfg->app_symbol); CONFIG_LOG_DEBUG("packet_io->app_symbol : %s", pkt_io_opts->app_symbol);
CONFIG_LOG_DEBUG("packet_io->dev_symbol : %s", pkt_io_cfg->dev_symbol); CONFIG_LOG_DEBUG("packet_io->dev_symbol : %s", pkt_io_opts->dev_symbol);
} }
CONFIG_LOG_DEBUG("packet_io->nr_threads : %d", pkt_io_cfg->nr_threads); CONFIG_LOG_DEBUG("packet_io->nr_threads : %d", pkt_io_opts->nr_threads);
for (uint8_t i = 0; i < pkt_io_cfg->nr_threads; i++) for (uint8_t i = 0; i < pkt_io_opts->nr_threads; i++)
{ {
CONFIG_LOG_DEBUG("packet_io->cpu_mask[%03d] : %d", i, pkt_io_cfg->cpu_mask[i]); CONFIG_LOG_DEBUG("packet_io->cpu_mask[%03d] : %d", i, pkt_io_opts->cpu_mask[i]);
} }
// ip reassemble config // ip reassemble config
CONFIG_LOG_DEBUG("ip_reassembly->enable : %d", ip_reass_cfg->enable); CONFIG_LOG_DEBUG("ip_reassembly->enable : %d", ip_reass_opts->enable);
CONFIG_LOG_DEBUG("ip_reassembly->timeout : %d", ip_reass_cfg->timeout); CONFIG_LOG_DEBUG("ip_reassembly->timeout : %d", ip_reass_opts->timeout);
CONFIG_LOG_DEBUG("ip_reassembly->bucket_entries : %d", ip_reass_cfg->bucket_entries); CONFIG_LOG_DEBUG("ip_reassembly->bucket_entries : %d", ip_reass_opts->bucket_entries);
CONFIG_LOG_DEBUG("ip_reassembly->bucket_num : %d", ip_reass_cfg->bucket_num); CONFIG_LOG_DEBUG("ip_reassembly->bucket_num : %d", ip_reass_opts->bucket_num);
// session manager config // session manager config
CONFIG_LOG_DEBUG("session_manager->max_tcp_session_num : %ld", sess_mgr_cfg->max_tcp_session_num); CONFIG_LOG_DEBUG("session_manager->max_tcp_session_num : %ld", sess_mgr_opts->max_tcp_session_num);
CONFIG_LOG_DEBUG("session_manager->max_udp_session_num : %ld", sess_mgr_cfg->max_udp_session_num); CONFIG_LOG_DEBUG("session_manager->max_udp_session_num : %ld", sess_mgr_opts->max_udp_session_num);
CONFIG_LOG_DEBUG("session_manager->tcp_overload_evict_old_sess : %d", sess_mgr_cfg->tcp_overload_evict_old_sess); CONFIG_LOG_DEBUG("session_manager->tcp_overload_evict_old_sess : %d", sess_mgr_opts->tcp_overload_evict_old_sess);
CONFIG_LOG_DEBUG("session_manager->udp_overload_evict_old_sess : %d", sess_mgr_cfg->udp_overload_evict_old_sess); CONFIG_LOG_DEBUG("session_manager->udp_overload_evict_old_sess : %d", sess_mgr_opts->udp_overload_evict_old_sess);
CONFIG_LOG_DEBUG("session_manager->tcp_timeout_init : %ld", sess_mgr_cfg->tcp_timeout_init); CONFIG_LOG_DEBUG("session_manager->tcp_timeout_init : %ld", sess_mgr_opts->tcp_timeout_init);
CONFIG_LOG_DEBUG("session_manager->tcp_timeout_handshake : %ld", sess_mgr_cfg->tcp_timeout_handshake); CONFIG_LOG_DEBUG("session_manager->tcp_timeout_handshake : %ld", sess_mgr_opts->tcp_timeout_handshake);
CONFIG_LOG_DEBUG("session_manager->tcp_timeout_data : %ld", sess_mgr_cfg->tcp_timeout_data); CONFIG_LOG_DEBUG("session_manager->tcp_timeout_data : %ld", sess_mgr_opts->tcp_timeout_data);
CONFIG_LOG_DEBUG("session_manager->tcp_timeout_half_closed : %ld", sess_mgr_cfg->tcp_timeout_half_closed); CONFIG_LOG_DEBUG("session_manager->tcp_timeout_half_closed : %ld", sess_mgr_opts->tcp_timeout_half_closed);
CONFIG_LOG_DEBUG("session_manager->tcp_timeout_time_wait : %ld", sess_mgr_cfg->tcp_timeout_time_wait); CONFIG_LOG_DEBUG("session_manager->tcp_timeout_time_wait : %ld", sess_mgr_opts->tcp_timeout_time_wait);
CONFIG_LOG_DEBUG("session_manager->tcp_timeout_discard : %ld", sess_mgr_cfg->tcp_timeout_discard); CONFIG_LOG_DEBUG("session_manager->tcp_timeout_discard : %ld", sess_mgr_opts->tcp_timeout_discard);
CONFIG_LOG_DEBUG("session_manager->udp_timeout_data : %ld", sess_mgr_cfg->udp_timeout_data); CONFIG_LOG_DEBUG("session_manager->udp_timeout_data : %ld", sess_mgr_opts->udp_timeout_data);
CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_enable : %d", sess_mgr_cfg->tcp_dupkt_filter_enable); CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_enable : %d", sess_mgr_opts->tcp_dupkt_filter_enable);
CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_capacity : %ld", sess_mgr_cfg->tcp_dupkt_filter_capacity); CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_capacity : %ld", sess_mgr_opts->tcp_dupkt_filter_capacity);
CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_timeout : %ld", sess_mgr_cfg->tcp_dupkt_filter_timeout); CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_timeout : %ld", sess_mgr_opts->tcp_dupkt_filter_timeout);
CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_error_rate : %f", sess_mgr_cfg->tcp_dupkt_filter_error_rate); CONFIG_LOG_DEBUG("session_manager->tcp_dupkt_filter_error_rate : %f", sess_mgr_opts->tcp_dupkt_filter_error_rate);
CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_enable : %d", sess_mgr_cfg->udp_eviction_filter_enable); CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_enable : %d", sess_mgr_opts->udp_eviction_filter_enable);
CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_capacity : %ld", sess_mgr_cfg->udp_eviction_filter_capacity); CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_capacity : %ld", sess_mgr_opts->udp_eviction_filter_capacity);
CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_timeout : %ld", sess_mgr_cfg->udp_eviction_filter_timeout); CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_timeout : %ld", sess_mgr_opts->udp_eviction_filter_timeout);
CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_error_rate : %f", sess_mgr_cfg->udp_eviction_filter_error_rate); CONFIG_LOG_DEBUG("session_manager->udp_eviction_filter_error_rate : %f", sess_mgr_opts->udp_eviction_filter_error_rate);
} }

View File

@@ -22,7 +22,7 @@ extern "C"
fprintf(stderr, "DEBUG (config), " format "\n", ##__VA_ARGS__); fprintf(stderr, "DEBUG (config), " format "\n", ##__VA_ARGS__);
#endif #endif
struct device_config struct device_options
{ {
uint8_t device_base; uint8_t device_base;
uint8_t device_offset; uint8_t device_offset;
@@ -30,10 +30,10 @@ struct device_config
struct config struct config
{ {
struct device_config dev_cfg; struct device_options dev_opts;
struct packet_io_config pkt_io_cfg; struct packet_io_options pkt_io_opts;
struct ip_reassembly_config ip_reass_cfg; struct ip_reassembly_options ip_reass_opts;
struct session_manager_config sess_mgr_cfg; struct session_manager_options sess_mgr_opts;
}; };
int config_load(struct config *cfg, const char *cfg_file); int config_load(struct config *cfg, const char *cfg_file);

View File

@@ -110,7 +110,7 @@ struct ip_flow
struct ip_reassembly struct ip_reassembly
{ {
// config // options
bool enable; bool enable;
uint32_t timeout; uint32_t timeout;
uint32_t bucket_entries; uint32_t bucket_entries;
@@ -189,29 +189,29 @@ static inline int is_power_of_2(uint32_t n)
return n && !(n & (n - 1)); return n && !(n & (n - 1));
} }
static inline int ip_reassembly_check_config(const struct ip_reassembly_config *config) static inline int ip_reassembly_check_options(const struct ip_reassembly_options *opts)
{ {
if (config == NULL) if (opts == NULL)
{ {
IP_REASSEMBLE_DEBUG("invalid config"); IP_REASSEMBLE_DEBUG("invalid options");
return -1; return -1;
} }
if (config->enable) if (opts->enable)
{ {
if (config->timeout == 0) if (opts->timeout == 0)
{ {
IP_REASSEMBLE_DEBUG("invalid timeout"); IP_REASSEMBLE_DEBUG("invalid timeout");
return -1; return -1;
} }
if (config->bucket_entries == 0 || is_power_of_2(config->bucket_entries) == 0) if (opts->bucket_entries == 0 || is_power_of_2(opts->bucket_entries) == 0)
{ {
IP_REASSEMBLE_DEBUG("invalid bucket entries, must be power of 2"); IP_REASSEMBLE_DEBUG("invalid bucket entries, must be power of 2");
return -1; return -1;
} }
if (config->bucket_num == 0) if (opts->bucket_num == 0)
{ {
IP_REASSEMBLE_DEBUG("invalid bucket num"); IP_REASSEMBLE_DEBUG("invalid bucket num");
return -1; return -1;
@@ -752,9 +752,9 @@ error_out_overlap:
* Public API * Public API
******************************************************************************/ ******************************************************************************/
struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_config *config) struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_options *opts)
{ {
if (ip_reassembly_check_config(config) != 0) if (ip_reassembly_check_options(opts) != 0)
{ {
return NULL; return NULL;
} }
@@ -765,10 +765,10 @@ struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_config *confi
IP_REASSEMBLE_ERROR("unable to allocate memory"); IP_REASSEMBLE_ERROR("unable to allocate memory");
return NULL; return NULL;
} }
mgr->enable = config->enable; mgr->enable = opts->enable;
mgr->timeout = config->timeout; mgr->timeout = opts->timeout;
mgr->bucket_entries = config->bucket_entries; mgr->bucket_entries = opts->bucket_entries;
mgr->bucket_num = config->bucket_num; mgr->bucket_num = opts->bucket_num;
if (!mgr->enable) if (!mgr->enable)
{ {

View File

@@ -12,7 +12,7 @@ extern "C"
#define IP_REASSEMBLE_DEBUG(format, ...) LOG_DEBUG("ip_reassembly", format, ##__VA_ARGS__) #define IP_REASSEMBLE_DEBUG(format, ...) LOG_DEBUG("ip_reassembly", format, ##__VA_ARGS__)
#define IP_REASSEMBLE_ERROR(format, ...) LOG_ERROR("ip_reassembly", format, ##__VA_ARGS__) #define IP_REASSEMBLE_ERROR(format, ...) LOG_ERROR("ip_reassembly", format, ##__VA_ARGS__)
struct ip_reassembly_config struct ip_reassembly_options
{ {
bool enable; bool enable;
@@ -50,7 +50,7 @@ struct ip_reassembly_stat
uint64_t ip6_flow_bypass_dup_last_frag; uint64_t ip6_flow_bypass_dup_last_frag;
}; };
struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_config *config); struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_options *opts);
void ip_reassembly_free(struct ip_reassembly *mgr); void ip_reassembly_free(struct ip_reassembly *mgr);
void ip_reassembly_expire(struct ip_reassembly *mgr); void ip_reassembly_expire(struct ip_reassembly *mgr);
void ip_reassembly_print_stat(struct ip_reassembly *mgr); void ip_reassembly_print_stat(struct ip_reassembly *mgr);

View File

@@ -198,7 +198,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
struct packet *new_pkt; struct packet *new_pkt;
const struct layer_record *layer; const struct layer_record *layer;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -207,7 +207,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -293,7 +293,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
struct packet *new_pkt; struct packet *new_pkt;
const struct layer_record *layer; const struct layer_record *layer;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -302,7 +302,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -387,7 +387,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -396,7 +396,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -445,7 +445,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
struct packet *new_pkt; struct packet *new_pkt;
const struct layer_record *layer; const struct layer_record *layer;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -454,7 +454,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -551,7 +551,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
struct packet *new_pkt; struct packet *new_pkt;
const struct layer_record *layer; const struct layer_record *layer;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -560,7 +560,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -656,7 +656,7 @@ TEST(IPV4_REASSEMBLE, FULL)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 1, .bucket_entries = 1,
@@ -665,7 +665,7 @@ TEST(IPV4_REASSEMBLE, FULL)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),

View File

@@ -609,7 +609,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
struct packet *new_pkt; struct packet *new_pkt;
const struct layer_record *layer; const struct layer_record *layer;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -618,7 +618,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -719,7 +719,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -728,7 +728,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -777,7 +777,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
struct packet *new_pkt; struct packet *new_pkt;
const struct layer_record *layer; const struct layer_record *layer;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -786,7 +786,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -899,7 +899,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
struct packet *new_pkt; struct packet *new_pkt;
const struct layer_record *layer; const struct layer_record *layer;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -908,7 +908,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -1021,7 +1021,7 @@ TEST(IPV6_REASSEMBLE, FULL)
struct packet *new_pkt; struct packet *new_pkt;
struct in6_addr src_addr; struct in6_addr src_addr;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 1, .bucket_entries = 1,
@@ -1030,7 +1030,7 @@ TEST(IPV6_REASSEMBLE, FULL)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),
@@ -1092,7 +1092,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
struct packet pkt; struct packet pkt;
struct packet *new_pkt; struct packet *new_pkt;
struct ip_reassembly *mgr; struct ip_reassembly *mgr;
struct ip_reassembly_config config = { struct ip_reassembly_options opts = {
.enable = true, .enable = true,
.timeout = 1, .timeout = 1,
.bucket_entries = 16, .bucket_entries = 16,
@@ -1101,7 +1101,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
timestamp_update(); timestamp_update();
mgr = ip_reassembly_new(&config); mgr = ip_reassembly_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// ip_reassembly_print_stat(mgr); // ip_reassembly_print_stat(mgr);
check_stat(ip_reassembly_get_stat(mgr), check_stat(ip_reassembly_get_stat(mgr),

View File

@@ -5,7 +5,7 @@
#include "packet_io_marsio.h" #include "packet_io_marsio.h"
#include "packet_io_dumpfile.h" #include "packet_io_dumpfile.h"
typedef void *new_cb(void *config); typedef void *new_cb(void *options);
typedef void free_cb(void *handle); typedef void free_cb(void *handle);
typedef void *stat_cb(void *handle); typedef void *stat_cb(void *handle);
typedef int init_cb(void *handle, uint16_t thread_id); typedef int init_cb(void *handle, uint16_t thread_id);
@@ -23,7 +23,7 @@ struct packet_io
send_cb *on_send; send_cb *on_send;
}; };
struct packet_io *packet_io_new(struct packet_io_config *config) struct packet_io *packet_io_new(struct packet_io_options *opts)
{ {
struct packet_io *handle = (struct packet_io *)calloc(1, sizeof(struct packet_io)); struct packet_io *handle = (struct packet_io *)calloc(1, sizeof(struct packet_io));
if (handle == NULL) if (handle == NULL)
@@ -32,21 +32,21 @@ struct packet_io *packet_io_new(struct packet_io_config *config)
return NULL; return NULL;
} }
struct packet_io_marsio_confg marsio_config; struct packet_io_marsio_opts marsio_opts;
strncpy(marsio_config.app_symbol, config->app_symbol, sizeof(marsio_config.app_symbol)); strncpy(marsio_opts.app_symbol, opts->app_symbol, sizeof(marsio_opts.app_symbol));
strncpy(marsio_config.dev_symbol, config->dev_symbol, sizeof(marsio_config.dev_symbol)); strncpy(marsio_opts.dev_symbol, opts->dev_symbol, sizeof(marsio_opts.dev_symbol));
memcpy(marsio_config.cpu_mask, config->cpu_mask, sizeof(marsio_config.cpu_mask)); memcpy(marsio_opts.cpu_mask, opts->cpu_mask, sizeof(marsio_opts.cpu_mask));
marsio_config.nr_threads = config->nr_threads; marsio_opts.nr_threads = opts->nr_threads;
struct packet_io_dumpfile_confg dumpfile_config; struct packet_io_dumpfile_opts dumpfile_opts;
strncpy(dumpfile_config.dumpfile_dir, config->dumpfile_dir, sizeof(dumpfile_config.dumpfile_dir)); strncpy(dumpfile_opts.dumpfile_dir, opts->dumpfile_dir, sizeof(dumpfile_opts.dumpfile_dir));
dumpfile_config.nr_threads = config->nr_threads; dumpfile_opts.nr_threads = opts->nr_threads;
void *_config = NULL; void *_opts = NULL;
if (config->mode == PACKET_IO_MARSIO) if (opts->mode == PACKET_IO_MARSIO)
{ {
_config = &marsio_config; _opts = &marsio_opts;
handle->on_new = (new_cb *)packet_io_marsio_new; handle->on_new = (new_cb *)packet_io_marsio_new;
handle->on_free = (free_cb *)packet_io_marsio_free; handle->on_free = (free_cb *)packet_io_marsio_free;
handle->on_stat = (stat_cb *)packet_io_marsio_stat; handle->on_stat = (stat_cb *)packet_io_marsio_stat;
@@ -56,7 +56,7 @@ struct packet_io *packet_io_new(struct packet_io_config *config)
} }
else else
{ {
_config = &dumpfile_config; _opts = &dumpfile_opts;
handle->on_new = (new_cb *)packet_io_dumpfile_new; handle->on_new = (new_cb *)packet_io_dumpfile_new;
handle->on_free = (free_cb *)packet_io_dumpfile_free; handle->on_free = (free_cb *)packet_io_dumpfile_free;
handle->on_stat = (stat_cb *)packet_io_dumpfile_stat; handle->on_stat = (stat_cb *)packet_io_dumpfile_stat;
@@ -65,7 +65,7 @@ struct packet_io *packet_io_new(struct packet_io_config *config)
handle->on_send = (send_cb *)packet_io_dumpfile_send; handle->on_send = (send_cb *)packet_io_dumpfile_send;
} }
handle->handle = handle->on_new(_config); handle->handle = handle->on_new(_opts);
if (handle->handle == NULL) if (handle->handle == NULL)
{ {
goto error_out; goto error_out;

View File

@@ -37,7 +37,7 @@ enum packet_io_mode
PACKET_IO_MARSIO = 1, PACKET_IO_MARSIO = 1,
}; };
struct packet_io_config struct packet_io_options
{ {
enum packet_io_mode mode; enum packet_io_mode mode;
@@ -53,7 +53,7 @@ struct packet_io_config
}; };
struct packet_io; struct packet_io;
struct packet_io *packet_io_new(struct packet_io_config *config); struct packet_io *packet_io_new(struct packet_io_options *opts);
void packet_io_free(struct packet_io *handle); void packet_io_free(struct packet_io *handle);
void packet_io_print_stat(struct packet_io *handle); void packet_io_print_stat(struct packet_io *handle);
struct packet_io_stat *packet_io_get_stat(struct packet_io *handle); struct packet_io_stat *packet_io_get_stat(struct packet_io *handle);

View File

@@ -91,7 +91,7 @@ static void *dumpfile_thread_cycle(void *arg)
* Public API * Public API
******************************************************************************/ ******************************************************************************/
struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_confg *config) struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_opts *opts)
{ {
pthread_t tid; pthread_t tid;
struct packet_io_dumpfile *handle = (struct packet_io_dumpfile *)calloc(1, sizeof(struct packet_io_dumpfile)); struct packet_io_dumpfile *handle = (struct packet_io_dumpfile *)calloc(1, sizeof(struct packet_io_dumpfile));
@@ -101,8 +101,8 @@ struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_conf
return NULL; return NULL;
} }
handle->nr_threads = config->nr_threads; handle->nr_threads = opts->nr_threads;
strncpy(handle->dumpfile_dir, config->dumpfile_dir, sizeof(handle->dumpfile_dir)); strncpy(handle->dumpfile_dir, opts->dumpfile_dir, sizeof(handle->dumpfile_dir));
for (uint16_t i = 0; i < handle->nr_threads; i++) for (uint16_t i = 0; i < handle->nr_threads; i++)
{ {

View File

@@ -8,7 +8,7 @@ extern "C"
#include "packet.h" #include "packet.h"
struct packet_io_dumpfile_confg struct packet_io_dumpfile_opts
{ {
char dumpfile_dir[256]; char dumpfile_dir[256];
uint8_t nr_threads; uint8_t nr_threads;
@@ -16,7 +16,7 @@ struct packet_io_dumpfile_confg
struct packet_io_dumpfile; struct packet_io_dumpfile;
struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_confg *config); struct packet_io_dumpfile *packet_io_dumpfile_new(struct packet_io_dumpfile_opts *opts);
void packet_io_dumpfile_free(struct packet_io_dumpfile *handle); void packet_io_dumpfile_free(struct packet_io_dumpfile *handle);
struct packet_io_stat *packet_io_dumpfile_stat(struct packet_io_dumpfile *handle); struct packet_io_stat *packet_io_dumpfile_stat(struct packet_io_dumpfile *handle);

View File

@@ -65,14 +65,14 @@ static int is_keepalive_packet(const char *data, int len)
* Public API * Public API
******************************************************************************/ ******************************************************************************/
struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_confg *config) struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_opts *opts)
{ {
int opt = 1; int opt = 1;
cpu_set_t coremask; cpu_set_t coremask;
CPU_ZERO(&coremask); CPU_ZERO(&coremask);
for (uint8_t i = 0; i < config->nr_threads; i++) for (uint8_t i = 0; i < opts->nr_threads; i++)
{ {
CPU_SET(config->cpu_mask[i], &coremask); CPU_SET(opts->cpu_mask[i], &coremask);
} }
struct packet_io_marsio *handle = (struct packet_io_marsio *)calloc(1, sizeof(struct packet_io_marsio)); struct packet_io_marsio *handle = (struct packet_io_marsio *)calloc(1, sizeof(struct packet_io_marsio));
@@ -92,13 +92,13 @@ struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_confg *con
marsio_option_set(handle->mr_ins, MARSIO_OPT_THREAD_MASK_IN_CPUSET, &coremask, sizeof(coremask)); marsio_option_set(handle->mr_ins, MARSIO_OPT_THREAD_MASK_IN_CPUSET, &coremask, sizeof(coremask));
marsio_option_set(handle->mr_ins, MARSIO_OPT_EXIT_WHEN_ERR, &opt, sizeof(opt)); marsio_option_set(handle->mr_ins, MARSIO_OPT_EXIT_WHEN_ERR, &opt, sizeof(opt));
if (marsio_init(handle->mr_ins, config->app_symbol) != 0) if (marsio_init(handle->mr_ins, opts->app_symbol) != 0)
{ {
PACKET_IO_LOG_ERROR("unable to init marsio instance"); PACKET_IO_LOG_ERROR("unable to init marsio instance");
goto error_out; goto error_out;
} }
handle->mr_dev = marsio_open_device(handle->mr_ins, config->dev_symbol, config->nr_threads, config->nr_threads); handle->mr_dev = marsio_open_device(handle->mr_ins, opts->dev_symbol, opts->nr_threads, opts->nr_threads);
if (handle->mr_dev == NULL) if (handle->mr_dev == NULL)
{ {
PACKET_IO_LOG_ERROR("unable to open marsio device"); PACKET_IO_LOG_ERROR("unable to open marsio device");

View File

@@ -8,7 +8,7 @@ extern "C"
#include "packet.h" #include "packet.h"
struct packet_io_marsio_confg struct packet_io_marsio_opts
{ {
char app_symbol[64]; char app_symbol[64];
char dev_symbol[64]; char dev_symbol[64];
@@ -18,7 +18,7 @@ struct packet_io_marsio_confg
struct packet_io_marsio; struct packet_io_marsio;
struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_confg *config); struct packet_io_marsio *packet_io_marsio_new(struct packet_io_marsio_opts *opts);
void packet_io_marsio_free(struct packet_io_marsio *handle); void packet_io_marsio_free(struct packet_io_marsio *handle);
struct packet_io_stat *packet_io_marsio_stat(struct packet_io_marsio *handle); struct packet_io_stat *packet_io_marsio_stat(struct packet_io_marsio *handle);

View File

@@ -27,7 +27,7 @@ struct session_manager
struct dupkt_filter *tcp_dupkt_filter; struct dupkt_filter *tcp_dupkt_filter;
struct eviction_filter *udp_eviction_filter; struct eviction_filter *udp_eviction_filter;
struct session_manager_config config; struct session_manager_options opts;
/*************************************************************** /***************************************************************
* session manager status * session manager status
@@ -66,7 +66,7 @@ static inline void tcp_half_closed_timeout_cb(struct session *sess, void *arg);
static inline void tcp_time_wait_timeout_cb(struct session *sess, void *arg); static inline void tcp_time_wait_timeout_cb(struct session *sess, void *arg);
static inline void udp_data_timeout_cb(struct session *sess, void *arg); static inline void udp_data_timeout_cb(struct session *sess, void *arg);
static inline int session_manager_check_config(struct session_manager_config *config); static inline int session_manager_check_options(struct session_manager_options *opts);
static inline uint64_t session_manager_alloc_session_id(void); static inline uint64_t session_manager_alloc_session_id(void);
static inline int session_manager_update_tcp_filter(struct session_manager *mgr, struct session *sess, const struct packet *pkt, enum session_dir curr_dir); static inline int session_manager_update_tcp_filter(struct session_manager *mgr, struct session *sess, const struct packet *pkt, enum session_dir curr_dir);
@@ -181,123 +181,123 @@ static inline void udp_data_timeout_cb(struct session *sess, void *arg)
} }
// return 0: success // return 0: success
// return -1: invalid config // return -1: invalid opts
static inline int session_manager_check_config(struct session_manager_config *config) static inline int session_manager_check_options(struct session_manager_options *opts)
{ {
if (config == NULL) if (opts == NULL)
{ {
SESSION_LOG_ERROR("invalid config"); SESSION_LOG_ERROR("invalid opts");
return -1; return -1;
} }
// max session number // max session number
if (config->max_tcp_session_num < 2) if (opts->max_tcp_session_num < 2)
{ {
SESSION_LOG_ERROR("invalid max tcp session number"); SESSION_LOG_ERROR("invalid max tcp session number");
return -1; return -1;
} }
if (config->max_udp_session_num < 2) if (opts->max_udp_session_num < 2)
{ {
SESSION_LOG_ERROR("invalid max udp session number"); SESSION_LOG_ERROR("invalid max udp session number");
return -1; return -1;
} }
// session overload // session overload
if (config->tcp_overload_evict_old_sess != 0 && config->tcp_overload_evict_old_sess != 1) if (opts->tcp_overload_evict_old_sess != 0 && opts->tcp_overload_evict_old_sess != 1)
{ {
SESSION_LOG_ERROR("invalid tcp overload evict old session, support range: 0-1"); SESSION_LOG_ERROR("invalid tcp overload evict old session, support range: 0-1");
return -1; return -1;
} }
if (config->udp_overload_evict_old_sess != 0 && config->udp_overload_evict_old_sess != 1) if (opts->udp_overload_evict_old_sess != 0 && opts->udp_overload_evict_old_sess != 1)
{ {
SESSION_LOG_ERROR("invalid udp overload evict old session, support range: 0-1"); SESSION_LOG_ERROR("invalid udp overload evict old session, support range: 0-1");
return -1; return -1;
} }
// TCP timeout config // TCP timeout opts
if (config->tcp_timeout_init < 1 || config->tcp_timeout_init > 60) if (opts->tcp_timeout_init < 1 || opts->tcp_timeout_init > 60)
{ {
SESSION_LOG_ERROR("invalid tcp timeout init, support range: 1-60"); SESSION_LOG_ERROR("invalid tcp timeout init, support range: 1-60");
return -1; return -1;
} }
if (config->tcp_timeout_handshake < 1 || config->tcp_timeout_handshake > 60) if (opts->tcp_timeout_handshake < 1 || opts->tcp_timeout_handshake > 60)
{ {
SESSION_LOG_ERROR("invalid tcp timeout handshake, support range: 1-60"); SESSION_LOG_ERROR("invalid tcp timeout handshake, support range: 1-60");
return -1; return -1;
} }
if (config->tcp_timeout_data < 1 || config->tcp_timeout_data > 15999999) if (opts->tcp_timeout_data < 1 || opts->tcp_timeout_data > 15999999)
{ {
SESSION_LOG_ERROR("invalid tcp timeout data, support range: 1-15,999,999"); SESSION_LOG_ERROR("invalid tcp timeout data, support range: 1-15,999,999");
return -1; return -1;
} }
if (config->tcp_timeout_half_closed < 1 || config->tcp_timeout_half_closed > 604800) if (opts->tcp_timeout_half_closed < 1 || opts->tcp_timeout_half_closed > 604800)
{ {
SESSION_LOG_ERROR("invalid tcp timeout half closed, support range: 1-604,800"); SESSION_LOG_ERROR("invalid tcp timeout half closed, support range: 1-604,800");
return -1; return -1;
} }
if (config->tcp_timeout_time_wait < 1 || config->tcp_timeout_time_wait > 600) if (opts->tcp_timeout_time_wait < 1 || opts->tcp_timeout_time_wait > 600)
{ {
SESSION_LOG_ERROR("invalid tcp timeout time wait, support range: 1-600"); SESSION_LOG_ERROR("invalid tcp timeout time wait, support range: 1-600");
return -1; return -1;
} }
if (config->tcp_timeout_discard < 1 || config->tcp_timeout_discard > 15999999) if (opts->tcp_timeout_discard < 1 || opts->tcp_timeout_discard > 15999999)
{ {
SESSION_LOG_ERROR("invalid tcp timeout discard, support range: 1-15,999,999"); SESSION_LOG_ERROR("invalid tcp timeout discard, support range: 1-15,999,999");
return -1; return -1;
} }
// UDP timeout config // UDP timeout opts
if (config->udp_timeout_data < 1 || config->udp_timeout_data > 15999999) if (opts->udp_timeout_data < 1 || opts->udp_timeout_data > 15999999)
{ {
SESSION_LOG_ERROR("invalid udp timeout data, support range: 1-15,999,999"); SESSION_LOG_ERROR("invalid udp timeout data, support range: 1-15,999,999");
return -1; return -1;
} }
// TCP duplicate packet filter config // TCP duplicate packet filter opts
if (config->tcp_dupkt_filter_enable != 0 && config->tcp_dupkt_filter_enable != 1) if (opts->tcp_dupkt_filter_enable != 0 && opts->tcp_dupkt_filter_enable != 1)
{ {
SESSION_LOG_ERROR("invalid tcp dupkt filter enable, support range: 0-1"); SESSION_LOG_ERROR("invalid tcp dupkt filter enable, support range: 0-1");
return -1; return -1;
} }
if (config->tcp_dupkt_filter_enable) if (opts->tcp_dupkt_filter_enable)
{ {
if (config->tcp_dupkt_filter_capacity == 0) if (opts->tcp_dupkt_filter_capacity == 0)
{ {
SESSION_LOG_ERROR("invalid tcp dupkt filter capacity"); SESSION_LOG_ERROR("invalid tcp dupkt filter capacity");
return -1; return -1;
} }
if (config->tcp_dupkt_filter_timeout < 1 || config->tcp_dupkt_filter_timeout > 60) if (opts->tcp_dupkt_filter_timeout < 1 || opts->tcp_dupkt_filter_timeout > 60)
{ {
SESSION_LOG_ERROR("invalid tcp dupkt filter timeout, support range: 1-60"); SESSION_LOG_ERROR("invalid tcp dupkt filter timeout, support range: 1-60");
return -1; return -1;
} }
if (config->tcp_dupkt_filter_error_rate < 0 || config->tcp_dupkt_filter_error_rate > 1) if (opts->tcp_dupkt_filter_error_rate < 0 || opts->tcp_dupkt_filter_error_rate > 1)
{ {
SESSION_LOG_ERROR("invalid tcp dupkt filter error rate, support range: 0-1"); SESSION_LOG_ERROR("invalid tcp dupkt filter error rate, support range: 0-1");
return -1; return -1;
} }
} }
// UDP eviction filter config // UDP eviction filter opts
if (config->udp_eviction_filter_enable != 0 && config->udp_eviction_filter_enable != 1) if (opts->udp_eviction_filter_enable != 0 && opts->udp_eviction_filter_enable != 1)
{ {
SESSION_LOG_ERROR("invalid udp eviction filter enable, support range: 0-1"); SESSION_LOG_ERROR("invalid udp eviction filter enable, support range: 0-1");
return -1; return -1;
} }
if (config->udp_eviction_filter_enable) if (opts->udp_eviction_filter_enable)
{ {
if (config->udp_eviction_filter_capacity == 0) if (opts->udp_eviction_filter_capacity == 0)
{ {
SESSION_LOG_ERROR("invalid udp eviction filter capacity"); SESSION_LOG_ERROR("invalid udp eviction filter capacity");
return -1; return -1;
} }
if (config->udp_eviction_filter_timeout < 1 || config->udp_eviction_filter_timeout > 60) if (opts->udp_eviction_filter_timeout < 1 || opts->udp_eviction_filter_timeout > 60)
{ {
SESSION_LOG_ERROR("invalid udp eviction filter timeout, support range: 1-60"); SESSION_LOG_ERROR("invalid udp eviction filter timeout, support range: 1-60");
return -1; return -1;
} }
if (config->udp_eviction_filter_error_rate < 0 || config->udp_eviction_filter_error_rate > 1) if (opts->udp_eviction_filter_error_rate < 0 || opts->udp_eviction_filter_error_rate > 1)
{ {
SESSION_LOG_ERROR("invalid udp eviction filter error rate, support range: 0-1"); SESSION_LOG_ERROR("invalid udp eviction filter error rate, support range: 0-1");
return -1; return -1;
@@ -633,13 +633,13 @@ static inline void session_manager_update_session_packet(struct session_manager
static inline void session_manager_update_udp_to_opening(struct session_manager *mgr, struct session *sess) static inline void session_manager_update_udp_to_opening(struct session_manager *mgr, struct session *sess)
{ {
session_manager_update_session_state(mgr, sess, SESSION_STATE_OPENING); session_manager_update_session_state(mgr, sess, SESSION_STATE_OPENING);
session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->config.udp_timeout_data); session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->opts.udp_timeout_data);
} }
static inline void session_manager_update_udp_to_active(struct session_manager *mgr, struct session *sess) static inline void session_manager_update_udp_to_active(struct session_manager *mgr, struct session *sess)
{ {
session_manager_update_session_state(mgr, sess, SESSION_STATE_ACTIVE); session_manager_update_session_state(mgr, sess, SESSION_STATE_ACTIVE);
session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->config.udp_timeout_data); session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->opts.udp_timeout_data);
} }
static inline void session_manager_update_udp_to_closing(struct session_manager *mgr, struct session *sess) static inline void session_manager_update_udp_to_closing(struct session_manager *mgr, struct session *sess)
@@ -655,18 +655,18 @@ static inline void session_manager_update_tcp_to_opening(struct session_manager
session_manager_update_session_state(mgr, sess, SESSION_STATE_OPENING); session_manager_update_session_state(mgr, sess, SESSION_STATE_OPENING);
if (opening_by_syn) if (opening_by_syn)
{ {
session_manager_update_session_timer(mgr, sess, tcp_init_timeout_cb, mgr->config.tcp_timeout_init); session_manager_update_session_timer(mgr, sess, tcp_init_timeout_cb, mgr->opts.tcp_timeout_init);
} }
else else
{ {
session_manager_update_session_timer(mgr, sess, tcp_handshake_timeout_cb, mgr->config.tcp_timeout_handshake); session_manager_update_session_timer(mgr, sess, tcp_handshake_timeout_cb, mgr->opts.tcp_timeout_handshake);
} }
} }
static inline void session_manager_update_tcp_to_active(struct session_manager *mgr, struct session *sess) static inline void session_manager_update_tcp_to_active(struct session_manager *mgr, struct session *sess)
{ {
session_manager_update_session_state(mgr, sess, SESSION_STATE_ACTIVE); session_manager_update_session_state(mgr, sess, SESSION_STATE_ACTIVE);
session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->config.tcp_timeout_data); session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->opts.tcp_timeout_data);
} }
static inline void session_manager_update_tcp_to_closing(struct session_manager *mgr, struct session *sess, int enable_time_wait) static inline void session_manager_update_tcp_to_closing(struct session_manager *mgr, struct session *sess, int enable_time_wait)
@@ -674,7 +674,7 @@ static inline void session_manager_update_tcp_to_closing(struct session_manager
session_manager_update_session_state(mgr, sess, SESSION_STATE_CLOSING); session_manager_update_session_state(mgr, sess, SESSION_STATE_CLOSING);
if (enable_time_wait) if (enable_time_wait)
{ {
session_manager_update_session_timer(mgr, sess, tcp_time_wait_timeout_cb, mgr->config.tcp_timeout_time_wait); session_manager_update_session_timer(mgr, sess, tcp_time_wait_timeout_cb, mgr->opts.tcp_timeout_time_wait);
} }
else else
{ {
@@ -724,7 +724,7 @@ static inline void session_manager_handle_tcp_on_opening(struct session_manager
SESSION_LOG_DEBUG("TCP %s FIN received, session %lu opening -> opening", (tcp_curr_state & TCP_C2S_FIN_RECVED ? "C2S" : "S2C"), session_get_id(sess)); SESSION_LOG_DEBUG("TCP %s FIN received, session %lu opening -> opening", (tcp_curr_state & TCP_C2S_FIN_RECVED ? "C2S" : "S2C"), session_get_id(sess));
// still opening, only update timeout // still opening, only update timeout
session_set_closing_reason(sess, (tcp_mod_state & TCP_C2S_FIN_RECVED) ? CLOSING_BY_CLIENT_FIN : CLOSING_BY_SERVER_FIN); session_set_closing_reason(sess, (tcp_mod_state & TCP_C2S_FIN_RECVED) ? CLOSING_BY_CLIENT_FIN : CLOSING_BY_SERVER_FIN);
session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->config.tcp_timeout_half_closed); session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->opts.tcp_timeout_half_closed);
return; return;
} }
@@ -732,7 +732,7 @@ static inline void session_manager_handle_tcp_on_opening(struct session_manager
{ {
SESSION_LOG_DEBUG("TCP %s ACK received, session %lu opening -> opening", (tcp_curr_state & TCP_C2S_ACK_RECVED ? "C2S" : "S2C"), session_get_id(sess)); SESSION_LOG_DEBUG("TCP %s ACK received, session %lu opening -> opening", (tcp_curr_state & TCP_C2S_ACK_RECVED ? "C2S" : "S2C"), session_get_id(sess));
// still opening, only update timeout // still opening, only update timeout
session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->config.tcp_timeout_data); session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->opts.tcp_timeout_data);
return; return;
} }
@@ -783,7 +783,7 @@ static inline void session_manager_handle_tcp_on_active(struct session_manager *
SESSION_LOG_DEBUG("TCP %s FIN received, session %lu active -> active", (tcp_curr_state & TCP_C2S_FIN_RECVED) ? "C2S" : "S2C", session_get_id(sess)); SESSION_LOG_DEBUG("TCP %s FIN received, session %lu active -> active", (tcp_curr_state & TCP_C2S_FIN_RECVED) ? "C2S" : "S2C", session_get_id(sess));
// still active // still active
session_set_closing_reason(sess, (tcp_curr_state & TCP_C2S_FIN_RECVED) ? CLOSING_BY_CLIENT_FIN : CLOSING_BY_SERVER_FIN); session_set_closing_reason(sess, (tcp_curr_state & TCP_C2S_FIN_RECVED) ? CLOSING_BY_CLIENT_FIN : CLOSING_BY_SERVER_FIN);
session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->config.tcp_timeout_half_closed); session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->opts.tcp_timeout_half_closed);
return; return;
} }
@@ -815,9 +815,9 @@ static inline struct session *session_manager_new_tcp_session(struct session_man
return NULL; return NULL;
} }
if (mgr->tcp_sess_num >= mgr->config.max_tcp_session_num - 1) if (mgr->tcp_sess_num >= mgr->opts.max_tcp_session_num - 1)
{ {
if (mgr->config.tcp_overload_evict_old_sess) if (mgr->opts.tcp_overload_evict_old_sess)
{ {
struct session *evicted_sess = session_table_find_least_recently_unused_session(mgr->tcp_sess_table); struct session *evicted_sess = session_table_find_least_recently_unused_session(mgr->tcp_sess_table);
assert(evicted_sess); assert(evicted_sess);
@@ -826,7 +826,7 @@ static inline struct session *session_manager_new_tcp_session(struct session_man
} }
else else
{ {
if (mgr->tcp_sess_num >= mgr->config.max_tcp_session_num) if (mgr->tcp_sess_num >= mgr->opts.max_tcp_session_num)
{ {
mgr->tcp_overload_evict_new_sess_num++; mgr->tcp_overload_evict_new_sess_num++;
return NULL; return NULL;
@@ -866,9 +866,9 @@ static inline struct session *session_manager_new_udp_session(struct session_man
return NULL; return NULL;
} }
if (mgr->udp_sess_num >= mgr->config.max_udp_session_num - 1) if (mgr->udp_sess_num >= mgr->opts.max_udp_session_num - 1)
{ {
if (mgr->config.udp_overload_evict_old_sess) if (mgr->opts.udp_overload_evict_old_sess)
{ {
struct session *evicted_sess = session_table_find_least_recently_unused_session(mgr->udp_sess_table); struct session *evicted_sess = session_table_find_least_recently_unused_session(mgr->udp_sess_table);
assert(evicted_sess); assert(evicted_sess);
@@ -877,7 +877,7 @@ static inline struct session *session_manager_new_udp_session(struct session_man
} }
else else
{ {
if (mgr->udp_sess_num >= mgr->config.max_udp_session_num) if (mgr->udp_sess_num >= mgr->opts.max_udp_session_num)
{ {
mgr->udp_overload_evict_new_sess_num++; mgr->udp_overload_evict_new_sess_num++;
return NULL; return NULL;
@@ -1029,9 +1029,9 @@ static inline void session_manager_evicte_session(struct session_manager *mgr, s
* Public API * Public API
******************************************************************************/ ******************************************************************************/
struct session_manager *session_manager_new(struct session_manager_config *config) struct session_manager *session_manager_new(struct session_manager_options *opts)
{ {
if (session_manager_check_config(config)) if (session_manager_check_options(opts))
{ {
return NULL; return NULL;
} }
@@ -1042,8 +1042,8 @@ struct session_manager *session_manager_new(struct session_manager_config *confi
return NULL; return NULL;
} }
memcpy(&mgr->config, config, sizeof(struct session_manager_config)); memcpy(&mgr->opts, opts, sizeof(struct session_manager_options));
mgr->sess_pool = session_pool_new(mgr->config.max_tcp_session_num + mgr->config.max_udp_session_num); mgr->sess_pool = session_pool_new(mgr->opts.max_tcp_session_num + mgr->opts.max_udp_session_num);
if (mgr->sess_pool == NULL) if (mgr->sess_pool == NULL)
{ {
goto error; goto error;
@@ -1079,13 +1079,13 @@ struct session_manager *session_manager_new(struct session_manager_config *confi
goto error; goto error;
} }
mgr->tcp_dupkt_filter = dupkt_filter_new(mgr->config.tcp_dupkt_filter_enable, mgr->config.tcp_dupkt_filter_capacity, mgr->config.tcp_dupkt_filter_error_rate, mgr->config.tcp_dupkt_filter_timeout); mgr->tcp_dupkt_filter = dupkt_filter_new(mgr->opts.tcp_dupkt_filter_enable, mgr->opts.tcp_dupkt_filter_capacity, mgr->opts.tcp_dupkt_filter_error_rate, mgr->opts.tcp_dupkt_filter_timeout);
if (mgr->tcp_dupkt_filter == NULL) if (mgr->tcp_dupkt_filter == NULL)
{ {
goto error; goto error;
} }
mgr->udp_eviction_filter = eviction_filter_new(mgr->config.udp_eviction_filter_enable, mgr->config.udp_eviction_filter_capacity, mgr->config.udp_eviction_filter_error_rate, mgr->config.udp_eviction_filter_timeout); mgr->udp_eviction_filter = eviction_filter_new(mgr->opts.udp_eviction_filter_enable, mgr->opts.udp_eviction_filter_capacity, mgr->opts.udp_eviction_filter_error_rate, mgr->opts.udp_eviction_filter_timeout);
if (mgr->udp_eviction_filter == NULL) if (mgr->udp_eviction_filter == NULL)
{ {
goto error; goto error;

View File

@@ -12,7 +12,7 @@ extern "C"
#define SESSION_LOG_ERROR(format, ...) LOG_ERROR("session", format, ##__VA_ARGS__) #define SESSION_LOG_ERROR(format, ...) LOG_ERROR("session", format, ##__VA_ARGS__)
#define SESSION_LOG_DEBUG(format, ...) LOG_DEBUG("session", format, ##__VA_ARGS__) #define SESSION_LOG_DEBUG(format, ...) LOG_DEBUG("session", format, ##__VA_ARGS__)
struct session_manager_config struct session_manager_options
{ {
// max session number // max session number
uint64_t max_tcp_session_num; uint64_t max_tcp_session_num;
@@ -47,7 +47,7 @@ struct session_manager_config
}; };
struct session_manager; struct session_manager;
struct session_manager *session_manager_new(struct session_manager_config *config); struct session_manager *session_manager_new(struct session_manager_options *opts);
void session_manager_free(struct session_manager *mgr); void session_manager_free(struct session_manager *mgr);
// only use the packet six-tuple to find the session, not update it // only use the packet six-tuple to find the session, not update it

View File

@@ -9,7 +9,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SYN_DUP)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -61,7 +61,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, S2C_DUP)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// S2C SYNACK Packet // S2C SYNACK Packet
@@ -116,7 +116,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SKIP_FILTER)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -178,13 +178,13 @@ TEST(TCP_DUPKT_FILTER_DISABLE, C2S_DUPKT)
struct packet pkt; struct packet pkt;
struct session *sess = NULL; struct session *sess = NULL;
struct session_manager *mgr = NULL; struct session_manager *mgr = NULL;
struct session_manager_config _config; struct session_manager_options _opts;
memcpy(&_config, &config, sizeof(struct session_manager_config)); memcpy(&_opts, &opts, sizeof(struct session_manager_options));
_config.tcp_dupkt_filter_enable = 0; _opts.tcp_dupkt_filter_enable = 0;
timestamp_update(); timestamp_update();
mgr = session_manager_new(&_config); mgr = session_manager_new(&_opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -233,13 +233,13 @@ TEST(TCP_DUPKT_FILTER_DISABLE, S2C_DUP)
struct packet pkt; struct packet pkt;
struct session *sess = NULL; struct session *sess = NULL;
struct session_manager *mgr = NULL; struct session_manager *mgr = NULL;
struct session_manager_config _config; struct session_manager_options _opts;
memcpy(&_config, &config, sizeof(struct session_manager_config)); memcpy(&_opts, &opts, sizeof(struct session_manager_options));
_config.tcp_dupkt_filter_enable = 0; _opts.tcp_dupkt_filter_enable = 0;
timestamp_update(); timestamp_update();
mgr = session_manager_new(&_config); mgr = session_manager_new(&_opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// S2C SYNACK Packet // S2C SYNACK Packet

View File

@@ -9,7 +9,7 @@ TEST(UDP_EVICTION_FILTER_ENABLE, HIT_FILTER_THEN_EVICT_SESS)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S REQ Packet // C2S REQ Packet
@@ -43,13 +43,13 @@ TEST(UDP_EVICTION_FILTER_ENABLE, MISS_FILTER_THEN_NEW_SESS)
struct packet pkt; struct packet pkt;
struct session *sess = NULL; struct session *sess = NULL;
struct session_manager *mgr = NULL; struct session_manager *mgr = NULL;
struct session_manager_config _config; struct session_manager_options _opts;
memcpy(&_config, &config, sizeof(struct session_manager_config)); memcpy(&_opts, &opts, sizeof(struct session_manager_options));
_config.udp_eviction_filter_timeout = 2; _opts.udp_eviction_filter_timeout = 2;
timestamp_update(); timestamp_update();
mgr = session_manager_new(&_config); mgr = session_manager_new(&_opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S REQ Packet // C2S REQ Packet
@@ -66,7 +66,7 @@ TEST(UDP_EVICTION_FILTER_ENABLE, MISS_FILTER_THEN_NEW_SESS)
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// wait udp eviction filter timeout // wait udp eviction filter timeout
sleep(_config.udp_eviction_filter_timeout); sleep(_opts.udp_eviction_filter_timeout);
timestamp_update(); timestamp_update();
// C2S REQ Packet // C2S REQ Packet
@@ -91,13 +91,13 @@ TEST(UDP_EVICTION_FILTER_DISABLE, MISS_FILTER_THEN_NEW_SESS)
struct packet pkt; struct packet pkt;
struct session *sess = NULL; struct session *sess = NULL;
struct session_manager *mgr = NULL; struct session_manager *mgr = NULL;
struct session_manager_config _config; struct session_manager_options _opts;
memcpy(&_config, &config, sizeof(struct session_manager_config)); memcpy(&_opts, &opts, sizeof(struct session_manager_options));
_config.udp_eviction_filter_enable = 0; _opts.udp_eviction_filter_enable = 0;
timestamp_update(); timestamp_update();
mgr = session_manager_new(&_config); mgr = session_manager_new(&_opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S REQ Packet // C2S REQ Packet

View File

@@ -19,10 +19,10 @@ TEST(OVERLOAD, EVICT_TCP_OLD_SESS)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
for (uint64_t i = 0; i < config.max_tcp_session_num; i++) for (uint64_t i = 0; i < opts.max_tcp_session_num; i++)
{ {
// C2S SYN Packet // C2S SYN Packet
printf("\n====================== new session (%lu) ======================\n\n", i + 1); printf("\n====================== new session (%lu) ======================\n\n", i + 1);
@@ -37,7 +37,7 @@ TEST(OVERLOAD, EVICT_TCP_OLD_SESS)
__session_dispatch(sess); __session_dispatch(sess);
session_manager_print_stat(mgr); session_manager_print_stat(mgr);
if (i == config.max_tcp_session_num - 1) if (i == opts.max_tcp_session_num - 1)
{ {
__session_manager_check_counter(mgr, __session_manager_check_counter(mgr,
i, 0, 1, // tcp_opening_sess_num, tcp_active_sess_num, tcp_closing_sess_num, i, 0, 1, // tcp_opening_sess_num, tcp_active_sess_num, tcp_closing_sess_num,
@@ -91,16 +91,16 @@ TEST(OVERLOAD, EVICT_TCP_NEW_SESS)
struct session *sess = NULL; struct session *sess = NULL;
struct session_manager *mgr = NULL; struct session_manager *mgr = NULL;
char buffer[1500] = {0}; char buffer[1500] = {0};
struct session_manager_config _config; struct session_manager_options _opts;
memcpy(&_config, &config, sizeof(struct session_manager_config)); memcpy(&_opts, &opts, sizeof(struct session_manager_options));
_config.tcp_overload_evict_old_sess = 0; _opts.tcp_overload_evict_old_sess = 0;
timestamp_update(); timestamp_update();
mgr = session_manager_new(&_config); mgr = session_manager_new(&_opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
for (uint64_t i = 0; i <= _config.max_tcp_session_num; i++) for (uint64_t i = 0; i <= _opts.max_tcp_session_num; i++)
{ {
// C2S SYN Packet // C2S SYN Packet
printf("\n====================== new session (%lu) ======================\n\n", i + 1); printf("\n====================== new session (%lu) ======================\n\n", i + 1);
@@ -111,7 +111,7 @@ TEST(OVERLOAD, EVICT_TCP_NEW_SESS)
printf("<= packet parse\n\n"); printf("<= packet parse\n\n");
sess = session_manager_update_session(mgr, &pkt); sess = session_manager_update_session(mgr, &pkt);
if (i == _config.max_tcp_session_num) if (i == _opts.max_tcp_session_num)
{ {
EXPECT_TRUE(sess == NULL); EXPECT_TRUE(sess == NULL);
__session_manager_check_counter(mgr, __session_manager_check_counter(mgr,

View File

@@ -19,10 +19,10 @@ TEST(OVERLOAD, EVICT_UDP_OLD_SESS)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
for (uint64_t i = 0; i < config.max_udp_session_num; i++) for (uint64_t i = 0; i < opts.max_udp_session_num; i++)
{ {
// C2S REQ Packet // C2S REQ Packet
printf("\n====================== new session (%lu) ======================\n\n", i + 1); printf("\n====================== new session (%lu) ======================\n\n", i + 1);
@@ -37,7 +37,7 @@ TEST(OVERLOAD, EVICT_UDP_OLD_SESS)
__session_dispatch(sess); __session_dispatch(sess);
session_manager_print_stat(mgr); session_manager_print_stat(mgr);
if (i == config.max_udp_session_num - 1) if (i == opts.max_udp_session_num - 1)
{ {
__session_manager_check_counter(mgr, __session_manager_check_counter(mgr,
0, 0, 0, // tcp_opening_sess_num, tcp_active_sess_num, tcp_closing_sess_num, 0, 0, 0, // tcp_opening_sess_num, tcp_active_sess_num, tcp_closing_sess_num,
@@ -91,16 +91,16 @@ TEST(OVERLOAD, EVICT_UDP_NEW_SESS)
struct session *sess = NULL; struct session *sess = NULL;
struct session_manager *mgr = NULL; struct session_manager *mgr = NULL;
char buffer[1500] = {0}; char buffer[1500] = {0};
struct session_manager_config _config; struct session_manager_options _opts;
memcpy(&_config, &config, sizeof(struct session_manager_config)); memcpy(&_opts, &opts, sizeof(struct session_manager_options));
_config.udp_overload_evict_old_sess = 0; _opts.udp_overload_evict_old_sess = 0;
timestamp_update(); timestamp_update();
mgr = session_manager_new(&_config); mgr = session_manager_new(&_opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
for (uint64_t i = 0; i <= _config.max_udp_session_num; i++) for (uint64_t i = 0; i <= _opts.max_udp_session_num; i++)
{ {
// C2S REQ Packet // C2S REQ Packet
printf("\n====================== new session (%lu) ======================\n\n", i + 1); printf("\n====================== new session (%lu) ======================\n\n", i + 1);
@@ -111,7 +111,7 @@ TEST(OVERLOAD, EVICT_UDP_NEW_SESS)
printf("<= packet parse\n\n"); printf("<= packet parse\n\n");
sess = session_manager_update_session(mgr, &pkt); sess = session_manager_update_session(mgr, &pkt);
if (i == _config.max_udp_session_num) if (i == _opts.max_udp_session_num)
{ {
EXPECT_TRUE(sess == NULL); EXPECT_TRUE(sess == NULL);
__session_manager_check_counter(mgr, __session_manager_check_counter(mgr,

View File

@@ -91,7 +91,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_FIN_FIN)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet & C2S DATA Packet // C2S SYN Packet & C2S DATA Packet
@@ -182,7 +182,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_RST)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet & C2S DATA Packet // C2S SYN Packet & C2S DATA Packet
@@ -246,7 +246,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_RST)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet & C2S DATA Packet // C2S SYN Packet & C2S DATA Packet
@@ -308,7 +308,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_DATA_TIMEOUT)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet & C2S DATA Packet // C2S SYN Packet & C2S DATA Packet
@@ -336,7 +336,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_HALF_CLOSED_TIMEOUT)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet & C2S DATA Packet // C2S SYN Packet & C2S DATA Packet
@@ -393,7 +393,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_HALF_CLOSED_TIMEOUT)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet & C2S DATA Packet // C2S SYN Packet & C2S DATA Packet

View File

@@ -16,7 +16,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -71,7 +71,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// SYNACK Packet // SYNACK Packet
@@ -126,7 +126,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -216,7 +216,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK_ACK)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -342,7 +342,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_RETRANSMISSION)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -440,7 +440,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK_RETRANSMISSION)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// SYNACK Packet // SYNACK Packet
@@ -536,7 +536,7 @@ TEST(TCP_INIT_TO_OPENING, BY_C2S_ASMMETRIC)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -626,7 +626,7 @@ TEST(TCP_INIT_TO_OPENING, BY_S2C_ASMMETRIC)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// SYNACK Packet // SYNACK Packet

View File

@@ -12,7 +12,7 @@ TEST(TCP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING_TO_CLOSED, TEST)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet

View File

@@ -16,7 +16,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYN_C2S_DATA)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -105,7 +105,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYNACK_S2C_DATA)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// SYNACK Packet // SYNACK Packet

View File

@@ -57,7 +57,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_FIN_FIN)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -148,7 +148,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_RST)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -212,7 +212,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_RST)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -274,7 +274,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_INIT_TIMEOUT)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -302,7 +302,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_HANDSHAKE_TIMEOUT)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -360,7 +360,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_DATA_TIMEOUT)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -452,7 +452,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_HALF_CLOSED_TIMEOUT)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -509,7 +509,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_HALF_CLOSED_TIMEOUT)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet

View File

@@ -20,7 +20,7 @@ TEST(UDP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING, TEST)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S REQ Packet // C2S REQ Packet

View File

@@ -18,7 +18,7 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_C2S)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S REQ Packet // C2S REQ Packet
@@ -75,7 +75,7 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_S2C)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// S2C RESP Packet // S2C RESP Packet

View File

@@ -9,7 +9,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_DATA)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -28,8 +28,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_DATA)
__session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
__session_manager_check_tcp_timeout_data(mgr, &config); __session_manager_check_tcp_timeout_data(mgr, &opts);
__session_manager_check_tcp_timeout_time_wait(mgr, &config); __session_manager_check_tcp_timeout_time_wait(mgr, &opts);
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

View File

@@ -9,7 +9,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_HALF_CLOSED1)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -28,8 +28,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_HALF_CLOSED1)
__session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
__session_manager_check_tcp_timeout_half_closed(mgr, &config, SESSION_STATE_OPENING); __session_manager_check_tcp_timeout_half_closed(mgr, &opts, SESSION_STATE_OPENING);
__session_manager_check_tcp_timeout_time_wait(mgr, &config); __session_manager_check_tcp_timeout_time_wait(mgr, &opts);
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
@@ -46,7 +46,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_HALF_CLOSED2)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -72,8 +72,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_HALF_CLOSED2)
__session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
__session_manager_check_tcp_timeout_half_closed(mgr, &config, SESSION_STATE_ACTIVE); __session_manager_check_tcp_timeout_half_closed(mgr, &opts, SESSION_STATE_ACTIVE);
__session_manager_check_tcp_timeout_time_wait(mgr, &config); __session_manager_check_tcp_timeout_time_wait(mgr, &opts);
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

View File

@@ -9,7 +9,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_HANDSHAKE)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// SYNACK Packet // SYNACK Packet
@@ -21,8 +21,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_HANDSHAKE)
__session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
__session_manager_check_tcp_timeout_handshake(mgr, &config); __session_manager_check_tcp_timeout_handshake(mgr, &opts);
__session_manager_check_tcp_timeout_time_wait(mgr, &config); __session_manager_check_tcp_timeout_time_wait(mgr, &opts);
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

View File

@@ -9,7 +9,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT1)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S SYN Packet // C2S SYN Packet
@@ -21,8 +21,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT1)
__session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
__session_manager_check_tcp_timeout_init(mgr, &config); __session_manager_check_tcp_timeout_init(mgr, &opts);
__session_manager_check_tcp_timeout_time_wait(mgr, &config); __session_manager_check_tcp_timeout_time_wait(mgr, &opts);
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
@@ -39,7 +39,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT2)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// S2C SYNACK Packet // S2C SYNACK Packet
@@ -51,8 +51,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT2)
__session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
__session_manager_check_tcp_timeout_init(mgr, &config); __session_manager_check_tcp_timeout_init(mgr, &opts);
__session_manager_check_tcp_timeout_time_wait(mgr, &config); __session_manager_check_tcp_timeout_time_wait(mgr, &opts);
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

View File

@@ -9,7 +9,7 @@ TEST(TIMEOUT, UDP_TIMEOUT_DATA1)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S REQ Packet // C2S REQ Packet
@@ -21,7 +21,7 @@ TEST(TIMEOUT, UDP_TIMEOUT_DATA1)
__session_manager_check_counter(mgr, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0);
__session_manager_check_udp_timeout_data(mgr, &config, SESSION_STATE_OPENING); __session_manager_check_udp_timeout_data(mgr, &opts, SESSION_STATE_OPENING);
EXPECT_TRUE(session_manager_get_expired_session(mgr) == NULL); EXPECT_TRUE(session_manager_get_expired_session(mgr) == NULL);
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
@@ -39,7 +39,7 @@ TEST(TIMEOUT, UDP_TIMEOUT_DATA2)
timestamp_update(); timestamp_update();
mgr = session_manager_new(&config); mgr = session_manager_new(&opts);
EXPECT_TRUE(mgr != NULL); EXPECT_TRUE(mgr != NULL);
// C2S REQ Packet // C2S REQ Packet
@@ -58,7 +58,7 @@ TEST(TIMEOUT, UDP_TIMEOUT_DATA2)
__session_manager_check_counter(mgr, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0);
__session_manager_check_udp_timeout_data(mgr, &config, SESSION_STATE_ACTIVE); __session_manager_check_udp_timeout_data(mgr, &opts, SESSION_STATE_ACTIVE);
EXPECT_TRUE(session_manager_get_expired_session(mgr) == NULL); EXPECT_TRUE(session_manager_get_expired_session(mgr) == NULL);
__session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

View File

@@ -15,7 +15,7 @@ extern "C"
#include "ipv4_utils.h" #include "ipv4_utils.h"
#include "test_packets.h" #include "test_packets.h"
struct session_manager_config config = { struct session_manager_options opts = {
// max session number // max session number
.max_tcp_session_num = 3, .max_tcp_session_num = 3,
.max_udp_session_num = 3, .max_udp_session_num = 3,
@@ -112,20 +112,20 @@ __attribute__((unused)) static void __session_manager_check_counter(struct sessi
EXPECT_TRUE(counter.udp_overload_evict_old_sess_num == udp_overload_evict_old_sess_num); EXPECT_TRUE(counter.udp_overload_evict_old_sess_num == udp_overload_evict_old_sess_num);
} }
__attribute__((unused)) static void __session_manager_check_tcp_timeout_init(struct session_manager *mgr, struct session_manager_config *config) __attribute__((unused)) static void __session_manager_check_tcp_timeout_init(struct session_manager *mgr, struct session_manager_options *opts)
{ {
struct session *sess; struct session *sess;
uint64_t interval; uint64_t interval;
uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_init; uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_init;
printf("\n=> tcp_timeout_init\n"); printf("\n=> tcp_timeout_init\n");
for (uint64_t i = 0; i <= config->tcp_timeout_init; i++) for (uint64_t i = 0; i <= opts->tcp_timeout_init; i++)
{ {
timestamp_update(); timestamp_update();
sess = session_manager_get_expired_session(mgr); sess = session_manager_get_expired_session(mgr);
interval = session_manager_get_expire_interval(mgr); interval = session_manager_get_expire_interval(mgr);
if (i == config->tcp_timeout_init) if (i == opts->tcp_timeout_init)
{ {
printf("timeout_time: %lu, curr_time: %lu, session expired\n", printf("timeout_time: %lu, curr_time: %lu, session expired\n",
timeout_time, timestamp_get_sec()); timeout_time, timestamp_get_sec());
@@ -139,7 +139,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_init(str
printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n",
timeout_time, timestamp_get_sec(), interval); timeout_time, timestamp_get_sec(), interval);
EXPECT_TRUE(interval <= config->tcp_timeout_init); EXPECT_TRUE(interval <= opts->tcp_timeout_init);
__session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
EXPECT_TRUE(sess == NULL); EXPECT_TRUE(sess == NULL);
} }
@@ -148,20 +148,20 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_init(str
printf("<= tcp_timeout_init\n\n"); printf("<= tcp_timeout_init\n\n");
} }
__attribute__((unused)) static void __session_manager_check_tcp_timeout_handshake(struct session_manager *mgr, struct session_manager_config *config) __attribute__((unused)) static void __session_manager_check_tcp_timeout_handshake(struct session_manager *mgr, struct session_manager_options *opts)
{ {
struct session *sess; struct session *sess;
uint64_t interval; uint64_t interval;
uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_handshake; uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_handshake;
printf("\n=> tcp_timeout_handshake\n"); printf("\n=> tcp_timeout_handshake\n");
for (uint64_t i = 0; i <= config->tcp_timeout_handshake; i++) for (uint64_t i = 0; i <= opts->tcp_timeout_handshake; i++)
{ {
timestamp_update(); timestamp_update();
sess = session_manager_get_expired_session(mgr); sess = session_manager_get_expired_session(mgr);
interval = session_manager_get_expire_interval(mgr); interval = session_manager_get_expire_interval(mgr);
if (i == config->tcp_timeout_handshake) if (i == opts->tcp_timeout_handshake)
{ {
printf("timeout_time: %lu, curr_time: %lu, session expired\n", printf("timeout_time: %lu, curr_time: %lu, session expired\n",
timeout_time, timestamp_get_sec()); timeout_time, timestamp_get_sec());
@@ -175,7 +175,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_handshak
printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n",
timeout_time, timestamp_get_sec(), interval); timeout_time, timestamp_get_sec(), interval);
EXPECT_TRUE(interval <= config->tcp_timeout_handshake); EXPECT_TRUE(interval <= opts->tcp_timeout_handshake);
__session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
EXPECT_TRUE(sess == NULL); EXPECT_TRUE(sess == NULL);
} }
@@ -184,20 +184,20 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_handshak
printf("<= tcp_timeout_handshake\n\n"); printf("<= tcp_timeout_handshake\n\n");
} }
__attribute__((unused)) static void __session_manager_check_tcp_timeout_data(struct session_manager *mgr, struct session_manager_config *config) __attribute__((unused)) static void __session_manager_check_tcp_timeout_data(struct session_manager *mgr, struct session_manager_options *opts)
{ {
struct session *sess; struct session *sess;
uint64_t interval; uint64_t interval;
uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_data; uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_data;
printf("\n=> tcp_timeout_data\n"); printf("\n=> tcp_timeout_data\n");
for (uint64_t i = 0; i <= config->tcp_timeout_data; i++) for (uint64_t i = 0; i <= opts->tcp_timeout_data; i++)
{ {
timestamp_update(); timestamp_update();
sess = session_manager_get_expired_session(mgr); sess = session_manager_get_expired_session(mgr);
interval = session_manager_get_expire_interval(mgr); interval = session_manager_get_expire_interval(mgr);
if (i == config->tcp_timeout_data) if (i == opts->tcp_timeout_data)
{ {
printf("timeout_time: %lu, curr_time: %lu, session expired\n", printf("timeout_time: %lu, curr_time: %lu, session expired\n",
timeout_time, timestamp_get_sec()); timeout_time, timestamp_get_sec());
@@ -211,7 +211,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_data(str
printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n",
timeout_time, timestamp_get_sec(), interval); timeout_time, timestamp_get_sec(), interval);
EXPECT_TRUE(interval <= config->tcp_timeout_data); EXPECT_TRUE(interval <= opts->tcp_timeout_data);
__session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
EXPECT_TRUE(sess == NULL); EXPECT_TRUE(sess == NULL);
} }
@@ -220,22 +220,22 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_data(str
printf("<= tcp_timeout_data\n\n"); printf("<= tcp_timeout_data\n\n");
} }
__attribute__((unused)) static void __session_manager_check_tcp_timeout_half_closed(struct session_manager *mgr, struct session_manager_config *config, enum session_state curr_state) __attribute__((unused)) static void __session_manager_check_tcp_timeout_half_closed(struct session_manager *mgr, struct session_manager_options *opts, enum session_state curr_state)
{ {
EXPECT_TRUE(curr_state == SESSION_STATE_OPENING || curr_state == SESSION_STATE_ACTIVE); EXPECT_TRUE(curr_state == SESSION_STATE_OPENING || curr_state == SESSION_STATE_ACTIVE);
struct session *sess; struct session *sess;
uint64_t interval; uint64_t interval;
uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_half_closed; uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_half_closed;
printf("\n=> tcp_timeout_half_closed\n"); printf("\n=> tcp_timeout_half_closed\n");
for (uint64_t i = 0; i <= config->tcp_timeout_half_closed; i++) for (uint64_t i = 0; i <= opts->tcp_timeout_half_closed; i++)
{ {
timestamp_update(); timestamp_update();
sess = session_manager_get_expired_session(mgr); sess = session_manager_get_expired_session(mgr);
interval = session_manager_get_expire_interval(mgr); interval = session_manager_get_expire_interval(mgr);
if (i == config->tcp_timeout_half_closed) if (i == opts->tcp_timeout_half_closed)
{ {
printf("timeout_time: %lu, curr_time: %lu, session expired\n", printf("timeout_time: %lu, curr_time: %lu, session expired\n",
timeout_time, timestamp_get_sec()); timeout_time, timestamp_get_sec());
@@ -249,7 +249,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_half_clo
printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n",
timeout_time, timestamp_get_sec(), interval); timeout_time, timestamp_get_sec(), interval);
EXPECT_TRUE(interval <= config->tcp_timeout_half_closed); EXPECT_TRUE(interval <= opts->tcp_timeout_half_closed);
if (curr_state == SESSION_STATE_OPENING) if (curr_state == SESSION_STATE_OPENING)
{ {
__session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
@@ -265,20 +265,20 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_half_clo
printf("<= tcp_timeout_half_closed\n\n"); printf("<= tcp_timeout_half_closed\n\n");
} }
__attribute__((unused)) static void __session_manager_check_tcp_timeout_time_wait(struct session_manager *mgr, struct session_manager_config *config) __attribute__((unused)) static void __session_manager_check_tcp_timeout_time_wait(struct session_manager *mgr, struct session_manager_options *opts)
{ {
struct session *sess; struct session *sess;
uint64_t interval; uint64_t interval;
uint64_t timeout_time = timestamp_get_sec() + config->tcp_timeout_time_wait; uint64_t timeout_time = timestamp_get_sec() + opts->tcp_timeout_time_wait;
printf("\n=> tcp_timeout_time_wait\n"); printf("\n=> tcp_timeout_time_wait\n");
for (uint64_t i = 0; i <= config->tcp_timeout_time_wait; i++) for (uint64_t i = 0; i <= opts->tcp_timeout_time_wait; i++)
{ {
timestamp_update(); timestamp_update();
sess = session_manager_get_expired_session(mgr); sess = session_manager_get_expired_session(mgr);
interval = session_manager_get_expire_interval(mgr); interval = session_manager_get_expire_interval(mgr);
if (i == config->tcp_timeout_time_wait) if (i == opts->tcp_timeout_time_wait)
{ {
printf("timeout_time: %lu, curr_time: %lu, session expired\n", printf("timeout_time: %lu, curr_time: %lu, session expired\n",
timeout_time, timestamp_get_sec()); timeout_time, timestamp_get_sec());
@@ -292,7 +292,7 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_time_wai
printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n",
timeout_time, timestamp_get_sec(), interval); timeout_time, timestamp_get_sec(), interval);
EXPECT_TRUE(interval <= config->tcp_timeout_init); EXPECT_TRUE(interval <= opts->tcp_timeout_init);
__session_manager_check_counter(mgr, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0);
EXPECT_TRUE(sess == NULL); EXPECT_TRUE(sess == NULL);
} }
@@ -301,22 +301,22 @@ __attribute__((unused)) static void __session_manager_check_tcp_timeout_time_wai
printf("<= tcp_timeout_time_wait\n\n"); printf("<= tcp_timeout_time_wait\n\n");
} }
__attribute__((unused)) static void __session_manager_check_udp_timeout_data(struct session_manager *mgr, struct session_manager_config *config, enum session_state curr_state) __attribute__((unused)) static void __session_manager_check_udp_timeout_data(struct session_manager *mgr, struct session_manager_options *opts, enum session_state curr_state)
{ {
EXPECT_TRUE(curr_state == SESSION_STATE_OPENING || curr_state == SESSION_STATE_ACTIVE); EXPECT_TRUE(curr_state == SESSION_STATE_OPENING || curr_state == SESSION_STATE_ACTIVE);
struct session *sess; struct session *sess;
uint64_t interval; uint64_t interval;
uint64_t timeout_time = timestamp_get_sec() + config->udp_timeout_data; uint64_t timeout_time = timestamp_get_sec() + opts->udp_timeout_data;
printf("\n=> udp_timeout_data\n"); printf("\n=> udp_timeout_data\n");
for (uint64_t i = 0; i <= config->udp_timeout_data; i++) for (uint64_t i = 0; i <= opts->udp_timeout_data; i++)
{ {
timestamp_update(); timestamp_update();
sess = session_manager_get_expired_session(mgr); sess = session_manager_get_expired_session(mgr);
interval = session_manager_get_expire_interval(mgr); interval = session_manager_get_expire_interval(mgr);
if (i == config->udp_timeout_data) if (i == opts->udp_timeout_data)
{ {
printf("timeout_time: %lu, curr_time: %lu, session expired\n", printf("timeout_time: %lu, curr_time: %lu, session expired\n",
timeout_time, timestamp_get_sec()); timeout_time, timestamp_get_sec());
@@ -330,7 +330,7 @@ __attribute__((unused)) static void __session_manager_check_udp_timeout_data(str
printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n", printf("timeout_time: %lu, curr_time: %lu, interval : %lu, session not expire\n",
timeout_time, timestamp_get_sec(), interval); timeout_time, timestamp_get_sec(), interval);
EXPECT_TRUE(interval <= config->udp_timeout_data); EXPECT_TRUE(interval <= opts->udp_timeout_data);
if (curr_state == SESSION_STATE_OPENING) if (curr_state == SESSION_STATE_OPENING)
{ {
__session_manager_check_counter(mgr, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0); __session_manager_check_counter(mgr, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0);

View File

@@ -48,10 +48,10 @@ struct stellar_context stellar_context;
struct stellar_context *stellar_ctx = &stellar_context; struct stellar_context *stellar_ctx = &stellar_context;
// config // config
struct device_config *dev_cfg = &stellar_context.config.dev_cfg; struct device_options *dev_opts = &stellar_context.config.dev_opts;
struct packet_io_config *pkt_io_cfg = &stellar_context.config.pkt_io_cfg; struct packet_io_options *pkt_io_opts = &stellar_context.config.pkt_io_opts;
struct ip_reassembly_config *ip_reass_cfg = &stellar_context.config.ip_reass_cfg; struct ip_reassembly_options *ip_reass_opts = &stellar_context.config.ip_reass_opts;
struct session_manager_config *sess_mgr_cfg = &stellar_context.config.sess_mgr_cfg; struct session_manager_options *sess_mgr_opts = &stellar_context.config.sess_mgr_opts;
static const char *log_config_file = "./conf/log.toml"; static const char *log_config_file = "./conf/log.toml";
static const char *stellar_config_file = "./conf/stellar.toml"; static const char *stellar_config_file = "./conf/stellar.toml";
@@ -207,14 +207,14 @@ static int thread_context_init(struct stellar_context *ctx, uint8_t nr_threads)
threads_ctx->need_exit = 0; threads_ctx->need_exit = 0;
threads_ctx->is_runing = 0; threads_ctx->is_runing = 0;
threads_ctx->sess_mgr = session_manager_new(sess_mgr_cfg); threads_ctx->sess_mgr = session_manager_new(sess_mgr_opts);
if (threads_ctx->sess_mgr == NULL) if (threads_ctx->sess_mgr == NULL)
{ {
STELLAR_LOG_ERROR("unable to create session manager"); STELLAR_LOG_ERROR("unable to create session manager");
return -1; return -1;
} }
threads_ctx->ip_mgr = ip_reassembly_new(ip_reass_cfg); threads_ctx->ip_mgr = ip_reassembly_new(ip_reass_opts);
if (threads_ctx->ip_mgr == NULL) if (threads_ctx->ip_mgr == NULL)
{ {
STELLAR_LOG_ERROR("unable to create ip reassemble manager"); STELLAR_LOG_ERROR("unable to create ip reassemble manager");
@@ -298,7 +298,7 @@ int main(int argc, char **argv)
config_dump(&stellar_ctx->config); config_dump(&stellar_ctx->config);
if (id_generator_init(dev_cfg->device_base, dev_cfg->device_offset) != 0) if (id_generator_init(dev_opts->device_base, dev_opts->device_offset) != 0)
{ {
STELLAR_LOG_ERROR("unable to init id generator"); STELLAR_LOG_ERROR("unable to init id generator");
return -1; return -1;
@@ -306,8 +306,8 @@ int main(int argc, char **argv)
// TODO load plugin // TODO load plugin
uint8_t nr_threads = pkt_io_cfg->nr_threads; uint8_t nr_threads = pkt_io_opts->nr_threads;
stellar_ctx->packet_io = packet_io_new(pkt_io_cfg); stellar_ctx->packet_io = packet_io_new(pkt_io_opts);
if (stellar_ctx->packet_io == NULL) if (stellar_ctx->packet_io == NULL)
{ {
STELLAR_LOG_ERROR("unable to create packet io"); STELLAR_LOG_ERROR("unable to create packet io");