From 3efdc9d2ac70580e827131ae89eb535d36306dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Ondr=C3=A1=C4=8Dek?= Date: Wed, 15 Jan 2025 16:20:17 +0100 Subject: [PATCH] daemon/defer: fix setting price-factor from views --- modules/policy/policy.lua | 7 +++++++ .../datamodel/templates/macros/policy_macros.lua.j2 | 9 ++++++++- python/knot_resolver/datamodel/templates/views.lua.j2 | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/policy/policy.lua b/modules/policy/policy.lua index 036e8cf69..41eff2daa 100644 --- a/modules/policy/policy.lua +++ b/modules/policy/policy.lua @@ -218,6 +218,13 @@ function policy.FLAGS(opts_set, opts_clear) end end +-- Set price-factor +function policy.PRICE_FACTOR16(factor) + return function(_, req) + ffi.C.defer_set_price_factor16(req, factor) + end +end + local function mkauth_soa(answer, dname, mname, ttl) if mname == nil then mname = dname diff --git a/python/knot_resolver/datamodel/templates/macros/policy_macros.lua.j2 b/python/knot_resolver/datamodel/templates/macros/policy_macros.lua.j2 index 347532e6b..946833567 100644 --- a/python/knot_resolver/datamodel/templates/macros/policy_macros.lua.j2 +++ b/python/knot_resolver/datamodel/templates/macros/policy_macros.lua.j2 @@ -42,6 +42,13 @@ policy.FLAGS({ {%- endmacro %} +{# Price factor #} + +{% macro policy_price_factor(factor) -%} +policy.PRICE_FACTOR16({{ (factor|float * 2**16)|round|int }}) +{%- endmacro %} + + {# Tags assign #} {% macro policy_tags_assign(tags) -%} @@ -276,4 +283,4 @@ policy.todnames({ {%- endfor -%} {%- endif -%} }) -{%- endmacro %} \ No newline at end of file +{%- endmacro %} diff --git a/python/knot_resolver/datamodel/templates/views.lua.j2 b/python/knot_resolver/datamodel/templates/views.lua.j2 index 0b6022391..1f27830b3 100644 --- a/python/knot_resolver/datamodel/templates/views.lua.j2 +++ b/python/knot_resolver/datamodel/templates/views.lua.j2 @@ -1,6 +1,6 @@ {% from 'macros/common_macros.lua.j2' import quotes %} {% from 'macros/view_macros.lua.j2' import get_proto_set, view_flags, view_answer %} -{% from 'macros/policy_macros.lua.j2' import policy_flags, policy_tags_assign %} +{% from 'macros/policy_macros.lua.j2' import policy_flags, policy_tags_assign, policy_price_factor %} {% if cfg.views %} {% for view in cfg.views %} @@ -13,7 +13,7 @@ assert(C.kr_view_insert_action('{{ subnet }}', '{{ view.dst_subnet or '' }}', {{ quotes(policy_flags(flags)) }}, {%- endif %} {% if view.options.price_factor|float != 1.0 %} - 'C.defer_set_price_factor16(req, {{ (view.options.price_factor|float * 2**16)|round|int }})', + {{ quotes(policy_price_factor(view.options.price_factor)) }}, {%- endif %} {% if view.tags %} {{ policy_tags_assign(view.tags) }},