diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2005-10-19 12:32:18 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2005-10-19 12:32:18 +0000 |
commit | 90117bd480f49dc64613a7265ad82531cfb37135 (patch) | |
tree | 6b14e46bbe2cb2379b3e1fb794e79f7cae52c395 /usr.sbin | |
parent | 0ca429e0b70fa7f675e1e0182c5354c98d8a4107 (diff) |
for "bgpctl neighbor foo up/down/clear", make bgpctl not exit after sending
the request, but wait for the new IMSG_CTL_RESULT message, which contains
a status code to indicate wether the request was processed successfully
or wether an error occured and if so what kind of error.
no more "IMSG_CTL_NEIGHBOR_ with unknown neighbor foobaz" in the log
when you mistyped foobar - no bgpctl itself complains
claudio ok
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 40 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 10 | ||||
-rw-r--r-- | usr.sbin/bgpd/control.c | 14 | ||||
-rw-r--r-- | usr.sbin/bgpd/log.h | 7 |
4 files changed, 54 insertions, 17 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index a2f81eb8b09..0db49f27791 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.91 2005/09/20 14:40:32 henning Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.92 2005/10/19 12:32:17 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -71,6 +71,7 @@ const char * print_origin(u_int8_t, int); int show_rib_summary_msg(struct imsg *); void send_filterset(struct imsgbuf *, struct filter_set_head *); static const char *get_errstr(u_int8_t, u_int8_t); +int show_result(struct imsg *); struct imsgbuf *ibuf; @@ -221,20 +222,14 @@ main(int argc, char *argv[]) case NEIGHBOR_UP: imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_UP, 0, 0, -1, &neighbor, sizeof(neighbor)); - printf("request sent.\n"); - done = 1; break; case NEIGHBOR_DOWN: imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_DOWN, 0, 0, -1, &neighbor, sizeof(neighbor)); - printf("request sent.\n"); - done = 1; break; case NEIGHBOR_CLEAR: imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_CLEAR, 0, 0, -1, &neighbor, sizeof(neighbor)); - printf("request sent.\n"); - done = 1; break; case NETWORK_ADD: case NETWORK_REMOVE: @@ -307,15 +302,17 @@ main(int argc, char *argv[]) case NETWORK_SHOW: done = show_fib_msg(&imsg); break; + case NEIGHBOR: + case NEIGHBOR_UP: + case NEIGHBOR_DOWN: + case NEIGHBOR_CLEAR: + done = show_result(&imsg); + break; case NONE: case RELOAD: case FIB: case FIB_COUPLE: case FIB_DECOUPLE: - case NEIGHBOR: - case NEIGHBOR_UP: - case NEIGHBOR_DOWN: - case NEIGHBOR_CLEAR: case NETWORK_ADD: case NETWORK_REMOVE: case NETWORK_FLUSH: @@ -1030,3 +1027,24 @@ get_errstr(u_int8_t errcode, u_int8_t subcode) return (errstr); } + +int +show_result(struct imsg *imsg) +{ + u_int rescode; + + if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(rescode)) + errx(1, "got IMSG_CTL_RESULT with wrong len"); + memcpy(&rescode, imsg->data, sizeof(rescode)); + + if (rescode == 0) + printf("request processed\n"); + else { + if (rescode > + sizeof(ctl_res_strerror)/sizeof(ctl_res_strerror[0])) + errx(1, "illegal error code %u", rescode); + printf("%s\n", ctl_res_strerror[rescode]); + } + + return (1); +} diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 9a8c09593ea..c4578092e6f 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.178 2005/10/19 10:42:06 henning Exp $ */ +/* $OpenBSD: bgpd.h,v 1.179 2005/10/19 12:32:16 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -297,7 +297,6 @@ enum imsg_type { IMSG_NETWORK_FLUSH, IMSG_NETWORK_DONE, IMSG_FILTER_SET, - IMSG_CTL_SHOW_NEIGHBOR, IMSG_CTL_END, IMSG_CTL_RELOAD, IMSG_CTL_FIB_COUPLE, @@ -308,6 +307,8 @@ enum imsg_type { IMSG_CTL_KROUTE, IMSG_CTL_KROUTE6, IMSG_CTL_KROUTE_ADDR, + IMSG_CTL_RESULT, + IMSG_CTL_SHOW_NEIGHBOR, IMSG_CTL_SHOW_NEXTHOP, IMSG_CTL_SHOW_INTERFACE, IMSG_CTL_SHOW_RIB, @@ -331,6 +332,11 @@ struct imsg { void *data; }; +enum ctl_results { + CTL_RES_OK, + CTL_RES_NOSUCHPEER +}; + /* needed for session.h parse prototype */ LIST_HEAD(mrt_head, mrt); diff --git a/usr.sbin/bgpd/control.c b/usr.sbin/bgpd/control.c index aa39dc8d5de..18f63aa8dc8 100644 --- a/usr.sbin/bgpd/control.c +++ b/usr.sbin/bgpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.44 2005/10/19 10:26:21 henning Exp $ */ +/* $OpenBSD: control.c,v 1.45 2005/10/19 12:32:16 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -37,6 +37,7 @@ struct { struct ctl_conn *control_connbyfd(int); struct ctl_conn *control_connbypid(pid_t); int control_close(int); +void control_result(struct ctl_conn *, u_int); int control_init(void) @@ -253,8 +254,7 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt) if (p == NULL) p = getpeerbydesc(neighbor->descr); if (p == NULL) { - log_warnx("IMSG_CTL_NEIGHBOR_ " - "with unknown neighbor"); + control_result(c, CTL_RES_NOSUCHPEER); break; } switch (imsg.hdr.type) { @@ -272,6 +272,7 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt) default: fatal("king bula wants more humppa"); } + control_result(c, CTL_RES_OK); } else log_warnx("got IMSG_CTL_NEIGHBOR_ with " "wrong length"); @@ -320,3 +321,10 @@ control_imsg_relay(struct imsg *imsg) return (imsg_compose(&c->ibuf, imsg->hdr.type, 0, imsg->hdr.pid, -1, imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE)); } + +void +control_result(struct ctl_conn *c, u_int code) +{ + imsg_compose(&c->ibuf, IMSG_CTL_RESULT, 0, c->ibuf.pid, -1, + &code, sizeof(code)); +} diff --git a/usr.sbin/bgpd/log.h b/usr.sbin/bgpd/log.h index 8fdec4256dd..a8387e00957 100644 --- a/usr.sbin/bgpd/log.h +++ b/usr.sbin/bgpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.4 2005/06/05 19:50:09 henning Exp $ */ +/* $OpenBSD: log.h,v 1.5 2005/10/19 12:32:16 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -103,3 +103,8 @@ static const char * const procnames[] = { "SE", "RDE" }; + +static const char * const ctl_res_strerror[] = { + "no error", + "no such neighbor" +}; |