diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-04 18:51:24 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-04 18:51:24 +0000 |
commit | 28b7b3ac46fb9369695f70ad210291f7a919568d (patch) | |
tree | 54b06bd568c9f4258f6c3095332266be1ecffd20 | |
parent | c7bb0964d9cd0217cdaf4a82ab3d44c63597eaaf (diff) |
allow "show neighbor" to be limited to one specific neighbor
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 31 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 12 | ||||
-rw-r--r-- | usr.sbin/bgpd/control.c | 19 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.c | 4 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.h | 8 |
5 files changed, 60 insertions, 14 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index 4677c491b73..39033abc062 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.10 2004/01/04 17:55:19 henning Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.11 2004/01/04 18:51:23 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -54,6 +54,7 @@ void show_summary_head(void); int show_summary_msg(struct imsg *); int show_neighbor_msg(struct imsg *); static char *fmt_timeframe(time_t t); +int parse_addr(const char *, struct bgpd_addr *); struct imsgbuf ibuf; @@ -64,6 +65,7 @@ main(int argc, char *argv[]) int fd, n, done; struct imsg imsg; enum actions action = SHOW_SUMMARY; + struct bgpd_addr addr; if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { err(1, "control_init: socket"); @@ -102,7 +104,13 @@ again: break; case SHOW_NEIGHBOR: /* get ip address of neighbor, limit query to that */ - imsg_compose(&ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, NULL, 0); + if (argc >= 4) { + if (!parse_addr(argv[3], &addr)) + errx(1, "%s: not an IP address", argv[3]); + imsg_compose(&ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, + &addr, sizeof(addr)); + } else + imsg_compose(&ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, NULL, 0); break; } @@ -262,4 +270,21 @@ fmt_timeframe(time_t t) snprintf(buf, TF_LEN, "%02u:%02u:%02u", hrs, min, sec); return (buf); -}
\ No newline at end of file +} + +int +parse_addr(const char *word, struct bgpd_addr *addr) +{ + struct in_addr ina; + + bzero(addr, sizeof(struct bgpd_addr)); + bzero(&ina, sizeof(ina)); + + if (inet_pton(AF_INET, word, &ina)) { + addr->af = AF_INET; + addr->v4 = ina; + return (1); + } + + return (0); +} diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index f7d8f6ba2bf..2f97b8a0c74 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.50 2004/01/03 20:37:34 henning Exp $ */ +/* $OpenBSD: bgpd.h,v 1.51 2004/01/04 18:51:23 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -75,6 +75,16 @@ struct msgbuf { TAILQ_HEAD(bufs, buf) bufs; }; +struct bgpd_addr { + sa_family_t af; + union { + struct in_addr v4; + struct in6_addr v6; + } ba; /* 128-bit address */ +#define v4 ba.v4 +#define v6 ba.v6 +}; + struct bgpd_config { int opts; u_int16_t as; diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c index fbeb4f22f24..7eb6dda7f69 100644 --- a/usr.sbin/bgpd/control.c +++ b/usr.sbin/bgpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.7 2004/01/03 20:22:07 henning Exp $ */ +/* $OpenBSD: control.c,v 1.8 2004/01/04 18:51:23 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -173,6 +173,7 @@ control_dispatch_msg(struct pollfd *pfd, int i) struct ctl_conn *c; int n; struct peer *p; + struct bgpd_addr *addr; if ((c = control_connbyfd(pfd->fd)) == NULL) { log_err("control_dispatch_msg: fd %d: not found", pfd->fd); @@ -195,9 +196,19 @@ control_dispatch_msg(struct pollfd *pfd, int i) switch (imsg.hdr.type) { case IMSG_CTL_SHOW_NEIGHBOR: - for (p = peers; p != NULL; p = p->next) - imsg_compose(&c->ibuf, IMSG_CTL_SHOW_NEIGHBOR, - 0, p, sizeof(struct peer)); + if (imsg.hdr.len == IMSG_HEADER_SIZE + + sizeof(struct bgpd_addr)) { + addr = imsg.data; + p = getpeerbyip(addr->v4.s_addr); + if (p != NULL) + imsg_compose(&c->ibuf, + IMSG_CTL_SHOW_NEIGHBOR, + 0, p, sizeof(struct peer)); + } else + for (p = peers; p != NULL; p = p->next) + imsg_compose(&c->ibuf, + IMSG_CTL_SHOW_NEIGHBOR, + 0, p, sizeof(struct peer)); imsg_compose(&c->ibuf, IMSG_CTL_END, 0, NULL, 0); break; default: diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index 25c01842f45..f7df8dfbc99 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.59 2004/01/04 17:19:41 henning Exp $ */ +/* $OpenBSD: session.c,v 1.60 2004/01/04 18:51:23 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -78,8 +78,6 @@ void session_dispatch_imsg(struct imsgbuf *, int); void session_up(struct peer *); void session_down(struct peer *); -struct peer *getpeerbyip(in_addr_t); - struct bgpd_config *conf, *nconf = NULL; struct peer *npeers; volatile sig_atomic_t session_quit = 0; diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index 8ad48abdd65..96be2a88899 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.7 2004/01/03 22:44:29 henning Exp $ */ +/* $OpenBSD: session.h,v 1.8 2004/01/04 18:51:23 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -144,9 +144,11 @@ struct peer { struct peer *peers; /* session.c */ -void session_socket_blockmode(int, enum blockmodes); -int session_main(struct bgpd_config *, struct peer *, int[2], +void session_socket_blockmode(int, enum blockmodes); +int session_main(struct bgpd_config *, struct peer *, int[2], int[2]); +struct peer *getpeerbyip(in_addr_t); + /* log.c */ void log_peer_err(const struct peer *, const char *, ...); |