Code cleanup

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2019-07-22 13:04:37 +00:00
parent 56b5a41633
commit 1f82b15373
2 changed files with 23 additions and 31 deletions

2
mud

Submodule mud updated: a91f8e2971...67a7c91220

View File

@@ -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)