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

PowerDNS / pdns / 12595591960

03 Jan 2025 09:27AM UTC coverage: 62.774% (+2.5%) from 60.245%
12595591960

Pull #15008

github

web-flow
Merge c2a2749d3 into 788f396a7
Pull Request #15008: Do not follow CNAME records for ANY or CNAME queries

30393 of 78644 branches covered (38.65%)

Branch coverage included in aggregate %.

105822 of 138350 relevant lines covered (76.49%)

4613078.44 hits per line

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

58.24
/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
{
82✔
31
  return makeProxyHeader(dq.overTCP(), dq.ids.origRemote, dq.ids.origDest, dq.proxyProtocolValues ? *dq.proxyProtocolValues : std::vector<ProxyProtocolValue>());
82✔
32
}
82✔
33

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

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

43
bool addProxyProtocol(DNSQuestion& dq, size_t* payloadSize)
44
{
23✔
45
  auto payload = getProxyProtocolPayload(dq);
23✔
46
  if (payloadSize != nullptr) {
23✔
47
    *payloadSize = payload.size();
21✔
48
  }
21✔
49

50
  return addProxyProtocol(dq, payload);
23✔
51
}
23✔
52

53
bool addProxyProtocol(PacketBuffer& buffer, const std::string& payload)
54
{
31✔
55
  auto previousSize = buffer.size();
31✔
56
  if (payload.size() > (std::numeric_limits<size_t>::max() - previousSize)) {
31!
57
    return false;
×
58
  }
×
59

60
  buffer.insert(buffer.begin(), payload.begin(), payload.end());
31✔
61

62
  return true;
31✔
63
}
31✔
64

65
bool addProxyProtocol(PacketBuffer& buffer, bool tcp, const ComboAddress& source, const ComboAddress& destination, const std::vector<ProxyProtocolValue>& values)
66
{
×
67
  auto payload = makeProxyHeader(tcp, source, destination, values);
×
68
  return addProxyProtocol(buffer, payload);
×
69
}
×
70

71
bool expectProxyProtocolFrom(const ComboAddress& remote)
72
{
4,388✔
73
  return dnsdist::configuration::getCurrentRuntimeConfiguration().d_proxyProtocolACL.match(remote);
4,388✔
74
}
4,388✔
75

76
bool handleProxyProtocol(const ComboAddress& remote, bool isTCP, const NetmaskGroup& acl, PacketBuffer& query, ComboAddress& realRemote, ComboAddress& realDestination, std::vector<ProxyProtocolValue>& values)
77
{
18✔
78
  bool tcp;
18✔
79
  bool proxyProto;
18✔
80

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

93
  query.erase(query.begin(), query.begin() + used);
17✔
94

95
  /* on TCP we have not read the actual query yet */
96
  if (!isTCP && query.size() < sizeof(struct dnsheader)) {
17!
97
    ++dnsdist::metrics::g_stats.nonCompliantQueries;
×
98
    return false;
×
99
  }
×
100

101
  if (proxyProto && dnsdist::configuration::getCurrentRuntimeConfiguration().d_applyACLToProxiedClients) {
17!
102
    if (!acl.match(realRemote)) {
×
103
      vinfolog("Query from %s dropped because of ACL", realRemote.toStringWithPort());
×
104
      ++dnsdist::metrics::g_stats.aclDrops;
×
105
      return false;
×
106
    }
×
107
  }
×
108

109
  return true;
17✔
110
}
17✔
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