Update and fix MTU

This commit is contained in:
Adrien Gallouët
2016-12-21 16:14:40 +00:00
parent bd102c5fb0
commit 234f0d8592
2 changed files with 22 additions and 17 deletions

2
mud

Submodule mud updated: b5a5cb2f1f...fe5499d46d

View File

@@ -24,6 +24,8 @@
#define O_CLOEXEC 0
#endif
#define GT_MTU(X) ((X) - 28)
static struct {
volatile sig_atomic_t quit;
char *dev;
@@ -48,7 +50,6 @@ static struct {
.bind = {
.port = 5000,
},
.mtu = 1450,
.timeout = 5000,
.ipv4 = 1,
#ifdef __linux__
@@ -167,8 +168,9 @@ gt_setup_secretkey(struct mud *mud, char *keyfile)
static int
gt_setup_option(int argc, char **argv)
{
struct option opts[] = {
// clang-format off
struct option opts[] = {
{ "host", &gt.host, option_str },
{ "port", &gt.port, option_long },
{ "bind", &gt.bind.list, option_str },
@@ -185,9 +187,10 @@ gt_setup_option(int argc, char **argv)
{ "chacha20", NULL, option_option },
{ "version", NULL, option_option },
{ NULL },
// clang-format on
};
// clang-format on
if (option(opts, argc, argv))
return 1;
@@ -257,13 +260,8 @@ main(int argc, char **argv)
return 1;
}
if (tun_set_mtu(tun_name, gt.mtu) == -1) {
perror("tun_set_mtu");
return 1;
}
struct mud *mud = mud_create(gt.bind.port, gt.ipv4, gt.ipv6,
!gt.chacha20, gt.mtu);
!gt.chacha20, GT_MTU(gt.mtu));
if (!mud) {
gt_log("couldn't create mud\n");
@@ -315,6 +313,13 @@ main(int argc, char **argv)
}
}
gt.mtu = GT_MTU(mud_get_mtu(mud));
if (tun_set_mtu(tun_name, gt.mtu) == -1) {
perror("tun_set_mtu");
return 1;
}
int mud_fd = mud_get_fd(mud);
fd_set_nonblock(tun_fd);
@@ -356,7 +361,7 @@ main(int argc, char **argv)
int mtu = (data[6] << 8) | data[7];
if (mtu) {
gt_log("received MTU from ICMP: %i\n", mtu);
mud_set_mtu(mud, mtu - 50); // XXX
mud_set_mtu(mud, GT_MTU(mtu));
}
}
}
@@ -407,24 +412,24 @@ main(int argc, char **argv)
int r = mud_send(mud, &buf[p], q - p, tc);
if (r == -1 && errno == EMSGSIZE) {
int mtu = mud_get_mtu(mud);
int mtu = GT_MTU(mud_get_mtu(mud));
if (mtu != gt.mtu) {
if (mtu != (int)gt.mtu) {
gt.mtu = mtu;
gt_log("MTU changed: %li\n", gt.mtu);
gt_log("setup MTU to %i on interface %s\n", mtu, tun_name);
if (tun_set_mtu(tun_name, gt.mtu) == -1)
if (tun_set_mtu(tun_name, mtu) == -1)
perror("tun_set_mtu");
}
} else {
if (r == -1 && errno != EAGAIN)
perror("mud_send");
}
p = q;
}
}
}
if (FD_ISSET(mud_fd, &rfds)) {
while (1) {