完成链接统计信息功能

monitor日志等到CLOSE状态发送日志
This commit is contained in:
liuxueli
2020-01-07 13:04:00 +08:00
parent 03109fb27e
commit 2546578fd5
4 changed files with 163 additions and 143 deletions

View File

@@ -3,6 +3,14 @@
#include <MESA/Maat_rule.h> #include <MESA/Maat_rule.h>
#define TSG_ACTION_NONE 0x00
#define TSG_ACTION_MONITOR 0x01
#define TSG_ACTION_INTERCEPT 0x02
#define TSG_ACTION_DENY 0x10
#define TSG_ACTION_MANIPULATE 0x30
#define TSG_ACTION_BYPASS 0x80
#define TSG_ACTION_MAX 0x80
enum TSG_ETHOD_TYPE enum TSG_ETHOD_TYPE
{ {
TSG_METHOD_TYPE_UNKNOWN=0, TSG_METHOD_TYPE_UNKNOWN=0,

View File

@@ -10,6 +10,7 @@
#include "tsg_rule.h" #include "tsg_rule.h"
#include "tsg_entry.h" #include "tsg_entry.h"
#include "tsg_send_log.h" #include "tsg_send_log.h"
#include "tsg_statistic.h"
#include "tsg_send_log_internal.h" #include "tsg_send_log_internal.h"
#ifdef __cplusplus #ifdef __cplusplus
@@ -52,54 +53,32 @@ static void free_policy_label(int thread_seq, void *project_req_value)
project_req_value=NULL; project_req_value=NULL;
} }
#if 0 static int master_send_log(struct streaminfo *a_stream, struct Maat_rule_t *p_result, int result_num, struct _identify_info *identify_info, int thread_seq)
static int is_ip_policy(Maat_rule_t *p_result, char *protocol, int len, int thread_seq)
{ {
int ret=0; tsg_log_t log_msg;
cJSON *item=NULL; char *domain_field_name=NULL;
char *service_defined=NULL; char *schema_field_name=NULL;
cJSON *user_define_object=NULL; struct TLD_handle_t *TLD_handle=NULL;
if(p_result->serv_def_len>MAX_SERVICE_DEFINE_LEN) TLD_handle=TLD_create(thread_seq);
if(identify_info!=NULL)
{ {
service_defined=dictator_malloc(thread_seq, p_result->serv_def_len+1); schema_field_name=log_field_id2name(g_tsg_log_instance, LOG_COMMON_SCHAME_TYPE);
ret=Maat_read_rule(g_tsg_maat_feather, p_result, MAAT_RULE_SERV_DEFINE, service_defined, p_result->serv_def_len+1); TLD_append(TLD_handle, schema_field_name, (void *)((identify_info->proto==PROTO_HTTP) ? "HTTP" : "SSL"), TLD_TYPE_STRING);
assert(ret==p_result->serv_def_len+1);
user_define_object=cJSON_Parse(service_defined); domain_field_name=log_field_id2name(g_tsg_log_instance, ((identify_info->proto==PROTO_HTTP) ? LOG_HTTP_HOST : LOG_SSL_SNI));
} TLD_append(TLD_handle, domain_field_name, (void *)identify_info->domain, TLD_TYPE_STRING);
else
{
user_define_object=cJSON_Parse(p_result->service_defined);
} }
if(user_define_object!=NULL) log_msg.a_stream=a_stream;
{ log_msg.result=p_result;
item=cJSON_GetObjectItem(user_define_object, "protocol"); log_msg.result_num=result_num;
if(item!=NULL && item->valuestring!=NULL) tsg_send_log(g_tsg_log_instance, TLD_handle, &log_msg, thread_seq);
{ tsg_set_policy_flow(a_stream, p_result, thread_seq);
memcpy(protocol, item->valuestring, (len>strlen(item->valuestring)) ? strlen(item->valuestring): len);
}
item=cJSON_GetObjectItem(user_define_object, "method"); return 1;
if((item==NULL) || ((strncasecmp(item->valuestring, "http", strlen(item->valuestring)))!=0 && (strncasecmp(item->valuestring, "ssl", strlen(item->valuestring)))!=0))
{
ret=1;
}
cJSON_Delete(user_define_object);
user_define_object=NULL;
}
if(service_defined!=NULL)
{
dictator_free(thread_seq, service_defined);
service_defined=NULL;
}
return ret;
} }
#endif
static struct Maat_rule_t *tsg_policy_decision_criteria(Maat_rule_t *result, int result_num) static struct Maat_rule_t *tsg_policy_decision_criteria(Maat_rule_t *result, int result_num)
{ {
int i=0; int i=0;
@@ -133,19 +112,16 @@ static struct Maat_rule_t *tsg_policy_decision_criteria(Maat_rule_t *result, int
extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet) extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet)
{ {
int send_log=0,identify_flag=0; int identify_flag=0;
int ret=0,hit_num=0; int ret=0,hit_num=0;
int state=APP_STATE_DROPME; int state=APP_STATE_DROPME;
scan_status_t mid=NULL; scan_status_t mid=NULL;
char *domain_field_name=NULL;
char *schema_field_name=NULL;
Maat_rule_t *p_result=NULL; Maat_rule_t *p_result=NULL;
Maat_rule_t *q_result=NULL; Maat_rule_t *q_result=NULL;
tsg_log_t log_msg;
struct TLD_handle_t *TLD_handle=NULL;
struct _identify_info identify_info; struct _identify_info identify_info;
Maat_rule_t all_result[MAX_RESULT_NUM]; Maat_rule_t all_result[MAX_RESULT_NUM];
policy_priority_label_t *priority_label=NULL; policy_priority_label_t *priority_label=NULL;
struct _master_context *_context=(struct _master_context *)*pme;
switch(a_tcp->opstate) switch(a_tcp->opstate)
{ {
@@ -226,27 +202,41 @@ printaddr(&a_tcp->addr, thread_seq), ret);
switch((unsigned char)p_result->action) switch((unsigned char)p_result->action)
{ {
case TSG_ACTION_DENY: case TSG_ACTION_DENY:
send_log=1;
MESA_kill_tcp(a_tcp, a_packet); MESA_kill_tcp(a_tcp, a_packet);
state|=APP_STATE_DROPPKT|APP_STATE_KILL_OTHER;
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_DENY], 0, FS_OP_ADD, 1); FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_DENY], 0, FS_OP_ADD, 1);
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_DEBUG, "DENY", "Hit deny policy, policy_id: %d action: %d addr: %s", MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_DEBUG, "DENY", "Hit deny policy, policy_id: %d action: %d addr: %s",
p_result[0].config_id, p_result[0].action, printaddr(&a_tcp->addr, thread_seq)); p_result[0].config_id, p_result[0].action, printaddr(&a_tcp->addr, thread_seq));
master_send_log(a_tcp, p_result, 1, ((identify_flag==1) ? &identify_info : NULL), thread_seq);
state|=APP_STATE_DROPPKT|APP_STATE_KILL_OTHER;
break; break;
case TSG_ACTION_MONITOR: case TSG_ACTION_MONITOR:
if(q_result!=NULL && (p_result==q_result)) if(q_result!=NULL && (p_result==q_result))
{ {
send_log=1; *pme=dictator_malloc(thread_seq, sizeof(struct _master_context));
_context=(struct _master_context *)*pme;
_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));
state=APP_STATE_GIVEME;
} }
break; break;
case TSG_ACTION_BYPASS: case TSG_ACTION_BYPASS:
send_log=1; *pme=dictator_malloc(thread_seq, sizeof(struct _master_context));
state|=APP_STATE_KILL_OTHER; //TODO _context=(struct _master_context *)*pme;
_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));
state=APP_STATE_GIVEME|APP_STATE_KILL_OTHER;
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_BYPASS], 0, FS_OP_ADD, 1); FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_BYPASS], 0, FS_OP_ADD, 1);
break; break;
case TSG_ACTION_INTERCEPT: case TSG_ACTION_INTERCEPT:
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_INTERCEPT], 0, FS_OP_ADD, 1); FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_INTERCEPT], 0, FS_OP_ADD, 1);
tsg_set_policy_flow(a_tcp, p_result, thread_seq);
priority_label=(policy_priority_label_t *)dictator_malloc(thread_seq, sizeof(policy_priority_label_t)); priority_label=(policy_priority_label_t *)dictator_malloc(thread_seq, sizeof(policy_priority_label_t));
priority_label->result_num=1; priority_label->result_num=1;
@@ -272,28 +262,19 @@ printaddr(&a_tcp->addr, thread_seq), ret);
assert(0); assert(0);
break; break;
} }
if(send_log==1 && p_result->do_log>0)
{
TLD_handle=TLD_create(thread_seq);
if(identify_flag==1)
{
schema_field_name=log_field_id2name(g_tsg_log_instance, LOG_COMMON_SCHAME_TYPE);
TLD_append(TLD_handle, schema_field_name, (void *)((identify_info.proto==PROTO_HTTP) ? "HTTP" : "SSL"), TLD_TYPE_STRING);
domain_field_name=log_field_id2name(g_tsg_log_instance, ((identify_info.proto==PROTO_HTTP) ? LOG_HTTP_HOST : LOG_SSL_SNI));
TLD_append(TLD_handle, domain_field_name, (void *)identify_info.domain, TLD_TYPE_STRING);
}
log_msg.a_stream=a_tcp;
log_msg.result=p_result;
log_msg.result_num=1;
tsg_send_log(g_tsg_log_instance, TLD_handle, &log_msg, thread_seq);
}
} }
break; break;
case OP_STATE_DATA: case OP_STATE_DATA:
case OP_STATE_CLOSE: case OP_STATE_CLOSE:
if(_context!=NULL)
{
if(_context->hit_cnt>0 && _context->result!=NULL)
{
master_send_log(a_tcp, _context->result, _context->hit_cnt, NULL, thread_seq);
dictator_free(thread_seq, (void *)_context->result);
_context->result=NULL;
}
}
default: default:
break; break;
} }

View File

@@ -5,15 +5,6 @@
#include <MESA/field_stat2.h> #include <MESA/field_stat2.h>
#include "tsg_rule.h" #include "tsg_rule.h"
#define TSG_ACTION_NONE 0x00
#define TSG_ACTION_MONITOR 0x01
#define TSG_ACTION_INTERCEPT 0x02
#define TSG_ACTION_DENY 0x10
#define TSG_ACTION_MANIPULATE 0x30
#define TSG_ACTION_BYPASS 0x80
#define TSG_ACTION_MAX 0x80
enum TSG_FS2_TYPE{ enum TSG_FS2_TYPE{
TSG_FS2_LINKS=0, TSG_FS2_LINKS=0,
TSG_FS2_BYPASS, TSG_FS2_BYPASS,
@@ -43,6 +34,11 @@ typedef struct _policy_priority_label
Maat_rule_t result[MAX_RESULT_NUM]; Maat_rule_t result[MAX_RESULT_NUM];
}policy_priority_label_t; }policy_priority_label_t;
struct _master_context
{
int hit_cnt;
struct Maat_rule_t *result;
};
typedef struct _tsg_para typedef struct _tsg_para
{ {
@@ -66,7 +62,7 @@ typedef enum _tsg_statis_field_id
STATIS_ENTRANCE_ID=1, STATIS_ENTRANCE_ID=1,
STATIS_TOTAL_CON_NUM, STATIS_TOTAL_CON_NUM,
STATIS_NEW_CON_NUM, STATIS_NEW_CON_NUM,
STATIS_LIVE_CON_NUM, STATIS_ESTABLISHED_CON_NUM,
STATIS_CLOSE_CON_NUM, STATIS_CLOSE_CON_NUM,
STATIS_TOTAL_IN_BYTES, STATIS_TOTAL_IN_BYTES,
STATIS_TOTAL_OUT_BYTES, STATIS_TOTAL_OUT_BYTES,
@@ -121,8 +117,9 @@ struct _traffic_info
typedef struct _tsg_statistic typedef struct _tsg_statistic
{ {
int cycle; int cycle;
int fs_line_id;
int fs_field_id[STATIS_MAX]; int fs_field_id[STATIS_MAX];
struct _traffic_info *traffic_info[TSG_ACTION_MAX]; struct _traffic_info *traffic_info[TSG_ACTION_MAX+1];
screen_stat_handle_t fs2_handle; screen_stat_handle_t fs2_handle;
}tsg_statis_para_t; }tsg_statis_para_t;

View File

@@ -14,6 +14,8 @@ tsg_statis_para_t g_tsg_statis_para;
int tsg_set_policy_flow(struct streaminfo *a_stream, Maat_rule_t *p_result, int thread_seq) int tsg_set_policy_flow(struct streaminfo *a_stream, Maat_rule_t *p_result, int thread_seq)
{ {
unsigned long long value=0;
int value_len=sizeof(unsigned long long);
struct _traffic_info *traffic_info=NULL; struct _traffic_info *traffic_info=NULL;
if(g_tsg_statis_para.cycle<=0) if(g_tsg_statis_para.cycle<=0)
@@ -26,15 +28,39 @@ int tsg_set_policy_flow(struct streaminfo *a_stream, Maat_rule_t *p_result, int
return -1; return -1;
} }
traffic_info=&(g_tsg_statis_para.traffic_info[(int)p_result->action][thread_seq]); traffic_info=&(g_tsg_statis_para.traffic_info[(unsigned char)p_result->action][thread_seq]);
traffic_info->con_num++; traffic_info->con_num++;
traffic_info->in_bytes+=a_stream->ptcpdetail->clientbytes;
traffic_info->in_packets+=a_stream->ptcpdetail->clientpktnum;
traffic_info->out_bytes+=a_stream->ptcpdetail->serverbytes; value=0;
traffic_info->out_packets+=a_stream->ptcpdetail->serverpktnum; MESA_get_stream_opt(a_stream, MSO_TOTAL_INBOUND_BYTE, (void *)&value, &value_len);
traffic_info->in_bytes+=value;
value=0;
MESA_get_stream_opt(a_stream, MSO_TOTAL_INBOUND_PKT, (void *)&value, &value_len);
traffic_info->in_packets+=value;
value=0;
MESA_get_stream_opt(a_stream, MSO_TOTAL_OUTBOUND_BYTE, (void *)&value, &value_len);
traffic_info->out_bytes+=value;
value=0;
MESA_get_stream_opt(a_stream, MSO_TOTAL_OUTBOUND_PKT, (void *)&value, &value_len);
traffic_info->out_packets+=value;
return 0;
}
static int _get_traffic_info(struct _traffic_info *total, struct _traffic_info *policy, struct _traffic_info *out)
{
if(total!=NULL && policy!=NULL && out!=NULL)
{
out->con_num=total->con_num-policy->con_num;
out->in_bytes=total->in_bytes-policy->in_bytes;
out->in_packets=total->in_packets-policy->in_packets;
out->out_bytes=total->out_bytes-policy->out_bytes;
out->out_packets=total->out_packets-policy->out_packets;
}
return 0; return 0;
} }
@@ -129,24 +155,24 @@ static int _set_traffic_info(struct _traffic_info *from, struct _traffic_info *t
break; break;
} }
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_field_id[con_num_id], 0, FS_OP_SET, con_num_sum); FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[con_num_id], FS_OP_SET, con_num_sum);
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_field_id[in_bytes_id], 0, FS_OP_SET, in_bytes_sum); FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[in_bytes_id], FS_OP_SET, in_bytes_sum);
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_field_id[in_packets_id], 0, FS_OP_SET, in_packets_sum); FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[in_packets_id], FS_OP_SET, in_packets_sum);
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_field_id[out_bytes_id], 0, FS_OP_SET, out_bytes_sum); FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[out_bytes_id], FS_OP_SET, out_bytes_sum);
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_field_id[out_packets_id], 0, FS_OP_SET, out_packets_sum); FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_line_id, g_tsg_statis_para.fs_field_id[out_packets_id], FS_OP_SET, out_packets_sum);
return 0; return 0;
} }
static void *tsg_statistic_thread(void *arg) static void *tsg_statistic_thread(void *arg)
{ {
long long value=0; long long value=0;
int value_len=sizeof(value); int value_len=sizeof(long long);
int thread_num=get_thread_count(); int thread_num=get_thread_count();
struct _traffic_info policy_traffic_info; struct _traffic_info policy_traffic_info;
struct _traffic_info total_traffic_info; struct _traffic_info total_traffic_info;
struct _traffic_info default_traffic_info; struct _traffic_info default_traffic_info;
FS_start(g_tsg_para.fs2_handle); FS_start(g_tsg_statis_para.fs2_handle);
while(1) while(1)
{ {
@@ -155,38 +181,42 @@ static void *tsg_statistic_thread(void *arg)
memset(&default_traffic_info, 0, sizeof(default_traffic_info)); memset(&default_traffic_info, 0, sizeof(default_traffic_info));
value=0; value=0;
value_len=sizeof(value);
sapp_get_platform_opt(SPO_TCP_STREAM_NEW, (void *)&value, &value_len); 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_field_id[STATIS_NEW_CON_NUM], 0, FS_OP_SET, value);
total_traffic_info.con_num+=value; 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);
value=0; value=0;
value_len=sizeof(value); sapp_get_platform_opt(SPO_TCP_STREAM_ESTAB, (void *)&value, &value_len);
sapp_get_platform_opt(SPO_TCP_STREAM_LIVE, (void *)&value, &value_len);
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_field_id[STATIS_LIVE_CON_NUM], 0, FS_OP_SET, value);
total_traffic_info.con_num+=value; 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; value=0;
value_len=sizeof(value);
sapp_get_platform_opt(SPO_TCP_STREAM_CLOSE, (void *)&value, &value_len); sapp_get_platform_opt(SPO_TCP_STREAM_CLOSE, (void *)&value, &value_len);
FS_operate(g_tsg_statis_para.fs2_handle, g_tsg_statis_para.fs_field_id[STATIS_CLOSE_CON_NUM], 0, FS_OP_SET, value);
total_traffic_info.con_num+=value; 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_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);
sapp_get_platform_opt(SPO_TOTAL_INBOUND_PKT, (void *)&total_traffic_info.in_packets, &value_len);
value_len=sizeof(total_traffic_info.out_bytes); value_len=sizeof(total_traffic_info.out_bytes);
sapp_get_platform_opt(SPO_TOTAL_EGRESS_BYTE, (void *)&total_traffic_info.out_bytes, &value_len); sapp_get_platform_opt(SPO_TOTAL_OUTBOUND_BYTE, (void *)&total_traffic_info.out_bytes, &value_len);
value_len=sizeof(total_traffic_info.out_packets);
value_len=sizeof(total_traffic_info.out_bytes); sapp_get_platform_opt(SPO_TOTAL_OUTBOUND_PKT, (void *)&total_traffic_info.out_packets, &value_len);
sapp_get_platform_opt(SPO_TOTAL_EGRESS_BYTE, (void *)&total_traffic_info.out_bytes, &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_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_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_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(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, 0);
_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, 0);
FS_passive_output(g_tsg_statis_para.fs2_handle);
sleep(g_tsg_statis_para.cycle); sleep(g_tsg_statis_para.cycle);
} }
@@ -205,7 +235,7 @@ int tsg_statistic_init(const char *conffile, void *logger)
memset(&g_tsg_statis_para, 0, sizeof(g_tsg_statis_para)); memset(&g_tsg_statis_para, 0, sizeof(g_tsg_statis_para));
thread_num=get_thread_count(); thread_num=get_thread_count();
for(i=0; i<TSG_ACTION_MAX; i++) for(i=0; i<TSG_ACTION_MAX+1; i++)
{ {
g_tsg_statis_para.traffic_info[i]=(struct _traffic_info *)calloc(1, sizeof(struct _traffic_info)*thread_num); g_tsg_statis_para.traffic_info[i]=(struct _traffic_info *)calloc(1, sizeof(struct _traffic_info)*thread_num);
} }
@@ -226,7 +256,7 @@ int tsg_statistic_init(const char *conffile, void *logger)
value=1;//Rewrite value=1;//Rewrite
FS_set_para(g_tsg_statis_para.fs2_handle, PRINT_MODE, &value, sizeof(value)); FS_set_para(g_tsg_statis_para.fs2_handle, PRINT_MODE, &value, sizeof(value));
value=1;//Do not create stat thread value=0;//Do not create stat thread
FS_set_para(g_tsg_statis_para.fs2_handle, CREATE_THREAD, &value, sizeof(value)); FS_set_para(g_tsg_statis_para.fs2_handle, CREATE_THREAD, &value, sizeof(value));
FS_set_para(g_tsg_statis_para.fs2_handle, STAT_CYCLE, &g_tsg_statis_para.cycle, sizeof(g_tsg_statis_para.cycle)); FS_set_para(g_tsg_statis_para.fs2_handle, STAT_CYCLE, &g_tsg_statis_para.cycle, sizeof(g_tsg_statis_para.cycle));
@@ -239,45 +269,49 @@ int tsg_statistic_init(const char *conffile, void *logger)
FS_set_para(g_tsg_statis_para.fs2_handle, STATS_SERVER_PORT,&(fs_server_port), sizeof(fs_server_port)); FS_set_para(g_tsg_statis_para.fs2_handle, STATS_SERVER_PORT,&(fs_server_port), sizeof(fs_server_port));
} }
g_tsg_statis_para.fs_field_id[STATIS_ENTRANCE_ID]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"entrance_id"); value=FS_OUTPUT_INFLUX_LINE;
g_tsg_statis_para.fs_field_id[STATIS_TOTAL_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"total_conn_num"); FS_set_para(g_tsg_statis_para.fs2_handle, STATS_FORMAT, &value, sizeof(value));
g_tsg_statis_para.fs_field_id[STATIS_NEW_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"new_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_LIVE_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"live_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_CLOSE_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"close_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_TOTAL_IN_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"total_in_bytes");
g_tsg_statis_para.fs_field_id[STATIS_TOTAL_OUT_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"total_out_bytes");
g_tsg_statis_para.fs_field_id[STATIS_TOTAL_IN_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"total_in_packets");
g_tsg_statis_para.fs_field_id[STATIS_TOTAL_OUT_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"total_out_packets");
g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"default_conn_num"); g_tsg_statis_para.fs_field_id[STATIS_NEW_CON_NUM]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"new_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_IN_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"default_in_bytes"); g_tsg_statis_para.fs_field_id[STATIS_ESTABLISHED_CON_NUM]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, (char *)"established_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_OUT_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"default_out_bytes"); g_tsg_statis_para.fs_field_id[STATIS_CLOSE_CON_NUM]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"close_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_IN_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"default_in_packets"); g_tsg_statis_para.fs_field_id[STATIS_TOTAL_IN_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"total_in_bytes");
g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_OUT_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"default_out_packets"); g_tsg_statis_para.fs_field_id[STATIS_TOTAL_OUT_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"total_out_bytes");
g_tsg_statis_para.fs_field_id[STATIS_TOTAL_IN_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"total_in_packets");
g_tsg_statis_para.fs_field_id[STATIS_TOTAL_OUT_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"total_out_packets");
g_tsg_statis_para.fs_field_id[STATIS_ALLOW_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"allow_conn_num"); g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_CON_NUM]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"default_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_ALLOW_IN_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"allow_in_bytes"); g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_IN_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"default_in_bytes");
g_tsg_statis_para.fs_field_id[STATIS_ALLOW_OUT_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"allow_out_bytes"); g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_OUT_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"default_out_bytes");
g_tsg_statis_para.fs_field_id[STATIS_ALLOW_IN_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"allow_in_packets"); g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_IN_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"default_in_packets");
g_tsg_statis_para.fs_field_id[STATIS_ALLOW_OUT_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"allow_out_packets"); g_tsg_statis_para.fs_field_id[STATIS_DEFAULT_OUT_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"default_out_packets");
g_tsg_statis_para.fs_field_id[STATIS_DENY_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"deny_conn_num"); g_tsg_statis_para.fs_field_id[STATIS_ALLOW_CON_NUM]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"allow_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_DENY_IN_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"deny_in_bytes"); g_tsg_statis_para.fs_field_id[STATIS_ALLOW_IN_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"allow_in_bytes");
g_tsg_statis_para.fs_field_id[STATIS_DENY_OUT_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"deny_out_bytes"); g_tsg_statis_para.fs_field_id[STATIS_ALLOW_OUT_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"allow_out_bytes");
g_tsg_statis_para.fs_field_id[STATIS_DENY_IN_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"deny_in_packets"); g_tsg_statis_para.fs_field_id[STATIS_ALLOW_IN_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"allow_in_packets");
g_tsg_statis_para.fs_field_id[STATIS_DENY_OUT_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"deny_out_packets"); g_tsg_statis_para.fs_field_id[STATIS_ALLOW_OUT_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"allow_out_packets");
g_tsg_statis_para.fs_field_id[STATIS_MONITOR_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"monitor_conn_num"); g_tsg_statis_para.fs_field_id[STATIS_DENY_CON_NUM]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"deny_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_MONITOR_IN_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"monitor_in_bytes"); g_tsg_statis_para.fs_field_id[STATIS_DENY_IN_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"deny_in_bytes");
g_tsg_statis_para.fs_field_id[STATIS_MONITOR_OUT_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"monitor_out_bytes"); g_tsg_statis_para.fs_field_id[STATIS_DENY_OUT_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"deny_out_bytes");
g_tsg_statis_para.fs_field_id[STATIS_MONITOR_IN_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"monitor_in_packets"); g_tsg_statis_para.fs_field_id[STATIS_DENY_IN_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"deny_in_packets");
g_tsg_statis_para.fs_field_id[STATIS_MONITOR_OUT_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"monitor_out_packets"); g_tsg_statis_para.fs_field_id[STATIS_DENY_OUT_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"deny_out_packets");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_CON_NUM]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"intercept_conn_num"); g_tsg_statis_para.fs_field_id[STATIS_MONITOR_CON_NUM]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"monitor_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_IN_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"intercept_in_bytes"); g_tsg_statis_para.fs_field_id[STATIS_MONITOR_IN_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"monitor_in_bytes");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_OUT_BYTES]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"intercept_out_bytes"); g_tsg_statis_para.fs_field_id[STATIS_MONITOR_OUT_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"monitor_out_bytes");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_IN_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"intercept_in_packets"); g_tsg_statis_para.fs_field_id[STATIS_MONITOR_IN_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"monitor_in_packets");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_OUT_PACKETS]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, (char *)"intercept_out_packets"); g_tsg_statis_para.fs_field_id[STATIS_MONITOR_OUT_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"monitor_out_packets");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_CON_NUM]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"intercept_conn_num");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_IN_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"intercept_in_bytes");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_OUT_BYTES]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"intercept_out_bytes");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_IN_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"intercept_in_packets");
g_tsg_statis_para.fs_field_id[STATIS_INTERCEPT_OUT_PACKETS]=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, (char *)"intercept_out_packets");
g_tsg_statis_para.fs_line_id=FS_register(g_tsg_statis_para.fs2_handle, FS_STYLE_LINE, FS_CALC_CURRENT, (const char *)"TRAFFIC");
pthread_t stat_thread_t; pthread_t stat_thread_t;
pthread_create(&stat_thread_t, NULL, tsg_statistic_thread, NULL); pthread_create(&stat_thread_t, NULL, tsg_statistic_thread, NULL);