// this action does not stop the processing
SetExtendedDNSErrorAction(uint16_t infoCode, const std::string& extraText, bool clearExistingEntries)
{
- d_ede.infoCode = infoCode;
- d_ede.extraText = extraText;
+ d_ede.error.infoCode = infoCode;
+ d_ede.error.extraText = extraText;
d_ede.clearExisting = clearExistingEntries;
}
{
(void)ruleresult;
if (d_ede.clearExisting) {
- dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
+ dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<edns::SetExtendedDNSErrorOperation>>(std::initializer_list<edns::SetExtendedDNSErrorOperation>({d_ede}));
}
else {
if (!dnsQuestion->ids.d_extendedErrors) {
- dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
+ dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<edns::SetExtendedDNSErrorOperation>>(std::initializer_list<edns::SetExtendedDNSErrorOperation>({d_ede}));
}
else {
dnsQuestion->ids.d_extendedErrors->emplace_back(d_ede);
[[nodiscard]] std::string toString() const override
{
- return "set EDNS Extended DNS Error to " + std::to_string(d_ede.infoCode) + (d_ede.extraText.empty() ? std::string() : std::string(": \"") + d_ede.extraText + std::string("\""));
+ return "set EDNS Extended DNS Error to " + std::to_string(d_ede.error.infoCode) + (d_ede.error.extraText.empty() ? std::string() : std::string(": \"") + d_ede.error.extraText + std::string("\""));
}
private:
- EDNSExtendedError d_ede;
+ edns::SetExtendedDNSErrorOperation d_ede;
};
class SetExtendedDNSErrorResponseAction : public DNSResponseAction
// this action does not stop the processing
SetExtendedDNSErrorResponseAction(uint16_t infoCode, const std::string& extraText, bool clearExistingEntries)
{
- d_ede.infoCode = infoCode;
- d_ede.extraText = extraText;
+ d_ede.error.infoCode = infoCode;
+ d_ede.error.extraText = extraText;
d_ede.clearExisting = clearExistingEntries;
}
{
(void)ruleresult;
if (d_ede.clearExisting) {
- dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
+ dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<edns::SetExtendedDNSErrorOperation>>(std::initializer_list<edns::SetExtendedDNSErrorOperation>({d_ede}));
}
else {
if (!dnsResponse->ids.d_extendedErrors) {
- dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
+ dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<edns::SetExtendedDNSErrorOperation>>(std::initializer_list<edns::SetExtendedDNSErrorOperation>({d_ede}));
}
else {
dnsResponse->ids.d_extendedErrors->emplace_back(d_ede);
[[nodiscard]] std::string toString() const override
{
- return "set EDNS Extended DNS Error to " + std::to_string(d_ede.infoCode) + (d_ede.extraText.empty() ? std::string() : std::string(": \"") + d_ede.extraText + std::string("\""));
+ return "set EDNS Extended DNS Error to " + std::to_string(d_ede.error.infoCode) + (d_ede.error.extraText.empty() ? std::string() : std::string(": \"") + d_ede.error.extraText + std::string("\""));
}
private:
- EDNSExtendedError d_ede;
+ edns::SetExtendedDNSErrorOperation d_ede;
};
class LimitTTLResponseAction : public DNSResponseAction, public boost::noncopyable
#include <string>
#include <utility>
+#include "ednsextendederror.hh"
#include "noinitvector.hh"
namespace dnsdist::edns
{
+struct SetExtendedDNSErrorOperation
+{
+ EDNSExtendedError error;
+ bool clearExisting = true;
+};
+
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 clearExisting);
}
#include "config.h"
#include "dnscrypt.hh"
#include "dnsdist-configuration.hh"
+#include "dnsdist-edns.hh"
#include "dnsname.hh"
#include "dnsdist-protocols.hh"
#include "ednsextendederror.hh"
#ifndef DISABLE_PROTOBUF
std::vector<std::pair<std::string, std::shared_ptr<RemoteLoggerInterface>>> delayedResponseMsgs;
#endif
- std::unique_ptr<std::vector<EDNSExtendedError>> d_extendedErrors{nullptr};
+ std::unique_ptr<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>> d_extendedErrors{nullptr};
std::optional<uint32_t> tempFailureTTL{std::nullopt}; // 8
ClientState* cs{nullptr}; // 8
std::unique_ptr<DOHUnitInterface> du; // 8
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "dnsdist-edns.hh"
#include "dnsdist.hh"
#include "dnsdist-async.hh"
#include "dnsdist-dnsparser.hh"
});
luaCtx.registerFunction<void (DNSQuestion::*)(uint16_t infoCode, const std::optional<std::string>& extraText, const std::optional<bool> clearExistingEntries)>("setExtendedDNSError", [](DNSQuestion& dnsQuestion, uint16_t infoCode, const std::optional<std::string>& extraText, const std::optional<bool> clearExistingEntries) {
- EDNSExtendedError ede;
- ede.infoCode = infoCode;
+ dnsdist::edns::SetExtendedDNSErrorOperation ede;
+ ede.error.infoCode = infoCode;
if (extraText) {
- ede.extraText = *extraText;
+ ede.error.extraText = *extraText;
}
- if (clearExistingEntries.value_or(true)) {
- dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+ ede.clearExisting = clearExistingEntries.value_or(true);
+ if (ede.clearExisting) {
+ dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
}
else {
if (!dnsQuestion.ids.d_extendedErrors) {
- dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+ dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
}
else {
dnsQuestion.ids.d_extendedErrors->emplace_back(ede);
}
}
- dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
});
luaCtx.registerFunction<bool (DNSQuestion::*)(uint16_t asyncID, uint16_t queryID, uint32_t timeoutMs)>("suspend", [](DNSQuestion& dnsQuestion, uint16_t asyncID, uint16_t queryID, uint32_t timeoutMs) {
});
luaCtx.registerFunction<void (DNSResponse::*)(uint16_t infoCode, const std::optional<std::string>& extraText, const std::optional<bool> clearExistingEntries)>("setExtendedDNSError", [](DNSResponse& dnsResponse, uint16_t infoCode, const std::optional<std::string>& extraText, const std::optional<bool> clearExistingEntries) {
- EDNSExtendedError ede;
- ede.infoCode = infoCode;
+ dnsdist::edns::SetExtendedDNSErrorOperation ede;
+ ede.error.infoCode = infoCode;
if (extraText) {
- ede.extraText = *extraText;
+ ede.error.extraText = *extraText;
}
- if (clearExistingEntries.value_or(true)) {
- dnsResponse.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+ ede.clearExisting = clearExistingEntries.value_or(true);
+ if (ede.clearExisting) {
+ dnsResponse.ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
}
else {
if (!dnsResponse.ids.d_extendedErrors) {
- dnsResponse.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+ dnsResponse.ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
}
else {
dnsResponse.ids.d_extendedErrors->emplace_back(ede);
#include "dnsdist-dynblocks.hh"
#include "dnsdist-ecs.hh"
#include "dnsdist-lua-ffi.hh"
+#include "dnsdist-edns.hh"
#include "dnsdist-mac-address.hh"
#include "dnsdist-metrics.hh"
#include "dnsdist-lua-network.hh"
void dnsdist_ffi_dnsquestion_set_extended_dns_error(dnsdist_ffi_dnsquestion_t* dnsQuestion, uint16_t infoCode, const char* extraText, size_t extraTextSize)
{
- EDNSExtendedError ede;
- ede.infoCode = infoCode;
+ dnsdist::edns::SetExtendedDNSErrorOperation ede;
+ ede.error.infoCode = infoCode;
if (extraText != nullptr && extraTextSize > 0) {
- ede.extraText = std::string(extraText, extraTextSize);
+ ede.error.extraText = std::string(extraText, extraTextSize);
}
- dnsQuestion->dq->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+ ede.clearExisting = true;
+ dnsQuestion->dq->ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
}
void dnsdist_ffi_dnsquestion_add_extended_dns_error(dnsdist_ffi_dnsquestion_t* dnsQuestion, uint16_t infoCode, const char* extraText, size_t extraTextSize)
{
- EDNSExtendedError ede;
- ede.infoCode = infoCode;
+ dnsdist::edns::SetExtendedDNSErrorOperation ede;
+ ede.error.infoCode = infoCode;
if (extraText != nullptr && extraTextSize > 0) {
- ede.extraText = std::string(extraText, extraTextSize);
+ ede.error.extraText = std::string(extraText, extraTextSize);
}
ede.clearExisting = false;
if (!dnsQuestion->dq->ids.d_extendedErrors) {
- dnsQuestion->dq->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+ dnsQuestion->dq->ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
}
else {
dnsQuestion->dq->ids.d_extendedErrors->emplace_back(ede);
if (dnsResponse.ids.d_extendedErrors) {
for (auto ede : *dnsResponse.ids.d_extendedErrors) {
- dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText, ede.clearExisting);
+ dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.error.infoCode, ede.error.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, ede.clearExisting);
+ dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.error.infoCode, ede.error.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, ede.clearExisting);
+ dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.error.infoCode, ede.error.extraText, ede.clearExisting);
}
}
};
uint16_t infoCode;
std::string extraText;
- bool clearExisting = true;
};
bool getEDNSExtendedErrorOptFromString(const char* option, unsigned int len, EDNSExtendedError& eee);