7 Commits

Author SHA1 Message Date
liuxueli
2a25c20cea 控制日志输出,在FATAL模式下不调用printaddr 2021-04-19 20:21:26 +08:00
刘学利
ab097e3bff 命中策略后返回GIVEME,处理链接上后续的DNS请求
用户自定义没有符合的欺骗IP时,串联环境丢弃真实应答包
2021-04-17 13:38:01 +00:00
杨威
badd5547da Update fw_dns_plug.cpp 2020-12-25 15:08:19 +08:00
杨威
95bdca7514 Merge branch 'patch-1' into 'master'
Update .gitlab-ci.yml testing源仅debug版开启asan

See merge request tango/fw_dns_plug!7
2020-10-30 23:22:39 +08:00
杨威
9e4ed53bb1 Update .gitlab-ci.yml testing源仅debug版开启asan 2020-10-30 22:56:20 +08:00
杨威
4942106aab Merge branch 'patch-1' into 'master'
Update travis.sh, ASAN using devtoolset-7

See merge request tango/fw_dns_plug!6
2020-10-14 18:32:51 +08:00
杨威
28cfd57e98 Update travis.sh, ASAN using devtoolset-7 2020-10-14 15:54:09 +08:00
3 changed files with 49 additions and 26 deletions

View File

@@ -67,7 +67,6 @@ develop_build_release:
BUILD_TYPE: RelWithDebInfo
PACKAGE: 1
UPLOAD_RPM: 1
ASAN_OPTION: ADDRESS
TESTING_VERSION_BUILD: 1
PULP3_REPO_NAME: tsg-testing-x86_64.el7
PULP3_DIST_NAME: tsg-testing-x86_64.el7

View File

@@ -37,6 +37,11 @@ if [ -n "${INSTALL_DEPENDENCY_LIBRARY}" ]; then
yum install -y $INSTALL_DEPENDENCY_LIBRARY
source /etc/profile.d/framework.sh
fi
if [ $ASAN_OPTION ];then
source /opt/rh/devtoolset-7/enable
fi
mkdir build || true
cd build

View File

@@ -35,6 +35,10 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
}
#endif
#ifndef PRINTADDR
#define PRINTADDR(a, b) ((b)<RLOG_LV_FATAL ? printaddr(&(a->addr), a->threadnum) : "")
#endif
char *g_fw_dns_conffile=(char *)"tsgconf/main.conf";
char FW_DNS_PLUG_VERSION_20191220=0;
@@ -112,7 +116,7 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
p_result->service_defined,
(char *)dns_info->query_question.qname,
dns_info->query_question.qtype,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
}
else
@@ -131,7 +135,7 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
tmp_buff,
(char *)dns_info->query_question.qname,
dns_info->query_question.qtype,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
}
@@ -147,7 +151,7 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
(tmp_buff==NULL) ? p_result->service_defined : tmp_buff,
(char *)dns_info->query_question.qname,
dns_info->query_question.qtype,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
if(tmp_buff!=NULL)
@@ -156,7 +160,7 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
tmp_buff=NULL;
}
return PROT_STATE_GIVEME;
return PROT_STATE_GIVEME|PROT_STATE_DROPPKT;
}
item=cJSON_GetObjectItem(object, "method");
@@ -168,7 +172,7 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
switch(method_type)
{
case TSG_METHOD_TYPE_DROP:
state=PROT_STATE_DROPME|PROT_STATE_DROPPKT;
state=PROT_STATE_GIVEME|PROT_STATE_DROPPKT;
break;
case TSG_METHOD_TYPE_REDIRECTION:
if(g_fw_dns_plug_info.mode==0 && dns_info->hdr_info.qr==1) //mirror
@@ -240,10 +244,27 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
payload_len=build_cheat_pkt(cheat_pkt_payload, MAX_CHEAT_PKT_PAYLOAD_LEN, &dns_info->query_question, cheat_opt, used_num);
if(payload_len==-1)
{
MESA_handle_runtime_log(g_fw_dns_plug_info.logger,
RLOG_LV_FATAL,
"DO_ACTION",
"Hit policy_id: %d service: %d action: %d build_cheat_pkt ret: %d addr: %s",
p_result->config_id,
p_result->service_id,
p_result->action,
payload_len,
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
return -1;
}
senddir = MESA_dir_reverse(a_stream->routedir);
if(dns_info->hdr_info.qr==0)
{
senddir = MESA_dir_reverse(a_stream->routedir);
}
else
{
senddir = a_stream->routedir;
}
ret=MESA_inject_pkt(a_stream, (const char *)cheat_pkt_payload, payload_len, (const char *)a_packet, senddir);
if(ret<0)
{
@@ -256,11 +277,11 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
dns_info->query_question.qtype,
p_result->config_id,
p_result->service_id,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
}
state=PROT_STATE_DROPME|PROT_STATE_DROPPKT;
state=PROT_STATE_GIVEME|PROT_STATE_DROPPKT;
}
else
{
@@ -274,9 +295,9 @@ static char fw_dns_action(struct streaminfo *a_stream, dns_info_t *dns_info, Maa
(tmp_buff==NULL) ? p_result->service_defined : tmp_buff,
(char *)dns_info->query_question.qname,
dns_info->query_question.qtype,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
state=PROT_STATE_GIVEME;
state=PROT_STATE_GIVEME|PROT_STATE_DROPPKT;
}
break;
default:
@@ -335,10 +356,11 @@ static int fw_dns_send_log(struct streaminfo *a_stream, dns_info_t *dns_info, st
}
cname=cJSON_PrintUnformatted(cname_array);
if(strlen(cname)>0)
if(cname!=NULL && strlen(cname)>0)
{
TLD_append(handle, (char *)"dns_cname", (void *)cname, TLD_TYPE_STRING);
free(cname);
cJSON_free(cname);
cname=NULL;
}
cJSON_Delete(cname_array);
cname_array=NULL;
@@ -351,7 +373,7 @@ static int fw_dns_send_log(struct streaminfo *a_stream, dns_info_t *dns_info, st
cJSON_Delete(object);
object=NULL;
free(rr_buf);
cJSON_free(rr_buf);
rr_buf=NULL;
TLD_append(handle, (char *)"dns_sub", (void *)(long)dns_sec, TLD_TYPE_LONG);
@@ -377,7 +399,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
struct Maat_rule_t result[MAX_RESULT_NUM], *p_result=NULL;
dns_info_t *dns_info=(dns_info_t *)session_info->app_info;
if(dns_info==NULL)
if(dns_info==NULL || a_stream==NULL)
{
return state;
}
@@ -389,7 +411,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
"DNS_PLUG",
"Qname is %s, addr: %s",
(dns_info==NULL) ? "NULL" : ((strlen((char *)dns_info->query_question.qname)==0) ? "NULL" : (char *)dns_info->query_question.qname),
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
return state;
}
@@ -406,7 +428,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
result[hit_num].action,
(char *)dns_info->query_question.qname,
dns_info->query_question.qtype,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
hit_num+=ret;
}
@@ -419,7 +441,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
(char *)dns_info->query_question.qname,
dns_info->query_question.qtype,
ret,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
}
@@ -447,7 +469,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
result[hit_num].config_id,
result[hit_num].service_id,
result[hit_num].action,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
hit_num+=ret;
}
@@ -460,7 +482,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
(char *)dns_info->query_question.qname,
dns_info->query_question.qtype,
ret,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
}
@@ -480,7 +502,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
result[hit_num].config_id,
result[hit_num].service_id,
result[hit_num].action,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
hit_num+=ret;
}
@@ -493,7 +515,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
(char *)dns_info->query_question.qname,
category_id[i],
ret,
(g_fw_dns_plug_info.level<RLOG_LV_FATAL ? printaddr(&a_stream->addr, a_stream->threadnum) : "")
PRINTADDR(a_stream, g_fw_dns_plug_info.level)
);
}
@@ -506,10 +528,7 @@ extern "C" char FW_DNS_PLUG_ENTRY(stSessionInfo* session_info, void **pme, int
if(p_result!=NULL)
{
state=fw_dns_action(a_stream, dns_info, p_result, a_packet);
if(PROT_STATE_GIVEME!=state)
{
fw_dns_send_log(a_stream, dns_info, p_result, 1, thread_seq);
}
fw_dns_send_log(a_stream, dns_info, p_result, 1, thread_seq);
}
else
{