Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 10 additions & 40 deletions src/wg-quick/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
static bool is_exiting = false;
static bool binder_available = false;
static unsigned int sdk_version;
static bool is_awg_on = false;

static void *xmalloc(size_t size)
{
Expand Down Expand Up @@ -631,12 +630,19 @@ static void auto_su(int argc, char *argv[])
exit(errno);
}

static bool kernel_module_available(void)
{
struct stat st;

return stat("/sys/module/amneziawg", &st) == 0 && S_ISDIR(st.st_mode);
}

static void add_if(const char *iface)
{
if (is_awg_on)
cmd("amneziawg-go %s", iface);
else
if (kernel_module_available())
cmd("ip link add %s type amneziawg", iface);
else
cmd("amneziawg-go %s", iface);
}

static void del_if(const char *iface)
Expand Down Expand Up @@ -1260,42 +1266,6 @@ static void parse_options(char **iface, char **config, unsigned int *mtu, char *
} else if (!strncasecmp(clean, "MTU=", 4) && j > 4) {
*mtu = atoi(clean + 4);
continue;
} else if (!strncasecmp(clean, "Jc=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "Jmin=", 5) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "Jmax=", 5) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "S1=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "S2=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "S3=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "S4=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "H1=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "H2=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "H3=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "H4=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "I1=", 3) && j > 4) {
is_awg_on = true;
} else if (!strncasecmp(clean, "I2=", 3) && j >= 3) {
// I2 can be empty, so we only check for the prefix
is_awg_on = true;
} else if (!strncasecmp(clean, "I3=", 3) && j >= 3) {
// I3 can be empty, so we only check for the prefix
is_awg_on = true;
} else if (!strncasecmp(clean, "I4=", 3) && j >= 3) {
// I4 can be empty, so we only check for the prefix
is_awg_on = true;
} else if (!strncasecmp(clean, "I5=", 3) && j >= 3) {
// I5 can be empty, so we only check for the prefix
is_awg_on = true;
}
}
*config = concat_and_free(*config, "", line);
Expand Down