summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/imsg.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bgpd/imsg.c')
-rw-r--r--usr.sbin/bgpd/imsg.c93
1 files changed, 13 insertions, 80 deletions
diff --git a/usr.sbin/bgpd/imsg.c b/usr.sbin/bgpd/imsg.c
index 9235a78a84e..dd1eb7eb746 100644
--- a/usr.sbin/bgpd/imsg.c
+++ b/usr.sbin/bgpd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.30 2004/08/19 10:40:14 henning Exp $ */
+/* $OpenBSD: imsg.c,v 1.31 2004/09/16 17:36:29 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -26,11 +26,6 @@
#include "bgpd.h"
-int imsg_compose_core(struct imsgbuf *, int, u_int32_t, void *,
- u_int16_t, pid_t, int);
-struct buf *imsg_create_core(struct imsgbuf *, int, u_int32_t, u_int16_t,
- pid_t);
-
void
imsg_init(struct imsgbuf *ibuf, int fd)
{
@@ -127,93 +122,34 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
}
int
-imsg_compose(struct imsgbuf *ibuf, int type, u_int32_t peerid, void *data,
- u_int16_t datalen)
-{
- return (imsg_compose_core(ibuf, type, peerid, data, datalen,
- ibuf->pid, -1));
-}
-
-int
-imsg_compose_pid(struct imsgbuf *ibuf, int type, pid_t pid, void *data,
- u_int16_t datalen)
-{
- return (imsg_compose_core(ibuf, type, 0, data, datalen, pid, -1));
-}
-
-int
-imsg_compose_fdpass(struct imsgbuf *ibuf, int type, int fd, void *data,
- u_int16_t datalen)
-{
- return (imsg_compose_core(ibuf, type, 0, data, datalen, ibuf->pid, fd));
-}
-
-int
-imsg_compose_core(struct imsgbuf *ibuf, int type, u_int32_t peerid, void *data,
- u_int16_t datalen, pid_t pid, int fd)
+imsg_compose(struct imsgbuf *ibuf, int type, u_int32_t peerid, pid_t pid,
+ int fd, void *data, u_int16_t datalen)
{
struct buf *wbuf;
- struct imsg_hdr hdr;
int n;
- if (datalen + IMSG_HEADER_SIZE > MAX_IMSGSIZE) {
- log_warnx("imsg_compose_core: len %u > MAX_IMSGSIZE; "
- "type %u peerid %lu", datalen + IMSG_HEADER_SIZE,
- type, peerid);
+ if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
return (-1);
- }
- hdr.len = datalen + IMSG_HEADER_SIZE;
- hdr.type = type;
- hdr.peerid = peerid;
- hdr.pid = pid;
- wbuf = buf_open(hdr.len);
- if (wbuf == NULL) {
- log_warn("imsg_compose: buf_open");
- return (-1);
- }
- if (buf_add(wbuf, &hdr, sizeof(hdr)) == -1) {
- log_warnx("imsg_compose: buf_add error");
- buf_free(wbuf);
+ if (imsg_add(wbuf, data, datalen) == -1)
return (-1);
- }
- if (datalen)
- if (buf_add(wbuf, data, datalen) == -1) {
- log_warnx("imsg_compose: buf_add error");
- buf_free(wbuf);
- return (-1);
- }
wbuf->fd = fd;
- if ((n = buf_close(&ibuf->w, wbuf)) < 0) {
- log_warnx("imsg_compose: buf_add error");
- buf_free(wbuf);
+ if ((n = imsg_close(ibuf, wbuf)) < 0)
return (-1);
- }
- return (n);
-}
-struct buf *
-imsg_create(struct imsgbuf *ibuf, int type, u_int32_t peerid, u_int16_t dlen)
-{
- return (imsg_create_core(ibuf, type, peerid, dlen, ibuf->pid));
-}
-
-struct buf *
-imsg_create_pid(struct imsgbuf *ibuf, int type, pid_t pid, u_int16_t datalen)
-{
- return (imsg_create_core(ibuf, type, 0, datalen, pid));
+ return (n);
}
struct buf *
-imsg_create_core(struct imsgbuf *ibuf, int type, u_int32_t peerid,
- u_int16_t datalen, pid_t pid)
+imsg_create(struct imsgbuf *ibuf, int type, u_int32_t peerid,
+ pid_t pid, u_int16_t datalen)
{
struct buf *wbuf;
struct imsg_hdr hdr;
- if (datalen + IMSG_HEADER_SIZE > MAX_IMSGSIZE) {
+ if (datalen > MAX_IMSGSIZE - IMSG_HEADER_SIZE) {
log_warnx("imsg_create_core: len %u > MAX_IMSGSIZE; "
"type %u peerid %lu", datalen + IMSG_HEADER_SIZE,
type, peerid);
@@ -224,16 +160,13 @@ imsg_create_core(struct imsgbuf *ibuf, int type, u_int32_t peerid,
hdr.type = type;
hdr.peerid = peerid;
hdr.pid = pid;
- wbuf = buf_open(hdr.len);
- if (wbuf == NULL) {
+ if ((wbuf = buf_open(hdr.len)) == NULL) {
log_warn("imsg_create: buf_open");
return (NULL);
}
- if (buf_add(wbuf, &hdr, sizeof(hdr)) == -1) {
- log_warnx("imsg_create: buf_add error");
- buf_free(wbuf);
+ if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1)
return (NULL);
- }
+
return (wbuf);
}