Coverage Report

Created: 2025-08-03 06:23

/src/ndpi/src/lib/protocols/rmcp.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * rmcp.c
3
 *
4
 * Copyright (C) 2023 - ntop.org
5
 *
6
 * This file is part of nDPI, an open source deep packet inspection
7
 * library based on the OpenDPI and PACE technology by ipoque GmbH
8
 *
9
 * nDPI is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Lesser General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * nDPI is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
#include "ndpi_protocol_ids.h"
25
26
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_RMCP
27
28
#include "ndpi_api.h"
29
#include "ndpi_private.h"
30
31
PACK_ON
32
struct rmcp_header {
33
  uint8_t version;
34
  uint8_t reserved;
35
  uint8_t sequence;
36
#if defined(__BIG_ENDIAN__)
37
  uint8_t type : 1; // Either Normal RMCP (0) or ACK (1)
38
  uint8_t class : 7;
39
#elif defined(__LITTLE_ENDIAN__)
40
  uint8_t class : 7;
41
  uint8_t type : 1; // Either Normal RMCP (0) or ACK (1)
42
#else
43
#error "Missing endian macro definitions."
44
#endif
45
} PACK_OFF;
46
47
static void ndpi_int_rmcp_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
48
                                         struct ndpi_flow_struct *flow)
49
0
{
50
0
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RMCP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
51
0
}
52
53
static void ndpi_search_rmcp(struct ndpi_detection_module_struct *ndpi_struct,
54
                             struct ndpi_flow_struct *flow)
55
0
{
56
0
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
57
58
0
  NDPI_LOG_DBG(ndpi_struct, "search RMCP\n");
59
60
0
  if (packet->payload_packet_len < sizeof(struct rmcp_header)) {
61
0
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
62
0
    return;
63
0
  }
64
65
0
  struct rmcp_header const * const rmcp_header = (struct rmcp_header *)packet->payload;
66
67
0
  if (rmcp_header->version != 0x06 || rmcp_header->reserved != 0x00) {
68
0
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
69
0
    return;
70
0
  }
71
72
0
  if (rmcp_header->type != 0 && rmcp_header->sequence == 0xFF) {
73
    // No ACK allowed if SEQUENCE number is 255.
74
0
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
75
0
    return;
76
0
  }
77
78
0
  if (rmcp_header->class != 0x06 /* Alert Standard Forum (ASF)*/
79
0
      && rmcp_header->class != 0x07 /* Intelligent Platform Management Interface (IPMI) */)
80
0
  {
81
0
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
82
0
    return;
83
0
  }
84
85
0
  ndpi_int_rmcp_add_connection(ndpi_struct, flow);
86
0
}
87
88
89
void init_rmcp_dissector(struct ndpi_detection_module_struct *ndpi_struct)
90
0
{
91
0
  register_dissector("RMCP", ndpi_struct,
92
0
                     ndpi_search_rmcp,
93
0
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
94
0
                     1, NDPI_PROTOCOL_RMCP);
95
0
}
96