Skip to content

Commit

Permalink
dnsdist: Fix compilation when dynamic blocks are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Jul 5, 2024
1 parent d0e851b commit e4a1b37
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 186 deletions.
1 change: 1 addition & 0 deletions pdns/dnsdistdist/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ dnsdist_SOURCES = \
dns.cc dns.hh \
dns_random.hh \
dnscrypt.cc dnscrypt.hh \
dnsdist-actions.hh \
dnsdist-async.cc dnsdist-async.hh \
dnsdist-backend.cc dnsdist-backend.hh \
dnsdist-backoff.hh \
Expand Down
128 changes: 128 additions & 0 deletions pdns/dnsdistdist/dnsdist-actions.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* This file is part of PowerDNS or dnsdist.
* Copyright -- PowerDNS.COM B.V. and its contributors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* In addition, for the avoidance of any doubt, permission is granted to
* link this program with OpenSSL and to (re)distribute the binaries
* produced as the result of such linking.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once

/* so what could you do:
drop,
fake up nxdomain,
provide actual answer,
allow & and stop processing,
continue processing,
modify header: (servfail|refused|notimp), set TC=1,
send to pool */

struct DNSQuestion;
struct DNSResponse;

class DNSAction
{
public:
enum class Action : uint8_t
{
Drop,
Nxdomain,
Refused,
Spoof,
Allow,
HeaderModify,
Pool,
Delay,
Truncate,
ServFail,
None,
NoOp,
NoRecurse,
SpoofRaw,
SpoofPacket,
SetTag,
};
static std::string typeToString(const Action& action)
{
switch (action) {
case Action::Drop:
return "Drop";
case Action::Nxdomain:
return "Send NXDomain";
case Action::Refused:
return "Send Refused";
case Action::Spoof:
return "Spoof an answer";
case Action::SpoofPacket:
return "Spoof a raw answer from bytes";
case Action::SpoofRaw:
return "Spoof an answer from raw bytes";
case Action::Allow:
return "Allow";
case Action::HeaderModify:
return "Modify the header";
case Action::Pool:
return "Route to a pool";
case Action::Delay:
return "Delay";
case Action::Truncate:
return "Truncate over UDP";
case Action::ServFail:
return "Send ServFail";
case Action::SetTag:
return "Set Tag";
case Action::None:
case Action::NoOp:
return "Do nothing";
case Action::NoRecurse:
return "Set rd=0";
}

return "Unknown";
}

virtual Action operator()(DNSQuestion*, std::string* ruleresult) const = 0;
virtual ~DNSAction() = default;
virtual std::string toString() const = 0;
virtual std::map<std::string, double> getStats() const
{
return {{}};
}
virtual void reload()
{
}
};

class DNSResponseAction
{
public:
enum class Action : uint8_t
{
Allow,
Delay,
Drop,
HeaderModify,
ServFail,
Truncate,
None
};
virtual Action operator()(DNSResponse*, std::string* ruleresult) const = 0;
virtual ~DNSResponseAction() = default;
virtual std::string toString() const = 0;
virtual void reload()
{
}
};
1 change: 1 addition & 0 deletions pdns/dnsdistdist/dnsdist-async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "dnsdist-async.hh"
#include "dnsdist-internal-queries.hh"
#include "dolog.hh"
#include "mplexer.hh"
#include "threadname.hh"

namespace dnsdist
Expand Down
5 changes: 2 additions & 3 deletions pdns/dnsdistdist/dnsdist-async.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private:
uint16_t d_queryID;
};

typedef multi_index_container<
using content_t = multi_index_container<
Entry,
indexed_by<
ordered_unique<tag<IDTag>,
Expand All @@ -68,8 +68,7 @@ private:
member<Entry, uint16_t, &Entry::d_queryID>,
member<Entry, uint16_t, &Entry::d_asyncID>>>,
ordered_non_unique<tag<TTDTag>,
member<Entry, struct timeval, &Entry::d_ttd>>>>
content_t;
member<Entry, struct timeval, &Entry::d_ttd>>>>;

static void pickupExpired(content_t&, const struct timeval& now, std::list<std::pair<uint16_t, std::unique_ptr<CrossProtocolQuery>>>& expiredEvents);
static struct timeval getNextTTD(const content_t&);
Expand Down
1 change: 1 addition & 0 deletions pdns/dnsdistdist/dnsdist-carbon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#endif

#include "dnsdist-carbon.hh"
#include "dnsdist-cache.hh"
#include "dnsdist.hh"
#include "dnsdist-backoff.hh"
#include "dnsdist-configuration.hh"
Expand Down
107 changes: 1 addition & 106 deletions pdns/dnsdistdist/dnsdist-configuration.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,117 +29,12 @@

#include "config.h"
#include "credentials.hh"
#include "dnsdist-actions.hh"
#include "dnsdist-carbon.hh"
#include "dnsdist-query-count.hh"
#include "dnsdist-rule-chains.hh"
#include "iputils.hh"

/* so what could you do:
drop,
fake up nxdomain,
provide actual answer,
allow & and stop processing,
continue processing,
modify header: (servfail|refused|notimp), set TC=1,
send to pool */

struct DNSQuestion;
struct DNSResponse;

class DNSAction
{
public:
enum class Action : uint8_t
{
Drop,
Nxdomain,
Refused,
Spoof,
Allow,
HeaderModify,
Pool,
Delay,
Truncate,
ServFail,
None,
NoOp,
NoRecurse,
SpoofRaw,
SpoofPacket,
SetTag,
};
static std::string typeToString(const Action& action)
{
switch (action) {
case Action::Drop:
return "Drop";
case Action::Nxdomain:
return "Send NXDomain";
case Action::Refused:
return "Send Refused";
case Action::Spoof:
return "Spoof an answer";
case Action::SpoofPacket:
return "Spoof a raw answer from bytes";
case Action::SpoofRaw:
return "Spoof an answer from raw bytes";
case Action::Allow:
return "Allow";
case Action::HeaderModify:
return "Modify the header";
case Action::Pool:
return "Route to a pool";
case Action::Delay:
return "Delay";
case Action::Truncate:
return "Truncate over UDP";
case Action::ServFail:
return "Send ServFail";
case Action::SetTag:
return "Set Tag";
case Action::None:
case Action::NoOp:
return "Do nothing";
case Action::NoRecurse:
return "Set rd=0";
}

return "Unknown";
}

virtual Action operator()(DNSQuestion*, std::string* ruleresult) const = 0;
virtual ~DNSAction() = default;
virtual std::string toString() const = 0;
virtual std::map<std::string, double> getStats() const
{
return {{}};
}
virtual void reload()
{
}
};

class DNSResponseAction
{
public:
enum class Action : uint8_t
{
Allow,
Delay,
Drop,
HeaderModify,
ServFail,
Truncate,
None
};
virtual Action operator()(DNSResponse*, std::string* ruleresult) const = 0;
virtual ~DNSResponseAction() = default;
virtual std::string toString() const = 0;
virtual void reload()
{
}
};

class ServerPolicy;
struct ServerPool;
struct DownstreamState;
Expand Down
1 change: 1 addition & 0 deletions pdns/dnsdistdist/dnsdist-dnsquestion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "dnsdist.hh"
#include "dnsdist-configuration.hh"
#include "dnsdist-dnsparser.hh"

std::string DNSQuestion::getTrailingData() const
Expand Down
67 changes: 67 additions & 0 deletions pdns/dnsdistdist/dnsdist-dynblocks.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,73 @@ struct dnsdist_ffi_stat_node_t
SMTBlockParameters& d_blockParameters;
};

struct DynBlock
{
DynBlock()
{
until.tv_sec = 0;
until.tv_nsec = 0;
}

DynBlock(const std::string& reason_, const struct timespec& until_, const DNSName& domain_, DNSAction::Action action_) :
reason(reason_), domain(domain_), until(until_), action(action_)
{
}

DynBlock(const DynBlock& rhs) :
reason(rhs.reason), domain(rhs.domain), until(rhs.until), tagSettings(rhs.tagSettings), action(rhs.action), warning(rhs.warning), bpf(rhs.bpf)
{
blocks.store(rhs.blocks);
}

DynBlock(DynBlock&& rhs) :
reason(std::move(rhs.reason)), domain(std::move(rhs.domain)), until(rhs.until), tagSettings(std::move(rhs.tagSettings)), action(rhs.action), warning(rhs.warning), bpf(rhs.bpf)
{
blocks.store(rhs.blocks);
}

DynBlock& operator=(const DynBlock& rhs)
{
reason = rhs.reason;
until = rhs.until;
domain = rhs.domain;
action = rhs.action;
blocks.store(rhs.blocks);
warning = rhs.warning;
bpf = rhs.bpf;
tagSettings = rhs.tagSettings;
return *this;
}

DynBlock& operator=(DynBlock&& rhs)
{
reason = std::move(rhs.reason);
until = rhs.until;
domain = std::move(rhs.domain);
action = rhs.action;
blocks.store(rhs.blocks);
warning = rhs.warning;
bpf = rhs.bpf;
tagSettings = std::move(rhs.tagSettings);
return *this;
}

struct TagSettings
{
std::string d_name;
std::string d_value;
};

string reason;
DNSName domain;
timespec until{};
std::shared_ptr<TagSettings> tagSettings{nullptr};
mutable std::atomic<uint32_t> blocks{0};
DNSAction::Action action{DNSAction::Action::None};
bool warning{false};
bool bpf{false};
};

using dnsdist_ffi_dynamic_block_inserted_hook = std::function<void(uint8_t type, const char* key, const char* reason, uint8_t action, uint64_t duration, bool warning)>;
using ClientAddressDynamicRules = NetmaskTree<DynBlock, AddressAndPortRange>;
using SuffixDynamicRules = SuffixMatchTree<DynBlock>;
Expand Down
2 changes: 2 additions & 0 deletions pdns/dnsdistdist/dnsdist-dynbpf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
#include "dnsdist-dynbpf.hh"

std::vector<std::shared_ptr<DynBPFFilter>> g_dynBPFFilters;

bool DynBPFFilter::block(const ComboAddress& addr, const struct timespec& until)
{
bool inserted = false;
Expand Down
2 changes: 2 additions & 0 deletions pdns/dnsdistdist/dnsdist-dynbpf.hh
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ private:
};
LockGuarded<Data> d_data;
};

extern std::vector<std::shared_ptr<DynBPFFilter>> g_dynBPFFilters;
1 change: 1 addition & 0 deletions pdns/dnsdistdist/dnsdist-frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "dnsdist-frontend.hh"
#include "dnsdist.hh"
#include "dnsdist-configuration.hh"

namespace dnsdist
{
Expand Down
Loading

0 comments on commit e4a1b37

Please sign in to comment.