Allow fallback tables for relays, not just redirections.
authorsthen <sthen@openbsd.org>
Sun, 1 Aug 2010 22:18:35 +0000 (22:18 +0000)
committersthen <sthen@openbsd.org>
Sun, 1 Aug 2010 22:18:35 +0000 (22:18 +0000)
Seems reasonable to jsg, ok phessler, no response from reyk or pyr

usr.sbin/relayd/parse.y
usr.sbin/relayd/pfe.c
usr.sbin/relayd/relay.c
usr.sbin/relayd/relayd.conf.5
usr.sbin/relayd/relayd.h

index 0520135..edd24e2 100644 (file)
@@ -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;
+                       }
                }
                ;
 
index 0a09538..4abbf87 100644 (file)
@@ -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:
index a056218..dcd1e58 100644 (file)
@@ -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) {
index b64661e..4285027 100644 (file)
@@ -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
index 21e3833..1194cf6 100644 (file)
@@ -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;