diff --git a/desync.c b/desync.c index 0b3208a..fde50b3 100644 --- a/desync.c +++ b/desync.c @@ -249,7 +249,9 @@ ssize_t send_fake(int sfd, char *buffer, close(fds[1]); return len; } -#else +#endif + +#ifdef _WIN32 OVERLAPPED ov = {}; ssize_t send_fake(int sfd, char *buffer, diff --git a/dist/linux/README.md b/dist/linux/README.md index 96db4d8..f211b46 100644 --- a/dist/linux/README.md +++ b/dist/linux/README.md @@ -9,16 +9,30 @@ sudo make install ## Systemd Service (optional) -Copy and enable the service: +You can configure the program to run as systemd service, user- or system-wide (only one at a time). + +### As user service: ```sh cp byedpi.service ~/.config/systemd/user/ -systemctl --user daemon-reload -systemctl --user enable byedpi.service -systemctl --user start byedpi.service +cp byedpi.conf ~/.config/ +systemctl --user enable --now byedpi.service ``` You should see the service now marked as "active": ```sh systemctl --user status byedpi.service ``` + +### As system service: + +```sh +sudo cp byedpi.service /etc/systemd/system/ +sudo cp byedpi.conf /etc/ +sudo systemctl enable --now byedpi.service +``` + +You should see the service now marked as "active": +```sh +systemctl status byedpi.service +``` diff --git a/dist/linux/byedpi.conf b/dist/linux/byedpi.conf new file mode 100644 index 0000000..e52e18a --- /dev/null +++ b/dist/linux/byedpi.conf @@ -0,0 +1,8 @@ +# More options and their descriptions can be found here: +# https://github.com/hufrea/byedpi/blob/main/README.md +# +# By default, ciadpi listens on all interfaces, +# a specific one can be specified via "--ip 127.0.0.1". + +# Put your options here +BYEDPI_OPTIONS="--split 1 --disorder 3+s --mod-http=h,d --auto=torst --tlsrec 1+s" diff --git a/dist/linux/byedpi.service b/dist/linux/byedpi.service index af986ae..7abe067 100644 --- a/dist/linux/byedpi.service +++ b/dist/linux/byedpi.service @@ -1,14 +1,19 @@ [Unit] -Description=byedpi +Description=ByeDPI Documentation=https://github.com/hufrea/byedpi +Wants=network-online.target +After=network-online.target nss-lookup.target [Service] -ExecStart=ciadpi --split 1 --disorder 3+s --mod-http=h,d --auto=torst --tlsrec 1+s +NoNewPrivileges=yes +StandardOutput=null +StandardError=journal +EnvironmentFile=-/etc/byedpi.conf +EnvironmentFile=-%h/.config/byedpi.conf +ExecStart=ciadpi $BYEDPI_OPTIONS TimeoutStopSec=5s -LimitNOFILE=1048576 -LimitNPROC=512 PrivateTmp=true ProtectSystem=full [Install] -WantedBy=default.target \ No newline at end of file +WantedBy=default.target diff --git a/extend.c b/extend.c index c696cbe..d03c326 100644 --- a/extend.c +++ b/extend.c @@ -23,8 +23,7 @@ #include "desync.h" #include "packets.h" -#define KEY_SIZE sizeof(uint16_t) + \ - sizeof(sa_family_t) + sizeof(struct sockaddr_in6) +#define KEY_SIZE sizeof(struct sockaddr_ina) int set_timeout(int fd, unsigned int s) @@ -223,21 +222,24 @@ int on_torst(struct poolhd *pool, struct eval *val) for (; m < params.dp_count; m++) { struct desync_params *dp = ¶ms.dp[m]; if (!dp->detect) { - return -1; + m = 0; + break; } if (dp->detect & DETECT_TORST) { break; } } - if (m >= params.dp_count) { + if (m == 0) { + } + else if (m >= params.dp_count) { if (m > 1) mode_add_get( (struct sockaddr_ina *)&val->in6, 0); } - else if (can_reconn) + else if (can_reconn) { return reconnect(pool, val, m); - else - mode_add_get( - (struct sockaddr_ina *)&val->in6, m); + } + else mode_add_get( + (struct sockaddr_ina *)&val->in6, m); } struct linger l = { .l_onoff = 1 }; if (setsockopt(val->pair->fd, SOL_SOCKET, diff --git a/main.c b/main.c index b8d1e36..dc16943 100644 --- a/main.c +++ b/main.c @@ -361,6 +361,17 @@ int get_default_ttl() } +bool ipv6_support() +{ + int fd = socket(AF_INET6, SOCK_STREAM, 0); + if (fd < 0) { + return 0; + } + close(fd); + return 1; +} + + int parse_offset(struct part *part, const char *str) { char *end = 0; @@ -473,12 +484,16 @@ int main(int argc, char **argv) } params.laddr.sin6_port = htons(1080); + if (!ipv6_support()) { + params.baddr.sin6_family = AF_INET; + } int rez; int invalid = 0; long val = 0; char *end = 0; + bool all_limited = 1; struct desync_params *dp = add((void *)¶ms.dp, ¶ms.dp_count, sizeof(struct desync_params)); @@ -573,6 +588,9 @@ int main(int argc, char **argv) break; case 'A': + if (!(dp->hosts || dp->proto || dp->pf[0] || dp->detect)) { + all_limited = 0; + } dp = add((void *)¶ms.dp, ¶ms.dp_count, sizeof(struct desync_params)); if (!dp) { @@ -866,7 +884,7 @@ int main(int argc, char **argv) clear_params(); return -1; } - if (dp->hosts || dp->proto || dp->pf[0]) { + if (all_limited) { dp = add((void *)¶ms.dp, ¶ms.dp_count, sizeof(struct desync_params)); if (!dp) {