Coverage Report

Created: 2024-04-25 06:27

/src/pdns/pdns/dnsdistdist/proxy-protocol.hh
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
23
#pragma once
24
25
#include "iputils.hh"
26
27
struct ProxyProtocolValue
28
{
29
  std::string content;
30
  uint8_t type;
31
32
  bool operator==(const ProxyProtocolValue& rhs) const
33
0
  {
34
0
    return type == rhs.type && content == rhs.content;
35
0
  }
36
37
  enum class Types : uint8_t { PP_TLV_ALPN = 0x01, PP_TLV_SSL = 0x20 };
38
};
39
40
static const size_t s_proxyProtocolMinimumHeaderSize = 16;
41
42
std::string makeLocalProxyHeader();
43
std::string makeProxyHeader(bool tcp, const ComboAddress& source, const ComboAddress& destination, const std::vector<ProxyProtocolValue>& values);
44
45
/* returns: number of bytes consumed (positive) after successful parse
46
         or number of bytes missing (negative)
47
         or unfixable parse error (0)*/
48
template<typename Container> ssize_t isProxyHeaderComplete(const Container& header, bool* proxy=nullptr, bool* tcp=nullptr, size_t* addrSizeOut=nullptr, uint8_t* protocolOut=nullptr);
49
50
/* returns: number of bytes consumed (positive) after successful parse
51
         or number of bytes missing (negative)
52
         or unfixable parse error (0)*/
53
template<typename Container> ssize_t parseProxyHeader(const Container& header, bool& proxy, ComboAddress& source, ComboAddress& destination, bool& tcp, std::vector<ProxyProtocolValue>& values);