命中APP_ID时填写协议字段

调整流量统计
修正配置文件
This commit is contained in:
liuxueli
2020-01-17 16:06:21 +08:00
parent 4ba746a4b5
commit 8e53cecd2a
6 changed files with 27 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
[STATIC]
MAAT_MODE=2
MAAT_MODE=1
#EFFECTIVE_FLAG=
STAT_SWITCH=1
PERF_SWITCH=1
@@ -15,7 +15,7 @@ INC_CFG_DIR=tsgrule/inc/index/
FULL_CFG_DIR=tsgrule/full/index/
[DYNAMIC]
MAAT_MODE=2
MAAT_MODE=1
#EFFECTIVE_FLAG=
STAT_SWITCH=1
PERF_SWITCH=1

View File

@@ -6,7 +6,7 @@ CB_SUBSCRIBER_IP_TABLE=TSG_DYN_SUBSCRIBER_IP
[TSG_LOG]
MODE=1
NIC_NAME=enp8s0
NIC_NAME=lo
MAX_SERVICE=1
LOG_LEVEL=10
LOG_PATH=./tsglog/tsglog

View File

@@ -38,7 +38,7 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
#endif
char TSG_MASTER_VERSION_20200113=0;
char TSG_MASTER_VERSION_20200117=0;
const char *tsg_conffile="tsgconf/main.conf";
g_tsg_para_t g_tsg_para;
@@ -311,7 +311,7 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t
p_result=tsg_policy_decision_criteria(all_result, hit_num);
if(p_result!=NULL)
{
{
switch((unsigned char)p_result->action)
{
case TSG_ACTION_DENY:
@@ -335,6 +335,7 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t
{
*pme=dictator_malloc(thread_seq, sizeof(struct _master_context));
_context=(struct _master_context *)*pme;
_context->proto=identify_info.proto;
_context->hit_cnt=1;
_context->result=(struct Maat_rule_t *)dictator_malloc(thread_seq, sizeof(struct Maat_rule_t));
memcpy(_context->result, p_result, sizeof(struct Maat_rule_t));
@@ -345,6 +346,7 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t
case TSG_ACTION_BYPASS:
*pme=dictator_malloc(thread_seq, sizeof(struct _master_context));
_context=(struct _master_context *)*pme;
_context->proto=identify_info.proto;
_context->hit_cnt=1;
_context->result=(struct Maat_rule_t *)dictator_malloc(thread_seq, sizeof(struct Maat_rule_t));
memcpy(_context->result, p_result, sizeof(struct Maat_rule_t));
@@ -396,7 +398,10 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t
{
if(_context->hit_cnt>0 && _context->result!=NULL)
{
master_send_log(a_tcp, _context->result, _context->hit_cnt, NULL, thread_seq);
memset(&identify_info, 0, sizeof(identify_info));
identify_info.proto=_context->proto;
master_send_log(a_tcp, _context->result, _context->hit_cnt, &identify_info, thread_seq);
dictator_free(thread_seq, (void *)_context->result);
_context->result=NULL;
}
@@ -424,7 +429,7 @@ extern "C" int TSG_MASTER_INIT()
memset(&g_tsg_para, 0, sizeof(g_tsg_para));
MESA_load_profile_int_def(tsg_conffile, "SYSTEM","LOG_LEVEL", &level, 30);
MESA_load_profile_string_def(tsg_conffile, "SYSTEM","LOG_PATH", log_path, sizeof(log_path), NULL);
MESA_load_profile_string_def(tsg_conffile, "SYSTEM","LOG_PATH", log_path, sizeof(log_path), "tsglog/tsg_master");
g_tsg_para.logger=MESA_create_runtime_log_handle(log_path, level);
if(g_tsg_para.logger==NULL)

View File

@@ -51,6 +51,7 @@ typedef struct _policy_priority_label
struct _master_context
{
tsg_protocol_t proto;
int hit_cnt;
struct Maat_rule_t *result;
};

View File

@@ -314,7 +314,7 @@ struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile)
_instance=(struct tsg_log_instance_t *)calloc(1, sizeof(struct tsg_log_instance_t));
MESA_load_profile_int_def(conffile, "TSG_LOG", "LOG_LEVEL",&(level), 30);
MESA_load_profile_string_def(conffile, "TSG_LOG", "LOG_PATH", log_path, sizeof(log_path), NULL);
MESA_load_profile_string_def(conffile, "TSG_LOG", "LOG_PATH", log_path, sizeof(log_path), "./tsglog/tsglog");
_instance->logger=MESA_create_runtime_log_handle(log_path, level);
if(_instance->logger==NULL)

View File

@@ -130,25 +130,13 @@ static int _set_traffic_info(struct _traffic_info *from, struct _traffic_info *t
in_packets_id=STATIS_DEFAULT_IN_PACKETS;
out_bytes_id=STATIS_DEFAULT_OUT_BYTES;
out_packets_id=STATIS_DEFAULT_OUT_PACKETS;
con_num_sum+=from->con_num;
in_bytes_sum+=from->in_bytes;
in_packets_sum+=from->in_packets;
out_bytes_sum+=from->out_bytes;
out_packets_sum+=from->out_packets;
break;
case -1:
con_num_id=STATIS_TOTAL_CON_NUM;
con_num_id=STATIS_NEW_CON_NUM;
in_bytes_id=STATIS_TOTAL_IN_BYTES;
in_packets_id=STATIS_TOTAL_IN_PACKETS;
out_bytes_id=STATIS_TOTAL_OUT_BYTES;
out_packets_id=STATIS_TOTAL_OUT_PACKETS;
con_num_sum+=from->con_num;
in_bytes_sum+=from->in_bytes;
in_packets_sum+=from->in_packets;
out_bytes_sum+=from->out_bytes;
out_packets_sum+=from->out_packets;
break;
default:
return 0;
@@ -180,21 +168,25 @@ static void *tsg_statistic_thread(void *arg)
memset(&total_traffic_info, 0, sizeof(total_traffic_info));
memset(&default_traffic_info, 0, sizeof(default_traffic_info));
value=0;
sapp_get_platform_opt(SPO_TCP_STREAM_NEW, (void *)&value, &value_len);
total_traffic_info.con_num+=value;
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_NEW_CON_NUM], FS_OP_SET, value);
_set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_BYPASS], &policy_traffic_info, TSG_ACTION_BYPASS, thread_num);
_set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_DENY], &policy_traffic_info, TSG_ACTION_DENY, thread_num);
_set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_MONITOR], &policy_traffic_info, TSG_ACTION_MONITOR, thread_num);
_set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_INTERCEPT], &policy_traffic_info, TSG_ACTION_INTERCEPT, thread_num);
value=0;
sapp_get_platform_opt(SPO_TCP_STREAM_ESTAB, (void *)&value, &value_len);
total_traffic_info.con_num+=value;
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_ESTABLISHED_CON_NUM], FS_OP_SET, value);
value=0;
sapp_get_platform_opt(SPO_TCP_STREAM_CLOSE, (void *)&value, &value_len);
total_traffic_info.con_num+=value;
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_CLOSE_CON_NUM], FS_OP_SET, value);
value=0;
sapp_get_platform_opt(SPO_TCP_STREAM_NEW, (void *)&value, &value_len);
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[STATIS_NEW_CON_NUM], FS_OP_SET, value);
total_traffic_info.con_num+=value;
value_len=sizeof(total_traffic_info.in_bytes);
sapp_get_platform_opt(SPO_TOTAL_INBOUND_BYTE, (void *)&total_traffic_info.in_bytes, &value_len);
value_len=sizeof(total_traffic_info.in_packets);
@@ -204,16 +196,11 @@ static void *tsg_statistic_thread(void *arg)
sapp_get_platform_opt(SPO_TOTAL_OUTBOUND_BYTE, (void *)&total_traffic_info.out_bytes, &value_len);
value_len=sizeof(total_traffic_info.out_packets);
sapp_get_platform_opt(SPO_TOTAL_OUTBOUND_PKT, (void *)&total_traffic_info.out_packets, &value_len);
_set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_BYPASS], &policy_traffic_info, TSG_ACTION_BYPASS, thread_num);
_set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_DENY], &policy_traffic_info, TSG_ACTION_DENY, thread_num);
_set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_MONITOR], &policy_traffic_info, TSG_ACTION_MONITOR, thread_num);
_set_traffic_info(g_tsg_statis_para.traffic_info[TSG_ACTION_INTERCEPT], &policy_traffic_info, TSG_ACTION_INTERCEPT, thread_num);
_set_traffic_info(&total_traffic_info, NULL, -1, 0);
_set_traffic_info(&total_traffic_info, NULL, -1, 1);
_get_traffic_info(&total_traffic_info, &policy_traffic_info, &default_traffic_info);
_set_traffic_info(&default_traffic_info, NULL, TSG_ACTION_NONE, 0);
_set_traffic_info(&default_traffic_info, NULL, TSG_ACTION_NONE, 1);
FS_passive_output(g_tsg_statis_para.fs2_handle);