drop-sack

This commit is contained in:
ruti 2024-08-09 22:49:44 +03:00
parent 2f98038991
commit 550f2d2f5f
5 changed files with 66 additions and 2 deletions

View File

@ -15,8 +15,9 @@
#ifndef __linux__
#include <netinet/tcp.h>
#else
#include <sys/sendfile.h>
#include <linux/tcp.h>
#include <sys/sendfile.h>
#include <linux/filter.h>
#include <sys/syscall.h>
#define memfd_create(name, flags) syscall(__NR_memfd_create, name, flags)
@ -67,6 +68,32 @@ int setttl(int fd, int ttl, int family) {
return 0;
}
#ifdef __linux__
int drop_sack(int fd)
{
struct sock_filter code[] = {
{ 0x30, 0, 0, 0x0000000c },
{ 0x74, 0, 0, 0x00000004 },
{ 0x35, 0, 3, 0x0000000b },
{ 0x30, 0, 0, 0x00000022 },
{ 0x15, 0, 1, 0x00000005 },
{ 0x6, 0, 0, 0x00000000 },
{ 0x6, 0, 0, 0x00040000 },
};
struct sock_fprog bpf = {
.len = sizeof(code)/sizeof(*code),
.filter = code
};
if (setsockopt(fd, SOL_SOCKET,
SO_ATTACH_FILTER, (char *)&bpf, sizeof(bpf)) == -1) {
uniperror("setsockopt SO_ATTACH_FILTER");
return -1;
}
return 0;
}
#endif
#ifndef _WIN32
static inline void delay(long ms)
{
@ -471,6 +498,11 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
}
}
// desync
#ifdef __linux__
if (dp.drop_sack && drop_sack(sfd)) {
return -1;
}
#endif
long lp = offset;
for (int i = 0; i < dp.parts_n; i++) {
@ -565,6 +597,23 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
}
int post_desync(int sfd, int dp_c)
{
struct desync_params *dp = &params.dp[dp_c];
#ifdef __linux__
if (dp->drop_sack) {
if (setsockopt(sfd, SOL_SOCKET,
SO_DETACH_FILTER, &dp_c, sizeof(dp_c)) == -1) {
uniperror("setsockopt SO_DETACH_FILTER");
return -1;
}
}
#endif
return 0;
}
ssize_t desync_udp(int sfd, char *buffer, size_t bfsize,
ssize_t n, struct sockaddr *dst, int dp_c)
{

View File

@ -18,4 +18,6 @@ int get_family(struct sockaddr *dst);
int setttl(int fd, int ttl, int family);
int post_desync(int sfd, int dp_c);
#endif

View File

@ -285,6 +285,10 @@ int on_tunnel_check(struct poolhd *pool, struct eval *val,
}
int m = pair->attempt;
if (post_desync(val->fd, m)) {
return -1;
}
if (!pair->cache) {
return 0;
}

8
main.c
View File

@ -106,6 +106,9 @@ const char help_text[] = {
" -M, --mod-http <h,d,r> Modify HTTP: hcsmix,dcsmix,rmspace\n"
" -r, --tlsrec <n[+s]> Make TLS record at position\n"
" -a, --udp-fake <count> UDP fakes count, default 0\n"
#ifdef __linux__
" -Y, --drop-sack Drop packets with SACK extension\n"
#endif
};
@ -156,6 +159,7 @@ const struct option options[] = {
{"delay", 1, 0, 'w'}, //
{"not-wait-send", 0, 0, 'W'}, //
#ifdef __linux__
{"drop-sack", 0, 0, 'Y'},
{"protect-path", 1, 0, 'P'}, //
#endif
{0}
@ -802,6 +806,10 @@ int main(int argc, char **argv)
}
break;
case 'Y':
dp->drop_sack = 1;
break;
case 'w': //
params.sfdelay = strtol(optarg, &end, 0);
if (params.sfdelay < 0 || optarg == end

View File

@ -67,6 +67,7 @@ struct desync_params {
struct packet fake_data;
int udp_fake_count;
int fake_offset;
char drop_sack;
int parts_n;
struct part *parts;