From 49ff374f565b46d63678d1ea92eba436eacaa8cc Mon Sep 17 00:00:00 2001 From: Jeffrey Hutzelman Date: Sat, 5 Jan 2013 15:29:16 -0500 Subject: Abstract realm server usability test Whether a particular server is usable currently depends only on whether we have successfully obtained its IP address. However, eventually it will also depend on additional factors such as whether the server has been deleted from the realm.list. To ease that transition, replace the 'usable' flag with a 'got_addr' flag (which is set when the address lookup succeeds), and add a new function to test whether a server is usable. --- server/realm.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'server/realm.c') diff --git a/server/realm.c b/server/realm.c index d4eeff6..60b2783 100644 --- a/server/realm.c +++ b/server/realm.c @@ -76,6 +76,12 @@ static Code_t ticket_retrieve(ZRealm *realm); static int ticket_lookup(char *realm); #endif +static int +is_usable(ZRealm_server *srvr) +{ + return srvr->got_addr; +} + static int realm_get_idx_by_addr(ZRealm *realm, struct sockaddr_in *who) @@ -85,7 +91,7 @@ realm_get_idx_by_addr(ZRealm *realm, /* loop through the realms */ for (srvr = realm->srvrs, b = 0; b < realm->count; b++, srvr++) { - if (!srvr->usable) + if (!is_usable(srvr)) continue; if (srvr->addr.sin_addr.s_addr == who->sin_addr.s_addr) return(b); @@ -107,7 +113,7 @@ realm_next_idx_by_idx(realm, idx) while (a > 0) { a--; srvr++; } for (srvr, b = idx; b < realm->count; b++, srvr++) { - if (!srvr->usable) + if (!is_usable(srvr)) continue; if (!srvr->dontsend) return(b); @@ -116,7 +122,7 @@ realm_next_idx_by_idx(realm, idx) /* recycle */ if (idx != 0) for (srvr = realm->srvrs, b = 0; b < idx; b++, srvr++) { - if (!srvr->usable) + if (!is_usable(srvr)) continue; if (!srvr->dontsend) return(b); @@ -335,7 +341,7 @@ realm_which_realm(struct sockaddr_in *who) for (srvr = otherrealms[a]->srvrs, b = 0; b < otherrealms[a]->count; b++, srvr++) { - if (!srvr->usable) + if (!is_usable(srvr)) continue; if (srvr->addr.sin_addr.s_addr == who->sin_addr.s_addr) return(otherrealms[a]); @@ -586,7 +592,7 @@ realm_init(void) /* use the server port */ srvr->addr.sin_port = srv_addr.sin_port; srvr->addr.sin_family = AF_INET; - srvr->usable = 1; + srvr->got_addr = 1; } else syslog(LOG_WARNING, "hostname failed, %s", srvr->name->string); } -- cgit v1.2.3