Compare commits
36 Commits
v0.0.97-mu
...
v0.0.99-mu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3bb488fd5 | ||
|
|
022e478fb9 | ||
|
|
f3b44e2f45 | ||
|
|
23b7aeb68f | ||
|
|
1e2004c7dd | ||
|
|
e12d136ba3 | ||
|
|
ca96be5fe5 | ||
|
|
d0a9c69f7c | ||
|
|
3ffce5da1b | ||
|
|
aeb33342a4 | ||
|
|
ca71508e5c | ||
|
|
36be8008d8 | ||
|
|
be17650555 | ||
|
|
873efb4f82 | ||
|
|
357d5a0859 | ||
|
|
5c532b2e56 | ||
|
|
0cce48e9fd | ||
|
|
ee9ed7e3a6 | ||
|
|
841c2afed0 | ||
|
|
60a5b3e00a | ||
|
|
e243d8371a | ||
|
|
767aff211f | ||
|
|
eb04190c58 | ||
|
|
d25957b108 | ||
|
|
a5f634ee28 | ||
|
|
1736b6e043 | ||
|
|
8401b7c112 | ||
|
|
7276305906 | ||
|
|
6e75f4282d | ||
|
|
7999344c39 | ||
|
|
7a9f6fc8b8 | ||
|
|
dabd16e4b4 | ||
|
|
1698a08b08 | ||
|
|
4646cbb15e | ||
|
|
c2bd415382 | ||
|
|
245b8e671e |
116
README.md
116
README.md
@@ -1,54 +1,112 @@
|
|||||||
# Glorytun
|
# Glorytun
|
||||||
|
|
||||||
Small, Simple and Stupid VPN over [mud](https://github.com/angt/mud).
|
Glorytun is a small, simple and secure VPN over [mud](https://github.com/angt/mud).
|
||||||
|
It runs on Linux, OpenBSD, FreeBSD and MacOS.
|
||||||
|
|
||||||
### Build and Install
|
## Features
|
||||||
|
|
||||||
|
The key features of Glorytun come directly from mud:
|
||||||
|
|
||||||
|
* **Fast and highly secure**
|
||||||
|
|
||||||
|
The use of UDP and [libsodium](https://github.com/jedisct1/libsodium) allows you to secure
|
||||||
|
your communications without impacting performance.
|
||||||
|
Glorytun uses AES only if AES-NI is available otherwise ChaCha20 is used.
|
||||||
|
You can force the use of ChaCha20 for higher security.
|
||||||
|
All messages are encrypted, authenticated and marked with a timestamp.
|
||||||
|
Perfect forward secrecy is also implemented with ECDH over Curve25519.
|
||||||
|
|
||||||
|
* **Multipath and active failover**
|
||||||
|
|
||||||
|
This is the main feature of Glorytun that allows to build an SD-WAN like service.
|
||||||
|
This allows a TCP connection to explore and exploit multiple links without being disconnected.
|
||||||
|
|
||||||
|
* **Path MTU discovery without ICMP**
|
||||||
|
|
||||||
|
Bad MTU configuration is a very common problem in the world of VPN.
|
||||||
|
As it is critical, Glorytun will try to setup it correctly by guessing its value.
|
||||||
|
It doesn't rely on ICMP Next-hop MTU to avoid black holes.
|
||||||
|
|
||||||
|
## Build and Install
|
||||||
|
|
||||||
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.
|
||||||
|
We recommend the use of [meson](http://mesonbuild.com) for building instead of
|
||||||
|
the more classical autotools suite (also available for old systems).
|
||||||
|
|
||||||
On Ubuntu, the following command should be sufficient:
|
On Ubuntu, the following command should be sufficient to get all the necessary build dependencies:
|
||||||
|
|
||||||
$ sudo apt-get install meson libsodium-dev pkg-config
|
$ sudo apt-get install meson libsodium-dev pkg-config
|
||||||
|
|
||||||
Grab the latest release from github:
|
To build and install the latest release from github:
|
||||||
|
|
||||||
$ git clone https://github.com/angt/glorytun --recursive
|
$ git clone https://github.com/angt/glorytun --recursive
|
||||||
$ cd glorytun
|
$ meson glorytun glorytun/build
|
||||||
|
$ sudo ninja -C glorytun/build install
|
||||||
|
|
||||||
To build and install the latest version with [meson](http://mesonbuild.com):
|
This will install all binaries in `/usr/local/bin` by default.
|
||||||
|
|
||||||
$ meson build
|
You can easily customize your setup with meson (see `meson help`).
|
||||||
$ sudo ninja -C build install
|
|
||||||
|
|
||||||
The more classical autotools suite is also available.
|
## Usage
|
||||||
|
|
||||||
### Easy setup with systemd
|
Just run `glorytun` with no arguments to view the list of available commands:
|
||||||
|
|
||||||
Just call `glorytun-setup` and follow the instructions.
|
```
|
||||||
|
$ glorytun
|
||||||
|
available commands:
|
||||||
|
|
||||||
First, setup the server:
|
show show all running tunnels
|
||||||
|
bench start a crypto bench
|
||||||
|
bind start a new tunnel
|
||||||
|
set change tunnel properties
|
||||||
|
keygen generate a new secret key
|
||||||
|
path manage paths
|
||||||
|
version show version
|
||||||
|
|
||||||
$ sudo glorytun-setup
|
```
|
||||||
Config filename (tun0):
|
|
||||||
Server ip (enter for server conf):
|
|
||||||
Bind to port (5000):
|
|
||||||
Server key (enter to generate a new one):
|
|
||||||
Your new key: NEW_KEY
|
|
||||||
Start glorytun now ? (enter to skip): y
|
|
||||||
|
|
||||||
Copy the new generated key and use it when configuring the client:
|
Use the keyword `help` after a command to show its usage.
|
||||||
|
|
||||||
$ sudo glorytun-setup
|
## Mini HowTo
|
||||||
Config filename (tun0):
|
|
||||||
Server ip (enter for server conf): SERVER_IP
|
|
||||||
Server port (5000):
|
|
||||||
Server key (enter to generate a new one): NEW_KEY
|
|
||||||
Start glorytun now ? (enter to skip): y
|
|
||||||
|
|
||||||
You can check easily if it works by looking at your public ip.
|
Glorytun does not touch the configuration of its network interface (except for the MTU),
|
||||||
To stop the service:
|
It is up to the user to do it according to the tools available
|
||||||
|
on his system (systemd-networkd, netifd, ...).
|
||||||
|
This also allows a wide variety of configurations.
|
||||||
|
|
||||||
$ sudo systemctl stop glorytun@tun0
|
To start a server:
|
||||||
|
|
||||||
|
# (umask 066; glorytun keygen > my_secret_key)
|
||||||
|
# glorytun bind 0.0.0.0 keyfile my_secret_key &
|
||||||
|
|
||||||
|
You should now have an unconfigured network interface (let's say `tun0`).
|
||||||
|
For exemple, the simplest setup with `ifconfig`:
|
||||||
|
|
||||||
|
# ifconfig tun0 10.0.1.1 pointopoint 10.0.1.2 up
|
||||||
|
|
||||||
|
To check if the server is running, simply call `glorytun show`.
|
||||||
|
It will show you all the running tunnels.
|
||||||
|
|
||||||
|
To start a new client, you need to get the secret key generated for the server.
|
||||||
|
Then simply call:
|
||||||
|
|
||||||
|
# glorytun bind 0.0.0.0 to SERVER_IP keyfile my_secret_key &
|
||||||
|
# ifconfig tun0 10.0.1.2 pointopoint 10.0.1.1 up
|
||||||
|
|
||||||
|
Here the tricky part... You need to specify your paths or glorytun will not send anything, it's easy:
|
||||||
|
|
||||||
|
# glorytun path LOCAL_IPADDR up
|
||||||
|
|
||||||
|
Again, to check if your path is working, you can watch its status with `glorytun path`.
|
||||||
|
You should now be able to ping your server with `ping 10.0.1.1`.
|
||||||
|
|
||||||
|
If you have systemd-networkd, you can use the helper program `glorytun-setup`.
|
||||||
|
|
||||||
|
## Thanks
|
||||||
|
|
||||||
|
* @jedisct1 for all his help and the code for MacOS/BSD.
|
||||||
|
* The team OTB (@bessa, @gregdel, @pouulet, @sduponch and @simon) for all tests and discussions.
|
||||||
|
* OVH
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
2
argz
2
argz
Submodule argz updated: 2d6a6d635f...3ee68b227f
@@ -4,7 +4,6 @@ AC_INIT([glorytun],
|
|||||||
[https://github.com/angt/glorytun/issues],
|
[https://github.com/angt/glorytun/issues],
|
||||||
[glorytun],
|
[glorytun],
|
||||||
[https://github.com/angt/glorytun])
|
[https://github.com/angt/glorytun])
|
||||||
AC_DEFINE_UNQUOTED([VERSION_MAJOR], [m4_esyscmd([./version.sh major])])
|
|
||||||
AC_CONFIG_SRCDIR([src/common.h])
|
AC_CONFIG_SRCDIR([src/common.h])
|
||||||
AC_CONFIG_AUX_DIR([build-aux])
|
AC_CONFIG_AUX_DIR([build-aux])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|||||||
2
mud
2
mud
Submodule mud updated: ef319d2153...964672adb5
@@ -105,7 +105,7 @@ gt_bench(int argc, char **argv)
|
|||||||
double mbps_max = 0.0;
|
double mbps_max = 0.0;
|
||||||
double mbps_dlt = INFINITY;
|
double mbps_dlt = INFINITY;
|
||||||
|
|
||||||
while (!gt_quit && mbps_dlt > ldexp(mbps, -precision)) {
|
while (!gt_quit && mbps_dlt > ldexp(mbps, -(int)precision)) {
|
||||||
crypto_aead_aes256gcm_state ctx;
|
crypto_aead_aes256gcm_state ctx;
|
||||||
|
|
||||||
if (!chacha)
|
if (!chacha)
|
||||||
|
|||||||
138
src/bind.c
138
src/bind.c
@@ -94,8 +94,6 @@ gt_setup_mtu(struct mud *mud, const char *tun_name)
|
|||||||
if (mtu == oldmtu)
|
if (mtu == oldmtu)
|
||||||
return mtu;
|
return mtu;
|
||||||
|
|
||||||
gt_log("setup MTU to %zu on interface %s\n", mtu, tun_name);
|
|
||||||
|
|
||||||
if (iface_set_mtu(tun_name, mtu) == -1)
|
if (iface_set_mtu(tun_name, mtu) == -1)
|
||||||
perror("tun_set_mtu");
|
perror("tun_set_mtu");
|
||||||
|
|
||||||
@@ -113,8 +111,6 @@ gt_bind(int argc, char **argv)
|
|||||||
unsigned short peer_port = bind_port;
|
unsigned short peer_port = bind_port;
|
||||||
const char *dev = NULL;
|
const char *dev = NULL;
|
||||||
const char *keyfile = NULL;
|
const char *keyfile = NULL;
|
||||||
size_t bufsize = 64 * 1024 * 1024;
|
|
||||||
size_t mtu = 1330;
|
|
||||||
|
|
||||||
struct argz toz[] = {
|
struct argz toz[] = {
|
||||||
{NULL, "IPADDR", &peer_addr, argz_addr},
|
{NULL, "IPADDR", &peer_addr, argz_addr},
|
||||||
@@ -126,19 +122,23 @@ gt_bind(int argc, char **argv)
|
|||||||
{NULL, "PORT", &bind_port, argz_ushort},
|
{NULL, "PORT", &bind_port, argz_ushort},
|
||||||
{"to", NULL, &toz, argz_option},
|
{"to", NULL, &toz, argz_option},
|
||||||
{"dev", "NAME", &dev, argz_str},
|
{"dev", "NAME", &dev, argz_str},
|
||||||
{"mtu", "BYTES", &mtu, argz_bytes},
|
|
||||||
{"keyfile", "FILE", &keyfile, argz_str},
|
{"keyfile", "FILE", &keyfile, argz_str},
|
||||||
{"chacha", NULL, NULL, argz_option},
|
{"chacha", NULL, NULL, argz_option},
|
||||||
{"persist", NULL, NULL, argz_option},
|
{"persist", NULL, NULL, argz_option},
|
||||||
{"bufsize", "BYTES", &bufsize, argz_bytes},
|
|
||||||
{NULL}};
|
{NULL}};
|
||||||
|
|
||||||
if (argz(bindz, argc, argv))
|
if (argz(bindz, argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
if (str_empty(keyfile)) {
|
||||||
|
gt_log("a keyfile is needed!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
gt_set_port((struct sockaddr *)&bind_addr, bind_port);
|
gt_set_port((struct sockaddr *)&bind_addr, bind_port);
|
||||||
gt_set_port((struct sockaddr *)&peer_addr, peer_port);
|
gt_set_port((struct sockaddr *)&peer_addr, peer_port);
|
||||||
|
|
||||||
|
const size_t bufsize = 4096U;
|
||||||
unsigned char *buf = malloc(bufsize);
|
unsigned char *buf = malloc(bufsize);
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
@@ -156,31 +156,23 @@ gt_bind(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_empty(keyfile)) {
|
if (gt_setup_secretkey(mud, keyfile))
|
||||||
if (mud_set_key(mud, NULL, 0)) {
|
return 1;
|
||||||
gt_log("couldn't generate a new key\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (gt_setup_secretkey(mud, keyfile))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!chacha && mud_set_aes(mud)) {
|
if (!chacha && mud_set_aes(mud)) {
|
||||||
gt_log("AES is not available\n");
|
gt_log("AES is not available, enjoy ChaCha20!\n");
|
||||||
chacha = 1;
|
chacha = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char tun_name[64];
|
char tun_name[64];
|
||||||
int tun_fd = tun_create(tun_name, sizeof(tun_name) - 1, dev);
|
const int tun_fd = tun_create(tun_name, sizeof(tun_name) - 1, dev);
|
||||||
|
|
||||||
if (tun_fd == -1) {
|
if (tun_fd == -1) {
|
||||||
gt_log("couldn't create tun device\n");
|
gt_log("couldn't create tun device\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mud_set_mtu(mud, mtu);
|
size_t mtu = gt_setup_mtu(mud, tun_name);
|
||||||
mtu = gt_setup_mtu(mud, tun_name);
|
|
||||||
|
|
||||||
if (tun_set_persist(tun_fd, persist) == -1)
|
if (tun_set_persist(tun_fd, persist) == -1)
|
||||||
perror("tun_set_persist");
|
perror("tun_set_persist");
|
||||||
@@ -192,25 +184,27 @@ gt_bind(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ctl_fd = ctl_create(GT_RUNDIR, tun_name);
|
const int ctl_fd = ctl_create(GT_RUNDIR, tun_name);
|
||||||
|
|
||||||
if (ctl_fd == -1) {
|
if (ctl_fd == -1) {
|
||||||
perror("ctl_create");
|
perror("ctl_create");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mud_fd = mud_get_fd(mud);
|
const int mud_fd = mud_get_fd(mud);
|
||||||
|
|
||||||
fd_set_nonblock(tun_fd);
|
fd_set_nonblock(tun_fd);
|
||||||
fd_set_nonblock(mud_fd);
|
fd_set_nonblock(mud_fd);
|
||||||
fd_set_nonblock(ctl_fd);
|
fd_set_nonblock(ctl_fd);
|
||||||
|
|
||||||
gt_log("running...\n");
|
const long pid = (long)getpid();
|
||||||
|
|
||||||
|
gt_log("running on device %s as pid %li\n", tun_name, pid);
|
||||||
|
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
|
|
||||||
int last_fd = 1 + MAX(tun_fd, MAX(mud_fd, ctl_fd));
|
const int last_fd = 1 + MAX(tun_fd, MAX(mud_fd, ctl_fd));
|
||||||
|
|
||||||
while (!gt_quit) {
|
while (!gt_quit) {
|
||||||
FD_SET(tun_fd, &rfds);
|
FD_SET(tun_fd, &rfds);
|
||||||
@@ -263,6 +257,7 @@ gt_bind(int argc, char **argv)
|
|||||||
perror("sendto(ctl)");
|
perror("sendto(ctl)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(paths);
|
||||||
res.ret = 0;
|
res.ret = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -288,6 +283,7 @@ gt_bind(int argc, char **argv)
|
|||||||
res.ret = errno;
|
res.ret = errno;
|
||||||
break;
|
break;
|
||||||
case CTL_STATUS:
|
case CTL_STATUS:
|
||||||
|
res.status.pid = pid;
|
||||||
res.status.mtu = mtu;
|
res.status.mtu = mtu;
|
||||||
res.status.chacha = chacha;
|
res.status.chacha = chacha;
|
||||||
res.status.bind = bind_addr;
|
res.status.bind = bind_addr;
|
||||||
@@ -303,88 +299,30 @@ gt_bind(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(tun_fd, &rfds)) {
|
if (FD_ISSET(tun_fd, &rfds)) {
|
||||||
size_t size = 0;
|
struct ip_common ic;
|
||||||
|
const int r = tun_read(tun_fd, buf, bufsize);
|
||||||
|
|
||||||
while (bufsize - size >= mtu) {
|
if (r <= 0) {
|
||||||
const int r = tun_read(tun_fd, &buf[size], bufsize - size);
|
if (r == -1 && errno != EAGAIN)
|
||||||
|
perror("tun_read");
|
||||||
if (r <= 0 || r > mtu)
|
} else if ((!ip_get_common(&ic, buf, r)) &&
|
||||||
break;
|
(mud_send(mud, buf, r, ic.tc) == -1)) {
|
||||||
|
if (errno != EAGAIN)
|
||||||
struct ip_common ic;
|
perror("mud_send");
|
||||||
|
|
||||||
if (ip_get_common(&ic, &buf[size], r) || ic.size != r)
|
|
||||||
break;
|
|
||||||
|
|
||||||
size += r;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t p = 0;
|
|
||||||
|
|
||||||
while (p < size) {
|
|
||||||
size_t q = p;
|
|
||||||
int tc = 0;
|
|
||||||
|
|
||||||
while (q < size) {
|
|
||||||
struct ip_common ic;
|
|
||||||
|
|
||||||
if ((ip_get_common(&ic, &buf[q], size - q)) ||
|
|
||||||
(ic.size > size - q))
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (q + ic.size > p + mtu)
|
|
||||||
break;
|
|
||||||
|
|
||||||
q += ic.size;
|
|
||||||
|
|
||||||
if (tc < (ic.tc & 0xFC))
|
|
||||||
tc = ic.tc & 0xFC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p >= q)
|
|
||||||
break;
|
|
||||||
|
|
||||||
int r = mud_send(mud, &buf[p], q - p, tc);
|
|
||||||
|
|
||||||
if (r == -1) {
|
|
||||||
if (errno == EMSGSIZE) {
|
|
||||||
mtu = gt_setup_mtu(mud, tun_name);
|
|
||||||
} else if (errno != EAGAIN) {
|
|
||||||
perror("mud_send");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p = q;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(mud_fd, &rfds)) {
|
if (FD_ISSET(mud_fd, &rfds)) {
|
||||||
size_t size = 0;
|
struct ip_common ic;
|
||||||
|
const int r = mud_recv(mud, buf, bufsize);
|
||||||
|
|
||||||
while (bufsize - size >= mtu) {
|
if (r <= 0) {
|
||||||
const int r = mud_recv(mud, &buf[size], bufsize - size);
|
if (r == -1 && errno != EAGAIN)
|
||||||
|
perror("mud_recv");
|
||||||
if (r <= 0) {
|
} else if ((!ip_get_common(&ic, buf, r)) &&
|
||||||
if (r == -1 && errno != EAGAIN)
|
(tun_write(tun_fd, buf, r) == -1)) {
|
||||||
perror("mud_recv");
|
if (errno != EAGAIN)
|
||||||
break;
|
perror("tun_write");
|
||||||
}
|
|
||||||
|
|
||||||
size += r;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t p = 0;
|
|
||||||
|
|
||||||
while (p < size) {
|
|
||||||
struct ip_common ic;
|
|
||||||
|
|
||||||
if ((ip_get_common(&ic, &buf[p], size - p)) ||
|
|
||||||
(ic.size > size - p))
|
|
||||||
break;
|
|
||||||
|
|
||||||
tun_write(tun_fd, &buf[p], ic.size);
|
|
||||||
|
|
||||||
p += ic.size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -394,7 +332,9 @@ gt_bind(int argc, char **argv)
|
|||||||
perror("tun_set_persist");
|
perror("tun_set_persist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mud_delete(mud);
|
||||||
ctl_delete(ctl_fd);
|
ctl_delete(ctl_fd);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ gt_get_port(struct sockaddr *sa)
|
|||||||
int
|
int
|
||||||
gt_toaddr(char *str, size_t size, struct sockaddr *sa)
|
gt_toaddr(char *str, size_t size, struct sockaddr *sa)
|
||||||
{
|
{
|
||||||
|
if (str)
|
||||||
|
str[0] = 0;
|
||||||
|
|
||||||
switch (sa->sa_family) {
|
switch (sa->sa_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
return -!inet_ntop(AF_INET,
|
return -!inet_ntop(AF_INET,
|
||||||
|
|||||||
21
src/ctl.c
21
src/ctl.c
@@ -133,13 +133,15 @@ ctl_create(const char *dir, const char *file)
|
|||||||
int
|
int
|
||||||
ctl_connect(const char *dir, const char *file)
|
ctl_connect(const char *dir, const char *file)
|
||||||
{
|
{
|
||||||
|
DIR *dp = NULL;
|
||||||
|
|
||||||
if (str_empty(dir)) {
|
if (str_empty(dir)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
DIR *dp = opendir(dir);
|
dp = opendir(dir);
|
||||||
|
|
||||||
if (!dp)
|
if (!dp)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -152,19 +154,28 @@ ctl_connect(const char *dir, const char *file)
|
|||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
errno = ENOENT;
|
return -3;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file = &d->d_name[0];
|
file = &d->d_name[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dp);
|
if (!file) {
|
||||||
|
closedir(dp);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr_un sun;
|
struct sockaddr_un sun;
|
||||||
|
const int ret = ctl_setsun(&sun, dir, file);
|
||||||
|
|
||||||
if (ctl_setsun(&sun, dir, file))
|
if (dp) {
|
||||||
|
int err = errno;
|
||||||
|
closedir(dp);
|
||||||
|
errno = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int fd = ctl_create(dir, NULL);
|
int fd = ctl_create(dir, NULL);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ struct ctl_msg {
|
|||||||
} path;
|
} path;
|
||||||
struct mud_path path_status;
|
struct mud_path path_status;
|
||||||
struct {
|
struct {
|
||||||
|
long pid;
|
||||||
size_t mtu;
|
size_t mtu;
|
||||||
int chacha;
|
int chacha;
|
||||||
struct sockaddr_storage bind;
|
struct sockaddr_storage bind;
|
||||||
|
|||||||
55
src/ip.h
55
src/ip.h
@@ -3,32 +3,16 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct ip_common {
|
struct ip_common {
|
||||||
uint8_t version;
|
|
||||||
uint8_t tc;
|
uint8_t tc;
|
||||||
uint8_t proto;
|
uint8_t proto;
|
||||||
uint8_t hdr_size;
|
|
||||||
uint16_t size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_pure_ static inline uint8_t
|
static inline uint8_t
|
||||||
ip_get_version(const uint8_t *data, size_t size)
|
ip_get_version(const uint8_t *data)
|
||||||
{
|
{
|
||||||
if (size < 20)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return data[0] >> 4;
|
return data[0] >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t
|
|
||||||
ip_read32(const uint8_t *src)
|
|
||||||
{
|
|
||||||
uint32_t ret = src[3];
|
|
||||||
ret |= ((uint32_t)src[2]) << 8;
|
|
||||||
ret |= ((uint32_t)src[1]) << 16;
|
|
||||||
ret |= ((uint32_t)src[0]) << 24;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint16_t
|
static inline uint16_t
|
||||||
ip_read16(const uint8_t *src)
|
ip_read16(const uint8_t *src)
|
||||||
{
|
{
|
||||||
@@ -37,45 +21,22 @@ ip_read16(const uint8_t *src)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline size_t
|
|
||||||
ip_get_mtu(struct ip_common *ic, const uint8_t *data, size_t size)
|
|
||||||
{
|
|
||||||
if (ic->hdr_size <= 0 || ic->hdr_size + 8 > size)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
const uint8_t *p = &data[ic->hdr_size];
|
|
||||||
|
|
||||||
if (ic->version == 4 && ic->proto == 1 && p[0] == 3)
|
|
||||||
return ip_read16(&p[6]);
|
|
||||||
|
|
||||||
// not tested..
|
|
||||||
// if (ic->version == 6 && ic->proto == 58 && p[0] == 2)
|
|
||||||
// return ip_read32(&p[4]);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
ip_get_common(struct ip_common *ic, const uint8_t *data, size_t size)
|
ip_get_common(struct ip_common *ic, const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
ic->version = ip_get_version(data, size);
|
if (size < 20)
|
||||||
|
return 1;
|
||||||
|
|
||||||
switch (ic->version) {
|
switch (ip_get_version(data)) {
|
||||||
case 4:
|
case 4:
|
||||||
ic->tc = data[1];
|
ic->tc = data[1];
|
||||||
ic->proto = data[9];
|
ic->proto = data[9];
|
||||||
ic->hdr_size = (data[0] & 0xF) << 2;
|
return size != ip_read16(&data[2]);
|
||||||
ic->size = ip_read16(&data[2]);
|
|
||||||
if (ic->size >= 20)
|
|
||||||
return 0;
|
|
||||||
break;
|
|
||||||
case 6:
|
case 6:
|
||||||
ic->tc = ((data[0] & 0xF) << 4) | (data[1] >> 4);
|
ic->tc = ((data[0] & 0xF) << 4) | (data[1] >> 4);
|
||||||
ic->proto = data[6];
|
ic->proto = data[6];
|
||||||
ic->hdr_size = 40;
|
return size != ip_read16(&data[4]) + 40;
|
||||||
ic->size = ip_read16(&data[4]) + 40;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/main.c
13
src/main.c
@@ -69,15 +69,14 @@ main(int argc, char **argv)
|
|||||||
{"version", "show version", gt_version},
|
{"version", "show version", gt_version},
|
||||||
{NULL}};
|
{NULL}};
|
||||||
|
|
||||||
if (argc < 2)
|
if (argv[1]) {
|
||||||
return gt_show(argc, argv);
|
for (int k = 0; cmd[k].name; k++) {
|
||||||
|
if (!str_cmp(cmd[k].name, argv[1]))
|
||||||
for (int k = 0; cmd[k].name; k++) {
|
return cmd[k].call(argc - 1, argv + 1);
|
||||||
if (!str_cmp(cmd[k].name, argv[1]))
|
}
|
||||||
return cmd[k].call(argc - 1, argv + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("unknown command `%s', available commands:\n\n", argv[1]);
|
printf("available commands:\n\n");
|
||||||
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
|
|||||||
73
src/path.c
73
src/path.c
@@ -27,17 +27,16 @@ gt_path_status(int fd)
|
|||||||
if (!res.ret)
|
if (!res.ret)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
char bindstr[INET6_ADDRSTRLEN] = {0};
|
char bindstr[INET6_ADDRSTRLEN];
|
||||||
char publstr[INET6_ADDRSTRLEN] = {0};
|
char publstr[INET6_ADDRSTRLEN];
|
||||||
char peerstr[INET6_ADDRSTRLEN] = {0};
|
char peerstr[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
if (gt_toaddr(bindstr, sizeof(bindstr),
|
gt_toaddr(bindstr, sizeof(bindstr),
|
||||||
(struct sockaddr *)&res.path_status.local_addr) ||
|
(struct sockaddr *)&res.path_status.local_addr);
|
||||||
gt_toaddr(publstr, sizeof(publstr),
|
gt_toaddr(publstr, sizeof(publstr),
|
||||||
(struct sockaddr *)&res.path_status.r_addr) ||
|
(struct sockaddr *)&res.path_status.r_addr);
|
||||||
gt_toaddr(peerstr, sizeof(peerstr),
|
gt_toaddr(peerstr, sizeof(peerstr),
|
||||||
(struct sockaddr *)&res.path_status.addr))
|
(struct sockaddr *)&res.path_status.addr);
|
||||||
return -2;
|
|
||||||
|
|
||||||
const char *statestr = NULL;
|
const char *statestr = NULL;
|
||||||
|
|
||||||
@@ -49,17 +48,32 @@ gt_path_status(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("path %s\n"
|
printf("path %s\n"
|
||||||
" bind: %s\n"
|
" bind: %s port %"PRIu16"\n"
|
||||||
" public: %s port %"PRIu16"\n"
|
" public: %s port %"PRIu16"\n"
|
||||||
" peer: %s port %"PRIu16"\n"
|
" peer: %s port %"PRIu16"\n"
|
||||||
" mtu: %zu bytes\n"
|
" mtu: %zu bytes\n"
|
||||||
" rtt: %.3f ms\n",
|
" rtt: %.3f ms\n"
|
||||||
statestr, bindstr,
|
" rttvar: %.3f ms\n"
|
||||||
publstr, gt_get_port((struct sockaddr *)&res.path_status.r_addr),
|
" upload: %"PRIu64" bytes/s (max: %"PRIu64")\n"
|
||||||
peerstr, gt_get_port((struct sockaddr *)&res.path_status.addr),
|
" download: %"PRIu64" bytes/s (max: %"PRIu64")\n"
|
||||||
res.path_status.mtu.ok + 28U, /* ip+udp hdr */
|
" output: %"PRIu64" packets\n"
|
||||||
res.path_status.rtt/(double)1e3);
|
" input: %"PRIu64" packets\n",
|
||||||
|
statestr,
|
||||||
|
bindstr[0] ? bindstr : "-",
|
||||||
|
gt_get_port((struct sockaddr *)&res.path_status.local_addr),
|
||||||
|
publstr[0] ? publstr : "-",
|
||||||
|
gt_get_port((struct sockaddr *)&res.path_status.r_addr),
|
||||||
|
peerstr[0] ? peerstr : "-",
|
||||||
|
gt_get_port((struct sockaddr *)&res.path_status.addr),
|
||||||
|
res.path_status.mtu.ok,
|
||||||
|
res.path_status.rtt/(double)1e3,
|
||||||
|
res.path_status.rttvar/(double)1e3,
|
||||||
|
res.path_status.r_rate,
|
||||||
|
res.path_status.r_ratemax,
|
||||||
|
res.path_status.recv.rate,
|
||||||
|
res.path_status.recv.ratemax,
|
||||||
|
res.path_status.send.total,
|
||||||
|
res.path_status.recv.total);
|
||||||
} while (res.ret == EAGAIN);
|
} while (res.ret == EAGAIN);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -85,9 +99,20 @@ gt_path(int argc, char **argv)
|
|||||||
|
|
||||||
int fd = ctl_connect(GT_RUNDIR, dev);
|
int fd = ctl_connect(GT_RUNDIR, dev);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd < 0) {
|
||||||
perror("path");
|
switch (fd) {
|
||||||
ctl_delete(fd);
|
case -1:
|
||||||
|
perror("path");
|
||||||
|
break;
|
||||||
|
case -2:
|
||||||
|
gt_log("no device\n");
|
||||||
|
break;
|
||||||
|
case -3:
|
||||||
|
gt_log("please choose a device\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gt_log("couldn't connect\n");
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/set.c
16
src/set.c
@@ -149,8 +149,20 @@ gt_set(int argc, char **argv)
|
|||||||
|
|
||||||
int fd = ctl_connect(GT_RUNDIR, dev);
|
int fd = ctl_connect(GT_RUNDIR, dev);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd < 0) {
|
||||||
perror("set");
|
switch (fd) {
|
||||||
|
case -1:
|
||||||
|
perror("set");
|
||||||
|
break;
|
||||||
|
case -2:
|
||||||
|
gt_log("no device\n");
|
||||||
|
break;
|
||||||
|
case -3:
|
||||||
|
gt_log("please choose a device\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
gt_log("couldn't connect\n");
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
src/show.c
27
src/show.c
@@ -18,34 +18,40 @@ gt_show_dev_status(int fd, const char *dev)
|
|||||||
if (ctl_reply(fd, &res, &req))
|
if (ctl_reply(fd, &res, &req))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
char bindstr[INET6_ADDRSTRLEN] = {0};
|
char bindstr[INET6_ADDRSTRLEN];
|
||||||
char peerstr[INET6_ADDRSTRLEN] = {0};
|
char peerstr[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
if (gt_toaddr(bindstr, sizeof(bindstr),
|
gt_toaddr(bindstr, sizeof(bindstr),
|
||||||
(struct sockaddr *)&res.status.bind))
|
(struct sockaddr *)&res.status.bind);
|
||||||
return -2;
|
|
||||||
|
|
||||||
int server = gt_toaddr(peerstr, sizeof(peerstr),
|
int server = gt_toaddr(peerstr, sizeof(peerstr),
|
||||||
(struct sockaddr *)&res.status.peer);
|
(struct sockaddr *)&res.status.peer);
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
printf("server %s:\n"
|
printf("server %s:\n"
|
||||||
|
" pid: %li\n"
|
||||||
" bind: %s port %"PRIu16"\n"
|
" bind: %s port %"PRIu16"\n"
|
||||||
" mtu: %zu\n"
|
" mtu: %zu\n"
|
||||||
" cipher: %s\n",
|
" cipher: %s\n",
|
||||||
dev,
|
dev,
|
||||||
bindstr, gt_get_port((struct sockaddr *)&res.status.bind),
|
res.status.pid,
|
||||||
|
bindstr[0] ? bindstr : "-",
|
||||||
|
gt_get_port((struct sockaddr *)&res.status.bind),
|
||||||
res.status.mtu,
|
res.status.mtu,
|
||||||
res.status.chacha ? "chacha20poly1305" : "aes256gcm");
|
res.status.chacha ? "chacha20poly1305" : "aes256gcm");
|
||||||
} else {
|
} else {
|
||||||
printf("client %s:\n"
|
printf("client %s:\n"
|
||||||
|
" pid: %li\n"
|
||||||
" bind: %s port %"PRIu16"\n"
|
" bind: %s port %"PRIu16"\n"
|
||||||
" peer: %s port %"PRIu16"\n"
|
" peer: %s port %"PRIu16"\n"
|
||||||
" mtu: %zu\n"
|
" mtu: %zu\n"
|
||||||
" cipher: %s\n",
|
" cipher: %s\n",
|
||||||
dev,
|
dev,
|
||||||
bindstr, gt_get_port((struct sockaddr *)&res.status.bind),
|
res.status.pid,
|
||||||
peerstr, gt_get_port((struct sockaddr *)&res.status.peer),
|
bindstr[0] ? bindstr : "-",
|
||||||
|
gt_get_port((struct sockaddr *)&res.status.bind),
|
||||||
|
peerstr[0] ? peerstr : "-",
|
||||||
|
gt_get_port((struct sockaddr *)&res.status.peer),
|
||||||
res.status.mtu,
|
res.status.mtu,
|
||||||
res.status.chacha ? "chacha20poly1305" : "aes256gcm");
|
res.status.chacha ? "chacha20poly1305" : "aes256gcm");
|
||||||
}
|
}
|
||||||
@@ -58,8 +64,9 @@ gt_show_dev(const char *dev)
|
|||||||
{
|
{
|
||||||
int fd = ctl_connect(GT_RUNDIR, dev);
|
int fd = ctl_connect(GT_RUNDIR, dev);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd < 0) {
|
||||||
perror(dev);
|
if (fd == -1)
|
||||||
|
perror("show");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ tun_write(int fd, const void *data, size_t size)
|
|||||||
#ifdef GT_BSD_TUN
|
#ifdef GT_BSD_TUN
|
||||||
uint32_t family;
|
uint32_t family;
|
||||||
|
|
||||||
switch (ip_get_version(data, size)) {
|
switch (ip_get_version(data)) {
|
||||||
case 4:
|
case 4:
|
||||||
family = htonl(AF_INET);
|
family = htonl(AF_INET);
|
||||||
break;
|
break;
|
||||||
|
|||||||
13
version.sh
13
version.sh
@@ -1,13 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
[ -z "${VERSION}" ] && VERSION=`git describe --tags --match='v[0-9].*' 2>/dev/null` \
|
[ -z "${VERSION}" ] && VERSION="$(git describe --tags --match='v[0-9].*' 2>/dev/null)" \
|
||||||
&& VERSION=${VERSION#v}
|
&& VERSION="${VERSION#v}"
|
||||||
|
|
||||||
[ -z "${VERSION}" ] && VERSION=`cat VERSION 2>/dev/null`
|
[ -z "${VERSION}" ] && VERSION="$(git rev-parse HEAD 2>/dev/null)"
|
||||||
|
|
||||||
[ -z "${VERSION}" ] && VERSION=0.0.0
|
[ -z "${VERSION}" ] && VERSION="$(cat VERSION 2>/dev/null)"
|
||||||
|
|
||||||
[ "$1" = "major" ] && printf ${VERSION%%.*} \
|
[ -z "${VERSION}" ] && VERSION="0.0.0"
|
||||||
&& exit 0
|
|
||||||
|
|
||||||
printf ${VERSION} | tee VERSION
|
printf "%s" "${VERSION}" | tee VERSION
|
||||||
|
|||||||
Reference in New Issue
Block a user