summaryrefslogtreecommitdiff
path: root/src/tsg_bridge.h
diff options
context:
space:
mode:
author刘学利 <[email protected]>2023-04-03 08:30:49 +0000
committer刘学利 <[email protected]>2023-04-03 08:30:49 +0000
commitb696e82879bcecc4559cf9828e00232ca7cc6541 (patch)
tree9d397f967881a2ef64f56447fffc8fd834cb8750 /src/tsg_bridge.h
parent8819217948c6717b1f57114d2c710f1fc612dd9c (diff)
TSG-13778 TSG master支持MAAT4
Diffstat (limited to 'src/tsg_bridge.h')
-rw-r--r--src/tsg_bridge.h160
1 files changed, 103 insertions, 57 deletions
diff --git a/src/tsg_bridge.h b/src/tsg_bridge.h
index 632028b..45f7636 100644
--- a/src/tsg_bridge.h
+++ b/src/tsg_bridge.h
@@ -1,10 +1,10 @@
#pragma once
#include <MESA/stream.h>
-#include <MESA/Maat_rule.h>
-#include "tsg_rule.h"
#include "app_label.h"
+#include "tsg_label.h"
+#include "tsg_rule.h"
#include "tsg_leaky_bucket.h"
#ifndef MAX_BRIDGE_NAME_LEN
@@ -15,24 +15,29 @@ enum BRIDGE_TYPE
{
BRIDGE_TYPE_SEND_CONN_SKETCH_DATA=0,
BRIDGE_TYPE_RECV_CONN_SKETCH_DATA,
- BRIDGE_TYPE_APP_IDENTIFY_RESULT,
- BRIDGE_TYPE_NOTIFY_FLAGS,
- BRIDGE_TYPE_NOTIFY_SHAPING_RESULT, //sync and async
- BRIDGE_TYPE_DATA_CONTEXT, //async
- BRIDGE_TYPE_ALL_CONTEXT, //async
+ BRIDGE_TYPE_SYNC_APP_IDENTIFY_RESULT,
+ BRIDGE_TYPE_SYNC_SESSION_FLAGS,
+ BRIDGE_TYPE_SHAPING_RESULT, //sync and async
+ BRIDGE_TYPE_SESSION_PROCESS_CONTEXT, //async
+ BRIDGE_TYPE_SESSION_ACTION_CONTEXT, //async
BRIDGE_TYPE_GATHER_APP_RESULT, //async
- BRIDGE_TYPE_POLICY_PRIORITY, //async
- BRIDGE_TYPE_SERVICE_CHAINING, //async
+ BRIDGE_TYPE_SERVICE_CHAINING_RESULT, //async
+ BRIDGE_TYPE_SECURITY_RESULT, //async
+ BRIDGE_TYPE_SESSION_ATTRIBUTE, //async
+ BRIDGE_TYPE_MAC_LINKINFO, //async
+ BRIDGE_TYPE_NAT_C2S_LINKINFO,
+ BRIDGE_TYPE_NAT_S2C_LINKINFO,
+ BRIDGE_TYPE_APP_LUA_RESULT,
+ BRIDGE_TYPE_BUSINESS_S3_FILENAME,
+ BRIDGE_TYPE_APP_BEHAVIOR_RESULT,
+ BRIDGE_TYPE_POLICY_ACTION_PARA_EXEC_RESULT,
+ BRIDGE_TYPE_ASYNC_SESSION_FLAGS,
+ BRIDGE_TYPE_APP_SIGNATURE_RESULT,
+ BRIDGE_TYPE_INTERCEPT_RESULT, //sync and async
+ BRIDGE_TYPE_SEGMENT_IDS, //async service_chaining or shping SID
BRIDGE_TYPE_MAX
};
-struct tm_hited_result
-{
- int sid;
- int result_num;
- struct Maat_rule_t result[MAX_RESULT_NUM];
-};
-
struct app_attributes
{
unsigned int app_id;
@@ -47,29 +52,13 @@ struct gather_app_result
struct app_attributes attributes[MAX_APP_ID_NUM];
};
-struct policy_priority_label
-{
- tsg_protocol_t proto; //enum _tsg_protocol (tsg_types.h)
- int domain_len;
- int result_type; //enum _PULL_RESULT_TYPE (tsg_rule.h)
- int security_result_num;
- union
- {
- char *http_url;
- char *quic_ua;
- void *para;
- };
- char domain[MAX_DOMAIN_LEN];
- struct Maat_rule_t security_result[MAX_RESULT_NUM];
-};
-
struct hited_app_para
{
int hited_app_id;
int after_n_packets;
};
-struct master_context
+struct session_runtime_process_context
{
unsigned char is_esni;
unsigned char is_hited_allow;
@@ -77,63 +66,120 @@ struct master_context
unsigned char is_app_link;
unsigned char sync_cb_state;
unsigned short timeout;
- tsg_protocol_t proto;
+ enum TSG_PROTOCOL proto;
int hited_app_id; // only app
unsigned int quic_version;
unsigned long session_flag;
- char *domain;
+ union
+ {
+ char *ssl_sni;
+ char *quic_sni;
+ char *dtls_sni;
+ char *http_host;
+ char *domain;
+ };
union
{
char *http_url;
char *quic_ua;
void *para;
};
- scan_status_t mid;
+ struct maat_state *mid;
struct hited_app_para hited_para; // l7 protocol and app
long long last_scan_time;
- struct Maat_rule_t *hited_result;
+ struct maat_rule *hited_result;
};
-struct tcpall_context
+struct session_runtime_action_context
{
char udp_data_dropme;
char set_latency_flag;
char direction;
char padding[5];
enum TSG_METHOD_TYPE method_type;
- tsg_protocol_t protocol;
+ enum TSG_PROTOCOL protocol;
union
{
struct leaky_bucket *bucket;
- long tamper_count;
+ long tamper_count;
int default_policy_after_n_packets;
struct hited_app_para hited_para;
void *para;
};
};
-struct udp_context
+struct udp_session_runtime_context
{
- struct master_context *data_entry;
- struct tcpall_context *all_entry;
+ struct session_runtime_process_context *srt_process_context;
+ struct session_runtime_action_context *srt_action_context;
};
-struct bridge_info
+struct session_runtime_attribute
{
- int id;
- char name[MAX_BRIDGE_NAME_LEN];
- stream_bridge_free_cb_t *free_cb;
- stream_bridge_sync_cb_t *sync_cb;
+ int http_action_file_size;
+ size_t n_fqdn_category_ids;
+ enum TSG_PROTOCOL proto;
+ long establish_latency_ms;
+ struct asn_info *client_asn;
+ struct asn_info *server_asn;
+ struct location_info *client_location;
+ struct location_info *server_location;
+ struct subscribe_id_info *client_subscribe_id;
+ struct subscribe_id_info *server_subscribe_id;
+ const char *ja3_fingerprint;
+ unsigned int fqdn_category_ids[MAX_CATEGORY_ID_NUM];
+ struct umts_user_info *user_info;
+ struct tunnel_endpoint *client_endpoint;
+ struct tunnel_endpoint *server_endpoint;
+ unsigned long session_flags;
};
-int tsg_init_bridge(const char *conffile);
-
-void free_context_label(const struct streaminfo *stream, int bridge_id, void *data);
-void free_tcpall_label(const struct streaminfo *stream, int bridge_id, void *data);
-void free_policy_label(const struct streaminfo *stream, int bridge_id, void *data);
-void free_shaping_result(const struct streaminfo *stream, int bridge_id, void *data);
-void free_gather_app_result(const struct streaminfo *stream, int bridge_id, void *data);
-void *tsg_get_xxx_from_bridge(const struct streaminfo *a_stream, int bridge_id);
-int tsg_set_xxx_to_bridge(const struct streaminfo *a_stream, int bridge_id, void *data);
+// init
+int tsg_bridge_init(const char *conffile);
+
+//send log
+void *session_mac_linkinfo_get(const struct streaminfo * a_stream);
+void *session_conn_sketch_notify_data_get(const struct streaminfo * a_stream);
+void *session_business_data_get(const struct streaminfo * a_stream);
+void *session_session_flags_get(const struct streaminfo * a_stream);
+void *session_application_behavior_get(const struct streaminfo * a_stream);
+void *session_mirrored_and_capture_packets_exec_result_get(const struct streaminfo * a_stream);
+void *session_lua_user_defined_attribute_get(const struct streaminfo * a_stream);
+void *session_nat_c2s_linkinfo_get(const struct streaminfo * a_stream);
+void *session_nat_s2c_linkinfo_get(const struct streaminfo * a_stream);
+
+void *session_control_segment_ids_get(const struct streaminfo *a_stream);
+int session_control_segment_ids_async(const struct streaminfo *a_stream, void *data);
+
+void session_matched_rules_free(const struct streaminfo * a_stream, TSG_SERVICE service, void * data);
+int session_matched_rules_async(const struct streaminfo * a_stream, TSG_SERVICE service, void * data);
+const struct matched_policy_rules *session_matched_rules_get(const struct streaminfo *a_stream, enum TSG_SERVICE service);
+int session_capture_packets_sync(const struct streaminfo *a_stream, struct maat_rule *results, int depth);
+int session_mirror_packets_sync(const struct streaminfo *a_stream, struct maat_rule *results, struct mirrored_vlan *vlan);
+
+// security
+void session_matched_rules_notify(const struct streaminfo * a_stream, TSG_SERVICE service, struct maat_rule *results, size_t n_results, int thread_seq);
+
+// session runtime attribute
+int srt_attribute_set_protocol(const struct streaminfo * a_stream, TSG_PROTOCOL protocol);
+int srt_attribute_set_flags(const struct streaminfo * a_stream, unsigned long s_flags);
+int srt_attribute_set_establish_latecy(const struct streaminfo * a_stream);
+int srt_attribute_set_ja3_fingprint(const struct streaminfo *a_stream, const char *ja3_fingerprint);
+int srt_attribute_set_reponse_size(const struct streaminfo *a_stream, int http_action_file_size);
+
+//gather app identify result
+int session_gather_app_results_async(const struct streaminfo * a_stream, void * data);
+void *session_gather_app_results_get(const struct streaminfo * a_stream);
+
+// session runtime do action context
+int session_runtime_action_context_async(const struct streaminfo *a_stream, void *data);
+const struct session_runtime_action_context *session_runtime_action_context_get(const struct streaminfo *a_stream);
+int srt_action_context_set_leaky_bucket(const struct streaminfo * a_stream, struct leaky_bucket * bucket, int thread_seq);
+int srt_action_context_set_l7_protocol(const struct streaminfo * a_stream, TSG_PROTOCOL protocol, int thread_seq);
+int srt_action_context_set_rule_method(const struct streaminfo * a_stream, enum TSG_METHOD_TYPE method_type, int thread_seq);
+int srt_action_context_set_after_n_packet(const struct streaminfo * a_stream, int after_n_packets, int thread_seq);
+int srt_action_context_set_hitted_app_id(const struct streaminfo * a_stream, int hited_app_id, int thread_seq);
+
+char srt_action_context_get_direction(const struct streaminfo * a_stream);