Modify the stat of session
This commit is contained in:
@@ -60,12 +60,12 @@ enum session_dir session_get_tuple_dir(const struct session *sess)
|
||||
return sess->tuple_dir;
|
||||
}
|
||||
|
||||
void session_set_cur_dir(struct session *sess, enum session_dir dir)
|
||||
void session_set_current_dir(struct session *sess, enum session_dir dir)
|
||||
{
|
||||
sess->cur_dir = dir;
|
||||
}
|
||||
|
||||
enum session_dir session_get_cur_dir(const struct session *sess)
|
||||
enum session_dir session_get_current_dir(const struct session *sess)
|
||||
{
|
||||
return sess->cur_dir;
|
||||
}
|
||||
@@ -110,63 +110,44 @@ enum closing_reason session_get_closing_reason(const struct session *sess)
|
||||
return sess->reason;
|
||||
}
|
||||
|
||||
void session_inc_metric(struct session *sess, enum session_metric_index idx, uint64_t val)
|
||||
void session_inc_stat(struct session *sess, enum session_dir dir, enum session_stat stat, uint64_t val)
|
||||
{
|
||||
sess->metrics[idx] += val;
|
||||
sess->stats[dir][stat] += val;
|
||||
}
|
||||
|
||||
void session_set_metric(struct session *sess, enum session_metric_index idx, uint64_t val)
|
||||
uint64_t session_get_stat(const struct session *sess, enum session_dir dir, enum session_stat stat)
|
||||
{
|
||||
sess->metrics[idx] = val;
|
||||
return sess->stats[dir][stat];
|
||||
}
|
||||
|
||||
uint64_t session_get_metric(const struct session *sess, enum session_metric_index idx)
|
||||
{
|
||||
return sess->metrics[idx];
|
||||
}
|
||||
|
||||
void session_set_timestamp(struct session *sess, enum session_timestamp_index idx, uint64_t timestamp)
|
||||
void session_set_timestamp(struct session *sess, enum session_timestamp idx, uint64_t timestamp)
|
||||
{
|
||||
sess->timestamps[idx] = timestamp;
|
||||
}
|
||||
|
||||
uint64_t session_get_timestamp(const struct session *sess, enum session_timestamp_index idx)
|
||||
uint64_t session_get_timestamp(const struct session *sess, enum session_timestamp idx)
|
||||
{
|
||||
return sess->timestamps[idx];
|
||||
}
|
||||
|
||||
void session_set_packet(struct session *sess, enum session_packet_index idx, const struct packet *pkt)
|
||||
void session_set_1st_packet(struct session *sess, enum session_dir dir, const struct packet *pkt)
|
||||
{
|
||||
if (idx == SESSION_PACKET_CURRENT)
|
||||
{
|
||||
sess->packets[idx] = pkt;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sess->packets[idx])
|
||||
{
|
||||
return;
|
||||
}
|
||||
sess->packets[idx] = packet_dup(pkt);
|
||||
}
|
||||
sess->first_pkt[dir] = packet_dup(pkt);
|
||||
}
|
||||
|
||||
void session_clean_packet(struct session *sess, enum session_packet_index idx)
|
||||
const struct packet *session_get_1st_packet(const struct session *sess, enum session_dir dir)
|
||||
{
|
||||
if (idx == SESSION_PACKET_CURRENT)
|
||||
{
|
||||
sess->packets[idx] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_free((struct packet *)sess->packets[idx]);
|
||||
sess->packets[idx] = NULL;
|
||||
}
|
||||
return sess->first_pkt[dir];
|
||||
}
|
||||
|
||||
const struct packet *session_get_packet(const struct session *sess, enum session_packet_index idx)
|
||||
void session_set_current_packet(struct session *sess, const struct packet *pkt)
|
||||
{
|
||||
return sess->packets[idx];
|
||||
sess->curr_pkt = pkt;
|
||||
}
|
||||
|
||||
const struct packet *session_get_current_packet(const struct session *sess)
|
||||
{
|
||||
return sess->curr_pkt;
|
||||
}
|
||||
|
||||
void session_set_user_data(struct session *sess, void *user_data)
|
||||
@@ -181,27 +162,22 @@ void *session_get_user_data(const struct session *sess)
|
||||
|
||||
struct tcp_segment *session_get_tcp_segment(struct session *sess)
|
||||
{
|
||||
struct tcp_half *half = NULL;
|
||||
if (session_get_cur_dir(sess) == SESSION_DIR_C2S)
|
||||
{
|
||||
half = &sess->tcp_pcb.c2s;
|
||||
}
|
||||
else
|
||||
{
|
||||
half = &sess->tcp_pcb.s2c;
|
||||
}
|
||||
enum session_dir dir = session_get_current_dir(sess);
|
||||
struct tcp_half *half = &sess->tcp_halfs[dir];
|
||||
|
||||
if (half->order.data != NULL && half->order.len > 0)
|
||||
if (half->in_order.data != NULL && half->in_order.len > 0)
|
||||
{
|
||||
return &half->order;
|
||||
return &half->in_order;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct tcp_segment *seg = tcp_reassembly_pop(half->assembler);
|
||||
if (seg)
|
||||
{
|
||||
session_inc_stat(sess, dir, STAT_TCP_SEGS_REORDERED, 1);
|
||||
session_inc_stat(sess, dir, STAT_TCP_PLDS_REORDERED, seg->len);
|
||||
|
||||
sess->mgr_stat->nr_tcp_seg_reorded++;
|
||||
half->nr_tcp_seg_reorded++;
|
||||
}
|
||||
return seg;
|
||||
}
|
||||
@@ -214,26 +190,21 @@ void session_free_tcp_segment(struct session *sess, struct tcp_segment *seg)
|
||||
return;
|
||||
}
|
||||
|
||||
struct tcp_half *half = NULL;
|
||||
if (session_get_cur_dir(sess) == SESSION_DIR_C2S)
|
||||
{
|
||||
half = &sess->tcp_pcb.c2s;
|
||||
}
|
||||
else
|
||||
{
|
||||
half = &sess->tcp_pcb.s2c;
|
||||
}
|
||||
enum session_dir dir = session_get_current_dir(sess);
|
||||
struct tcp_half *half = &sess->tcp_halfs[dir];
|
||||
|
||||
if (seg == &half->order)
|
||||
if (seg == &half->in_order)
|
||||
{
|
||||
half->order.data = NULL;
|
||||
half->order.len = 0;
|
||||
half->in_order.data = NULL;
|
||||
half->in_order.len = 0;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
session_inc_stat(sess, dir, STAT_TCP_SEGS_RELEASED, 1);
|
||||
session_inc_stat(sess, dir, STAT_TCP_PLDS_RELEASED, seg->len);
|
||||
sess->mgr_stat->nr_tcp_seg_released++;
|
||||
half->nr_tcp_seg_released++;
|
||||
|
||||
tcp_segment_free(seg);
|
||||
}
|
||||
}
|
||||
@@ -412,36 +383,26 @@ const char *session_dir_to_str(enum session_dir dir)
|
||||
}
|
||||
}
|
||||
|
||||
void tcp_half_dump(const struct tcp_half *half)
|
||||
void tcp_flags_to_str(uint8_t flags, char *buffer, size_t len)
|
||||
{
|
||||
char buffer[32] = {0};
|
||||
int used = 0;
|
||||
|
||||
if (half->flags & TH_SYN)
|
||||
if (flags & TH_SYN)
|
||||
{
|
||||
used += snprintf(buffer + used, sizeof(buffer) - used, "SYN ");
|
||||
used += snprintf(buffer + used, len - used, "SYN ");
|
||||
}
|
||||
if (half->flags & TH_ACK)
|
||||
if (flags & TH_ACK)
|
||||
{
|
||||
used += snprintf(buffer + used, sizeof(buffer) - used, "ACK ");
|
||||
used += snprintf(buffer + used, len - used, "ACK ");
|
||||
}
|
||||
if (half->flags & TH_FIN)
|
||||
if (flags & TH_FIN)
|
||||
{
|
||||
used += snprintf(buffer + used, sizeof(buffer) - used, "FIN ");
|
||||
used += snprintf(buffer + used, len - used, "FIN ");
|
||||
}
|
||||
if (half->flags & TH_RST)
|
||||
if (flags & TH_RST)
|
||||
{
|
||||
used += snprintf(buffer + used, sizeof(buffer) - used, "RST ");
|
||||
used += snprintf(buffer + used, len - used, "RST ");
|
||||
}
|
||||
printf(" flags : %s\n", buffer);
|
||||
printf(" nr_tcp_seg_received : %lu\n", half->nr_tcp_seg_received);
|
||||
printf(" nr_tcp_seg_expired : %lu\n", half->nr_tcp_seg_expired);
|
||||
printf(" nr_tcp_seg_overlap : %lu\n", half->nr_tcp_seg_overlap);
|
||||
printf(" nr_tcp_seg_no_space : %lu\n", half->nr_tcp_seg_no_space);
|
||||
printf(" nr_tcp_seg_inorder : %lu\n", half->nr_tcp_seg_inorder);
|
||||
printf(" nr_tcp_seg_reorded : %lu\n", half->nr_tcp_seg_reorded);
|
||||
printf(" nr_tcp_seg_buffered : %lu\n", half->nr_tcp_seg_buffered);
|
||||
printf(" nr_tcp_seg_released : %lu\n", half->nr_tcp_seg_released);
|
||||
}
|
||||
|
||||
void session_dump(struct session *sess)
|
||||
@@ -456,24 +417,15 @@ void session_dump(struct session *sess)
|
||||
printf("session type : %s\n", session_type_to_str(session_get_type(sess)));
|
||||
printf("session dup traffic : %d\n", session_has_dup_traffic(sess));
|
||||
printf("session closing reason : %s\n", closing_reason_to_str(session_get_closing_reason(sess)));
|
||||
printf("session C2S packets : %" PRIu64 "\n", session_get_metric(sess, SESSION_METRIC_C2S_PACKETS));
|
||||
printf("session C2S bytes : %" PRIu64 "\n", session_get_metric(sess, SESSION_METRIC_C2S_BYTES));
|
||||
printf("session S2C packets : %" PRIu64 "\n", session_get_metric(sess, SESSION_METRIC_S2C_PACKETS));
|
||||
printf("session S2C bytes : %" PRIu64 "\n", session_get_metric(sess, SESSION_METRIC_S2C_BYTES));
|
||||
printf("session new time : %" PRIu64 "\n", session_get_timestamp(sess, SESSION_TIMESTAMP_NEW));
|
||||
printf("session last time : %" PRIu64 "\n", session_get_timestamp(sess, SESSION_TIMESTAMP_LAST));
|
||||
printf("session current packet ptr : %p\n", (void *)session_get_packet(sess, SESSION_PACKET_CURRENT));
|
||||
printf("session current packet dir : %s\n", session_dir_to_str(session_get_cur_dir(sess)));
|
||||
printf("session current packet dir : %s\n", session_dir_to_str(session_get_current_dir(sess)));
|
||||
|
||||
// TODO session stat
|
||||
|
||||
printf("session ex data:\n");
|
||||
for (uint8_t i = 0; i < g_ex_manager.count; i++)
|
||||
{
|
||||
printf(" ex_idx: %d, ex_key: %s, ex_data: %p\n", i, g_ex_manager.schemas[i].key, sess->ex_data[i]);
|
||||
}
|
||||
if (session_get_type(sess) == SESSION_TYPE_TCP)
|
||||
{
|
||||
printf("session TCP C2S:\n");
|
||||
tcp_half_dump(&sess->tcp_pcb.c2s);
|
||||
printf("session TCP S2C:\n");
|
||||
tcp_half_dump(&sess->tcp_pcb.s2c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user