diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2007-03-07 17:40:33 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2007-03-07 17:40:33 +0000 |
commit | 577a9f29e7e7f9565e573a6e48ac3061cd90b62f (patch) | |
tree | 7e0055f153507b08335847a83f8b18947c30eb46 /usr.sbin | |
parent | f38341b9ce7dd7d1de01b260afd7330c7ec160ad (diff) |
- fix the hoststatectl host disable/enable commands to work with relay
layer 7 loadbalancing.
- allow to run relays with tables without depending on services
- show hosts and tables assigned to relays in hoststatectl show commands
ok pyr@ deraadt@ with some input from mcbride@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/hoststated/hce.c | 4 | ||||
-rw-r--r-- | usr.sbin/hoststated/parse.y | 3 | ||||
-rw-r--r-- | usr.sbin/hoststated/pfe.c | 24 | ||||
-rw-r--r-- | usr.sbin/hoststated/relay.c | 24 | ||||
-rw-r--r-- | usr.sbin/relayd/hce.c | 4 | ||||
-rw-r--r-- | usr.sbin/relayd/parse.y | 3 | ||||
-rw-r--r-- | usr.sbin/relayd/pfe.c | 24 | ||||
-rw-r--r-- | usr.sbin/relayd/relay.c | 24 |
8 files changed, 96 insertions, 14 deletions
diff --git a/usr.sbin/hoststated/hce.c b/usr.sbin/hoststated/hce.c index a987f662f8e..490ebb10168 100644 --- a/usr.sbin/hoststated/hce.c +++ b/usr.sbin/hoststated/hce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hce.c,v 1.17 2007/03/06 19:37:31 reyk Exp $ */ +/* $OpenBSD: hce.c,v 1.18 2007/03/07 17:40:32 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -141,7 +141,7 @@ hce(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2], ibuf_main->handler, ibuf_main); event_add(&ibuf_main->ev, NULL); - if (!TAILQ_EMPTY(&env->services)) { + if (!TAILQ_EMPTY(&env->tables)) { evtimer_set(&env->ev, hce_launch_checks, env); bzero(&tv, sizeof(tv)); evtimer_add(&env->ev, &tv); diff --git a/usr.sbin/hoststated/parse.y b/usr.sbin/hoststated/parse.y index 18cfa36c18c..996994ce8a6 100644 --- a/usr.sbin/hoststated/parse.y +++ b/usr.sbin/hoststated/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.34 2007/03/06 19:26:46 reyk Exp $ */ +/* $OpenBSD: parse.y,v 1.35 2007/03/07 17:40:32 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -929,6 +929,7 @@ relayoptsl : LISTEN ON STRING port optssl { rlay->dsttable = dsttable; rlay->dstmode = $3; rlay->dstcheck = $4; + rlay->dsttable->flags |= F_USED; } | PROTO STRING { struct protocol *p; diff --git a/usr.sbin/hoststated/pfe.c b/usr.sbin/hoststated/pfe.c index c3a3ba14b46..f8f818c5218 100644 --- a/usr.sbin/hoststated/pfe.c +++ b/usr.sbin/hoststated/pfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe.c,v 1.18 2007/02/26 16:10:24 reyk Exp $ */ +/* $OpenBSD: pfe.c,v 1.19 2007/03/07 17:40:32 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -215,7 +215,8 @@ pfe_dispatch_imsg(int fd, short event, void *ptr) memcpy(&st, imsg.data, sizeof(st)); if ((host = host_find(env, st.id)) == NULL) fatalx("pfe_dispatch_imsg: invalid host id"); - + if (host->flags & F_DISABLE) + break; host->retry_cnt = st.retry_cnt; if (st.up != HOST_UNKNOWN) { host->check_cnt++; @@ -416,6 +417,15 @@ show(struct ctl_conn *c) rlay, sizeof(*rlay)); imsg_compose(&c->ibuf, IMSG_CTL_STATISTICS, 0, 0, &rlay->stats, sizeof(rlay->stats)); + + if (rlay->dsttable == NULL) + continue; + imsg_compose(&c->ibuf, IMSG_CTL_TABLE, 0, 0, + rlay->dsttable, sizeof(*rlay->dsttable)); + if (!(rlay->dsttable->flags & F_DISABLE)) + TAILQ_FOREACH(host, &rlay->dsttable->hosts, entry) + imsg_compose(&c->ibuf, IMSG_CTL_HOST, 0, 0, + host, sizeof(*host)); } imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, NULL, 0); @@ -550,6 +560,7 @@ disable_host(struct ctl_conn *c, struct ctl_id *id) { struct host *host; struct table *table; + int n; if (id->id == EMPTY_ID) host = host_findbyname(env, id->name); @@ -578,6 +589,10 @@ disable_host(struct ctl_conn *c, struct ctl_id *id) imsg_compose(ibuf_hce, IMSG_HOST_DISABLE, 0, 0, &host->id, sizeof(host->id)); + /* Forward to relay engine(s) */ + for (n = 0; n < env->prefork_relay; n++) + imsg_compose(&ibuf_relay[n], + IMSG_HOST_DISABLE, 0, 0, &host->id, sizeof(host->id)); log_debug("disable_host: disabled host %d", host->id); pfe_sync(); return (0); @@ -587,6 +602,7 @@ int enable_host(struct ctl_conn *c, struct ctl_id *id) { struct host *host; + int n; if (id->id == EMPTY_ID) host = host_findbyname(env, id->name); @@ -606,6 +622,10 @@ enable_host(struct ctl_conn *c, struct ctl_id *id) imsg_compose(ibuf_hce, IMSG_HOST_ENABLE, 0, 0, &host->id, sizeof (host->id)); + /* Forward to relay engine(s) */ + for (n = 0; n < env->prefork_relay; n++) + imsg_compose(&ibuf_relay[n], + IMSG_HOST_ENABLE, 0, 0, &host->id, sizeof(host->id)); log_debug("enable_host: enabled host %d", host->id); pfe_sync(); return (0); diff --git a/usr.sbin/hoststated/relay.c b/usr.sbin/hoststated/relay.c index dc60fb7a2f2..1ccc1680eae 100644 --- a/usr.sbin/hoststated/relay.c +++ b/usr.sbin/hoststated/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.17 2007/03/06 19:26:46 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.18 2007/03/07 17:40:32 reyk Exp $ */ /* * Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org> @@ -1723,6 +1723,7 @@ relay_dispatch_pfe(int fd, short event, void *ptr) struct host *host; struct table *table; struct ctl_status st; + objid_t id; ibuf = ptr; switch (event) { @@ -1748,13 +1749,32 @@ relay_dispatch_pfe(int fd, short event, void *ptr) break; switch (imsg.hdr.type) { + case IMSG_HOST_DISABLE: + memcpy(&id, imsg.data, sizeof(id)); + if ((host = host_find(env, id)) == NULL) + fatalx("relay_dispatch_pfe: desynchronized"); + if ((table = table_find(env, host->tableid)) == NULL) + fatalx("relay_dispatch_pfe: invalid table id"); + if (host->up == HOST_UP) + table->up--; + host->flags |= F_DISABLE; + host->up = HOST_UNKNOWN; + break; + case IMSG_HOST_ENABLE: + memcpy(&id, imsg.data, sizeof(id)); + if ((host = host_find(env, id)) == NULL) + fatalx("relay_dispatch_pfe: desynchronized"); + host->flags &= ~(F_DISABLE); + host->up = HOST_UNKNOWN; + break; case IMSG_HOST_STATUS: if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(st)) fatalx("relay_dispatch_pfe: invalid request"); memcpy(&st, imsg.data, sizeof(st)); if ((host = host_find(env, st.id)) == NULL) fatalx("relay_dispatch_pfe: invalid host id"); - + if (host->flags & F_DISABLE) + break; if (host->up == st.up) { log_debug("relay_dispatch_pfe: host %d => %d", host->id, host->up); diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c index a987f662f8e..490ebb10168 100644 --- a/usr.sbin/relayd/hce.c +++ b/usr.sbin/relayd/hce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hce.c,v 1.17 2007/03/06 19:37:31 reyk Exp $ */ +/* $OpenBSD: hce.c,v 1.18 2007/03/07 17:40:32 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -141,7 +141,7 @@ hce(struct hoststated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2], ibuf_main->handler, ibuf_main); event_add(&ibuf_main->ev, NULL); - if (!TAILQ_EMPTY(&env->services)) { + if (!TAILQ_EMPTY(&env->tables)) { evtimer_set(&env->ev, hce_launch_checks, env); bzero(&tv, sizeof(tv)); evtimer_add(&env->ev, &tv); diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y index 18cfa36c18c..996994ce8a6 100644 --- a/usr.sbin/relayd/parse.y +++ b/usr.sbin/relayd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.34 2007/03/06 19:26:46 reyk Exp $ */ +/* $OpenBSD: parse.y,v 1.35 2007/03/07 17:40:32 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -929,6 +929,7 @@ relayoptsl : LISTEN ON STRING port optssl { rlay->dsttable = dsttable; rlay->dstmode = $3; rlay->dstcheck = $4; + rlay->dsttable->flags |= F_USED; } | PROTO STRING { struct protocol *p; diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c index c3a3ba14b46..f8f818c5218 100644 --- a/usr.sbin/relayd/pfe.c +++ b/usr.sbin/relayd/pfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfe.c,v 1.18 2007/02/26 16:10:24 reyk Exp $ */ +/* $OpenBSD: pfe.c,v 1.19 2007/03/07 17:40:32 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -215,7 +215,8 @@ pfe_dispatch_imsg(int fd, short event, void *ptr) memcpy(&st, imsg.data, sizeof(st)); if ((host = host_find(env, st.id)) == NULL) fatalx("pfe_dispatch_imsg: invalid host id"); - + if (host->flags & F_DISABLE) + break; host->retry_cnt = st.retry_cnt; if (st.up != HOST_UNKNOWN) { host->check_cnt++; @@ -416,6 +417,15 @@ show(struct ctl_conn *c) rlay, sizeof(*rlay)); imsg_compose(&c->ibuf, IMSG_CTL_STATISTICS, 0, 0, &rlay->stats, sizeof(rlay->stats)); + + if (rlay->dsttable == NULL) + continue; + imsg_compose(&c->ibuf, IMSG_CTL_TABLE, 0, 0, + rlay->dsttable, sizeof(*rlay->dsttable)); + if (!(rlay->dsttable->flags & F_DISABLE)) + TAILQ_FOREACH(host, &rlay->dsttable->hosts, entry) + imsg_compose(&c->ibuf, IMSG_CTL_HOST, 0, 0, + host, sizeof(*host)); } imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, NULL, 0); @@ -550,6 +560,7 @@ disable_host(struct ctl_conn *c, struct ctl_id *id) { struct host *host; struct table *table; + int n; if (id->id == EMPTY_ID) host = host_findbyname(env, id->name); @@ -578,6 +589,10 @@ disable_host(struct ctl_conn *c, struct ctl_id *id) imsg_compose(ibuf_hce, IMSG_HOST_DISABLE, 0, 0, &host->id, sizeof(host->id)); + /* Forward to relay engine(s) */ + for (n = 0; n < env->prefork_relay; n++) + imsg_compose(&ibuf_relay[n], + IMSG_HOST_DISABLE, 0, 0, &host->id, sizeof(host->id)); log_debug("disable_host: disabled host %d", host->id); pfe_sync(); return (0); @@ -587,6 +602,7 @@ int enable_host(struct ctl_conn *c, struct ctl_id *id) { struct host *host; + int n; if (id->id == EMPTY_ID) host = host_findbyname(env, id->name); @@ -606,6 +622,10 @@ enable_host(struct ctl_conn *c, struct ctl_id *id) imsg_compose(ibuf_hce, IMSG_HOST_ENABLE, 0, 0, &host->id, sizeof (host->id)); + /* Forward to relay engine(s) */ + for (n = 0; n < env->prefork_relay; n++) + imsg_compose(&ibuf_relay[n], + IMSG_HOST_ENABLE, 0, 0, &host->id, sizeof(host->id)); log_debug("enable_host: enabled host %d", host->id); pfe_sync(); return (0); diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index dc60fb7a2f2..1ccc1680eae 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.17 2007/03/06 19:26:46 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.18 2007/03/07 17:40:32 reyk Exp $ */ /* * Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org> @@ -1723,6 +1723,7 @@ relay_dispatch_pfe(int fd, short event, void *ptr) struct host *host; struct table *table; struct ctl_status st; + objid_t id; ibuf = ptr; switch (event) { @@ -1748,13 +1749,32 @@ relay_dispatch_pfe(int fd, short event, void *ptr) break; switch (imsg.hdr.type) { + case IMSG_HOST_DISABLE: + memcpy(&id, imsg.data, sizeof(id)); + if ((host = host_find(env, id)) == NULL) + fatalx("relay_dispatch_pfe: desynchronized"); + if ((table = table_find(env, host->tableid)) == NULL) + fatalx("relay_dispatch_pfe: invalid table id"); + if (host->up == HOST_UP) + table->up--; + host->flags |= F_DISABLE; + host->up = HOST_UNKNOWN; + break; + case IMSG_HOST_ENABLE: + memcpy(&id, imsg.data, sizeof(id)); + if ((host = host_find(env, id)) == NULL) + fatalx("relay_dispatch_pfe: desynchronized"); + host->flags &= ~(F_DISABLE); + host->up = HOST_UNKNOWN; + break; case IMSG_HOST_STATUS: if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(st)) fatalx("relay_dispatch_pfe: invalid request"); memcpy(&st, imsg.data, sizeof(st)); if ((host = host_find(env, st.id)) == NULL) fatalx("relay_dispatch_pfe: invalid host id"); - + if (host->flags & F_DISABLE) + break; if (host->up == st.up) { log_debug("relay_dispatch_pfe: host %d => %d", host->id, host->up); |