summaryrefslogtreecommitdiff
path: root/usr.sbin/relayd
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2010-11-16 15:31:02 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2010-11-16 15:31:02 +0000
commit8216150a6c43e6ca7b9ec06cf003e76359928f9d (patch)
treef366b98d04fcb7f971fb05984902b6fef06d8112 /usr.sbin/relayd
parent1e15a85d6d204e715adcc53f3f7bcee745c288ea (diff)
Add support for enable/disable table when using relays instead of redirects.
From Patrik Lundin and Linus Widstromer. ok reyk@
Diffstat (limited to 'usr.sbin/relayd')
-rw-r--r--usr.sbin/relayd/pfe.c20
-rw-r--r--usr.sbin/relayd/relay.c18
2 files changed, 32 insertions, 6 deletions
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 4abbf874d6d..7c93fc6c5f3 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.65 2010/08/01 22:18:35 sthen Exp $ */
+/* $OpenBSD: pfe.c,v 1.66 2010/11/16 15:31:01 jsg Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -739,8 +739,8 @@ int
disable_table(struct ctl_conn *c, struct ctl_id *id)
{
struct table *table;
- struct rdr *rdr;
struct host *host;
+ int n;
if (id->id == EMPTY_ID)
table = table_findbyname(env, id->name);
@@ -749,7 +749,7 @@ disable_table(struct ctl_conn *c, struct ctl_id *id)
if (table == NULL)
return (-1);
id->id = table->conf.id;
- if ((rdr = rdr_find(env, table->conf.rdrid)) == NULL)
+ if (table->conf.rdrid > 0 && rdr_find(env, table->conf.rdrid) == NULL)
fatalx("disable_table: desynchronised");
if (table->conf.flags & F_DISABLE)
@@ -760,6 +760,11 @@ disable_table(struct ctl_conn *c, struct ctl_id *id)
host->up = HOST_UNKNOWN;
imsg_compose_event(iev_hce, IMSG_TABLE_DISABLE, 0, 0, -1,
&table->conf.id, sizeof(table->conf.id));
+ /* Forward to relay engine(s) */
+ for (n = 0; n < env->sc_prefork_relay; n++)
+ imsg_compose_event(&iev_relay[n],
+ IMSG_TABLE_DISABLE, 0, 0, -1,
+ &table->conf.id, sizeof(table->conf.id));
log_debug("disable_table: disabled table %d", table->conf.id);
pfe_sync();
return (0);
@@ -768,9 +773,9 @@ disable_table(struct ctl_conn *c, struct ctl_id *id)
int
enable_table(struct ctl_conn *c, struct ctl_id *id)
{
- struct rdr *rdr;
struct table *table;
struct host *host;
+ int n;
if (id->id == EMPTY_ID)
table = table_findbyname(env, id->name);
@@ -780,7 +785,7 @@ enable_table(struct ctl_conn *c, struct ctl_id *id)
return (-1);
id->id = table->conf.id;
- if ((rdr = rdr_find(env, table->conf.rdrid)) == NULL)
+ if (table->conf.rdrid > 0 && rdr_find(env, table->conf.rdrid) == NULL)
fatalx("enable_table: desynchronised");
if (!(table->conf.flags & F_DISABLE))
@@ -792,6 +797,11 @@ enable_table(struct ctl_conn *c, struct ctl_id *id)
host->up = HOST_UNKNOWN;
imsg_compose_event(iev_hce, IMSG_TABLE_ENABLE, 0, 0, -1,
&table->conf.id, sizeof(table->conf.id));
+ /* Forward to relay engine(s) */
+ for (n = 0; n < env->sc_prefork_relay; n++)
+ imsg_compose_event(&iev_relay[n],
+ IMSG_TABLE_ENABLE, 0, 0, -1,
+ &table->conf.id, sizeof(table->conf.id));
log_debug("enable_table: enabled table %d", table->conf.id);
pfe_sync();
return (0);
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index c421e851ffc..e7ddef25742 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.123 2010/10/12 14:52:21 dhill Exp $ */
+/* $OpenBSD: relay.c,v 1.124 2010/11/16 15:31:01 jsg Exp $ */
/*
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -2492,6 +2492,22 @@ relay_dispatch_pfe(int fd, short event, void *ptr)
host->flags &= ~(F_DISABLE);
host->up = HOST_UNKNOWN;
break;
+ case IMSG_TABLE_DISABLE:
+ memcpy(&id, imsg.data, sizeof(id));
+ if ((table = table_find(env, id)) == NULL)
+ fatalx("relay_dispatch_pfe: desynchronized");
+ table->conf.flags |= F_DISABLE;
+ TAILQ_FOREACH(host, &table->hosts, entry)
+ host->up = HOST_UNKNOWN;
+ break;
+ case IMSG_TABLE_ENABLE:
+ memcpy(&id, imsg.data, sizeof(id));
+ if ((table = table_find(env, id)) == NULL)
+ fatalx("relay_dispatch_pfe: desynchronized");
+ table->conf.flags &= ~(F_DISABLE);
+ TAILQ_FOREACH(host, &table->hosts, entry)
+ host->up = HOST_UNKNOWN;
+ break;
case IMSG_HOST_STATUS:
if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(st))
fatalx("relay_dispatch_pfe: invalid request");