]>
Commit | Line | Data |
---|---|---|
53c57da7 RG |
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-xpf.hh" | |
24 | ||
25 | #include "dnsparser.hh" | |
26 | #include "xpf.hh" | |
27 | ||
341d2553 | 28 | bool addXPF(DNSQuestion& dq, uint16_t optionCode) |
53c57da7 | 29 | { |
592b1d99 | 30 | std::string payload = generateXPFPayload(dq.overTCP(), dq.ids.origRemote, dq.ids.origDest); |
53c57da7 RG |
31 | uint8_t root = '\0'; |
32 | dnsrecordheader drh; | |
33 | drh.d_type = htons(optionCode); | |
34 | drh.d_class = htons(QClass::IN); | |
35 | drh.d_ttl = 0; | |
36 | drh.d_clen = htons(payload.size()); | |
37 | size_t recordHeaderLen = sizeof(root) + sizeof(drh); | |
38 | ||
341d2553 | 39 | if (!dq.hasRoomFor(payload.size() + recordHeaderLen)) { |
53c57da7 RG |
40 | return false; |
41 | } | |
42 | ||
43 | size_t xpfSize = sizeof(root) + sizeof(drh) + payload.size(); | |
341d2553 RG |
44 | auto& data = dq.getMutableData(); |
45 | uint32_t realPacketLen = getDNSPacketLength(reinterpret_cast<const char*>(data.data()), data.size()); | |
46 | data.resize(realPacketLen + xpfSize); | |
53c57da7 RG |
47 | |
48 | size_t pos = realPacketLen; | |
341d2553 | 49 | memcpy(reinterpret_cast<char*>(&data.at(pos)), &root, sizeof(root)); |
53c57da7 | 50 | pos += sizeof(root); |
341d2553 | 51 | memcpy(reinterpret_cast<char*>(&data.at(pos)), &drh, sizeof(drh)); |
53c57da7 | 52 | pos += sizeof(drh); |
341d2553 | 53 | memcpy(reinterpret_cast<char*>(&data.at(pos)), payload.data(), payload.size()); |
53c57da7 | 54 | pos += payload.size(); |
90ee15b3 | 55 | (void) pos; |
53c57da7 | 56 | |
341d2553 | 57 | dq.getHeader()->arcount = htons(ntohs(dq.getHeader()->arcount) + 1); |
53c57da7 RG |
58 | |
59 | return true; | |
60 | } |