]> git.ipfire.org Git - thirdparty/pdns.git/blame - modules/geoipbackend/geoipbackend.hh
Standardize license text in all PDNS files
[thirdparty/pdns.git] / modules / geoipbackend / geoipbackend.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 */
680f25f8
RK
22#ifndef PDNS_GEOIPBACKEND_HH
23#define PDNS_GEOIPBACKEND_HH
24
709ca59f
AT
25#include "pdns/namespaces.hh"
26
27#include <vector>
28#include <map>
29#include <string>
30#include <fstream>
31#include <yaml-cpp/yaml.h>
32#include <pthread.h>
fa8fd4d2 33
709ca59f
AT
34#include <GeoIP.h>
35#include <GeoIPCity.h>
36#include <sys/types.h>
37#include <dirent.h>
38
39#include "pdns/dnspacket.hh"
40#include "pdns/dns.hh"
41#include "pdns/dnsbackend.hh"
42#include "pdns/lock.hh"
43
8434e5c2
AT
44struct geoip_deleter;
45
709ca59f
AT
46class GeoIPDomain;
47
48class GeoIPBackend: public DNSBackend {
49public:
8434e5c2 50 typedef pair<int,unique_ptr<GeoIP,geoip_deleter> > geoip_file_t;
709ca59f
AT
51 GeoIPBackend(const std::string& suffix="");
52 ~GeoIPBackend();
53
cac80fee
AT
54 virtual void lookup(const QType &qtype, const DNSName &qdomain, DNSPacket *pkt_p=0, int zoneId=-1);
55 virtual bool list(const DNSName &target, int domain_id, bool include_disabled=false) { return false; } // not supported
709ca59f
AT
56 virtual bool get(DNSResourceRecord &r);
57 virtual void reload();
58 virtual void rediscover(string *status = 0);
cac80fee 59 virtual bool getDomainInfo(const DNSName& domain, DomainInfo &di);
709ca59f
AT
60
61 // dnssec support
62 virtual bool doesDNSSEC() { return d_dnssec; };
cac80fee
AT
63 virtual bool getAllDomainMetadata(const DNSName& name, std::map<std::string, std::vector<std::string> >& meta);
64 virtual bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector<std::string>& meta);
65 virtual bool getDomainKeys(const DNSName& name, unsigned int kind, std::vector<DNSBackend::KeyData>& keys);
66 virtual bool removeDomainKey(const DNSName& name, unsigned int id);
67 virtual int addDomainKey(const DNSName& name, const KeyData& key);
68 virtual bool activateDomainKey(const DNSName& name, unsigned int id);
69 virtual bool deactivateDomainKey(const DNSName& name, unsigned int id);
709ca59f
AT
70
71 enum GeoIPQueryAttribute {
8434e5c2 72 ASn,
709ca59f
AT
73 City,
74 Continent,
75 Country,
76 Name,
77 Region
78 };
79
80private:
81 static pthread_rwlock_t s_state_lock;
82
83 void initialize();
84 void ip2geo(const GeoIPDomain& dom, const string& qname, const string& ip);
f2c595ad 85 string queryGeoIP(const string &ip, bool v6, GeoIPQueryAttribute attribute, GeoIPLookup* gl);
8434e5c2
AT
86 bool queryCountry(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
87 bool queryCountryV6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
88 bool queryContinent(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
89 bool queryContinentV6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
90 bool queryName(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
91 bool queryNameV6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
92 bool queryASnum(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
93 bool queryASnumV6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
94 bool queryRegion(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
95 bool queryRegionV6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
96 bool queryCity(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
97 bool queryCityV6(string &ret, GeoIPLookup* gl, const string &ip, const geoip_file_t& gi);
f2c595ad 98 string format2str(string format, const string& ip, bool v6, GeoIPLookup* gl);
709ca59f 99 bool d_dnssec;
cac80fee 100 bool hasDNSSECkey(const DNSName& name);
709ca59f
AT
101
102 vector<DNSResourceRecord> d_result;
103};
680f25f8
RK
104
105#endif /* PDNS_GEOIPBACKEND_HH */