Add set option kxtimeout

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-03-14 07:57:32 +00:00
parent b0a589b792
commit c06abdbe3c
3 changed files with 39 additions and 12 deletions

View File

@@ -267,7 +267,7 @@ gt_bind(int argc, char **argv)
} }
break; break;
case CTL_MTU: case CTL_MTU:
mud_set_mtu(mud, (size_t)req.mtu); mud_set_mtu(mud, req.mtu);
mtu = gt_setup_mtu(mud, tun_name); mtu = gt_setup_mtu(mud, tun_name);
res.mtu = mtu; res.mtu = mtu;
break; break;
@@ -275,12 +275,16 @@ gt_bind(int argc, char **argv)
if (mud_set_tc(mud, req.tc)) if (mud_set_tc(mud, req.tc))
res.ret = errno; res.ret = errno;
break; break;
case CTL_KXTIMEOUT:
if (mud_set_keyx_timeout(mud, req.ms))
res.ret = errno;
break;
case CTL_TIMEOUT: case CTL_TIMEOUT:
if (mud_set_send_timeout(mud, req.timeout)) if (mud_set_send_timeout(mud, req.ms))
res.ret = errno; res.ret = errno;
break; break;
case CTL_TIMETOLERANCE: case CTL_TIMETOLERANCE:
if (mud_set_time_tolerance(mud, req.timetolerance)) if (mud_set_time_tolerance(mud, req.ms))
res.ret = errno; res.ret = errno;
break; break;
case CTL_STATUS: case CTL_STATUS:

View File

@@ -10,6 +10,7 @@ enum ctl_type {
CTL_STATUS, CTL_STATUS,
CTL_MTU, CTL_MTU,
CTL_TC, CTL_TC,
CTL_KXTIMEOUT,
CTL_TIMEOUT, CTL_TIMEOUT,
CTL_TIMETOLERANCE, CTL_TIMETOLERANCE,
CTL_PATH_STATUS, CTL_PATH_STATUS,
@@ -30,10 +31,9 @@ struct ctl_msg {
struct sockaddr_storage bind; struct sockaddr_storage bind;
struct sockaddr_storage peer; struct sockaddr_storage peer;
} status; } status;
int mtu; size_t mtu;
int tc; int tc;
unsigned long timeout; unsigned long ms;
unsigned long timetolerance;
}; };
}; };

View File

@@ -22,17 +22,35 @@ gt_set_mtu(int fd, size_t mtu)
return 1; return 1;
} }
printf("mtu set to %i\n", res.mtu); printf("mtu set to %zu\n", res.mtu);
return 0; return 0;
} }
static int static int
gt_set_timeout(int fd, unsigned long timeout) gt_set_kxtimeout(int fd, unsigned long ms)
{
struct ctl_msg res, req = {
.type = CTL_KXTIMEOUT,
.ms = ms,
};
int ret = ctl_reply(fd, &res, &req);
if (ret) {
perror("set kxtimeout");
return 1;
}
return 0;
}
static int
gt_set_timeout(int fd, unsigned long ms)
{ {
struct ctl_msg res, req = { struct ctl_msg res, req = {
.type = CTL_TIMEOUT, .type = CTL_TIMEOUT,
.timeout = timeout, .ms = ms,
}; };
int ret = ctl_reply(fd, &res, &req); int ret = ctl_reply(fd, &res, &req);
@@ -46,11 +64,11 @@ gt_set_timeout(int fd, unsigned long timeout)
} }
static int static int
gt_set_timetolerance(int fd, unsigned long timetolerance) gt_set_timetolerance(int fd, unsigned long ms)
{ {
struct ctl_msg res, req = { struct ctl_msg res, req = {
.type = CTL_TIMETOLERANCE, .type = CTL_TIMETOLERANCE,
.timetolerance = timetolerance, .ms = ms,
}; };
int ret = ctl_reply(fd, &res, &req); int ret = ctl_reply(fd, &res, &req);
@@ -113,13 +131,15 @@ gt_set(int argc, char **argv)
const char *dev = NULL; const char *dev = NULL;
size_t mtu; size_t mtu;
int tc; int tc;
unsigned long timetolerance; unsigned long kxtimeout;
unsigned long timeout; unsigned long timeout;
unsigned long timetolerance;
struct argz pathz[] = { struct argz pathz[] = {
{"dev", "NAME", &dev, argz_str}, {"dev", "NAME", &dev, argz_str},
{"mtu", "BYTES", &mtu, argz_bytes}, {"mtu", "BYTES", &mtu, argz_bytes},
{"tc", "CS|AF|EF", &tc, gt_argz_tc}, {"tc", "CS|AF|EF", &tc, gt_argz_tc},
{"kxtimeout", "SECONDS", &kxtimeout, argz_time},
{"timeout", "SECONDS", &timeout, argz_time}, {"timeout", "SECONDS", &timeout, argz_time},
{"timetolerance", "SECONDS", &timetolerance, argz_time}, {"timetolerance", "SECONDS", &timetolerance, argz_time},
{NULL}}; {NULL}};
@@ -142,6 +162,9 @@ gt_set(int argc, char **argv)
if (argz_is_set(pathz, "tc")) if (argz_is_set(pathz, "tc"))
ret |= gt_set_tc(fd, tc); ret |= gt_set_tc(fd, tc);
if (argz_is_set(pathz, "kxtimeout"))
ret |= gt_set_kxtimeout(fd, kxtimeout);
if (argz_is_set(pathz, "timeout")) if (argz_is_set(pathz, "timeout"))
ret |= gt_set_timeout(fd, timeout); ret |= gt_set_timeout(fd, timeout);