mirror of
https://github.com/bol-van/zapret.git
synced 2025-03-20 13:37:55 +05:00
tpws: detect WSL 1 and warn about non-working options
This commit is contained in:
parent
bd8decddc5
commit
15e22fa1bd
@ -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
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
// 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
|
||||
|
21
tpws/tpws.c
21
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())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user