0
0
mirror of https://github.com/hufrea/byedpi.git synced 2025-07-01 02:53:03 +00:00

Merge branch 'main' into cmake

This commit is contained in:
Nikolay Raspopov 2024-08-13 18:09:45 +03:00 committed by GitHub
commit 70f4def660
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 108 additions and 38 deletions

5
.gitignore vendored
View File

@ -1,4 +1,7 @@
.vscode
ciadpi.exe
ciadpi
*.o
compile_flags.txt
build
*.user
*.user

View File

@ -1,6 +1,6 @@
TARGET = ciadpi
CPPFLAGS = -D_XOPEN_SOURCE=500
#CPPFLAGS = -D_XOPEN_SOURCE=500
CFLAGS += -I. -std=c99 -Wall -Wno-unused -O2
WIN_LDFLAGS = -lws2_32 -lmswsock

View File

@ -1,4 +1,3 @@
#define CONEV_H
#include "conev.h"
#include <stdlib.h>

View File

@ -1,4 +1,6 @@
#pragma once
#ifndef CONEV_H
#define CONEV_H
#include <stdint.h>
#ifndef __linux__
@ -107,3 +109,5 @@ void destroy_pool(struct poolhd *pool);
struct eval *next_event(struct poolhd *pool, int *offs, int *type);
int mod_etype(struct poolhd *pool, struct eval *val, int type);
#endif

View File

@ -1,5 +1,7 @@
#define _GNU_SOURCE
#include "desync.h"
#include <stdio.h>
#include <string.h>
@ -16,7 +18,6 @@
#include <sys/sendfile.h>
#include <fcntl.h>
#include <desync.h>
#ifdef MFD_CLOEXEC
#include <sys/syscall.h>
@ -391,12 +392,12 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
type = IS_HTTP;
}
if (len && host) {
LOG(LOG_S, "host: %.*s (%ld)\n",
LOG(LOG_S, "host: %.*s (%zd)\n",
len, host, host - buffer);
}
// modify packet
if (type == IS_HTTP && dp.mod_http) {
LOG(LOG_S, "modify HTTP: n=%ld\n", n);
LOG(LOG_S, "modify HTTP: n=%zd\n", n);
if (mod_http(buffer, n, dp.mod_http)) {
LOG(LOG_E, "mod http error\n");
return -1;
@ -420,10 +421,10 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
}
if (!part_tls(buffer + lp,
bfsize - lp, n - lp, pos - lp)) {
LOG(LOG_E, "tlsrec error: pos=%ld, n=%ld\n", pos, n);
LOG(LOG_E, "tlsrec error: pos=%ld, n=%zd\n", pos, n);
break;
}
LOG(LOG_S, "tlsrec: pos=%ld, n=%ld\n", pos, n);
LOG(LOG_S, "tlsrec: pos=%ld, n=%zd\n", pos, n);
n += 5;
lp = pos + 5;
}
@ -462,7 +463,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
continue;
}
else if (pos <= 0 || pos >= n || pos <= lp) {
LOG(LOG_E, "split cancel: pos=%ld-%ld, n=%ld\n", lp, pos, n);
LOG(LOG_E, "split cancel: pos=%ld-%ld, n=%zd\n", lp, pos, n);
break;
}
// send part
@ -494,7 +495,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
default:
return -1;
}
LOG(LOG_S, "split: pos=%ld-%ld (%ld), m: %s\n", lp, pos, s, demode_str[part.m]);
LOG(LOG_S, "split: pos=%ld-%ld (%zd), m: %s\n", lp, pos, s, demode_str[part.m]);
if (s < 0) {
if (get_e() == EAGAIN) {
@ -503,14 +504,14 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
return -1;
}
else if (s != (pos - lp)) {
LOG(LOG_E, "%ld != %ld\n", s, pos - lp);
LOG(LOG_E, "%zd != %ld\n", s, pos - lp);
return lp + s;
}
lp = pos;
}
// send all/rest
if (lp < n) {
LOG((lp ? LOG_S : LOG_L), "send: pos=%ld-%ld\n", lp, n);
LOG((lp ? LOG_S : LOG_L), "send: pos=%ld-%zd\n", lp, n);
if (send(sfd, buffer + lp, n - lp, 0) < 0) {
if (get_e() == EAGAIN) {
return lp;

View File

@ -1,3 +1,15 @@
#ifndef DESYNC_H
#define DESYNC_H
#include <stdint.h>
#include <stddef.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#endif
ssize_t desync(int sfd, char *buffer, size_t bfsize, ssize_t n, ssize_t offset, struct sockaddr *dst, int dp_c);
ssize_t desync_udp(int sfd, char *buffer, size_t bfsize, ssize_t n, struct sockaddr *dst, int dp_c);
@ -9,4 +21,6 @@ struct tcpi {
uint32_t unacked;
uint32_t rrr[29];
uint32_t notsent_bytes;
};
};
#endif

View File

@ -1,3 +1,6 @@
#ifndef CIADPI_ERROR_H
#define CIADPI_ERROR_H
#include <stdio.h>
#include <errno.h>
@ -18,7 +21,7 @@
#ifdef _WIN32
#define uniperror(str) \
fprintf(stderr, "%s: %d\n", str, GetLastError())
fprintf(stderr, "%s: %ld\n", str, GetLastError())
#else
#ifdef ANDROID_APP
#define uniperror(str) \
@ -72,3 +75,5 @@ static inline const int unie(int e)
inet_ntop(AF_INET, &dst.in.sin_addr, ADDR_STR, sizeof(ADDR_STR)); \
else \
inet_ntop(AF_INET6, &dst.in6.sin6_addr, ADDR_STR, sizeof(ADDR_STR));
#endif

View File

@ -1,3 +1,5 @@
#include "extend.h"
#ifdef _WIN32
#include <ws2tcpip.h>

View File

@ -1,3 +1,10 @@
#ifndef EXTEND_H
#define EXTEND_H
#include <stddef.h>
#include "proxy.h"
int connect_hook(struct poolhd *pool, struct eval *val,
struct sockaddr_ina *dst, int next);
@ -14,4 +21,6 @@ ssize_t udp_hook(struct eval *val,
int protect(int conn_fd, const char *path);
#else
#define protect(fd, path) 0
#endif
#endif
#endif

5
main.c
View File

@ -16,8 +16,9 @@
#include <unistd.h>
#include <netdb.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/mman.h>
#include <sys/socket.h>
#else
#include <ws2tcpip.h>
#include "win_service.h"
@ -441,7 +442,7 @@ int main(int argc, char **argv)
return -1;
}
while (!invalid && (rez = getopt_long_only(
while (!invalid && (rez = getopt_long(
argc, argv, opt, options, 0)) != -1) {
switch (rez) {

View File

@ -1,8 +1,8 @@
#include "mpool.h"
#include <stdlib.h>
#include <string.h>
#include "mpool.h"
static inline int scmp(const struct elem *p, const struct elem *q)
{

View File

@ -1,3 +1,6 @@
#ifndef MPOOL_H
#define MPOOL_H
#include <stdbool.h>
#include <time.h>
#include "kavl.h"
@ -24,3 +27,5 @@ struct elem *mem_add(struct mphdr *hdr, char *str, int len);
void mem_delete(struct mphdr *hdr, char *str, int len);
void mem_destroy(struct mphdr *hdr);
#endif

View File

@ -1,12 +1,12 @@
#define _GNU_SOURCE
#include "packets.h"
#include <packets.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#ifdef _WIN32
#include <winsock2.h>

View File

@ -1,3 +1,6 @@
#ifndef PACKETS_H
#define PACKETS_H
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
@ -43,3 +46,6 @@ int part_tls(char *buffer, size_t bsize, ssize_t n, long pos);
//bool is_dns_req(char *buffer, size_t n);
//bool is_quic_initial(char *buffer, size_t bsize);
#endif

View File

@ -1,3 +1,6 @@
#ifndef PARAMS_H
#define PARAMS_H
#include <stdint.h>
#include <stdio.h>
@ -7,6 +10,9 @@
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/socket.h>
#endif
#if defined(__linux__) || defined(_WIN32)
@ -107,4 +113,6 @@ extern struct packet fake_http;
extern struct packet oob_data;
extern struct packet fake_udp;
extern char ip_option[1];
extern char ip_option[1];
#endif

28
proxy.c
View File

@ -1,6 +1,8 @@
#define _GNU_SOURCE
#define EID_STR
#include "proxy.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@ -8,7 +10,6 @@
#include <signal.h>
#include <assert.h>
#include "proxy.h"
#include "params.h"
#include "conev.h"
#include "extend.h"
@ -57,7 +58,8 @@ void map_fix(struct sockaddr_ina *addr, char f6)
else if (!ipv6m->o64 && !ipv6m->o16 &&
ipv6m->t16 == 0xffff && !f6) {
addr->sa.sa_family = AF_INET;
addr->in.sin_addr = *(struct in_addr *)(&ipv6m->o32);
const struct in_addr *sin_addr_ptr = (struct in_addr *) &ipv6m->o32;
addr->in.sin_addr = *sin_addr_ptr;
}
}
@ -344,7 +346,7 @@ int create_conn(struct poolhd *pool,
}
}
if (bind(sfd, (struct sockaddr *)&params.baddr,
sizeof(params.baddr)) < 0) {
SA_SIZE(&params.baddr)) < 0) {
uniperror("bind");
close(sfd);
return -1;
@ -374,7 +376,7 @@ int create_conn(struct poolhd *pool,
close(sfd);
return -1;
}
int status = connect(sfd, &addr.sa, sizeof(addr));
int status = connect(sfd, &addr.sa, SA_SIZE(&addr));
if (status == 0 && params.tfo) {
LOG(LOG_S, "TFO supported!\n");
}
@ -430,7 +432,7 @@ int udp_associate(struct poolhd *pool,
map_fix(&addr, 6);
}
if (bind(ufd, (struct sockaddr *)&params.baddr,
sizeof(params.baddr)) < 0) {
SA_SIZE(&params.baddr)) < 0) {
uniperror("bind");
close(ufd);
return -1;
@ -441,7 +443,7 @@ int udp_associate(struct poolhd *pool,
return -1;
}
if (dst->in6.sin6_port != 0) {
if (connect(ufd, &addr.sa, sizeof(addr)) < 0) {
if (connect(ufd, &addr.sa, SA_SIZE(&addr)) < 0) {
uniperror("connect");
del_event(pool, pair);
return -1;
@ -463,7 +465,7 @@ int udp_associate(struct poolhd *pool,
del_event(pool, pair);
return -1;
}
if (bind(cfd, &addr.sa, sizeof(addr)) < 0) {
if (bind(cfd, &addr.sa, SA_SIZE(&addr)) < 0) {
uniperror("bind");
del_event(pool, pair);
close(cfd);
@ -617,7 +619,7 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
}
sn = 0;
}
LOG(LOG_S, "send: %ld != %ld (fd: %d)\n", sn, n, pair->fd);
LOG(LOG_S, "send: %zd != %zd (fd: %d)\n", sn, n, pair->fd);
assert(!(val->buff.size || val->buff.offset));
val->buff.size = n - sn;
@ -668,7 +670,7 @@ int on_udp_tunnel(struct eval *val, char *buffer, size_t bfsize)
if (!addr_equ(&addr, (struct sockaddr_ina *)&val->in6)) {
return 0;
}
if (connect(val->fd, &addr.sa, sizeof(addr)) < 0) {
if (connect(val->fd, &addr.sa, SA_SIZE(&addr)) < 0) {
uniperror("connect");
return -1;
}
@ -689,7 +691,7 @@ int on_udp_tunnel(struct eval *val, char *buffer, size_t bfsize)
if (params.baddr.sin6_family != addr.sa.sa_family) {
return -1;
}
if (connect(val->pair->fd, &addr.sa, sizeof(addr)) < 0) {
if (connect(val->pair->fd, &addr.sa, SA_SIZE(&addr)) < 0) {
uniperror("connect");
return -1;
}
@ -738,7 +740,7 @@ static inline int on_request(struct poolhd *pool, struct eval *val,
return 0;
}
if (n < S_SIZE_MIN) {
LOG(LOG_E, "ss: request to small (%ld)\n", n);
LOG(LOG_E, "ss: request to small (%zd)\n", n);
return -1;
}
struct s5_req *r = (struct s5_req *)buffer;
@ -780,7 +782,7 @@ static inline int on_request(struct poolhd *pool, struct eval *val,
error = connect_hook(pool, val, &dst, EV_CONNECT);
}
else {
LOG(LOG_E, "ss: invalid version: 0x%x (%lu)\n", *buffer, n);
LOG(LOG_E, "ss: invalid version: 0x%x (%zd)\n", *buffer, n);
return -1;
}
if (error) {
@ -938,7 +940,7 @@ int listen_socket(struct sockaddr_ina *srv)
close(srvfd);
return -1;
}
if (bind(srvfd, &srv->sa, sizeof(*srv)) < 0) {
if (bind(srvfd, &srv->sa, SA_SIZE(srv)) < 0) {
uniperror("bind");
close(srvfd);
return -1;

10
proxy.h
View File

@ -1,13 +1,21 @@
#ifndef PROXY_H
#define PROXY_H
#include <stdint.h>
#ifdef _WIN32
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <sys/socket.h>
#endif
#include "conev.h"
#define SA_SIZE(s) \
(((struct sockaddr *)s)->sa_family == AF_INET6) ? \
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)
struct sockaddr_ina {
union {
struct sockaddr sa;
@ -111,3 +119,5 @@ int listen_socket(struct sockaddr_ina *srv);
int event_loop(int srvfd);
int run(struct sockaddr_ina *srv);
#endif

View File

@ -1,4 +1,5 @@
#include "win_service.h"
#include <windows.h>
#define SERVICE_NAME "ByeDPI"
@ -76,4 +77,4 @@ int register_winsvc(int argc, char *argv[])
svc_argv = argv;
return StartServiceCtrlDispatcher(ServiceTable);
}
}

View File

@ -1 +1 @@
int register_winsvc(int argc, char *argv[]);
int register_winsvc(int argc, char *argv[]);