Compare commits
14 Commits
v0.0.29-mu
...
v0.0.40-mu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39e3f53139 | ||
|
|
babe14d544 | ||
|
|
278fc69789 | ||
|
|
99262777fc | ||
|
|
b0f60caab2 | ||
|
|
efd5e0bb36 | ||
|
|
ade4617d53 | ||
|
|
64a5fd8227 | ||
|
|
eba968797c | ||
|
|
d60f28a7fe | ||
|
|
32069eb104 | ||
|
|
a6adcefc25 | ||
|
|
743b0ee0da | ||
|
|
ba06a6fc10 |
2
mud
2
mud
Submodule mud updated: 1b58401095...f0ad4bbdd3
81
src/main.c
81
src/main.c
@@ -242,17 +242,25 @@ int main (int argc, char **argv)
|
||||
|
||||
gt.timeout = 5000;
|
||||
|
||||
long time_tolerance = 0;
|
||||
|
||||
int v4 = 1;
|
||||
int v6 = 1;
|
||||
|
||||
struct option opts[] = {
|
||||
{ "host", &host, option_str },
|
||||
{ "port", &port, option_str },
|
||||
{ "bind", &bind_list, option_str },
|
||||
{ "bind-port", &bind_port, option_str },
|
||||
{ "dev", &dev, option_str },
|
||||
{ "keyfile", &keyfile, option_str },
|
||||
{ "multiqueue", NULL, option_option },
|
||||
{ "statefile", &statefile, option_str },
|
||||
{ "timeout", >.timeout, option_long },
|
||||
{ "version", NULL, option_option },
|
||||
{ "host", &host, option_str },
|
||||
{ "port", &port, option_str },
|
||||
{ "bind", &bind_list, option_str },
|
||||
{ "bind-port", &bind_port, option_str },
|
||||
{ "dev", &dev, option_str },
|
||||
{ "keyfile", &keyfile, option_str },
|
||||
{ "multiqueue", NULL, option_option },
|
||||
{ "statefile", &statefile, option_str },
|
||||
{ "timeout", >.timeout, option_long },
|
||||
{ "time-tolerance", &time_tolerance, option_long },
|
||||
{ "v4only", NULL, option_option },
|
||||
{ "v6only", NULL, option_option },
|
||||
{ "version", NULL, option_option },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
@@ -264,6 +272,17 @@ int main (int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (option_is_set(opts, "v4only"))
|
||||
v6 = 0;
|
||||
|
||||
if (option_is_set(opts, "v6only"))
|
||||
v4 = 0;
|
||||
|
||||
if (!v4 && !v6) {
|
||||
gt_log("v4only and v6only are both set\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!option_is_set(opts, "keyfile")) {
|
||||
gt_log("keyfile option must be set\n");
|
||||
return 1;
|
||||
@@ -279,11 +298,6 @@ int main (int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!crypto_aead_aes256gcm_is_available()) {
|
||||
gt_na("AES-256-GCM");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (state_init(statefile))
|
||||
return 1;
|
||||
|
||||
@@ -301,7 +315,7 @@ int main (int argc, char **argv)
|
||||
if (gt_setup_secretkey(keyfile))
|
||||
return 1;
|
||||
|
||||
struct mud *mud = mud_create(bind_port);
|
||||
struct mud *mud = mud_create(bind_port, v4, v6);
|
||||
|
||||
if (!mud) {
|
||||
gt_log("couldn't create mud\n");
|
||||
@@ -310,6 +324,11 @@ int main (int argc, char **argv)
|
||||
|
||||
mud_set_key(mud, gt.key, sizeof(gt.key));
|
||||
|
||||
mud_set_send_timeout_msec(mud, gt.timeout);
|
||||
|
||||
if (time_tolerance > 0)
|
||||
mud_set_time_tolerance_sec(mud, time_tolerance);
|
||||
|
||||
if (bind_list) {
|
||||
char tmp[1024];
|
||||
char *name = &tmp[0];
|
||||
@@ -355,9 +374,12 @@ int main (int argc, char **argv)
|
||||
}
|
||||
|
||||
struct timeval timeout = {
|
||||
.tv_usec = 1000,
|
||||
.tv_usec = 100000,
|
||||
};
|
||||
|
||||
if (mud_can_push(mud))
|
||||
timeout.tv_usec = 1000;
|
||||
|
||||
if _0_(select(mud_fd+1, &rfds, NULL, NULL, &timeout)==-1) {
|
||||
if (errno==EINTR)
|
||||
continue;
|
||||
@@ -367,20 +389,24 @@ int main (int argc, char **argv)
|
||||
|
||||
if (mud_is_up(mud)) {
|
||||
if (!started) {
|
||||
state("STARTED", NULL);
|
||||
state("STARTED", tun_name);
|
||||
started = 1;
|
||||
}
|
||||
} else if (started) {
|
||||
state("STOPPED", NULL);
|
||||
started = 0;
|
||||
} else {
|
||||
if (started) {
|
||||
state("STOPPED", tun_name);
|
||||
started = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (FD_ISSET(tun_fd, &rfds)) {
|
||||
while (1) {
|
||||
const ssize_t r = tun_read(tun_fd, buf, sizeof(buf));
|
||||
|
||||
if (r<=0)
|
||||
if (r<=0) {
|
||||
gt.quit |= !r;
|
||||
break;
|
||||
}
|
||||
|
||||
struct ip_common ic;
|
||||
|
||||
@@ -395,12 +421,17 @@ int main (int argc, char **argv)
|
||||
mud_pull(mud);
|
||||
|
||||
while (1) {
|
||||
const int r = mud_recv(mud, buf, sizeof(buf));
|
||||
const int size = mud_recv(mud, buf, sizeof(buf));
|
||||
|
||||
if (r<=0)
|
||||
if (size<=0)
|
||||
break;
|
||||
|
||||
tun_write(tun_fd, buf, r);
|
||||
const ssize_t r = tun_write(tun_fd, buf, size);
|
||||
|
||||
if (r<=0) {
|
||||
gt.quit |= !r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user