This allows more control over which ENDS EDE entries will be kept (e.g.
clear on first one, to delete existing data and then add additional
codes on top of that).
Signed-off-by: Ensar Sarajčić <dev@ensarsarajcic.com>
{
public:
// this action does not stop the processing
- SetExtendedDNSErrorAction(uint16_t infoCode, const std::string& extraText, bool clearExistingEntries) :
- d_clearExistingEntries(clearExistingEntries)
+ SetExtendedDNSErrorAction(uint16_t infoCode, const std::string& extraText, bool clearExistingEntries)
{
d_ede.infoCode = infoCode;
d_ede.extraText = extraText;
+ d_ede.clearExisting = clearExistingEntries;
}
DNSAction::Action operator()(DNSQuestion* dnsQuestion, std::string* ruleresult) const override
{
(void)ruleresult;
- if (d_clearExistingEntries) {
+ if (d_ede.clearExisting) {
dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
}
else {
private:
EDNSExtendedError d_ede;
- bool d_clearExistingEntries;
};
class SetExtendedDNSErrorResponseAction : public DNSResponseAction
{
public:
// this action does not stop the processing
- SetExtendedDNSErrorResponseAction(uint16_t infoCode, const std::string& extraText, bool clearExistingEntries) :
- d_clearExistingEntries(clearExistingEntries)
+ SetExtendedDNSErrorResponseAction(uint16_t infoCode, const std::string& extraText, bool clearExistingEntries)
{
d_ede.infoCode = infoCode;
d_ede.extraText = extraText;
+ d_ede.clearExisting = clearExistingEntries;
}
DNSResponseAction::Action operator()(DNSResponse* dnsResponse, std::string* ruleresult) const override
{
(void)ruleresult;
- if (d_clearExistingEntries) {
+ if (d_ede.clearExisting) {
dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
}
else {
private:
EDNSExtendedError d_ede;
- bool d_clearExistingEntries;
};
class LimitTTLResponseAction : public DNSResponseAction, public boost::noncopyable
return {infoCode, std::move(extraText)};
}
-bool addExtendedDNSError(PacketBuffer& packet, size_t maximumPacketSize, uint16_t code, const std::string& extraStatus)
+bool addExtendedDNSError(PacketBuffer& packet, size_t maximumPacketSize, uint16_t code, const std::string& extraStatus, bool clearExisting)
{
uint16_t optStart = 0;
size_t optLen = 0;
PacketBuffer newContent;
bool ednsAdded = false;
bool edeAdded = false;
- if (!slowRewriteEDNSOptionInQueryWithRecords(packet, newContent, ednsAdded, EDNSOptionCode::EXTENDEDERROR, edeAdded, false, true, edeOption)) {
+ if (!slowRewriteEDNSOptionInQueryWithRecords(packet, newContent, ednsAdded, EDNSOptionCode::EXTENDEDERROR, edeAdded, clearExisting, !clearExisting, edeOption)) {
return false;
}
namespace dnsdist::edns
{
std::pair<std::optional<uint16_t>, std::optional<std::string>> getExtendedDNSError(const PacketBuffer& packet);
-bool addExtendedDNSError(PacketBuffer& packet, size_t maximumPacketSize, uint16_t code, const std::string& extraStatus);
+bool addExtendedDNSError(PacketBuffer& packet, size_t maximumPacketSize, uint16_t code, const std::string& extraStatus, bool clearExisting);
}
if (dnsResponse.ids.d_extendedErrors) {
for (auto ede : *dnsResponse.ids.d_extendedErrors) {
- dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText);
+ dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText, ede.clearExisting);
}
}
if (dnsResponse.ids.d_extendedErrors) {
for (auto ede : *dnsResponse.ids.d_extendedErrors) {
- dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText);
+ dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText, ede.clearExisting);
}
}
if (dnsResponse.ids.d_extendedErrors) {
for (auto ede : *dnsResponse.ids.d_extendedErrors) {
- dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText);
+ dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText, ede.clearExisting);
}
}
};
uint16_t infoCode;
std::string extraText;
+ bool clearExisting = true;
};
bool getEDNSExtendedErrorOptFromString(const char* option, unsigned int len, EDNSExtendedError& eee);