Index | Thread | Search

From:
Alexandr Nedvedicky <sashan@fastmail.net>
Subject:
Re: relayd disable/enable all hosts with same name
To:
Kapetanakis Giannis <bilias@edu.physics.uoc.gr>
Cc:
tech@openbsd.org
Date:
Fri, 24 May 2024 08:13:32 +0200

Download raw body.

Thread
Hello,

I'm not using a relayd so I can't tell exactly. The relayctl(8) says:

    host disable [name | id]
             Disable a host.  Treat it as though it were always down.

    host enable [name | id]
             Enable the host.  Start checking its health again.

so the whole issue feels like a kind of bug. See further below for comments on
change itself. Note I'm not very familiar with relayctl code.

</snip>
> 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);
			^^^^
			I'm not sure if it is right place for TAILQ_FOREACH()
			over all tables here. The thing is the loop does call
			disable_host() recursively. So each level of
			recursion is going to walk over the same set of
			all tables relayd keeps.

			also lines exceed 80 characters.

</snip>

thanks and
regards
sashan