Fix request parsing

This commit is contained in:
ruti 2024-10-16 02:15:21 +03:00
parent ed7708c4e7
commit 7e52ce9abf

View File

@ -172,12 +172,12 @@ int reconnect(struct poolhd *pool, struct eval *val, int m)
} }
bool check_host(struct mphdr *hosts, struct eval *val) bool check_host(struct mphdr *hosts, char *buffer, ssize_t n)
{ {
char *host = 0; char *host = 0;
int len; int len;
if (!(len = parse_tls(val->buff.data, val->buff.size, &host))) { if (!(len = parse_tls(buffer, n, &host))) {
len = parse_http(val->buff.data, val->buff.size, &host, 0); len = parse_http(buffer, n, &host, 0);
} }
assert(len == 0 || host != 0); assert(len == 0 || host != 0);
if (len <= 0) { if (len <= 0) {
@ -196,17 +196,17 @@ bool check_host(struct mphdr *hosts, struct eval *val)
} }
bool check_proto_tcp(int proto, struct eval *val) bool check_proto_tcp(int proto, char *buffer, ssize_t n)
{ {
if (proto & IS_TCP) { if (proto & IS_TCP) {
return 1; return 1;
} }
else if ((proto & IS_HTTP) && else if ((proto & IS_HTTP) &&
is_http(val->buff.data, val->buff.size)) { is_http(buffer, n)) {
return 1; return 1;
} }
else if ((proto & IS_HTTPS) && else if ((proto & IS_HTTPS) &&
is_tls_chello(val->buff.data, val->buff.size)) { is_tls_chello(buffer, n)) {
return 1; return 1;
} }
return 0; return 0;
@ -218,7 +218,7 @@ int on_torst(struct poolhd *pool, struct eval *val)
int m = val->pair->attempt + 1; int m = val->pair->attempt + 1;
bool can_reconn = ( bool can_reconn = (
val->pair->buff.data && !val->recv_count val->pair->buff.locked && !val->recv_count
); );
if (can_reconn || params.auto_level > AUTO_NOSAVE) { if (can_reconn || params.auto_level > AUTO_NOSAVE) {
for (; m < params.dp_count; m++) { for (; m < params.dp_count; m++) {
@ -258,7 +258,7 @@ int on_fin(struct poolhd *pool, struct eval *val)
int m = val->pair->attempt + 1; int m = val->pair->attempt + 1;
bool can_reconn = ( bool can_reconn = (
val->pair->buff.data && !val->recv_count val->pair->buff.locked && !val->recv_count
); );
if (!can_reconn && params.auto_level <= AUTO_NOSAVE) { if (!can_reconn && params.auto_level <= AUTO_NOSAVE) {
return -1; return -1;
@ -346,12 +346,13 @@ ssize_t on_first_send(struct eval *client, char *buffer, ssize_t n, ssize_t bfsi
struct desync_params *dp = &params.dp[m]; struct desync_params *dp = &params.dp[m];
if (!dp->detect && if (!dp->detect &&
(!dp->pf[0] || check_port(dp->pf, &client->pair->in6)) && (!dp->pf[0] || check_port(dp->pf, &client->pair->in6)) &&
(!dp->proto || check_proto_tcp(dp->proto, client)) && (!dp->proto || check_proto_tcp(dp->proto, buffer, n)) &&
(!dp->hosts || check_host(dp->hosts, client))) { (!dp->hosts || check_host(dp->hosts, buffer, n))) {
break; break;
} }
} }
if (m >= params.dp_count) { if (m >= params.dp_count) {
LOG(LOG_E, "drop connection (m=%d)\n", m);
return -1; return -1;
} }
if (params.auto_level > AUTO_NOSAVE && params.dp_count > 1) { if (params.auto_level > AUTO_NOSAVE && params.dp_count > 1) {
@ -386,7 +387,6 @@ ssize_t tcp_send_hook(struct poolhd *pool, struct eval *remote,
return sn; return sn;
} }
struct eval *client = remote->pair; struct eval *client = remote->pair;
int m = client->attempt;
if (client->recv_count == n) { if (client->recv_count == n) {
n = on_first_send(client, buffer, n, bfsize); n = on_first_send(client, buffer, n, bfsize);
@ -394,6 +394,7 @@ ssize_t tcp_send_hook(struct poolhd *pool, struct eval *remote,
return -1; return -1;
} }
} }
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);
sn = desync(remote->fd, buffer, bfsize, n, sn = desync(remote->fd, buffer, bfsize, n,