Compare commits
19 Commits
v0.0.42-mu
...
v0.0.59-mu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84156a9eba | ||
|
|
b13501b9fb | ||
|
|
3363e219a7 | ||
|
|
00ee23b0b6 | ||
|
|
1286b0f69e | ||
|
|
fe5bc5454e | ||
|
|
f4e94a9089 | ||
|
|
6a7da371e2 | ||
|
|
4cf5f7a118 | ||
|
|
35fd01f9ee | ||
|
|
04aad57789 | ||
|
|
7a277a8810 | ||
|
|
b232a101d2 | ||
|
|
a01dc81500 | ||
|
|
1db628d84a | ||
|
|
f11cd34dc4 | ||
|
|
d0376e3aa5 | ||
|
|
a7518c0e5a | ||
|
|
378316bd68 |
15
.build.sh
Executable file
15
.build.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
export CC="gcc -static"
|
||||||
|
|
||||||
|
git clone https://github.com/jedisct1/libsodium --depth=1 --branch stable
|
||||||
|
cd libsodium || exit 1
|
||||||
|
./autogen.sh && ./configure --enable-minimal --disable-shared --prefix=/usr && make install
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
./autogen.sh && ./configure && make
|
||||||
|
[ -x glorytun ] || exit 1
|
||||||
|
|
||||||
|
mkdir -p deploy
|
||||||
|
strip -s glorytun
|
||||||
|
mv glorytun deploy/glorytun-$(cat VERSION)-$(uname -m).bin
|
||||||
@@ -14,8 +14,9 @@ AM_SILENT_RULES([yes])
|
|||||||
AM_PROG_CC_C_O
|
AM_PROG_CC_C_O
|
||||||
AC_PROG_CC_C99
|
AC_PROG_CC_C99
|
||||||
AC_USE_SYSTEM_EXTENSIONS
|
AC_USE_SYSTEM_EXTENSIONS
|
||||||
AC_SEARCH_LIBS([getaddrinfo], [resolv nsl])
|
|
||||||
AC_SEARCH_LIBS([socket], [socket])
|
AC_SEARCH_LIBS([socket], [socket])
|
||||||
|
AC_CHECK_LIB([rt], [clock_gettime])
|
||||||
|
AC_CHECK_FUNCS([clock_gettime])
|
||||||
PKG_CHECK_MODULES([libsodium], [libsodium >= 1.0.4])
|
PKG_CHECK_MODULES([libsodium], [libsodium >= 1.0.4])
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|||||||
2
mud
2
mud
Submodule mud updated: 2c4443a823...1fe5190e8a
83
src/main.c
83
src/main.c
@@ -245,12 +245,18 @@ int main (int argc, char **argv)
|
|||||||
char *keyfile = NULL;
|
char *keyfile = NULL;
|
||||||
char *statefile = NULL;
|
char *statefile = NULL;
|
||||||
|
|
||||||
|
long mtu = 1450;
|
||||||
|
|
||||||
gt.timeout = 5000;
|
gt.timeout = 5000;
|
||||||
|
|
||||||
long time_tolerance = 0;
|
long time_tolerance = 0;
|
||||||
|
|
||||||
int v4 = 1;
|
int v4 = 1;
|
||||||
int v6 = 1;
|
int v6 = 0;
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
v6 = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct option opts[] = {
|
struct option opts[] = {
|
||||||
{ "host", &host, option_str },
|
{ "host", &host, option_str },
|
||||||
@@ -258,6 +264,7 @@ int main (int argc, char **argv)
|
|||||||
{ "bind", &bind_list, option_str },
|
{ "bind", &bind_list, option_str },
|
||||||
{ "bind-port", &bind_port, option_long },
|
{ "bind-port", &bind_port, option_long },
|
||||||
{ "dev", &dev, option_str },
|
{ "dev", &dev, option_str },
|
||||||
|
{ "mtu", &mtu, option_long },
|
||||||
{ "keyfile", &keyfile, option_str },
|
{ "keyfile", &keyfile, option_str },
|
||||||
{ "multiqueue", NULL, option_option },
|
{ "multiqueue", NULL, option_option },
|
||||||
{ "statefile", &statefile, option_str },
|
{ "statefile", &statefile, option_str },
|
||||||
@@ -265,6 +272,7 @@ int main (int argc, char **argv)
|
|||||||
{ "time-tolerance", &time_tolerance, option_long },
|
{ "time-tolerance", &time_tolerance, option_long },
|
||||||
{ "v4only", NULL, option_option },
|
{ "v4only", NULL, option_option },
|
||||||
{ "v6only", NULL, option_option },
|
{ "v6only", NULL, option_option },
|
||||||
|
{ "chacha20", NULL, option_option },
|
||||||
{ "version", NULL, option_option },
|
{ "version", NULL, option_option },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
@@ -277,13 +285,18 @@ int main (int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option_is_set(opts, "v4only"))
|
if (option_is_set(opts, "v4only")) {
|
||||||
|
v4 = 1;
|
||||||
v6 = 0;
|
v6 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (option_is_set(opts, "v6only"))
|
if (option_is_set(opts, "v6only")) {
|
||||||
v4 = 0;
|
v4 = 0;
|
||||||
|
v6 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!v4 && !v6) {
|
if (option_is_set(opts, "v4only") &&
|
||||||
|
option_is_set(opts, "v6only")) {
|
||||||
gt_log("v4only and v6only are both set\n");
|
gt_log("v4only and v6only are both set\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -314,7 +327,9 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
fd_set_nonblock(tun_fd);
|
fd_set_nonblock(tun_fd);
|
||||||
|
|
||||||
struct mud *mud = mud_create(bind_port, v4, v6);
|
int chacha = option_is_set(opts, "chacha20");
|
||||||
|
|
||||||
|
struct mud *mud = mud_create(bind_port, v4, v6, !chacha);
|
||||||
|
|
||||||
if (!mud) {
|
if (!mud) {
|
||||||
gt_log("couldn't create mud\n");
|
gt_log("couldn't create mud\n");
|
||||||
@@ -359,7 +374,16 @@ int main (int argc, char **argv)
|
|||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
|
|
||||||
int started = 0;
|
int started = 0;
|
||||||
unsigned char buf[2048];
|
|
||||||
|
struct {
|
||||||
|
unsigned char *buf;
|
||||||
|
} send, recv;
|
||||||
|
|
||||||
|
send.buf = malloc(2*mtu);
|
||||||
|
recv.buf = malloc(mtu);
|
||||||
|
|
||||||
|
size_t send_size = 0;
|
||||||
|
size_t send_limit = 0;
|
||||||
|
|
||||||
while (!gt.quit) {
|
while (!gt.quit) {
|
||||||
FD_SET(tun_fd, &rfds);
|
FD_SET(tun_fd, &rfds);
|
||||||
@@ -374,7 +398,7 @@ int main (int argc, char **argv)
|
|||||||
.tv_usec = 100000,
|
.tv_usec = 100000,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mud_can_push(mud))
|
if (mud_can_push(mud) || send_size)
|
||||||
timeout.tv_usec = 1000;
|
timeout.tv_usec = 1000;
|
||||||
|
|
||||||
if _0_(select(mud_fd+1, &rfds, NULL, NULL, &timeout)==-1) {
|
if _0_(select(mud_fd+1, &rfds, NULL, NULL, &timeout)==-1) {
|
||||||
@@ -397,8 +421,8 @@ int main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(tun_fd, &rfds)) {
|
if (FD_ISSET(tun_fd, &rfds)) {
|
||||||
while (1) {
|
while (send_size<mtu) {
|
||||||
const ssize_t r = tun_read(tun_fd, buf, sizeof(buf));
|
const ssize_t r = tun_read(tun_fd, send.buf+send_size, mtu);
|
||||||
|
|
||||||
if (r<=0) {
|
if (r<=0) {
|
||||||
gt.quit |= !r;
|
gt.quit |= !r;
|
||||||
@@ -407,27 +431,52 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
struct ip_common ic;
|
struct ip_common ic;
|
||||||
|
|
||||||
if (!ip_get_common(&ic, buf, sizeof(buf)) && ic.size==r)
|
if (ip_get_common(&ic, send.buf+send_size, mtu) || ic.size!=r) {
|
||||||
mud_send(mud, buf, r);
|
gt_log("packet dropped: malformed\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
send_size += r;
|
||||||
|
|
||||||
|
if (send_size<=mtu)
|
||||||
|
send_limit = send_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (send_limit && mud_send(mud, send.buf, send_limit)==send_limit) {
|
||||||
|
if (send_size>send_limit)
|
||||||
|
memmove(&send.buf[0], &send.buf[send_limit], send_size-send_limit);
|
||||||
|
send_size -= send_limit;
|
||||||
|
send_limit = send_size;
|
||||||
|
}
|
||||||
|
|
||||||
mud_push(mud);
|
mud_push(mud);
|
||||||
|
|
||||||
if (FD_ISSET(mud_fd, &rfds))
|
if (FD_ISSET(mud_fd, &rfds))
|
||||||
mud_pull(mud);
|
mud_pull(mud);
|
||||||
|
|
||||||
while (1) {
|
while (!gt.quit) {
|
||||||
const int size = mud_recv(mud, buf, sizeof(buf));
|
const int size = mud_recv(mud, recv.buf, mtu);
|
||||||
|
|
||||||
if (size<=0)
|
if (size<=0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const ssize_t r = tun_write(tun_fd, buf, size);
|
int p = 0;
|
||||||
|
|
||||||
if (r<=0) {
|
while (p<size) {
|
||||||
gt.quit |= !r;
|
struct ip_common ic;
|
||||||
break;
|
|
||||||
|
if (ip_get_common(&ic, recv.buf+p, size-p) || ic.size>size-p)
|
||||||
|
break;
|
||||||
|
|
||||||
|
const ssize_t r = tun_write(tun_fd, recv.buf+p, ic.size);
|
||||||
|
|
||||||
|
if (r<=0) {
|
||||||
|
gt.quit |= !r;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
p += ic.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user