2023-12-13 19:20:34 +08:00
|
|
|
#ifndef _SESSION_MANAGER_H
|
|
|
|
|
#define _SESSION_MANAGER_H
|
|
|
|
|
|
|
|
|
|
#ifdef __cpluscplus
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "session.h"
|
2024-01-26 14:41:40 +08:00
|
|
|
#include "log.h"
|
2023-12-13 19:20:34 +08:00
|
|
|
|
2024-01-26 14:41:40 +08:00
|
|
|
#define SESSION_LOG_ERROR(format, ...) LOG_ERROR("session", format, ##__VA_ARGS__)
|
|
|
|
|
#define SESSION_LOG_DEBUG(format, ...) LOG_DEBUG("session", format, ##__VA_ARGS__)
|
2023-12-13 19:20:34 +08:00
|
|
|
|
2024-03-08 14:51:21 +08:00
|
|
|
struct session_manager_options
|
2024-01-17 11:47:55 +08:00
|
|
|
{
|
|
|
|
|
// max session number
|
|
|
|
|
uint64_t max_tcp_session_num;
|
|
|
|
|
uint64_t max_udp_session_num;
|
|
|
|
|
|
2024-01-26 14:13:54 +08:00
|
|
|
// session overload
|
|
|
|
|
uint8_t tcp_overload_evict_old_sess; // 1: evict old session, 0: bypass new session
|
|
|
|
|
uint8_t udp_overload_evict_old_sess; // 1: evict old session, 0: bypass new session
|
|
|
|
|
|
2024-01-17 11:47:55 +08:00
|
|
|
// TCP timeout
|
|
|
|
|
uint64_t tcp_timeout_init; // seconds, Range: 1-60
|
|
|
|
|
uint64_t tcp_timeout_handshake; // seconds, Range: 1-60
|
|
|
|
|
uint64_t tcp_timeout_data; // seconds, Range: 1-15,999,999
|
|
|
|
|
uint64_t tcp_timeout_half_closed; // seconds, Range: 1-604,800
|
2024-01-23 14:30:46 +08:00
|
|
|
uint64_t tcp_timeout_time_wait; // seconds, Range: 1-600
|
2024-01-17 11:47:55 +08:00
|
|
|
uint64_t tcp_timeout_discard; // seconds, Range: 1-15,999,999
|
2023-12-13 19:20:34 +08:00
|
|
|
|
2024-01-17 11:47:55 +08:00
|
|
|
// UDP timeout
|
|
|
|
|
uint64_t udp_timeout_data; // seconds, Range: 1-15,999,999
|
2023-12-19 10:47:26 +08:00
|
|
|
|
2024-01-17 11:47:55 +08:00
|
|
|
// TCP duplicate packet filter
|
|
|
|
|
uint8_t tcp_dupkt_filter_enable;
|
|
|
|
|
uint64_t tcp_dupkt_filter_capacity;
|
|
|
|
|
uint64_t tcp_dupkt_filter_timeout; // seconds, Range: 1-60
|
|
|
|
|
double tcp_dupkt_filter_error_rate;
|
|
|
|
|
|
|
|
|
|
// UDP eviction filter
|
|
|
|
|
uint8_t udp_eviction_filter_enable;
|
|
|
|
|
uint64_t udp_eviction_filter_capacity;
|
|
|
|
|
uint64_t udp_eviction_filter_timeout; // seconds, Range: 1-60
|
|
|
|
|
double udp_eviction_filter_error_rate;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct session_manager;
|
2024-03-08 14:51:21 +08:00
|
|
|
struct session_manager *session_manager_new(struct session_manager_options *opts);
|
2024-03-08 14:20:36 +08:00
|
|
|
void session_manager_free(struct session_manager *mgr);
|
2023-12-13 19:20:34 +08:00
|
|
|
|
2024-01-17 11:47:55 +08:00
|
|
|
// only use the packet six-tuple to find the session, not update it
|
|
|
|
|
struct session *session_manager_lookup_sesssion(struct session_manager *mgr, const struct packet *pkt);
|
|
|
|
|
/*
|
|
|
|
|
* Return NULL in the following cases:
|
|
|
|
|
* 1.not a TCP or UDP packet
|
|
|
|
|
* 2.TCP packet miss session but no syn packet seen
|
|
|
|
|
* 3.TCP duplicate packet
|
|
|
|
|
* 4.TCP discards packets
|
|
|
|
|
* 5.UDP evict packet
|
|
|
|
|
* pakcet will not update the session and needs to be fast forwarded
|
|
|
|
|
*/
|
|
|
|
|
struct session *session_manager_update_session(struct session_manager *mgr, const struct packet *pkt);
|
|
|
|
|
struct session *session_manager_get_expired_session(struct session_manager *mgr);
|
|
|
|
|
struct session *session_manager_get_evicted_session(struct session_manager *mgr);
|
2024-01-25 16:08:55 +08:00
|
|
|
// return 0: have already timeout session
|
|
|
|
|
// return >0: next expire interval
|
2024-01-17 11:47:55 +08:00
|
|
|
uint64_t session_manager_get_expire_interval(struct session_manager *mgr);
|
2023-12-19 10:47:26 +08:00
|
|
|
|
2024-03-08 14:25:01 +08:00
|
|
|
struct session_manager_stat
|
2024-01-25 16:08:55 +08:00
|
|
|
{
|
|
|
|
|
uint64_t tcp_sess_num;
|
|
|
|
|
uint64_t tcp_opening_sess_num;
|
|
|
|
|
uint64_t tcp_active_sess_num;
|
|
|
|
|
uint64_t tcp_closing_sess_num;
|
|
|
|
|
|
|
|
|
|
uint64_t udp_sess_num;
|
|
|
|
|
uint64_t udp_opening_sess_num;
|
|
|
|
|
uint64_t udp_active_sess_num;
|
|
|
|
|
uint64_t udp_closing_sess_num;
|
2024-01-26 14:13:54 +08:00
|
|
|
|
|
|
|
|
uint64_t tcp_overload_evict_old_sess_num;
|
|
|
|
|
uint64_t tcp_overload_evict_new_sess_num;
|
|
|
|
|
uint64_t udp_overload_evict_old_sess_num;
|
|
|
|
|
uint64_t udp_overload_evict_new_sess_num;
|
2024-01-25 16:08:55 +08:00
|
|
|
};
|
|
|
|
|
|
2024-03-08 14:25:01 +08:00
|
|
|
void session_manager_print_stat(struct session_manager *mgr);
|
|
|
|
|
void session_manager_get_stat(struct session_manager *mgr, struct session_manager_stat *out);
|
2024-01-23 14:30:46 +08:00
|
|
|
|
2023-12-13 19:20:34 +08:00
|
|
|
#ifdef __cpluscplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|