summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclaudio <claudio@openbsd.org>2013-06-04 02:40:17 +0000
committerclaudio <claudio@openbsd.org>2013-06-04 02:40:17 +0000
commitd50436bb195a5a74dcfca8f2fb4808b3964ec686 (patch)
treebe59c519170bf7f53a65bec4a268b6c7f0498785
parentSpeed-up the session establishment process (diff)
downloadwireguard-openbsd-d50436bb195a5a74dcfca8f2fb4808b3964ec686.tar.xz
wireguard-openbsd-d50436bb195a5a74dcfca8f2fb4808b3964ec686.zip
Introduce the 'ldpctl show discovery' command
Diff by Renato Westphal
-rw-r--r--usr.sbin/ldpctl/ldpctl.c43
-rw-r--r--usr.sbin/ldpctl/parser.c9
-rw-r--r--usr.sbin/ldpctl/parser.h3
3 files changed, 52 insertions, 3 deletions
diff --git a/usr.sbin/ldpctl/ldpctl.c b/usr.sbin/ldpctl/ldpctl.c
index a0b04b772f3..ac38dc7ab14 100644
--- a/usr.sbin/ldpctl/ldpctl.c
+++ b/usr.sbin/ldpctl/ldpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpctl.c,v 1.14 2013/06/04 02:28:58 claudio Exp $
+/* $OpenBSD: ldpctl.c,v 1.15 2013/06/04 02:40:17 claudio Exp $
*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -42,6 +42,7 @@ __dead void usage(void);
const char *fmt_timeframe_core(time_t);
const char *get_linkstate(int, int);
int show_interface_msg(struct imsg *);
+int show_discovery_msg(struct imsg *);
int get_ifms_type(int);
int show_lib_msg(struct imsg *);
int show_nbr_msg(struct imsg *);
@@ -111,6 +112,12 @@ main(int argc, char *argv[])
imsg_compose(ibuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1,
&ifidx, sizeof(ifidx));
break;
+ case SHOW_DISC:
+ printf("%-15s %-9s %-15s %-9s\n",
+ "ID", "Type", "Source", "Holdtime");
+ imsg_compose(ibuf, IMSG_CTL_SHOW_DISCOVERY, 0, 0, -1,
+ NULL, 0);
+ break;
case SHOW_NBR:
printf("%-15s %-18s %-15s %-10s\n", "ID",
"State", "Address", "Uptime");
@@ -187,6 +194,9 @@ main(int argc, char *argv[])
case SHOW_IFACE:
done = show_interface_msg(&imsg);
break;
+ case SHOW_DISC:
+ done = show_discovery_msg(&imsg);
+ break;
case SHOW_NBR:
done = show_nbr_msg(&imsg);
break;
@@ -318,6 +328,37 @@ show_interface_msg(struct imsg *imsg)
}
int
+show_discovery_msg(struct imsg *imsg)
+{
+ struct ctl_adj *adj;
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_DISCOVERY:
+ adj = imsg->data;
+
+ printf("%-15s ", inet_ntoa(adj->id));
+ switch(adj->type) {
+ case HELLO_LINK:
+ printf("%-9s %-15s ", "Link", adj->ifname);
+ break;
+ case HELLO_TARGETED:
+ printf("%-9s %-15s ", "Targeted",
+ inet_ntoa(adj->src_addr));
+ break;
+ }
+ printf("%-9u\n", adj->holdtime);
+ break;
+ case IMSG_CTL_END:
+ printf("\n");
+ return (1);
+ default:
+ break;
+ }
+
+ return (0);
+}
+
+int
show_lib_msg(struct imsg *imsg)
{
struct ctl_rt *rt;
diff --git a/usr.sbin/ldpctl/parser.c b/usr.sbin/ldpctl/parser.c
index 312e8611775..3312de06f08 100644
--- a/usr.sbin/ldpctl/parser.c
+++ b/usr.sbin/ldpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.5 2010/09/04 21:31:04 tedu Exp $ */
+/* $OpenBSD: parser.c,v 1.6 2013/06/04 02:40:17 claudio Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -54,6 +54,7 @@ static const struct token t_main[];
static const struct token t_fib[];
static const struct token t_show[];
static const struct token t_show_iface[];
+static const struct token t_show_disc[];
static const struct token t_show_db[];
static const struct token t_show_area[];
static const struct token t_show_nbr[];
@@ -78,6 +79,7 @@ static const struct token t_fib[] = {
static const struct token t_show[] = {
{NOTOKEN, "", NONE, NULL},
{KEYWORD, "interfaces", SHOW_IFACE, t_show_iface},
+ {KEYWORD, "discovery", SHOW_DISC, t_show_disc},
{KEYWORD, "neighbor", SHOW_NBR, t_show_nbr},
{KEYWORD, "lib", SHOW_LIB, t_show_lib},
{KEYWORD, "fib", SHOW_FIB, t_show_fib},
@@ -89,6 +91,11 @@ static const struct token t_show_iface[] = {
{ENDTOKEN, "", NONE, NULL}
};
+static const struct token t_show_disc[] = {
+ {NOTOKEN, "", NONE, NULL},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
static const struct token t_show_nbr[] = {
{NOTOKEN, "", NONE, NULL},
{ENDTOKEN, "", NONE, NULL}
diff --git a/usr.sbin/ldpctl/parser.h b/usr.sbin/ldpctl/parser.h
index 424eb0df59e..0a824783236 100644
--- a/usr.sbin/ldpctl/parser.h
+++ b/usr.sbin/ldpctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.5 2010/09/04 21:31:04 tedu Exp $ */
+/* $OpenBSD: parser.h,v 1.6 2013/06/04 02:40:17 claudio Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -33,6 +33,7 @@ enum actions {
LOG_VERBOSE,
LOG_BRIEF,
SHOW,
+ SHOW_DISC,
SHOW_IFACE,
SHOW_NBR,
SHOW_LIB,