/src/ndpi/src/lib/protocols/glbp.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * glbp.c |
3 | | * |
4 | | * Gateway Load Balancing Protocol |
5 | | * |
6 | | * Copyright (C) 2025 - ntop.org |
7 | | * Copyright (C) 2025 - V.G <v.gavrilov@securitycode.ru> |
8 | | * |
9 | | * This file is part of nDPI, an open source deep packet inspection |
10 | | * library based on the OpenDPI and PACE technology by ipoque GmbH |
11 | | * |
12 | | * nDPI is free software: you can redistribute it and/or modify |
13 | | * it under the terms of the GNU Lesser General Public License as published by |
14 | | * the Free Software Foundation, either version 3 of the License, or |
15 | | * (at your option) any later version. |
16 | | * |
17 | | * nDPI is distributed in the hope that it will be useful, |
18 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | | * GNU Lesser General Public License for more details. |
21 | | * |
22 | | * You should have received a copy of the GNU Lesser General Public License |
23 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
24 | | * |
25 | | */ |
26 | | |
27 | | #include "ndpi_protocol_ids.h" |
28 | | |
29 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_GLBP |
30 | | |
31 | | #include "ndpi_api.h" |
32 | | #include "ndpi_private.h" |
33 | | |
34 | | #define GLBP_PORT 3222 /* IANA registered */ |
35 | | |
36 | | static void ndpi_int_glbp_add_connection(struct ndpi_detection_module_struct * const ndpi_struct, |
37 | | struct ndpi_flow_struct * const flow) |
38 | 0 | { |
39 | 0 | NDPI_LOG_INFO(ndpi_struct, "found GLBP\n"); |
40 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, |
41 | 0 | NDPI_PROTOCOL_GLBP, NDPI_PROTOCOL_UNKNOWN, |
42 | 0 | NDPI_CONFIDENCE_DPI); |
43 | 0 | } |
44 | | |
45 | | static void ndpi_search_glbp(struct ndpi_detection_module_struct *ndpi_struct, |
46 | | struct ndpi_flow_struct *flow) |
47 | 0 | { |
48 | 0 | struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; |
49 | |
|
50 | 0 | NDPI_LOG_DBG(ndpi_struct, "search GLBP\n"); |
51 | |
|
52 | 0 | if (packet->payload_packet_len < 12) { |
53 | 0 | goto exclude; |
54 | 0 | } |
55 | | |
56 | 0 | if ((packet->udp->source != htons(GLBP_PORT)) || |
57 | 0 | (packet->udp->dest != htons(GLBP_PORT))) |
58 | 0 | { |
59 | 0 | goto exclude; |
60 | 0 | } |
61 | | |
62 | 0 | if ((packet->payload[0] > 1) || |
63 | 0 | (ntohs(get_u_int16_t(packet->payload, 2)) > 1023)) |
64 | 0 | { |
65 | 0 | goto exclude; |
66 | 0 | } |
67 | | |
68 | 0 | ndpi_int_glbp_add_connection(ndpi_struct, flow); |
69 | 0 | return; |
70 | | |
71 | 0 | exclude: |
72 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
73 | 0 | } |
74 | | |
75 | | void init_glbp_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
76 | 0 | { |
77 | 0 | register_dissector("GLBP", ndpi_struct, |
78 | 0 | ndpi_search_glbp, |
79 | 0 | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD, |
80 | 0 | 1, NDPI_PROTOCOL_GLBP); |
81 | 0 | } |