]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/geoipbackend/geoipbackend.hh
Merge pull request #9070 from rgacogne/boost-173
[thirdparty/pdns.git] / modules / geoipbackend / geoipbackend.hh
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 #pragma once
23 #include "pdns/namespaces.hh"
24
25 #include <vector>
26 #include <map>
27 #include <string>
28 #include <pthread.h>
29 #include <sys/types.h>
30 #include <dirent.h>
31
32 #include "pdns/dnspacket.hh"
33 #include "pdns/dns.hh"
34 #include "pdns/dnsbackend.hh"
35 #include "pdns/lock.hh"
36
37 class GeoIPInterface;
38
39 struct GeoIPDomain;
40
41 struct GeoIPNetmask {
42 int netmask;
43 };
44
45 class GeoIPBackend: public DNSBackend {
46 public:
47 GeoIPBackend(const std::string& suffix="");
48 ~GeoIPBackend();
49
50 void lookup(const QType &qtype, const DNSName &qdomain, int zoneId, DNSPacket *pkt_p=nullptr) override;
51 bool list(const DNSName &target, int domain_id, bool include_disabled=false) override { return false; } // not supported
52 bool get(DNSResourceRecord &r) override;
53 void reload() override;
54 void rediscover(string *status = 0) override;
55 bool getDomainInfo(const DNSName& domain, DomainInfo &di, bool getSerial=true) override;
56
57 // dnssec support
58 bool doesDNSSEC() override { return d_dnssec; };
59 bool getAllDomainMetadata(const DNSName& name, std::map<std::string, std::vector<std::string> >& meta) override;
60 bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta) override;
61 bool getDomainKeys(const DNSName& name, std::vector<DNSBackend::KeyData>& keys) override;
62 bool removeDomainKey(const DNSName& name, unsigned int id) override;
63 bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id) override;
64 bool activateDomainKey(const DNSName& name, unsigned int id) override;
65 bool deactivateDomainKey(const DNSName& name, unsigned int id) override;
66 bool publishDomainKey(const DNSName& name, unsigned int id) override;
67 bool unpublishDomainKey(const DNSName& name, unsigned int id) override;
68
69 private:
70 static ReadWriteLock s_state_lock;
71
72 void initialize();
73 string format2str(string format, const Netmask &addr, GeoIPNetmask& gl);
74 bool d_dnssec;
75 bool hasDNSSECkey(const DNSName& name);
76 bool lookup_static(const GeoIPDomain &dom, const DNSName &search, const QType &qtype, const DNSName& qdomain, const Netmask &addr, GeoIPNetmask& gl);
77 vector<DNSResourceRecord> d_result;
78 vector<GeoIPInterface> d_files;
79 };