diff --git a/docs/changes.txt b/docs/changes.txt index 7d5e822..d9a40ca 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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. + diff --git a/nfq2/helpers.c b/nfq2/helpers.c index 33513ff..4c96df6 100644 --- a/nfq2/helpers.c +++ b/nfq2/helpers.c @@ -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++) diff --git a/nfq2/helpers.h b/nfq2/helpers.h index b64be89..680c3a4 100644 --- a/nfq2/helpers.h +++ b/nfq2/helpers.h @@ -12,6 +12,9 @@ #include #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 diff --git a/nfq2/protocol.c b/nfq2/protocol.c index b4f0bcc..cccd9b2 100644 --- a/nfq2/protocol.c +++ b/nfq2/protocol.c @@ -1252,6 +1252,11 @@ 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>=l2 && l1<=r2 || r1>=l2 && r1<=r2 || l2>=l1 && l2<=r1 || r2>=l1 && r2<=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 @@ -1262,10 +1267,10 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz uint8_t *defrag_data = defrag+10; size_t defrag_data_len = *defrag_len-10; uint8_t ft; - uint64_t offset,sz,szmax=0,zeropos=0,pos=0; - bool found=false; + uint64_t offset,sz,szmax=0,zeropos=0,pos=0,r1,r2; + bool found=false, isect; struct range64 ranges[MAX_DEFRAG_PIECES]; - int i,range=0; + int i,j,range=0; while(pos zeropos) zeropos=offset+sz; + memcpy(defrag_data+offset,clean+pos,sz); if ((offset+sz) > szmax) szmax = offset+sz; found=true; pos+=sz; - ranges[range].offset = offset; ranges[range].len = sz; range++; @@ -1305,6 +1310,37 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz } if (found) { + //for(i=0 ; i=0 ; i--) + { + r1 = ranges[i].offset + ranges[i].len; + for(j=i-1 ; j>=0 ; j--) + { + r2 = ranges[j].offset + ranges[j].len; + //printf("test intersect i=%d j=%d %llu-%llu %llu-%llu\n",i,j,ranges[i].offset,r1,ranges[j].offset,r2); + if (intersected_u64(ranges[i].offset,r1,ranges[j].offset,r2)) + { + // join range + isect = true; + ranges[j].offset = MIN(ranges[i].offset, ranges[j].offset); + ranges[j].len = MAX(r1,r2) - ranges[j].offset; + // delete element i + memmove(ranges+i, ranges+i+1, (range-i-1)*sizeof(*ranges)); + range--; + //printf("intersected %llu-%llu\n",ranges[j].offset,ranges[j].offset+ranges[j].len); + //for(int k=0 ; k