diff --git a/mud b/mud index a91f8e2..67a7c91 160000 --- a/mud +++ b/mud @@ -1 +1 @@ -Subproject commit a91f8e29716629b2b4c6db68783e49a041d1eef6 +Subproject commit 67a7c912202d7f06db593f2a4547695d2b682b96 diff --git a/src/bind.c b/src/bind.c index 3b1a896..ae4d1c4 100644 --- a/src/bind.c +++ b/src/bind.c @@ -240,6 +240,28 @@ gt_bind(int argc, char **argv) mtu = gt_setup_mtu(mud, mtu, tun_name); + if (FD_ISSET(tun_fd, &rfds)) { + struct ip_common ic; + const int r = tun_read(tun_fd, buf, sizeof(buf)); + + if (r > 0 && !ip_get_common(&ic, buf, r)) + mud_send(mud, buf, (size_t)r, ic.tc); + } + + if (FD_ISSET(mud_fd, &rfds)) { + int n = 1000; + + while (n--) { + const int r = mud_recv(mud, buf, sizeof(buf)); + + if (r <= 0) + break; + + if (ip_is_valid(buf, r)) + tun_write(tun_fd, buf, (size_t)r); + } + } + if (FD_ISSET(ctl_fd, &rfds)) { struct ctl_msg req, res = {.reply = 1}; struct sockaddr_storage ss; @@ -314,36 +336,6 @@ gt_bind(int argc, char **argv) perror("recvfrom(ctl)"); } } - - if (FD_ISSET(mud_fd, &rfds)) { - int n = 1000; - - while (n--) { - const int r = mud_recv(mud, buf, sizeof(buf)); - - if (r <= 0) - break; - - if (ip_is_valid(buf, r)) - tun_write(tun_fd, buf, (size_t)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 (r > 0 && !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, (size_t)r, (h << 8) | ic.tc); - } - } } if (gt_reload && tun_fd >= 0)