Add option 'set tc'
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
@@ -315,6 +315,10 @@ gt_bind(int argc, char **argv)
|
|||||||
res.mtu = gt_setup_mtu(mud, tun_name);
|
res.mtu = gt_setup_mtu(mud, tun_name);
|
||||||
mtu = res.mtu;
|
mtu = res.mtu;
|
||||||
break;
|
break;
|
||||||
|
case CTL_TC:
|
||||||
|
if (mud_set_tc(mud, req.tc))
|
||||||
|
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.timeout))
|
||||||
res.ret = errno;
|
res.ret = errno;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ enum ctl_type {
|
|||||||
CTL_STATE,
|
CTL_STATE,
|
||||||
CTL_STATUS,
|
CTL_STATUS,
|
||||||
CTL_MTU,
|
CTL_MTU,
|
||||||
|
CTL_TC,
|
||||||
CTL_TIMEOUT,
|
CTL_TIMEOUT,
|
||||||
CTL_TIMETOLERANCE,
|
CTL_TIMETOLERANCE,
|
||||||
CTL_PATH_STATUS,
|
CTL_PATH_STATUS,
|
||||||
@@ -31,6 +32,7 @@ struct ctl_msg {
|
|||||||
struct sockaddr_storage peer;
|
struct sockaddr_storage peer;
|
||||||
} status;
|
} status;
|
||||||
int mtu;
|
int mtu;
|
||||||
|
int tc;
|
||||||
unsigned long timeout;
|
unsigned long timeout;
|
||||||
unsigned long timetolerance;
|
unsigned long timetolerance;
|
||||||
};
|
};
|
||||||
|
|||||||
101
src/set.c
101
src/set.c
@@ -17,10 +17,14 @@ gt_set_mtu(int fd, size_t mtu)
|
|||||||
|
|
||||||
int ret = ctl_reply(fd, &res, &req);
|
int ret = ctl_reply(fd, &res, &req);
|
||||||
|
|
||||||
if (!ret)
|
if (ret) {
|
||||||
printf("new mtu: %i\n", res.mtu);
|
perror("set mtu");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
printf("mtu set to %i\n", res.mtu);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -31,7 +35,14 @@ gt_set_timeout(int fd, unsigned long timeout)
|
|||||||
.timeout = 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
|
static int
|
||||||
@@ -42,20 +53,73 @@ gt_set_timetolerance(int fd, unsigned long timetolerance)
|
|||||||
.timetolerance = 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
|
int
|
||||||
gt_set(int argc, char **argv)
|
gt_set(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *dev = NULL;
|
const char *dev = NULL;
|
||||||
unsigned long timetolerance = 0;
|
size_t mtu;
|
||||||
unsigned long timeout = 0;
|
int tc;
|
||||||
size_t mtu = 0;
|
unsigned long timetolerance;
|
||||||
|
unsigned long timeout;
|
||||||
|
|
||||||
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},
|
||||||
{"timeout", "SECONDS", &timeout, argz_time},
|
{"timeout", "SECONDS", &timeout, argz_time},
|
||||||
{"timetolerance", "SECONDS", &timetolerance, argz_time},
|
{"timetolerance", "SECONDS", &timetolerance, argz_time},
|
||||||
{NULL}};
|
{NULL}};
|
||||||
@@ -78,20 +142,17 @@ gt_set(int argc, char **argv)
|
|||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (mtu && gt_set_mtu(fd, mtu)) {
|
if (argz_is_set(pathz, "mtu"))
|
||||||
perror("mtu");
|
ret |= gt_set_mtu(fd, mtu);
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ret && timeout && gt_set_timeout(fd, timeout)) {
|
if (argz_is_set(pathz, "tc"))
|
||||||
perror("timeout");
|
ret |= gt_set_tc(fd, tc);
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ret && timetolerance && gt_set_timetolerance(fd, timetolerance)) {
|
if (argz_is_set(pathz, "timeout"))
|
||||||
perror("timetolerance");
|
ret |= gt_set_timeout(fd, timeout);
|
||||||
ret = 1;
|
|
||||||
}
|
if (argz_is_set(pathz, "timetolerance"))
|
||||||
|
ret |= gt_set_timetolerance(fd, timetolerance);
|
||||||
|
|
||||||
ctl_delete(fd);
|
ctl_delete(fd);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user