]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/anadns.hh
Merge pull request #14195 from rgacogne/ddist-no-assertions
[thirdparty/pdns.git] / pdns / anadns.hh
CommitLineData
12471842
PL
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 */
e8c59f2d 22#pragma once
9a450843
BH
23#include <string>
24#include <netinet/ip.h>
25#include <netinet/udp.h>
26#include "dnsparser.hh"
8b422c02 27#include "iputils.hh"
61b26744 28#include "namespaces.hh"
9a450843
BH
29
30struct QuestionIdentifier
31{
abb11ca4 32 QuestionIdentifier() = default;
9a450843
BH
33
34 bool operator<(const QuestionIdentifier& rhs) const
35 {
36 return
905dae56
RG
37 std::tie(d_id, d_qtype, d_source, d_dest, d_qname) <
38 std::tie(rhs.d_id, rhs.d_qtype, rhs.d_source, rhs.d_dest, rhs.d_qname);
9a450843
BH
39 }
40
ef890b79 41
9a450843 42 // the canonical direction is that of the question
ef890b79 43 static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const struct dnsheader& header, const DNSName& qname, uint16_t qtype)
9a450843
BH
44 {
45 QuestionIdentifier ret;
a5d9353e 46
ef890b79 47 if(header.qr) {
a5d9353e 48 ret.d_source = dst;
49 ret.d_dest = src;
9a450843
BH
50 }
51 else {
a5d9353e 52 ret.d_source = src;
53 ret.d_dest = dst;
9a450843 54 }
ef890b79 55 ret.d_qname=qname;
56 ret.d_qtype=qtype;
57 ret.d_id=ntohs(header.id);
9a450843
BH
58 return ret;
59 }
60
ef890b79 61 // the canonical direction is that of the question
62 static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const MOADNSParser& mdp)
63 {
64 return create(src, dst, mdp.d_header, mdp.d_qname, mdp.d_qtype);
65 }
66
67
8b422c02 68 ComboAddress d_source, d_dest;
9a450843 69
af6406f5 70 DNSName d_qname;
1902ab7d
OM
71 uint16_t d_qtype{0};
72 uint16_t d_id{0};
9a450843
BH
73};
74
75inline ostream& operator<<(ostream &s, const QuestionIdentifier& qi)
76{
81aa6d25 77 s<< "'"<<qi.d_qname<<"|"<<DNSRecordContent::NumberToType(qi.d_qtype)<<"', with id " << qi.d_id <<" from "<<qi.d_source.toStringWithPort();
9a450843 78
8b422c02 79 s<<" to " << qi.d_dest.toStringWithPort();
80 return s;
9a450843 81}