diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2007-12-23 18:26:14 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2007-12-23 18:26:14 +0000 |
commit | fe6013908a1d752eb9c790f25e79494b86767fb2 (patch) | |
tree | 478eb8289b44995b5b3325c021edf6b8d44efcd4 /usr.sbin | |
parent | 77034fd18c7f36f31b3e5cc87625768cf9870e89 (diff) |
send timers for bgpctlshow neighbor foo timer in seperate messages after
the peer data. makes bgpctl display code independent from timer
implementation internals. only running timers are displayed now, stopped
ones are skipped.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 46 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 4 | ||||
-rw-r--r-- | usr.sbin/bgpd/control.c | 33 | ||||
-rw-r--r-- | usr.sbin/bgpd/log.h | 12 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.h | 10 | ||||
-rw-r--r-- | usr.sbin/bgpd/timer.c | 4 |
6 files changed, 69 insertions, 40 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index 83cb3e101e9..accfdcb57b6 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.129 2007/12/20 17:08:48 henning Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.130 2007/12/23 18:26:13 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -53,8 +53,7 @@ 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 *); -void print_neighbor_timers(struct peer *); -void print_timer(const char *, struct peer *, enum Timer, u_int); +void print_timer(const char *, time_t); static char *fmt_timeframe(time_t t); static char *fmt_timeframe_core(time_t t); void show_fib_head(void); @@ -196,6 +195,7 @@ main(int argc, char *argv[]) case SHOW_NEIGHBOR: case SHOW_NEIGHBOR_TIMERS: case SHOW_NEIGHBOR_TERSE: + neighbor.show_timers = (res->action == SHOW_NEIGHBOR_TIMERS); if (res->peeraddr.af || res->peerdesc[0]) imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, &neighbor, sizeof(neighbor)); @@ -518,6 +518,7 @@ int show_neighbor_msg(struct imsg *imsg, enum neighbor_views nv) { struct peer *p; + struct ctl_timer *t; struct in_addr ina; char buf[NI_MAXHOST], pbuf[NI_MAXSERV], *s; @@ -582,14 +583,9 @@ show_neighbor_msg(struct imsg *imsg, enum neighbor_views nv) printf(" 4-byte AS numbers\n"); } printf("\n"); - switch (nv) { - case NV_DEFAULT: - print_neighbor_msgstats(p); + if (nv == NV_TIMERS) break; - case NV_TIMERS: - print_neighbor_timers(p); - break; - } + print_neighbor_msgstats(p); printf("\n"); if (p->state == STATE_IDLE) { static const char *errstr; @@ -621,6 +617,11 @@ show_neighbor_msg(struct imsg *imsg, enum neighbor_views nv) printf("\n"); } break; + case IMSG_CTL_SHOW_TIMER: + t = imsg->data; + if (t->type > 0 && t->type < Timer_Max) + print_timer(timernames[t->type], t->val); + break; case IMSG_CTL_END: return (1); break; @@ -679,31 +680,14 @@ print_neighbor_msgstats(struct peer *p) } void -print_neighbor_timers(struct peer *p) +print_timer(const char *name, timer_t d) { - print_timer("IdleHoldTimer:", p, Timer_IdleHold, p->IdleHoldTime); - print_timer("ConnectRetryTimer:", p, Timer_ConnectRetry, - INTERVAL_CONNECTRETRY); - print_timer("HoldTimer:", p, Timer_Hold, (u_int)p->holdtime); - print_timer("KeepaliveTimer:", p, Timer_Keepalive, (u_int)p->holdtime/3); -} - -void -print_timer(const char *name, struct peer *p, enum Timer timer, u_int interval) -{ - time_t d; - int running = timer_running(p, timer, &d); - printf(" %-20s ", name); - if (running == 0) - printf("%-20s", "not running"); - else if (d <= 0) - printf("%-20s", "due"); + if (d <= 0) + printf("%-20s\n", "due"); else - printf("due in %-13s", fmt_timeframe_core(d)); - - printf("Interval: %5us\n", interval); + printf("due in %-13s\n", fmt_timeframe_core(d)); } #define TF_BUFS 8 diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 1a9dbf9ce4b..43ec728aae4 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.220 2007/10/13 16:35:19 deraadt Exp $ */ +/* $OpenBSD: bgpd.h,v 1.221 2007/12/23 18:26:13 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -346,6 +346,7 @@ enum imsg_type { IMSG_CTL_SHOW_NETWORK6, IMSG_CTL_SHOW_RIB_MEM, IMSG_CTL_SHOW_TERSE, + IMSG_CTL_SHOW_TIMER, IMSG_REFRESH, IMSG_IFINFO, IMSG_DEMOTE @@ -479,6 +480,7 @@ struct ctl_show_nexthop { struct ctl_neighbor { struct bgpd_addr addr; char descr[PEER_DESCR_LEN]; + int show_timers; }; struct kroute_label { diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c index cbf55ae23f8..9bbd6be1ecd 100644 --- a/usr.sbin/bgpd/control.c +++ b/usr.sbin/bgpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.56 2007/12/20 17:08:48 henning Exp $ */ +/* $OpenBSD: control.c,v 1.57 2007/12/23 18:26:13 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -256,16 +256,41 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt) p = getpeerbyaddr(&neighbor->addr); if (p == NULL) p = getpeerbydesc(neighbor->descr); - if (p != NULL) + if (p != NULL && !neighbor->show_timers) { imsg_compose_rde(imsg.hdr.type, imsg.hdr.pid, p, sizeof(struct peer)); - } else + imsg_compose_rde(IMSG_CTL_END, + imsg.hdr.pid, NULL, 0); + } + if (p != NULL && neighbor->show_timers) { + u_int i; + time_t d; + struct ctl_timer ct; + + imsg_compose(&c->ibuf, + IMSG_CTL_SHOW_NEIGHBOR, + 0, 0, -1, p, sizeof(*p)); + for (i = 1; i < Timer_Max; i++) { + if (!timer_running(p, i, &d)) + continue; + ct.type = i; + ct.val = d; + imsg_compose(&c->ibuf, + IMSG_CTL_SHOW_TIMER, + 0, 0, -1, &ct, sizeof(ct)); + } + imsg_compose(&c->ibuf, IMSG_CTL_END, + 0, 0, -1, NULL, 0); + } + } else { for (p = peers; p != NULL; p = p->next) imsg_compose_rde(imsg.hdr.type, imsg.hdr.pid, p, sizeof(struct peer)); - imsg_compose_rde(IMSG_CTL_END, imsg.hdr.pid, NULL, 0); + imsg_compose_rde(IMSG_CTL_END, imsg.hdr.pid, + NULL, 0); + } break; case IMSG_CTL_SHOW_TERSE: for (p = peers; p != NULL; p = p->next) diff --git a/usr.sbin/bgpd/log.h b/usr.sbin/bgpd/log.h index 58256e55681..884ff1584e2 100644 --- a/usr.sbin/bgpd/log.h +++ b/usr.sbin/bgpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.9 2007/02/25 11:59:39 henning Exp $ */ +/* $OpenBSD: log.h,v 1.10 2007/12/23 18:26:13 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -111,3 +111,13 @@ static const char * const ctl_res_strerror[] = { "neighbor does not have this capability", "config file has errors, reload failed" }; + +static const char * const timernames[] = { + "None", + "ConnectRetryTimer", + "KeepaliveTimer", + "HoldTimer", + "IdleHoldTimer", + "IdleHoldResetTimer", + "" +}; diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index 7e823497d22..a1798514267 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.93 2007/12/20 17:08:48 henning Exp $ */ +/* $OpenBSD: session.h,v 1.94 2007/12/23 18:26:13 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -210,7 +210,13 @@ enum Timer { Timer_Keepalive, Timer_Hold, Timer_IdleHold, - Timer_IdleHoldReset + Timer_IdleHoldReset, + Timer_Max +}; + +struct ctl_timer { + enum Timer type; + time_t val; }; /* session.c */ diff --git a/usr.sbin/bgpd/timer.c b/usr.sbin/bgpd/timer.c index 5d5cd25b7b5..d6b97bd0896 100644 --- a/usr.sbin/bgpd/timer.c +++ b/usr.sbin/bgpd/timer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: timer.c,v 1.2 2007/12/23 16:40:43 henning Exp $ */ +/* $OpenBSD: timer.c,v 1.3 2007/12/23 18:26:13 henning Exp $ */ /* * Copyright (c) 2003-2007 Henning Brauer <henning@openbsd.org> @@ -38,6 +38,8 @@ timer_get(struct peer *p, enum Timer timer) return (&p->IdleHoldTimer); case Timer_IdleHoldReset: return (&p->IdleHoldResetTimer); + case Timer_Max: + fatal("timer_get called with Timer_Max"); } fatal("King Bula lost in time"); |