summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2007-04-06 18:36:33 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2007-04-06 18:36:33 +0000
commit47c50248c1d6305fed37f4b7429b498f2e445611 (patch)
tree9e652f6009cee6405f67c4dc45e2bd3fc25503f4
parentec923d2c209408ddb282e1be4e1f50b365574b73 (diff)
Implement "bgpctl show neighbor <peer> terse" this will print all statistics
in an easily parseable form. This output can be used to implement SNMP MIBs or rrdtool/mrtg update scripts. OK henning@
-rw-r--r--usr.sbin/bgpctl/bgpctl.c37
-rw-r--r--usr.sbin/bgpctl/parser.c5
-rw-r--r--usr.sbin/bgpctl/parser.h3
3 files changed, 41 insertions, 4 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c
index 2596cd5991b..cbedfb8cbe0 100644
--- a/usr.sbin/bgpctl/bgpctl.c
+++ b/usr.sbin/bgpctl/bgpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpctl.c,v 1.121 2007/04/06 18:14:48 claudio Exp $ */
+/* $OpenBSD: bgpctl.c,v 1.122 2007/04/06 18:36:32 claudio Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -49,6 +49,7 @@ char *fmt_peer(const char *, const struct bgpd_addr *, int, int);
void show_summary_head(void);
int show_summary_msg(struct imsg *, int);
int show_summary_terse_msg(struct imsg *, int);
+int show_neighbor_terse(struct imsg *);
int show_neighbor_msg(struct imsg *, enum neighbor_views);
void print_neighbor_capa_mp_safi(u_int8_t);
void print_neighbor_msgstats(struct peer *);
@@ -194,6 +195,7 @@ main(int argc, char *argv[])
break;
case SHOW_NEIGHBOR:
case SHOW_NEIGHBOR_TIMERS:
+ case SHOW_NEIGHBOR_TERSE:
if (res->peeraddr.af || res->peerdesc[0])
imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1,
&neighbor, sizeof(neighbor));
@@ -340,6 +342,9 @@ main(int argc, char *argv[])
case SHOW_NEIGHBOR_TIMERS:
done = show_neighbor_msg(&imsg, NV_TIMERS);
break;
+ case SHOW_NEIGHBOR_TERSE:
+ done = show_neighbor_terse(&imsg);
+ break;
case SHOW_RIB:
if (res->flags & F_CTL_DETAIL)
done = show_rib_detail_msg(&imsg,
@@ -479,6 +484,36 @@ show_summary_terse_msg(struct imsg *imsg, int nodescr)
}
int
+show_neighbor_terse(struct imsg *imsg)
+{
+ struct peer *p;
+
+ switch (imsg->hdr.type) {
+ case IMSG_CTL_SHOW_NEIGHBOR:
+ p = imsg->data;
+ printf("%llu %llu %llu %llu %llu %llu %llu "
+ "%llu %llu %llu %u %u %llu %llu %llu %llu\n",
+ p->stats.msg_sent_open, p->stats.msg_rcvd_open,
+ p->stats.msg_sent_notification,
+ p->stats.msg_rcvd_notification,
+ p->stats.msg_sent_update, p->stats.msg_rcvd_update,
+ p->stats.msg_sent_keepalive, p->stats.msg_rcvd_keepalive,
+ p->stats.msg_sent_rrefresh, p->stats.msg_rcvd_rrefresh,
+ p->stats.prefix_cnt, p->conf.max_prefix,
+ p->stats.prefix_sent_update, p->stats.prefix_rcvd_update,
+ p->stats.prefix_sent_withdraw,
+ p->stats.prefix_rcvd_withdraw);
+ break;
+ case IMSG_CTL_END:
+ return (1);
+ default:
+ break;
+ }
+
+ return (0);
+}
+
+int
show_neighbor_msg(struct imsg *imsg, enum neighbor_views nv)
{
struct peer *p;
diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c
index 710b07cb74a..1e63514c73e 100644
--- a/usr.sbin/bgpctl/parser.c
+++ b/usr.sbin/bgpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.42 2007/03/31 12:46:55 henning Exp $ */
+/* $OpenBSD: parser.c,v 1.43 2007/04/06 18:36:32 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -141,7 +141,7 @@ static const struct token t_show_rib[] = {
{ FLAG, "in", F_CTL_ADJ_IN, t_show_rib},
{ FLAG, "out", F_CTL_ADJ_OUT, t_show_rib},
{ KEYWORD, "neighbor", NONE, t_show_rib_neigh},
- { KEYWORD, "summary", SHOW_SUMMARY, NULL},
+ { KEYWORD, "summary", SHOW_SUMMARY, t_show_summary},
{ KEYWORD, "memory", SHOW_RIB_MEM, NULL},
{ FAMILY, "", NONE, t_show_rib},
{ PREFIX, "", NONE, t_show_prefix},
@@ -165,6 +165,7 @@ static const struct token t_show_neighbor_modifiers[] = {
{ NOTOKEN, "", NONE, NULL},
{ KEYWORD, "timers", SHOW_NEIGHBOR_TIMERS, NULL},
{ KEYWORD, "messages", SHOW_NEIGHBOR, NULL},
+ { KEYWORD, "terse", SHOW_NEIGHBOR_TERSE, NULL},
{ ENDTOKEN, "", NONE, NULL}
};
diff --git a/usr.sbin/bgpctl/parser.h b/usr.sbin/bgpctl/parser.h
index 18981134b22..4d6caf224ef 100644
--- a/usr.sbin/bgpctl/parser.h
+++ b/usr.sbin/bgpctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.16 2007/03/28 12:34:08 henning Exp $ */
+/* $OpenBSD: parser.h,v 1.17 2007/04/06 18:36:32 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -27,6 +27,7 @@ enum actions {
SHOW_SUMMARY_TERSE,
SHOW_NEIGHBOR,
SHOW_NEIGHBOR_TIMERS,
+ SHOW_NEIGHBOR_TERSE,
SHOW_FIB,
SHOW_RIB,
SHOW_RIB_MEM,