diff options
| author | liuxueli <[email protected]> | 2020-11-16 12:30:44 +0600 |
|---|---|---|
| committer | liuxueli <[email protected]> | 2020-11-16 12:30:44 +0600 |
| commit | 7a5aea443753141d659b967ae0f558633d851d86 (patch) | |
| tree | 29788f183822b7fbbbd20cc9822e6d2c9489a2a0 | |
| parent | 701eb1c9b60cf00bb1042d323b142233aecc7c20 (diff) | |
增加命中策略并不发日志的计数
| -rw-r--r-- | src/tsg_entry.cpp | 7 | ||||
| -rw-r--r-- | src/tsg_entry.h | 5 | ||||
| -rw-r--r-- | src/tsg_send_log.cpp | 29 | ||||
| -rw-r--r-- | src/tsg_statistic.cpp | 21 |
4 files changed, 48 insertions, 14 deletions
diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index 9d0b357..8b1b0f5 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -56,7 +56,12 @@ id2field_t g_tsg_fs2_field[TSG_FS2_MAX]={{TLD_TYPE_UNKNOWN, TSG_FS2_TCP_LINKS, " {TLD_TYPE_UNKNOWN, TSG_FS2_INTERCEPT, "intercept"}, {TLD_TYPE_UNKNOWN, TSG_FS2_SUCCESS_LOG, "success_log"}, {TLD_TYPE_UNKNOWN, TSG_FS2_FAILED_LOG, "failed_log"}, - {TLD_TYPE_UNKNOWN, TSG_FS2_DROP_LOG, "drop_log"} + {TLD_TYPE_UNKNOWN, TSG_FS2_DROP_LOG, "drop_log"}, + {TLD_TYPE_UNKNOWN, TSG_FS2_ABORT_ALLOW, "abort_allow"}, + {TLD_TYPE_UNKNOWN, TSG_FS2_ABORT_DENY, "abort_deny"}, + {TLD_TYPE_UNKNOWN, TSG_FS2_ABORT_MONITOR, "abort_monitor"}, + {TLD_TYPE_UNKNOWN, TSG_FS2_ABORT_INTERCEPT, "abort_intercept"}, + {TLD_TYPE_UNKNOWN, TSG_FS2_ABORT_UNKNOWN, "abort_unknown"} }; id2field_t g_tsg_proto_name2id[PROTO_MAX]={{TLD_TYPE_UNKNOWN, PROTO_UNKONWN, "unknown"}, diff --git a/src/tsg_entry.h b/src/tsg_entry.h index 337a5a2..76bb044 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -57,6 +57,11 @@ enum TSG_FS2_TYPE{ TSG_FS2_SUCCESS_LOG, TSG_FS2_FAILED_LOG, TSG_FS2_DROP_LOG, + TSG_FS2_ABORT_ALLOW, + TSG_FS2_ABORT_DENY, + TSG_FS2_ABORT_MONITOR, + TSG_FS2_ABORT_INTERCEPT, + TSG_FS2_ABORT_UNKNOWN, TSG_FS2_MAX }; diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index 5991fa5..dec40c4 100644 --- a/src/tsg_send_log.cpp +++ b/src/tsg_send_log.cpp @@ -34,6 +34,30 @@ const id2field_t tld_type[TLD_TYPE_MAX]={{TLD_TYPE_UNKNOWN, TLD_TYPE_UNKNOWN, " extern "C" int MESA_get_dev_ipv4(const char *device, int *ip_add); +static int action2fs_id(int action) +{ + switch(action) + { + case TSG_ACTION_DENY: + return TSG_FS2_ABORT_DENY; + break; + case TSG_ACTION_BYPASS: + return TSG_FS2_ABORT_ALLOW; + break; + case TSG_ACTION_MONITOR: + return TSG_FS2_ABORT_MONITOR; + break; + case TSG_ACTION_INTERCEPT: + return TSG_FS2_ABORT_INTERCEPT; + break; + default: + return TSG_FS2_ABORT_UNKNOWN; + break; + } + + return TSG_FS2_ABORT_UNKNOWN; +} + int is_multi_hit_same_policy(struct Maat_rule_t *result, int *policy_id, int *policy_id_num) { return 0; @@ -692,6 +716,7 @@ struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile) int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handle, tsg_log_t *log_msg, int thread_id) { + int fs_id=0; int i=0,status=0; char *payload=NULL; int repeat_cnt=0; @@ -766,7 +791,9 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl log_msg->result[i].service_id, (_instance->level<RLOG_LV_FATAL ? (log_msg->a_stream==NULL ? "" : printaddr(&(log_msg->a_stream->addr), thread_id)) : "") ); - + + fs_id=action2fs_id((int)log_msg->result[i].action); + FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[fs_id], 0, FS_OP_ADD, 1); continue; break; case LOG_ALL: diff --git a/src/tsg_statistic.cpp b/src/tsg_statistic.cpp index 5f2c798..13d5d53 100644 --- a/src/tsg_statistic.cpp +++ b/src/tsg_statistic.cpp @@ -90,6 +90,8 @@ int tsg_set_policy_flow(struct streaminfo *a_stream, Maat_rule_t *p_result, int static int _get_traffic_info(struct _traffic_info *total, struct _traffic_info *policy, struct _traffic_info *out) { + struct _traffic_info *acc=NULL; + if(total!=NULL && policy!=NULL && out!=NULL) { out->con_num=total->con_num-policy->con_num; @@ -98,18 +100,13 @@ static int _get_traffic_info(struct _traffic_info *total, struct _traffic_info * out->out_bytes=total->out_bytes-policy->out_bytes; out->out_packets=total->out_packets-policy->out_packets; - if(out->con_num-g_tsg_statis_para.default_total_info.con_num<0 - || out->in_bytes-g_tsg_statis_para.default_total_info.in_bytes<0 - || out->in_packets-g_tsg_statis_para.default_total_info.in_packets<0 - || out->out_bytes-g_tsg_statis_para.default_total_info.out_bytes<0 - || out->out_packets-g_tsg_statis_para.default_total_info.out_packets<0) - { - memcpy(out, &g_tsg_statis_para.default_total_info, sizeof(struct _traffic_info)); - } - else - { - memcpy(&g_tsg_statis_para.default_total_info, out, sizeof(struct _traffic_info)); - } + acc=&g_tsg_statis_para.default_total_info; + + acc->con_num=(out->con_num-acc->con_num)>0 ? out->con_num : acc->con_num; + acc->in_bytes=(out->in_bytes-acc->in_bytes)>0 ? out->in_bytes: acc->in_bytes; + acc->in_packets=(out->in_packets-acc->in_packets)>0 ? out->in_packets: acc->in_packets; + acc->out_bytes=(out->out_bytes-acc->out_bytes)>0 ? out->out_bytes: acc->out_bytes; + acc->out_packets=(out->out_packets-acc->out_packets)>0 ? out->out_packets: acc->out_packets; } return 0; |
