]> git.ipfire.org Git - thirdparty/squid.git/blame - src/proxyp/Elements.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / proxyp / Elements.h
CommitLineData
36c774f7 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
36c774f7
EB
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_PROXYP_ELEMENTS_H
10#define SQUID_PROXYP_ELEMENTS_H
11
12#include "sbuf/SBuf.h"
13
14// https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
15namespace ProxyProtocol {
16namespace Two {
17
18/// numeric IDs of registered PROXY protocol TLV types and pseudo headers
19typedef enum {
20 htUnknown = 0x00,
21
22 // The PROXY protocol specs list these TLV types as already registered.
23 htAlpn = 0x01, // PP2_TYPE_ALPN
24 htAuthority = 0x02, // PP2_TYPE_AUTHORITY
25 htCrc32c = 0x03, // PP2_TYPE_CRC32C
26 htNoop = 0x04, // PP2_TYPE_NOOP
27 htSsl = 0x20, // PP2_TYPE_SSL
28 htSslVersion = 0x21, // PP2_SUBTYPE_SSL_VERSION
29 htSslCn = 0x22, // PP2_SUBTYPE_SSL_CN
30 htSslCipher = 0x23, // PP2_SUBTYPE_SSL_CIPHER
31 htSslSigAlg = 0x24, // PP2_SUBTYPE_SSL_SIG_ALG
32 htSslKeyAlg = 0x25, // PP2_SUBTYPE_SSL_KEY_ALG
33 htNetns = 0x30, // PP2_TYPE_NETNS
34
35 // IDs for PROXY protocol header pseudo-headers.
36 // Larger than 255 to avoid clashes with possible TLV type IDs.
e015580e
EB
37 htPseudoBegin = 0x101, // smallest pseudo-header value (for iteration)
38 htPseudoVersion,
39 htPseudoCommand,
40 htPseudoSrcAddr,
41 htPseudoDstAddr,
42 htPseudoSrcPort,
43 htPseudoDstPort,
44 htPseudoEnd // largest pseudo-header value plus 1 (for iteration)
36c774f7
EB
45} FieldType;
46
47/// PROXY protocol 'command' field value
48typedef enum {
49 cmdLocal = 0x00,
50 cmdProxy = 0x01
51} Command;
52
53typedef enum {
54 /// corresponds to a local connection or an unsupported protocol family
55 afUnspecified = 0x00,
56 afInet = 0x1,
57 afInet6 = 0x2,
58 afUnix = 0x3
59} AddressFamily;
60
61typedef enum {
62 tpUnspecified = 0x00,
63 tpStream = 0x1,
64 tpDgram = 0x2
65} TransportProtocol;
66
67/// a single Type-Length-Value (TLV) block from PROXY protocol specs
68class Tlv
69{
70public:
71 typedef uint8_t value_type;
72
73 Tlv(const value_type t, const SBuf &val): value(val), type(t) {}
74
75 SBuf value;
76 value_type type;
77};
78
79} // namespace Two
80
e015580e
EB
81/// \returns human-friendly PROXY protocol field name for the given field type
82/// from the [htPseudoBegin,htPseudoEnd) range
83const SBuf &PseudoFieldTypeToFieldName(const Two::FieldType);
36c774f7
EB
84
85/// Parses human-friendly PROXY protocol field type representation.
86/// Only pseudo headers can (and should) be represented by their names.
87Two::FieldType FieldNameToFieldType(const SBuf &nameOrId);
88
89} // namespace ProxyProtocol
90
91#endif
92