/src/ndpi/src/lib/protocols/iax.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * iax.c |
3 | | * |
4 | | * Copyright (C) 2009-11 - ipoque GmbH |
5 | | * Copyright (C) 2011-25 - 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 | 0 | #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 | 0 | { |
38 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IAX, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
39 | 0 | } |
40 | | |
41 | | static void ndpi_search_setup_iax(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) |
42 | 660 | { |
43 | 660 | struct ndpi_packet_struct *packet = &ndpi_struct->packet; |
44 | 660 | u_int8_t i; |
45 | 660 | u_int16_t packet_len; |
46 | | |
47 | 660 | if ( /* 1. iax is udp based, port 4569 */ |
48 | 660 | (packet->udp->source == htons(4569) || packet->udp->dest == htons(4569)) |
49 | | /* check for iax new packet */ |
50 | 660 | && 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 | 660 | && (packet->payload[0] & 0x80) != 0 |
55 | | /* outbound seq == 0 */ |
56 | 660 | && packet->payload[8] == 0 |
57 | | /* inbound seq == 0 || 1 */ |
58 | 660 | && (packet->payload[9] == 0 || packet->payload[9] == 0x01) |
59 | | /* */ |
60 | 660 | && packet->payload[10] == 0x06 |
61 | | /* IAX type: 0-15 */ |
62 | 660 | && packet->payload[11] <= 15) { |
63 | |
|
64 | 0 | if (packet->payload_packet_len == 12) { |
65 | 0 | NDPI_LOG_INFO(ndpi_struct, "found IAX\n"); |
66 | 0 | ndpi_int_iax_add_connection(ndpi_struct, flow); |
67 | 0 | return; |
68 | 0 | } |
69 | | |
70 | 0 | packet_len = 12; |
71 | 0 | for(i = 0; i < NDPI_IAX_MAX_INFORMATION_ELEMENTS; i++) { |
72 | 0 | if ((packet_len+1) >= packet->payload_packet_len) |
73 | 0 | break; |
74 | | |
75 | 0 | packet_len = packet_len + 2 + packet->payload[packet_len + 1]; |
76 | 0 | if(packet_len == packet->payload_packet_len) { |
77 | 0 | NDPI_LOG_INFO(ndpi_struct, "found IAX\n"); |
78 | 0 | ndpi_int_iax_add_connection(ndpi_struct, flow); |
79 | 0 | return; |
80 | 0 | } |
81 | 0 | } |
82 | |
|
83 | 0 | } |
84 | | |
85 | 660 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
86 | | |
87 | 660 | } |
88 | | |
89 | | static void ndpi_search_iax(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) |
90 | 660 | { |
91 | 660 | struct ndpi_packet_struct *packet = &ndpi_struct->packet; |
92 | | |
93 | 660 | if(packet->udp |
94 | 660 | && (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)) |
95 | 660 | ndpi_search_setup_iax(ndpi_struct, flow); |
96 | 660 | } |
97 | | |
98 | | |
99 | | void init_iax_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
100 | 7.49k | { |
101 | 7.49k | register_dissector("IAX", ndpi_struct, |
102 | 7.49k | ndpi_search_iax, |
103 | 7.49k | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD, |
104 | 7.49k | 1, NDPI_PROTOCOL_IAX); |
105 | 7.49k | } |