Coverage Report

Created: 2025-11-02 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/nano.c
Line
Count
Source
1
/*
2
 * nano.c
3
 *
4
 * Nano Network 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_NANO
30
31
#include "ndpi_api.h"
32
#include "ndpi_private.h"
33
34
/* 
35
 * Look for the latest version at https://docs.nano.org/releases/node-releases
36
 */
37
0
#define NANO_MIN_PROTOCOL_VER 18
38
0
#define NANO_MAX_PROTOCOL_VER 20
39
40
static void ndpi_int_nano_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
41
                                         struct ndpi_flow_struct *flow)
42
0
{
43
0
  NDPI_LOG_INFO(ndpi_struct, "found Nano Network Protocol\n");
44
45
0
  ndpi_set_detected_protocol(ndpi_struct, flow,
46
0
                             NDPI_PROTOCOL_NANO, NDPI_PROTOCOL_UNKNOWN,
47
0
                             NDPI_CONFIDENCE_DPI);
48
49
0
  if(ndpi_struct->mining_cache)
50
0
  {
51
0
    ndpi_lru_add_to_cache(ndpi_struct->mining_cache, mining_make_lru_cache_key(flow),
52
0
                          NDPI_PROTOCOL_NANO, ndpi_get_current_time(flow));
53
0
  }
54
0
}
55
56
static void ndpi_search_nano(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
57
0
{
58
0
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
59
60
0
  NDPI_LOG_DBG(ndpi_struct, "search Nano Network Protocol\n");
61
62
0
  if (packet->payload_packet_len > 32 &&
63
0
      packet->payload[0] == 'R' && packet->payload[1] == 'C')
64
0
  {
65
0
    const u_int8_t max_ver = packet->payload[2];
66
0
    const u_int8_t use_ver = packet->payload[3];
67
0
    const u_int8_t min_ver = packet->payload[4];
68
69
0
    if (max_ver == NANO_MAX_PROTOCOL_VER &&
70
0
        use_ver <= NANO_MAX_PROTOCOL_VER && use_ver >= NANO_MIN_PROTOCOL_VER &&
71
0
        min_ver >= NANO_MIN_PROTOCOL_VER && min_ver < NANO_MAX_PROTOCOL_VER &&
72
0
        packet->payload[5] <= 0x0F)
73
0
    {
74
0
      ndpi_int_nano_add_connection(ndpi_struct, flow);
75
0
      return;
76
0
    }
77
0
  }
78
79
0
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
80
0
}
81
82
void init_nano_dissector(struct ndpi_detection_module_struct *ndpi_struct)
83
1
{
84
1
  register_dissector("Nano", ndpi_struct,
85
1
                     ndpi_search_nano,
86
1
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
87
1
                     1, NDPI_PROTOCOL_NANO);
88
1
}