summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2007-03-17 22:46:42 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2007-03-17 22:46:42 +0000
commitec0c40572ff05e05f4c2eb1a1da3d10053a7e850 (patch)
treef17e08b1dba99e9872304b266140321156c827aa
parent180ac8efb8b9657f4af16e441b36ba2db04b5cbc (diff)
fix a bug in the initial setup of the pfe2relay communication sockets
which prevented the pfe to accept statistics updates and natlookups from any other process then the first one. in other words, this will show you the total relay statistics off _all_ preforked processes (hoststatectl show relays) and it will unbreak the natlookup mode with more than one running relay process.
-rw-r--r--usr.sbin/hoststated/pfe.c15
-rw-r--r--usr.sbin/relayd/pfe.c15
2 files changed, 20 insertions, 10 deletions
diff --git a/usr.sbin/hoststated/pfe.c b/usr.sbin/hoststated/pfe.c
index f8f818c5218..bdd57ed623e 100644
--- a/usr.sbin/hoststated/pfe.c
+++ b/usr.sbin/hoststated/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.19 2007/03/07 17:40:32 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.20 2007/03/17 22:46:41 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -72,6 +72,7 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
struct event ev_sigterm;
int i;
struct imsgbuf *ibuf;
+ size_t size;
switch (pid = fork()) {
case -1:
@@ -124,9 +125,10 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
for (i = 0; i < env->prefork_relay; i++)
close(pipe_pfe2relay[i][0]);
- if ((ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_relay = calloc(i, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ size = sizeof(struct imsgbuf);
+ if ((ibuf_hce = calloc(1, size)) == NULL ||
+ (ibuf_relay = calloc(env->prefork_relay, size)) == NULL ||
+ (ibuf_main = calloc(1, size)) == NULL)
fatal("pfe");
imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
@@ -145,7 +147,7 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
ibuf = &ibuf_relay[i];
imsg_init(ibuf, pipe_pfe2relay[i][1], pfe_dispatch_relay);
- ibuf_relay->events = EV_READ;
+ ibuf->events = EV_READ;
event_set(&ibuf->ev, ibuf->fd, ibuf->events,
ibuf->handler, ibuf);
event_add(&ibuf->ev, NULL);
@@ -354,6 +356,9 @@ pfe_dispatch_relay(int fd, short event, void * ptr)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(cnl))
fatalx("invalid imsg header len");
bcopy(imsg.data, &cnl, sizeof(cnl));
+ if (cnl.proc > env->prefork_relay)
+ fatalx("pfe_dispatch_relay: "
+ "invalid relay proc");
if (natlook(env, &cnl) != 0)
cnl.in = -1;
imsg_compose(&ibuf_relay[cnl.proc], IMSG_NATLOOK, 0, 0,
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index f8f818c5218..bdd57ed623e 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.19 2007/03/07 17:40:32 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.20 2007/03/17 22:46:41 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -72,6 +72,7 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
struct event ev_sigterm;
int i;
struct imsgbuf *ibuf;
+ size_t size;
switch (pid = fork()) {
case -1:
@@ -124,9 +125,10 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
for (i = 0; i < env->prefork_relay; i++)
close(pipe_pfe2relay[i][0]);
- if ((ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_relay = calloc(i, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ size = sizeof(struct imsgbuf);
+ if ((ibuf_hce = calloc(1, size)) == NULL ||
+ (ibuf_relay = calloc(env->prefork_relay, size)) == NULL ||
+ (ibuf_main = calloc(1, size)) == NULL)
fatal("pfe");
imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
@@ -145,7 +147,7 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
ibuf = &ibuf_relay[i];
imsg_init(ibuf, pipe_pfe2relay[i][1], pfe_dispatch_relay);
- ibuf_relay->events = EV_READ;
+ ibuf->events = EV_READ;
event_set(&ibuf->ev, ibuf->fd, ibuf->events,
ibuf->handler, ibuf);
event_add(&ibuf->ev, NULL);
@@ -354,6 +356,9 @@ pfe_dispatch_relay(int fd, short event, void * ptr)
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(cnl))
fatalx("invalid imsg header len");
bcopy(imsg.data, &cnl, sizeof(cnl));
+ if (cnl.proc > env->prefork_relay)
+ fatalx("pfe_dispatch_relay: "
+ "invalid relay proc");
if (natlook(env, &cnl) != 0)
cnl.in = -1;
imsg_compose(&ibuf_relay[cnl.proc], IMSG_NATLOOK, 0, 0,