Modify the stat of session

This commit is contained in:
luwenpeng
2024-04-09 15:07:53 +08:00
parent 3b00acab81
commit a5a133bf91
13 changed files with 671 additions and 732 deletions

View File

@@ -103,8 +103,6 @@ void plugin_manager_dispatch(void *plugin_mgr, struct session *sess, const struc
session_free_tcp_segment(sess, seg);
} while (1);
}
session_clean_packet(sess, SESSION_PACKET_CURRENT);
session_set_cur_dir(sess, SESSION_DIR_NONE);
printf("<= plugin dispatch session\n");
}
@@ -139,6 +137,42 @@ static void signal_handler(int signo)
}
}
static void execute_packet_action(struct packet_io *packet_io, struct session *sess, struct packet *pkt, uint16_t thr_idx)
{
enum packet_action action = packet_get_action(pkt);
enum packet_type type = packet_get_type(pkt);
if (sess)
{
enum session_stat stat_pkt;
enum session_stat stat_byte;
if (action == PACKET_ACTION_DROP)
{
stat_pkt = (type == PACKET_TYPE_CTRL) ? STAT_CTRL_PKTS_DROP : STAT_RAW_PKTS_DROP;
stat_byte = (type == PACKET_TYPE_CTRL) ? STAT_CTRL_BYTES_DROP : STAT_RAW_BYTES_DROP;
}
else
{
stat_pkt = (type == PACKET_TYPE_CTRL) ? STAT_CTRL_PKTS_TX : STAT_RAW_PKTS_TX;
stat_byte = (type == PACKET_TYPE_CTRL) ? STAT_CTRL_BYTES_TX : STAT_RAW_BYTES_TX;
}
session_inc_stat(sess, session_get_current_dir(sess), stat_pkt, 1);
session_inc_stat(sess, session_get_current_dir(sess), stat_byte, packet_get_len(pkt));
session_set_current_packet(sess, NULL);
session_set_current_dir(sess, SESSION_DIR_NONE);
}
if (action == PACKET_ACTION_DROP)
{
packet_io_drop(packet_io, thr_idx, pkt, 1);
}
else
{
packet_io_egress(packet_io, thr_idx, pkt, 1);
}
}
/******************************************************************************
* thread
******************************************************************************/
@@ -165,7 +199,6 @@ static void *main_loop(void *arg)
void *plug_mgr_ctx = NULL;
int nr_recv;
int need_drop_pkt = 1; // TODO
uint64_t now = 0;
uint16_t thr_idx = threads_ctx->index;
@@ -198,7 +231,7 @@ static void *main_loop(void *arg)
struct packet *defraged_pkt = ip_reassembly_packet(ip_reass, pkt, now);
if (defraged_pkt == NULL)
{
continue;
goto fast_path;
}
else
{
@@ -207,15 +240,13 @@ static void *main_loop(void *arg)
}
}
// 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, now);
if (sess == NULL)
{
continue;
goto fast_path;
}
plug_mgr_ctx = plugin_manager_new_ctx();
session_set_user_data(sess, plug_mgr_ctx);
@@ -225,25 +256,9 @@ static void *main_loop(void *arg)
session_manager_update_session(sess_mgr, sess, pkt, now);
}
plugin_manager_dispatch(plug_mgr, sess, pkt);
}
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);
fast_path:
execute_packet_action(packet_io, sess, pkt, thr_idx);
}
idle_tasks: