• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.73
/pdns/dnsdistdist/dnsdist-proxy-protocol.cc
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
#include "dnsdist-proxy-protocol.hh"
24

25
#include "dnsdist.hh"
26
#include "dnsdist-metrics.hh"
27
#include "dolog.hh"
28

29
std::string getProxyProtocolPayload(const DNSQuestion& dq)
30
{
101✔
31
  return makeProxyHeader(dq.overTCP(), dq.ids.origRemote, dq.ids.origDest, dq.proxyProtocolValues ? *dq.proxyProtocolValues : std::vector<ProxyProtocolValue>());
101✔
32
}
101✔
33

34
bool addProxyProtocol(DNSQuestion& dq, const std::string& payload)
35
{
22✔
36
  if (!dq.hasRoomFor(payload.size())) {
22!
37
    return false;
×
38
  }
×
39

40
  return addProxyProtocol(dq.getMutableData(), payload);
22✔
41
}
22✔
42

43
bool addProxyProtocol(DNSQuestion& dnsQuestion, size_t* proxyProtocolPayloadSize)
44
{
24✔
45
  auto payload = getProxyProtocolPayload(dnsQuestion);
24✔
46
  size_t payloadSize = payload.size();
24✔
47

48
  if (!addProxyProtocol(dnsQuestion, payload)) {
24!
49
    return false;
×
50
  }
×
51

52
  if (proxyProtocolPayloadSize != nullptr) {
24✔
53
    *proxyProtocolPayloadSize = payloadSize;
22✔
54
  }
22✔
55
  return true;
24✔
56
}
24✔
57

58
bool addProxyProtocol(PacketBuffer& buffer, const std::string& payload)
59
{
32✔
60
  auto previousSize = buffer.size();
32✔
61
  if (payload.size() > (std::numeric_limits<size_t>::max() - previousSize)) {
32!
62
    return false;
×
63
  }
×
64

65
  buffer.insert(buffer.begin(), payload.begin(), payload.end());
32✔
66

67
  return true;
32✔
68
}
32✔
69

70
bool addProxyProtocol(PacketBuffer& buffer, bool tcp, const ComboAddress& source, const ComboAddress& destination, const std::vector<ProxyProtocolValue>& values)
71
{
×
72
  auto payload = makeProxyHeader(tcp, source, destination, values);
×
73
  return addProxyProtocol(buffer, payload);
×
74
}
×
75

76
bool expectProxyProtocolFrom(const ComboAddress& remote)
77
{
5,731✔
78
  return dnsdist::configuration::getCurrentRuntimeConfiguration().d_proxyProtocolACL.match(remote);
5,731✔
79
}
5,731✔
80

81
bool handleProxyProtocol(const ComboAddress& remote, bool isTCP, const NetmaskGroup& acl, PacketBuffer& query, ComboAddress& realRemote, ComboAddress& realDestination, std::vector<ProxyProtocolValue>& values)
82
{
19✔
83
  bool tcp;
19✔
84
  bool proxyProto;
19✔
85

86
  ssize_t used = parseProxyHeader(query, proxyProto, realRemote, realDestination, tcp, values);
19✔
87
  if (used <= 0) {
19✔
88
    ++dnsdist::metrics::g_stats.proxyProtocolInvalid;
1✔
89
    vinfolog("Ignoring invalid proxy protocol (%d, %d) query over %s from %s", query.size(), used, (isTCP ? "TCP" : "UDP"), remote.toStringWithPort());
1!
90
    return false;
1✔
91
  }
1✔
92
  if (static_cast<size_t>(used) > dnsdist::configuration::getCurrentRuntimeConfiguration().d_proxyProtocolMaximumSize) {
18!
93
    vinfolog("Proxy protocol header in %s packet from %s is larger than proxy-protocol-maximum-size (%d), dropping", (isTCP ? "TCP" : "UDP"), remote.toStringWithPort(), used);
×
94
    ++dnsdist::metrics::g_stats.proxyProtocolInvalid;
×
95
    return false;
×
96
  }
×
97

98
  query.erase(query.begin(), query.begin() + used);
18✔
99

100
  /* on TCP we have not read the actual query yet */
101
  if (!isTCP && query.size() < sizeof(struct dnsheader)) {
18!
102
    ++dnsdist::metrics::g_stats.nonCompliantQueries;
×
103
    return false;
×
104
  }
×
105

106
  if (proxyProto && dnsdist::configuration::getCurrentRuntimeConfiguration().d_applyACLToProxiedClients) {
18!
107
    if (!acl.match(realRemote)) {
×
108
      vinfolog("Query from %s dropped because of ACL", realRemote.toStringWithPort());
×
109
      ++dnsdist::metrics::g_stats.aclDrops;
×
110
      return false;
×
111
    }
×
112
  }
×
113

114
  return true;
18✔
115
}
18✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc