auto maps = d_maps.lock();
- maps->d_v4 = BPFFilter::Map(configs["v4Params"], d_mapFormat);
- maps->d_v6 = BPFFilter::Map(configs["v6Params"], d_mapFormat);
- maps->d_qnames = BPFFilter::Map(configs["qnameParams"], d_mapFormat);
+ maps->d_v4 = BPFFilter::Map(configs["ipv4"], d_mapFormat);
+ maps->d_v6 = BPFFilter::Map(configs["ipv6"], d_mapFormat);
+ maps->d_qnames = BPFFilter::Map(configs["qnames"], d_mapFormat);
if (!external) {
BPFFilter::MapConfiguration filters;
filters.d_maxItems = 1;
/* BPF Filter */
#ifdef HAVE_EBPF
- using bpfFilterMapParams = boost::variant<uint32_t, LuaAssociativeTable<boost::variant<uint32_t, std::string>>>;
- using bpfopts_t = LuaAssociativeTable<boost::variant<bool, std::string, bpfFilterMapParams>>;
+ using bpfopts_t = LuaAssociativeTable<boost::variant<bool, uint32_t, std::string>>;
luaCtx.writeFunction("newBPFFilter", [client](bpfopts_t opts) {
if (client) {
return std::shared_ptr<BPFFilter>(nullptr);
std::unordered_map<std::string, BPFFilter::MapConfiguration> mapsConfig;
const auto convertParamsToConfig = [&](const std::string name, BPFFilter::MapType type) {
- if (!opts.count(name)) {
- return;
- }
- const auto& tmp = opts.at(name);
- if (tmp.type() != typeid(bpfFilterMapParams)) {
- throw std::runtime_error("params is invalid");
- }
- const auto& params = boost::get<bpfFilterMapParams>(tmp);
BPFFilter::MapConfiguration config;
- config.d_type = type;
- if (params.type() == typeid(uint32_t)) {
- config.d_maxItems = boost::get<uint32_t>(params);
- }
- else if (params.type() == typeid(LuaAssociativeTable<boost::variant<uint32_t, std::string>>)) {
- const auto& map = boost::get<LuaAssociativeTable<boost::variant<uint32_t, std::string>>>(params);
- if (map.count("maxItems")) {
- config.d_maxItems = boost::get<uint32_t>(map.at("maxItems"));
+ if (const string key = name + "MaxItems"; opts.count(key)) {
+ const auto& tmp = opts.at(name);
+ if (tmp.type() != typeid(uint32_t)) {
+ throw std::runtime_error("params is invalid");
}
- if (map.count("pinnedPath")) {
- config.d_pinnedPath = boost::get<std::string>(map.at("pinnedPath"));
+ const auto& params = boost::get<uint32_t>(tmp);
+ config.d_maxItems = params;
+ }
+
+ if (const string key = name + "PinnedPath"; opts.count(key)) {
+ auto& tmp = opts.at(name);
+ if (tmp.type() != typeid(string)) {
+ throw std::runtime_error("params is invalid");
}
+ auto& params = boost::get<string>(tmp);
+ config.d_pinnedPath = std::move(params);
}
mapsConfig[name] = config;
};
- convertParamsToConfig("v4Params", BPFFilter::MapType::IPv4);
- convertParamsToConfig("v6Params", BPFFilter::MapType::IPv6);
- convertParamsToConfig("qnameParams", BPFFilter::MapType::QNames);
+ convertParamsToConfig("ipv4", BPFFilter::MapType::IPv4);
+ convertParamsToConfig("ipv6", BPFFilter::MapType::IPv6);
+ convertParamsToConfig("qnames", BPFFilter::MapType::QNames);
BPFFilter::MapFormat format = BPFFilter::MapFormat::Legacy;
bool external = false;
}
return std::make_shared<BPFFilter>(mapsConfig, format, external);
- });
+ });
luaCtx.registerFunction<void(std::shared_ptr<BPFFilter>::*)(const ComboAddress& ca, boost::optional<uint32_t> action)>("block", [](std::shared_ptr<BPFFilter> bpf, const ComboAddress& ca, boost::optional<uint32_t> action) {
if (bpf) {
:param table options: A table with key: value pairs with options.
Options:
- * ``v4Params``: int or table - Maximum number of entries in this filter or a table with ``maxItems`` or ``pinnedPath`` .
- * ``v6Params``: int or table - Maximum number of entries in this filter or a table with ``maxItems`` or ``pinnedPath`` .
- * ``qnameParams``: int or table - Maximum number of entries in this filter or a table with ``maxItems`` or ``pinnedPath`` .
+ * ``ipv4MaxItems``: int - The maximum number of entries in a given map. Default is 0 which will not allow any entry at all.
+ * ``ipv4PinnedPath``: int - The filesystem path this map should be pinned to.
+ * ``ipv6MaxItems``: int - The maximum number of entries in a given map. Default is 0 which will not allow any entry at all.
+ * ``ipv6PinnedPath``: int - The filesystem path this map should be pinned to.
+ * ``qnamesMaxItems``: int - The maximum number of entries in a given map. Default is 0 which will not allow any entry at all.
+ * ``qnamesPinnedPath``: int - The filesystem path this map should be pinned to.
* ``external``: bool - If set to true, DNSDist can to load the internal eBPF program.
- Options for ``v4Params`` , ``v6Params`` and ``qnameParams``:
- * ``maxItems``: int - The maximum number of entries in a given map. Default is 0 which will not allow any entry at all.
- * ``pinnedPath``: str - The filesystem path this map should be pinned to.
-
.. function:: newDynBPFFilter(bpf) -> DynBPFFilter
Return a new dynamic eBPF filter associated to a given BPF Filter.