mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-14 06:13:09 +00:00
nfqws2: coroutine compat
This commit is contained in:
@@ -796,7 +796,7 @@ static uint8_t desync(
|
||||
|
||||
if (b_cutoff_all)
|
||||
{
|
||||
if (lua_instance_cutoff_check(&ctx, bIncoming))
|
||||
if (lua_instance_cutoff_check(params.L, &ctx, bIncoming))
|
||||
DLOG("* lua '%s' : voluntary cutoff\n", instance);
|
||||
else if (check_pos_cutoff(pos, range))
|
||||
{
|
||||
@@ -827,43 +827,43 @@ static uint8_t desync(
|
||||
{
|
||||
// create arg table that persists across multiple desync function calls
|
||||
lua_newtable(params.L);
|
||||
lua_pushf_dissect(dis);
|
||||
lua_pushf_ctrack(ctrack, tpos, bIncoming);
|
||||
lua_pushf_int("profile_n", dp->n);
|
||||
if (dp->name) lua_pushf_str("profile_name", dp->name);
|
||||
if (dp->n_tpl) lua_pushf_int("template_n", dp->n_tpl);
|
||||
if (dp->name_tpl) lua_pushf_str("template_name", dp->name_tpl);
|
||||
if (dp->cookie) lua_pushf_str("cookie", dp->cookie);
|
||||
lua_pushf_bool("outgoing", !bIncoming);
|
||||
lua_pushf_str("ifin", (ifin && *ifin) ? ifin : NULL);
|
||||
lua_pushf_str("ifout", (ifout && *ifout) ? ifout : NULL);
|
||||
lua_pushf_lint("fwmark", fwmark);
|
||||
lua_pushf_table("target");
|
||||
lua_pushf_dissect(params.L, dis);
|
||||
lua_pushf_ctrack(params.L, ctrack, tpos, bIncoming);
|
||||
lua_pushf_int(params.L, "profile_n", dp->n);
|
||||
if (dp->name) lua_pushf_str(params.L, "profile_name", dp->name);
|
||||
if (dp->n_tpl) lua_pushf_int(params.L, "template_n", dp->n_tpl);
|
||||
if (dp->name_tpl) lua_pushf_str(params.L, "template_name", dp->name_tpl);
|
||||
if (dp->cookie) lua_pushf_str(params.L, "cookie", dp->cookie);
|
||||
lua_pushf_bool(params.L, "outgoing", !bIncoming);
|
||||
lua_pushf_str(params.L, "ifin", (ifin && *ifin) ? ifin : NULL);
|
||||
lua_pushf_str(params.L, "ifout", (ifout && *ifout) ? ifout : NULL);
|
||||
lua_pushf_lint(params.L, "fwmark", fwmark);
|
||||
lua_pushf_table(params.L, "target");
|
||||
lua_getfield(params.L,-1,"target");
|
||||
if (sdport) lua_pushf_int("port",sdport);
|
||||
if (sdp4) lua_pushf_lstr("ip",(const char*)sdp4,sizeof(*sdp4));
|
||||
if (sdp6) lua_pushf_lstr("ip6",(const char*)sdp6,sizeof(*sdp6));
|
||||
if (sdport) lua_pushf_int(params.L, "port",sdport);
|
||||
if (sdp4) lua_pushf_lstr(params.L, "ip",(const char*)sdp4,sizeof(*sdp4));
|
||||
if (sdp6) lua_pushf_lstr(params.L, "ip6",(const char*)sdp6,sizeof(*sdp6));
|
||||
lua_pop(params.L,1);
|
||||
lua_pushf_bool("replay", !!replay_piece_count);
|
||||
lua_pushf_bool(params.L, "replay", !!replay_piece_count);
|
||||
if (replay_piece_count)
|
||||
{
|
||||
lua_pushf_int("replay_piece", replay_piece+1);
|
||||
lua_pushf_int("replay_piece_count", replay_piece_count);
|
||||
lua_pushf_bool("replay_piece_last", (replay_piece+1)>=replay_piece_count);
|
||||
lua_pushf_int(params.L, "replay_piece", replay_piece+1);
|
||||
lua_pushf_int(params.L, "replay_piece_count", replay_piece_count);
|
||||
lua_pushf_bool(params.L, "replay_piece_last", (replay_piece+1)>=replay_piece_count);
|
||||
}
|
||||
lua_pushf_str("l7payload", l7payload_str(l7payload));
|
||||
lua_pushf_str("l7proto", l7proto_str(l7proto));
|
||||
lua_pushf_int("reasm_offset", reasm_offset);
|
||||
lua_pushf_raw("reasm_data", rdata_payload, rlen_payload);
|
||||
lua_pushf_raw("decrypt_data", data_decrypt, len_decrypt);
|
||||
lua_pushf_str(params.L, "l7payload", l7payload_str(l7payload));
|
||||
lua_pushf_str(params.L, "l7proto", l7proto_str(l7proto));
|
||||
lua_pushf_int(params.L, "reasm_offset", reasm_offset);
|
||||
lua_pushf_raw(params.L, "reasm_data", rdata_payload, rlen_payload);
|
||||
lua_pushf_raw(params.L, "decrypt_data", data_decrypt, len_decrypt);
|
||||
//if (ctrack) lua_pushf_reg("instance_cutoff", ctrack->lua_instance_cutoff);
|
||||
if (dis->tcp)
|
||||
{
|
||||
// recommended mss value for generated packets
|
||||
if (rpos && rpos->mss)
|
||||
lua_pushf_int("tcp_mss", rpos->mss);
|
||||
lua_pushf_int(params.L, "tcp_mss", rpos->mss);
|
||||
else
|
||||
lua_pushf_global("tcp_mss", "DEFAULT_MSS");
|
||||
lua_pushf_global(params.L, "tcp_mss", "DEFAULT_MSS");
|
||||
}
|
||||
ref_arg = luaL_ref(params.L, LUA_REGISTRYINDEX);
|
||||
|
||||
@@ -874,7 +874,7 @@ static uint8_t desync(
|
||||
desync_instance(func->func, dp->n, ctx.func_n, instance, sizeof(instance));
|
||||
ctx.instance = instance;
|
||||
|
||||
if (!lua_instance_cutoff_check(&ctx, bIncoming))
|
||||
if (!lua_instance_cutoff_check(params.L, &ctx, bIncoming))
|
||||
{
|
||||
range = bIncoming ? &func->range_in : &func->range_out;
|
||||
if (check_pos_range(pos, range))
|
||||
@@ -899,10 +899,10 @@ static uint8_t desync(
|
||||
}
|
||||
lua_pushlightuserdata(params.L, &ctx);
|
||||
lua_rawgeti(params.L, LUA_REGISTRYINDEX, ref_arg);
|
||||
lua_pushf_args(&func->args, -1, true);
|
||||
lua_pushf_str("func", func->func);
|
||||
lua_pushf_int("func_n", ctx.func_n);
|
||||
lua_pushf_str("func_instance", instance);
|
||||
lua_pushf_args(params.L, &func->args, -1, true);
|
||||
lua_pushf_str(params.L, "func", func->func);
|
||||
lua_pushf_int(params.L, "func_n", ctx.func_n);
|
||||
lua_pushf_str(params.L, "func_instance", instance);
|
||||
|
||||
// lua should not store and access ctx outside of this call
|
||||
// if this happens make our best to prevent access to bad memory
|
||||
@@ -960,7 +960,7 @@ static uint8_t desync(
|
||||
}
|
||||
else
|
||||
{
|
||||
b = lua_reconstruct_dissect(-1, mod_pkt, len_mod_pkt, false, false);
|
||||
b = lua_reconstruct_dissect(params.L, -1, mod_pkt, len_mod_pkt, false, false);
|
||||
lua_pop(params.L, 2);
|
||||
if (!b)
|
||||
{
|
||||
|
||||
1164
nfq2/lua.c
1164
nfq2/lua.c
File diff suppressed because it is too large
Load Diff
82
nfq2/lua.h
82
nfq2/lua.h
@@ -57,49 +57,49 @@ int lua_absindex(lua_State *L, int idx);
|
||||
// push - create object and push to the stack
|
||||
// pushf - create object and set it as a named field of a table already present on the stack
|
||||
// pushi - create object and set it as a index field of a table already present on the stack
|
||||
void lua_pushf_nil(const char *field);
|
||||
void lua_pushi_nil(lua_Integer idx);
|
||||
void lua_pushf_bool(const char *field, bool b);
|
||||
void lua_pushi_bool(lua_Integer idx, bool b);
|
||||
void lua_pushf_str(const char *field, const char *str);
|
||||
void lua_pushi_str(lua_Integer idx, const char *str);
|
||||
void lua_pushf_lstr(const char *field, const char *str, size_t len);
|
||||
void lua_pushi_lstr(lua_Integer idx, const char *str, size_t len);
|
||||
void lua_pushf_int(const char *field, lua_Integer v);
|
||||
void lua_pushi_int(lua_Integer idx, lua_Integer v);
|
||||
void lua_pushf_lint(const char *field, int64_t v);
|
||||
void lua_pushi_lint(lua_Integer idx, int64_t v);
|
||||
void lua_pushf_number(const char *field, lua_Number v);
|
||||
void lua_pushi_number(lua_Integer idx, lua_Number v);
|
||||
void lua_push_raw(const void *v, size_t l);
|
||||
void lua_pushf_raw(const char *field, const void *v, size_t l);
|
||||
void lua_pushi_raw(lua_Integer idx, const void *v, size_t l);
|
||||
void lua_pushf_reg(const char *field, int ref);
|
||||
void lua_pushf_lud(const char *field, void *p);
|
||||
void lua_pushf_table(const char *field);
|
||||
void lua_pushi_table(lua_Integer idx);
|
||||
void lua_pushf_nil(lua_State *L, const char *field);
|
||||
void lua_pushi_nil(lua_State *L, lua_Integer idx);
|
||||
void lua_pushf_bool(lua_State *L, const char *field, bool b);
|
||||
void lua_pushi_bool(lua_State *L, lua_Integer idx, bool b);
|
||||
void lua_pushf_str(lua_State *L, const char *field, const char *str);
|
||||
void lua_pushi_str(lua_State *L, lua_Integer idx, const char *str);
|
||||
void lua_pushf_lstr(lua_State *L, const char *field, const char *str, size_t len);
|
||||
void lua_pushi_lstr(lua_State *L, lua_Integer idx, const char *str, size_t len);
|
||||
void lua_pushf_int(lua_State *L, const char *field, lua_Integer v);
|
||||
void lua_pushi_int(lua_State *L, lua_Integer idx, lua_Integer v);
|
||||
void lua_pushf_lint(lua_State *L, const char *field, int64_t v);
|
||||
void lua_pushi_lint(lua_State *L, lua_Integer idx, int64_t v);
|
||||
void lua_pushf_number(lua_State *L, const char *field, lua_Number v);
|
||||
void lua_pushi_number(lua_State *L, lua_Integer idx, lua_Number v);
|
||||
void lua_push_raw(lua_State *L, const void *v, size_t l);
|
||||
void lua_pushf_raw(lua_State *L, const char *field, const void *v, size_t l);
|
||||
void lua_pushi_raw(lua_State *L, lua_Integer idx, const void *v, size_t l);
|
||||
void lua_pushf_reg(lua_State *L, const char *field, int ref);
|
||||
void lua_pushf_lud(lua_State *L, const char *field, void *p);
|
||||
void lua_pushf_table(lua_State *L, const char *field);
|
||||
void lua_pushi_table(lua_State *L, lua_Integer idx);
|
||||
|
||||
void lua_push_blob(int idx_desync, const char *blob);
|
||||
void lua_pushf_blob(int idx_desync, const char *field, const char *blob);
|
||||
void lua_push_blob(lua_State *L, int idx_desync, const char *blob);
|
||||
void lua_pushf_blob(lua_State *L, int idx_desync, const char *field, const char *blob);
|
||||
|
||||
void lua_pushf_tcphdr_options(const struct tcphdr *tcp, size_t len);
|
||||
void lua_pushf_tcphdr(const struct tcphdr *tcp, size_t len);
|
||||
void lua_pushf_udphdr(const struct udphdr *udp, size_t len);
|
||||
void lua_pushf_iphdr(const struct ip *ip, size_t len);
|
||||
void lua_pushf_ip6hdr(const struct ip6_hdr *ip6, size_t len);
|
||||
void lua_push_dissect(const struct dissect *dis);
|
||||
void lua_pushf_dissect(const struct dissect *dis);
|
||||
void lua_pushf_ctrack(const t_ctrack *ctrack, const t_ctrack_positions *tpos, bool bIncoming);
|
||||
void lua_pushf_args(const struct str2_list_head *args, int idx_desync, bool subst_prefix);
|
||||
void lua_pushf_pos(const char *name, const struct packet_pos *pos);
|
||||
void lua_pushf_range(const char *name, const struct packet_range *range);
|
||||
void lua_pushf_global(const char *field, const char *global);
|
||||
void lua_pushf_tcphdr_options(lua_State *L, const struct tcphdr *tcp, size_t len);
|
||||
void lua_pushf_tcphdr(lua_State *L, const struct tcphdr *tcp, size_t len);
|
||||
void lua_pushf_udphdr(lua_State *L, const struct udphdr *udp, size_t len);
|
||||
void lua_pushf_iphdr(lua_State *L, const struct ip *ip, size_t len);
|
||||
void lua_pushf_ip6hdr(lua_State *L, const struct ip6_hdr *ip6, size_t len);
|
||||
void lua_push_dissect(lua_State *L, const struct dissect *dis);
|
||||
void lua_pushf_dissect(lua_State *L, const struct dissect *dis);
|
||||
void lua_pushf_ctrack(lua_State *L, const t_ctrack *ctrack, const t_ctrack_positions *tpos, bool bIncoming);
|
||||
void lua_pushf_args(lua_State *L, const struct str2_list_head *args, int idx_desync, bool subst_prefix);
|
||||
void lua_pushf_pos(lua_State *L, const char *name, const struct packet_pos *pos);
|
||||
void lua_pushf_range(lua_State *L, const char *name, const struct packet_range *range);
|
||||
void lua_pushf_global(lua_State *L, const char *field, const char *global);
|
||||
|
||||
bool lua_reconstruct_ip6hdr(int idx, struct ip6_hdr *ip6, size_t *len, uint8_t last_proto, bool preserve_next);
|
||||
bool lua_reconstruct_iphdr(int idx, struct ip *ip, size_t *len);
|
||||
bool lua_reconstruct_tcphdr(int idx, struct tcphdr *tcp, size_t *len);
|
||||
bool lua_reconstruct_udphdr(int idx, struct udphdr *udp);
|
||||
bool lua_reconstruct_dissect(int idx, uint8_t *buf, size_t *len, bool badsum, bool ip6_preserve_next);
|
||||
bool lua_reconstruct_ip6hdr(lua_State *L, int idx, struct ip6_hdr *ip6, size_t *len, uint8_t last_proto, bool preserve_next);
|
||||
bool lua_reconstruct_iphdr(lua_State *L, int idx, struct ip *ip, size_t *len);
|
||||
bool lua_reconstruct_tcphdr(lua_State *L, int idx, struct tcphdr *tcp, size_t *len);
|
||||
bool lua_reconstruct_udphdr(lua_State *L, int idx, struct udphdr *udp);
|
||||
bool lua_reconstruct_dissect(lua_State *L, int idx, uint8_t *buf, size_t *len, bool badsum, bool ip6_preserve_next);
|
||||
|
||||
#define MAGIC_CTX 0xE73DC935
|
||||
typedef struct {
|
||||
@@ -112,4 +112,4 @@ typedef struct {
|
||||
bool incoming,cancel;
|
||||
} t_lua_desync_context;
|
||||
|
||||
bool lua_instance_cutoff_check(const t_lua_desync_context *ctx, bool bIn);
|
||||
bool lua_instance_cutoff_check(lua_State *L, const t_lua_desync_context *ctx, bool bIn);
|
||||
|
||||
Reference in New Issue
Block a user