mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 14:25:44 +00:00
Make -R param local
This commit is contained in:
parent
05bca80eca
commit
240185efe0
51
extend.c
51
extend.c
@ -212,6 +212,12 @@ static bool check_proto_tcp(int proto, char *buffer, ssize_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool check_round(int nr[2], int r)
|
||||||
|
{
|
||||||
|
return (!nr[1] && r <= 1) || (r >= nr[0] && r <= nr[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int on_trigger(int type, struct poolhd *pool, struct eval *val)
|
static int on_trigger(int type, struct poolhd *pool, struct eval *val)
|
||||||
{
|
{
|
||||||
int m = val->pair->attempt + 1;
|
int m = val->pair->attempt + 1;
|
||||||
@ -435,31 +441,35 @@ ssize_t tcp_send_hook(struct eval *remote,
|
|||||||
char *buffer, size_t bfsize, ssize_t n)
|
char *buffer, size_t bfsize, ssize_t n)
|
||||||
{
|
{
|
||||||
ssize_t sn = -1;
|
ssize_t sn = -1;
|
||||||
|
int skip = remote->flag != FLAG_CONN;
|
||||||
|
|
||||||
if (remote->flag != FLAG_CONN
|
if (!skip) {
|
||||||
|| remote->pair->round_count > params.repeats) {
|
|
||||||
sn = send(remote->fd, buffer, n, 0);
|
|
||||||
if (sn < 0 && get_e() == EAGAIN) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
remote->pair->round_sent += sn;
|
|
||||||
return sn;
|
|
||||||
}
|
|
||||||
struct eval *client = remote->pair;
|
struct eval *client = remote->pair;
|
||||||
|
|
||||||
if (client->recv_count == n
|
if (client->recv_count == n
|
||||||
&& setup_conn(client, buffer, n) < 0) {
|
&& setup_conn(client, buffer, n) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int m = client->attempt;
|
int m = client->attempt, r = client->round_count;
|
||||||
LOG((m ? LOG_S : LOG_L), "desync TCP, m=%d\n", m);
|
if (!check_round(params.dp[m].rounds, r)) {
|
||||||
|
skip = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG((m ? LOG_S : LOG_L), "desync TCP, m=%d, r=%d\n", m, r);
|
||||||
|
|
||||||
ssize_t offset = client->round_sent;
|
ssize_t offset = remote->pair->round_sent;
|
||||||
if (!offset && remote->round_count) offset = -1;
|
if (!offset && remote->round_count) offset = -1;
|
||||||
|
|
||||||
sn = desync(remote->fd, buffer, bfsize, n,
|
sn = desync(remote->fd, buffer, bfsize, n,
|
||||||
offset, (struct sockaddr *)&remote->in6, m);
|
offset, (struct sockaddr *)&remote->in6, m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (skip) {
|
||||||
|
sn = send(remote->fd, buffer, n, 0);
|
||||||
|
if (sn < 0 && get_e() == EAGAIN) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
remote->pair->round_sent += sn;
|
remote->pair->round_sent += sn;
|
||||||
return sn;
|
return sn;
|
||||||
}
|
}
|
||||||
@ -497,7 +507,8 @@ ssize_t tcp_recv_hook(struct poolhd *pool, struct eval *val,
|
|||||||
val->pair->round_sent = 0;
|
val->pair->round_sent = 0;
|
||||||
}
|
}
|
||||||
if (val->flag == FLAG_CONN
|
if (val->flag == FLAG_CONN
|
||||||
&& val->round_count >= params.repeats
|
&& check_round(
|
||||||
|
params.dp[val->pair->attempt].rounds, val->round_count)
|
||||||
&& cancel_setup(val)) {
|
&& cancel_setup(val)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -510,10 +521,7 @@ ssize_t udp_hook(struct eval *val,
|
|||||||
{
|
{
|
||||||
struct eval *pair = val->pair->pair;
|
struct eval *pair = val->pair->pair;
|
||||||
|
|
||||||
if (pair->round_count > params.repeats) {
|
int m = pair->attempt, r = pair->round_count;
|
||||||
return send(val->fd, buffer, n, 0);
|
|
||||||
}
|
|
||||||
int m = val->attempt;
|
|
||||||
if (!m) {
|
if (!m) {
|
||||||
for (; m < params.dp_count; m++) {
|
for (; m < params.dp_count; m++) {
|
||||||
struct desync_params *dp = ¶ms.dp[m];
|
struct desync_params *dp = ¶ms.dp[m];
|
||||||
@ -526,9 +534,12 @@ ssize_t udp_hook(struct eval *val,
|
|||||||
if (m >= params.dp_count) {
|
if (m >= params.dp_count) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
val->attempt = m;
|
pair->attempt = m;
|
||||||
}
|
}
|
||||||
LOG(LOG_S, "desync UDP, m=%d\n", m);
|
if (!check_round(params.dp[m].rounds, r)) {
|
||||||
|
return send(val->fd, buffer, n, 0);
|
||||||
|
}
|
||||||
|
LOG(LOG_S, "desync UDP, m=%d, r=%d\n", m, r);
|
||||||
return desync_udp(val->fd, buffer, bfsize, n, &dst->sa, m);
|
return desync_udp(val->fd, buffer, bfsize, n, &dst->sa, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
main.c
31
main.c
@ -54,7 +54,6 @@ struct params params = {
|
|||||||
.laddr = {
|
.laddr = {
|
||||||
.sin6_family = AF_INET
|
.sin6_family = AF_INET
|
||||||
},
|
},
|
||||||
.repeats = 1,
|
|
||||||
.debug = 0,
|
.debug = 0,
|
||||||
.auto_level = AUTO_NOBUFF
|
.auto_level = AUTO_NOBUFF
|
||||||
};
|
};
|
||||||
@ -81,13 +80,13 @@ const char help_text[] = {
|
|||||||
" Detect: torst,redirect,ssl_err,none\n"
|
" Detect: torst,redirect,ssl_err,none\n"
|
||||||
" -L, --auto-mode <0|1> 1 - handle trigger after several packets\n"
|
" -L, --auto-mode <0|1> 1 - handle trigger after several packets\n"
|
||||||
" -u, --cache-ttl <sec> Lifetime of cached desync params for IP\n"
|
" -u, --cache-ttl <sec> Lifetime of cached desync params for IP\n"
|
||||||
" -R, --repeats <num> Number of requests to which desync will be applied\n"
|
|
||||||
#ifdef TIMEOUT_SUPPORT
|
#ifdef TIMEOUT_SUPPORT
|
||||||
" -T, --timeout <sec> Timeout waiting for response, after which trigger auto\n"
|
" -T, --timeout <sec> Timeout waiting for response, after which trigger auto\n"
|
||||||
#endif
|
#endif
|
||||||
" -K, --proto <t,h,u> Protocol whitelist: tls,http,udp\n"
|
" -K, --proto <t,h,u> Protocol whitelist: tls,http,udp\n"
|
||||||
" -H, --hosts <file|:str> Hosts whitelist, filename or :string\n"
|
" -H, --hosts <file|:str> Hosts whitelist, filename or :string\n"
|
||||||
" -V, --pf <port[-portr]> Ports range whitelist\n"
|
" -V, --pf <port[-portr]> Ports range whitelist\n"
|
||||||
|
" -R, --round <num[-numr> Number of request to which desync will be applied\n"
|
||||||
" -s, --split <pos_t> Position format: offset[:repeats:skip][+flag1[flag2]]\n"
|
" -s, --split <pos_t> Position format: offset[:repeats:skip][+flag1[flag2]]\n"
|
||||||
" Flags: +s - SNI offset, +h - HTTP host offset\n"
|
" Flags: +s - SNI offset, +h - HTTP host offset\n"
|
||||||
" Additional flags: +e - end, +m - middle, +r - random\n"
|
" Additional flags: +e - end, +m - middle, +r - random\n"
|
||||||
@ -136,7 +135,6 @@ const struct option options[] = {
|
|||||||
#endif
|
#endif
|
||||||
{"auto", 1, 0, 'A'},
|
{"auto", 1, 0, 'A'},
|
||||||
{"auto-mode", 1, 0, 'L'},
|
{"auto-mode", 1, 0, 'L'},
|
||||||
{"repeats", 1, 0, 'R'},
|
|
||||||
{"cache-ttl", 1, 0, 'u'},
|
{"cache-ttl", 1, 0, 'u'},
|
||||||
#ifdef TIMEOUT_SUPPORT
|
#ifdef TIMEOUT_SUPPORT
|
||||||
{"timeout", 1, 0, 'T'},
|
{"timeout", 1, 0, 'T'},
|
||||||
@ -144,6 +142,7 @@ const struct option options[] = {
|
|||||||
{"proto", 1, 0, 'K'},
|
{"proto", 1, 0, 'K'},
|
||||||
{"hosts", 1, 0, 'H'},
|
{"hosts", 1, 0, 'H'},
|
||||||
{"pf", 1, 0, 'V'},
|
{"pf", 1, 0, 'V'},
|
||||||
|
{"repeats", 1, 0, 'R'},
|
||||||
{"split", 1, 0, 's'},
|
{"split", 1, 0, 's'},
|
||||||
{"disorder", 1, 0, 'd'},
|
{"disorder", 1, 0, 'd'},
|
||||||
{"oob", 1, 0, 'o'},
|
{"oob", 1, 0, 'o'},
|
||||||
@ -620,14 +619,6 @@ int main(int argc, char **argv)
|
|||||||
params.auto_level = val;
|
params.auto_level = val;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'R':
|
|
||||||
val = strtol(optarg, &end, 0);
|
|
||||||
if (val < 1 || val > INT_MAX || *end)
|
|
||||||
invalid = 1;
|
|
||||||
else
|
|
||||||
params.repeats = val;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'A':
|
case 'A':
|
||||||
if (!(dp->hosts || dp->proto || dp->pf[0] || dp->detect)) {
|
if (!(dp->hosts || dp->proto || dp->pf[0] || dp->detect)) {
|
||||||
all_limited = 0;
|
all_limited = 0;
|
||||||
@ -881,6 +872,24 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'R':
|
||||||
|
val = strtol(optarg, &end, 0);
|
||||||
|
if (val <= 0 || val > INT_MAX)
|
||||||
|
invalid = 1;
|
||||||
|
else {
|
||||||
|
dp->rounds[0] = val;
|
||||||
|
if (*end == '-') {
|
||||||
|
val = strtol(end + 1, &end, 0);
|
||||||
|
if (val <= 0 || val > INT_MAX)
|
||||||
|
invalid = 1;
|
||||||
|
}
|
||||||
|
if (*end)
|
||||||
|
invalid = 1;
|
||||||
|
else
|
||||||
|
dp->rounds[1] = val;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
val = strtol(optarg, &end, 0);
|
val = strtol(optarg, &end, 0);
|
||||||
if (val <= 0 || val > 255 || *end)
|
if (val <= 0 || val > 255 || *end)
|
||||||
|
3
params.h
3
params.h
@ -89,6 +89,7 @@ struct desync_params {
|
|||||||
int detect;
|
int detect;
|
||||||
struct mphdr *hosts;
|
struct mphdr *hosts;
|
||||||
uint16_t pf[2];
|
uint16_t pf[2];
|
||||||
|
int rounds[2];
|
||||||
|
|
||||||
char *file_ptr;
|
char *file_ptr;
|
||||||
ssize_t file_size;
|
ssize_t file_size;
|
||||||
@ -118,8 +119,6 @@ struct params {
|
|||||||
struct mphdr *mempool;
|
struct mphdr *mempool;
|
||||||
|
|
||||||
char *protect_path;
|
char *protect_path;
|
||||||
|
|
||||||
int repeats;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct params params;
|
extern struct params params;
|
||||||
|
Loading…
Reference in New Issue
Block a user