From 4a22d7ca1d4f711b0d777095e5ce793e04a93c78 Mon Sep 17 00:00:00 2001
From: Emmanuel Hocdet <manu@gandi.net>
Date: Mon, 5 Feb 2018 16:23:23 +0100
Subject: [PATCH 3/3] MINOR: accept-proxy: support proxy protocol v2 CRC32c
 checksum

When proxy protocol v2 CRC32c tlv is received, check it before accept
connection (as describe in "doc/proxy-protocol.txt").
---
 src/connection.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/connection.c b/src/connection.c
index 833763e4c..8fd3209d5 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -612,6 +612,13 @@ int conn_recv_proxy(struct connection *conn, int flag)
 				tlv_offset += tlv_len + TLV_HEADER_SIZE;
 
 				switch (tlv_packet->type) {
+				case PP2_TYPE_CRC32C: {
+					uint32_t n_crc32c = ntohl(*(uint32_t *)tlv_packet->value);
+					*(uint32_t *)tlv_packet->value = 0;
+					if (hash_crc32c(trash.str, PP2_HEADER_LEN + ntohs(hdr_v2->len)) != n_crc32c)
+						goto bad_header;
+					break;
+				}
 #ifdef CONFIG_HAP_NS
 				case PP2_TYPE_NETNS: {
 					const struct netns_entry *ns;
-- 
2.11.0

