Skip to content

Commit 2b23a2c

Browse files
committed
Improve HAProxy to support Proxy Protocol v2 as well
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
1 parent 9eb914d commit 2b23a2c

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

doc/protocols.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3185,7 +3185,7 @@ Notes:
31853185
========================
31863186
HAProxy is a high availability load balancer and reverse proxy.
31873187

3188-
References: `HAProxy official site: <https://www.haproxy.org>`_
3188+
References: `HAProxy official site: <https://www.haproxy.org>`_, `Proxy Protocol v2: <https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt>`_
31893189

31903190

31913191
.. _Proto_351:

src/lib/protocols/haproxy.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ static void ndpi_int_haproxy_add_connection(struct ndpi_detection_module_struct
2929
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HAPROXY, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
3030
}
3131

32+
static int search_proxy_protocol_v2(struct ndpi_detection_module_struct *ndpi_struct)
33+
{
34+
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
35+
static const unsigned char pp2_sig[] = { 0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54, 0x0A };
36+
37+
if (packet->payload_packet_len < sizeof(pp2_sig)) {
38+
return 0;
39+
}
40+
41+
if (memcmp(packet->payload, pp2_sig, sizeof(pp2_sig)) == 0) {
42+
return 1;
43+
}
44+
45+
return 0;
46+
}
47+
3248
static void ndpi_search_haproxy(struct ndpi_detection_module_struct *ndpi_struct,
3349
struct ndpi_flow_struct *flow)
3450
{
@@ -37,6 +53,12 @@ static void ndpi_search_haproxy(struct ndpi_detection_module_struct *ndpi_struct
3753

3854
NDPI_LOG_DBG(ndpi_struct, "search HAProxy\n");
3955

56+
if (search_proxy_protocol_v2(ndpi_struct) != 0) {
57+
NDPI_LOG_DBG(ndpi_struct, "found HAProxy (Proxy Protocol v2)\n");
58+
ndpi_int_haproxy_add_connection(ndpi_struct, flow);
59+
return;
60+
}
61+
4062
if (packet->payload_packet_len < NDPI_STATICSTRING_LEN("PROXY TCP"))
4163
{
4264
NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);

0 commit comments

Comments
 (0)