This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/src/session/session_private.h

128 lines
4.5 KiB
C
Raw Normal View History

#ifndef _SESSION_PRIVATE_H
#define _SESSION_PRIVATE_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include "list.h"
#include "tuple.h"
#include "packet_private.h"
#include "timeout.h"
#include "uthash.h"
#include "session.h"
#include "tcp_reassembly.h"
#include "session_manager.h"
#define EX_DATA_MAX_COUNT 16
// tuple6 str format: "src_addr:src_port -> dst_addr:dst_port, proto: ip_proto, domain: domain"
// tuple6 max len: 46 + 1 + 5 + 4 + 46 + 1 + 5 + 9 + 1 + 10 + 20 = 107
#define TUPLE6_STR_SIZE 108
struct tcp_half
{
struct tcp_reassembly *assembler;
struct tcp_segment in_order;
uint32_t seq;
uint32_t ack;
uint8_t flags;
};
struct session
{
int dup;
uint64_t id;
uint64_t stats[MAX_DIRECTION][MAX_STAT];
uint64_t timestamps[MAX_TIMESTAMP];
struct tuple6 tuple;
char tuple_str[TUPLE6_STR_SIZE];
enum session_direction tuple_dir;
enum session_direction cur_dir;
enum session_type type;
enum session_state state;
enum closing_reason reason;
const struct packet *first_pkt[MAX_DIRECTION];
const struct packet *curr_pkt;
void *ex_data[EX_DATA_MAX_COUNT];
void *user_data;
struct tcp_half tcp_halfs[MAX_DIRECTION];
struct timeout timeout; // used for timer
struct list_head lru; // used for lru queue
struct list_head free; // used for free queue
struct list_head evicte; // used for evicte queue
UT_hash_handle hh; // used for hash table
struct session_manager_stat *mgr_stat;
};
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);
const struct tuple6 *session_get_tuple(const struct session *sess);
void session_set_tuple_direction(struct session *sess, enum session_direction dir);
enum session_direction session_get_tuple_direction(const struct session *sess);
void session_set_current_direction(struct session *sess, enum session_direction dir);
void session_set_state(struct session *sess, enum session_state state);
void session_set_type(struct session *sess, enum session_type type);
void session_set_dup_traffic(struct session *sess);
void session_set_closing_reason(struct session *sess, enum closing_reason reason);
void session_inc_stat(struct session *sess, enum session_direction dir, enum session_stat stat, uint64_t val);
void session_set_timestamp(struct session *sess, enum session_timestamp type, uint64_t value);
void session_set_1st_packet(struct session *sess, enum session_direction dir, const struct packet *pkt);
void session_set_current_packet(struct session *sess, const struct packet *pkt);
const struct packet *session_get_current_packet(const struct session *sess);
void session_set_user_data(struct session *sess, void *user_data);
void *session_get_user_data(const struct session *sess);
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);
/******************************************************************************
* debug
******************************************************************************/
void session_dump(struct session *sess);
#ifdef __cpluscplus
}
#endif
#endif