Compare commits

...

7 Commits

Author SHA1 Message Date
Adrien Gallouët
b232a101d2 Update mud 2016-06-30 09:41:32 +00:00
Adrien Gallouët
a01dc81500 Don't wait too long when we have data to send 2016-06-27 11:19:16 +00:00
Adrien Gallouët
1db628d84a Update mud 2016-06-24 13:21:02 +00:00
Adrien Gallouët
f11cd34dc4 Update mud 2016-06-22 17:55:18 +00:00
Adrien Gallouët
d0376e3aa5 Update mud 2016-06-22 09:18:34 +00:00
Adrien Gallouët
a7518c0e5a Update mud 2016-06-21 16:51:24 +00:00
Adrien Gallouët
378316bd68 Add mtu option 2016-06-13 15:43:45 +00:00
2 changed files with 50 additions and 13 deletions

2
mud

Submodule mud updated: 2c4443a823...5c77233093

View File

@@ -245,6 +245,8 @@ int main (int argc, char **argv)
char *keyfile = NULL;
char *statefile = NULL;
long mtu = 1450;
gt.timeout = 5000;
long time_tolerance = 0;
@@ -258,6 +260,7 @@ int main (int argc, char **argv)
{ "bind", &bind_list, option_str },
{ "bind-port", &bind_port, option_long },
{ "dev", &dev, option_str },
{ "mtu", &mtu, option_long },
{ "keyfile", &keyfile, option_str },
{ "multiqueue", NULL, option_option },
{ "statefile", &statefile, option_str },
@@ -359,7 +362,16 @@ int main (int argc, char **argv)
FD_ZERO(&rfds);
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) {
FD_SET(tun_fd, &rfds);
@@ -374,7 +386,7 @@ int main (int argc, char **argv)
.tv_usec = 100000,
};
if (mud_can_push(mud))
if (mud_can_push(mud) || send_size)
timeout.tv_usec = 1000;
if _0_(select(mud_fd+1, &rfds, NULL, NULL, &timeout)==-1) {
@@ -397,8 +409,8 @@ int main (int argc, char **argv)
}
if (FD_ISSET(tun_fd, &rfds)) {
while (1) {
const ssize_t r = tun_read(tun_fd, buf, sizeof(buf));
while (send_size<mtu) {
const ssize_t r = tun_read(tun_fd, send.buf+send_size, mtu);
if (r<=0) {
gt.quit |= !r;
@@ -407,27 +419,52 @@ int main (int argc, char **argv)
struct ip_common ic;
if (!ip_get_common(&ic, buf, sizeof(buf)) && ic.size==r)
mud_send(mud, buf, r);
if (ip_get_common(&ic, send.buf+send_size, mtu) || ic.size!=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);
if (FD_ISSET(mud_fd, &rfds))
mud_pull(mud);
while (1) {
const int size = mud_recv(mud, buf, sizeof(buf));
while (!gt.quit) {
const int size = mud_recv(mud, recv.buf, mtu);
if (size<=0)
break;
const ssize_t r = tun_write(tun_fd, buf, size);
int p = 0;
if (r<=0) {
gt.quit |= !r;
break;
while (p<size) {
struct ip_common ic;
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;
}
}
}