Compare commits
7 Commits
v0.0.42-mu
...
v0.0.49-mu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b232a101d2 | ||
|
|
a01dc81500 | ||
|
|
1db628d84a | ||
|
|
f11cd34dc4 | ||
|
|
d0376e3aa5 | ||
|
|
a7518c0e5a | ||
|
|
378316bd68 |
2
mud
2
mud
Submodule mud updated: 2c4443a823...5c77233093
61
src/main.c
61
src/main.c
@@ -245,6 +245,8 @@ 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;
|
||||||
@@ -258,6 +260,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 },
|
||||||
@@ -359,7 +362,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 +386,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 +409,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 +419,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