185 lines
6.8 KiB
C
185 lines
6.8 KiB
C
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include "tuple.h"
|
|
#include "stellar/session.h"
|
|
|
|
#define SESSION_MANAGER_LOG_FATAL(format, ...) STELLAR_LOG_FATAL(__thread_local_logger, "session manager", format, ##__VA_ARGS__)
|
|
#define SESSION_MANAGER_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "session manager", format, ##__VA_ARGS__)
|
|
#define SESSION_MANAGER_LOG_DEBUG(format, ...) STELLAR_LOG_DEBUG(__thread_local_logger, "session manager", format, ##__VA_ARGS__)
|
|
#define SESSION_MANAGER_LOG_INFO(format, ...) STELLAR_LOG_INFO(__thread_local_logger, "session manager", format, ##__VA_ARGS__)
|
|
|
|
struct session_manager_config
|
|
{
|
|
uint64_t instance_id;
|
|
uint16_t thread_num;
|
|
uint64_t session_id_seed;
|
|
uint64_t tcp_session_max;
|
|
uint64_t udp_session_max;
|
|
|
|
uint8_t evict_old_on_tcp_table_limit; // range: [0, 1]
|
|
uint8_t evict_old_on_udp_table_limit; // range: [0, 1]
|
|
|
|
uint64_t expire_period_ms; // range: [0, 60000] (ms)
|
|
uint64_t expire_batch_max; // range: [1, 1024]
|
|
|
|
struct
|
|
{
|
|
uint64_t init; // range: [1, 60000] (ms)
|
|
uint64_t handshake; // range: [1, 60000] (ms)
|
|
uint64_t data; // range: [1, 15999999000] (ms)
|
|
uint64_t half_closed; // range: [1, 604800000] (ms)
|
|
uint64_t time_wait; // range: [1, 600000] (ms)
|
|
uint64_t discard_default; // range: [1, 15999999000] (ms)
|
|
uint64_t unverified_rst; // range: [1, 600000] (ms)
|
|
} tcp_timeout_ms;
|
|
|
|
struct
|
|
{
|
|
uint64_t data; // range: [1, 15999999000] (ms)
|
|
uint64_t discard_default; // range: [1, 15999999000] (ms)
|
|
} udp_timeout_ms;
|
|
|
|
struct
|
|
{
|
|
uint8_t enable; // range: [0, 1]
|
|
uint32_t capacity; // range: [1, 4294967295]
|
|
uint32_t time_window_ms; // range: [1, 60000] (ms)
|
|
double error_rate; // range: [0.0, 1.0]
|
|
} duplicated_packet_bloom_filter;
|
|
|
|
struct
|
|
{
|
|
uint8_t enable; // range: [0, 1]
|
|
uint32_t capacity; // range: [1, 4294967295]
|
|
uint32_t time_window_ms; // range: [1, 60000] (ms)
|
|
double error_rate; // range: [0.0, 1.0]
|
|
} evicted_session_bloom_filter;
|
|
|
|
struct
|
|
{
|
|
uint8_t enable; // range: [0, 1]
|
|
uint32_t timeout_ms; // range: [1, 60000] (ms)
|
|
uint32_t buffered_segments_max; // range: [2, 4096]
|
|
} tcp_reassembly;
|
|
};
|
|
|
|
struct session_manager_stat
|
|
{
|
|
// TCP session
|
|
uint64_t history_tcp_sessions;
|
|
uint64_t tcp_sess_used;
|
|
uint64_t tcp_sess_opening;
|
|
uint64_t tcp_sess_active;
|
|
uint64_t tcp_sess_closing;
|
|
uint64_t tcp_sess_discard;
|
|
uint64_t tcp_sess_closed;
|
|
|
|
// UDP session
|
|
uint64_t history_udp_sessions;
|
|
uint64_t udp_sess_used;
|
|
uint64_t udp_sess_opening;
|
|
uint64_t udp_sess_active;
|
|
uint64_t udp_sess_closing;
|
|
uint64_t udp_sess_discard;
|
|
uint64_t udp_sess_closed;
|
|
|
|
// Evicted session
|
|
uint64_t tcp_sess_evicted; // sum
|
|
uint64_t udp_sess_evicted; // sum
|
|
|
|
// Packet
|
|
uint64_t udp_pkts_bypass_table_full; // sum
|
|
uint64_t tcp_pkts_bypass_table_full; // sum
|
|
uint64_t tcp_pkts_bypass_session_not_found; // sum
|
|
uint64_t tcp_pkts_bypass_duplicated; // sum
|
|
uint64_t udp_pkts_bypass_duplicated; // sum
|
|
uint64_t udp_pkts_bypass_session_evicted; // sum
|
|
|
|
// TCP segments
|
|
uint64_t tcp_segs_input; // sum
|
|
uint64_t tcp_segs_consumed; // sum
|
|
uint64_t tcp_segs_timeout; // sum
|
|
uint64_t tcp_segs_retransmited; // sum
|
|
uint64_t tcp_segs_overlapped; // sum
|
|
uint64_t tcp_segs_omitted_too_many; // sum
|
|
uint64_t tcp_segs_inorder; // sum
|
|
uint64_t tcp_segs_reordered; // sum
|
|
uint64_t tcp_segs_buffered; // sum
|
|
uint64_t tcp_segs_freed; // sum
|
|
} __attribute__((aligned(64)));
|
|
|
|
enum session_scan_flags
|
|
{
|
|
SESSION_SCAN_TYPE = 1 << 0,
|
|
SESSION_SCAN_STATE = 1 << 1,
|
|
|
|
SESSION_SCAN_SIP = 1 << 2,
|
|
SESSION_SCAN_DIP = 1 << 3,
|
|
|
|
SESSION_SCAN_SPORT = 1 << 4,
|
|
SESSION_SCAN_DPORT = 1 << 5,
|
|
|
|
SESSION_SCAN_CREATE_TIME = 1 << 6,
|
|
SESSION_SCAN_LAST_PKT_TIME = 1 << 7,
|
|
};
|
|
|
|
struct session_scan_opts
|
|
{
|
|
// required
|
|
uint32_t flags;
|
|
uint32_t cursor;
|
|
uint32_t count;
|
|
|
|
// optional
|
|
enum session_type type;
|
|
enum session_state state;
|
|
|
|
uint32_t addr_family; // AF_INET or AF_INET6
|
|
union ip_address src_addr[2]; // network byte order
|
|
union ip_address dst_addr[2]; // network byte order
|
|
uint16_t src_port; // network byte order
|
|
uint16_t dst_port; // network byte order
|
|
|
|
uint64_t create_time_ms[2];
|
|
uint64_t last_pkt_time_ms[2];
|
|
};
|
|
|
|
// new/free/print config
|
|
struct session_manager_config *session_manager_config_new(const char *toml_file);
|
|
void session_manager_config_free(struct session_manager_config *sess_mgr_cfg);
|
|
void session_manager_config_print(struct session_manager_config *sess_mgr_cfg);
|
|
|
|
// new/free runtime
|
|
struct session_manager_runtime;
|
|
struct session_manager_runtime *session_manager_runtime_new(const struct session_manager_config *sess_mgr_cfg, uint64_t now_ms);
|
|
void session_manager_runtime_free(struct session_manager_runtime *sess_mgr_rt);
|
|
|
|
// new/free/lookup/update/clean session
|
|
struct session *session_manager_runtime_new_session(struct session_manager_runtime *sess_mgr_rt, const struct packet *pkt, uint64_t now_ms);
|
|
void session_manager_runtime_free_session(struct session_manager_runtime *sess_mgr_rt, struct session *sess);
|
|
struct session *session_manager_runtime_lookup_session_by_packet(struct session_manager_runtime *sess_mgr_rt, const struct packet *pkt);
|
|
struct session *session_manager_runtime_lookup_session_by_id(struct session_manager_runtime *sess_mgr_rt, uint64_t sess_id);
|
|
int session_manager_runtime_update_session(struct session_manager_runtime *sess_mgr_rt, struct session *sess, const struct packet *pkt, uint64_t now_ms);
|
|
struct session *session_manager_runtime_get_expired_session(struct session_manager_runtime *sess_mgr_rt, uint64_t now_ms);
|
|
struct session *session_manager_runtime_get_evicted_session(struct session_manager_runtime *sess_mgr_rt);
|
|
uint64_t session_manager_runtime_clean_session(struct session_manager_runtime *sess_mgr_rt, uint64_t now_ms, struct session *cleaned_sess[], uint64_t array_size);
|
|
|
|
// stat
|
|
struct session_manager_stat *session_manager_runtime_get_stat(struct session_manager_runtime *sess_mgr_rt);
|
|
void session_manager_runtime_print_stat(struct session_manager_runtime *sess_mgr_rt);
|
|
|
|
// scan
|
|
uint64_t session_manager_runtime_scan(const struct session_manager_runtime *sess_mgr_rt, const struct session_scan_opts *opts, uint64_t mached_sess_ids[], uint64_t array_size);
|
|
|
|
// duplicated packet
|
|
void session_manager_runtime_record_duplicated_packet(struct session_manager_runtime *sess_mgr_rt, const struct packet *pkt);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|