mirror of
https://github.com/hufrea/byedpi.git
synced 2025-01-04 13:24:18 +00:00
FreeBSD support
This commit is contained in:
parent
99e2d9b648
commit
5529d0ae25
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
|||||||
TARGET = ciadpi
|
TARGET = ciadpi
|
||||||
|
|
||||||
CPPFLAGS = -D_XOPEN_SOURCE=500
|
CPPFLAGS = -D_XOPEN_SOURCE=600 -D__BSD_VISIBLE=1
|
||||||
CFLAGS += -I. -std=c99 -Wall -Wno-unused -O2
|
CFLAGS += -I. -std=c99 -Wall -Wno-unused -O2
|
||||||
WIN_LDFLAGS = -lws2_32 -lmswsock
|
WIN_LDFLAGS = -lws2_32 -lmswsock
|
||||||
|
|
||||||
|
32
desync.c
32
desync.c
@ -13,12 +13,13 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#ifdef __linux__
|
||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
|
#endif
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
#ifdef MFD_CLOEXEC
|
#ifdef MFD_CLOEXEC
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#define memfd_create(name, flags) syscall(__NR_memfd_create, name, flags);
|
#define memfd_create(name, flags) syscall(__NR_memfd_create, name, flags);
|
||||||
@ -83,7 +84,7 @@ static inline void delay(long ms)
|
|||||||
#define delay(ms) Sleep(ms)
|
#define delay(ms) Sleep(ms)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
void wait_send(int sfd)
|
void wait_send(int sfd)
|
||||||
{
|
{
|
||||||
for (int i = 0; params.wait_send && i < 500; i++) {
|
for (int i = 0; params.wait_send && i < 500; i++) {
|
||||||
@ -119,7 +120,7 @@ void wait_send(int sfd)
|
|||||||
#define wait_send_if_support(sfd) // :(
|
#define wait_send_if_support(sfd) // :(
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -166,11 +167,18 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (opt->md5sig) {
|
if (opt->md5sig) {
|
||||||
|
#ifdef __linux__
|
||||||
struct tcp_md5sig md5 = {
|
struct tcp_md5sig md5 = {
|
||||||
.tcpm_keylen = 5
|
.tcpm_keylen = 5
|
||||||
};
|
};
|
||||||
memcpy(&md5.tcpm_addr, &addr, addr_size);
|
memcpy(&md5.tcpm_addr, &addr, addr_size);
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
// FIXME: Should be struct tcpmd5_support
|
||||||
|
// but netipsec/ipsec_support.h hides this under ifdef KERNEL
|
||||||
|
int md5 = 1;
|
||||||
|
#else
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
if (setsockopt(sfd, IPPROTO_TCP,
|
if (setsockopt(sfd, IPPROTO_TCP,
|
||||||
TCP_MD5SIG, (char *)&md5, sizeof(md5)) < 0) {
|
TCP_MD5SIG, (char *)&md5, sizeof(md5)) < 0) {
|
||||||
uniperror("setsockopt TCP_MD5SIG");
|
uniperror("setsockopt TCP_MD5SIG");
|
||||||
@ -184,7 +192,15 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
len = sendfile(sfd, ffd, 0, pos);
|
len = sendfile(sfd, ffd, 0, pos);
|
||||||
|
#else
|
||||||
|
int ret = sendfile(ffd, sfd, 0, pos, NULL, &len, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
uniperror("sendfile");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
uniperror("sendfile");
|
uniperror("sendfile");
|
||||||
break;
|
break;
|
||||||
@ -202,10 +218,16 @@ ssize_t send_fake(int sfd, char *buffer,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (opt->md5sig) {
|
if (opt->md5sig) {
|
||||||
|
#ifdef __linux__
|
||||||
struct tcp_md5sig md5 = {
|
struct tcp_md5sig md5 = {
|
||||||
.tcpm_keylen = 0
|
.tcpm_keylen = 0
|
||||||
};
|
};
|
||||||
memcpy(&md5.tcpm_addr, &addr, addr_size);
|
memcpy(&md5.tcpm_addr, &addr, addr_size);
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
int md5 = 0;
|
||||||
|
#else
|
||||||
|
#error
|
||||||
|
#endif
|
||||||
|
|
||||||
if (setsockopt(sfd, IPPROTO_TCP,
|
if (setsockopt(sfd, IPPROTO_TCP,
|
||||||
TCP_MD5SIG, (char *)&md5, sizeof(md5)) < 0) {
|
TCP_MD5SIG, (char *)&md5, sizeof(md5)) < 0) {
|
||||||
|
7
extend.c
7
extend.c
@ -33,15 +33,16 @@ int set_timeout(int fd, unsigned int s)
|
|||||||
uniperror("setsockopt TCP_USER_TIMEOUT");
|
uniperror("setsockopt TCP_USER_TIMEOUT");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#elif defined(__FreeBSD__)
|
||||||
#ifdef _WIN32
|
// https://wiki.freebsd.org/CatalinNicutar/TCPUTO
|
||||||
|
// sadly not yet available
|
||||||
|
#elif defined(_WIN32)
|
||||||
if (setsockopt(fd, IPPROTO_TCP,
|
if (setsockopt(fd, IPPROTO_TCP,
|
||||||
TCP_MAXRT, (char *)&s, sizeof(s))) {
|
TCP_MAXRT, (char *)&s, sizeof(s))) {
|
||||||
uniperror("setsockopt TCP_MAXRT");
|
uniperror("setsockopt TCP_MAXRT");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
main.c
8
main.c
@ -24,6 +24,10 @@
|
|||||||
#define close(fd) closesocket(fd)
|
#define close(fd) closesocket(fd)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define VERSION "12"
|
#define VERSION "12"
|
||||||
|
|
||||||
char oob_char[1] = "a";
|
char oob_char[1] = "a";
|
||||||
@ -94,7 +98,7 @@ const char help_text[] = {
|
|||||||
#ifdef FAKE_SUPPORT
|
#ifdef FAKE_SUPPORT
|
||||||
" -f, --fake <n[+s]> Split and send fake packet\n"
|
" -f, --fake <n[+s]> Split and send fake packet\n"
|
||||||
" -t, --ttl <num> TTL of fake packets, default 8\n"
|
" -t, --ttl <num> TTL of fake packets, default 8\n"
|
||||||
#ifdef __linux__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
" -k, --ip-opt[=f|:str] IP options of fake packets\n"
|
" -k, --ip-opt[=f|:str] IP options of fake packets\n"
|
||||||
" -S, --md5sig Add MD5 Signature option for fake packets\n"
|
" -S, --md5sig Add MD5 Signature option for fake packets\n"
|
||||||
#endif
|
#endif
|
||||||
@ -138,7 +142,7 @@ const struct option options[] = {
|
|||||||
#ifdef FAKE_SUPPORT
|
#ifdef FAKE_SUPPORT
|
||||||
{"fake", 1, 0, 'f'},
|
{"fake", 1, 0, 'f'},
|
||||||
{"ttl", 1, 0, 't'},
|
{"ttl", 1, 0, 't'},
|
||||||
#ifdef __linux__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
{"ip-opt", 2, 0, 'k'},
|
{"ip-opt", 2, 0, 'k'},
|
||||||
{"md5sig", 0, 0, 'S'},
|
{"md5sig", 0, 0, 'S'},
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,6 +15,10 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#include <strings.h>
|
||||||
|
#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])
|
||||||
|
|
||||||
|
8
params.h
8
params.h
@ -9,12 +9,20 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#else
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__linux__) || defined(_WIN32)
|
#if defined(__linux__) || defined(_WIN32)
|
||||||
#define FAKE_SUPPORT 1
|
#define FAKE_SUPPORT 1
|
||||||
#define TIMEOUT_SUPPORT 1
|
#define TIMEOUT_SUPPORT 1
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
#define FAKE_SUPPORT 1
|
||||||
|
// TIMEOUT_SUPPORT can't be used
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OFFSET_SNI 1
|
#define OFFSET_SNI 1
|
||||||
|
11
proxy.c
11
proxy.c
@ -82,7 +82,7 @@ static inline char addr_equ(
|
|||||||
|
|
||||||
static inline int nb_socket(int domain, int type)
|
static inline int nb_socket(int domain, int type)
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
int fd = socket(domain, type | SOCK_NONBLOCK, 0);
|
int fd = socket(domain, type | SOCK_NONBLOCK, 0);
|
||||||
#else
|
#else
|
||||||
int fd = socket(domain, type, 0);
|
int fd = socket(domain, type, 0);
|
||||||
@ -98,15 +98,13 @@ static inline int nb_socket(int domain, int type)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#elif !defined(__linux__)
|
||||||
#ifndef __linux__
|
|
||||||
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
|
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||||
uniperror("fcntl");
|
uniperror("fcntl");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,7 +515,7 @@ static inline int on_accept(struct poolhd *pool, struct eval *val)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
socklen_t len = sizeof(client);
|
socklen_t len = sizeof(client);
|
||||||
#ifdef __linux__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
int c = accept4(val->fd, &client.sa, &len, SOCK_NONBLOCK);
|
int c = accept4(val->fd, &client.sa, &len, SOCK_NONBLOCK);
|
||||||
#else
|
#else
|
||||||
int c = accept(val->fd, &client.sa, &len);
|
int c = accept(val->fd, &client.sa, &len);
|
||||||
@ -940,7 +938,8 @@ int listen_socket(struct sockaddr_ina *srv)
|
|||||||
close(srvfd);
|
close(srvfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (bind(srvfd, &srv->sa, sizeof(*srv)) < 0) {
|
size_t size = srv->sa.sa_family == AF_INET6 ? sizeof(srv->in6) : sizeof(srv->in);
|
||||||
|
if (bind(srvfd, &srv->sa, size) < 0) {
|
||||||
uniperror("bind");
|
uniperror("bind");
|
||||||
close(srvfd);
|
close(srvfd);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user