接口适配
This commit is contained in:
@@ -11,33 +11,33 @@ enum kni_scan_table{
|
|||||||
SCAN_TABLE_MAX
|
SCAN_TABLE_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
struct kni_protocol_identify_result{
|
|
||||||
enum tsg_protocol protocol;
|
|
||||||
char domain[TSG_DOMAIN_MAX];
|
|
||||||
int domain_len;
|
|
||||||
};
|
|
||||||
|
|
||||||
Maat_feather_t g_kni_maat_feather;
|
Maat_feather_t g_kni_maat_feather;
|
||||||
const char *g_kni_scan_table_name[SCAN_TABLE_MAX];
|
const char *g_kni_scan_table_name[SCAN_TABLE_MAX];
|
||||||
int g_kni_scan_tableid[SCAN_TABLE_MAX] = {0};
|
int g_kni_scan_tableid[SCAN_TABLE_MAX] = {0};
|
||||||
|
|
||||||
static void protocol_identify(char *buff, int buff_len, struct kni_protocol_identify_result *result){
|
static void protocol_identify(char *buff, int buff_len, struct _identify_info *result){
|
||||||
result->protocol = TSG_PROTOCOL_UNKNOWN;
|
result->protocol = -1;
|
||||||
//TODO: http: get from http protocol plugin
|
//TODO: http: get from http protocol plugin
|
||||||
|
/*
|
||||||
|
if(is_http){
|
||||||
|
result->protocol = PROTO_HTTP;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
//ssl
|
//ssl
|
||||||
enum chello_parse_result chello_status = CHELLO_PARSE_INVALID_FORMAT;
|
enum chello_parse_result chello_status = CHELLO_PARSE_INVALID_FORMAT;
|
||||||
struct ssl_chello *chello = NULL;
|
struct ssl_chello *chello = NULL;
|
||||||
chello = ssl_chello_parse((const unsigned char*)buff, buff_len, &chello_status);
|
chello = ssl_chello_parse((const unsigned char*)buff, buff_len, &chello_status);
|
||||||
if(chello_status == CHELLO_PARSE_SUCCESS){
|
if(chello_status == CHELLO_PARSE_SUCCESS){
|
||||||
result->protocol = TSG_PROTOCOL_SSL;
|
result->protocol = PROTO_SSL;
|
||||||
if(chello->sni == NULL){
|
if(chello->sni == NULL){
|
||||||
result->domain_len = 0;
|
result->domain_len = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
strncpy(result->domain, chello->sni, strnlen(chello->sni, sizeof(result->domain) - 1));
|
result->domain_len = strnlen(chello->sni, sizeof(result->domain) - 1);
|
||||||
result->domain_len = strlen(result->domain);
|
strncpy(result->domain, chello->sni, result->domain_len);
|
||||||
}
|
}
|
||||||
|
result->domain[result->domain_len] = '\0';
|
||||||
}
|
}
|
||||||
ssl_chello_free(chello);
|
ssl_chello_free(chello);
|
||||||
return;
|
return;
|
||||||
@@ -60,25 +60,22 @@ int tsg_shared_table_init(const char *conffile, Maat_feather_t maat_feather, voi
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//return -1 if failed, return 0 on success
|
|
||||||
int tsg_scan_shared_policy(Maat_feather_t maat_feather, void *pkt, int pkt_len, Maat_rule_t *result, int result_num, enum tsg_protocol *protocol, char *domain, int *domain_len,
|
//return value: -1: failed, 0: not hit, >0: hit count
|
||||||
scan_status_t *mid, void *logger, int thread_seq){
|
int tsg_scan_shared_policy(Maat_feather_t maat_feather, void *pkt, int pkt_len, Maat_rule_t *result, int result_num,
|
||||||
struct kni_protocol_identify_result protocol_identify_res;
|
struct _identify_info *identify_info, scan_status_t *mid, void *logger, int thread_seq){
|
||||||
memset(&protocol_identify_res, 0, sizeof(protocol_identify_res));
|
memset(identify_info, 0, sizeof(*identify_info));
|
||||||
protocol_identify((char*)pkt, pkt_len, &protocol_identify_res);
|
protocol_identify((char*)pkt, pkt_len, identify_info);
|
||||||
if(protocol_identify_res.protocol == TSG_PROTOCOL_UNKNOWN){
|
if(identify_info->protocol != TSG_PROTOCOL_SSL && identify_info->protocol != TSG_PROTOCOL_HTTP){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*protocol = protocol_identify_res.protocol;
|
|
||||||
*domain_len = protocol_identify_res.domain_len;
|
|
||||||
strncpy(domain, protocol_identify_res.domain, *domain_len);
|
|
||||||
int tableid;
|
int tableid;
|
||||||
if(protocol_identify_res.protocol == TSG_PROTOCOL_SSL){
|
if(identify_info->protocol == TSG_PROTOCOL_SSL){
|
||||||
tableid = g_kni_scan_tableid[TSG_FIELD_SSL_SNI];
|
tableid = g_kni_scan_tableid[TSG_FIELD_SSL_SNI];
|
||||||
}
|
}
|
||||||
if(protocol_identify_res.protocol == TSG_PROTOCOL_HTTP){
|
else{
|
||||||
tableid = g_kni_scan_tableid[TSG_FIELD_HTTP_HOST];
|
tableid = g_kni_scan_tableid[TSG_FIELD_HTTP_HOST];
|
||||||
}
|
}
|
||||||
return Maat_full_scan_string(g_kni_maat_feather, tableid, CHARSET_UTF8, domain, *domain_len,
|
return Maat_full_scan_string(g_kni_maat_feather, tableid, CHARSET_UTF8, identify_info->domain, identify_info->domain_len,
|
||||||
result, NULL, result_num, mid, thread_seq);
|
result, NULL, result_num, mid, thread_seq);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user