Compare commits

...

8 Commits

Author SHA1 Message Date
Adrien Gallouët
c06abdbe3c Add set option kxtimeout
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2018-03-14 07:57:32 +00:00
Adrien Gallouët
b0a589b792 Use GT_RUNDIR for local sockets
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2018-03-14 07:06:25 +00:00
Adrien Gallouët
66cdcf2ee3 Update mud
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2018-03-14 06:55:37 +00:00
Adrien Gallouët
7c50a9d162 Show public ip and port for each path
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2018-03-10 15:33:18 +00:00
Adrien Gallouët
6538d301d1 Show mtu for each path
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2018-03-09 23:17:10 +00:00
Adrien Gallouët
63831d6efc Update mud and path_status
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2018-03-09 23:16:13 +00:00
Adrien Gallouët
cbb498bb74 Update mud
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2018-03-06 16:04:04 +00:00
Adrien Gallouët
e2706aecdb Set errno when gt_toaddr() fails
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2018-03-06 16:03:25 +00:00
8 changed files with 71 additions and 26 deletions

2
mud

Submodule mud updated: b809bf0785...ef319d2153

View File

@@ -192,7 +192,7 @@ gt_bind(int argc, char **argv)
}
}
int ctl_fd = ctl_create("/run/" PACKAGE_NAME, tun_name);
int ctl_fd = ctl_create(GT_RUNDIR, tun_name);
if (ctl_fd == -1) {
perror("ctl_create");
@@ -257,17 +257,17 @@ gt_bind(int argc, char **argv)
res.ret = EAGAIN;
for (unsigned i = 0; i < count; i++) {
if (i && sendto(ctl_fd, &res, sizeof(res), 0,
(const struct sockaddr *)&ss, sl) == -1)
perror("sendto(ctl)");
memcpy(&res.path_status, &paths[i], sizeof(struct mud_path));
if (sendto(ctl_fd, &res, sizeof(res), 0,
(const struct sockaddr *)&ss, sl) == -1)
perror("sendto(ctl)");
}
res.ret = 0;
}
break;
case CTL_MTU:
mud_set_mtu(mud, (size_t)req.mtu);
mud_set_mtu(mud, req.mtu);
mtu = gt_setup_mtu(mud, tun_name);
res.mtu = mtu;
break;
@@ -275,12 +275,16 @@ gt_bind(int argc, char **argv)
if (mud_set_tc(mud, req.tc))
res.ret = errno;
break;
case CTL_KXTIMEOUT:
if (mud_set_keyx_timeout(mud, req.ms))
res.ret = errno;
break;
case CTL_TIMEOUT:
if (mud_set_send_timeout(mud, req.timeout))
if (mud_set_send_timeout(mud, req.ms))
res.ret = errno;
break;
case CTL_TIMETOLERANCE:
if (mud_set_time_tolerance(mud, req.timetolerance))
if (mud_set_time_tolerance(mud, req.ms))
res.ret = errno;
break;
case CTL_STATUS:

View File

@@ -108,5 +108,6 @@ gt_toaddr(char *str, size_t size, struct sockaddr *sa)
&((struct sockaddr_in6 *)sa)->sin6_addr, str, size);
}
errno = EAFNOSUPPORT;
return -1;
}

View File

@@ -21,6 +21,10 @@
#define PACKAGE_VERSION "0.0.0"
#endif
#ifndef GT_RUNDIR
#define GT_RUNDIR "/run/" PACKAGE_NAME
#endif
#define COUNT(x) (sizeof(x)/sizeof(x[0]))
#define ALIGN_SIZE (1<<4)

View File

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

View File

@@ -21,11 +21,20 @@ gt_path_status(int fd)
if (recv(fd, &res, sizeof(struct ctl_msg), 0) == -1)
return -1;
if (res.type != req.type)
return -2;
if (!res.ret)
return 0;
char bindstr[INET6_ADDRSTRLEN] = {0};
char publstr[INET6_ADDRSTRLEN] = {0};
char peerstr[INET6_ADDRSTRLEN] = {0};
if (gt_toaddr(bindstr, sizeof(bindstr),
(struct sockaddr *)&res.path_status.local_addr) ||
gt_toaddr(publstr, sizeof(publstr),
(struct sockaddr *)&res.path_status.r_addr) ||
gt_toaddr(peerstr, sizeof(peerstr),
(struct sockaddr *)&res.path_status.addr))
return -2;
@@ -40,11 +49,15 @@ gt_path_status(int fd)
}
printf("path %s\n"
" bind: %s\n"
" peer: %s port %"PRIu16"\n"
" rtt: %.3f\n",
statestr, bindstr, peerstr,
gt_get_port((struct sockaddr *)&res.path_status.addr),
" bind: %s\n"
" public: %s port %"PRIu16"\n"
" peer: %s port %"PRIu16"\n"
" mtu: %zu bytes\n"
" rtt: %.3f ms\n",
statestr, bindstr,
publstr, gt_get_port((struct sockaddr *)&res.path_status.r_addr),
peerstr, gt_get_port((struct sockaddr *)&res.path_status.addr),
res.path_status.mtu.ok + 28U, /* ip+udp hdr */
res.path_status.rtt/(double)1e3);
} while (res.ret == EAGAIN);
@@ -70,7 +83,7 @@ gt_path(int argc, char **argv)
if (argz(pathz, argc, argv))
return 1;
int fd = ctl_connect("/run/" PACKAGE_NAME, dev);
int fd = ctl_connect(GT_RUNDIR, dev);
if (fd == -1) {
perror("path");

View File

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

View File

@@ -56,7 +56,7 @@ gt_show_dev_status(int fd, const char *dev)
static int
gt_show_dev(const char *dev)
{
int fd = ctl_connect("/run/" PACKAGE_NAME, dev);
int fd = ctl_connect(GT_RUNDIR, dev);
if (fd == -1) {
perror(dev);
@@ -93,7 +93,7 @@ gt_show(int argc, char **argv)
return 0;
}
DIR *dp = opendir("/run/" PACKAGE_NAME);
DIR *dp = opendir(GT_RUNDIR);
if (!dp) {
if (errno == ENOENT)