diff options
author | wssxsxxsx <147610076+wssxsxxsx@users.noreply.github.com> | 2024-08-24 04:35:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-23 22:35:08 +0200 |
commit | 8894ebc76f4e3d928dd3c2e32a0470149ce90550 (patch) | |
tree | 109a79965131d54f0b74031ec83ce55d6a3ca8d6 /src | |
parent | f03938a725695a22e301497253436b9bcfd4820d (diff) |
Add Automatic Tank Gauge protocol (#2527)
See also #2523
---------
Co-authored-by: Nardi Ivan <nardi.ivan@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_private.h | 1 | ||||
-rw-r--r-- | src/include/ndpi_protocol_ids.h | 1 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 7 | ||||
-rw-r--r-- | src/lib/protocols/atg.c | 67 |
4 files changed, 76 insertions, 0 deletions
diff --git a/src/include/ndpi_private.h b/src/include/ndpi_private.h index ae732f624..4fb1afccf 100644 --- a/src/include/ndpi_private.h +++ b/src/include/ndpi_private.h @@ -933,6 +933,7 @@ void init_cloudflare_warp_dissector(struct ndpi_detection_module_struct *ndpi_st void init_nano_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); void init_openwire_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); void init_cnp_ip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); +void init_atg_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); #endif diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h index 0f1b5e2d0..b465626b9 100644 --- a/src/include/ndpi_protocol_ids.h +++ b/src/include/ndpi_protocol_ids.h @@ -451,6 +451,7 @@ typedef enum { NDPI_PROTOCOL_NANO = 420, NDPI_PROTOCOL_OPENWIRE = 421, NDPI_PROTOCOL_CNP_IP = 422, + NDPI_PROTOCOL_ATG = 423, #ifdef CUSTOM_NDPI_PROTOCOLS #include "../../../nDPI-custom/custom_ndpi_protocol_ids.h" diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 983fadef6..b496888cb 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -2302,6 +2302,10 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp "CNP-IP", NDPI_PROTOCOL_CATEGORY_IOT_SCADA, ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */, ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */); + ndpi_set_proto_defaults(ndpi_str, 1 /* cleartext */, 0 /* nw proto */, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_ATG, + "ATG", NDPI_PROTOCOL_CATEGORY_IOT_SCADA, + ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */, + ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */); #ifdef CUSTOM_NDPI_PROTOCOLS #include "../../../nDPI-custom/custom_ndpi_main.c" @@ -6259,6 +6263,9 @@ static int ndpi_callback_init(struct ndpi_detection_module_struct *ndpi_str) { /* ISO/IEC 14908-4 */ init_cnp_ip_dissector(ndpi_str, &a); + /* ATG */ + init_atg_dissector(ndpi_str, &a); + #ifdef CUSTOM_NDPI_PROTOCOLS #include "../../../nDPI-custom/custom_ndpi_main_init.c" #endif diff --git a/src/lib/protocols/atg.c b/src/lib/protocols/atg.c new file mode 100644 index 000000000..cc25a70ce --- /dev/null +++ b/src/lib/protocols/atg.c @@ -0,0 +1,67 @@ +/* + * atg.c + * + * Copyright (C) 2024 - ntop.org + * + * nDPI is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * nDPI is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with nDPI. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include "ndpi_protocol_ids.h" + +#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_ATG + +#include "ndpi_api.h" +#include "ndpi_private.h" + +static void ndpi_int_atg_add_connection(struct ndpi_detection_module_struct + *ndpi_struct, struct ndpi_flow_struct *flow) { + ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ATG, + NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); +} + + +static void ndpi_search_atg(struct ndpi_detection_module_struct *ndpi_struct, + struct ndpi_flow_struct *flow) { + struct ndpi_packet_struct *packet = &ndpi_struct->packet; + + NDPI_LOG_DBG(ndpi_struct, "search for ATG\n"); + + if(packet->payload_packet_len >= 8) { + u_int16_t atg_port = ntohs(10001); + + if((packet->tcp->source == atg_port) || (packet->tcp->dest == atg_port)) { + if(packet->payload[0] == 0x01 && + (packet->payload[1] == 0x49 || packet->payload[1] == 0x69 || packet->payload[1] == 0x53 || packet->payload[1] == 0x73 ) && + memcmp(&packet->payload[packet->payload_packet_len - 2], "\r\n", 2) == 0) { + NDPI_LOG_INFO(ndpi_struct, "found atg\n"); + ndpi_int_atg_add_connection(ndpi_struct, flow); + return; + } + } + } + + NDPI_EXCLUDE_PROTO(ndpi_struct, flow); +} + +void init_atg_dissector(struct ndpi_detection_module_struct *ndpi_struct, + u_int32_t *id) { + ndpi_set_bitmask_protocol_detection("ATG", ndpi_struct, *id, + NDPI_PROTOCOL_ATG, + ndpi_search_atg, + NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, + SAVE_DETECTION_BITMASK_AS_UNKNOWN, + ADD_TO_DETECTION_BITMASK); + *id += 1; +} |