mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 14:25:44 +00:00
Restore offset in splited request
This commit is contained in:
parent
721e5808fb
commit
a067afe6e4
13
conev.h
13
conev.h
@ -2,6 +2,7 @@
|
|||||||
#define CONEV_H
|
#define CONEV_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifndef __linux__
|
#ifndef __linux__
|
||||||
#define NOEPOLL
|
#define NOEPOLL
|
||||||
@ -56,10 +57,10 @@ char *eid_name[] = {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct buffer {
|
struct buffer {
|
||||||
ssize_t size;
|
size_t size;
|
||||||
int offset;
|
unsigned int offset;
|
||||||
char *data;
|
char *data;
|
||||||
char locked;
|
bool locked;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct eval {
|
struct eval {
|
||||||
@ -75,11 +76,11 @@ struct eval {
|
|||||||
struct sockaddr_in6 in6;
|
struct sockaddr_in6 in6;
|
||||||
};
|
};
|
||||||
ssize_t recv_count;
|
ssize_t recv_count;
|
||||||
|
ssize_t round_sent;
|
||||||
unsigned int round_count;
|
unsigned int round_count;
|
||||||
char last_round;
|
|
||||||
int attempt;
|
int attempt;
|
||||||
char cache;
|
bool cache;
|
||||||
char mark; //
|
bool mark; //
|
||||||
};
|
};
|
||||||
|
|
||||||
struct poolhd {
|
struct poolhd {
|
||||||
|
34
desync.c
34
desync.c
@ -434,19 +434,19 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
|||||||
char *host = 0;
|
char *host = 0;
|
||||||
int len = 0, type = 0, host_pos = 0;
|
int len = 0, type = 0, host_pos = 0;
|
||||||
|
|
||||||
// parse packet
|
if (offset == 0) {
|
||||||
if ((len = parse_tls(buffer, n, &host))) {
|
if ((len = parse_tls(buffer, n, &host))) {
|
||||||
type = IS_HTTPS;
|
type = IS_HTTPS;
|
||||||
|
}
|
||||||
|
else if ((len = parse_http(buffer, n, &host, 0))) {
|
||||||
|
type = IS_HTTP;
|
||||||
|
}
|
||||||
|
if (len && host) {
|
||||||
|
LOG(LOG_S, "host: %.*s (%zd)\n",
|
||||||
|
len, host, host - buffer);
|
||||||
|
host_pos = host - buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ((len = parse_http(buffer, n, &host, 0))) {
|
|
||||||
type = IS_HTTP;
|
|
||||||
}
|
|
||||||
if (len && host) {
|
|
||||||
LOG(LOG_S, "host: %.*s (%zd)\n",
|
|
||||||
len, host, host - buffer);
|
|
||||||
host_pos = host - buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// modify packet
|
// modify packet
|
||||||
if (type == IS_HTTP && dp.mod_http) {
|
if (type == IS_HTTP && dp.mod_http) {
|
||||||
LOG(LOG_S, "modify HTTP: n=%zd\n", n);
|
LOG(LOG_S, "modify HTTP: n=%zd\n", n);
|
||||||
@ -484,9 +484,8 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
|||||||
lp = pos + 5;
|
lp = pos + 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// desync
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (dp.drop_sack && drop_sack(sfd)) {
|
if (!offset && dp.drop_sack && drop_sack(sfd)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -504,15 +503,14 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
|||||||
|
|
||||||
pos += part.s * (part.r - r);
|
pos += part.s * (part.r - r);
|
||||||
|
|
||||||
// after EAGAIN
|
if (!(part.flag & OFFSET_START) && offset && pos <= offset) {
|
||||||
if (offset && pos <= offset) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (pos < 0 || pos > n || pos < lp) {
|
if (pos < 0 || pos > n || pos < lp) {
|
||||||
LOG(LOG_E, "split cancel: pos=%ld-%ld, n=%zd\n", lp, pos, n);
|
LOG(LOG_E, "split cancel: pos=%ld-%ld, n=%zd\n", lp, pos, n);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// send part
|
|
||||||
ssize_t s = 0;
|
ssize_t s = 0;
|
||||||
switch (part.m) {
|
switch (part.m) {
|
||||||
#ifdef FAKE_SUPPORT
|
#ifdef FAKE_SUPPORT
|
||||||
|
5
extend.c
5
extend.c
@ -367,8 +367,11 @@ ssize_t tcp_send_hook(struct poolhd *pool, struct eval *remote,
|
|||||||
int m = client->attempt;
|
int m = client->attempt;
|
||||||
LOG((m ? LOG_S : LOG_L), "desync params index: %d\n", m);
|
LOG((m ? LOG_S : LOG_L), "desync params index: %d\n", m);
|
||||||
|
|
||||||
|
ssize_t offset = client->round_sent + client->buff.offset;
|
||||||
|
if (!offset && remote->round_count) offset = -1;
|
||||||
|
|
||||||
sn = desync(remote->fd, buffer, bfsize, n,
|
sn = desync(remote->fd, buffer, bfsize, n,
|
||||||
0, (struct sockaddr *)&remote->in6, m);
|
offset, (struct sockaddr *)&remote->in6, m);
|
||||||
return sn;
|
return sn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
main.c
3
main.c
@ -421,7 +421,8 @@ int parse_offset(struct part *part, const char *str)
|
|||||||
case 'r':
|
case 'r':
|
||||||
part->flag |= OFFSET_RAND;
|
part->flag |= OFFSET_RAND;
|
||||||
break;
|
break;
|
||||||
case 's':;
|
case 's':
|
||||||
|
part->flag |= OFFSET_START;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
part->pos = val;
|
part->pos = val;
|
||||||
|
1
params.h
1
params.h
@ -26,6 +26,7 @@
|
|||||||
#define OFFSET_RAND 4
|
#define OFFSET_RAND 4
|
||||||
#define OFFSET_SNI 8
|
#define OFFSET_SNI 8
|
||||||
#define OFFSET_HOST 16
|
#define OFFSET_HOST 16
|
||||||
|
#define OFFSET_START 32
|
||||||
|
|
||||||
#define DETECT_HTTP_LOCAT 1
|
#define DETECT_HTTP_LOCAT 1
|
||||||
#define DETECT_TLS_ERR 2
|
#define DETECT_TLS_ERR 2
|
||||||
|
6
proxy.c
6
proxy.c
@ -686,13 +686,13 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
val->recv_count += n;
|
val->recv_count += n;
|
||||||
if (!val->last_round) {
|
if (val->round_sent == 0) {
|
||||||
val->round_count++;
|
val->round_count++;
|
||||||
val->last_round = 1;
|
pair->round_sent = 0;
|
||||||
pair->last_round = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t sn = tcp_send_hook(pool, pair, buffer, bfsize, n);
|
ssize_t sn = tcp_send_hook(pool, pair, buffer, bfsize, n);
|
||||||
|
val->round_sent += sn > 0 ? sn : 0;
|
||||||
if (sn < n) {
|
if (sn < n) {
|
||||||
if (sn < 0) {
|
if (sn < 0) {
|
||||||
uniperror("send");
|
uniperror("send");
|
||||||
|
Loading…
Reference in New Issue
Block a user