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 +++++++++++----- server/zserver.h | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) 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); } diff --git a/server/zserver.h b/server/zserver.h index fc6f847..ecdd06e 100644 --- a/server/zserver.h +++ b/server/zserver.h @@ -114,8 +114,8 @@ struct _Destlist { struct _ZRealm_server { String *name; /* server's hostname */ struct sockaddr_in addr; /* server's address */ - unsigned int usable :1; /* set once entry is usable */ unsigned int dontsend :1; /* private server, do not send */ + unsigned int got_addr :1; /* IP address is valid */ }; struct _ZRealm { -- cgit v1.2.3