From 9571ef3180105a43f5f823ff867d5657771a282b Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Thu, 22 Nov 2007 16:07:04 +0000 Subject: Fix relay roundrobin mode to work correctly when multiple hosts in a table are down. Thanks to Preston Norvell at serialssolutions dot com for reporting the problem. --- usr.sbin/hoststated/hoststated.h | 3 ++- usr.sbin/hoststated/relay.c | 7 +++++-- usr.sbin/relayd/relay.c | 7 +++++-- usr.sbin/relayd/relayd.h | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h index e2377678efc..9ab299b04bb 100644 --- a/usr.sbin/hoststated/hoststated.h +++ b/usr.sbin/hoststated/hoststated.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hoststated.h,v 1.81 2007/11/22 10:09:53 reyk Exp $ */ +/* $OpenBSD: hoststated.h,v 1.82 2007/11/22 16:07:03 reyk Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard @@ -327,6 +327,7 @@ struct host { u_long up_cnt; int retry_cnt; struct ctl_tcp_event cte; + int idx; }; TAILQ_HEAD(hostlist, host); diff --git a/usr.sbin/hoststated/relay.c b/usr.sbin/hoststated/relay.c index 466e17323f6..dd3776b7f26 100644 --- a/usr.sbin/hoststated/relay.c +++ b/usr.sbin/hoststated/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.65 2007/11/22 10:09:53 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.66 2007/11/22 16:07:03 reyk Exp $ */ /* * Copyright (c) 2006, 2007 Reyk Floeter @@ -463,6 +463,7 @@ relay_init(void) if (rlay->dstnhosts >= RELAY_MAXHOSTS) fatal("relay_init: " "too many hosts in table"); + host->idx = rlay->dstnhosts; rlay->dsthost[rlay->dstnhosts++] = host; } log_info("adding %d hosts from table %s%s", @@ -1903,7 +1904,7 @@ relay_from_table(struct session *con) case RELAY_DSTMODE_ROUNDROBIN: if ((int)rlay->dstkey >= rlay->dstnhosts) rlay->dstkey = 0; - idx = (int)rlay->dstkey++; + idx = (int)rlay->dstkey; break; case RELAY_DSTMODE_LOADBALANCE: p = relay_hash_addr(&con->in.ss, p); @@ -1933,6 +1934,8 @@ relay_from_table(struct session *con) fatalx("relay_from_table: no active hosts, desynchronized"); found: + if (rlay->conf.dstmode == RELAY_DSTMODE_ROUNDROBIN) + rlay->dstkey = host->idx + 1; con->retry = host->conf.retry; con->out.port = table->conf.port; bcopy(&host->conf.ss, &con->out.ss, sizeof(con->out.ss)); diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 466e17323f6..dd3776b7f26 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.65 2007/11/22 10:09:53 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.66 2007/11/22 16:07:03 reyk Exp $ */ /* * Copyright (c) 2006, 2007 Reyk Floeter @@ -463,6 +463,7 @@ relay_init(void) if (rlay->dstnhosts >= RELAY_MAXHOSTS) fatal("relay_init: " "too many hosts in table"); + host->idx = rlay->dstnhosts; rlay->dsthost[rlay->dstnhosts++] = host; } log_info("adding %d hosts from table %s%s", @@ -1903,7 +1904,7 @@ relay_from_table(struct session *con) case RELAY_DSTMODE_ROUNDROBIN: if ((int)rlay->dstkey >= rlay->dstnhosts) rlay->dstkey = 0; - idx = (int)rlay->dstkey++; + idx = (int)rlay->dstkey; break; case RELAY_DSTMODE_LOADBALANCE: p = relay_hash_addr(&con->in.ss, p); @@ -1933,6 +1934,8 @@ relay_from_table(struct session *con) fatalx("relay_from_table: no active hosts, desynchronized"); found: + if (rlay->conf.dstmode == RELAY_DSTMODE_ROUNDROBIN) + rlay->dstkey = host->idx + 1; con->retry = host->conf.retry; con->out.port = table->conf.port; bcopy(&host->conf.ss, &con->out.ss, sizeof(con->out.ss)); diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h index b016a3a5283..83562c3a213 100644 --- a/usr.sbin/relayd/relayd.h +++ b/usr.sbin/relayd/relayd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.h,v 1.81 2007/11/22 10:09:53 reyk Exp $ */ +/* $OpenBSD: relayd.h,v 1.82 2007/11/22 16:07:03 reyk Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard @@ -327,6 +327,7 @@ struct host { u_long up_cnt; int retry_cnt; struct ctl_tcp_event cte; + int idx; }; TAILQ_HEAD(hostlist, host); -- cgit v1.2.3