Template
1
0
mirror of https://github.com/bol-van/zapret2.git synced 2026-03-13 22:03:09 +00:00

9 Commits

Author SHA1 Message Date
bol-van
766b60544f nfqws2: remove unused var 2026-03-04 22:50:31 +03:00
bol-van
e563f60153 AI fixes 2026-03-04 22:36:31 +03:00
bol-van
6d7f8efc49 nfqws2: optimize quic CRYPTO defrag 2026-03-04 19:33:49 +03:00
bol-van
e46cde8e6e nfqws2: optimize 2026-03-04 18:58:39 +03:00
bol-van
52072359f0 nfqws2: remove unneeded function 2026-03-04 18:54:38 +03:00
bol-van
cafacf35bc nfqws2: quic CRYPTO frag early dedup 2026-03-04 18:52:47 +03:00
bol-van
55dc47bae4 nfqws2: remove unneeded loop 2026-03-04 14:16:19 +03:00
bol-van
14a2548bf5 nfqws2: allow quic CRYPTO fragment intersection and dups 2026-03-04 12:31:40 +03:00
bol-van
f59ddbb645 github,linux-builder: revert to lj_alloc for arm64 and mips64 2026-03-03 19:25:33 +03:00
6 changed files with 74 additions and 20 deletions

View File

@@ -100,6 +100,7 @@ jobs:
export PKG_CONFIG_PATH=$DEPS_DIR/lib/pkgconfig
export STAGING_DIR=$RUNNER_TEMP
OPTIMIZE=-Oz
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
case "$ARCH" in
lexra)
OPTIMIZE=-Os
@@ -107,6 +108,10 @@ jobs:
arm)
CPU="-mcpu=cortex-a7 -mthumb"
;;
arm64|mips64)
# not safe without GC64
SYSMALLOC=
;;
esac
MINSIZE="$OPTIMIZE $MINSIZE"
@@ -131,9 +136,10 @@ jobs:
*)
HOSTCC="cc -m32"
esac
echo ARCH=$ARCH SYSMALLOC=$SYSMALLOC
(
cd luajit2-*
make BUILDMODE=static XCFLAGS="-DLUAJIT_USE_SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS" -j$(nproc)
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS" -j$(nproc)
make install PREFIX= DESTDIR=$DEPS_DIR
)
LJIT=1
@@ -236,10 +242,15 @@ jobs:
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
export PKG_CONFIG_PATH=$DEPS_DIR/lib/pkgconfig
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
case "$ABI" in
armeabi-v7a)
CPU="-mthumb"
;;
arm64-v8a)
# not safe without GC64
SYSMALLOC=
;;
esac
# luajit
@@ -253,7 +264,7 @@ jobs:
esac
(
cd luajit2-*
make BUILDMODE=static XCFLAGS="-DLUAJIT_USE_SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" -j$(nproc)
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" -j$(nproc)
make install PREFIX= DESTDIR=$DEPS_DIR
)
LJIT=1

View File

@@ -266,3 +266,9 @@ v0.9.4.3
* github, linux-builder: reduce arm executable size by 20% - move to armv7+thumb
* init.d: warn if hostlist/ipset files are inside zapret2 root
* zapret-lib: do not call apply_arg_prefix in apply_execution_plan - call it right before instance execute
0.9.4.5
* github: rollback to lj_alloc in luajit for arm64 and mips64
* nfqws2: join fragments in quic CRYPTO reconstruction. allow intersections.

View File

@@ -62,11 +62,20 @@ build_lua()
build_luajit()
{
local CFL="$CFLAGS"
local SYSMALLOC=
(
cd luajit2-*
CFLAGS="-Os"
make clean
make BUILDMODE=static XCFLAGS="-DLUAJIT_USE_SYSMALLOC -DLUAJIT_DISABLE_FFI $CFLAGS_PIC" HOST_CC="$HOST_CC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$OPTIMIZE $MINSIZE $CFL" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS"
case $TARGET in
aarch64*|mips64*)
# sysmalloc can cause troubles without GC64. GC64 slows down by 10-15%. better not to use sysmalloc and leave lj_alloc.
;;
*)
# save some exe size
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
esac
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI $CFLAGS_PIC" HOST_CC="$HOST_CC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$OPTIMIZE $MINSIZE $CFL" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS"
make install PREFIX= DESTDIR="$STAGING_DIR"
)
}

View File

@@ -50,7 +50,6 @@ void qsort_ssize_t(ssize_t *array, int ct)
qsort(array, ct, sizeof(*array), cmp_ssize_t);
}
int str_index(const char **strs, int count, const char *str)
{
for (int i = 0; i < count; i++)

View File

@@ -12,6 +12,9 @@
#include <fcntl.h>
#define UNARY_PLUS(v) (v>0 ? "+" : "")
//#define MIN(v1,v2) ((v1)<(v2) ? (v1) : (v2))
//#define MAX(v1,v2) ((v1)<(v2) ? (v2) : (v1))
// this saves memory. sockaddr_storage is larger than required. it can be 128 bytes. sockaddr_in6 is 28 bytes.
typedef union

View File

@@ -1252,6 +1252,13 @@ static int cmp_range64(const void * a, const void * b)
{
return (((struct range64*)a)->offset < ((struct range64*)b)->offset) ? -1 : (((struct range64*)a)->offset > ((struct range64*)b)->offset) ? 1 : 0;
}
/*
static bool intersected_u64(uint64_t l1, uint64_t r1, uint64_t l2, uint64_t r2)
{
return l1 <= r2 && l2 <= r1;
}
*/
bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,size_t *defrag_len, bool *bFull)
{
// Crypto frame can be split into multiple chunks
@@ -1265,7 +1272,7 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
uint64_t offset,sz,szmax=0,zeropos=0,pos=0;
bool found=false;
struct range64 ranges[MAX_DEFRAG_PIECES];
int i,range=0;
int i,j,range=0;
while(pos<clean_len)
{
@@ -1292,19 +1299,50 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
memset(defrag_data+zeropos,0,offset-zeropos);
if ((offset+sz) > zeropos)
zeropos=offset+sz;
memcpy(defrag_data+offset,clean+pos,sz);
if ((offset+sz) > szmax) szmax = offset+sz;
found=true;
pos+=sz;
// remove exact duplicates early to save cpu
for(i=0;i<range;i++)
if (ranges[i].offset==offset && ranges[i].len==sz)
goto endloop;
ranges[range].offset = offset;
ranges[range].len = sz;
range++;
}
endloop:
}
if (found)
{
qsort(ranges, range, sizeof(*ranges), cmp_range64);
// for(i=0 ; i<range ; i++)
// printf("range1 %llu-%llu\n",ranges[i].offset,ranges[i].offset+ranges[i].len);
if (range>0)
{
for (j=0,i=1; i < range; i++)
{
uint64_t current_end = ranges[j].offset + ranges[j].len;
uint64_t next_start = ranges[i].offset;
uint64_t next_end = ranges[i].offset + ranges[i].len;
if (next_start <= current_end)
ranges[j].len = MAX(next_end,current_end) - ranges[j].offset;
else
ranges[++j] = ranges[i];
}
range = j+1;
}
// for(i=0 ; i<range ; i++)
// printf("range2 %llu-%llu\n",ranges[i].offset,ranges[i].offset+ranges[i].len);
defrag[0] = 6;
defrag[1] = 0; // offset
// 2..9 - length 64 bit
@@ -1313,21 +1351,7 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
defrag[2] |= 0xC0; // 64 bit value
*defrag_len = (size_t)(szmax+10);
qsort(ranges, range, sizeof(*ranges), cmp_range64);
//for(i=0 ; i<range ; i++)
// printf("RANGE %zu len %zu\n",ranges[i].offset,ranges[i].len);
for(i=0,offset=0,*bFull=true ; i<range ; i++)
{
if (ranges[i].offset!=offset)
{
*bFull = false;
break;
}
offset += ranges[i].len;
}
*bFull = range==1 && !ranges[0].offset;
//printf("bFull=%u\n",*bFull);
}
return found;
@@ -1350,6 +1374,8 @@ bool IsQUICInitial(const uint8_t *data, size_t len)
if (data[offset] > QUIC_MAX_CID_LENGTH) return false;
offset += 1 + data[offset];
if (offset>=len) return false;
// SCID
if (data[offset] > QUIC_MAX_CID_LENGTH) return false;
offset += 1 + data[offset];