return *dq.qTag;
});
- luaCtx.registerFunction<void(DNSQuestion::*)(std::vector<std::pair<uint8_t, std::string>>)>("setProxyProtocolValues", [](DNSQuestion& dq, const std::vector<std::pair<uint8_t, std::string>>& values) {
+ luaCtx.registerFunction<void(DNSQuestion::*)(std::vector<std::pair<int, std::string>>)>("setProxyProtocolValues", [](DNSQuestion& dq, const std::vector<std::pair<int, std::string>>& values) {
if (!dq.proxyProtocolValues) {
dq.proxyProtocolValues = make_unique<std::vector<ProxyProtocolValue>>();
}
dq.proxyProtocolValues->clear();
dq.proxyProtocolValues->reserve(values.size());
for (const auto& value : values) {
- dq.proxyProtocolValues->push_back({value.second, value.first});
+ checkParameterBound("setProxyProtocolValues", value.first, std::numeric_limits<uint8_t>::max());
+ dq.proxyProtocolValues->push_back({value.second, static_cast<uint8_t>(value.first)});
}
});
- luaCtx.registerFunction<void(DNSQuestion::*)(uint8_t, std::string)>("addProxyProtocolValue", [](DNSQuestion& dq, uint8_t type, std::string value) {
+ luaCtx.registerFunction<void(DNSQuestion::*)(uint64_t, std::string)>("addProxyProtocolValue", [](DNSQuestion& dq, uint64_t type, std::string value) {
+ checkParameterBound("addProxyProtocolValue", type, std::numeric_limits<uint8_t>::max());
if (!dq.proxyProtocolValues) {
dq.proxyProtocolValues = make_unique<std::vector<ProxyProtocolValue>>();
}
- dq.proxyProtocolValues->push_back({value, type});
+ dq.proxyProtocolValues->push_back({value, static_cast<uint8_t>(type)});
});
- luaCtx.registerFunction<std::vector<std::pair<uint8_t, std::string>>(DNSQuestion::*)()>("getProxyProtocolValues", [](const DNSQuestion& dq) {
+ luaCtx.registerFunction<std::vector<std::pair<int, std::string>>(DNSQuestion::*)()>("getProxyProtocolValues", [](const DNSQuestion& dq) {
if (!dq.proxyProtocolValues) {
- return std::vector<std::pair<uint8_t, std::string>>();
+ return std::vector<std::pair<int, std::string>>();
}
- std::vector<std::pair<uint8_t, std::string>> result;
+ std::vector<std::pair<int, std::string>> result;
result.resize(dq.proxyProtocolValues->size());
for (const auto& value : *dq.proxyProtocolValues) {
result.push_back({ value.type, value.content });
return dq.du->getHTTPHeaders();
});
- luaCtx.registerFunction<void(DNSQuestion::*)(uint16_t statusCode, const std::string& body, const boost::optional<std::string> contentType)>("setHTTPResponse", [](DNSQuestion& dq, uint16_t statusCode, const std::string& body, const boost::optional<std::string> contentType) {
+ luaCtx.registerFunction<void(DNSQuestion::*)(uint64_t statusCode, const std::string& body, const boost::optional<std::string> contentType)>("setHTTPResponse", [](DNSQuestion& dq, uint64_t statusCode, const std::string& body, const boost::optional<std::string> contentType) {
if (dq.du == nullptr) {
return;
}
+ checkParameterBound("DNSQuestion::setHTTPResponse", statusCode, std::numeric_limits<uint16_t>::max());
PacketBuffer vect(body.begin(), body.end());
dq.du->setHTTPResponse(statusCode, std::move(vect), contentType ? *contentType : "");
});
#endif /* HAVE_DNS_OVER_HTTPS */
- luaCtx.registerFunction<bool(DNSQuestion::*)(bool nxd, const std::string& zone, uint32_t ttl, const std::string& mname, const std::string& rname, uint32_t serial, uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum)>("setNegativeAndAdditionalSOA", [](DNSQuestion& dq, bool nxd, const std::string& zone, uint32_t ttl, const std::string& mname, const std::string& rname, uint32_t serial, uint32_t refresh, uint32_t retry, uint32_t expire, uint32_t minimum) {
+ luaCtx.registerFunction<bool(DNSQuestion::*)(bool nxd, const std::string& zone, uint64_t ttl, const std::string& mname, const std::string& rname, uint64_t serial, uint64_t refresh, uint64_t retry, uint64_t expire, uint64_t minimum)>("setNegativeAndAdditionalSOA", [](DNSQuestion& dq, bool nxd, const std::string& zone, uint64_t ttl, const std::string& mname, const std::string& rname, uint64_t serial, uint64_t refresh, uint64_t retry, uint64_t expire, uint64_t minimum) {
+ checkParameterBound("setNegativeAndAdditionalSOA", ttl, std::numeric_limits<uint32_t>::max());
+ checkParameterBound("setNegativeAndAdditionalSOA", serial, std::numeric_limits<uint32_t>::max());
+ checkParameterBound("setNegativeAndAdditionalSOA", refresh, std::numeric_limits<uint32_t>::max());
+ checkParameterBound("setNegativeAndAdditionalSOA", retry, std::numeric_limits<uint32_t>::max());
+ checkParameterBound("setNegativeAndAdditionalSOA", expire, std::numeric_limits<uint32_t>::max());
+ checkParameterBound("setNegativeAndAdditionalSOA", minimum, std::numeric_limits<uint32_t>::max());
return setNegativeAndAdditionalSOA(dq, nxd, DNSName(zone), ttl, DNSName(mname), DNSName(rname), serial, refresh, retry, expire, minimum);
});
}
g_noLuaSideEffect = boost::logic::indeterminate;
}
-typedef std::unordered_map<std::string, boost::variant<bool, int, std::string, std::vector<std::pair<int, int>>, std::vector<std::pair<int, std::string>>, std::map<std::string, std::string>>> localbind_t;
+typedef std::unordered_map<std::string, boost::variant<bool, int, std::string, std::vector<std::pair<int, int>>, std::vector<std::pair<int, std::string>>, std::vector<std::pair<std::string, std::string>>>> localbind_t;
-static void parseLocalBindVars(boost::optional<localbind_t> vars, bool& reusePort, int& tcpFastOpenQueueSize, std::string& interface, std::set<int>& cpus, int& tcpListenQueueSize, size_t& maxInFlightQueriesPerConnection, size_t& tcpMaxConcurrentConnections)
+static void parseLocalBindVars(boost::optional<localbind_t> vars, bool& reusePort, int& tcpFastOpenQueueSize, std::string& interface, std::set<int>& cpus, int& tcpListenQueueSize, uint64_t& maxInFlightQueriesPerConnection, uint64_t& tcpMaxConcurrentConnections)
{
if (vars) {
if (vars->count("reusePort")) {
#endif // defined(HAVE_DNS_OVER_TLS) || defined(HAVE_DNS_OVER_HTTPS)
-static void checkParameterBound(const std::string& parameter, uint64_t value, size_t max = std::numeric_limits<uint16_t>::max())
+void checkParameterBound(const std::string& parameter, uint64_t value, size_t max)
{
if (value > max) {
throw std::runtime_error("The value (" + std::to_string(value) + ") passed to " + parameter + " is too large, the maximum is " + std::to_string(max));
return *poolServers;
});
- luaCtx.writeFunction("getServer", [client](boost::variant<unsigned int, std::string> i) {
+ luaCtx.writeFunction("getServer", [client](boost::variant<int, std::string> i) {
if (client) {
return std::make_shared<DownstreamState>(ComboAddress());
}
}
}
}
- else if (auto pos = boost::get<unsigned int>(&i)) {
+ else if (auto pos = boost::get<int>(&i)) {
return states.at(*pos);
}
});
#ifndef DISABLE_CARBON
- luaCtx.writeFunction("carbonServer", [](const std::string& address, boost::optional<string> ourName, boost::optional<unsigned int> interval, boost::optional<string> namespace_name, boost::optional<string> instance_name) {
+ luaCtx.writeFunction("carbonServer", [](const std::string& address, boost::optional<string> ourName, boost::optional<uint64_t> interval, boost::optional<string> namespace_name, boost::optional<string> instance_name) {
setLuaSideEffect();
auto ours = g_carbon.getCopy();
ours.push_back({ComboAddress(address, 2003),
(namespace_name && !namespace_name->empty()) ? *namespace_name : "dnsdist",
ourName ? *ourName : "",
(instance_name && !instance_name->empty()) ? *instance_name : "main",
- interval ? *interval : 30});
+ (interval && *interval < std::numeric_limits<unsigned int>::max()) ? static_cast<unsigned int>(*interval) : 30});
g_carbon.setState(ours);
});
#endif /* DISABLE_CARBON */
- luaCtx.writeFunction("webserver", [client, configCheck](const std::string& address, boost::optional<std::string> password, boost::optional<std::string> apiKey, const boost::optional<std::map<std::string, std::string>> customHeaders, const boost::optional<std::string> acl) {
+ luaCtx.writeFunction("webserver", [client, configCheck](const std::string& address, boost::optional<std::string> password, boost::optional<std::string> apiKey, const boost::optional<std::unordered_map<std::string, std::string>> customHeaders, const boost::optional<std::string> acl) {
setLuaSideEffect();
ComboAddress local;
try {
}
});
- typedef std::unordered_map<std::string, boost::variant<bool, std::string, std::map<std::string, std::string>>> webserveropts_t;
+ typedef std::unordered_map<std::string, boost::variant<bool, std::string, std::unordered_map<std::string, std::string>>> webserveropts_t;
luaCtx.writeFunction("setWebserverConfig", [](boost::optional<webserveropts_t> vars) {
setLuaSideEffect();
}
if (vars->count("customHeaders")) {
- const boost::optional<std::map<std::string, std::string>> headers = boost::get<std::map<std::string, std::string>>(vars->at("customHeaders"));
+ const auto headers = boost::get<std::unordered_map<std::string, std::string>>(vars->at("customHeaders"));
setWebserverCustomHeaders(headers);
}
}
});
- luaCtx.writeFunction("setConsoleMaximumConcurrentConnections", [](size_t max) {
+ luaCtx.writeFunction("setConsoleMaximumConcurrentConnections", [](uint64_t max) {
setLuaSideEffect();
setConsoleMaximumConcurrentConnections(max);
});
g_outputBuffer = (fmt % size).str();
});
- luaCtx.writeFunction("getQueryCounters", [](boost::optional<unsigned int> optMax) {
+ luaCtx.writeFunction("getQueryCounters", [](boost::optional<uint64_t> optMax) {
setLuaNoSideEffect();
auto records = g_qcount.records.read_lock();
g_outputBuffer = "query counting is currently: ";
g_outputBuffer += (boost::format(" (%d records in buffer)\n") % records->size()).str();
boost::format fmt("%-3d %s: %d request(s)\n");
- unsigned int max = optMax ? *optMax : 10;
- unsigned int index{1};
+ uint64_t max = optMax ? *optMax : 10U;
+ uint64_t index{1};
for (auto it = records->begin(); it != records->end() && index <= max; ++it, ++index) {
g_outputBuffer += (fmt % index % it->first % it->second).str();
}
}
});
- luaCtx.writeFunction("setMaxTCPQueriesPerConnection", [](size_t max) {
+ luaCtx.writeFunction("setMaxTCPQueriesPerConnection", [](uint64_t max) {
if (!g_configurationDone) {
g_maxTCPQueriesPerConn = max;
}
}
});
- luaCtx.writeFunction("setMaxTCPConnectionsPerClient", [](size_t max) {
+ luaCtx.writeFunction("setMaxTCPConnectionsPerClient", [](uint64_t max) {
if (!g_configurationDone) {
g_maxTCPConnectionsPerClient = max;
}
}
});
- luaCtx.writeFunction("setMaxTCPConnectionDuration", [](size_t max) {
+ luaCtx.writeFunction("setMaxTCPConnectionDuration", [](uint64_t max) {
if (!g_configurationDone) {
g_maxTCPConnectionDuration = max;
}
}
});
- luaCtx.writeFunction("setMaxCachedTCPConnectionsPerDownstream", [](size_t max) {
+ luaCtx.writeFunction("setMaxCachedTCPConnectionsPerDownstream", [](uint64_t max) {
DownstreamTCPConnectionsManager::setMaxIdleConnectionsPerDownstream(max);
});
- luaCtx.writeFunction("setMaxIdleDoHConnectionsPerDownstream", [](size_t max) {
+ luaCtx.writeFunction("setMaxIdleDoHConnectionsPerDownstream", [](uint64_t max) {
setDoHDownstreamMaxIdleConnectionsPerBackend(max);
});
g_cacheCleaningDelay = delay;
});
- luaCtx.writeFunction("setCacheCleaningPercentage", [](uint16_t percentage) { if (percentage < 100) g_cacheCleaningPercentage = percentage; else g_cacheCleaningPercentage = 100; });
+ luaCtx.writeFunction("setCacheCleaningPercentage", [](uint64_t percentage) { if (percentage < 100) g_cacheCleaningPercentage = percentage; else g_cacheCleaningPercentage = 100; });
- luaCtx.writeFunction("setECSSourcePrefixV4", [](uint16_t prefix) { g_ECSSourcePrefixV4 = prefix; });
+ luaCtx.writeFunction("setECSSourcePrefixV4", [](uint64_t prefix) {
+ checkParameterBound("setECSSourcePrefixV4", prefix, std::numeric_limits<uint16_t>::max());
+ g_ECSSourcePrefixV4 = prefix;
+ });
- luaCtx.writeFunction("setECSSourcePrefixV6", [](uint16_t prefix) { g_ECSSourcePrefixV6 = prefix; });
+ luaCtx.writeFunction("setECSSourcePrefixV6", [](uint64_t prefix) {
+ checkParameterBound("setECSSourcePrefixV6", prefix, std::numeric_limits<uint16_t>::max());
+ g_ECSSourcePrefixV6 = prefix;
+ });
luaCtx.writeFunction("setECSOverride", [](bool override) { g_ECSOverride = override; });
});
luaCtx.writeFunction("addDynBlockSMT",
- [](const vector<pair<unsigned int, string>>& names, const std::string& msg, boost::optional<int> seconds, boost::optional<DNSAction::Action> action) {
+ [](const vector<pair<int, string>>& names, const std::string& msg, boost::optional<int> seconds, boost::optional<DNSAction::Action> action) {
if (names.empty()) {
return;
}
}
});
- luaCtx.writeFunction("setDynBlocksPurgeInterval", [](unsigned int interval) {
+ luaCtx.writeFunction("setDynBlocksPurgeInterval", [](uint64_t interval) {
DynBlockMaintenance::s_expiredDynBlocksPurgeInterval = interval;
});
#endif
});
- luaCtx.writeFunction("getDNSCryptBind", [](size_t idx) {
+ luaCtx.writeFunction("getDNSCryptBind", [](uint64_t idx) {
setLuaNoSideEffect();
#ifdef HAVE_DNSCRYPT
std::shared_ptr<DNSCryptContext> ret = nullptr;
}
});
- luaCtx.writeFunction("getBind", [](size_t num) {
+ luaCtx.writeFunction("getBind", [](uint64_t num) {
setLuaNoSideEffect();
ClientState* ret = nullptr;
if (num < g_frontends.size()) {
}
});
- luaCtx.writeFunction("setRingBuffersSize", [client](size_t capacity, boost::optional<size_t> numberOfShards) {
+ luaCtx.writeFunction("setRingBuffersSize", [client](uint64_t capacity, boost::optional<uint64_t> numberOfShards) {
setLuaSideEffect();
if (g_configurationDone) {
errlog("setRingBuffersSize() cannot be used at runtime!");
}
});
- luaCtx.writeFunction("setRingBuffersLockRetries", [](size_t retries) {
+ luaCtx.writeFunction("setRingBuffersLockRetries", [](uint64_t retries) {
setLuaSideEffect();
g_rings.setNumberOfLockRetries(retries);
});
g_hashperturb = perturb;
});
- luaCtx.writeFunction("setTCPInternalPipeBufferSize", [](size_t size) { g_tcpInternalPipeBufferSize = size; });
+ luaCtx.writeFunction("setTCPInternalPipeBufferSize", [](uint64_t size) { g_tcpInternalPipeBufferSize = size; });
luaCtx.writeFunction("snmpAgent", [client, configCheck](bool enableTraps, boost::optional<std::string> daemonSocket) {
if (client || configCheck)
g_applyACLToProxiedClients = apply;
});
- luaCtx.writeFunction("setProxyProtocolMaximumPayloadSize", [](size_t size) {
+ luaCtx.writeFunction("setProxyProtocolMaximumPayloadSize", [](uint64_t size) {
if (g_configurationDone) {
errlog("setProxyProtocolMaximumPayloadSize() cannot be used at runtime!");
g_outputBuffer = "setProxyProtocolMaximumPayloadSize() cannot be used at runtime!\n";
g_proxyProtocolMaximumSize = std::max(static_cast<size_t>(16), size);
});
- luaCtx.writeFunction("setUDPMultipleMessagesVectorSize", [](size_t vSize) {
+ luaCtx.writeFunction("setUDPMultipleMessagesVectorSize", [](uint64_t vSize) {
if (g_configurationDone) {
errlog("setUDPMultipleMessagesVectorSize() cannot be used at runtime!");
g_outputBuffer = "setUDPMultipleMessagesVectorSize() cannot be used at runtime!\n";
g_addEDNSToSelfGeneratedResponses = add;
});
- luaCtx.writeFunction("setPayloadSizeOnSelfGeneratedAnswers", [](uint16_t payloadSize) {
+ luaCtx.writeFunction("setPayloadSizeOnSelfGeneratedAnswers", [](uint64_t payloadSize) {
if (payloadSize < 512) {
warnlog("setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead!");
g_outputBuffer = "setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead!";
}
if (vars->count("customResponseHeaders")) {
- for (auto const& headerMap : boost::get<std::map<std::string, std::string>>((*vars).at("customResponseHeaders"))) {
+ for (auto const& headerMap : boost::get<std::vector<std::pair<std::string, std::string>>>((*vars).at("customResponseHeaders"))) {
frontend->d_customResponseHeaders.emplace_back(boost::to_lower_copy(headerMap.first), headerMap.second);
}
}
#endif
});
- luaCtx.writeFunction("getDOHFrontend", [client](size_t index) {
+ luaCtx.writeFunction("getDOHFrontend", [client](uint64_t index) {
std::shared_ptr<DOHFrontend> result = nullptr;
if (client) {
return result;
}
});
- luaCtx.registerFunction<void (std::shared_ptr<DOHFrontend>::*)(const std::map<int, std::shared_ptr<DOHResponseMapEntry>>&)>("setResponsesMap", [](std::shared_ptr<DOHFrontend> frontend, const std::map<int, std::shared_ptr<DOHResponseMapEntry>>& map) {
+ luaCtx.registerFunction<void (std::shared_ptr<DOHFrontend>::*)(const std::vector<std::pair<int, std::shared_ptr<DOHResponseMapEntry>>>&)>("setResponsesMap", [](std::shared_ptr<DOHFrontend> frontend, const std::vector<std::pair<int, std::shared_ptr<DOHResponseMapEntry>>>& map) {
if (frontend != nullptr) {
auto newMap = std::make_shared<std::vector<std::shared_ptr<DOHResponseMapEntry>>>();
newMap->reserve(map.size());
#endif
});
- luaCtx.writeFunction("getTLSContext", [](size_t index) {
+ luaCtx.writeFunction("getTLSContext", [](uint64_t index) {
std::shared_ptr<TLSCtx> result = nullptr;
#ifdef HAVE_DNS_OVER_TLS
setLuaNoSideEffect();
return result;
});
- luaCtx.writeFunction("getTLSFrontend", [](size_t index) {
+ luaCtx.writeFunction("getTLSFrontend", [](uint64_t index) {
std::shared_ptr<TLSFrontend> result = nullptr;
#ifdef HAVE_DNS_OVER_TLS
setLuaNoSideEffect();
});
#endif /* HAVE_LIBSSL && HAVE_OCSP_BASIC_SIGN*/
- luaCtx.writeFunction("addCapabilitiesToRetain", [](boost::variant<std::string, std::map<int, std::string>> caps) {
+ luaCtx.writeFunction("addCapabilitiesToRetain", [](boost::variant<std::string, std::vector<std::pair<int, std::string>>> caps) {
setLuaSideEffect();
if (g_configurationDone) {
g_outputBuffer = "addCapabilitiesToRetain cannot be used at runtime!\n";
if (caps.type() == typeid(std::string)) {
g_capabilitiesToRetain.insert(boost::get<std::string>(caps));
}
- else if (caps.type() == typeid(std::map<int, std::string>)) {
- for (const auto& cap : boost::get<std::map<int, std::string>>(caps)) {
+ else if (caps.type() == typeid(std::vector<std::pair<int, std::string>>)) {
+ for (const auto& cap : boost::get<std::vector<std::pair<int, std::string>>>(caps)) {
g_capabilitiesToRetain.insert(cap.second);
}
}