remove session_manager_subscribe_xxx() API; convert session closing events to pseudo packets

when a session is closed, use the packet manager to create a pseudo packet,
    set the session to be closed as packet Exdata, and schedule it to the packet forwarding stage.
    when the pseudo packet free, the session will be free.
This commit is contained in:
luwenpeng
2024-11-18 18:33:19 +08:00
parent 746d7fca06
commit c2e9275a9e
25 changed files with 210 additions and 378 deletions

View File

@@ -227,6 +227,8 @@ struct packet *packet_manager_build_udp_packet(struct packet_manager *pkt_mgr, c
const char *udp_payload, uint16_t udp_payload_len);
struct packet *packet_manager_build_l3_packet(struct packet_manager *pkt_mgr, const struct packet *origin_pkt,
uint8_t ip_proto, const char *l3_payload, uint16_t l3_payload_len);
struct packet *packet_manager_dup_packet(struct packet_manager *pkt_mgr, const struct packet *origin_pkt);
void packet_manager_free_packet(struct packet_manager *pkt_mgr, struct packet *pkt);
#ifdef __cplusplus
}

View File

@@ -130,7 +130,6 @@ int session_has_duplicate_traffic(const struct session *sess);
enum session_type session_get_type(const struct session *sess);
enum session_state session_get_current_state(const struct session *sess);
const struct packet *session_get_current_packet(const struct session *sess);
enum closing_reason session_get_closing_reason(const struct session *sess);
enum session_direction session_get_direction(const struct session *sess);
@@ -152,15 +151,7 @@ struct session_manager;
struct session_manager *module_to_session_manager(struct module *mod);
int session_manager_new_session_exdata_index(struct session_manager *sess_mgr, const char *name, exdata_free *func, void *arg);
// When the state is SESSION_STATE_CLOSED, the packet is NULL, and the session will be destroyed.
typedef void on_session_message_callback(struct session *sess, enum session_state state, struct packet *pkt, void *args);
// When the state is SESSION_STATE_CLOSED, the tcp_payload is NULL, and the session will be destroyed.
typedef void on_tcp_payload_callback(struct session *sess, enum session_state state, const char *tcp_payload, uint32_t tcp_payload_len, void *args);
int session_manager_subscribe_tcp(struct session_manager *sess_mgr, on_session_message_callback *cb, void *args);
int session_manager_subscribe_udp(struct session_manager *sess_mgr, on_session_message_callback *cb, void *args);
int session_manager_subscribe_control_packet(struct session_manager *sess_mgr, on_session_message_callback *cb, void *args);
int session_manager_subscribe_tcp_stream(struct session_manager *sess_mgr, on_tcp_payload_callback *cb, void *args);
struct session *packet_exdata_to_session(struct packet *pkt);
#ifdef __cplusplus
}