mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 14:25:44 +00:00
Merge pull request #47 from dartvader316/fix-headers
Fix headers and format
This commit is contained in:
commit
99e2d9b648
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
.vscode
|
.vscode
|
||||||
ciadpi.exe
|
ciadpi.exe
|
||||||
|
ciadpi
|
||||||
|
*.o
|
||||||
|
compile_flags.txt
|
||||||
|
2
conev.c
2
conev.c
@ -1,4 +1,4 @@
|
|||||||
#define CONEV_H
|
|
||||||
#include "conev.h"
|
#include "conev.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
6
conev.h
6
conev.h
@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#ifndef CONEV_H
|
||||||
|
#define CONEV_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef __linux__
|
#ifndef __linux__
|
||||||
@ -107,3 +109,5 @@ void destroy_pool(struct poolhd *pool);
|
|||||||
struct eval *next_event(struct poolhd *pool, int *offs, int *type);
|
struct eval *next_event(struct poolhd *pool, int *offs, int *type);
|
||||||
|
|
||||||
int mod_etype(struct poolhd *pool, struct eval *val, int type);
|
int mod_etype(struct poolhd *pool, struct eval *val, int type);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
19
desync.c
19
desync.c
@ -1,5 +1,7 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
|
#include "desync.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -16,7 +18,6 @@
|
|||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include <desync.h>
|
|
||||||
|
|
||||||
#ifdef MFD_CLOEXEC
|
#ifdef MFD_CLOEXEC
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
@ -391,12 +392,12 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
|||||||
type = IS_HTTP;
|
type = IS_HTTP;
|
||||||
}
|
}
|
||||||
if (len && host) {
|
if (len && host) {
|
||||||
LOG(LOG_S, "host: %.*s (%ld)\n",
|
LOG(LOG_S, "host: %.*s (%zd)\n",
|
||||||
len, host, host - buffer);
|
len, host, 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=%ld\n", n);
|
LOG(LOG_S, "modify HTTP: n=%zd\n", n);
|
||||||
if (mod_http(buffer, n, dp.mod_http)) {
|
if (mod_http(buffer, n, dp.mod_http)) {
|
||||||
LOG(LOG_E, "mod http error\n");
|
LOG(LOG_E, "mod http error\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -420,10 +421,10 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
|||||||
}
|
}
|
||||||
if (!part_tls(buffer + lp,
|
if (!part_tls(buffer + lp,
|
||||||
bfsize - lp, n - lp, pos - 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;
|
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;
|
n += 5;
|
||||||
lp = pos + 5;
|
lp = pos + 5;
|
||||||
}
|
}
|
||||||
@ -462,7 +463,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (pos <= 0 || pos >= n || pos <= lp) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
// send part
|
// send part
|
||||||
@ -494,7 +495,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
|||||||
default:
|
default:
|
||||||
return -1;
|
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 (s < 0) {
|
||||||
if (get_e() == EAGAIN) {
|
if (get_e() == EAGAIN) {
|
||||||
@ -503,14 +504,14 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (s != (pos - lp)) {
|
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;
|
return lp + s;
|
||||||
}
|
}
|
||||||
lp = pos;
|
lp = pos;
|
||||||
}
|
}
|
||||||
// send all/rest
|
// send all/rest
|
||||||
if (lp < n) {
|
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 (send(sfd, buffer + lp, n - lp, 0) < 0) {
|
||||||
if (get_e() == EAGAIN) {
|
if (get_e() == EAGAIN) {
|
||||||
return lp;
|
return lp;
|
||||||
|
14
desync.h
14
desync.h
@ -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(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);
|
ssize_t desync_udp(int sfd, char *buffer, size_t bfsize, ssize_t n, struct sockaddr *dst, int dp_c);
|
||||||
@ -10,3 +22,5 @@ struct tcpi {
|
|||||||
uint32_t rrr[29];
|
uint32_t rrr[29];
|
||||||
uint32_t notsent_bytes;
|
uint32_t notsent_bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
7
error.h
7
error.h
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef CIADPI_ERROR_H
|
||||||
|
#define CIADPI_ERROR_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
@ -18,7 +21,7 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define uniperror(str) \
|
#define uniperror(str) \
|
||||||
fprintf(stderr, "%s: %d\n", str, GetLastError())
|
fprintf(stderr, "%s: %ld\n", str, GetLastError())
|
||||||
#else
|
#else
|
||||||
#ifdef ANDROID_APP
|
#ifdef ANDROID_APP
|
||||||
#define uniperror(str) \
|
#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)); \
|
inet_ntop(AF_INET, &dst.in.sin_addr, ADDR_STR, sizeof(ADDR_STR)); \
|
||||||
else \
|
else \
|
||||||
inet_ntop(AF_INET6, &dst.in6.sin6_addr, ADDR_STR, sizeof(ADDR_STR));
|
inet_ntop(AF_INET6, &dst.in6.sin6_addr, ADDR_STR, sizeof(ADDR_STR));
|
||||||
|
|
||||||
|
#endif
|
||||||
|
3
extend.c
3
extend.c
@ -1,3 +1,6 @@
|
|||||||
|
|
||||||
|
#include "extend.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
|
10
extend.h
10
extend.h
@ -1,3 +1,11 @@
|
|||||||
|
#ifndef EXTEND_H
|
||||||
|
#define EXTEND_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "conev.h"
|
||||||
|
#include "proxy.h"
|
||||||
|
|
||||||
int connect_hook(struct poolhd *pool, struct eval *val,
|
int connect_hook(struct poolhd *pool, struct eval *val,
|
||||||
struct sockaddr_ina *dst, int next);
|
struct sockaddr_ina *dst, int next);
|
||||||
|
|
||||||
@ -15,3 +23,5 @@ int protect(int conn_fd, const char *path);
|
|||||||
#else
|
#else
|
||||||
#define protect(fd, path) 0
|
#define protect(fd, path) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
4
mpool.c
4
mpool.c
@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
|
#include "mpool.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "mpool.h"
|
|
||||||
|
|
||||||
|
|
||||||
static inline int scmp(const struct elem *p, const struct elem *q)
|
static inline int scmp(const struct elem *p, const struct elem *q)
|
||||||
|
5
mpool.h
5
mpool.h
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef MPOOL_H
|
||||||
|
#define MPOOL_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "kavl.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_delete(struct mphdr *hdr, char *str, int len);
|
||||||
|
|
||||||
void mem_destroy(struct mphdr *hdr);
|
void mem_destroy(struct mphdr *hdr);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <packets.h>
|
#include "packets.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef PACKETS_H
|
||||||
|
#define PACKETS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.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_dns_req(char *buffer, size_t n);
|
||||||
|
|
||||||
//bool is_quic_initial(char *buffer, size_t bsize);
|
//bool is_quic_initial(char *buffer, size_t bsize);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
5
params.h
5
params.h
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef PARAMS_H
|
||||||
|
#define PARAMS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -108,3 +111,5 @@ extern struct packet oob_data;
|
|||||||
extern struct packet fake_udp;
|
extern struct packet fake_udp;
|
||||||
|
|
||||||
extern char ip_option[1];
|
extern char ip_option[1];
|
||||||
|
|
||||||
|
#endif
|
||||||
|
12
proxy.c
12
proxy.c
@ -1,6 +1,8 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#define EID_STR
|
#define EID_STR
|
||||||
|
|
||||||
|
#include "proxy.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -8,7 +10,6 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "proxy.h"
|
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
#include "conev.h"
|
#include "conev.h"
|
||||||
#include "extend.h"
|
#include "extend.h"
|
||||||
@ -57,7 +58,8 @@ void map_fix(struct sockaddr_ina *addr, char f6)
|
|||||||
else if (!ipv6m->o64 && !ipv6m->o16 &&
|
else if (!ipv6m->o64 && !ipv6m->o16 &&
|
||||||
ipv6m->t16 == 0xffff && !f6) {
|
ipv6m->t16 == 0xffff && !f6) {
|
||||||
addr->sa.sa_family = AF_INET;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,7 +619,7 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
|
|||||||
}
|
}
|
||||||
sn = 0;
|
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));
|
assert(!(val->buff.size || val->buff.offset));
|
||||||
|
|
||||||
val->buff.size = n - sn;
|
val->buff.size = n - sn;
|
||||||
@ -738,7 +740,7 @@ static inline int on_request(struct poolhd *pool, struct eval *val,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (n < S_SIZE_MIN) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
struct s5_req *r = (struct s5_req *)buffer;
|
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);
|
error = connect_hook(pool, val, &dst, EV_CONNECT);
|
||||||
}
|
}
|
||||||
else {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
if (error) {
|
if (error) {
|
||||||
|
5
proxy.h
5
proxy.h
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef PROXY_H
|
||||||
|
#define PROXY_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -111,3 +114,5 @@ int listen_socket(struct sockaddr_ina *srv);
|
|||||||
int event_loop(int srvfd);
|
int event_loop(int srvfd);
|
||||||
|
|
||||||
int run(struct sockaddr_ina *srv);
|
int run(struct sockaddr_ina *srv);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
#include "win_service.h"
|
#include "win_service.h"
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#define SERVICE_NAME "ByeDPI"
|
#define SERVICE_NAME "ByeDPI"
|
||||||
|
@ -1 +1,7 @@
|
|||||||
|
#ifndef WIN_SERVICE_H
|
||||||
|
#define WIN_SERVICE_H
|
||||||
|
|
||||||
int register_winsvc(int argc, char *argv[]);
|
int register_winsvc(int argc, char *argv[]);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user