session manager: support session timeouts & tcp dupkt filter & udp eviction filter
This commit is contained in:
@@ -8,32 +8,65 @@ extern "C"
|
||||
|
||||
#include "session.h"
|
||||
|
||||
// #define SESSION_LOG_ERROR(format, ...) void(0)
|
||||
#ifndef SESSION_LOG_ERROR
|
||||
#define SESSION_LOG_ERROR(format, ...) \
|
||||
fprintf(stderr, "ERROR (session), " format "\n", ##__VA_ARGS__);
|
||||
#endif
|
||||
// #define SESSION_LOG_DEBUG(format, ...) void(0)
|
||||
#ifndef SESSION_LOG_DEBUG
|
||||
#define SESSION_LOG_DEBUG(format, ...) \
|
||||
fprintf(stderr, "DEBUG (session), " format "\n", ##__VA_ARGS__);
|
||||
#endif
|
||||
|
||||
struct session_manager_config
|
||||
{
|
||||
// max session number
|
||||
uint64_t max_tcp_session_num;
|
||||
uint64_t max_udp_session_num;
|
||||
|
||||
// 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
|
||||
uint64_t tcp_timeout_discard; // seconds, Range: 1-15,999,999
|
||||
|
||||
// UDP timeout
|
||||
uint64_t udp_timeout_data; // seconds, Range: 1-15,999,999
|
||||
|
||||
// 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;
|
||||
struct session_manager *session_manager_create(uint64_t max_session_num);
|
||||
struct session_manager *session_manager_create(struct session_manager_config *config);
|
||||
void session_manager_destroy(struct session_manager *mgr);
|
||||
|
||||
void session_manager_set_timeout_toclosing(struct session_manager *mgr, uint64_t timeout_ms);
|
||||
void session_manager_set_timeout_toclosed(struct session_manager *mgr, uint64_t timeout_ms);
|
||||
|
||||
struct session *session_manager_lookup(struct session_manager *mgr, const struct packet *pkt);
|
||||
// return null: invalid tuple6 or tcp first packet is not syn
|
||||
struct session *session_manager_update(struct session_manager *mgr, const struct packet *pkt);
|
||||
struct session *session_manager_expire(struct session_manager *mgr);
|
||||
struct session *session_manager_evicte(struct session_manager *mgr);
|
||||
|
||||
// for debug
|
||||
uint64_t session_manager_get_sessions(struct session_manager *mgr, enum session_type type, enum session_state state);
|
||||
// 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);
|
||||
// return interval (seconds) to next required update, return 0 if no session
|
||||
uint64_t session_manager_get_expire_interval(struct session_manager *mgr);
|
||||
uint64_t session_manager_get_session_number(struct session_manager *mgr, enum session_type type, enum session_state state);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user