Skip to content

Commit

Permalink
daemon/defer: fix setting price-factor from views
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukáš Ondráček committed Jan 15, 2025
1 parent 947f627 commit 3efdc9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions modules/policy/policy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) -%}
Expand Down Expand Up @@ -276,4 +283,4 @@ policy.todnames({
{%- endfor -%}
{%- endif -%}
})
{%- endmacro %}
{%- endmacro %}
4 changes: 2 additions & 2 deletions python/knot_resolver/datamodel/templates/views.lua.j2
Original file line number Diff line number Diff line change
@@ -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 %}
Expand All @@ -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) }},
Expand Down

0 comments on commit 3efdc9d

Please sign in to comment.