Coverage Report

Created: 2025-08-03 06:32

/src/ndpi/src/lib/protocols/dlep.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * dlep.c
3
 *
4
 * Dynamic Link Exchange Protocol
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_DLEP
30
31
#include "ndpi_api.h"
32
#include "ndpi_private.h"
33
34
static void ndpi_int_dlep_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 DLEP\n");
38
0
  ndpi_set_detected_protocol(ndpi_struct, flow,
39
0
                             NDPI_PROTOCOL_DLEP, NDPI_PROTOCOL_UNKNOWN,
40
0
                             NDPI_CONFIDENCE_DPI);
41
0
}
42
43
static void ndpi_search_dlep(struct ndpi_detection_module_struct *ndpi_struct,
44
                             struct ndpi_flow_struct *flow)
45
2.63k
{
46
2.63k
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
47
48
2.63k
  NDPI_LOG_DBG(ndpi_struct, "search DLEP\n");
49
50
2.63k
  if (packet->udp != NULL && packet->payload_packet_len > 27) {
51
608
    if ((memcmp(packet->payload, "DLEP", 4) == 0)) {
52
0
      ndpi_int_dlep_add_connection(ndpi_struct, flow);
53
0
      return;
54
0
    }
55
2.02k
  } else if (packet->tcp != NULL) {
56
    /* Maybe it's unnecessary, but it'll definitely eliminate any false positives. 
57
     * 854 port is IANA registered for DLEP. */
58
1.93k
    if (packet->payload_packet_len > 8 &&
59
1.93k
        (ntohs(packet->tcp->dest) == 854 || ntohs(packet->tcp->source) == 854))
60
1
    {
61
1
      if (ntohs(get_u_int16_t(packet->payload, 0)) < 0x11 &&
62
1
          ntohs(get_u_int16_t(packet->payload, 2)) == (u_int16_t)(packet->payload_packet_len-4))
63
0
      {
64
0
        ndpi_int_dlep_add_connection(ndpi_struct, flow);
65
0
        return;
66
0
      }
67
1
    }
68
1.93k
  }
69
70
2.63k
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
71
2.63k
}
72
73
void init_dlep_dissector(struct ndpi_detection_module_struct *ndpi_struct)
74
8.01k
{
75
8.01k
  register_dissector("DLEP", ndpi_struct,
76
8.01k
                     ndpi_search_dlep,
77
8.01k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
78
8.01k
                     1, NDPI_PROTOCOL_DLEP);
79
8.01k
}