mirror of
https://github.com/bol-van/zapret.git
synced 2024-12-22 06:15:25 +00:00
nfqws: optimize code
This commit is contained in:
parent
f973a6f3a6
commit
f8b3dca6f5
49
nfq/desync.c
49
nfq/desync.c
@ -1118,7 +1118,7 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
|
|||||||
DLOG("dpi desync src=%s dst=%s\n",s1,s2);
|
DLOG("dpi desync src=%s dst=%s\n",s1,s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct split_pos *spos;
|
const struct proto_pos *spos;
|
||||||
switch(l7proto)
|
switch(l7proto)
|
||||||
{
|
{
|
||||||
case HTTP:
|
case HTTP:
|
||||||
@ -1152,30 +1152,6 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
|
|||||||
else
|
else
|
||||||
DLOG("all multisplit pos are outside of this packet\n");
|
DLOG("all multisplit pos are outside of this packet\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (dp->desync_mode==DESYNC_SPLIT || dp->desync_mode==DESYNC_SPLIT2 || dp->desync_mode==DESYNC_DISORDER || dp->desync_mode==DESYNC_DISORDER2 ||
|
|
||||||
dp->desync_mode2==DESYNC_SPLIT || dp->desync_mode2==DESYNC_SPLIT2 || dp->desync_mode2==DESYNC_DISORDER || dp->desync_mode2==DESYNC_DISORDER2)
|
|
||||||
{
|
|
||||||
multisplit_count=0;
|
|
||||||
split_pos = ResolvePos(rdata_payload, rlen_payload, l7proto, spos);
|
|
||||||
DLOG("regular split pos: %zu\n",split_pos);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
multisplit_count=0;
|
|
||||||
split_pos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we do not need reasm buffer anymore
|
|
||||||
reasm_orig_cancel(ctrack);
|
|
||||||
rdata_payload=NULL;
|
|
||||||
|
|
||||||
if (!split_pos || split_pos>rlen_payload) split_pos=1;
|
|
||||||
split_pos=pos_normalize(split_pos,reasm_offset,dis->len_payload);
|
|
||||||
if (split_pos)
|
|
||||||
DLOG("normalized regular split pos : %zu\n",split_pos);
|
|
||||||
else
|
|
||||||
DLOG("regular split pos is outside of this packet\n");
|
|
||||||
if (multisplit_count)
|
if (multisplit_count)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
@ -1197,6 +1173,29 @@ static uint8_t dpi_desync_tcp_packet_play(bool replay, size_t reasm_offset, uint
|
|||||||
DLOG("all multisplit pos are outside of this packet\n");
|
DLOG("all multisplit pos are outside of this packet\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (dp->desync_mode==DESYNC_SPLIT || dp->desync_mode==DESYNC_SPLIT2 || dp->desync_mode==DESYNC_DISORDER || dp->desync_mode==DESYNC_DISORDER2 ||
|
||||||
|
dp->desync_mode2==DESYNC_SPLIT || dp->desync_mode2==DESYNC_SPLIT2 || dp->desync_mode2==DESYNC_DISORDER || dp->desync_mode2==DESYNC_DISORDER2)
|
||||||
|
{
|
||||||
|
multisplit_count=0;
|
||||||
|
split_pos = ResolvePos(rdata_payload, rlen_payload, l7proto, spos);
|
||||||
|
DLOG("regular split pos: %zu\n",split_pos);
|
||||||
|
if (!split_pos || split_pos>rlen_payload) split_pos=1;
|
||||||
|
split_pos=pos_normalize(split_pos,reasm_offset,dis->len_payload);
|
||||||
|
if (split_pos)
|
||||||
|
DLOG("normalized regular split pos : %zu\n",split_pos);
|
||||||
|
else
|
||||||
|
DLOG("regular split pos is outside of this packet\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
multisplit_count=0;
|
||||||
|
split_pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we do not need reasm buffer anymore
|
||||||
|
reasm_orig_cancel(ctrack);
|
||||||
|
rdata_payload=NULL;
|
||||||
|
|
||||||
uint32_t fooling_orig = FOOL_NONE;
|
uint32_t fooling_orig = FOOL_NONE;
|
||||||
bool bFake = false;
|
bool bFake = false;
|
||||||
|
12
nfq/nfqws.c
12
nfq/nfqws.c
@ -726,7 +726,7 @@ static bool wf_make_l3(char *opt, bool *ipv4, bool *ipv6)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_httpreqpos(const char *s, struct split_pos *sp)
|
static bool parse_httpreqpos(const char *s, struct proto_pos *sp)
|
||||||
{
|
{
|
||||||
if (!strcmp(s, "method"))
|
if (!strcmp(s, "method"))
|
||||||
{
|
{
|
||||||
@ -742,7 +742,7 @@ static bool parse_httpreqpos(const char *s, struct split_pos *sp)
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static bool parse_tlspos(const char *s, struct split_pos *sp)
|
static bool parse_tlspos(const char *s, struct proto_pos *sp)
|
||||||
{
|
{
|
||||||
if (!strcmp(s, "sni"))
|
if (!strcmp(s, "sni"))
|
||||||
{
|
{
|
||||||
@ -794,7 +794,7 @@ static bool parse_posmarker(const char *opt, uint8_t *posmarker)
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static bool parse_split_pos(char *opt, struct split_pos *split)
|
static bool parse_split_pos(char *opt, struct proto_pos *split)
|
||||||
{
|
{
|
||||||
if (parse_int16(opt,&split->pos))
|
if (parse_int16(opt,&split->pos))
|
||||||
{
|
{
|
||||||
@ -818,7 +818,7 @@ static bool parse_split_pos(char *opt, struct split_pos *split)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static bool parse_split_pos_list(char *opt, struct split_pos *splits, int splits_size, int *split_count)
|
static bool parse_split_pos_list(char *opt, struct proto_pos *splits, int splits_size, int *split_count)
|
||||||
{
|
{
|
||||||
char c,*e,*p;
|
char c,*e,*p;
|
||||||
|
|
||||||
@ -850,7 +850,7 @@ static void split_compat(struct desync_profile *dp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SPLIT_POS_EMPTY(&dp->split_http))
|
if (PROTO_POS_EMPTY(&dp->split_http))
|
||||||
{
|
{
|
||||||
dp->split_http=dp->split_unknown;
|
dp->split_http=dp->split_unknown;
|
||||||
for (i=0;i<dp->split_count;i++)
|
for (i=0;i<dp->split_count;i++)
|
||||||
@ -860,7 +860,7 @@ static void split_compat(struct desync_profile *dp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SPLIT_POS_EMPTY(&dp->split_tls))
|
if (PROTO_POS_EMPTY(&dp->split_tls))
|
||||||
{
|
{
|
||||||
dp->split_tls=dp->split_unknown;
|
dp->split_tls=dp->split_unknown;
|
||||||
for (i=0;i<dp->split_count;i++)
|
for (i=0;i<dp->split_count;i++)
|
||||||
|
@ -58,10 +58,10 @@ struct desync_profile
|
|||||||
unsigned int desync_repeats,desync_seqovl,desync_ipfrag_pos_tcp,desync_ipfrag_pos_udp;
|
unsigned int desync_repeats,desync_seqovl,desync_ipfrag_pos_tcp,desync_ipfrag_pos_udp;
|
||||||
|
|
||||||
// multisplit
|
// multisplit
|
||||||
struct split_pos splits[MAX_SPLITS];
|
struct proto_pos splits[MAX_SPLITS];
|
||||||
int split_count;
|
int split_count;
|
||||||
// single split pos cache
|
// single split pos cache
|
||||||
struct split_pos split_http,split_tls,split_unknown;
|
struct proto_pos split_http,split_tls,split_unknown;
|
||||||
|
|
||||||
char desync_start_mode, desync_cutoff_mode; // n - packets, d - data packets, s - relative sequence
|
char desync_start_mode, desync_cutoff_mode; // n - packets, d - data packets, s - relative sequence
|
||||||
unsigned int desync_start, desync_cutoff;
|
unsigned int desync_start, desync_cutoff;
|
||||||
|
@ -125,7 +125,7 @@ static size_t HostPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_
|
|||||||
}
|
}
|
||||||
return CheckPos(sz,offset);
|
return CheckPos(sz,offset);
|
||||||
}
|
}
|
||||||
size_t ResolvePos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *sp)
|
size_t ResolvePos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct proto_pos *sp)
|
||||||
{
|
{
|
||||||
switch(l7proto)
|
switch(l7proto)
|
||||||
{
|
{
|
||||||
@ -137,7 +137,7 @@ size_t ResolvePos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struc
|
|||||||
return AnyProtoPos(sp->marker, sp->pos, data, sz);
|
return AnyProtoPos(sp->marker, sp->pos, data, sz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ResolveMultiPos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *splits, int split_count, size_t *pos, int *pos_count)
|
void ResolveMultiPos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct proto_pos *splits, int split_count, size_t *pos, int *pos_count)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i,j;
|
||||||
for(i=j=0;i<split_count;i++)
|
for(i=j=0;i<split_count;i++)
|
||||||
|
@ -26,19 +26,19 @@ bool l7_proto_match(t_l7proto l7proto, uint32_t filter_l7);
|
|||||||
#define PM_HOST_ENDSLD 5
|
#define PM_HOST_ENDSLD 5
|
||||||
#define PM_HTTP_METHOD 6
|
#define PM_HTTP_METHOD 6
|
||||||
#define PM_SNI_EXT 7
|
#define PM_SNI_EXT 7
|
||||||
struct split_pos
|
struct proto_pos
|
||||||
{
|
{
|
||||||
int16_t pos;
|
int16_t pos;
|
||||||
uint8_t marker;
|
uint8_t marker;
|
||||||
};
|
};
|
||||||
#define SPLIT_POS_EMPTY(sp) ((sp)->marker==PM_ABS && (sp)->pos==0)
|
#define PROTO_POS_EMPTY(sp) ((sp)->marker==PM_ABS && (sp)->pos==0)
|
||||||
bool IsHostMarker(uint8_t posmarker);
|
bool IsHostMarker(uint8_t posmarker);
|
||||||
const char *posmarker_name(uint8_t posmarker);
|
const char *posmarker_name(uint8_t posmarker);
|
||||||
size_t AnyProtoPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
size_t AnyProtoPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
||||||
size_t HttpPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
size_t HttpPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
||||||
size_t TLSPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
size_t TLSPos(uint8_t posmarker, int16_t pos, const uint8_t *data, size_t sz);
|
||||||
size_t ResolvePos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *sp);
|
size_t ResolvePos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct proto_pos *sp);
|
||||||
void ResolveMultiPos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct split_pos *splits, int split_count, size_t *pos, int *pos_count);
|
void ResolveMultiPos(const uint8_t *data, size_t sz, t_l7proto l7proto, const struct proto_pos *splits, int split_count, size_t *pos, int *pos_count);
|
||||||
|
|
||||||
extern const char *http_methods[9];
|
extern const char *http_methods[9];
|
||||||
const char *HttpMethod(const uint8_t *data, size_t len);
|
const char *HttpMethod(const uint8_t *data, size_t len);
|
||||||
|
Loading…
Reference in New Issue
Block a user