Download raw body.
relayd disable/enable all hosts with same name
Hi,
When you have multiple redirect services on same servers but different ports,
the only way to conveniently put one host in maintenance is to put it with parent.
table <host_table> { host1, host2 }
table <host_table> { host3 parent 1, host 4 parent 2 }
However this disables TCP checks, on the new port and in advance makes the setup more complicated.
It is easier to use the same <host_table> on all redirects.
But in this case when you issue relayctl host en/dis host1
it only disables/enables the first host it finds.
This patch issues the disable/enable on all subsequent hosts when the command is given by host name and not by host id.
regards,
G
Index: pfe.c
===================================================================
RCS file: /cvs/src/usr.sbin/relayd/pfe.c,v
retrieving revision 1.90
diff -u -p -u -p -r1.90 pfe.c
--- pfe.c 14 Sep 2020 11:30:25 -0000 1.90
+++ pfe.c 23 May 2024 12:26:12 -0000
@@ -584,11 +584,14 @@ int
disable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host)
{
struct host *h;
- struct table *table;
+ struct table *table, *t;
+ int host_byname = 0;
if (host == NULL) {
- if (id->id == EMPTY_ID)
+ if (id->id == EMPTY_ID) {
host = host_findbyname(env, id->name);
+ host_byname = 1;
+ }
else
host = host_find(env, id->id);
if (host == NULL || host->conf.parentid)
@@ -625,6 +628,14 @@ disable_host(struct ctl_conn *c, struct
/* Disable all children */
SLIST_FOREACH(h, &host->children, child)
disable_host(c, id, h);
+
+ /* Disable hosts with same name on all tables */
+ if (host_byname)
+ TAILQ_FOREACH(t, env->sc_tables, entry)
+ TAILQ_FOREACH(h, &t->hosts, entry)
+ if (strcmp(h->conf.name, host->conf.name) == 0 &&
+ h->conf.id != host->conf.id && !h->conf.parentid)
+ disable_host(c, id, h);
pfe_sync();
}
return (0);
@@ -634,10 +645,15 @@ int
enable_host(struct ctl_conn *c, struct ctl_id *id, struct host *host)
{
struct host *h;
+ struct table *t;
+ int host_byname = 0;
+
if (host == NULL) {
- if (id->id == EMPTY_ID)
+ if (id->id == EMPTY_ID) {
host = host_findbyname(env, id->name);
+ host_byname = 1;
+ }
else
host = host_find(env, id->id);
if (host == NULL || host->conf.parentid)
@@ -666,6 +682,14 @@ enable_host(struct ctl_conn *c, struct c
/* Enable all children */
SLIST_FOREACH(h, &host->children, child)
enable_host(c, id, h);
+
+ /* Enable hosts with same name on all tables */
+ if (host_byname)
+ TAILQ_FOREACH(t, env->sc_tables, entry)
+ TAILQ_FOREACH(h, &t->hosts, entry)
+ if (strcmp(h->conf.name, host->conf.name) == 0 &&
+ h->conf.id != host->conf.id && !h->conf.parentid)
+ enable_host(c, id, h);
pfe_sync();
}
return (0);
relayd disable/enable all hosts with same name