/src/pdns/pdns/dnsdistdist/dnsdist-dnsquestion.cc
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 | | #include "dnsdist.hh" |
23 | | #include "dnsdist-configuration.hh" |
24 | | #include "dnsdist-dnsparser.hh" |
25 | | |
26 | | std::string DNSQuestion::getTrailingData() const |
27 | 0 | { |
28 | | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
29 | 0 | const auto* message = reinterpret_cast<const char*>(this->getData().data()); |
30 | 0 | const uint16_t messageLen = getDNSPacketLength(message, this->getData().size()); |
31 | | // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) |
32 | 0 | return {message + messageLen, this->getData().size() - messageLen}; |
33 | 0 | } |
34 | | |
35 | | bool DNSQuestion::setTrailingData(const std::string& tail) |
36 | 0 | { |
37 | | // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |
38 | 0 | const char* message = reinterpret_cast<const char*>(this->data.data()); |
39 | 0 | const uint16_t messageLen = getDNSPacketLength(message, this->data.size()); |
40 | 0 | this->data.resize(messageLen); |
41 | 0 | if (!tail.empty()) { |
42 | 0 | if (!hasRoomFor(tail.size())) { |
43 | 0 | return false; |
44 | 0 | } |
45 | 0 | this->data.insert(this->data.end(), tail.begin(), tail.end()); |
46 | 0 | } |
47 | 0 | return true; |
48 | 0 | } |
49 | | |
50 | | bool DNSQuestion::editHeader(const std::function<bool(dnsheader&)>& editFunction) |
51 | 0 | { |
52 | 0 | if (data.size() < sizeof(dnsheader)) { |
53 | 0 | throw std::runtime_error("Trying to access the dnsheader of a too small (" + std::to_string(data.size()) + ") DNSQuestion buffer"); |
54 | 0 | } |
55 | 0 | return dnsdist::PacketMangling::editDNSHeaderFromPacket(data, editFunction); |
56 | 0 | } |
57 | | |
58 | | DNSQuestion::DNSQuestion(InternalQueryState& ids_, PacketBuffer& data_) : |
59 | 0 | data(data_), ids(ids_), ecsPrefixLength(ids.origRemote.sin4.sin_family == AF_INET ? dnsdist::configuration::getCurrentRuntimeConfiguration().d_ECSSourcePrefixV4 : dnsdist::configuration::getCurrentRuntimeConfiguration().d_ECSSourcePrefixV6), ecsOverride(dnsdist::configuration::getCurrentRuntimeConfiguration().d_ecsOverride) |
60 | 0 | { |
61 | 0 | } |