diff --git a/mud b/mud index 0a9a139..2f5e346 160000 --- a/mud +++ b/mud @@ -1 +1 @@ -Subproject commit 0a9a1394096b0ebe6e918a18c35c6ced33c0fc15 +Subproject commit 2f5e346532828bc591a066d180e1305753e77f0f diff --git a/src/bind.c b/src/bind.c index 9624ffc..5c3b393 100644 --- a/src/bind.c +++ b/src/bind.c @@ -107,7 +107,6 @@ gt_bind(int argc, char **argv) struct sockaddr_storage peer_addr = { 0 }; unsigned short bind_port = 5000; unsigned short peer_port = bind_port; - unsigned long long keepalive = 100; const char *dev = NULL; const char *keyfile = NULL; @@ -124,7 +123,6 @@ gt_bind(int argc, char **argv) {"keyfile", "FILE", &keyfile, argz_str}, {"chacha", NULL, NULL, argz_option}, {"persist", NULL, NULL, argz_option}, - {"keepalive", "SECONDS", &keepalive, argz_time}, {NULL}}; if (argz(bindz, argc, argv)) @@ -243,8 +241,7 @@ gt_bind(int argc, char **argv) if (update) tv.tv_usec = 1000; } else { - tv.tv_sec = keepalive / 1000; - tv.tv_usec = 1000 * (keepalive % 1000); + tv.tv_usec = 100000; } } @@ -347,6 +344,10 @@ gt_bind(int argc, char **argv) if (mud_set_loss_limit(mud, req.percent)) res.ret = errno; break; + case CTL_KEEPALIVE: + if (mud_set_keepalive(mud, req.ms)) + res.ret = errno; + break; case CTL_STATUS: memcpy(res.status.tun_name, tun_name, sizeof(tun_name)); // XXX res.status.pid = pid; diff --git a/src/ctl.h b/src/ctl.h index 6504b4e..8e6eb83 100644 --- a/src/ctl.h +++ b/src/ctl.h @@ -15,6 +15,7 @@ enum ctl_type { CTL_KXTIMEOUT, CTL_TIMETOLERANCE, CTL_LOSSLIMIT, + CTL_KEEPALIVE, CTL_PATH_STATUS, CTL_BAD, }; diff --git a/src/set.c b/src/set.c index 3dfca43..f158102 100644 --- a/src/set.c +++ b/src/set.c @@ -61,6 +61,24 @@ gt_set_losslimit(int fd, unsigned percent) return 0; } +static int +gt_set_keepalive(int fd, unsigned long ms) +{ + struct ctl_msg res, req = { + .type = CTL_KEEPALIVE, + .ms = ms, + }; + + int ret = ctl_reply(fd, &res, &req); + + if (ret) { + perror("set keepalive"); + return 1; + } + + return 0; +} + static int gt_set_tc(int fd, int tc) { @@ -113,6 +131,7 @@ gt_set(int argc, char **argv) unsigned long kxtimeout; unsigned long timetolerance; unsigned losslimit; + unsigned long keepalive; struct argz pathz[] = { {"dev", "NAME", &dev, argz_str}, @@ -120,6 +139,7 @@ gt_set(int argc, char **argv) {"kxtimeout", "SECONDS", &kxtimeout, argz_time}, {"timetolerance", "SECONDS", &timetolerance, argz_time}, {"losslimit", "PERCENT", &losslimit, argz_percent}, + {"keepalive", "SECONDS", &keepalive, argz_time}, {NULL}}; if (argz(pathz, argc, argv)) @@ -158,6 +178,9 @@ gt_set(int argc, char **argv) if (argz_is_set(pathz, "losslimit")) ret |= gt_set_losslimit(fd, losslimit); + if (argz_is_set(pathz, "keepalive")) + ret |= gt_set_keepalive(fd, keepalive); + ctl_delete(fd); return ret;