summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsthen <sthen@openbsd.org>2010-08-01 22:18:35 +0000
committersthen <sthen@openbsd.org>2010-08-01 22:18:35 +0000
commit7a4012ef8daba8b8f27c158a0ccc12d3aa2cc016 (patch)
tree7eeded86433978a08a09f749e8503f098108575f
parentBe more generous when parsing the report descriptor: (diff)
downloadwireguard-openbsd-7a4012ef8daba8b8f27c158a0ccc12d3aa2cc016.tar.xz
wireguard-openbsd-7a4012ef8daba8b8f27c158a0ccc12d3aa2cc016.zip
Allow fallback tables for relays, not just redirections.
Seems reasonable to jsg, ok phessler, no response from reyk or pyr
-rw-r--r--usr.sbin/relayd/parse.y26
-rw-r--r--usr.sbin/relayd/pfe.c11
-rw-r--r--usr.sbin/relayd/relay.c6
-rw-r--r--usr.sbin/relayd/relayd.conf.57
-rw-r--r--usr.sbin/relayd/relayd.h4
5 files changed, 40 insertions, 14 deletions
diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y
index 0520135a079..edd24e2ae90 100644
--- a/usr.sbin/relayd/parse.y
+++ b/usr.sbin/relayd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.143 2010/02/24 15:44:18 jsg Exp $ */
+/* $OpenBSD: parse.y,v 1.144 2010/08/01 22:18:35 sthen Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -1213,6 +1213,11 @@ relay : RELAY STRING {
"or table", rlay->rl_conf.name);
YYERROR;
}
+ if (rlay->rl_backuptable == NULL) {
+ rlay->rl_conf.backuptable =
+ conf->sc_empty_table.conf.id;
+ rlay->rl_backuptable = &conf->sc_empty_table;
+ }
if (rlay->rl_conf.proto == EMPTY_ID) {
rlay->rl_proto = &conf->sc_proto_default;
rlay->rl_conf.proto = conf->sc_proto_default.id;
@@ -1362,16 +1367,21 @@ forwardspec : STRING port retry {
rlay->rl_conf.dstretry = $3;
}
| tablespec {
- if (rlay->rl_dsttable) {
- yyerror("table already specified");
+ if (rlay->rl_backuptable) {
+ yyerror("only one backup table is allowed");
purge_table(conf->sc_tables, $1);
YYERROR;
}
-
- rlay->rl_dsttable = $1;
- rlay->rl_dsttable->conf.flags |= F_USED;
- rlay->rl_conf.dsttable = $1->conf.id;
- rlay->rl_conf.dstport = $1->conf.port;
+ if (rlay->rl_dsttable) {
+ rlay->rl_backuptable = $1;
+ rlay->rl_backuptable->conf.flags |= F_USED;
+ rlay->rl_conf.backuptable = $1->conf.id;
+ } else {
+ rlay->rl_dsttable = $1;
+ rlay->rl_dsttable->conf.flags |= F_USED;
+ rlay->rl_conf.dsttable = $1->conf.id;
+ rlay->rl_conf.dstport = $1->conf.port;
+ }
}
;
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 0a095385bab..4abbf874d6d 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.64 2010/05/14 11:13:36 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.65 2010/08/01 22:18:35 sthen Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -586,6 +586,15 @@ relays:
TAILQ_FOREACH(host, &rlay->rl_dsttable->hosts, entry)
imsg_compose_event(&c->iev, IMSG_CTL_HOST,
0, 0, -1, host, sizeof(*host));
+
+ if (rlay->rl_conf.backuptable == EMPTY_TABLE)
+ continue;
+ imsg_compose_event(&c->iev, IMSG_CTL_TABLE, 0, 0, -1,
+ rlay->rl_backuptable, sizeof(*rlay->rl_backuptable));
+ if (!(rlay->rl_backuptable->conf.flags & F_DISABLE))
+ TAILQ_FOREACH(host, &rlay->rl_backuptable->hosts, entry)
+ imsg_compose_event(&c->iev, IMSG_CTL_HOST,
+ 0, 0, -1, host, sizeof(*host));
}
routers:
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index a0562187c16..dcd1e5863f1 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.121 2010/05/26 13:56:08 nicm Exp $ */
+/* $OpenBSD: relay.c,v 1.122 2010/08/01 22:18:35 sthen Exp $ */
/*
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -2123,9 +2123,11 @@ relay_from_table(struct rsession *con)
u_int32_t p = con->se_hashkey;
int idx = 0;
- if (table->conf.check && !table->up) {
+ if (table->conf.check && !table->up && !rlay->rl_backuptable->up) {
log_debug("relay_from_table: no active hosts");
return (-1);
+ } else if (!table->up && rlay->rl_backuptable->up) {
+ table = rlay->rl_backuptable;
}
switch (rlay->rl_conf.dstmode) {
diff --git a/usr.sbin/relayd/relayd.conf.5 b/usr.sbin/relayd/relayd.conf.5
index b64661e9ed5..428502742cd 100644
--- a/usr.sbin/relayd/relayd.conf.5
+++ b/usr.sbin/relayd/relayd.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: relayd.conf.5,v 1.113 2010/05/18 15:09:34 sobrado Exp $
+.\" $OpenBSD: relayd.conf.5,v 1.114 2010/08/01 22:18:35 sthen Exp $
.\"
.\" Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org>
.\" Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: May 18 2010 $
+.Dd $Mdocdate: August 1 2010 $
.Dt RELAYD.CONF 5
.Os
.Sh NAME
@@ -580,6 +580,9 @@ Like the previous directive, but connect to a host from the specified
table; see the
.Sx TABLES
section above for information about table options.
+This directive can be specified twice \(en the second entry will be used
+as the backup table if all hosts in the main table are down.
+At least one entry for the main table is mandatory.
.It Xo
.Ic forward to
.Ic nat lookup
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 21e3833cf05..1194cf69c3c 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.136 2010/05/26 13:56:08 nicm Exp $ */
+/* $OpenBSD: relayd.h,v 1.137 2010/08/01 22:18:35 sthen Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -536,6 +536,7 @@ struct relay_config {
int dstmode;
int dstretry;
objid_t dsttable;
+ objid_t backuptable;
struct sockaddr_storage ss;
struct sockaddr_storage dstss;
struct sockaddr_storage dstaf;
@@ -556,6 +557,7 @@ struct relay {
struct bufferevent *rl_dstbev;
struct table *rl_dsttable;
+ struct table *rl_backuptable;
u_int32_t rl_dstkey;
struct host *rl_dsthost[RELAY_MAXHOSTS];
int rl_dstnhosts;