Coverage Report

Created: 2026-02-21 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/eaq.c
Line
Count
Source
1
/*
2
 * eaq.c
3
 *
4
 * Copyright (C) 2015-22 - ntop.org
5
 *
6
 * This module is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This module is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License.
17
 * If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 */
20
21
22
/*
23
  EAQ: Entitade Aferidora da Qualidade de Banda Larga
24
25
  http://www.brasilbandalarga.com.br
26
 */
27
28
#include "ndpi_protocol_ids.h"
29
30
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_EAQ
31
32
#include "ndpi_api.h"
33
#include "ndpi_private.h"
34
35
0
#define EAQ_DEFAULT_PORT   6000
36
0
#define EAQ_DEFAULT_SIZE     16
37
38
static void ndpi_int_eaq_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
39
0
          struct ndpi_flow_struct *flow) {
40
0
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_EAQ, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
41
0
}
42
43
44
0
static void ndpi_search_eaq(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
45
0
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
46
0
  u_int16_t sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
47
  
48
0
  NDPI_LOG_DBG(ndpi_struct, "search eaq\n");
49
50
0
  do {
51
0
    if( (packet->payload_packet_len != EAQ_DEFAULT_SIZE) ||
52
0
        ((sport != EAQ_DEFAULT_PORT) && (dport != EAQ_DEFAULT_PORT)) )
53
0
      break;
54
      
55
0
      u_int32_t seq = (packet->payload[0] * 1000) + (packet->payload[1] * 100) + (packet->payload[2] * 10) + packet->payload[3];
56
57
0
      if(flow->l4.udp.eaq_pkt_id == 0)
58
0
        flow->l4.udp.eaq_sequence = seq;
59
0
      else {
60
0
        if( (flow->l4.udp.eaq_sequence != seq) &&
61
0
      ((flow->l4.udp.eaq_sequence+1) != seq))
62
0
    break;
63
0
  else
64
0
    flow->l4.udp.eaq_sequence = seq;
65
0
      }
66
67
0
      if(++flow->l4.udp.eaq_pkt_id == 4) {
68
        /* We have collected enough packets so we assume it's EAQ */
69
0
        NDPI_LOG_INFO(ndpi_struct, "found eaq\n");
70
0
        ndpi_int_eaq_add_connection(ndpi_struct, flow);
71
0
        return;
72
0
      } else
73
0
  return;
74
75
0
  } while(0);
76
77
0
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
78
79
0
}
80
81
82
void init_eaq_dissector(struct ndpi_detection_module_struct *ndpi_struct)
83
1
{
84
1
  ndpi_register_dissector("EAQ", ndpi_struct,
85
1
                     ndpi_search_eaq,
86
1
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
87
1
                     1, NDPI_PROTOCOL_EAQ);
88
1
}