Skip to content

Commit

Permalink
Show bad behaviors with command show bad
Browse files Browse the repository at this point in the history
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
  • Loading branch information
angt committed Oct 15, 2019
1 parent 289d88f commit 8bd9369
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mud
Submodule mud updated 2 files
+17 −6 mud.c
+10 −0 mud.h
4 changes: 4 additions & 0 deletions src/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ gt_bind(int argc, char **argv)
res.status.bind = bind_addr;
res.status.peer = peer_addr;
break;
case CTL_BAD:
if (mud_get_bad(mud, &res.bad))
res.ret = errno;
break;
}
if (sendto(ctl_fd, &res, sizeof(res), 0,
(const struct sockaddr *)&ss, sl) == -1)
Expand Down
2 changes: 2 additions & 0 deletions src/ctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum ctl_type {
CTL_KXTIMEOUT,
CTL_TIMETOLERANCE,
CTL_PATH_STATUS,
CTL_BAD,
};

struct ctl_msg {
Expand All @@ -37,6 +38,7 @@ struct ctl_msg {
struct sockaddr_storage bind;
struct sockaddr_storage peer;
} status;
struct mud_bad bad;
size_t mtu;
int tc;
unsigned long ms;
Expand Down
46 changes: 45 additions & 1 deletion src/show.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,47 @@
#include <arpa/inet.h>
#include <unistd.h>

static void
gt_show_bad_line(int term, char *name, uint64_t count,
struct sockaddr_storage *ss)
{
if (!count)
return;

char addr[INET6_ADDRSTRLEN];
gt_toaddr(addr, sizeof(addr), (struct sockaddr *)ss);

printf(term ? "%s:\n"
" count: %"PRIu64"\n"
" last: %s port %"PRIu16"\n"
: "%s"
" %"PRIu64
" %s %"PRIu16
"\n",
name, count, addr[0] ? addr : "-",
gt_get_port((struct sockaddr *)ss));
}

static int
gt_show_bad(int fd)
{
struct ctl_msg res, req = {.type = CTL_BAD};

if (ctl_reply(fd, &res, &req))
return -1;

int term = isatty(1);

gt_show_bad_line(term, "decrypt",
res.bad.decrypt.count, &res.bad.decrypt.addr);
gt_show_bad_line(term, "difftime",
res.bad.difftime.count, &res.bad.difftime.addr);
gt_show_bad_line(term, "keyx",
res.bad.keyx.count, &res.bad.keyx.addr);

return 0;
}

static int
gt_show_status(int fd)
{
Expand Down Expand Up @@ -82,6 +123,7 @@ gt_show(int argc, char **argv)

struct argz showz[] = {
{"dev", "NAME", &dev, argz_str},
{"bad", NULL, NULL, argz_option},
{NULL}};

if (argz(showz, argc, argv))
Expand All @@ -106,7 +148,9 @@ gt_show(int argc, char **argv)
return 1;
}

int ret = gt_show_status(fd);
int ret = argz_is_set(showz, "bad")
? gt_show_bad(fd)
: gt_show_status(fd);

if (ret == -1)
perror("show");
Expand Down

0 comments on commit 8bd9369

Please sign in to comment.