1 /*
2 * nest_log_sink.c
3 *
4 * Copyright (C) 2009-11 - ipoque GmbH
5 * Copyright (C) 2011-21 - ntop.org
6 * Copyright (C) 2018 - eGloo Incorporated
7 *
8 * This file is part of nDPI, an open source deep packet inspection
9 * library based on the OpenDPI and PACE technology by ipoque GmbH
10 *
11 * nDPI is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * nDPI is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
23 *
24 */
25
26 #include "ndpi_protocol_ids.h"
27
28 #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NEST_LOG_SINK
29
30 #include "ndpi_api.h"
31
32 #define NEST_LOG_SINK_PORT 11095
33 #define NEST_LOG_SINK_MIN_LEN 8
34 #define NEST_LOG_SINK_MIN_MATCH 3
35
ndpi_search_nest_log_sink(struct ndpi_detection_module_struct * ndpi_struct,struct ndpi_flow_struct * flow)36 void ndpi_search_nest_log_sink(
37 struct ndpi_detection_module_struct *ndpi_struct,
38 struct ndpi_flow_struct *flow)
39 {
40 struct ndpi_packet_struct *packet = &flow->packet;
41
42 NDPI_LOG_DBG(ndpi_struct, "search nest_log_sink\n");
43
44 if (packet->payload_packet_len < NEST_LOG_SINK_MIN_LEN) {
45 NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
46 return;
47 }
48
49 if (ntohs(packet->tcp->source) != NEST_LOG_SINK_PORT &&
50 ntohs(packet->tcp->dest) != NEST_LOG_SINK_PORT) {
51 NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
52 return;
53 }
54
55 if (packet->payload[1] <= 0x02 &&
56 (packet->payload[2] == 0x00 || packet->payload[2] == 0x10) &&
57 packet->payload[3] == 0x13)
58 flow->l4.tcp.nest_log_sink_matches++;
59
60 if (flow->l4.tcp.nest_log_sink_matches == NEST_LOG_SINK_MIN_MATCH) {
61 NDPI_LOG_INFO(ndpi_struct, "found nest_log_sink\n");
62 ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NEST_LOG_SINK, NDPI_PROTOCOL_UNKNOWN);
63 }
64 }
65
init_nest_log_sink_dissector(struct ndpi_detection_module_struct * ndpi_struct,u_int32_t * id,NDPI_PROTOCOL_BITMASK * detection_bitmask)66 void init_nest_log_sink_dissector(
67 struct ndpi_detection_module_struct *ndpi_struct,
68 u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
69 {
70 ndpi_set_bitmask_protocol_detection("NEST_LOG_SINK",
71 ndpi_struct, detection_bitmask, *id,
72 NDPI_PROTOCOL_NEST_LOG_SINK,
73 ndpi_search_nest_log_sink,
74 NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD,
75 SAVE_DETECTION_BITMASK_AS_UNKNOWN,
76 ADD_TO_DETECTION_BITMASK);
77
78 *id += 1;
79 }
80