2
mud
2
mud
Submodule mud updated: a91f8e2971...67a7c91220
52
src/bind.c
52
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)
|
||||
|
||||
Reference in New Issue
Block a user