|
|
|
|
@@ -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
|
|
|
|
|
{
|
|
|
|
|
|