Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72d771e126 | ||
|
|
4d7192667e | ||
|
|
43f5457802 | ||
|
|
2005068039 | ||
|
|
9028aaea88 | ||
|
|
e80eb158d8 | ||
|
|
68abb63f74 | ||
|
|
c458a4d86f | ||
|
|
cbdba8cba3 | ||
|
|
d787fa1dca | ||
|
|
b7582d0107 | ||
|
|
2d46958f9f | ||
|
|
9131742ff3 |
@@ -1,8 +1,9 @@
|
||||
# glorytun
|
||||
# Glorytun
|
||||
Small, Simple and Stupid **TCP** VPN.
|
||||
|
||||
**Work In Progress:** Do not touch!
|
||||
**Work In Progress:** Do not touch! This code will probably format your harddisk!
|
||||
|
||||
glorytun depends on [libsodium](https://github.com/jedisct1/libsodium) version >= 1.0.4
|
||||
Glorytun depends on [libsodium](https://github.com/jedisct1/libsodium) version >= 1.0.4
|
||||
and needs an AES-NI capable CPU.
|
||||
|
||||
To build and install the latest version:
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
AC_PREREQ([2.65])
|
||||
AC_INIT([glorytun], [0.0.10], [https://github.com/angt/glorytun/issues],
|
||||
AC_INIT([glorytun], [0.0.11], [https://github.com/angt/glorytun/issues],
|
||||
[glorytun], [https://github.com/angt/glorytun])
|
||||
AC_CONFIG_SRCDIR([src/common.h])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AM_INIT_AUTOMAKE([1.9 -Wall -Werror foreign tar-ustar subdir-objects])
|
||||
AM_DEP_TRACK
|
||||
AM_SILENT_RULES([yes])
|
||||
AM_PROG_CC_C_O
|
||||
AC_PROG_CC_C99
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
AC_SEARCH_LIBS([getaddrinfo], [resolv nsl])
|
||||
|
||||
62
src/main.c
62
src/main.c
@@ -23,7 +23,7 @@
|
||||
#endif
|
||||
|
||||
#define GT_BUFFER_SIZE (4*1024*1024)
|
||||
#define GT_TIMEOUT (1000)
|
||||
#define GT_TIMEOUT (5000)
|
||||
#define GT_MTU_MAX (1500)
|
||||
#define GT_TUNR_SIZE (0x7FFF-16)
|
||||
#define GT_TUNW_SIZE (0x7FFF)
|
||||
@@ -659,6 +659,7 @@ int main (int argc, char **argv)
|
||||
|
||||
long retry_count = 0;
|
||||
long retry_slope = 1000;
|
||||
long retry_const = 0;
|
||||
long retry_limit = 1000000;
|
||||
|
||||
struct option ka_opts[] = {
|
||||
@@ -676,6 +677,7 @@ int main (int argc, char **argv)
|
||||
struct option retry_opts[] = {
|
||||
{ "count", &retry_count, option_long },
|
||||
{ "slope", &retry_slope, option_long },
|
||||
{ "const", &retry_const, option_long },
|
||||
{ "limit", &retry_limit, option_long },
|
||||
{ NULL },
|
||||
};
|
||||
@@ -796,7 +798,7 @@ int main (int argc, char **argv)
|
||||
if (retry<LONG_MAX)
|
||||
retry++;
|
||||
|
||||
long usec = retry*retry_slope;
|
||||
long usec = retry*retry_slope+retry_const;
|
||||
|
||||
if (retry_count>=0 && retry>=retry_count) {
|
||||
gt_log("couldn't %s (%d attempt%s)\n",
|
||||
@@ -817,8 +819,6 @@ int main (int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
retry = 0;
|
||||
|
||||
char *sockname = sk_get_name(sock.fd);
|
||||
|
||||
if (!sockname) {
|
||||
@@ -826,9 +826,6 @@ int main (int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (option_is_set(opts, "trap"))
|
||||
kill(0, SIGUSR2);
|
||||
|
||||
gt_log("%s: connected\n", sockname);
|
||||
|
||||
fd_set_nonblock(sock.fd);
|
||||
@@ -850,14 +847,25 @@ int main (int argc, char **argv)
|
||||
sk_set(sock.fd, sk_congestion, congestion, str_len(congestion));
|
||||
|
||||
switch (gt_setup_crypto(&ctx, sock.fd, listener)) {
|
||||
case -2: gt_log("%s: key exchange could not be verified!\n", sockname);
|
||||
case -1: goto restart;
|
||||
default: break;
|
||||
case -2:
|
||||
gt_log("%s: key exchange could not be verified!\n", sockname);
|
||||
goto restart;
|
||||
case -1:
|
||||
gt_log("%s: key exchange failed\n", sockname);
|
||||
goto restart;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
fd_set rfds, wfds;
|
||||
retry = 0;
|
||||
|
||||
if (option_is_set(opts, "trap"))
|
||||
kill(0, SIGUSR2);
|
||||
|
||||
gt_log("%s: running\n", sockname);
|
||||
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&wfds);
|
||||
|
||||
int stop_loop = 0;
|
||||
|
||||
@@ -874,21 +882,32 @@ int main (int argc, char **argv)
|
||||
goto restart;
|
||||
FD_CLR(tun.fd, &rfds);
|
||||
} else {
|
||||
FD_SET(tun.fd, &rfds);
|
||||
if (!blks[blk_write].size) {
|
||||
FD_SET(tun.fd, &rfds);
|
||||
} else {
|
||||
FD_CLR(tun.fd, &rfds);
|
||||
}
|
||||
}
|
||||
|
||||
FD_SET(sock.fd, &rfds);
|
||||
buffer_shift(&sock.read);
|
||||
|
||||
if _0_(select(sock.fd+1, &rfds, &wfds, NULL, NULL)==-1) {
|
||||
if (buffer_write_size(&sock.read)) {
|
||||
FD_SET(sock.fd, &rfds);
|
||||
} else {
|
||||
FD_CLR(sock.fd, &rfds);
|
||||
}
|
||||
|
||||
struct timeval timeout = {
|
||||
.tv_usec = 1000,
|
||||
};
|
||||
|
||||
if _0_(select(sock.fd+1, &rfds, NULL, NULL, &timeout)==-1) {
|
||||
if (errno==EINTR)
|
||||
continue;
|
||||
perror("select");
|
||||
return 1;
|
||||
}
|
||||
|
||||
FD_CLR(sock.fd, &wfds);
|
||||
FD_CLR(tun.fd, &wfds);
|
||||
|
||||
// TODO
|
||||
// struct timeval now;
|
||||
// gettimeofday(&now, NULL);
|
||||
@@ -962,11 +981,8 @@ int main (int argc, char **argv)
|
||||
if (r>0) {
|
||||
sock.write.read += r;
|
||||
} else {
|
||||
if (!r) {
|
||||
if (!r)
|
||||
stop_loop |= (1<<2);
|
||||
} else {
|
||||
FD_SET(sock.fd, &wfds);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -980,7 +996,6 @@ int main (int argc, char **argv)
|
||||
}
|
||||
|
||||
buffer_shift(&sock.write);
|
||||
buffer_shift(&sock.read);
|
||||
|
||||
if (FD_ISSET(sock.fd, &rfds)) {
|
||||
if (noquickack)
|
||||
@@ -1021,7 +1036,6 @@ int main (int argc, char **argv)
|
||||
tun.write.read += r;
|
||||
} else {
|
||||
gt_close |= !r;
|
||||
FD_SET(tun.fd, &wfds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
15
src/option.c
15
src/option.c
@@ -94,18 +94,18 @@ static int option_usage (struct option *opts, int slen)
|
||||
if (!opts)
|
||||
return 0;
|
||||
|
||||
int len = slen;
|
||||
int len = 0;
|
||||
|
||||
for (int k=0; opts[k].name; k++) {
|
||||
if (len>slen+40) {
|
||||
gt_print("\n%*s", (int)slen, "");
|
||||
len = slen;
|
||||
if (len>40) {
|
||||
gt_print("\n%*s", slen, "");
|
||||
len = 0;
|
||||
}
|
||||
|
||||
len += gt_print(" [%s", opts[k].name);
|
||||
|
||||
if (opts[k].call==option_option) {
|
||||
len += option_usage((struct option *)opts[k].data, len);
|
||||
len += option_usage((struct option *)opts[k].data, slen+len);
|
||||
} else {
|
||||
len += gt_print(" ARG");
|
||||
}
|
||||
@@ -132,12 +132,11 @@ int option (struct option *opts, int argc, char **argv)
|
||||
|
||||
if (slen>40) {
|
||||
slen = 12;
|
||||
gt_print("\n%*s", (int)slen, "");
|
||||
gt_print("\n%*s", slen, "");
|
||||
}
|
||||
|
||||
option_usage(opts, slen);
|
||||
|
||||
printf("\n");
|
||||
gt_print("\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user