summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2003-12-26 18:33:12 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2003-12-26 18:33:12 +0000
commit8df7e50db052f3d9988d01cb19ae565da176d463 (patch)
tree317809e8f1ab578553c046f79d3f921496f89beb /usr.sbin/bgpd
parent813e6af054fdcbfbf7a2222b80c873ba29a90e6e (diff)
let imsg_get and imsg_compose not fatal() but return errors upstream.
make the callers cope.
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/bgpd.c37
-rw-r--r--usr.sbin/bgpd/imsg.c44
-rw-r--r--usr.sbin/bgpd/rde.c32
-rw-r--r--usr.sbin/bgpd/session.c22
4 files changed, 88 insertions, 47 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c
index a48b6270e97..77eec4923c5 100644
--- a/usr.sbin/bgpd/bgpd.c
+++ b/usr.sbin/bgpd/bgpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.c,v 1.38 2003/12/26 18:07:32 henning Exp $ */
+/* $OpenBSD: bgpd.c,v 1.39 2003/12/26 18:33:11 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -305,18 +305,23 @@ reconfigure(char *conffile, struct bgpd_config *conf, struct mrt_config *mrtc)
conffile);
return (-1);
}
- imsg_compose(&ibuf_se, IMSG_RECONF_CONF, 0,
- conf, sizeof(struct bgpd_config));
- imsg_compose(&ibuf_rde, IMSG_RECONF_CONF, 0,
- conf, sizeof(struct bgpd_config));
+ if (imsg_compose(&ibuf_se, IMSG_RECONF_CONF, 0,
+ conf, sizeof(struct bgpd_config)) == -1)
+ return (-1);
+ if (imsg_compose(&ibuf_rde, IMSG_RECONF_CONF, 0,
+ conf, sizeof(struct bgpd_config)) == -1)
+ return (-1);
for (p = conf->peers; p != NULL; p = p->next) {
- imsg_compose(&ibuf_se, IMSG_RECONF_PEER, p->conf.id,
- &p->conf, sizeof(struct peer_config));
- imsg_compose(&ibuf_rde, IMSG_RECONF_PEER, p->conf.id,
- &p->conf, sizeof(struct peer_config));
+ if (imsg_compose(&ibuf_se, IMSG_RECONF_PEER, p->conf.id,
+ &p->conf, sizeof(struct peer_config)) == -1)
+ return (-1);
+ if (imsg_compose(&ibuf_rde, IMSG_RECONF_PEER, p->conf.id,
+ &p->conf, sizeof(struct peer_config)) == -1)
+ return (-1);
}
- imsg_compose(&ibuf_se, IMSG_RECONF_DONE, 0, NULL, 0);
- imsg_compose(&ibuf_rde, IMSG_RECONF_DONE, 0, NULL, 0);
+ if (imsg_compose(&ibuf_se, IMSG_RECONF_DONE, 0, NULL, 0) == -1 ||
+ imsg_compose(&ibuf_rde, IMSG_RECONF_DONE, 0, NULL, 0) == -1)
+ return (-1);
return (0);
}
@@ -334,7 +339,10 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct mrt_config *conf)
int n;
in_addr_t ina;
- if (imsg_get(ibuf, &imsg) > 0) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ return (-1);
+
+ if (n > 0) {
switch (imsg.hdr.type) {
case IMSG_MRT_MSG:
case IMSG_MRT_END:
@@ -402,6 +410,7 @@ send_nexthop_update(struct kroute_nexthop *msg)
msg->gateway ? ": via " : "",
msg->gateway ? log_ntoa(msg->gateway) : "");
- imsg_compose(&ibuf_rde, IMSG_NEXTHOP_UPDATE, 0,
- msg, sizeof(struct kroute_nexthop));
+ if (imsg_compose(&ibuf_rde, IMSG_NEXTHOP_UPDATE, 0,
+ msg, sizeof(struct kroute_nexthop)) == -1)
+ quit = 1;
}
diff --git a/usr.sbin/bgpd/imsg.c b/usr.sbin/bgpd/imsg.c
index 7d8995a928d..7c740bc0a83 100644
--- a/usr.sbin/bgpd/imsg.c
+++ b/usr.sbin/bgpd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.10 2003/12/26 18:07:32 henning Exp $ */
+/* $OpenBSD: imsg.c,v 1.11 2003/12/26 18:33:11 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -54,8 +54,10 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
do {
if ((n = read(ibuf->sock, ibuf->r.wptr,
ibuf->r.pkt_len - ibuf->r.read_len)) == -1) {
- if (errno != EAGAIN && errno != EINTR)
- fatal("pipe read error");
+ if (errno != EAGAIN && errno != EINTR) {
+ log_err("imsg_get pipe read error");
+ return (-1);
+ }
return (0);
}
read_total += n;
@@ -68,8 +70,10 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
ibuf->r.pkt_len = hdr->len;
ibuf->r.peerid = hdr->peerid;
if (hdr->len < IMSG_HEADER_SIZE ||
- hdr->len > MAX_IMSGSIZE)
- fatalx("wrong imsg header len");
+ hdr->len > MAX_IMSGSIZE) {
+ logit(LOG_CRIT, "wrong imsg hdr len");
+ return (-1);
+ }
ibuf->r.seen_hdr = 1;
} else { /* we got the full packet */
imsg->hdr.type = ibuf->r.type;
@@ -77,8 +81,10 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
imsg->hdr.peerid = ibuf->r.peerid;
datalen = ibuf->r.pkt_len - IMSG_HEADER_SIZE;
rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
- if ((imsg->data = malloc(datalen)) == NULL)
- fatal("get_imsg malloc");
+ if ((imsg->data = malloc(datalen)) == NULL) {
+ log_err("imsg_get");
+ return (-1);
+ }
memcpy(imsg->data, rptr, datalen);
n = 0; /* give others a chance */
imsg_init_readbuf(ibuf);
@@ -104,16 +110,24 @@ imsg_compose(struct imsgbuf *ibuf, int type, u_int32_t peerid, void *data,
hdr.type = type;
hdr.peerid = peerid;
wbuf = buf_open(hdr.len);
- if (wbuf == NULL)
- fatalx("imsg_compose: buf_open error");
- if (buf_add(wbuf, &hdr, sizeof(hdr)) == -1)
- fatalx("imsg_compose: buf_add error");
+ if (wbuf == NULL) {
+ logit(LOG_CRIT, "imsg_compose: buf_open error");
+ return (-1);
+ }
+ if (buf_add(wbuf, &hdr, sizeof(hdr)) == -1) {
+ logit(LOG_CRIT, "imsg_compose: buf_add error");
+ return (-1);
+ }
if (datalen)
- if (buf_add(wbuf, data, datalen) == -1)
- fatalx("imsg_compose: buf_add error");
- if ((n = buf_close(&ibuf->w, wbuf)) < 0)
- fatal("imsg_compose: buf_close error");
+ if (buf_add(wbuf, data, datalen) == -1) {
+ logit(LOG_CRIT, "imsg_compose: buf_add error");
+ return (-1);
+ }
+ if ((n = buf_close(&ibuf->w, wbuf)) < 0) {
+ logit(LOG_CRIT, "imsg_compose: buf_add error");
+ return (-1);
+ }
return (n);
}
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 12b7f98375b..2f48e8a402b 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.32 2003/12/26 18:07:33 henning Exp $ */
+/* $OpenBSD: rde.c,v 1.33 2003/12/26 18:33:11 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -170,8 +170,12 @@ rde_dispatch_imsg(struct imsgbuf *ibuf, int idx)
struct peer_config *pconf;
struct rde_peer *p, *np;
u_int32_t rid;
+ int n;
- if (imsg_get(ibuf, &imsg) > 0) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("imsg_get error");
+
+ if (n > 0) {
switch (imsg.hdr.type) {
case IMSG_RECONF_CONF:
if (idx != PFD_PIPE_MAIN)
@@ -254,8 +258,9 @@ rde_dispatch_imsg(struct imsgbuf *ibuf, int idx)
if (idx != PFD_PIPE_MAIN)
fatalx("mrt request not from parent");
/* ignore end message because a dump is atomic */
- imsg_compose(&ibuf_main, IMSG_MRT_END,
- imsg.hdr.peerid, NULL, 0);
+ if (imsg_compose(&ibuf_main, IMSG_MRT_END,
+ imsg.hdr.peerid, NULL, 0) == -1)
+ fatalx("imsg_compose error");
break;
default:
break;
@@ -493,8 +498,9 @@ rde_update_err(u_int32_t peerid, enum suberr_update errorcode)
u_int8_t errcode;
errcode = errorcode;
- imsg_compose(&ibuf_se, IMSG_UPDATE_ERR, peerid,
- &errcode, sizeof(errcode));
+ if (imsg_compose(&ibuf_se, IMSG_UPDATE_ERR, peerid,
+ &errcode, sizeof(errcode)) == -1)
+ fatal("imsg_compose error");
}
/*
@@ -525,7 +531,8 @@ rde_send_kroute(struct prefix *new, struct prefix *old)
kr.prefixlen = p->prefix->prefixlen;
kr.nexthop = p->aspath->flags.nexthop.s_addr;
- imsg_compose(&ibuf_main, type, 0, &kr, sizeof(kr));
+ if (imsg_compose(&ibuf_main, type, 0, &kr, sizeof(kr)) == -1)
+ fatal("imsg_compose error");
}
/*
@@ -534,12 +541,15 @@ rde_send_kroute(struct prefix *new, struct prefix *old)
void
rde_send_nexthop(in_addr_t next, int valid)
{
+ int type;
+
if (valid)
- imsg_compose(&ibuf_main, IMSG_NEXTHOP_ADD, 0,
- &next, sizeof(next));
+ type = IMSG_NEXTHOP_ADD;
else
- imsg_compose(&ibuf_main, IMSG_NEXTHOP_REMOVE, 0,
- &next, sizeof(next));
+ type = IMSG_NEXTHOP_REMOVE;
+
+ if (imsg_compose(&ibuf_main, type, 0, &next, sizeof(next)) == -1)
+ fatal("imsg_compose error");
}
/*
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index 5e5508cc6eb..bb32d643a79 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.45 2003/12/26 18:07:33 henning Exp $ */
+/* $OpenBSD: session.c,v 1.46 2003/12/26 18:33:11 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -1189,7 +1189,9 @@ parse_update(struct peer *peer)
p += MSGSIZE_HEADER; /* header is already checked */
datalen -= MSGSIZE_HEADER;
- imsg_compose(&ibuf_rde, IMSG_UPDATE, peer->conf.id, p, datalen);
+ if (imsg_compose(&ibuf_rde, IMSG_UPDATE, peer->conf.id, p,
+ datalen) == -1)
+ return (-1);
return (0);
}
@@ -1235,8 +1237,12 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx)
struct peer_config *pconf;
struct peer *p, *next;
enum reconf_action reconf;
+ int n;
+
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("imsg_get error");
- if (imsg_get(ibuf, &imsg) > 0) {
+ if (n > 0) {
switch (imsg.hdr.type) {
case IMSG_RECONF_CONF:
if (idx != PFD_PIPE_MAIN)
@@ -1342,13 +1348,15 @@ getpeerbyip(in_addr_t ip)
void
session_down(struct peer *peer)
{
- imsg_compose(&ibuf_rde, IMSG_SESSION_DOWN, peer->conf.id,
- NULL, 0);
+ if (imsg_compose(&ibuf_rde, IMSG_SESSION_DOWN, peer->conf.id,
+ NULL, 0) == -1)
+ fatalx("imsg_compose error");
}
void
session_up(struct peer *peer)
{
- imsg_compose(&ibuf_rde, IMSG_SESSION_UP, peer->conf.id,
- &peer->remote_bgpid, sizeof(peer->remote_bgpid));
+ if (imsg_compose(&ibuf_rde, IMSG_SESSION_UP, peer->conf.id,
+ &peer->remote_bgpid, sizeof(peer->remote_bgpid)) == -1)
+ fatalx("imsg_compose error");
}