#include "rust/lib.rs.h"
#include "dnsdist-configuration-yaml-internal.hh"
-#include <boost/uuid/string_generator.hpp>
#include <variant>
+#include <boost/optional.hpp>
+#include <boost/uuid/string_generator.hpp>
+#include <boost/variant.hpp>
#endif /* HAVE_YAML_CONFIGURATION */
loadRulesConfiguration(globalConfig);
- s_registeredTypesMap.lock()->clear();
return true;
}
catch (const ::rust::Error& exp) {
catch (const std::exception& exp) {
errlog("Error while processing YAML configuration from file %s: %s", fileName, exp.what());
}
- s_registeredTypesMap.lock()->clear();
return false;
#else
(void)fileName;
throw std::runtime_error("Unsupported YAML configuration");
#endif /* HAVE_YAML_CONFIGURATION */
}
+
+void addLuaBindingsForYAMLObjects([[maybe_unused]] LuaContext& luaCtx)
+{
+#if defined(HAVE_YAML_CONFIGURATION)
+ using ReturnValue = boost::optional<boost::variant<std::shared_ptr<DNSDistPacketCache>, std::shared_ptr<DNSRule>, std::shared_ptr<DNSAction>, std::shared_ptr<DNSResponseAction>, std::shared_ptr<NetmaskGroup>, std::shared_ptr<KeyValueStore>, std::shared_ptr<KeyValueLookupKey>, std::shared_ptr<RemoteLoggerInterface>, std::shared_ptr<ServerPolicy>, std::shared_ptr<XSKMap>>>;
+
+ luaCtx.writeFunction("getObjectFromYAMLConfiguration", [](const std::string& name) {
+ ReturnValue object{boost::none};
+ auto map = s_registeredTypesMap.lock();
+ auto item = map->find(name);
+ if (item == map->end()) {
+ return object;
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<DNSDistPacketCache>>(&item->second)) {
+ return ReturnValue(*ptr);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<dnsdist::rust::settings::DNSSelector>>(&item->second)) {
+ return ReturnValue((*ptr)->d_rule);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<dnsdist::rust::settings::DNSActionWrapper>>(&item->second)) {
+ return ReturnValue((*ptr)->d_action);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<dnsdist::rust::settings::DNSResponseActionWrapper>>(&item->second)) {
+ return ReturnValue((*ptr)->d_action);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<NetmaskGroup>>(&item->second)) {
+ return ReturnValue(*ptr);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<KeyValueStore>>(&item->second)) {
+ return ReturnValue(*ptr);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<KeyValueLookupKey>>(&item->second)) {
+ return ReturnValue(*ptr);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<RemoteLoggerInterface>>(&item->second)) {
+ return ReturnValue(*ptr);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<ServerPolicy>>(&item->second)) {
+ return ReturnValue(*ptr);
+ }
+ if (auto* ptr = std::get_if<std::shared_ptr<XSKMap>>(&item->second)) {
+ return ReturnValue(*ptr);
+ }
+
+ return object;
+ });
+#endif /* HAVE_YAML_CONFIGURATION */
+}
}
#if defined(HAVE_YAML_CONFIGURATION)
#include "dnsdist-rust-bridge-actions-generated-body.hh"
#include "dnsdist-rust-bridge-selectors-generated-body.hh"
}
+
#endif /* defined(HAVE_YAML_CONFIGURATION) */
{"getListOfRangesOfNetworkInterface", true, "itf", "returns the list of network ranges configured on a given network interface, as strings"},
{"getMACAddress", true, "IP addr", "return the link-level address (MAC) corresponding to the supplied neighbour IP address, if known by the kernel"},
{"getMetric", true, "name", "Get the value of a custom metric"},
+ {"getObjectFromYAMLConfiguration", true, "name", "Get an object created in YAML configuration"},
{"getOutgoingTLSSessionCacheSize", true, "", "returns the number of TLS sessions (for outgoing connections) currently cached"},
{"getPool", true, "name", "return the pool named `name`, or \"\" for the default pool"},
{"getPoolServers", true, "pool", "return servers part of this pool"},