reactor packet I/O & duplicated packet filter & evicted session filter
This commit is contained in:
@@ -131,28 +131,29 @@ static void *main_loop(void *arg)
|
||||
struct thread_context *threads_ctx = (struct thread_context *)arg;
|
||||
struct packet_io *packet_io = stellar_ctx->packet_io;
|
||||
struct session_manager *sess_mgr = threads_ctx->sess_mgr;
|
||||
struct ip_reassembly *ip_mgr = threads_ctx->ip_mgr;
|
||||
struct ip_reassembly *ip_reass = threads_ctx->ip_mgr;
|
||||
void *plug_mgr = NULL;
|
||||
void *plug_mgr_ctx = NULL;
|
||||
|
||||
int nr_recv;
|
||||
uint16_t thd_idx = threads_ctx->index;
|
||||
uint64_t now_msec = 0;
|
||||
int need_drop_pkt = 1; // TODO
|
||||
uint64_t now_sec = 0;
|
||||
uint16_t thr_idx = threads_ctx->index;
|
||||
|
||||
if (packet_io_init(packet_io, thd_idx) != 0)
|
||||
if (packet_io_init(packet_io, thr_idx) != 0)
|
||||
{
|
||||
STELLAR_LOG_ERROR("unable to init marsio thread");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ATOMIC_SET(&threads_ctx->is_runing, 1);
|
||||
thread_set_name("stellar", thd_idx);
|
||||
STELLAR_LOG_STATE("worker thread %d runing", thd_idx);
|
||||
thread_set_name("stellar", thr_idx);
|
||||
STELLAR_LOG_STATE("worker thread %d runing", thr_idx);
|
||||
|
||||
while (ATOMIC_READ(&threads_ctx->need_exit) == 0)
|
||||
{
|
||||
now_msec = timestamp_get_msec();
|
||||
nr_recv = packet_io_ingress(packet_io, thd_idx, packets, RX_BURST_MAX);
|
||||
now_sec = timestamp_get_sec(); // TODO
|
||||
nr_recv = packet_io_ingress(packet_io, thr_idx, packets, RX_BURST_MAX);
|
||||
if (nr_recv == 0)
|
||||
{
|
||||
goto idle_tasks;
|
||||
@@ -162,53 +163,66 @@ static void *main_loop(void *arg)
|
||||
{
|
||||
pkt = &packets[i];
|
||||
|
||||
// TODO
|
||||
// call packet plugin
|
||||
|
||||
// ip fragment reassemble
|
||||
if (pkt->frag_layer)
|
||||
// call plugin_manager_dispatch_raw_pkt();
|
||||
if (packet_is_fragment(pkt))
|
||||
{
|
||||
struct packet *temp = ip_reassembly_packet(ip_mgr, pkt);
|
||||
packet_io_egress(packet_io, thd_idx, pkt, 1); // forward the original fragment packet
|
||||
if (temp == NULL)
|
||||
struct packet *defraged_pkt = ip_reassembly_packet(ip_reass, pkt, now_sec);
|
||||
if (defraged_pkt == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkt = temp;
|
||||
// call plugin_manager_dispatch_defrag_pkt();
|
||||
pkt = defraged_pkt;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO filter protocol before session lookup
|
||||
|
||||
sess = session_manager_lookup_session(sess_mgr, pkt);
|
||||
if (sess == NULL)
|
||||
{
|
||||
sess = session_manager_new_session(sess_mgr, pkt);
|
||||
if (sess == NULL)
|
||||
{
|
||||
// 1.Not TCP or UDP
|
||||
// 2.UDP evict packet
|
||||
// 3.UDP overloading and config to bypass new session
|
||||
// 4.TCP no SYN flag
|
||||
// 5.UDP overloading and config to bypass new session
|
||||
goto fast_forward;
|
||||
|
||||
continue;
|
||||
}
|
||||
plug_mgr_ctx = plugin_manager_new_ctx();
|
||||
session_set_id(sess, id_generator_alloc(now_sec, thr_idx));
|
||||
session_set_user_data(sess, plug_mgr_ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (session_manager_update_session(sess_mgr, sess, pkt) == -1)
|
||||
{
|
||||
// TCP duplicate packet
|
||||
goto fast_forward;
|
||||
}
|
||||
session_manager_update_session(sess_mgr, sess, pkt);
|
||||
}
|
||||
plugin_manager_dispatch(plug_mgr, sess, pkt);
|
||||
}
|
||||
|
||||
fast_forward:
|
||||
packet_io_egress(packet_io, thd_idx, pkt, 1);
|
||||
if (unlikely(need_drop_pkt))
|
||||
{
|
||||
for (int i = 0; i < nr_recv; i++)
|
||||
{
|
||||
if (packet_get_action(&packets[i]) == PACKET_ACTION_DROP)
|
||||
{
|
||||
packet_io_drop(packet_io, thr_idx, &packets[i], 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_io_egress(packet_io, thr_idx, &packets[i], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_io_egress(packet_io, thr_idx, packets, nr_recv);
|
||||
}
|
||||
|
||||
idle_tasks:
|
||||
// nr_recv packet atmost trigger nr_recv session evict
|
||||
for (int i = 0; i < nr_recv; i++)
|
||||
{
|
||||
evicted_sess = session_manager_get_evicted_session(sess_mgr);
|
||||
if (evicted_sess)
|
||||
{
|
||||
@@ -218,9 +232,7 @@ static void *main_loop(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
idle_tasks:
|
||||
expired_sess = session_manager_get_expired_session(sess_mgr);
|
||||
if (expired_sess)
|
||||
while ((expired_sess = session_manager_get_expired_session(sess_mgr)))
|
||||
{
|
||||
plug_mgr_ctx = session_get_user_data(expired_sess);
|
||||
plugin_manager_free_ctx(plug_mgr_ctx);
|
||||
@@ -234,7 +246,7 @@ static void *main_loop(void *arg)
|
||||
}
|
||||
|
||||
ATOMIC_SET(&threads_ctx->is_runing, 0);
|
||||
STELLAR_LOG_STATE("worker thread %d stop", thd_idx);
|
||||
STELLAR_LOG_STATE("worker thread %d stop", thr_idx);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -331,13 +343,13 @@ int main(int argc, char **argv)
|
||||
|
||||
STELLAR_LOG_STATE("Start Stellar (version: %s)\n %s", __stellar_version, logo_str);
|
||||
|
||||
if (config_load(&stellar_ctx->config, stellar_config_file) != 0)
|
||||
if (parse_config_file(stellar_config_file, &stellar_ctx->config) != 0)
|
||||
{
|
||||
STELLAR_LOG_ERROR("unable to load config file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
config_dump(&stellar_ctx->config);
|
||||
print_config_options(&stellar_ctx->config);
|
||||
|
||||
if (id_generator_init(dev_opts->device_base, dev_opts->device_offset) != 0)
|
||||
{
|
||||
@@ -380,7 +392,6 @@ error_out:
|
||||
|
||||
// TODO free plugin
|
||||
|
||||
id_generator_free();
|
||||
log_free();
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user