Add option 'set tc'

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-02-27 23:12:36 +00:00
parent 44f75458d1
commit ff5b966866
3 changed files with 87 additions and 20 deletions

View File

@@ -315,6 +315,10 @@ gt_bind(int argc, char **argv)
res.mtu = gt_setup_mtu(mud, tun_name);
mtu = res.mtu;
break;
case CTL_TC:
if (mud_set_tc(mud, req.tc))
res.ret = errno;
break;
case CTL_TIMEOUT:
if (mud_set_send_timeout(mud, req.timeout))
res.ret = errno;

View File

@@ -9,6 +9,7 @@ enum ctl_type {
CTL_STATE,
CTL_STATUS,
CTL_MTU,
CTL_TC,
CTL_TIMEOUT,
CTL_TIMETOLERANCE,
CTL_PATH_STATUS,
@@ -31,6 +32,7 @@ struct ctl_msg {
struct sockaddr_storage peer;
} status;
int mtu;
int tc;
unsigned long timeout;
unsigned long timetolerance;
};

101
src/set.c
View File

@@ -17,10 +17,14 @@ gt_set_mtu(int fd, size_t mtu)
int ret = ctl_reply(fd, &res, &req);
if (!ret)
printf("new mtu: %i\n", res.mtu);
if (ret) {
perror("set mtu");
return 1;
}
return ret;
printf("mtu set to %i\n", res.mtu);
return 0;
}
static int
@@ -31,7 +35,14 @@ gt_set_timeout(int fd, unsigned long timeout)
.timeout = timeout,
};
return ctl_reply(fd, &res, &req);
int ret = ctl_reply(fd, &res, &req);
if (ret) {
perror("set timeout");
return 1;
}
return 0;
}
static int
@@ -42,20 +53,73 @@ gt_set_timetolerance(int fd, unsigned long timetolerance)
.timetolerance = timetolerance,
};
return ctl_reply(fd, &res, &req);
int ret = ctl_reply(fd, &res, &req);
if (ret) {
perror("set timetolerance");
return 1;
}
return 0;
}
static int
gt_set_tc(int fd, int tc)
{
struct ctl_msg res, req = {
.type = CTL_TC,
.tc = tc,
};
int ret = ctl_reply(fd, &res, &req);
if (ret) {
perror("set tc");
return 1;
}
return 0;
}
static int
gt_argz_tc(void *data, int argc, char **argv)
{
if (argc < 1 || !argv[0])
return -1;
int val = 0;
const char *s = argv[0];
if ((s[0] == 'C') && (s[1] == 'S') &&
(s[2] >= '0') && (s[2] <= '7') && !s[3]) {
val = (s[2] - '0') << 3;
} else if ((s[0] == 'A') && (s[1] == 'F') &&
(s[2] >= '1') && (s[2] <= '4') &&
(s[3] >= '1') && (s[3] <= '3') && !s[4]) {
val = ((s[2] - '0') << 3) | ((s[3] - '0') << 1);
} else if ((s[0] == 'E') && (s[1] == 'F') && !s[2]) {
val = 46;
} else return -1;
if (data)
*(int *)data = val;
return 1;
}
int
gt_set(int argc, char **argv)
{
const char *dev = NULL;
unsigned long timetolerance = 0;
unsigned long timeout = 0;
size_t mtu = 0;
size_t mtu;
int tc;
unsigned long timetolerance;
unsigned long timeout;
struct argz pathz[] = {
{"dev", "NAME", &dev, argz_str},
{"mtu", "BYTES", &mtu, argz_bytes},
{"tc", "CS|AF|EF", &tc, gt_argz_tc},
{"timeout", "SECONDS", &timeout, argz_time},
{"timetolerance", "SECONDS", &timetolerance, argz_time},
{NULL}};
@@ -78,20 +142,17 @@ gt_set(int argc, char **argv)
int ret = 0;
if (mtu && gt_set_mtu(fd, mtu)) {
perror("mtu");
ret = 1;
}
if (argz_is_set(pathz, "mtu"))
ret |= gt_set_mtu(fd, mtu);
if (!ret && timeout && gt_set_timeout(fd, timeout)) {
perror("timeout");
ret = 1;
}
if (argz_is_set(pathz, "tc"))
ret |= gt_set_tc(fd, tc);
if (!ret && timetolerance && gt_set_timetolerance(fd, timetolerance)) {
perror("timetolerance");
ret = 1;
}
if (argz_is_set(pathz, "timeout"))
ret |= gt_set_timeout(fd, timeout);
if (argz_is_set(pathz, "timetolerance"))
ret |= gt_set_timetolerance(fd, timetolerance);
ctl_delete(fd);