Remove some useless checks (#1993)

In the main dissector callbacks the flow protocols are (almost) always
unknown. Only two exceptions:
* extra dissection data path
* HTTP sub-protocols
This commit is contained in:
Ivan Nardi
2023-05-28 12:59:18 +02:00
committed by GitHub
parent 6da3474203
commit 7ce14da0c8
18 changed files with 147 additions and 211 deletions
-2
View File
@@ -60,8 +60,6 @@ static void ndpi_search_amazon_video(struct ndpi_detection_module_struct *ndpi_s
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG(ndpi_struct, "search amazon_video\n"); NDPI_LOG_DBG(ndpi_struct, "search amazon_video\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_AMAZON_VIDEO)
ndpi_check_amazon_video(ndpi_struct, flow); ndpi_check_amazon_video(ndpi_struct, flow);
} }
-2
View File
@@ -89,8 +89,6 @@ static void ndpi_search_apple_push(struct ndpi_detection_module_struct *ndpi_str
{ {
NDPI_LOG_DBG(ndpi_struct, "search apple_push\n"); NDPI_LOG_DBG(ndpi_struct, "search apple_push\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_APPLE_PUSH)
ndpi_check_apple_push(ndpi_struct, flow); ndpi_check_apple_push(ndpi_struct, flow);
} }
-5
View File
@@ -17,7 +17,6 @@ static void ndpi_check_bjnp(struct ndpi_detection_module_struct *ndpi_struct, st
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
if(packet->udp != NULL) {
if(payload_len > 4) { if(payload_len > 4) {
if((memcmp((const char *)packet->payload, "BJNP", 4) == 0) if((memcmp((const char *)packet->payload, "BJNP", 4) == 0)
|| (memcmp((const char *)packet->payload, "BNJB", 4) == 0) || (memcmp((const char *)packet->payload, "BNJB", 4) == 0)
@@ -29,7 +28,6 @@ static void ndpi_check_bjnp(struct ndpi_detection_module_struct *ndpi_struct, st
return; return;
} }
} }
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
@@ -38,10 +36,7 @@ static void ndpi_search_bjnp(struct ndpi_detection_module_struct *ndpi_struct, s
{ {
NDPI_LOG_DBG(ndpi_struct, "search bjnp\n"); NDPI_LOG_DBG(ndpi_struct, "search bjnp\n");
/* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_BJNP) {
ndpi_check_bjnp(ndpi_struct, flow); ndpi_check_bjnp(ndpi_struct, flow);
}
} }
-2
View File
@@ -61,8 +61,6 @@ static void ndpi_search_citrix(struct ndpi_detection_module_struct *ndpi_struct,
{ {
NDPI_LOG_DBG(ndpi_struct, "search citrix\n"); NDPI_LOG_DBG(ndpi_struct, "search citrix\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_CITRIX)
ndpi_check_citrix(ndpi_struct, flow); ndpi_check_citrix(ndpi_struct, flow);
} }
-7
View File
@@ -40,10 +40,7 @@ static void ndpi_int_dropbox_add_connection(struct ndpi_detection_module_struct
static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
// const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
if(packet->udp != NULL) {
u_int16_t dropbox_port = htons(DB_LSP_PORT); u_int16_t dropbox_port = htons(DB_LSP_PORT);
if(packet->udp->dest == dropbox_port) { if(packet->udp->dest == dropbox_port) {
@@ -65,7 +62,6 @@ static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct,
} }
} }
} }
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
@@ -74,10 +70,7 @@ static void ndpi_search_dropbox(struct ndpi_detection_module_struct *ndpi_struct
{ {
NDPI_LOG_DBG(ndpi_struct, "search dropbox\n"); NDPI_LOG_DBG(ndpi_struct, "search dropbox\n");
/* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_DROPBOX) {
ndpi_check_dropbox(ndpi_struct, flow); ndpi_check_dropbox(ndpi_struct, flow);
}
} }
-3
View File
@@ -201,10 +201,7 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
static void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG(ndpi_struct, "search EDONKEY\n"); NDPI_LOG_DBG(ndpi_struct, "search EDONKEY\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_EDONKEY) {
ndpi_check_edonkey(ndpi_struct, flow); ndpi_check_edonkey(ndpi_struct, flow);
}
} }
-7
View File
@@ -589,9 +589,6 @@ static void ndpi_check_ftp_control(struct ndpi_detection_module_struct *ndpi_str
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
/* Check connection over TCP */
if(packet->tcp) {
u_int16_t twentyfive = htons(25); u_int16_t twentyfive = htons(25);
/* Exclude SMTP, which uses similar commands. */ /* Exclude SMTP, which uses similar commands. */
@@ -664,7 +661,6 @@ static void ndpi_check_ftp_control(struct ndpi_detection_module_struct *ndpi_str
flow->ftp_control_stage = 0; flow->ftp_control_stage = 0;
} }
} }
}
} }
/* *************************************************************** */ /* *************************************************************** */
@@ -673,10 +669,7 @@ static void ndpi_search_ftp_control(struct ndpi_detection_module_struct *ndpi_st
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG(ndpi_struct, "search FTP_CONTROL\n"); NDPI_LOG_DBG(ndpi_struct, "search FTP_CONTROL\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_FTP_CONTROL) {
ndpi_check_ftp_control(ndpi_struct, flow); ndpi_check_ftp_control(ndpi_struct, flow);
}
} }
/* *************************************************************** */ /* *************************************************************** */
+1 -3
View File
@@ -67,7 +67,7 @@ static void ndpi_check_gtp(struct ndpi_detection_module_struct *ndpi_struct, str
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
if((packet->udp != NULL) && (payload_len > sizeof(struct gtp_header_generic))) { if(payload_len > sizeof(struct gtp_header_generic)) {
u_int32_t gtp_u = ntohs(2152); u_int32_t gtp_u = ntohs(2152);
u_int32_t gtp_c = ntohs(2123); u_int32_t gtp_c = ntohs(2123);
u_int32_t gtp_prime = ntohs(3386); u_int32_t gtp_prime = ntohs(3386);
@@ -122,8 +122,6 @@ static void ndpi_search_gtp(struct ndpi_detection_module_struct *ndpi_struct, st
{ {
NDPI_LOG_DBG(ndpi_struct, "search gtp\n"); NDPI_LOG_DBG(ndpi_struct, "search gtp\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_GTP)
ndpi_check_gtp(ndpi_struct, flow); ndpi_check_gtp(ndpi_struct, flow);
} }
-5
View File
@@ -76,12 +76,7 @@ static void ndpi_search_lisp(struct ndpi_detection_module_struct *ndpi_struct, s
{ {
NDPI_LOG_DBG(ndpi_struct, "search lisp\n"); NDPI_LOG_DBG(ndpi_struct, "search lisp\n");
/* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_LISP) {
ndpi_check_lisp(ndpi_struct, flow); ndpi_check_lisp(ndpi_struct, flow);
}
} }
+1 -4
View File
@@ -41,8 +41,7 @@ static void ndpi_check_radius(struct ndpi_detection_module_struct *ndpi_struct,
// const u_int8_t *packet_payload = packet->payload; // const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
if(packet->udp != NULL && if((packet->udp->dest == htons(RADIUS_PORT) || packet->udp->source == htons(RADIUS_PORT) ||
(packet->udp->dest == htons(RADIUS_PORT) || packet->udp->source == htons(RADIUS_PORT) ||
packet->udp->dest == htons(RADIUS_PORT_ACC) || packet->udp->source == htons(RADIUS_PORT_ACC) || packet->udp->dest == htons(RADIUS_PORT_ACC) || packet->udp->source == htons(RADIUS_PORT_ACC) ||
packet->udp->dest == htons(RADIUS_PORT_ACC_ALTERNATIVE) || packet->udp->source == htons(RADIUS_PORT_ACC_ALTERNATIVE))) { packet->udp->dest == htons(RADIUS_PORT_ACC_ALTERNATIVE) || packet->udp->source == htons(RADIUS_PORT_ACC_ALTERNATIVE))) {
struct radius_header *h = (struct radius_header*)packet->payload; struct radius_header *h = (struct radius_header*)packet->payload;
@@ -69,8 +68,6 @@ static void ndpi_search_radius(struct ndpi_detection_module_struct *ndpi_struct,
{ {
NDPI_LOG_DBG(ndpi_struct, "search radius\n"); NDPI_LOG_DBG(ndpi_struct, "search radius\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_RADIUS)
ndpi_check_radius(ndpi_struct, flow); ndpi_check_radius(ndpi_struct, flow);
} }
-3
View File
@@ -76,10 +76,7 @@ static void ndpi_check_redis(struct ndpi_detection_module_struct *ndpi_struct, s
static void ndpi_search_redis(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static void ndpi_search_redis(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG(ndpi_struct, "search Redis\n"); NDPI_LOG_DBG(ndpi_struct, "search Redis\n");
/* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_REDIS) {
ndpi_check_redis(ndpi_struct, flow); ndpi_check_redis(ndpi_struct, flow);
}
} }
-3
View File
@@ -83,10 +83,7 @@ static void ndpi_search_rtmp(struct ndpi_detection_module_struct *ndpi_struct, s
{ {
NDPI_LOG_DBG(ndpi_struct, "search RTMP\n"); NDPI_LOG_DBG(ndpi_struct, "search RTMP\n");
/* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_RTMP) {
ndpi_check_rtmp(ndpi_struct, flow); ndpi_check_rtmp(ndpi_struct, flow);
}
} }
-5
View File
@@ -43,8 +43,6 @@ static void ndpi_check_skype(struct ndpi_detection_module_struct *ndpi_struct, s
if(flow->host_server_name[0] != '\0') if(flow->host_server_name[0] != '\0')
return; return;
if(packet->udp != NULL) {
if(flow->packet_counter < 5) { if(flow->packet_counter < 5) {
u_int16_t sport = ntohs(packet->udp->source); u_int16_t sport = ntohs(packet->udp->source);
u_int16_t dport = ntohs(packet->udp->dest); u_int16_t dport = ntohs(packet->udp->dest);
@@ -98,7 +96,6 @@ static void ndpi_check_skype(struct ndpi_detection_module_struct *ndpi_struct, s
} }
} }
} }
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return; return;
@@ -109,8 +106,6 @@ static void ndpi_search_skype(struct ndpi_detection_module_struct *ndpi_struct,
{ {
NDPI_LOG_DBG(ndpi_struct, "search skype\n"); NDPI_LOG_DBG(ndpi_struct, "search skype\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SKYPE_TEAMS)
ndpi_check_skype(ndpi_struct, flow); ndpi_check_skype(ndpi_struct, flow);
} }
-3
View File
@@ -121,13 +121,10 @@ static void ndpi_search_socks(struct ndpi_detection_module_struct *ndpi_struct,
{ {
NDPI_LOG_DBG(ndpi_struct, "search SOCKS\n"); NDPI_LOG_DBG(ndpi_struct, "search SOCKS\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS) {
ndpi_check_socks4(ndpi_struct, flow); ndpi_check_socks4(ndpi_struct, flow);
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS) if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS)
ndpi_check_socks5(ndpi_struct, flow); ndpi_check_socks5(ndpi_struct, flow);
}
} }
void init_socks_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id) void init_socks_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id)
-3
View File
@@ -72,10 +72,7 @@ static void ndpi_search_spotify(struct ndpi_detection_module_struct *ndpi_struct
{ {
NDPI_LOG_DBG(ndpi_struct, "search spotify\n"); NDPI_LOG_DBG(ndpi_struct, "search spotify\n");
/* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SPOTIFY) {
ndpi_check_spotify(ndpi_struct, flow); ndpi_check_spotify(ndpi_struct, flow);
}
} }
-4
View File
@@ -43,7 +43,6 @@ static void ndpi_check_vhua(struct ndpi_detection_module_struct *ndpi_struct, st
/* Break after 3 packets. */ /* Break after 3 packets. */
if((flow->packet_counter > 3) if((flow->packet_counter > 3)
|| (packet->udp == NULL)
|| (packet->payload_packet_len < sizeof(p0))) { || (packet->payload_packet_len < sizeof(p0))) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} else if(memcmp(packet->payload, p0, sizeof(p0)) == 0) { } else if(memcmp(packet->payload, p0, sizeof(p0)) == 0) {
@@ -54,10 +53,7 @@ static void ndpi_check_vhua(struct ndpi_detection_module_struct *ndpi_struct, st
static void ndpi_search_vhua(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static void ndpi_search_vhua(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG(ndpi_struct, "search VHUA\n"); NDPI_LOG_DBG(ndpi_struct, "search VHUA\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_VHUA) {
ndpi_check_vhua(ndpi_struct, flow); ndpi_check_vhua(ndpi_struct, flow);
}
} }
+1 -3
View File
@@ -30,7 +30,7 @@ static void ndpi_check_vxlan(struct ndpi_detection_module_struct *ndpi_struct, s
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
if((packet->udp != NULL) && (packet->payload_packet_len >= sizeof(struct ndpi_vxlanhdr))) { if(packet->payload_packet_len >= sizeof(struct ndpi_vxlanhdr)) {
/* /*
*rfc-7348 vxlan header *rfc-7348 vxlan header
@@ -60,8 +60,6 @@ static void ndpi_search_vxlan(struct ndpi_detection_module_struct *ndpi_struct,
{ {
NDPI_LOG_DBG(ndpi_struct, "search vxlan\n"); NDPI_LOG_DBG(ndpi_struct, "search vxlan\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_VXLAN)
ndpi_check_vxlan(ndpi_struct, flow); ndpi_check_vxlan(ndpi_struct, flow);
} }
-3
View File
@@ -84,10 +84,7 @@ static void ndpi_check_zmq(struct ndpi_detection_module_struct *ndpi_struct, str
static void ndpi_search_zmq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static void ndpi_search_zmq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG(ndpi_struct, "search ZMQ\n"); NDPI_LOG_DBG(ndpi_struct, "search ZMQ\n");
/* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_ZMQ) {
ndpi_check_zmq(ndpi_struct, flow); ndpi_check_zmq(ndpi_struct, flow);
}
} }