Code rework
This commit is contained in:
+2
-2
@@ -421,8 +421,8 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
|
|||||||
int i, j, n = 0;
|
int i, j, n = 0;
|
||||||
|
|
||||||
for(i=0, j = 0; j < sizeof(flow->bittorent_hash)-1; i++) {
|
for(i=0, j = 0; j < sizeof(flow->bittorent_hash)-1; i++) {
|
||||||
sprintf(&flow->bittorent_hash[j], "%02x", flow->ndpi_flow->bittorent_hash[i]);
|
sprintf(&flow->bittorent_hash[j], "%02x", flow->ndpi_flow->protos.bittorrent.hash[i]);
|
||||||
j += 2, n += flow->ndpi_flow->bittorent_hash[i];
|
j += 2, n += flow->ndpi_flow->protos.bittorrent.hash[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n == 0) flow->bittorent_hash[0] = '\0';
|
if(n == 0) flow->bittorent_hash[0] = '\0';
|
||||||
|
|||||||
@@ -908,8 +908,6 @@ struct ndpi_detection_module_struct {
|
|||||||
direction_detect_disable:1; /* disable internal detection of packet direction */
|
direction_detect_disable:1; /* disable internal detection of packet direction */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define dhcp_fingerprint host_server_name
|
|
||||||
|
|
||||||
struct ndpi_flow_struct {
|
struct ndpi_flow_struct {
|
||||||
u_int16_t detected_protocol_stack[NDPI_PROTOCOL_SIZE];
|
u_int16_t detected_protocol_stack[NDPI_PROTOCOL_SIZE];
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
@@ -948,13 +946,7 @@ struct ndpi_flow_struct {
|
|||||||
*/
|
*/
|
||||||
struct ndpi_id_struct *server_id;
|
struct ndpi_id_struct *server_id;
|
||||||
/* HTTP host or DNS query */
|
/* HTTP host or DNS query */
|
||||||
u_char host_server_name[256]; /* Shared with dhcp_fingerprint */
|
u_char host_server_name[256];
|
||||||
/* Via HTTP User-Agent */
|
|
||||||
u_char detected_os[32];
|
|
||||||
/* Via HTTP X-Forwarded-For */
|
|
||||||
u_char nat_ip[24];
|
|
||||||
/* Bittorrent hash */
|
|
||||||
u_char bittorent_hash[20];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This structure below will not not stay inside the protos
|
This structure below will not not stay inside the protos
|
||||||
@@ -998,6 +990,22 @@ struct ndpi_flow_struct {
|
|||||||
struct {
|
struct {
|
||||||
char version[96];
|
char version[96];
|
||||||
} ubntac2;
|
} ubntac2;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
/* Via HTTP User-Agent */
|
||||||
|
u_char detected_os[32];
|
||||||
|
/* Via HTTP X-Forwarded-For */
|
||||||
|
u_char nat_ip[24];
|
||||||
|
} http;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
/* Bittorrent hash */
|
||||||
|
u_char hash[20];
|
||||||
|
} bittorrent;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
char fingerprint[48];
|
||||||
|
} dhcp;
|
||||||
} protos;
|
} protos;
|
||||||
|
|
||||||
/*** ALL protocol specific 64 bit variables here ***/
|
/*** ALL protocol specific 64 bit variables here ***/
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc
|
|||||||
} else
|
} else
|
||||||
bt_hash = (const char*)&flow->packet.payload[28];
|
bt_hash = (const char*)&flow->packet.payload[28];
|
||||||
|
|
||||||
if(bt_hash) memcpy(flow->bittorent_hash, bt_hash, 20);
|
if(bt_hash) memcpy(flow->protos.bittorrent.hash, bt_hash, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_UNKNOWN);
|
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_UNKNOWN);
|
||||||
@@ -479,7 +479,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
|
|||||||
) {
|
) {
|
||||||
bittorrent_found:
|
bittorrent_found:
|
||||||
if(bt_proto && (packet->payload_packet_len > 47))
|
if(bt_proto && (packet->payload_packet_len > 47))
|
||||||
memcpy(flow->bittorent_hash, &bt_proto[27], 20);
|
memcpy(flow->protos.bittorrent.hash, &bt_proto[27], 20);
|
||||||
|
|
||||||
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT,
|
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT,
|
||||||
ndpi_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n");
|
ndpi_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n");
|
||||||
|
|||||||
@@ -96,11 +96,11 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
|
|||||||
if(msg_type <= 8) foundValidMsgType = 1;
|
if(msg_type <= 8) foundValidMsgType = 1;
|
||||||
} else if(id == 55 /* Parameter Request List / Fingerprint */) {
|
} else if(id == 55 /* Parameter Request List / Fingerprint */) {
|
||||||
u_int idx, offset = 0,
|
u_int idx, offset = 0,
|
||||||
hex_len = ndpi_min(len * 2, sizeof(flow->dhcp_fingerprint));
|
hex_len = ndpi_min(len * 2, sizeof(flow->protos.dhcp.fingerprint));
|
||||||
|
|
||||||
for(idx=0; idx<len; idx++) {
|
for(idx=0; idx<len; idx++) {
|
||||||
snprintf((char*)&flow->dhcp_fingerprint[offset],
|
snprintf((char*)&flow->protos.dhcp.fingerprint[offset],
|
||||||
sizeof(flow->dhcp_fingerprint)-offset-1,
|
sizeof(flow->protos.dhcp.fingerprint)-offset-1,
|
||||||
"%02X", dhcp->options[i+2+idx] & 0xFF);
|
"%02X", dhcp->options[i+2+idx] & 0xFF);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ static void setHttpUserAgent(struct ndpi_flow_struct *flow, char *ua) {
|
|||||||
* https://github.com/ua-parser/uap-core/blob/master/regexes.yaml */
|
* https://github.com/ua-parser/uap-core/blob/master/regexes.yaml */
|
||||||
|
|
||||||
//printf("==> %s\n", ua);
|
//printf("==> %s\n", ua);
|
||||||
snprintf((char*)flow->detected_os, sizeof(flow->detected_os), "%s", ua);
|
snprintf((char*)flow->protos.http.detected_os, sizeof(flow->protos.http.detected_os), "%s", ua);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
||||||
@@ -360,9 +360,9 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
|
|||||||
strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len);
|
strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len);
|
||||||
flow->host_server_name[len] = '\0', flow->server_id = flow->dst;
|
flow->host_server_name[len] = '\0', flow->server_id = flow->dst;
|
||||||
|
|
||||||
len = ndpi_min(packet->forwarded_line.len, sizeof(flow->nat_ip)-1);
|
len = ndpi_min(packet->forwarded_line.len, sizeof(flow->protos.http.nat_ip)-1);
|
||||||
strncpy((char*)flow->nat_ip, (char*)packet->forwarded_line.ptr, len);
|
strncpy((char*)flow->protos.http.nat_ip, (char*)packet->forwarded_line.ptr, len);
|
||||||
flow->nat_ip[len] = '\0';
|
flow->protos.http.nat_ip[len] = '\0';
|
||||||
|
|
||||||
if(ndpi_struct->http_dont_dissect_response)
|
if(ndpi_struct->http_dont_dissect_response)
|
||||||
parseHttpSubprotocol(ndpi_struct, flow);
|
parseHttpSubprotocol(ndpi_struct, flow);
|
||||||
|
|||||||
Reference in New Issue
Block a user