Use mud based keepalive

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2020-01-11 09:12:47 +00:00
parent 3df542b6d7
commit 4db90b42b6
4 changed files with 30 additions and 5 deletions

2
mud

Submodule mud updated: 0a9a139409...2f5e346532

View File

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

View File

@@ -15,6 +15,7 @@ enum ctl_type {
CTL_KXTIMEOUT,
CTL_TIMETOLERANCE,
CTL_LOSSLIMIT,
CTL_KEEPALIVE,
CTL_PATH_STATUS,
CTL_BAD,
};

View File

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