diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2023-05-28 12:59:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-28 12:59:18 +0200 |
commit | 7ce14da0c8c06967013503187081fa3a146ab8bb (patch) | |
tree | 0bd13c3aa54abf10d3901ef2f9f8d1435b912d88 /src/lib/protocols/skype.c | |
parent | 6da3474203fc2ff5981f6c73f7ad02fa81138166 (diff) |
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
Diffstat (limited to 'src/lib/protocols/skype.c')
-rw-r--r-- | src/lib/protocols/skype.c | 99 |
1 files changed, 47 insertions, 52 deletions
diff --git a/src/lib/protocols/skype.c b/src/lib/protocols/skype.c index d0d3c8060..bec650f25 100644 --- a/src/lib/protocols/skype.c +++ b/src/lib/protocols/skype.c @@ -43,59 +43,56 @@ static void ndpi_check_skype(struct ndpi_detection_module_struct *ndpi_struct, s if(flow->host_server_name[0] != '\0') return; - if(packet->udp != NULL) { - - if(flow->packet_counter < 5) { - u_int16_t sport = ntohs(packet->udp->source); - u_int16_t dport = ntohs(packet->udp->dest); - - /* skype-to-skype */ - if(is_port(sport, dport, 1119) /* It can be confused with battle.net */ - || is_port(sport, dport, 80) /* No HTTP-like protocols UDP/80 */ - ) { - ; - } else { - /* Too many false positives */ - if(((payload_len == 3) && ((packet->payload[2] & 0x0F)== 0x0d)) - || - ((payload_len >= 16) - && (((packet->payload[0] & 0xC0) >> 6) == 0x02 /* RTPv2 */ - || (((packet->payload[0] & 0xF0) >> 4) == 0 /* Zoom */) - || (((packet->payload[0] & 0xF0) >> 4) == 0x07 /* Skype */) - ) - && (packet->payload[0] != 0x30) /* Avoid invalid SNMP detection */ - && (packet->payload[0] != 0x00) /* Avoid invalid CAPWAP detection */ - && (packet->payload[2] == 0x02))) { - - if(is_port(sport, dport, 8801)) { - NDPI_LOG_INFO(ndpi_struct, "found ZOOM (in SKYPE_TEAMS code)\n"); - ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ZOOM, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); - } else if (payload_len >= 16 && packet->payload[0] != 0x01) /* Avoid invalid Cisco HSRP detection / RADIUS */ { - NDPI_LOG_INFO(ndpi_struct, "found SKYPE_TEAMS\n"); - ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE_TEAMS_CALL, NDPI_PROTOCOL_SKYPE_TEAMS, NDPI_CONFIDENCE_DPI); - } + if(flow->packet_counter < 5) { + u_int16_t sport = ntohs(packet->udp->source); + u_int16_t dport = ntohs(packet->udp->dest); + + /* skype-to-skype */ + if(is_port(sport, dport, 1119) /* It can be confused with battle.net */ + || is_port(sport, dport, 80) /* No HTTP-like protocols UDP/80 */ + ) { + ; + } else { + /* Too many false positives */ + if(((payload_len == 3) && ((packet->payload[2] & 0x0F)== 0x0d)) + || + ((payload_len >= 16) + && (((packet->payload[0] & 0xC0) >> 6) == 0x02 /* RTPv2 */ + || (((packet->payload[0] & 0xF0) >> 4) == 0 /* Zoom */) + || (((packet->payload[0] & 0xF0) >> 4) == 0x07 /* Skype */) + ) + && (packet->payload[0] != 0x30) /* Avoid invalid SNMP detection */ + && (packet->payload[0] != 0x00) /* Avoid invalid CAPWAP detection */ + && (packet->payload[2] == 0x02))) { + + if(is_port(sport, dport, 8801)) { + NDPI_LOG_INFO(ndpi_struct, "found ZOOM (in SKYPE_TEAMS code)\n"); + ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ZOOM, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); + } else if (payload_len >= 16 && packet->payload[0] != 0x01) /* Avoid invalid Cisco HSRP detection / RADIUS */ { + NDPI_LOG_INFO(ndpi_struct, "found SKYPE_TEAMS\n"); + ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE_TEAMS_CALL, NDPI_PROTOCOL_SKYPE_TEAMS, NDPI_CONFIDENCE_DPI); } + } - if (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) { - const uint8_t id_flags_iv_crc_len = 11; - const uint8_t crc_len = sizeof(flow->l4.udp.skype_crc); - const uint8_t crc_offset = id_flags_iv_crc_len - crc_len; - - /* Look for two pkts with the same crc */ - if((payload_len >= id_flags_iv_crc_len) && - (packet->payload[2] == 0x02 /* Payload flag */ )) { - if(flow->packet_counter == 1) { - memcpy(flow->l4.udp.skype_crc, &packet->payload[crc_offset], crc_len); - } else { - if(memcmp(flow->l4.udp.skype_crc, &packet->payload[crc_offset], crc_len) == 0) { - NDPI_LOG_INFO(ndpi_struct, "found SKYPE_TEAMS\n"); - ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE_TEAMS, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); - return; - } + if (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) { + const uint8_t id_flags_iv_crc_len = 11; + const uint8_t crc_len = sizeof(flow->l4.udp.skype_crc); + const uint8_t crc_offset = id_flags_iv_crc_len - crc_len; + + /* Look for two pkts with the same crc */ + if((payload_len >= id_flags_iv_crc_len) && + (packet->payload[2] == 0x02 /* Payload flag */ )) { + if(flow->packet_counter == 1) { + memcpy(flow->l4.udp.skype_crc, &packet->payload[crc_offset], crc_len); + } else { + if(memcmp(flow->l4.udp.skype_crc, &packet->payload[crc_offset], crc_len) == 0) { + NDPI_LOG_INFO(ndpi_struct, "found SKYPE_TEAMS\n"); + ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE_TEAMS, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); + return; } - /* No idea if the two pkts need to be consecutive; in doubt wait for some more pkts */ - return; } + /* No idea if the two pkts need to be consecutive; in doubt wait for some more pkts */ + return; } } } @@ -109,9 +106,7 @@ static void ndpi_search_skype(struct ndpi_detection_module_struct *ndpi_struct, { 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); } |