Skip to content

Commit 5eb468d

Browse files
authored
Add Apache Kafka protocol dissector (#2226)
1 parent 6fc8aa4 commit 5eb468d

File tree

101 files changed

+207
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+207
-99
lines changed

doc/protocols.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,12 @@ References: `RFC4918: <https://datatracker.ietf.org/doc/html/rfc4918>`_.
399399
Notes:
400400

401401
- WebDAV is almost always encrypted, i.e. transported over TLS.
402+
403+
404+
.. _Proto 377:
405+
406+
`NDPI_PROTOCOL_APACHE_KAFKA`
407+
======================
408+
Apache Kafka is a distributed event store and stream-processing platform.
409+
410+
References: `Official site <https://kafka.apache.org>`_ and `Github <https://github.com/apache/kafka>`_.

src/include/ndpi_protocol_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ typedef enum {
405405
NDPI_PROTOCOL_OPENFLOW = 374,
406406
NDPI_PROTOCOL_JSON_RPC = 375,
407407
NDPI_PROTOCOL_WEBDAV = 376,
408+
NDPI_PROTOCOL_APACHE_KAFKA = 377,
408409

409410
#ifdef CUSTOM_NDPI_PROTOCOLS
410411
#include "../../../nDPI-custom/custom_ndpi_protocol_ids.h"

src/lib/ndpi_main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,10 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
22132213
"WebDAV", NDPI_PROTOCOL_CATEGORY_COLLABORATIVE,
22142214
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */
22152215
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0)); /* UDP */
2216+
ndpi_set_proto_defaults(ndpi_str, 1 /* cleartext */, 0 /* nw proto */, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_APACHE_KAFKA,
2217+
"Kafka", NDPI_PROTOCOL_CATEGORY_RPC,
2218+
ndpi_build_default_ports(ports_a, 9092, 0, 0, 0, 0) /* TCP */,
2219+
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
22162220

22172221
#ifdef CUSTOM_NDPI_PROTOCOLS
22182222
#include "../../../nDPI-custom/custom_ndpi_main.c"
@@ -5716,6 +5720,9 @@ static int ndpi_callback_init(struct ndpi_detection_module_struct *ndpi_str) {
57165720
/* JSON-RPC */
57175721
init_json_rpc_dissector(ndpi_str, &a);
57185722

5723+
/* Apache Kafka */
5724+
init_kafka_dissector(ndpi_str, &a);
5725+
57195726
#ifdef CUSTOM_NDPI_PROTOCOLS
57205727
#include "../../../nDPI-custom/custom_ndpi_main_init.c"
57215728
#endif

src/lib/ndpi_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ void init_hislip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_i
639639
void init_uftp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
640640
void init_openflow_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
641641
void init_json_rpc_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
642+
void init_kafka_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
642643

643644
#endif
644645

src/lib/protocols/kafka.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* kafka.c
3+
*
4+
* Copyright (C) 2023 - ntop.org
5+
* Copyright (C) 2023 - V.G <[email protected]>
6+
*
7+
* This file is part of nDPI, an open source deep packet inspection
8+
* library based on the OpenDPI and PACE technology by ipoque GmbH
9+
*
10+
* nDPI is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* nDPI is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Lesser General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Lesser General Public License
21+
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
#include "ndpi_protocol_ids.h"
26+
27+
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_APACHE_KAFKA
28+
29+
#include "ndpi_api.h"
30+
#include "ndpi_private.h"
31+
32+
static void ndpi_search_kafka(struct ndpi_detection_module_struct *ndpi_struct,
33+
struct ndpi_flow_struct *flow)
34+
{
35+
struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
36+
37+
NDPI_LOG_DBG(ndpi_struct, "search Apache Kafka\n");
38+
39+
if (current_pkt_from_client_to_server(ndpi_struct, flow) &&
40+
packet->payload_packet_len > 40 &&
41+
ntohl(get_u_int32_t(packet->payload, 0)) == (u_int32_t)(packet->payload_packet_len-4) &&
42+
ntohs(get_u_int16_t(packet->payload, 4)) < 69)
43+
{
44+
NDPI_LOG_INFO(ndpi_struct, "found Apache Kafka\n");
45+
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_APACHE_KAFKA,
46+
NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
47+
return;
48+
}
49+
50+
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
51+
}
52+
53+
void init_kafka_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id)
54+
{
55+
ndpi_set_bitmask_protocol_detection("Kafka", ndpi_struct, *id,
56+
NDPI_PROTOCOL_APACHE_KAFKA,
57+
ndpi_search_kafka,
58+
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
59+
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
60+
ADD_TO_DETECTION_BITMASK);
61+
*id += 1;
62+
}

tests/cfgs/caches_cfg/result/ookla.pcap.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Guessed flow protos: 1
33
DPI Packets (TCP): 40 (6.67 pkts/flow)
44
Confidence Match by port : 1 (flows)
55
Confidence DPI : 5 (flows)
6-
Num dissector calls: 540 (90.00 diss/flow)
6+
Num dissector calls: 543 (90.50 diss/flow)
77
LRU cache ookla: 0/0/0 (insert/search/found)
88
LRU cache bittorrent: 0/3/0 (insert/search/found)
99
LRU cache zoom: 0/0/0 (insert/search/found)

tests/cfgs/caches_cfg/result/teams.pcap.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DPI Packets (other): 1 (1.00 pkts/flow)
66
Confidence Unknown : 1 (flows)
77
Confidence Match by port : 2 (flows)
88
Confidence DPI : 80 (flows)
9-
Num dissector calls: 525 (6.33 diss/flow)
9+
Num dissector calls: 526 (6.34 diss/flow)
1010
LRU cache ookla: 0/0/0 (insert/search/found)
1111
LRU cache bittorrent: 0/9/0 (insert/search/found)
1212
LRU cache zoom: 0/0/0 (insert/search/found)

tests/cfgs/default/pcap/kafka.pcapng

3.16 KB
Binary file not shown.

tests/cfgs/default/result/1kxun.pcap.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DPI Packets (UDP): 120 (1.21 pkts/flow)
55
Confidence Unknown : 14 (flows)
66
Confidence Match by port : 6 (flows)
77
Confidence DPI : 177 (flows)
8-
Num dissector calls: 4753 (24.13 diss/flow)
8+
Num dissector calls: 4756 (24.14 diss/flow)
99
LRU cache ookla: 0/0/0 (insert/search/found)
1010
LRU cache bittorrent: 0/60/0 (insert/search/found)
1111
LRU cache zoom: 0/0/0 (insert/search/found)

tests/cfgs/default/result/443-chrome.pcap.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Guessed flow protos: 1
22

33
DPI Packets (TCP): 1 (1.00 pkts/flow)
44
Confidence Match by port : 1 (flows)
5-
Num dissector calls: 133 (133.00 diss/flow)
5+
Num dissector calls: 134 (134.00 diss/flow)
66
LRU cache ookla: 0/0/0 (insert/search/found)
77
LRU cache bittorrent: 0/3/0 (insert/search/found)
88
LRU cache zoom: 0/0/0 (insert/search/found)

0 commit comments

Comments
 (0)