/src/ndpi/src/lib/protocols/haproxy.c
Line | Count | Source |
1 | | /* |
2 | | * haproxy.c |
3 | | * |
4 | | * Copyright (C) 2023 - ntop.org |
5 | | * |
6 | | * nDPI is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * nDPI is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
18 | | * |
19 | | */ |
20 | | #include "ndpi_protocol_ids.h" |
21 | | |
22 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HAPROXY |
23 | | |
24 | | #include "ndpi_api.h" |
25 | | #include "ndpi_private.h" |
26 | | |
27 | | static void ndpi_int_haproxy_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) |
28 | 0 | { |
29 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HAPROXY, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); |
30 | 0 | } |
31 | | |
32 | | static void ndpi_search_haproxy(struct ndpi_detection_module_struct *ndpi_struct, |
33 | | struct ndpi_flow_struct *flow) |
34 | 0 | { |
35 | 0 | struct ndpi_packet_struct *packet = &ndpi_struct->packet; |
36 | 0 | const uint8_t *haproxy_end; |
37 | |
|
38 | 0 | NDPI_LOG_DBG(ndpi_struct, "search HAProxy\n"); |
39 | |
|
40 | 0 | if (packet->payload_packet_len < NDPI_STATICSTRING_LEN("PROXY TCP")) |
41 | 0 | { |
42 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
43 | 0 | return; |
44 | 0 | } |
45 | | |
46 | 0 | if (strncmp((char *)packet->payload, "PROXY TCP", NDPI_STATICSTRING_LEN("PROXY TCP")) != 0) |
47 | 0 | { |
48 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
49 | 0 | return; |
50 | 0 | } |
51 | | |
52 | | /* The following code may be also used in the future to call subprotocol dissectors e.g. TLS. */ |
53 | 0 | haproxy_end = (uint8_t *)ndpi_strnstr((char *)packet->payload, "\r\n", packet->payload_packet_len); |
54 | 0 | if (haproxy_end == NULL) |
55 | 0 | { |
56 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
57 | 0 | return; |
58 | 0 | } |
59 | 0 | haproxy_end += 2; |
60 | 0 | if (packet->payload_packet_len - (haproxy_end - packet->payload) == 0) |
61 | 0 | { |
62 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
63 | 0 | return; |
64 | 0 | } |
65 | | |
66 | 0 | ndpi_int_haproxy_add_connection(ndpi_struct, flow); |
67 | 0 | } |
68 | | |
69 | | void init_haproxy_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
70 | 0 | { |
71 | 0 | register_dissector("HAProxy", ndpi_struct, |
72 | 0 | ndpi_search_haproxy, |
73 | 0 | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, |
74 | 0 | 1, NDPI_PROTOCOL_HAPROXY); |
75 | 0 | } |