zapret-auto: per_instance_condition feed target desync to cond function, code=>cond_code

This commit is contained in:
bol-van committed 2026-02-20 07:18:31 +03:00
1 parent 6e85c9650d
commit c13284b776
5 files changed
+26 -10

No files matched your search

+1
View File
@@ -252,3 +252,4 @@ v0.9.4
v0.9.5 v0.9.5
* builder_linux: simple scripts to build static linux bins for any supported architecture * builder_linux: simple scripts to build static linux bins for any supported architecture
* zapret-auto: incompatible change. cond_code "code" parameter => "cond_code". to avoid collision with luaexec
+6 -1
View File
@@ -3554,11 +3554,16 @@ Aggregates verdicts v1 and v2. VERDICT_MODIFY overrides VERDICT_PASS, while VERD
``` ```
function plan_instance_execute(desync, verdict, instance) function plan_instance_execute(desync, verdict, instance)
function plan_instance_execute_preapplied(desync, verdict, instance)
``` ```
Executes an [execution plan](#execution_plan) `instance`, taking into account the [instance cutoff](#instance_cutoff) and standard [payload](#in-profile-filters) and [range](#in-profile-filters) filters. Executes an [execution plan](#execution_plan) `instance`, taking into account the [instance cutoff](#instance_cutoff) and standard [payload](#in-profile-filters) and [range](#in-profile-filters) filters.
Returns the aggregation of the current verdict and the `instance` verdict. Returns the aggregation of the current verdict and the `instance` verdict.
The "preapplied" version does not apply execution plan, allowing the calling code to do so.
Sometimes, to decide whether to call an instance, you need a desync table configured for the called instance.
"preapplied" version allows to avoid double copying.
### plan_instance_pop ### plan_instance_pop
``` ```
@@ -4473,7 +4478,7 @@ Returns `true` if the dissect is tcp and has tcp timestamp option.
function cond_lua(desync) function cond_lua(desync)
``` ```
Executes a Lua code from the "code" argument. The code returns condition value. Direct addressing of the desync table is possible within the code. Executes a Lua code from the "cond_code" argument. The code returns condition value. Direct addressing of the desync table is possible within the code.
# Auxiliary programs # Auxiliary programs
+6 -1
View File
@@ -3733,11 +3733,16 @@ function verdict_aggregate(v1, v2)
``` ```
function plan_instance_execute(desync, verdict, instance) function plan_instance_execute(desync, verdict, instance)
function plan_instance_execute_preapplied(desync, verdict, instance)
``` ```
Выполняет элемент [execution plan](#execution_plan) `instance` с учетом [instance cutoff](#instance_cutoff) и стандартных фильтров [payload](#внутрипрофильные-фильтры) и [range](#внутрипрофильные-фильтры). Выполняет элемент [execution plan](#execution_plan) `instance` с учетом [instance cutoff](#instance_cutoff) и стандартных фильтров [payload](#внутрипрофильные-фильтры) и [range](#внутрипрофильные-фильтры).
Возвращает агрегацию verdict и вердикта `instance`. Возвращает агрегацию verdict и вердикта `instance`.
Вариант "preapplied" не выполняет apply_execution_plan, позволяя это сделат вызывающему коду.
Иногда для принятия решения вызывать ли instance требуется таблица desync, настроенная на вызываемый инстанс.
Чтобы не делать apply дважды (там копирование desync.arg) и существует этот вариант.
### plan_instance_pop ### plan_instance_pop
``` ```
@@ -4652,7 +4657,7 @@ function cond_tcp_ts(desync)
function cond_lua(desync) function cond_lua(desync)
``` ```
Выполняет Lua код из аргумента "code". Код возвращает значение условия через return. Возможна прямая адресация таблицы desync. Выполняет Lua код из аргумента "cond_code". Код возвращает значение условия через return. Возможна прямая адресация таблицы desync.
# Вспомогательные программы # Вспомогательные программы
+8 -6
View File
@@ -411,19 +411,19 @@ function cond_tcp_has_ts(desync)
end end
-- exec lua code in "code" arg and return it's result -- exec lua code in "code" arg and return it's result
function cond_lua(desync) function cond_lua(desync)
if not desync.arg.code then if not desync.arg.cond_code then
error("cond_lua: no 'code' parameter") error("cond_lua: no 'cond_code' parameter")
end end
local fname = desync.func_instance.."_cond_code" local fname = desync.func_instance.."_cond_cond_code"
if not _G[fname] then if not _G[fname] then
local err local err
_G[fname], err = load(desync.arg.code, fname) _G[fname], err = load(desync.arg.cond_code, fname)
if not _G[fname] then if not _G[fname] then
error(err) error(err)
return return
end end
end end
-- allow dynamic code to access desync -- allow dynamic cond_code to access desync
_G.desync = desync _G.desync = desync
local res, v = pcall(_G[fname]) local res, v = pcall(_G[fname])
_G.desync = nil _G.desync = nil
@@ -479,8 +479,10 @@ function per_instance_condition(ctx, desync)
if type(_G[instance.arg.cond])~="function" then if type(_G[instance.arg.cond])~="function" then
error("per_instance_condition: invalid 'iff' function '"..instance.arg.cond.."'") error("per_instance_condition: invalid 'iff' function '"..instance.arg.cond.."'")
end end
-- preapply exec plan to feed cond function correct args
apply_execution_plan(desync, instance)
if logical_xor(_G[instance.arg.cond](desync), instance.arg.cond_neg) then if logical_xor(_G[instance.arg.cond](desync), instance.arg.cond_neg) then
verdict = plan_instance_execute(desync, verdict, instance) verdict = plan_instance_execute_preapplied(desync, verdict, instance)
else else
DLOG("per_instance_condition: condition not satisfied. skipping '"..instance.func_instance.."'") DLOG("per_instance_condition: condition not satisfied. skipping '"..instance.func_instance.."'")
end end
+5 -2
View File
@@ -192,8 +192,7 @@ function verdict_aggregate(v1, v2)
end end
return bitor(v,vn) return bitor(v,vn)
end end
function plan_instance_execute(desync, verdict, instance) function plan_instance_execute_preapplied(desync, verdict, instance)
apply_execution_plan(desync, instance)
if cutoff_shim_check(desync) then if cutoff_shim_check(desync) then
DLOG("plan_instance_execute: not calling '"..desync.func_instance.."' because of voluntary cutoff") DLOG("plan_instance_execute: not calling '"..desync.func_instance.."' because of voluntary cutoff")
elseif not payload_match_filter(desync.l7payload, instance.payload_filter) then elseif not payload_match_filter(desync.l7payload, instance.payload_filter) then
@@ -206,6 +205,10 @@ function plan_instance_execute(desync, verdict, instance)
end end
return verdict return verdict
end end
function plan_instance_execute(desync, verdict, instance)
apply_execution_plan(desync, instance)
return plan_instance_execute_preapplied(desync,verdict,instance)
end
function plan_instance_pop(desync) function plan_instance_pop(desync)
return (desync.plan and #desync.plan>0) and table.remove(desync.plan, 1) or nil return (desync.plan and #desync.plan>0) and table.remove(desync.plan, 1) or nil
end end