summaryrefslogtreecommitdiff
path: root/usr.sbin/relayd
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/relayd')
-rw-r--r--usr.sbin/relayd/control.c55
-rw-r--r--usr.sbin/relayd/pfe.c9
-rw-r--r--usr.sbin/relayd/relayd.h9
3 files changed, 60 insertions, 13 deletions
diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c
index b7f78b2434e..a24b86deada 100644
--- a/usr.sbin/relayd/control.c
+++ b/usr.sbin/relayd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.10 2007/01/29 14:23:31 pyr Exp $ */
+/* $OpenBSD: control.c,v 1.11 2007/02/01 20:03:39 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -39,8 +39,6 @@
struct ctl_connlist ctl_conns;
-int control_imsg_relay(struct imsg *imsg);
-
struct ctl_conn *control_connbyfd(int);
struct ctl_conn *control_connbypid(pid_t);
void control_close(int);
@@ -238,9 +236,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (disable_service(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
- else
+ else {
+ memcpy(imsg.data, &id, sizeof(id));
+ control_imsg_forward(&imsg);
imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0,
NULL, 0);
+ }
break;
case IMSG_CTL_SERVICE_ENABLE:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
@@ -249,9 +250,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (enable_service(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
- else
+ else {
+ memcpy(imsg.data, &id, sizeof(id));
+ control_imsg_forward(&imsg);
imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0,
NULL, 0);
+ }
break;
case IMSG_CTL_TABLE_DISABLE:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
@@ -260,9 +264,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (disable_table(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
- else
+ else {
+ memcpy(imsg.data, &id, sizeof(id));
+ control_imsg_forward(&imsg);
imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0,
NULL, 0);
+ }
break;
case IMSG_CTL_TABLE_ENABLE:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
@@ -271,9 +278,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (enable_table(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
- else
+ else {
+ memcpy(imsg.data, &id, sizeof(id));
+ control_imsg_forward(&imsg);
imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0,
NULL, 0);
+ }
break;
case IMSG_CTL_HOST_DISABLE:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
@@ -282,9 +292,12 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (disable_host(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
- else
+ else {
+ memcpy(imsg.data, &id, sizeof(id));
+ control_imsg_forward(&imsg);
imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0,
NULL, 0);
+ }
break;
case IMSG_CTL_HOST_ENABLE:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(id))
@@ -293,14 +306,27 @@ control_dispatch_imsg(int fd, short event, void *arg)
if (enable_host(c, &id))
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
NULL, 0);
- else
+ else {
+ memcpy(imsg.data, &id, sizeof(id));
+ control_imsg_forward(&imsg);
imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0,
NULL, 0);
+ }
break;
case IMSG_CTL_SHUTDOWN:
case IMSG_CTL_RELOAD:
imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, NULL, 0);
break;
+ case IMSG_CTL_NOTIFY:
+ if (c->flags & CTL_CONN_NOTIFY) {
+ log_debug("control_dispatch_imsg: "
+ "client requested notify more than once");
+ imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0,
+ NULL, 0);
+ break;
+ }
+ c->flags |= CTL_CONN_NOTIFY;
+ break;
default:
log_debug("control_dispatch_imsg: "
"error handling imsg %d", imsg.hdr.type);
@@ -325,6 +351,17 @@ control_imsg_relay(struct imsg *imsg)
}
void
+control_imsg_forward(struct imsg *imsg)
+{
+ struct ctl_conn *c;
+
+ TAILQ_FOREACH(c, &ctl_conns, entry)
+ if (c->flags & CTL_CONN_NOTIFY)
+ imsg_compose(&c->ibuf, imsg->hdr.type, 0, imsg->hdr.pid,
+ imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE);
+}
+
+void
session_socket_blockmode(int fd, enum blockmodes bm)
{
int flags;
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 43c6f358c37..b77b411d82b 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.9 2007/01/29 14:23:31 pyr Exp $ */
+/* $OpenBSD: pfe.c,v 1.10 2007/02/01 20:03:39 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -182,6 +182,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
if (n == 0)
break;
+ control_imsg_forward(&imsg);
switch (imsg.hdr.type) {
case IMSG_HOST_STATUS:
if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(st))
@@ -314,6 +315,7 @@ disable_service(struct ctl_conn *c, struct ctl_id *id)
service = service_findbyname(env, id->name);
else
service = service_find(env, id->id);
+ id->id = service->id;
if (service == NULL)
return (-1);
@@ -339,6 +341,7 @@ enable_service(struct ctl_conn *c, struct ctl_id *id)
service = service_findbyname(env, id->name);
else
service = service_find(env, id->id);
+ id->id = service->id;
if (service == NULL)
return (-1);
@@ -373,6 +376,7 @@ disable_table(struct ctl_conn *c, struct ctl_id *id)
table = table_findbyname(env, id->name);
else
table = table_find(env, id->id);
+ id->id = table->id;
if (table == NULL)
return (-1);
if ((service = service_find(env, table->serviceid)) == NULL)
@@ -402,6 +406,7 @@ enable_table(struct ctl_conn *c, struct ctl_id *id)
table = table_findbyname(env, id->name);
else
table = table_find(env, id->id);
+ id->id = table->id;
if (table == NULL)
return (-1);
@@ -432,6 +437,7 @@ disable_host(struct ctl_conn *c, struct ctl_id *id)
host = host_findbyname(env, id->name);
else
host = host_find(env, id->id);
+ id->id = host->id;
if (host == NULL)
return (-1);
@@ -466,6 +472,7 @@ enable_host(struct ctl_conn *c, struct ctl_id *id)
host = host_findbyname(env, id->name);
else
host = host_find(env, id->id);
+ id->id = host->id;
if (host == NULL)
return (-1);
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index f375d5724c6..bd16884396a 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.17 2007/01/29 14:23:31 pyr Exp $ */
+/* $OpenBSD: relayd.h,v 1.18 2007/02/01 20:03:39 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -89,14 +89,14 @@ enum imsg_type {
IMSG_CTL_HOST_DISABLE,
IMSG_CTL_SHUTDOWN,
IMSG_CTL_RELOAD,
+ IMSG_CTL_NOTIFY,
IMSG_SERVICE_ENABLE, /* notifies from pfe to hce */
IMSG_SERVICE_DISABLE,
IMSG_TABLE_ENABLE,
IMSG_TABLE_DISABLE,
IMSG_HOST_ENABLE,
IMSG_HOST_DISABLE,
- IMSG_TABLE_STATUS, /* notifies from hce to pfe */
- IMSG_HOST_STATUS,
+ IMSG_HOST_STATUS, /* notifies from hce to pfe */
IMSG_SYNC
};
@@ -270,6 +270,8 @@ enum blockmodes {
struct ctl_conn {
TAILQ_ENTRY(ctl_conn) entry;
+ u_int8_t flags;
+#define CTL_CONN_NOTIFY 0x01
struct imsgbuf ibuf;
};
@@ -281,6 +283,7 @@ int control_listen(void);
void control_accept(int, short, void *);
void control_dispatch_imsg(int, short, void *);
int control_imsg_relay(struct imsg *);
+void control_imsg_forward(struct imsg *);
void control_cleanup(void);
void session_socket_blockmode(int, enum blockmodes);