Fix how some protocols handle tcp retransmissions (#1321)

Most (all?) protocols don't care about (tcp) retransmissions.

If a protocol registers itself with a
NDPI_SELECTION_BITMASK_PROTOCOL_*_WITHOUT_RETRANSMISSION value, its
callback is never triggered with a retransmitted packet.
This commit is contained in:
Ivan Nardi
2021-10-03 21:38:49 +02:00
committed by GitHub
parent e84da386c7
commit bc5be1e76c
13 changed files with 20 additions and 70 deletions
+2 -3
View File
@@ -406,8 +406,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) {
/* check for tcp retransmission here */ /* check for tcp retransmission here */
if((packet->tcp != NULL) if(packet->tcp != NULL) {
&& (packet->tcp_retransmission == 0 || packet->num_retried_bytes)) {
ndpi_int_search_bittorrent_tcp(ndpi_struct, flow); ndpi_int_search_bittorrent_tcp(ndpi_struct, flow);
} else if(packet->udp != NULL) { } else if(packet->udp != NULL) {
/* UDP */ /* UDP */
@@ -505,7 +504,7 @@ void init_bittorrent_dissector(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_set_bitmask_protocol_detection("BitTorrent", ndpi_struct, detection_bitmask, *id, ndpi_set_bitmask_protocol_detection("BitTorrent", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_BITTORRENT,
ndpi_search_bittorrent, ndpi_search_bittorrent,
NDPI_SELECTION_BITMASK_PROTOCOL_TCP_OR_UDP, NDPI_SELECTION_BITMASK_PROTOCOL_TCP_OR_UDP_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN, SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK); ADD_TO_DETECTION_BITMASK);
*id += 1; *id += 1;
-4
View File
@@ -36,17 +36,13 @@ static void ndpi_check_bjnp(struct ndpi_detection_module_struct *ndpi_struct, st
void ndpi_search_bjnp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_bjnp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search bjnp\n"); NDPI_LOG_DBG(ndpi_struct, "search bjnp\n");
/* skip marked packets */ /* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_BJNP) { if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_BJNP) {
if (packet->tcp_retransmission == 0) {
ndpi_check_bjnp(ndpi_struct, flow); ndpi_check_bjnp(ndpi_struct, flow);
} }
} }
}
void init_bjnp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_bjnp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
-4
View File
@@ -72,17 +72,13 @@ static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct,
void ndpi_search_dropbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_dropbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search dropbox\n"); NDPI_LOG_DBG(ndpi_struct, "search dropbox\n");
/* skip marked packets */ /* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_DROPBOX) { if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_DROPBOX) {
if (packet->tcp_retransmission == 0) {
ndpi_check_dropbox(ndpi_struct, flow); ndpi_check_dropbox(ndpi_struct, flow);
} }
} }
}
void init_dropbox_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_dropbox_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
-4
View File
@@ -204,17 +204,13 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
} }
void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search EDONKEY\n"); NDPI_LOG_DBG(ndpi_struct, "search EDONKEY\n");
/* skip marked packets */ /* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_EDONKEY) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_EDONKEY) {
if(packet->tcp_retransmission == 0) {
ndpi_check_edonkey(ndpi_struct, flow); ndpi_check_edonkey(ndpi_struct, flow);
} }
} }
}
void init_edonkey_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_edonkey_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
-4
View File
@@ -653,17 +653,13 @@ static void ndpi_check_ftp_control(struct ndpi_detection_module_struct *ndpi_str
void ndpi_search_ftp_control(struct ndpi_detection_module_struct *ndpi_struct, void ndpi_search_ftp_control(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search FTP_CONTROL\n"); NDPI_LOG_DBG(ndpi_struct, "search FTP_CONTROL\n");
/* skip marked packets */ /* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_FTP_CONTROL) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_FTP_CONTROL) {
if(packet->tcp_retransmission == 0) {
ndpi_check_ftp_control(ndpi_struct, flow); ndpi_check_ftp_control(ndpi_struct, flow);
} }
} }
}
/* *************************************************************** */ /* *************************************************************** */
-4
View File
@@ -77,17 +77,13 @@ static void ndpi_check_redis(struct ndpi_detection_module_struct *ndpi_struct, s
} }
void ndpi_search_redis(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_redis(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search Redis\n"); NDPI_LOG_DBG(ndpi_struct, "search Redis\n");
/* skip marked packets */ /* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_REDIS) { if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_REDIS) {
if (packet->tcp_retransmission == 0) {
ndpi_check_redis(ndpi_struct, flow); ndpi_check_redis(ndpi_struct, flow);
} }
} }
}
void init_redis_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_redis_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
-4
View File
@@ -78,17 +78,13 @@ static void ndpi_check_rtmp(struct ndpi_detection_module_struct *ndpi_struct, st
void ndpi_search_rtmp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_rtmp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search RTMP\n"); NDPI_LOG_DBG(ndpi_struct, "search RTMP\n");
/* skip marked packets */ /* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_RTMP) { if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_RTMP) {
if (packet->tcp_retransmission == 0) {
ndpi_check_rtmp(ndpi_struct, flow); ndpi_check_rtmp(ndpi_struct, flow);
} }
} }
}
void init_rtmp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_rtmp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
+1 -5
View File
@@ -178,8 +178,6 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
void ndpi_search_sip(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_sip(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search sip\n"); NDPI_LOG_DBG(ndpi_struct, "search sip\n");
if(flow->packet_counter > 5) if(flow->packet_counter > 5)
@@ -187,19 +185,17 @@ void ndpi_search_sip(struct ndpi_detection_module_struct *ndpi_struct, struct nd
else { else {
/* skip marked packets */ /* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SIP) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SIP) {
if(packet->tcp_retransmission == 0) {
ndpi_search_sip_handshake(ndpi_struct, flow); ndpi_search_sip_handshake(ndpi_struct, flow);
} }
} }
} }
}
void init_sip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_sip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{ {
ndpi_set_bitmask_protocol_detection("SIP", ndpi_struct, detection_bitmask, *id, ndpi_set_bitmask_protocol_detection("SIP", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_SIP, NDPI_PROTOCOL_SIP,
ndpi_search_sip, ndpi_search_sip,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD,/* Fix courtesy of Miguel Quesada <mquesadab@gmail.com> */ NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,/* Fix courtesy of Miguel Quesada <mquesadab@gmail.com> */
SAVE_DETECTION_BITMASK_AS_UNKNOWN, SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK); ADD_TO_DETECTION_BITMASK);
-4
View File
@@ -119,20 +119,16 @@ static void ndpi_check_socks5(struct ndpi_detection_module_struct *ndpi_struct,
void ndpi_search_socks(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_socks(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search SOCKS\n"); NDPI_LOG_DBG(ndpi_struct, "search SOCKS\n");
/* skip marked packets */ /* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS) {
if(packet->tcp_retransmission == 0) {
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, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_socks_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{ {
+1 -5
View File
@@ -121,17 +121,13 @@ static void ndpi_check_spotify(struct ndpi_detection_module_struct *ndpi_struct,
void ndpi_search_spotify(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_spotify(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search spotify\n"); NDPI_LOG_DBG(ndpi_struct, "search spotify\n");
/* skip marked packets */ /* skip marked packets */
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SPOTIFY) { if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_SPOTIFY) {
if (packet->tcp_retransmission == 0) {
ndpi_check_spotify(ndpi_struct, flow); ndpi_check_spotify(ndpi_struct, flow);
} }
} }
}
void init_spotify_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_spotify_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
@@ -139,7 +135,7 @@ void init_spotify_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_
ndpi_set_bitmask_protocol_detection("SPOTIFY", ndpi_struct, detection_bitmask, *id, ndpi_set_bitmask_protocol_detection("SPOTIFY", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_SPOTIFY, NDPI_PROTOCOL_SPOTIFY,
ndpi_search_spotify, ndpi_search_spotify,
NDPI_SELECTION_BITMASK_PROTOCOL_TCP_OR_UDP_WITH_PAYLOAD, NDPI_SELECTION_BITMASK_PROTOCOL_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN, SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK); ADD_TO_DETECTION_BITMASK);
+1 -6
View File
@@ -255,7 +255,6 @@ static void ndpi_check_steam_udp3(struct ndpi_detection_module_struct *ndpi_stru
} }
void ndpi_search_steam(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_steam(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
if(flow->packet.udp != NULL) { if(flow->packet.udp != NULL) {
if(flow->packet_counter > 5) { if(flow->packet_counter > 5) {
@@ -281,11 +280,7 @@ void ndpi_search_steam(struct ndpi_detection_module_struct *ndpi_struct, struct
return; return;
} }
/* skip marked or retransmitted packets */ /* skip marked packets */
if(packet->tcp_retransmission != 0) {
return;
}
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_STEAM) if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_STEAM)
return; return;
+1 -5
View File
@@ -129,23 +129,19 @@ static void ndpi_check_tinc(struct ndpi_detection_module_struct *ndpi_struct, st
} }
void ndpi_search_tinc(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) { void ndpi_search_tinc(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) {
struct ndpi_packet_struct* packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "tinc detection\n"); NDPI_LOG_DBG(ndpi_struct, "tinc detection\n");
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_TINC) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_TINC) {
if(packet->tcp_retransmission == 0) {
ndpi_check_tinc(ndpi_struct, flow); ndpi_check_tinc(ndpi_struct, flow);
} }
} }
}
void init_tinc_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_tinc_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{ {
ndpi_set_bitmask_protocol_detection("TINC", ndpi_struct, detection_bitmask, *id, ndpi_set_bitmask_protocol_detection("TINC", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_TINC, NDPI_PROTOCOL_TINC,
ndpi_search_tinc, ndpi_search_tinc,
NDPI_SELECTION_BITMASK_PROTOCOL_TCP_OR_UDP, NDPI_SELECTION_BITMASK_PROTOCOL_TCP_OR_UDP_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN, SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK); ADD_TO_DETECTION_BITMASK);
-4
View File
@@ -84,17 +84,13 @@ static void ndpi_check_zmq(struct ndpi_detection_module_struct *ndpi_struct, str
} }
void ndpi_search_zmq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_zmq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search ZMQ\n"); NDPI_LOG_DBG(ndpi_struct, "search ZMQ\n");
/* skip marked packets */ /* skip marked packets */
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_ZMQ) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_ZMQ) {
if(packet->tcp && packet->tcp_retransmission == 0) {
ndpi_check_zmq(ndpi_struct, flow); ndpi_check_zmq(ndpi_struct, flow);
} }
} }
}
void init_zmq_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_zmq_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)