refactor: session module (split to define/utils/pool/table/timer/transition/manager)
This commit is contained in:
139
src/session/session_utils.h
Normal file
139
src/session/session_utils.h
Normal file
@@ -0,0 +1,139 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "stellar/session.h"
|
||||
|
||||
/******************************************************************************
|
||||
* session set/get
|
||||
******************************************************************************/
|
||||
|
||||
void session_init(struct session *sess);
|
||||
|
||||
// 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);
|
||||
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);
|
||||
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);
|
||||
|
||||
/******************************************************************************
|
||||
* session ex data
|
||||
******************************************************************************/
|
||||
|
||||
typedef void session_ex_free_cb(struct session *sess, uint8_t idx, void *ex_ptr, void *arg);
|
||||
|
||||
/*
|
||||
* the exdata prodoced by user, and comsumed by same user.
|
||||
* so, the exdata is not shared by different user.
|
||||
* otherwise, the exdata need dup by refer count, and free by refer count.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* if key exist: run free_cb free old value, then set new value.
|
||||
* if not run free_cb, old value will be memory leak.
|
||||
* if not allow update, new value will be memory leak.
|
||||
* if key not exist: set new value.
|
||||
*/
|
||||
void session_set_ex_data(struct session *sess, uint8_t idx, void *val);
|
||||
void *session_get0_ex_data(const struct session *sess, uint8_t idx);
|
||||
/*
|
||||
* after set ex_data, the owner of ex_data is session, so user should not free it directly.
|
||||
* if user want to free ex_data, should use session_free_ex_data.
|
||||
*/
|
||||
void session_free_ex_data(struct session *sess, uint8_t idx);
|
||||
void session_free_all_ex_data(struct session *sess);
|
||||
|
||||
/******************************************************************************
|
||||
* to string
|
||||
******************************************************************************/
|
||||
|
||||
const char *closing_reason_to_str(enum closing_reason reason);
|
||||
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
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user