refactor: session module (split to define/utils/pool/table/timer/transition/manager)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
add_library(session_manager
|
||||
session.cpp
|
||||
session_utils.cpp
|
||||
session_pool.cpp
|
||||
session_table.cpp
|
||||
session_timer.cpp
|
||||
|
||||
83
src/session/session_def.h
Normal file
83
src/session/session_def.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "list.h"
|
||||
#include "tuple.h"
|
||||
#include "uthash.h"
|
||||
#include "timeout.h"
|
||||
#include "packet_def.h"
|
||||
#include "stellar/session.h"
|
||||
#include "tcp_reassembly.h"
|
||||
|
||||
#define EX_DATA_MAX_COUNT 4
|
||||
|
||||
// output format: "${src_addr}:${src_port}-${dst_addr}:${dst_port}-${ip_proto}-${domain}"
|
||||
// output max len: (46 + 1 + 5) + 1 + (46 + 1 + 5) + 1 + 1 + 1 + 20 = 129
|
||||
#define TUPLE6_STR_SIZE 130
|
||||
|
||||
struct tcp_half
|
||||
{
|
||||
struct tcp_reassembly *assembler;
|
||||
struct tcp_segment in_order; // current packet in order segment
|
||||
uint32_t in_order_ref; // reference count of current packet in order segment
|
||||
|
||||
uint32_t inject_inc_seq_offset; // inject packet base on current packet increase seq offset
|
||||
uint32_t inject_inc_ack_offset; // inject packet base on current packet increase ack offset
|
||||
|
||||
uint32_t seq; // current packet sequence number
|
||||
uint32_t ack; // current packet ack number
|
||||
uint16_t len; // current packet payload length
|
||||
uint8_t flags; // current packet flags
|
||||
|
||||
uint32_t isn; // current direction initial sequence number
|
||||
uint8_t history; // current direction received flags
|
||||
};
|
||||
|
||||
/*
|
||||
* sizeof(struct session) > 1024 bytes
|
||||
* max thread number = 128
|
||||
* per thread max tcp session number = 50000
|
||||
* per thread max udp session number = 50000
|
||||
*
|
||||
* session memory usage = 128 * (50000 + 50000) * 1024 = 13107200000 bytes = 12.2 GB
|
||||
*/
|
||||
struct session
|
||||
{
|
||||
uint64_t id;
|
||||
uint64_t stats[MAX_FLOW_DIRECTION][MAX_STAT];
|
||||
uint64_t timestamps[MAX_TIMESTAMP]; // realtime seconds
|
||||
struct tcp_half tcp_halfs[MAX_FLOW_DIRECTION];
|
||||
struct timeout timeout;
|
||||
struct list_head lru;
|
||||
struct list_head free;
|
||||
struct list_head evicte;
|
||||
UT_hash_handle hh1;
|
||||
UT_hash_handle hh2;
|
||||
UT_hash_handle hh3;
|
||||
struct tuple6 tuple;
|
||||
char tuple_str[TUPLE6_STR_SIZE];
|
||||
struct sids sids[MAX_FLOW_DIRECTION];
|
||||
struct route_ctx route_ctx[MAX_FLOW_DIRECTION];
|
||||
const struct packet *first_pkt[MAX_FLOW_DIRECTION];
|
||||
const struct packet *curr_pkt;
|
||||
void *ex_data[EX_DATA_MAX_COUNT];
|
||||
void *user_data;
|
||||
int is_symmetric;
|
||||
int dup;
|
||||
enum session_direction sess_dir;
|
||||
enum flow_direction tuple_dir;
|
||||
enum flow_direction flow_dir;
|
||||
enum session_type type;
|
||||
enum session_state state;
|
||||
enum closing_reason reason;
|
||||
struct session_manager *mgr;
|
||||
struct session_manager_stat *mgr_stat;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -2,12 +2,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "times.h"
|
||||
#include "tcp_utils.h"
|
||||
#include "udp_utils.h"
|
||||
#include "packet_layer.h"
|
||||
#include "packet_utils.h"
|
||||
#include "id_generator.h"
|
||||
#include "session_def.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_pool.h"
|
||||
#include "session_table.h"
|
||||
#include "session_timer.h"
|
||||
@@ -16,6 +20,9 @@
|
||||
#include "evicted_session_filter.h"
|
||||
#include "duplicated_packet_filter.h"
|
||||
|
||||
#define SESSION_LOG_ERROR(format, ...) LOG_ERROR("session", format, ##__VA_ARGS__)
|
||||
#define SESSION_LOG_DEBUG(format, ...) LOG_DEBUG("session", format, ##__VA_ARGS__)
|
||||
|
||||
struct session_manager
|
||||
{
|
||||
struct list_head evicte_queue;
|
||||
@@ -528,7 +535,7 @@ static void session_update(struct session *sess, enum session_state next_state,
|
||||
if (session_get_current_state(sess) == SESSION_STATE_INIT)
|
||||
{
|
||||
session_set_id(sess, id_generator_alloc());
|
||||
session_set_tuple(sess, key);
|
||||
session_set_tuple6(sess, key);
|
||||
session_set_tuple_direction(sess, dir);
|
||||
|
||||
enum packet_direction pkt_dir = packet_get_direction(pkt);
|
||||
|
||||
@@ -5,12 +5,6 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "session_priv.h"
|
||||
#include "log.h"
|
||||
|
||||
#define SESSION_LOG_ERROR(format, ...) LOG_ERROR("session", format, ##__VA_ARGS__)
|
||||
#define SESSION_LOG_DEBUG(format, ...) LOG_DEBUG("session", format, ##__VA_ARGS__)
|
||||
|
||||
struct session_manager_options
|
||||
{
|
||||
// max session number
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "session_def.h"
|
||||
#include "session_pool.h"
|
||||
|
||||
struct session_pool
|
||||
|
||||
@@ -5,7 +5,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "session_priv.h"
|
||||
#include <stdint.h>
|
||||
|
||||
struct session_pool;
|
||||
struct session_pool *session_pool_new(uint64_t count);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#define HASH_FUNCTION(keyptr, keylen, hashv) HASH_FUNCTION_OVERWRITE(keyptr, keylen, &hashv)
|
||||
#define HASH_KEYCMP(a, b, len) HASH_KEYCMP_OVERWRITE(a, b, len)
|
||||
#include "session_def.h"
|
||||
#include "session_table.h"
|
||||
|
||||
struct session_table
|
||||
|
||||
@@ -5,8 +5,6 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "session_priv.h"
|
||||
|
||||
struct session_table;
|
||||
struct session_table *session_table_new();
|
||||
void session_table_free(struct session_table *table);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "session_def.h"
|
||||
#include "session_timer.h"
|
||||
|
||||
struct session_timer
|
||||
|
||||
@@ -5,7 +5,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "session_priv.h"
|
||||
#include <stdint.h>
|
||||
|
||||
struct session_timer;
|
||||
struct session_timer *session_timer_new(uint64_t now);
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_transition.h"
|
||||
|
||||
#define SESSION_TRANSITION_LOG_INFO(format, ...) LOG_INFO("session transition", format, ##__VA_ARGS__)
|
||||
|
||||
#define MAX_TRANSITION_PER_STATE 8
|
||||
|
||||
struct session_transition
|
||||
|
||||
@@ -5,10 +5,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "log.h"
|
||||
#include "session_priv.h"
|
||||
|
||||
#define SESSION_TRANSITION_LOG_INFO(format, ...) LOG_INFO("session transition", format, ##__VA_ARGS__)
|
||||
#include "stellar/session.h"
|
||||
|
||||
enum session_inputs
|
||||
{
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "packet_def.h"
|
||||
#include "session_priv.h"
|
||||
#include "tcp_utils.h"
|
||||
#include "tcp_reassembly.h"
|
||||
#include "session_def.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#define EX_KEY_MAX_LEN 64
|
||||
|
||||
struct ex_schema
|
||||
struct session_exdata_schema
|
||||
{
|
||||
char key[EX_KEY_MAX_LEN];
|
||||
session_ex_free_cb *free_cb;
|
||||
void *args;
|
||||
};
|
||||
|
||||
struct ex_manager
|
||||
struct session_exdata_manager
|
||||
{
|
||||
struct ex_schema schemas[EX_DATA_MAX_COUNT];
|
||||
struct session_exdata_schema schemas[EX_DATA_MAX_COUNT];
|
||||
uint8_t count;
|
||||
};
|
||||
|
||||
static struct ex_manager g_ex_manager = {0};
|
||||
static struct session_exdata_manager g_ex_manager = {0};
|
||||
|
||||
/******************************************************************************
|
||||
* session set/get
|
||||
@@ -41,7 +40,7 @@ uint64_t session_get_id(const struct session *sess)
|
||||
return sess->id;
|
||||
}
|
||||
|
||||
void session_set_tuple(struct session *sess, const struct tuple6 *tuple)
|
||||
void session_set_tuple6(struct session *sess, const struct tuple6 *tuple)
|
||||
{
|
||||
memcpy(&sess->tuple, tuple, sizeof(struct tuple6));
|
||||
}
|
||||
@@ -264,6 +263,7 @@ struct tcp_segment *session_get_tcp_segment(struct session *sess)
|
||||
session_inc_stat(sess, dir, STAT_TCP_SEGMENTS_REORDERED, 1);
|
||||
session_inc_stat(sess, dir, STAT_TCP_PAYLOADS_REORDERED, seg->len);
|
||||
|
||||
// TODO
|
||||
sess->mgr_stat->nr_tcp_seg_reorded++;
|
||||
}
|
||||
return seg;
|
||||
@@ -326,7 +326,7 @@ uint8_t session_get_ex_new_index(const char *key, session_ex_free_cb *free_cb, v
|
||||
uint8_t idx = g_ex_manager.count;
|
||||
g_ex_manager.count++;
|
||||
|
||||
struct ex_schema *schema = &g_ex_manager.schemas[idx];
|
||||
struct session_exdata_schema *schema = &g_ex_manager.schemas[idx];
|
||||
strncpy(schema->key, key, EX_KEY_MAX_LEN);
|
||||
schema->free_cb = free_cb;
|
||||
schema->args = args;
|
||||
@@ -377,7 +377,7 @@ void session_free_ex_data(struct session *sess, uint8_t idx)
|
||||
return;
|
||||
}
|
||||
|
||||
struct ex_schema *schema = &g_ex_manager.schemas[idx];
|
||||
struct session_exdata_schema *schema = &g_ex_manager.schemas[idx];
|
||||
if (schema->free_cb != NULL && sess->ex_data[idx] != NULL)
|
||||
{
|
||||
printf("free ex_data, idx: %d, key: %s, val: %p\n", idx, schema->key, sess->ex_data[idx]);
|
||||
@@ -5,113 +5,88 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "list.h"
|
||||
#include "tuple.h"
|
||||
#include "uthash.h"
|
||||
#include "timeout.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_utils.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#include "stellar/session.h"
|
||||
#include "tcp_reassembly.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#define EX_DATA_MAX_COUNT 4
|
||||
|
||||
// output format: "${src_addr}:${src_port}-${dst_addr}:${dst_port}-${ip_proto}-${domain}"
|
||||
// output max len: (46 + 1 + 5) + 1 + (46 + 1 + 5) + 1 + 1 + 1 + 20 = 129
|
||||
#define TUPLE6_STR_SIZE 130
|
||||
|
||||
struct tcp_half
|
||||
{
|
||||
struct tcp_reassembly *assembler;
|
||||
struct tcp_segment in_order; // current packet in order segment
|
||||
uint32_t in_order_ref; // reference count of current packet in order segment
|
||||
|
||||
uint32_t inject_inc_seq_offset; // inject packet base on current packet increase seq offset
|
||||
uint32_t inject_inc_ack_offset; // inject packet base on current packet increase ack offset
|
||||
|
||||
uint32_t seq; // current packet sequence number
|
||||
uint32_t ack; // current packet ack number
|
||||
uint16_t len; // current packet payload length
|
||||
uint8_t flags; // current packet flags
|
||||
|
||||
uint32_t isn; // current direction initial sequence number
|
||||
uint8_t history; // current direction received flags
|
||||
};
|
||||
|
||||
/*
|
||||
* sizeof(struct session) > 1024 bytes
|
||||
* max thread number = 128
|
||||
* per thread max tcp session number = 50000
|
||||
* per thread max udp session number = 50000
|
||||
*
|
||||
* session memory usage = 128 * (50000 + 50000) * 1024 = 13107200000 bytes = 12.2 GB
|
||||
*/
|
||||
struct session
|
||||
{
|
||||
uint64_t id;
|
||||
uint64_t stats[MAX_FLOW_DIRECTION][MAX_STAT];
|
||||
uint64_t timestamps[MAX_TIMESTAMP]; // realtime seconds
|
||||
struct tcp_half tcp_halfs[MAX_FLOW_DIRECTION];
|
||||
struct timeout timeout;
|
||||
struct list_head lru;
|
||||
struct list_head free;
|
||||
struct list_head evicte;
|
||||
UT_hash_handle hh1;
|
||||
UT_hash_handle hh2;
|
||||
UT_hash_handle hh3;
|
||||
struct tuple6 tuple;
|
||||
char tuple_str[TUPLE6_STR_SIZE];
|
||||
struct sids sids[MAX_FLOW_DIRECTION];
|
||||
struct route_ctx route_ctx[MAX_FLOW_DIRECTION];
|
||||
const struct packet *first_pkt[MAX_FLOW_DIRECTION];
|
||||
const struct packet *curr_pkt;
|
||||
void *ex_data[EX_DATA_MAX_COUNT];
|
||||
void *user_data;
|
||||
int is_symmetric;
|
||||
int dup;
|
||||
enum session_direction sess_dir;
|
||||
enum flow_direction tuple_dir;
|
||||
enum flow_direction flow_dir;
|
||||
enum session_type type;
|
||||
enum session_state state;
|
||||
enum closing_reason reason;
|
||||
struct session_manager *mgr;
|
||||
struct session_manager_stat *mgr_stat;
|
||||
};
|
||||
/******************************************************************************
|
||||
* session set/get
|
||||
******************************************************************************/
|
||||
|
||||
void session_init(struct session *sess);
|
||||
void session_set_id(struct session *sess, uint64_t id);
|
||||
|
||||
void session_set_tuple(struct session *sess, const struct tuple6 *key);
|
||||
// session ID
|
||||
void session_set_id(struct session *sess, uint64_t id);
|
||||
uint64_t session_get_id(const struct session *sess);
|
||||
|
||||
// session tuple
|
||||
void session_set_tuple6(struct session *sess, const struct tuple6 *tuple);
|
||||
const struct tuple6 *session_get_tuple6(const struct session *sess);
|
||||
|
||||
// session tuple direction
|
||||
void session_set_tuple_direction(struct session *sess, enum flow_direction dir);
|
||||
enum flow_direction session_get_tuple6_direction(const struct session *sess);
|
||||
const char *session_get0_readable_addr(const struct session *sess);
|
||||
|
||||
// session direction
|
||||
void session_set_direction(struct session *sess, enum session_direction dir);
|
||||
void session_set_current_flow_direction(struct session *sess, enum flow_direction dir);
|
||||
void session_set_current_state(struct session *sess, enum session_state state);
|
||||
void session_set_type(struct session *sess, enum session_type type);
|
||||
void session_set_duplicate_traffic(struct session *sess);
|
||||
void session_set_closing_reason(struct session *sess, enum closing_reason reason);
|
||||
void session_inc_stat(struct session *sess, enum flow_direction dir, enum session_stat stat, uint64_t val);
|
||||
void session_set_timestamp(struct session *sess, enum session_timestamp type, uint64_t value);
|
||||
enum session_direction session_get_direction(const struct session *sess);
|
||||
|
||||
// session flow direction
|
||||
void session_set_current_flow_direction(struct session *sess, enum flow_direction dir);
|
||||
enum flow_direction session_get_current_flow_direction(const struct session *sess);
|
||||
|
||||
// session state
|
||||
void session_set_current_state(struct session *sess, enum session_state state);
|
||||
enum session_state session_get_current_state(const struct session *sess);
|
||||
|
||||
// session type
|
||||
void session_set_type(struct session *sess, enum session_type type);
|
||||
enum session_type session_get_type(const struct session *sess);
|
||||
|
||||
// session seen duplicate traffic
|
||||
void session_set_duplicate_traffic(struct session *sess);
|
||||
int session_has_duplicate_traffic(const struct session *sess);
|
||||
|
||||
// session closing reason
|
||||
void session_set_closing_reason(struct session *sess, enum closing_reason reason);
|
||||
enum closing_reason session_get_closing_reason(const struct session *sess);
|
||||
|
||||
// session stat
|
||||
void session_inc_stat(struct session *sess, enum flow_direction dir, enum session_stat stat, uint64_t val);
|
||||
uint64_t session_get_stat(const struct session *sess, enum flow_direction dir, enum session_stat stat);
|
||||
|
||||
// session timestamp
|
||||
void session_set_timestamp(struct session *sess, enum session_timestamp type, uint64_t value);
|
||||
uint64_t session_get_timestamp(const struct session *sess, enum session_timestamp type);
|
||||
|
||||
// session sids
|
||||
void session_clear_sids(struct session *sess, enum flow_direction dir);
|
||||
void session_set_sids(struct session *sess, enum flow_direction dir, const struct sids *sids);
|
||||
const struct sids *session_get_sids(const struct session *sess, enum flow_direction dir);
|
||||
|
||||
// session route ctx
|
||||
void session_clear_route_ctx(struct session *sess, enum flow_direction dir);
|
||||
void session_set_route_ctx(struct session *sess, enum flow_direction dir, const struct route_ctx *ctx);
|
||||
const struct route_ctx *session_get_route_ctx(const struct session *sess, enum flow_direction dir);
|
||||
|
||||
// session first packet
|
||||
void session_set_first_packet(struct session *sess, enum flow_direction dir, const struct packet *pkt);
|
||||
void session_set_current_packet(struct session *sess, const struct packet *pkt);
|
||||
const struct packet *session_get_first_packet(const struct session *sess, enum flow_direction dir);
|
||||
|
||||
// session current packet
|
||||
void session_set_current_packet(struct session *sess, const struct packet *pkt);
|
||||
const struct packet *session_get0_current_packet(const struct session *sess);
|
||||
const char *session_get0_current_payload(const struct session *sess, uint16_t *payload_len);
|
||||
|
||||
// session symmetric
|
||||
int session_is_symmetric(const struct session *sess, unsigned char *flag);
|
||||
|
||||
// session user data
|
||||
void session_set_user_data(struct session *sess, void *user_data);
|
||||
void *session_get_user_data(const struct session *sess);
|
||||
|
||||
// session tcp segment
|
||||
struct tcp_segment *session_get_tcp_segment(struct session *sess);
|
||||
void session_free_tcp_segment(struct session *sess, struct tcp_segment *seg);
|
||||
|
||||
@@ -129,6 +104,7 @@ typedef void session_ex_free_cb(struct session *sess, uint8_t idx, void *ex_ptr,
|
||||
* if key exist, not allow update, return original index.
|
||||
*/
|
||||
uint8_t session_get_ex_new_index(const char *key, session_ex_free_cb *free_cb, void *args);
|
||||
|
||||
/*
|
||||
* Support update ex_data.
|
||||
*
|
||||
@@ -147,15 +123,16 @@ void session_free_ex_data(struct session *sess, uint8_t idx);
|
||||
void session_free_all_ex_data(struct session *sess);
|
||||
|
||||
/******************************************************************************
|
||||
* debug
|
||||
* to string
|
||||
******************************************************************************/
|
||||
|
||||
const char *session_type_to_str(enum session_type type);
|
||||
const char *session_state_to_str(enum session_state state);
|
||||
const char *flow_direction_to_str(enum flow_direction dir);
|
||||
const char *closing_reason_to_str(enum closing_reason reason);
|
||||
void session_print(struct session *sess);
|
||||
const char *session_state_to_str(enum session_state state);
|
||||
const char *session_type_to_str(enum session_type type);
|
||||
const char *flow_direction_to_str(enum flow_direction dir);
|
||||
|
||||
int session_to_json(struct session *sess, char *buff, int size);
|
||||
void session_print(struct session *sess);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "session_priv.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
#include "tcp_reassembly.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
// max session number
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "session_priv.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "ipv4_utils.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "session_priv.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "macro.h"
|
||||
#include "ipv4_utils.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "session_priv.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "macro.h"
|
||||
#include "ipv4_utils.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "session_priv.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "ipv4_utils.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
#include "tcp_reassembly.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "session_priv.h"
|
||||
#include "session_def.h"
|
||||
#include "session_utils.h"
|
||||
|
||||
#define SESSION_KEY_IPV4_TCP(name) \
|
||||
struct tuple6 name; \
|
||||
@@ -57,7 +58,7 @@ TEST(SESSION, EX_NEW_INDEX)
|
||||
TEST(SESSION, EX_SET_GET)
|
||||
{
|
||||
struct session sess;
|
||||
memset(&sess, 0, sizeof(sess));
|
||||
session_init(&sess);
|
||||
uint8_t idx = session_get_ex_new_index("ex_set_get", NULL, NULL);
|
||||
session_set_ex_data(&sess, idx, (void *)0x1234);
|
||||
EXPECT_TRUE(session_get0_ex_data(&sess, idx) == (void *)0x1234);
|
||||
@@ -66,7 +67,7 @@ TEST(SESSION, EX_SET_GET)
|
||||
TEST(SESSION, EX_FREE_BY_RESET)
|
||||
{
|
||||
struct session sess;
|
||||
memset(&sess, 0, sizeof(sess));
|
||||
session_init(&sess);
|
||||
uint8_t idx = session_get_ex_new_index("ex_free_by_reset", free_ex_data, NULL);
|
||||
char *ptr = strdup("hello");
|
||||
session_set_ex_data(&sess, idx, ptr);
|
||||
@@ -76,7 +77,7 @@ TEST(SESSION, EX_FREE_BY_RESET)
|
||||
TEST(SESSION, EX_FREE_BY_CB)
|
||||
{
|
||||
struct session sess;
|
||||
memset(&sess, 0, sizeof(sess));
|
||||
session_init(&sess);
|
||||
uint8_t idx = session_get_ex_new_index("ex_free_by_cb", free_ex_data, NULL);
|
||||
char *ptr = strdup("hello");
|
||||
session_set_ex_data(&sess, idx, ptr);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_pool.h"
|
||||
#include "session_table.h"
|
||||
|
||||
@@ -112,17 +114,17 @@ TEST(SESSION_TABLE, OP_SESSION)
|
||||
sess1 = session_pool_pop(sess_pool);
|
||||
EXPECT_TRUE(sess1 != NULL);
|
||||
session_set_id(sess1, 1);
|
||||
session_set_tuple(sess1, &sess1_tup6);
|
||||
session_set_tuple6(sess1, &sess1_tup6);
|
||||
|
||||
sess2 = session_pool_pop(sess_pool);
|
||||
EXPECT_TRUE(sess2 != NULL);
|
||||
session_set_id(sess2, 2);
|
||||
session_set_tuple(sess2, &sess2_tup6);
|
||||
session_set_tuple6(sess2, &sess2_tup6);
|
||||
|
||||
sess3 = session_pool_pop(sess_pool);
|
||||
EXPECT_TRUE(sess3 != NULL);
|
||||
session_set_id(sess3, 3);
|
||||
session_set_tuple(sess3, &sess3_tup6);
|
||||
session_set_tuple6(sess3, &sess3_tup6);
|
||||
|
||||
session_table_add(sess_table, sess1);
|
||||
EXPECT_TRUE(session_table_get_count(sess_table) == 1);
|
||||
@@ -206,21 +208,21 @@ TEST(SESSION_TABLE, FIND_OLDEST_NEWEST)
|
||||
sess1 = session_pool_pop(sess_pool);
|
||||
EXPECT_TRUE(sess1 != NULL);
|
||||
session_set_id(sess1, 1);
|
||||
session_set_tuple(sess1, &sess1_tup6);
|
||||
session_set_tuple6(sess1, &sess1_tup6);
|
||||
session_table_add(sess_table, sess1);
|
||||
EXPECT_TRUE(session_table_find_lru(sess_table) == sess1);
|
||||
|
||||
sess2 = session_pool_pop(sess_pool);
|
||||
EXPECT_TRUE(sess2 != NULL);
|
||||
session_set_id(sess2, 2);
|
||||
session_set_tuple(sess2, &sess2_tup6);
|
||||
session_set_tuple6(sess2, &sess2_tup6);
|
||||
session_table_add(sess_table, sess2);
|
||||
EXPECT_TRUE(session_table_find_lru(sess_table) == sess1);
|
||||
|
||||
sess3 = session_pool_pop(sess_pool);
|
||||
EXPECT_TRUE(sess3 != NULL);
|
||||
session_set_id(sess3, 3);
|
||||
session_set_tuple(sess3, &sess3_tup6);
|
||||
session_set_tuple6(sess3, &sess3_tup6);
|
||||
session_table_add(sess_table, sess3);
|
||||
EXPECT_TRUE(session_table_find_lru(sess_table) == sess1);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "session_def.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_timer.h"
|
||||
|
||||
TEST(SESSION_TIMER, EXPIRE)
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// TCP state machine test: active -> closing
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "tcp_utils.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// TCP state machine test: init -> opening
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "ipv4_utils.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// TCP state machine test: init -> opening -> active -> closing -> closed
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// TCP state machine test: opening -> active
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// TCP state machine test: opening -> closing
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "tcp_utils.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// UDP state machine test: init -> opening -> active -> closing
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// UDP state machine test: init -> opening -> closing
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "ipv4_utils.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "ipv4_utils.h"
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "times.h"
|
||||
#include "session_priv.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
#include "session_utils.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include "test_packets.h"
|
||||
|
||||
struct session_manager_options opts = {
|
||||
|
||||
@@ -5,9 +5,6 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "packet_parse.h"
|
||||
#include "packet_layer.h"
|
||||
|
||||
/******************************************************************************
|
||||
* test packet: HTTP www.example.com
|
||||
******************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user