Coverage Report

Created: 2025-09-17 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/cnp-ip.c
Line
Count
Source
1
/*
2
 * cnp-ip.c
3
 *
4
 * Control Network Protocol - IP Communication (ISO/IEC 14908-4)
5
 * 
6
 * Copyright (C) 2024 - ntop.org
7
 * Copyright (C) 2024 - V.G <v.gavrilov@securitycode.ru>
8
 *
9
 * This file is part of nDPI, an open source deep packet inspection
10
 * library based on the OpenDPI and PACE technology by ipoque GmbH
11
 *
12
 * nDPI is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Lesser General Public License as published by
14
 * the Free Software Foundation, either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * nDPI is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Lesser General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Lesser General Public License
23
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
24
 * 
25
 */
26
27
#include "ndpi_protocol_ids.h"
28
29
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_CNP_IP
30
31
#include "ndpi_api.h"
32
#include "ndpi_private.h"
33
34
static void ndpi_int_cnp_ip_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
35
                                           struct ndpi_flow_struct *flow)
36
0
{
37
0
  NDPI_LOG_INFO(ndpi_struct, "found CNP-IP\n");
38
0
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CNP_IP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
39
0
}
40
41
static void ndpi_search_cnp_ip(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
42
0
{
43
0
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
44
45
0
  NDPI_LOG_DBG(ndpi_struct, "search CNP-IP\n");
46
47
0
  if (packet->payload_packet_len > 20 && packet->payload_packet_len == ntohs(get_u_int16_t(packet->payload, 0)) &&
48
0
      (packet->payload[3] & 0x1F) == 0x01 && packet->payload[4] == 0 && (packet->payload[5] & 0x1F) < 0x03)
49
0
  {
50
0
    ndpi_int_cnp_ip_add_connection(ndpi_struct, flow);
51
0
    return;
52
0
  }
53
54
0
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
55
0
}
56
57
void init_cnp_ip_dissector(struct ndpi_detection_module_struct *ndpi_struct)
58
1
{
59
1
  register_dissector("CNP-IP", ndpi_struct,
60
1
                     ndpi_search_cnp_ip,
61
1
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
62
1
                     1, NDPI_PROTOCOL_CNP_IP);
63
1
}