Coverage Report

Created: 2026-03-01 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/iax.c
Line
Count
Source
1
/*
2
 * iax.c
3
 *
4
 * Copyright (C) 2009-11 - ipoque GmbH
5
 * Copyright (C) 2011-26 - ntop.org
6
 *
7
 * This file is part of nDPI, an open source deep packet inspection
8
 * library based on the OpenDPI and PACE technology by ipoque GmbH
9
 *
10
 * nDPI is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Lesser General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * nDPI is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Lesser General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Lesser General Public License
21
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
26
#include "ndpi_protocol_ids.h"
27
28
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IAX
29
30
#include "ndpi_api.h"
31
#include "ndpi_private.h"
32
33
34
2.62k
#define NDPI_IAX_MAX_INFORMATION_ELEMENTS 15
35
36
static void ndpi_int_iax_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
37
150
{
38
150
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IAX, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
39
150
}
40
41
static void ndpi_search_setup_iax(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
42
998k
{
43
998k
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
44
998k
  u_int8_t i;
45
998k
  u_int16_t packet_len;
46
47
998k
  if (            /* 1. iax is udp based, port 4569 */
48
998k
      (packet->udp->source == htons(4569) || packet->udp->dest == htons(4569))
49
      /* check for iax new packet */
50
2.21k
      && packet->payload_packet_len >= 12
51
      /* check for dst call id == 0, do not check for highest bit (packet retransmission) */
52
      // && (ntohs(get_u_int16_t(packet->payload, 2)) & 0x7FFF) == 0
53
      /* check full IAX packet  */
54
2.00k
      && (packet->payload[0] & 0x80) != 0
55
      /* outbound seq == 0 */
56
1.36k
      && packet->payload[8] == 0
57
      /* inbound seq == 0 || 1  */
58
906
      && (packet->payload[9] == 0 || packet->payload[9] == 0x01)
59
      /*  */
60
750
      && packet->payload[10] == 0x06
61
      /* IAX type: 0-15 */
62
533
      && packet->payload[11] <= 15) {
63
64
426
    if (packet->payload_packet_len == 12) {
65
93
      NDPI_LOG_INFO(ndpi_struct, "found IAX\n");
66
93
      ndpi_int_iax_add_connection(ndpi_struct, flow);
67
93
      return;
68
93
    }
69
70
333
    packet_len = 12;
71
2.62k
    for(i = 0; i < NDPI_IAX_MAX_INFORMATION_ELEMENTS; i++) {
72
2.55k
      if ((packet_len+1) >= packet->payload_packet_len)
73
204
  break;      
74
75
2.35k
      packet_len = packet_len + 2 + packet->payload[packet_len + 1];
76
2.35k
      if(packet_len == packet->payload_packet_len) {
77
57
  NDPI_LOG_INFO(ndpi_struct, "found IAX\n");
78
57
  ndpi_int_iax_add_connection(ndpi_struct, flow);
79
57
  return;
80
57
      }
81
2.35k
    }
82
83
333
  }
84
85
998k
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
86
87
998k
}
88
89
static void ndpi_search_iax(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
90
998k
{
91
998k
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
92
93
998k
  if(packet->udp 
94
998k
     && (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN))
95
998k
    ndpi_search_setup_iax(ndpi_struct, flow);
96
998k
}
97
98
99
void init_iax_dissector(struct ndpi_detection_module_struct *ndpi_struct)
100
14.9k
{
101
14.9k
  ndpi_register_dissector("IAX", ndpi_struct,
102
14.9k
                     ndpi_search_iax,
103
14.9k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
104
14.9k
                     1, NDPI_PROTOCOL_IAX);
105
14.9k
}