mirror of
https://github.com/hufrea/byedpi.git
synced 2025-07-02 19:43:07 +00:00
Merge branch 'main' into rawtcp
This commit is contained in:
commit
6854935f6b
6
conev.c
6
conev.c
@ -153,9 +153,6 @@ struct eval *next_event(struct poolhd *pool, int *offs, int *type)
|
|||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (pool->iters == UINT_MAX) {
|
|
||||||
pool->iters = 0;
|
|
||||||
}
|
|
||||||
pool->iters++;
|
pool->iters++;
|
||||||
}
|
}
|
||||||
struct eval *val = pool->pevents[i].data.ptr;
|
struct eval *val = pool->pevents[i].data.ptr;
|
||||||
@ -188,9 +185,6 @@ struct eval *next_event(struct poolhd *pool, int *offs, int *typel)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
i = pool->count - 1;
|
i = pool->count - 1;
|
||||||
if (pool->iters == UINT_MAX) {
|
|
||||||
pool->iters = 0;
|
|
||||||
}
|
|
||||||
pool->iters++;
|
pool->iters++;
|
||||||
}
|
}
|
||||||
short type = pool->pevents[i].revents;
|
short type = pool->pevents[i].revents;
|
||||||
|
4
conev.h
4
conev.h
@ -68,7 +68,7 @@ struct buffer {
|
|||||||
struct eval {
|
struct eval {
|
||||||
int fd;
|
int fd;
|
||||||
int index;
|
int index;
|
||||||
unsigned int mod_iter;
|
unsigned long long mod_iter;
|
||||||
enum eid type;
|
enum eid type;
|
||||||
struct eval *pair;
|
struct eval *pair;
|
||||||
struct buffer buff;
|
struct buffer buff;
|
||||||
@ -93,7 +93,7 @@ struct poolhd {
|
|||||||
#else
|
#else
|
||||||
struct pollfd *pevents;
|
struct pollfd *pevents;
|
||||||
#endif
|
#endif
|
||||||
unsigned int iters;
|
unsigned long long iters;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct poolhd *init_pool(int count);
|
struct poolhd *init_pool(int count);
|
||||||
|
43
desync.c
43
desync.c
@ -1,3 +1,5 @@
|
|||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include "desync.h"
|
#include "desync.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -16,11 +18,7 @@
|
|||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#else
|
#else
|
||||||
#include <linux/tcp.h>
|
#include <linux/tcp.h>
|
||||||
#include <sys/sendfile.h>
|
|
||||||
#include <linux/filter.h>
|
#include <linux/filter.h>
|
||||||
#include <sys/syscall.h>
|
|
||||||
|
|
||||||
#define memfd_create(name, flags) syscall(__NR_memfd_create, name, flags)
|
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
@ -143,14 +141,12 @@ void wait_send(int sfd)
|
|||||||
#define wait_send_if_support(sfd) // :(
|
#define wait_send_if_support(sfd) // :(
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FAKE_SUPPORT
|
#ifdef __linux__
|
||||||
#ifndef _WIN32
|
|
||||||
ssize_t send_fake(int sfd, char *buffer,
|
ssize_t send_fake(int sfd, char *buffer,
|
||||||
int cnt, long pos, int fa, struct desync_params *opt)
|
int cnt, long pos, int fa, struct desync_params *opt)
|
||||||
{
|
{
|
||||||
struct sockaddr_in6 addr = {};
|
struct sockaddr_in6 addr = {};
|
||||||
socklen_t addr_size = sizeof(addr);
|
socklen_t addr_size = sizeof(addr);
|
||||||
#ifdef __linux__
|
|
||||||
if (opt->md5sig) {
|
if (opt->md5sig) {
|
||||||
if (getpeername(sfd,
|
if (getpeername(sfd,
|
||||||
(struct sockaddr *)&addr, &addr_size) < 0) {
|
(struct sockaddr *)&addr, &addr_size) < 0) {
|
||||||
@ -158,7 +154,6 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
struct packet pkt;
|
struct packet pkt;
|
||||||
if (opt->fake_data.data) {
|
if (opt->fake_data.data) {
|
||||||
pkt = opt->fake_data;
|
pkt = opt->fake_data;
|
||||||
@ -173,21 +168,16 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
}
|
}
|
||||||
else pkt.size = 0;
|
else pkt.size = 0;
|
||||||
}
|
}
|
||||||
|
int fds[2];
|
||||||
int ffd = memfd_create("name", 0);
|
if (pipe(fds) < 0) {
|
||||||
if (ffd < 0) {
|
uniperror("pipe");
|
||||||
uniperror("memfd_create");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char *p = 0;
|
char *p = 0;
|
||||||
ssize_t len = -1;
|
ssize_t len = -1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (ftruncate(ffd, pos) < 0) {
|
p = mmap(0, pos, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
|
||||||
uniperror("ftruncate");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
p = mmap(0, pos, PROT_WRITE, MAP_SHARED, ffd, 0);
|
|
||||||
if (p == MAP_FAILED) {
|
if (p == MAP_FAILED) {
|
||||||
uniperror("mmap");
|
uniperror("mmap");
|
||||||
p = 0;
|
p = 0;
|
||||||
@ -198,8 +188,6 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
if (setttl(sfd, opt->ttl ? opt->ttl : 8, fa) < 0) {
|
if (setttl(sfd, opt->ttl ? opt->ttl : 8, fa) < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
if (opt->md5sig) {
|
if (opt->md5sig) {
|
||||||
struct tcp_md5sig md5 = {
|
struct tcp_md5sig md5 = {
|
||||||
.tcpm_keylen = 5
|
.tcpm_keylen = 5
|
||||||
@ -212,17 +200,22 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (opt->ip_options && fa == AF_INET
|
if (opt->ip_options && fa == AF_INET
|
||||||
&& setsockopt(sfd, IPPROTO_IP, IP_OPTIONS,
|
&& setsockopt(sfd, IPPROTO_IP, IP_OPTIONS,
|
||||||
opt->ip_options, opt->ip_options_len) < 0) {
|
opt->ip_options, opt->ip_options_len) < 0) {
|
||||||
uniperror("setsockopt IP_OPTIONS");
|
uniperror("setsockopt IP_OPTIONS");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
struct iovec vec = { .iov_base = p, .iov_len = pos };
|
||||||
|
|
||||||
len = sendfile(sfd, ffd, 0, pos);
|
len = vmsplice(fds[1], &vec, 1, SPLICE_F_GIFT);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
uniperror("sendfile");
|
uniperror("vmsplice");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len = splice(fds[0], 0, sfd, 0, len, 0);
|
||||||
|
if (len < 0) {
|
||||||
|
uniperror("splice");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wait_send(sfd);
|
wait_send(sfd);
|
||||||
@ -237,7 +230,6 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
uniperror("setsockopt IP_OPTIONS");
|
uniperror("setsockopt IP_OPTIONS");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef __linux__
|
|
||||||
if (opt->md5sig) {
|
if (opt->md5sig) {
|
||||||
struct tcp_md5sig md5 = {
|
struct tcp_md5sig md5 = {
|
||||||
.tcpm_keylen = 0
|
.tcpm_keylen = 0
|
||||||
@ -250,11 +242,11 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (p) munmap(p, pos);
|
if (p) munmap(p, pos);
|
||||||
close(ffd);
|
close(fds[0]);
|
||||||
|
close(fds[1]);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -359,7 +351,6 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
ssize_t send_oob(int sfd, char *buffer,
|
ssize_t send_oob(int sfd, char *buffer,
|
||||||
ssize_t n, long pos, char *c)
|
ssize_t n, long pos, char *c)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ANTOHS(data, i) \
|
#define ANTOHS(data, i) \
|
||||||
(uint16_t)((data[i] << 8) + (uint8_t)data[i + 1])
|
(((uint16_t)data[i] << 8) + (uint8_t)data[i + 1])
|
||||||
|
|
||||||
#define SHTONA(data, i, x) \
|
#define SHTONA(data, i, x) \
|
||||||
data[i] = (uint8_t)((x) >> 8); \
|
data[i] = (uint8_t)((x) >> 8); \
|
||||||
|
5
proxy.c
5
proxy.c
@ -497,7 +497,7 @@ int udp_associate(struct poolhd *pool,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
struct eval *client = add_event(pool, EV_UDP_TUNNEL, cfd, POLLIN);
|
struct eval *client = add_event(pool, EV_UDP_TUNNEL, cfd, POLLIN);
|
||||||
if (!pair) {
|
if (!client) {
|
||||||
del_event(pool, pair);
|
del_event(pool, pair);
|
||||||
close(cfd);
|
close(cfd);
|
||||||
return -1;
|
return -1;
|
||||||
@ -929,8 +929,7 @@ int event_loop(int srvfd)
|
|||||||
}
|
}
|
||||||
assert(val->type >= 0
|
assert(val->type >= 0
|
||||||
&& val->type < sizeof(eid_name)/sizeof(*eid_name));
|
&& val->type < sizeof(eid_name)/sizeof(*eid_name));
|
||||||
LOG(LOG_L, "new event: fd: %d, evt: %s, mod_iter: %d\n",
|
LOG(LOG_L, "new event: fd: %d, evt: %s, mod_iter: %llu\n", val->fd, eid_name[val->type], val->mod_iter);
|
||||||
val->fd, eid_name[val->type], val->mod_iter);
|
|
||||||
|
|
||||||
switch (val->type) {
|
switch (val->type) {
|
||||||
case EV_ACCEPT:
|
case EV_ACCEPT:
|
||||||
|
Loading…
Reference in New Issue
Block a user