Compare commits
14 Commits
v0.0.82-mu
...
v0.0.89-mu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbf1c12f7a | ||
|
|
c54303da8f | ||
|
|
e3440cf1e9 | ||
|
|
86916f1999 | ||
|
|
9cebabfe01 | ||
|
|
0664fc3b21 | ||
|
|
2cb24c0523 | ||
|
|
65be22202c | ||
|
|
6cc32bafd9 | ||
|
|
6c268e658f | ||
|
|
33e24632d0 | ||
|
|
e1b4c6aafc | ||
|
|
09d1932588 | ||
|
|
4988479df4 |
@@ -11,5 +11,8 @@ cd ..
|
|||||||
[ -x glorytun ] || exit 1
|
[ -x glorytun ] || exit 1
|
||||||
|
|
||||||
mkdir -p deploy
|
mkdir -p deploy
|
||||||
|
|
||||||
|
cp glorytun deploy/glorytun-$(cat VERSION)-$(uname -m).debug.bin
|
||||||
|
|
||||||
strip -s glorytun
|
strip -s glorytun
|
||||||
mv glorytun deploy/glorytun-$(cat VERSION)-$(uname -m).bin
|
cp glorytun deploy/glorytun-$(cat VERSION)-$(uname -m).bin
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ glorytun_SOURCES = \
|
|||||||
src/db.c \
|
src/db.c \
|
||||||
src/db.h
|
src/db.h
|
||||||
|
|
||||||
glorytun_CFLAGS += -I$(srcdir)/mud
|
|
||||||
glorytun_SOURCES += \
|
glorytun_SOURCES += \
|
||||||
mud/mud.h \
|
mud/mud.h \
|
||||||
mud/mud.c
|
mud/mud.c
|
||||||
|
|||||||
2
mud
2
mud
Submodule mud updated: 7cc6e7ad72...dfcc08feed
4
src/ip.h
4
src/ip.h
@@ -30,7 +30,9 @@ ip_get_common(struct ip_common *ic, const uint8_t *data, size_t size)
|
|||||||
ic->proto = data[9];
|
ic->proto = data[9];
|
||||||
ic->hdr_size = (data[0] & 0xF) << 2;
|
ic->hdr_size = (data[0] & 0xF) << 2;
|
||||||
ic->size = ((data[2] << 8) | data[3]);
|
ic->size = ((data[2] << 8) | data[3]);
|
||||||
return 0;
|
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];
|
||||||
|
|||||||
71
src/main.c
71
src/main.c
@@ -18,13 +18,13 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
|
||||||
#include "mud.h"
|
#include "../mud/mud.h"
|
||||||
|
|
||||||
#ifndef O_CLOEXEC
|
#ifndef O_CLOEXEC
|
||||||
#define O_CLOEXEC 0
|
#define O_CLOEXEC 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GT_MTU(X) ((X) - 28)
|
#define GT_MTU(X) ((X)-28)
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
volatile sig_atomic_t quit;
|
volatile sig_atomic_t quit;
|
||||||
@@ -45,16 +45,24 @@ static struct {
|
|||||||
int mtu_auto;
|
int mtu_auto;
|
||||||
int chacha20;
|
int chacha20;
|
||||||
int version;
|
int version;
|
||||||
|
struct {
|
||||||
|
unsigned char *data;
|
||||||
|
long size;
|
||||||
|
} buf;
|
||||||
} gt = {
|
} gt = {
|
||||||
.port = 5000,
|
.port = 5000,
|
||||||
.bind = {
|
.bind = {
|
||||||
.port = 5000,
|
.port = 5000,
|
||||||
},
|
},
|
||||||
|
.mtu = 1500,
|
||||||
.timeout = 5000,
|
.timeout = 5000,
|
||||||
.ipv4 = 1,
|
.ipv4 = 1,
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
.ipv6 = 1,
|
.ipv6 = 1,
|
||||||
#endif
|
#endif
|
||||||
|
.buf = {
|
||||||
|
.size = 64 * 1024,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -185,6 +193,7 @@ gt_setup_option(int argc, char **argv)
|
|||||||
{ "v4only", NULL, option_option },
|
{ "v4only", NULL, option_option },
|
||||||
{ "v6only", NULL, option_option },
|
{ "v6only", NULL, option_option },
|
||||||
{ "chacha20", NULL, option_option },
|
{ "chacha20", NULL, option_option },
|
||||||
|
{ "buf-size", >.buf.size, option_long },
|
||||||
{ "version", NULL, option_option },
|
{ "version", NULL, option_option },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
@@ -212,6 +221,11 @@ gt_setup_option(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gt.buf.size <= 0) {
|
||||||
|
gt_log("bad buf-size\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (v4only) {
|
if (v4only) {
|
||||||
gt.ipv4 = 1;
|
gt.ipv4 = 1;
|
||||||
gt.ipv6 = 0;
|
gt.ipv6 = 0;
|
||||||
@@ -226,6 +240,8 @@ gt_setup_option(int argc, char **argv)
|
|||||||
gt.chacha20 = option_is_set(opts, "chacha20");
|
gt.chacha20 = option_is_set(opts, "chacha20");
|
||||||
gt.version = option_is_set(opts, "version");
|
gt.version = option_is_set(opts, "version");
|
||||||
|
|
||||||
|
gt.buf.data = malloc(gt.buf.size);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,8 +360,6 @@ main(int argc, char **argv)
|
|||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
|
|
||||||
unsigned char buf[8 * 1024];
|
|
||||||
|
|
||||||
int last_fd = 1 + MAX(tun_fd, MAX(mud_fd, icmp_fd));
|
int last_fd = 1 + MAX(tun_fd, MAX(mud_fd, icmp_fd));
|
||||||
|
|
||||||
while (!gt.quit) {
|
while (!gt.quit) {
|
||||||
@@ -365,12 +379,12 @@ main(int argc, char **argv)
|
|||||||
if (icmp_fd != -1 && FD_ISSET(icmp_fd, &rfds)) {
|
if (icmp_fd != -1 && FD_ISSET(icmp_fd, &rfds)) {
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
socklen_t sl = sizeof(ss);
|
socklen_t sl = sizeof(ss);
|
||||||
ssize_t r = recvfrom(icmp_fd, buf, sizeof(buf), 0,
|
ssize_t r = recvfrom(icmp_fd, gt.buf.data, gt.buf.size, 0,
|
||||||
(struct sockaddr *)&ss, &sl);
|
(struct sockaddr *)&ss, &sl);
|
||||||
if (r >= 8) {
|
if (r >= 8) {
|
||||||
struct ip_common ic;
|
struct ip_common ic;
|
||||||
if (!ip_get_common(&ic, buf, r) && ic.proto == 1) {
|
if (!ip_get_common(&ic, gt.buf.data, r) && ic.proto == 1) {
|
||||||
unsigned char *data = &buf[ic.hdr_size];
|
unsigned char *data = >.buf.data[ic.hdr_size];
|
||||||
if (data[0] == 3) {
|
if (data[0] == 3) {
|
||||||
int mtu = (data[6] << 8) | data[7];
|
int mtu = (data[6] << 8) | data[7];
|
||||||
if (mtu) {
|
if (mtu) {
|
||||||
@@ -385,16 +399,15 @@ main(int argc, char **argv)
|
|||||||
if (FD_ISSET(tun_fd, &rfds)) {
|
if (FD_ISSET(tun_fd, &rfds)) {
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
while (sizeof(buf) - size >= gt.mtu) {
|
while (gt.buf.size - size >= gt.mtu) {
|
||||||
const int r = tun_read(tun_fd, &buf[size],
|
const int r = tun_read(tun_fd, >.buf.data[size], gt.buf.size - size);
|
||||||
sizeof(buf) - size);
|
|
||||||
|
|
||||||
if (r <= 0 || r > gt.mtu)
|
if (r <= 0 || r > gt.mtu)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
struct ip_common ic;
|
struct ip_common ic;
|
||||||
|
|
||||||
if (ip_get_common(&ic, &buf[size], r) || ic.size != r)
|
if (ip_get_common(&ic, >.buf.data[size], r) || ic.size != r)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
size += r;
|
size += r;
|
||||||
@@ -409,7 +422,7 @@ main(int argc, char **argv)
|
|||||||
while (q < size) {
|
while (q < size) {
|
||||||
struct ip_common ic;
|
struct ip_common ic;
|
||||||
|
|
||||||
if ((ip_get_common(&ic, &buf[q], size - q)) ||
|
if ((ip_get_common(&ic, >.buf.data[q], size - q)) ||
|
||||||
(ic.size > size - q))
|
(ic.size > size - q))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -422,10 +435,10 @@ main(int argc, char **argv)
|
|||||||
tc = ic.tc & 0xFC;
|
tc = ic.tc & 0xFC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p == q)
|
if (p >= q)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
int r = mud_send(mud, &buf[p], q - p, tc);
|
int r = mud_send(mud, >.buf.data[p], q - p, tc);
|
||||||
|
|
||||||
if (r == -1 && errno == EMSGSIZE) {
|
if (r == -1 && errno == EMSGSIZE) {
|
||||||
gt_setup_mtu(mud, tun_name);
|
gt_setup_mtu(mud, tun_name);
|
||||||
@@ -439,28 +452,32 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(mud_fd, &rfds)) {
|
if (FD_ISSET(mud_fd, &rfds)) {
|
||||||
while (1) {
|
size_t size = 0;
|
||||||
const int size = mud_recv(mud, buf, sizeof(buf));
|
|
||||||
|
|
||||||
if (size <= 0) {
|
while (gt.buf.size - size >= gt.mtu) {
|
||||||
if (size == -1 && errno != EAGAIN)
|
const int r = mud_recv(mud, >.buf.data[size], gt.buf.size - size);
|
||||||
|
|
||||||
|
if (r <= 0) {
|
||||||
|
if (r == -1 && errno != EAGAIN)
|
||||||
perror("mud_recv");
|
perror("mud_recv");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int p = 0;
|
size += r;
|
||||||
|
}
|
||||||
|
|
||||||
while (p < size) {
|
int p = 0;
|
||||||
struct ip_common ic;
|
|
||||||
|
|
||||||
if ((ip_get_common(&ic, &buf[p], size - p)) ||
|
while (p < size) {
|
||||||
(ic.size > size - p))
|
struct ip_common ic;
|
||||||
break;
|
|
||||||
|
|
||||||
tun_write(tun_fd, &buf[p], ic.size);
|
if ((ip_get_common(&ic, >.buf.data[p], size - p)) ||
|
||||||
|
(ic.size > size - p))
|
||||||
|
break;
|
||||||
|
|
||||||
p += ic.size;
|
tun_write(tun_fd, >.buf.data[p], ic.size);
|
||||||
}
|
|
||||||
|
p += ic.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user