diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-09-16 22:36:19 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-09-16 22:36:19 +0000 |
commit | c35ea2410832f6adf4985d1b4bb037bee29be14e (patch) | |
tree | f12dba3827c6ba4538639efbdac1454908e9212b /usr.sbin | |
parent | 286a4d6747c6c5bc2f64a313348e018cafbc892f (diff) |
malloc ibuf instead of having it statically
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index 2349f2c9309..4d2808bded1 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.62 2004/09/16 17:40:10 henning Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.63 2004/09/16 22:36:18 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -67,7 +67,7 @@ void print_prefix(struct bgpd_addr *, u_int8_t, u_int8_t); const char * print_origin(u_int8_t, int); int show_rib_summary_msg(struct imsg *); -struct imsgbuf ibuf; +struct imsgbuf *ibuf; void usage(void) @@ -99,7 +99,9 @@ main(int argc, char *argv[]) if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) err(1, "connect: %s", SOCKET_NAME); - imsg_init(&ibuf, fd); + if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL) + fatal(NULL); + imsg_init(ibuf, fd); done = 0; switch (res->action) { @@ -108,38 +110,38 @@ main(int argc, char *argv[]) /* not reached */ case SHOW: case SHOW_SUMMARY: - imsg_compose(&ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, NULL, 0); + imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, NULL, 0); show_summary_head(); break; case SHOW_FIB: if (!res->addr.af) - imsg_compose(&ibuf, IMSG_CTL_KROUTE, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_KROUTE, 0, 0, -1, &res->flags, sizeof(res->flags)); else - imsg_compose(&ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_KROUTE_ADDR, 0, 0, -1, &res->addr, sizeof(res->addr)); show_fib_head(); break; case SHOW_NEXTHOP: - imsg_compose(&ibuf, IMSG_CTL_SHOW_NEXTHOP, 0, 0, -1, NULL, 0); + imsg_compose(ibuf, IMSG_CTL_SHOW_NEXTHOP, 0, 0, -1, NULL, 0); show_nexthop_head(); break; case SHOW_INTERFACE: - imsg_compose(&ibuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, NULL, 0); + imsg_compose(ibuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, NULL, 0); show_interface_head(); break; case SHOW_NEIGHBOR: case SHOW_NEIGHBOR_TIMERS: if (res->addr.af) - imsg_compose(&ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, &res->addr, sizeof(res->addr)); else - imsg_compose(&ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, NULL, 0); break; case SHOW_RIB: if (res->as.type != AS_NONE) - imsg_compose(&ibuf, IMSG_CTL_SHOW_RIB_AS, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_SHOW_RIB_AS, 0, 0, -1, &res->as, sizeof(res->as)); else if (res->addr.af) { struct ctl_show_rib_prefix msg; @@ -148,15 +150,15 @@ main(int argc, char *argv[]) memcpy(&msg.prefix, &res->addr, sizeof(res->addr)); msg.prefixlen = res->prefixlen; msg.flags = res->flags; - imsg_compose(&ibuf, IMSG_CTL_SHOW_RIB_PREFIX, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_SHOW_RIB_PREFIX, 0, 0, -1, &msg, sizeof(msg)); } else - imsg_compose(&ibuf, IMSG_CTL_SHOW_RIB, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_SHOW_RIB, 0, 0, -1, NULL, 0); show_rib_summary_head(); break; case RELOAD: - imsg_compose(&ibuf, IMSG_CTL_RELOAD, 0, 0, -1, NULL, 0); + imsg_compose(ibuf, IMSG_CTL_RELOAD, 0, 0, -1, NULL, 0); printf("reload request sent.\n"); done = 1; break; @@ -164,12 +166,12 @@ main(int argc, char *argv[]) errx(1, "action==FIB"); break; case FIB_COUPLE: - imsg_compose(&ibuf, IMSG_CTL_FIB_COUPLE, 0, 0, -1, NULL, 0); + imsg_compose(ibuf, IMSG_CTL_FIB_COUPLE, 0, 0, -1, NULL, 0); printf("couple request sent.\n"); done = 1; break; case FIB_DECOUPLE: - imsg_compose(&ibuf, IMSG_CTL_FIB_DECOUPLE, 0, 0, -1, NULL, 0); + imsg_compose(ibuf, IMSG_CTL_FIB_DECOUPLE, 0, 0, -1, NULL, 0); printf("decouple request sent.\n"); done = 1; break; @@ -177,19 +179,19 @@ main(int argc, char *argv[]) errx(1, "action==NEIGHBOR"); break; case NEIGHBOR_UP: - imsg_compose(&ibuf, IMSG_CTL_NEIGHBOR_UP, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_UP, 0, 0, -1, &res->addr, sizeof(res->addr)); printf("request sent.\n"); done = 1; break; case NEIGHBOR_DOWN: - imsg_compose(&ibuf, IMSG_CTL_NEIGHBOR_DOWN, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_DOWN, 0, 0, -1, &res->addr, sizeof(res->addr)); printf("request sent.\n"); done = 1; break; case NEIGHBOR_CLEAR: - imsg_compose(&ibuf, IMSG_CTL_NEIGHBOR_CLEAR, 0, 0, -1, + imsg_compose(ibuf, IMSG_CTL_NEIGHBOR_CLEAR, 0, 0, -1, &res->addr, sizeof(res->addr)); printf("request sent.\n"); done = 1; @@ -201,37 +203,37 @@ main(int argc, char *argv[]) net.prefixlen = res->prefixlen; /* attribute sets are not supported */ if (res->action == NETWORK_ADD) - imsg_compose(&ibuf, IMSG_NETWORK_ADD, 0, 0, -1, + imsg_compose(ibuf, IMSG_NETWORK_ADD, 0, 0, -1, &net, sizeof(net)); else - imsg_compose(&ibuf, IMSG_NETWORK_REMOVE, 0, 0, -1, + imsg_compose(ibuf, IMSG_NETWORK_REMOVE, 0, 0, -1, &net, sizeof(net)); printf("request sent.\n"); done = 1; break; case NETWORK_FLUSH: - imsg_compose(&ibuf, IMSG_NETWORK_FLUSH, 0, 0, -1, NULL, 0); + imsg_compose(ibuf, IMSG_NETWORK_FLUSH, 0, 0, -1, NULL, 0); printf("request sent.\n"); done = 1; break; case NETWORK_SHOW: - imsg_compose(&ibuf, IMSG_CTL_SHOW_NETWORK, 0, 0, -1, NULL, 0); + imsg_compose(ibuf, IMSG_CTL_SHOW_NETWORK, 0, 0, -1, NULL, 0); show_network_head(); break; } - while (ibuf.w.queued) - if (msgbuf_write(&ibuf.w) < 0) + while (ibuf->w.queued) + if (msgbuf_write(&ibuf->w) < 0) err(1, "write error"); while (!done) { - if ((n = imsg_read(&ibuf)) == -1) + if ((n = imsg_read(ibuf)) == -1) errx(1, "imsg_read error"); if (n == 0) errx(1, "pipe closed"); while (!done) { - if ((n = imsg_get(&ibuf, &imsg)) == -1) + if ((n = imsg_get(ibuf, &imsg)) == -1) errx(1, "imsg_get error"); if (n == 0) break; @@ -279,6 +281,7 @@ main(int argc, char *argv[]) } } close(fd); + free(ibuf); exit(0); } |