From 15e22fa1bdf36820aa54fb264006ce9dbfb1afb7 Mon Sep 17 00:00:00 2001 From: bol-van Date: Fri, 14 Mar 2025 11:35:26 +0300 Subject: [PATCH] tpws: detect WSL 1 and warn about non-working options --- tpws/helpers.c | 23 +++++++++++++++++++++++ tpws/helpers.h | 5 +++++ tpws/tpws.c | 21 ++++++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/tpws/helpers.c b/tpws/helpers.c index 47e8f2b2..23b5273d 100644 --- a/tpws/helpers.c +++ b/tpws/helpers.c @@ -78,6 +78,13 @@ char *strncasestr(const char *s, const char *find, size_t slen) return (char *)s; } +bool str_ends_with(const char *s, const char *suffix) +{ + size_t slen = strlen(s); + size_t suffix_len = strlen(suffix); + return suffix_len <= slen && !strcmp(s + slen - suffix_len, suffix); +} + bool load_file(const char *filename, void *buffer, size_t *buffer_size) { FILE *F; @@ -565,4 +572,20 @@ bool socket_wait_notsent(int sfd, unsigned int delay_ms, unsigned int *wasted_ms } return false; } + +int is_wsl(void) +{ + struct utsname buf; + if (uname(&buf) != 0) + return -1; + + if (strcmp(buf.sysname, "Linux") != 0) + return 0; + if (str_ends_with(buf.release, "microsoft-standard-WSL2")) + return 2; + if (str_ends_with(buf.release, "-Microsoft")) + return 1; + + return 0; +} #endif diff --git a/tpws/helpers.h b/tpws/helpers.h index 3c9c1536..c0301c2e 100644 --- a/tpws/helpers.h +++ b/tpws/helpers.h @@ -7,6 +7,7 @@ #include #include #include +#include // this saves memory. sockaddr_storage is larger than required. it can be 128 bytes. sockaddr_in6 is 28 bytes. typedef union @@ -22,6 +23,8 @@ void rtrim(char *s); void replace_char(char *s, char from, char to); char *strncasestr(const char *s,const char *find, size_t slen); +bool str_ends_with(const char *s, const char *suffix); + bool load_file(const char *filename,void *buffer,size_t *buffer_size); bool append_to_list_file(const char *filename, const char *s); @@ -133,4 +136,6 @@ void msleep(unsigned int ms); bool socket_supports_notsent(); bool socket_has_notsent(int sfd); bool socket_wait_notsent(int sfd, unsigned int delay_ms, unsigned int *wasted_ms); + +int is_wsl(); #endif diff --git a/tpws/tpws.c b/tpws/tpws.c index ff6bfc86..0256f42c 100644 --- a/tpws/tpws.c +++ b/tpws/tpws.c @@ -1474,7 +1474,7 @@ void parse_params(int argc, char *argv[]) params.binds_last=0; // default bind to all } if (!params.resolver_threads) params.resolver_threads = 5 + params.maxconn/50; - + VPRINT("adding low-priority default empty desync profile\n"); // add default empty profile if (!(dpl = dp_list_add(¶ms.desync_profiles))) @@ -1490,6 +1490,10 @@ void parse_params(int argc, char *argv[]) fprintf(stderr, "could not chown %s. log file may not be writable after privilege drop\n", params.debug_logfile); if (params.droproot && *params.hostlist_auto_debuglog && chown(params.hostlist_auto_debuglog, params.uid, -1)) DLOG_ERR("could not chown %s. auto hostlist debug log may not be writable after privilege drop\n", params.hostlist_auto_debuglog); + +#ifdef __linux__ + bool bHasMSS=false, bHasOOB=false, bHasDisorder=false; +#endif LIST_FOREACH(dpl, ¶ms.desync_profiles, next) { dp = &dpl->dp; @@ -1500,7 +1504,22 @@ void parse_params(int argc, char *argv[]) } if (params.droproot && dp->hostlist_auto && chown(dp->hostlist_auto->filename, params.uid, -1)) DLOG_ERR("could not chown %s. auto hostlist file may not be writable after privilege drop\n", dp->hostlist_auto->filename); +#ifdef __linux__ + if (dp->mss) bHasMSS=true; + if (dp->oob || dp->oob_http || dp->oob_tls) bHasOOB=true; + if (dp->disorder || dp->disorder_http || dp->disorder_tls) bHasDisorder=true; +#endif } +#ifdef __linux__ + if (is_wsl()==1) + { + if (!params.nosplice) DLOG_CONDUP("WARNING ! WSL1 may have problems with splice. Consider using `--nosplice`.\n"); + if (bHasMSS) DLOG_CONDUP("WARNING ! WSL1 does not support MSS socket option. MSS will likely fail.\n"); + if (bHasOOB) DLOG_CONDUP("WARNING ! WSL1 does not support OOB. OOB will likely fail.\n"); + if (bHasDisorder) DLOG_CONDUP("WARNING ! Windows retransmits whole TCP segment. Disorder will not function properly.\n"); + fflush(stdout); + } +#endif if (!LoadAllHostLists()) {