From 0e052dc2db1f71ba0538b06cea7f2701727d4963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Thu, 29 Nov 2018 22:22:29 +0000 Subject: [PATCH] Update mud MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud | 2 +- src/bind.c | 47 +++++++++++++++++++++++++++++------------------ src/path.c | 6 +++--- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/mud b/mud index ff55d6a..79688de 160000 --- a/mud +++ b/mud @@ -1 +1 @@ -Subproject commit ff55d6a17356947a6479d2d926c9addd08de116c +Subproject commit 79688de09e0c80fe3015dad23853e50401fa391e diff --git a/src/bind.c b/src/bind.c index 9e3cca7..fef5786 100644 --- a/src/bind.c +++ b/src/bind.c @@ -209,15 +209,23 @@ gt_bind(int argc, char **argv) unsigned char buf[4096]; while (!gt_quit) { - FD_SET(tun_fd, &rfds); + unsigned long send_wait = mud_send_wait(mud); + + if (send_wait) { + FD_CLR(tun_fd, &rfds); + } else { + FD_SET(tun_fd, &rfds); + } + FD_SET(mud_fd, &rfds); FD_SET(ctl_fd, &rfds); struct timeval tv = { - .tv_sec = sync / 1000UL, + .tv_sec = 0, + .tv_usec = send_wait, }; - const int ret = select(last_fd, &rfds, NULL, NULL, sync ? &tv : NULL); + const int ret = select(last_fd, &rfds, NULL, NULL, send_wait ? &tv : NULL); if (ret == -1) { if (errno == EBADF) { @@ -309,21 +317,6 @@ gt_bind(int argc, char **argv) } } - if (FD_ISSET(tun_fd, &rfds)) { - struct ip_common ic; - const int r = tun_read(tun_fd, buf, sizeof(buf)); - - if (!ip_get_common(&ic, buf, r)) { - unsigned char hash[crypto_shorthash_BYTES]; - crypto_shorthash(hash, (const unsigned char *)&ic, sizeof(ic), hashkey); - - unsigned h; - memcpy(&h, hash, sizeof(h)); - - mud_send(mud, buf, r, (h << 8) | ic.tc); - } - } - if (FD_ISSET(mud_fd, &rfds)) { const int r = mud_recv(mud, buf, sizeof(buf)); @@ -331,8 +324,26 @@ gt_bind(int argc, char **argv) tun_write(tun_fd, buf, r); } + if (FD_ISSET(tun_fd, &rfds) && !mud_send_wait(mud)) { + struct ip_common ic; + const int r = tun_read(tun_fd, buf, sizeof(buf)); + + if (!ip_get_common(&ic, buf, r)) { + // TODO: disable hash for now + // unsigned char hash[crypto_shorthash_BYTES]; + // crypto_shorthash(hash, (const unsigned char *)&ic, sizeof(ic), hashkey); + + unsigned h = 0; + // memcpy(&h, hash, sizeof(h)); + + mud_send(mud, buf, r, (h << 8) | ic.tc); + } + } + + /* TODO if (!ret) mud_sync(mud); + */ } if (gt_reload && tun_fd >= 0) { diff --git a/src/path.c b/src/path.c index 702c298..9075a9c 100644 --- a/src/path.c +++ b/src/path.c @@ -89,11 +89,11 @@ gt_path_status(int fd) 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.rtt.val / 1e3, + res.path_status.rtt.var / 1e3, res.path_status.r_rate * 10, res.path_status.r_ratemax * 10, - res.path_status.recv.rate * 10, + res.path_status.rate.val * 10, res.path_status.recv.ratemax * 10, res.path_status.send.total, res.path_status.recv.total);