summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@cvs.openbsd.org>2007-05-29 23:19:19 +0000
committerPierre-Yves Ritschard <pyr@cvs.openbsd.org>2007-05-29 23:19:19 +0000
commit6f0aa2bc0d2309a080e85b5470f4e466b941a8dc (patch)
treeea78ae79dde6e051ea7177a135474a13139ec134
parent3657b9f8de0def746e0c4241bee2fe4cc6f1e885 (diff)
allow the control handling code to send messages back to the parent.
forward IMSG_CTL_RELOAD which ends up not doing anything for now.
-rw-r--r--usr.sbin/hoststatectl/hoststatectl.c6
-rw-r--r--usr.sbin/hoststated/control.c23
-rw-r--r--usr.sbin/hoststated/hoststated.c16
-rw-r--r--usr.sbin/hoststated/hoststated.h4
-rw-r--r--usr.sbin/hoststated/pfe.c4
-rw-r--r--usr.sbin/relayctl/relayctl.c6
-rw-r--r--usr.sbin/relayd/control.c23
-rw-r--r--usr.sbin/relayd/pfe.c4
-rw-r--r--usr.sbin/relayd/relayd.c16
-rw-r--r--usr.sbin/relayd/relayd.h4
10 files changed, 72 insertions, 34 deletions
diff --git a/usr.sbin/hoststatectl/hoststatectl.c b/usr.sbin/hoststatectl/hoststatectl.c
index 7b5c539b144..68182e732a6 100644
--- a/usr.sbin/hoststatectl/hoststatectl.c
+++ b/usr.sbin/hoststatectl/hoststatectl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststatectl.c,v 1.18 2007/05/29 00:21:10 pyr Exp $ */
+/* $OpenBSD: hoststatectl.c,v 1.19 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -212,10 +212,10 @@ main(int argc, char *argv[])
case TABLE_ENABLE:
case HOST_DISABLE:
case HOST_ENABLE:
- done = show_command_output(&imsg);
- break;
case RELOAD:
case SHUTDOWN:
+ done = show_command_output(&imsg);
+ break;
case NONE:
break;
case MONITOR:
diff --git a/usr.sbin/hoststated/control.c b/usr.sbin/hoststated/control.c
index f758ee4a6b8..e4f42402748 100644
--- a/usr.sbin/hoststated/control.c
+++ b/usr.sbin/hoststated/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.14 2007/03/19 10:11:59 henning Exp $ */
+/* $OpenBSD: control.c,v 1.15 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -42,6 +42,8 @@ struct ctl_connlist ctl_conns;
struct ctl_conn *control_connbyfd(int);
void control_close(int);
+struct imsgbuf *ibuf_main = NULL;
+
int
control_init(void)
{
@@ -54,7 +56,6 @@ control_init(void)
return (-1);
}
- bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
if (strlcpy(sun.sun_path, HOSTSTATED_SOCKET,
sizeof(sun.sun_path)) >= sizeof(sun.sun_path)) {
@@ -93,16 +94,18 @@ control_init(void)
}
int
-control_listen(void)
+control_listen(struct hoststated *env, struct imsgbuf *ibuf)
{
+ ibuf_main = ibuf;
+
if (listen(control_state.fd, CONTROL_BACKLOG) == -1) {
log_warn("control_listen: listen");
return (-1);
}
event_set(&control_state.ev, control_state.fd, EV_READ | EV_PERSIST,
- control_accept, NULL);
+ control_accept, env);
event_add(&control_state.ev, NULL);
return (0);
@@ -122,6 +125,7 @@ control_accept(int listenfd, short event, void *arg)
socklen_t len;
struct sockaddr_un sun;
struct ctl_conn *c;
+ struct hoststated *env = arg;
len = sizeof(sun);
if ((connfd = accept(listenfd,
@@ -141,7 +145,7 @@ control_accept(int listenfd, short event, void *arg)
imsg_init(&c->ibuf, connfd, control_dispatch_imsg);
c->ibuf.events = EV_READ;
event_set(&c->ibuf.ev, c->ibuf.fd, c->ibuf.events,
- c->ibuf.handler, &c->ibuf);
+ c->ibuf.handler, env);
event_add(&c->ibuf.ev, NULL);
TAILQ_INSERT_TAIL(&ctl_conns, c, entry);
@@ -183,6 +187,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
struct imsg imsg;
struct ctl_id id;
int n;
+ struct hoststated *env = arg;
if ((c = control_connbyfd(fd)) == NULL) {
log_warn("control_dispatch_imsg: fd %d: not found", fd);
@@ -305,8 +310,16 @@ control_dispatch_imsg(int fd, short event, void *arg)
}
break;
case IMSG_CTL_SHUTDOWN:
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0);
+ break;
case IMSG_CTL_RELOAD:
+ if (env->prefork_relay > 0) {
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
+ NULL, 0);
+ break;
+ }
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0);
+ imsg_compose(ibuf_main, IMSG_CTL_RELOAD, 0, 0, NULL, 0);
break;
case IMSG_CTL_NOTIFY:
if (c->flags & CTL_CONN_NOTIFY) {
diff --git a/usr.sbin/hoststated/hoststated.c b/usr.sbin/hoststated/hoststated.c
index 8e15e31f67f..3608b59fa6e 100644
--- a/usr.sbin/hoststated/hoststated.c
+++ b/usr.sbin/hoststated/hoststated.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.c,v 1.28 2007/05/29 18:59:53 pyr Exp $ */
+/* $OpenBSD: hoststated.c,v 1.29 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -241,10 +241,11 @@ main(int argc, char *argv[])
(ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL)
fatal(NULL);
- if (env->prefork_relay > 0 &&
- (ibuf_relay = calloc(env->prefork_relay,
- sizeof(struct imsgbuf)) == NULL))
- fatal(NULL);
+ if (env->prefork_relay > 0) {
+ if ((ibuf_relay = calloc(env->prefork_relay,
+ sizeof(struct imsgbuf))) == NULL)
+ fatal(NULL);
+ }
imsg_init(ibuf_pfe, pipe_parent2pfe[0], main_dispatch_pfe);
imsg_init(ibuf_hce, pipe_parent2hce[0], main_dispatch_hce);
@@ -474,6 +475,11 @@ main_dispatch_pfe(int fd, short event, void *ptr)
memcpy(&demote, imsg.data, sizeof(demote));
carp_demote_set(demote.group, demote.level);
break;
+ case IMSG_CTL_RELOAD:
+ /*
+ * so far we only get here if no L7 (relay) is done.
+ */
+ break;
default:
log_debug("main_dispatch_pfe: unexpected imsg %d",
imsg.hdr.type);
diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h
index 5361acbc55d..4801b76c287 100644
--- a/usr.sbin/hoststated/hoststated.h
+++ b/usr.sbin/hoststated/hoststated.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.h,v 1.49 2007/05/29 19:05:13 pyr Exp $ */
+/* $OpenBSD: hoststated.h,v 1.50 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -603,7 +603,7 @@ TAILQ_HEAD(ctl_connlist, ctl_conn);
/* control.c */
int control_init(void);
-int control_listen(void);
+int control_listen(struct hoststated *, struct imsgbuf *);
void control_accept(int, short, void *);
void control_dispatch_imsg(int, short, void *);
void control_imsg_forward(struct imsg *);
diff --git a/usr.sbin/hoststated/pfe.c b/usr.sbin/hoststated/pfe.c
index a60f06c6b56..f91d0814a8a 100644
--- a/usr.sbin/hoststated/pfe.c
+++ b/usr.sbin/hoststated/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.24 2007/05/28 22:11:33 pyr Exp $ */
+/* $OpenBSD: pfe.c,v 1.25 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -157,7 +157,7 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
TAILQ_INIT(&ctl_conns);
- if (control_listen() == -1)
+ if (control_listen(env, ibuf_main) == -1)
fatalx("pfe: control socket listen failed");
/* Initial sync */
diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c
index d2e8f0b37fe..d4663156688 100644
--- a/usr.sbin/relayctl/relayctl.c
+++ b/usr.sbin/relayctl/relayctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayctl.c,v 1.18 2007/05/29 00:21:10 pyr Exp $ */
+/* $OpenBSD: relayctl.c,v 1.19 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -212,10 +212,10 @@ main(int argc, char *argv[])
case TABLE_ENABLE:
case HOST_DISABLE:
case HOST_ENABLE:
- done = show_command_output(&imsg);
- break;
case RELOAD:
case SHUTDOWN:
+ done = show_command_output(&imsg);
+ break;
case NONE:
break;
case MONITOR:
diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c
index f758ee4a6b8..e4f42402748 100644
--- a/usr.sbin/relayd/control.c
+++ b/usr.sbin/relayd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.14 2007/03/19 10:11:59 henning Exp $ */
+/* $OpenBSD: control.c,v 1.15 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -42,6 +42,8 @@ struct ctl_connlist ctl_conns;
struct ctl_conn *control_connbyfd(int);
void control_close(int);
+struct imsgbuf *ibuf_main = NULL;
+
int
control_init(void)
{
@@ -54,7 +56,6 @@ control_init(void)
return (-1);
}
- bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
if (strlcpy(sun.sun_path, HOSTSTATED_SOCKET,
sizeof(sun.sun_path)) >= sizeof(sun.sun_path)) {
@@ -93,16 +94,18 @@ control_init(void)
}
int
-control_listen(void)
+control_listen(struct hoststated *env, struct imsgbuf *ibuf)
{
+ ibuf_main = ibuf;
+
if (listen(control_state.fd, CONTROL_BACKLOG) == -1) {
log_warn("control_listen: listen");
return (-1);
}
event_set(&control_state.ev, control_state.fd, EV_READ | EV_PERSIST,
- control_accept, NULL);
+ control_accept, env);
event_add(&control_state.ev, NULL);
return (0);
@@ -122,6 +125,7 @@ control_accept(int listenfd, short event, void *arg)
socklen_t len;
struct sockaddr_un sun;
struct ctl_conn *c;
+ struct hoststated *env = arg;
len = sizeof(sun);
if ((connfd = accept(listenfd,
@@ -141,7 +145,7 @@ control_accept(int listenfd, short event, void *arg)
imsg_init(&c->ibuf, connfd, control_dispatch_imsg);
c->ibuf.events = EV_READ;
event_set(&c->ibuf.ev, c->ibuf.fd, c->ibuf.events,
- c->ibuf.handler, &c->ibuf);
+ c->ibuf.handler, env);
event_add(&c->ibuf.ev, NULL);
TAILQ_INSERT_TAIL(&ctl_conns, c, entry);
@@ -183,6 +187,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
struct imsg imsg;
struct ctl_id id;
int n;
+ struct hoststated *env = arg;
if ((c = control_connbyfd(fd)) == NULL) {
log_warn("control_dispatch_imsg: fd %d: not found", fd);
@@ -305,8 +310,16 @@ control_dispatch_imsg(int fd, short event, void *arg)
}
break;
case IMSG_CTL_SHUTDOWN:
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0);
+ break;
case IMSG_CTL_RELOAD:
+ if (env->prefork_relay > 0) {
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
+ NULL, 0);
+ break;
+ }
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0);
+ imsg_compose(ibuf_main, IMSG_CTL_RELOAD, 0, 0, NULL, 0);
break;
case IMSG_CTL_NOTIFY:
if (c->flags & CTL_CONN_NOTIFY) {
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index a60f06c6b56..f91d0814a8a 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.24 2007/05/28 22:11:33 pyr Exp $ */
+/* $OpenBSD: pfe.c,v 1.25 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -157,7 +157,7 @@ pfe(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
TAILQ_INIT(&ctl_conns);
- if (control_listen() == -1)
+ if (control_listen(env, ibuf_main) == -1)
fatalx("pfe: control socket listen failed");
/* Initial sync */
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index f7ac75092d8..10810254e13 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.28 2007/05/29 18:59:53 pyr Exp $ */
+/* $OpenBSD: relayd.c,v 1.29 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -241,10 +241,11 @@ main(int argc, char *argv[])
(ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL)
fatal(NULL);
- if (env->prefork_relay > 0 &&
- (ibuf_relay = calloc(env->prefork_relay,
- sizeof(struct imsgbuf)) == NULL))
- fatal(NULL);
+ if (env->prefork_relay > 0) {
+ if ((ibuf_relay = calloc(env->prefork_relay,
+ sizeof(struct imsgbuf))) == NULL)
+ fatal(NULL);
+ }
imsg_init(ibuf_pfe, pipe_parent2pfe[0], main_dispatch_pfe);
imsg_init(ibuf_hce, pipe_parent2hce[0], main_dispatch_hce);
@@ -474,6 +475,11 @@ main_dispatch_pfe(int fd, short event, void *ptr)
memcpy(&demote, imsg.data, sizeof(demote));
carp_demote_set(demote.group, demote.level);
break;
+ case IMSG_CTL_RELOAD:
+ /*
+ * so far we only get here if no L7 (relay) is done.
+ */
+ break;
default:
log_debug("main_dispatch_pfe: unexpected imsg %d",
imsg.hdr.type);
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 7885db2f4a8..10115512aed 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.49 2007/05/29 19:05:13 pyr Exp $ */
+/* $OpenBSD: relayd.h,v 1.50 2007/05/29 23:19:18 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -603,7 +603,7 @@ TAILQ_HEAD(ctl_connlist, ctl_conn);
/* control.c */
int control_init(void);
-int control_listen(void);
+int control_listen(struct hoststated *, struct imsgbuf *);
void control_accept(int, short, void *);
void control_dispatch_imsg(int, short, void *);
void control_imsg_forward(struct imsg *);