From c13284b776f67f3a4735250f22596a2538a7e89b Mon Sep 17 00:00:00 2001 From: bol-van Date: Fri, 20 Feb 2026 07:18:31 +0300 Subject: [PATCH] zapret-auto: per_instance_condition feed target desync to cond function, code=>cond_code --- docs/changes.txt | 1 + docs/manual.en.md | 7 ++++++- docs/manual.md | 7 ++++++- lua/zapret-auto.lua | 14 ++++++++------ lua/zapret-lib.lua | 7 +++++-- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 8ae8952..8a11d54 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -252,3 +252,4 @@ v0.9.4 v0.9.5 * 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 diff --git a/docs/manual.en.md b/docs/manual.en.md index 43cbbf0..3511b5f 100644 --- a/docs/manual.en.md +++ b/docs/manual.en.md @@ -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_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. 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 ``` @@ -4473,7 +4478,7 @@ Returns `true` if the dissect is tcp and has tcp timestamp option. 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 diff --git a/docs/manual.md b/docs/manual.md index ebf6bdb..73264d0 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -3733,11 +3733,16 @@ function verdict_aggregate(v1, v2) ``` 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](#внутрипрофильные-фильтры). Возвращает агрегацию verdict и вердикта `instance`. +Вариант "preapplied" не выполняет apply_execution_plan, позволяя это сделат вызывающему коду. +Иногда для принятия решения вызывать ли instance требуется таблица desync, настроенная на вызываемый инстанс. +Чтобы не делать apply дважды (там копирование desync.arg) и существует этот вариант. + ### plan_instance_pop ``` @@ -4652,7 +4657,7 @@ function cond_tcp_ts(desync) function cond_lua(desync) ``` -Выполняет Lua код из аргумента "code". Код возвращает значение условия через return. Возможна прямая адресация таблицы desync. +Выполняет Lua код из аргумента "cond_code". Код возвращает значение условия через return. Возможна прямая адресация таблицы desync. # Вспомогательные программы diff --git a/lua/zapret-auto.lua b/lua/zapret-auto.lua index 9b7a4c2..fe9bc09 100644 --- a/lua/zapret-auto.lua +++ b/lua/zapret-auto.lua @@ -411,19 +411,19 @@ function cond_tcp_has_ts(desync) end -- exec lua code in "code" arg and return it's result function cond_lua(desync) - if not desync.arg.code then - error("cond_lua: no 'code' parameter") + if not desync.arg.cond_code then + error("cond_lua: no 'cond_code' parameter") end - local fname = desync.func_instance.."_cond_code" + local fname = desync.func_instance.."_cond_cond_code" if not _G[fname] then local err - _G[fname], err = load(desync.arg.code, fname) + _G[fname], err = load(desync.arg.cond_code, fname) if not _G[fname] then error(err) return end end - -- allow dynamic code to access desync + -- allow dynamic cond_code to access desync _G.desync = desync local res, v = pcall(_G[fname]) _G.desync = nil @@ -479,8 +479,10 @@ function per_instance_condition(ctx, desync) if type(_G[instance.arg.cond])~="function" then error("per_instance_condition: invalid 'iff' function '"..instance.arg.cond.."'") 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 - verdict = plan_instance_execute(desync, verdict, instance) + verdict = plan_instance_execute_preapplied(desync, verdict, instance) else DLOG("per_instance_condition: condition not satisfied. skipping '"..instance.func_instance.."'") end diff --git a/lua/zapret-lib.lua b/lua/zapret-lib.lua index edccb56..70b33d7 100644 --- a/lua/zapret-lib.lua +++ b/lua/zapret-lib.lua @@ -192,8 +192,7 @@ function verdict_aggregate(v1, v2) end return bitor(v,vn) end -function plan_instance_execute(desync, verdict, instance) - apply_execution_plan(desync, instance) +function plan_instance_execute_preapplied(desync, verdict, instance) if cutoff_shim_check(desync) then DLOG("plan_instance_execute: not calling '"..desync.func_instance.."' because of voluntary cutoff") elseif not payload_match_filter(desync.l7payload, instance.payload_filter) then @@ -206,6 +205,10 @@ function plan_instance_execute(desync, verdict, instance) end return verdict 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) return (desync.plan and #desync.plan>0) and table.remove(desync.plan, 1) or nil end