Coverage Report

Created: 2025-08-29 06:29

/src/ndpi/src/lib/protocols/rmcp.c
Line
Count
Source
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
1
{
50
1
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RMCP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
51
1
}
52
53
static void ndpi_search_rmcp(struct ndpi_detection_module_struct *ndpi_struct,
54
                             struct ndpi_flow_struct *flow)
55
831
{
56
831
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
57
58
831
  NDPI_LOG_DBG(ndpi_struct, "search RMCP\n");
59
60
831
  if (packet->payload_packet_len < sizeof(struct rmcp_header)) {
61
7
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
62
7
    return;
63
7
  }
64
65
824
  struct rmcp_header const * const rmcp_header = (struct rmcp_header *)packet->payload;
66
67
824
  if (rmcp_header->version != 0x06 || rmcp_header->reserved != 0x00) {
68
818
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
69
818
    return;
70
818
  }
71
72
6
  if (rmcp_header->type != 0 && rmcp_header->sequence == 0xFF) {
73
    // No ACK allowed if SEQUENCE number is 255.
74
1
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
75
1
    return;
76
1
  }
77
78
5
  if (rmcp_header->class != 0x06 /* Alert Standard Forum (ASF)*/
79
5
      && rmcp_header->class != 0x07 /* Intelligent Platform Management Interface (IPMI) */)
80
4
  {
81
4
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
82
4
    return;
83
4
  }
84
85
1
  ndpi_int_rmcp_add_connection(ndpi_struct, flow);
86
1
}
87
88
89
void init_rmcp_dissector(struct ndpi_detection_module_struct *ndpi_struct)
90
8.20k
{
91
8.20k
  register_dissector("RMCP", ndpi_struct,
92
8.20k
                     ndpi_search_rmcp,
93
8.20k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
94
8.20k
                     1, NDPI_PROTOCOL_RMCP);
95
8.20k
}
96