The path command should only show the conf
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
104
src/path.c
104
src/path.c
@@ -9,75 +9,31 @@
|
|||||||
#include "../argz/argz.h"
|
#include "../argz/argz.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gt_path_print_status(struct mud_path *path, int term)
|
gt_path_print(struct mud_path *path, int term)
|
||||||
{
|
{
|
||||||
char bindstr[INET6_ADDRSTRLEN];
|
|
||||||
char publstr[INET6_ADDRSTRLEN];
|
|
||||||
char peerstr[INET6_ADDRSTRLEN];
|
|
||||||
|
|
||||||
gt_toaddr(bindstr, sizeof(bindstr),
|
|
||||||
(struct sockaddr *)&path->local_addr);
|
|
||||||
gt_toaddr(publstr, sizeof(publstr),
|
|
||||||
(struct sockaddr *)&path->r_addr);
|
|
||||||
gt_toaddr(peerstr, sizeof(peerstr),
|
|
||||||
(struct sockaddr *)&path->addr);
|
|
||||||
|
|
||||||
const char *statestr = NULL;
|
const char *statestr = NULL;
|
||||||
|
char bindstr[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
switch (path->state) {
|
switch (path->state) {
|
||||||
case MUD_UP: statestr = "UP"; break;
|
case MUD_UP: statestr = "up"; break;
|
||||||
case MUD_BACKUP: statestr = "BACKUP"; break;
|
case MUD_BACKUP: statestr = "backup"; break;
|
||||||
case MUD_DOWN: statestr = "DOWN"; break;
|
case MUD_DOWN: statestr = "down"; break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(term ? "path %s\n"
|
if (gt_toaddr(bindstr, sizeof(bindstr),
|
||||||
" status: %s\n"
|
(struct sockaddr *)&path->local_addr))
|
||||||
" bind: %s port %"PRIu16"\n"
|
return;
|
||||||
" public: %s port %"PRIu16"\n"
|
|
||||||
" peer: %s port %"PRIu16"\n"
|
printf(term ? "path %s %s losslimit %u%% beat %"PRIu64"ms "
|
||||||
" mtu: %zu bytes\n"
|
"rate %s tx %"PRIu64" rx %"PRIu64"\n"
|
||||||
" rtt: %.3f ms\n"
|
: "path %s %s %u %"PRIu64" %s %"PRIu64" %"PRIu64"\n",
|
||||||
" rttvar: %.3f ms\n"
|
statestr, bindstr,
|
||||||
" rate: %s\n"
|
path->conf.loss_limit * 100U / 255U,
|
||||||
" losslim: %u\n"
|
path->conf.beat / 1000,
|
||||||
" beat: %"PRIu64" ms\n"
|
path->conf.fixed_rate ? "fixed" : "auto",
|
||||||
" tx:\n"
|
path->conf.tx_max_rate,
|
||||||
" rate: %"PRIu64" bytes/sec\n"
|
path->conf.rx_max_rate);
|
||||||
" loss: %"PRIu64" percent\n"
|
|
||||||
" total: %"PRIu64" packets\n"
|
|
||||||
" rx:\n"
|
|
||||||
" rate: %"PRIu64" bytes/sec\n"
|
|
||||||
" loss: %"PRIu64" percent\n"
|
|
||||||
" total: %"PRIu64" packets\n"
|
|
||||||
: "path %s %s"
|
|
||||||
" %s %"PRIu16" %s %"PRIu16" %s %"PRIu16
|
|
||||||
" %zu %.3f %.3f"
|
|
||||||
" %s %u"
|
|
||||||
" %"PRIu64
|
|
||||||
" %"PRIu64" %"PRIu64" %"PRIu64
|
|
||||||
" %"PRIu64" %"PRIu64" %"PRIu64
|
|
||||||
"\n",
|
|
||||||
statestr,
|
|
||||||
path->ok ? "OK" : "DEGRADED",
|
|
||||||
bindstr[0] ? bindstr : "-",
|
|
||||||
gt_get_port((struct sockaddr *)&path->local_addr),
|
|
||||||
publstr[0] ? publstr : "-",
|
|
||||||
gt_get_port((struct sockaddr *)&path->r_addr),
|
|
||||||
peerstr[0] ? peerstr : "-",
|
|
||||||
gt_get_port((struct sockaddr *)&path->addr),
|
|
||||||
path->mtu.ok,
|
|
||||||
(double)path->rtt.val / 1e3,
|
|
||||||
(double)path->rtt.var / 1e3,
|
|
||||||
path->conf.fixed_rate ? "fixed" : "auto",
|
|
||||||
path->conf.loss_limit * 100 / 255,
|
|
||||||
path->conf.beat / 1000,
|
|
||||||
path->tx.rate,
|
|
||||||
path->tx.loss * 100 / 255,
|
|
||||||
path->tx.total,
|
|
||||||
path->rx.rate,
|
|
||||||
path->rx.loss * 100 / 255,
|
|
||||||
path->rx.total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -102,7 +58,7 @@ gt_path_cmp_addr(struct sockaddr_storage *a, struct sockaddr_storage *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
gt_path_status(int fd, enum mud_state state, struct sockaddr_storage *addr)
|
gt_path_print_all(int fd, enum mud_state state, struct sockaddr_storage *addr)
|
||||||
{
|
{
|
||||||
struct ctl_msg req = {
|
struct ctl_msg req = {
|
||||||
.type = CTL_PATH_STATUS,
|
.type = CTL_PATH_STATUS,
|
||||||
@@ -134,10 +90,15 @@ gt_path_status(int fd, enum mud_state state, struct sockaddr_storage *addr)
|
|||||||
|
|
||||||
int term = isatty(1);
|
int term = isatty(1);
|
||||||
|
|
||||||
|
if (!term)
|
||||||
|
printf("# STATE ADDR LOSSLIMIT BEAT RATE TX RX\n");
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if ((state == MUD_EMPTY || path[i].state == state) &&
|
if (state && path[i].state != state)
|
||||||
(!addr->ss_family || !gt_path_cmp_addr(addr, &path[i].local_addr)))
|
continue;
|
||||||
gt_path_print_status(&path[i], term);
|
if (addr->ss_family && gt_path_cmp_addr(addr, &path[i].local_addr))
|
||||||
|
continue;
|
||||||
|
gt_path_print(&path[i], term);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -219,14 +180,13 @@ gt_path(int argc, char **argv)
|
|||||||
req.path.fixed_rate = 1;
|
req.path.fixed_rate = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
if (!req.path.addr.ss_family ||
|
if (req.path.addr.ss_family && (req.path.state || set))
|
||||||
(req.path.state == MUD_EMPTY && !set)) {
|
|
||||||
ret = gt_path_status(fd, req.path.state, &req.path.addr);
|
|
||||||
} else {
|
|
||||||
ret = ctl_reply(fd, &res, &req);
|
ret = ctl_reply(fd, &res, &req);
|
||||||
}
|
|
||||||
|
if (!ret)
|
||||||
|
ret = gt_path_print_all(fd, req.path.state, &req.path.addr);
|
||||||
|
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
perror("path");
|
perror("path");
|
||||||
|
|||||||
Reference in New Issue
Block a user