#include <stdio.h>
#include <errno.h>
+#include <string.h>
#ifdef AFS_NT40_ENV
#include <fcntl.h>
#include <winsock2.h>
#include <netinet/in.h>
#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-
#include <afs/stds.h>
#include <rx/xdr.h>
#include <afs/assert.h>
extern int lwps; /* the max number of server threads */
extern afsUUID FS_HostUUID;
+afsUUID nulluuid;
int CEs = 0; /* active clients */
int CEBlocks = 0; /* number of blocks of CEs */
struct client *CEFree = 0; /* first free client */
static struct rx_securityClass *sc = NULL;
static void h_SetupCallbackConn_r(struct host * host);
-static void h_AddHostToHashTable_r(afs_uint32 addr, afs_uint16 port, struct host * host);
-static void h_AddHostToUuidHashTable_r(afsUUID * uuid, struct host * host);
-static int h_DeleteHostFromHashTableByAddr_r(afs_uint32 addr, afs_uint16 port, struct host *host);
#define CESPERBLOCK 73
struct CEBlock { /* block of CESPERBLOCK file entries */
};
static void h_TossStuff_r(register struct host *host);
-static int hashDelete_r(afs_uint32 addr, afs_uint16 port, struct host *host);
/*
* Make sure the subnet macros have been defined.
* to map IP addresses onto host pointers, and another
* to map host UUIDs onto host pointers.
*/
-static struct h_hashChain *hostHashTable[h_HASHENTRIES];
-static struct h_hashChain *hostUuidHashTable[h_HASHENTRIES];
+static struct h_AddrHashChain *hostAddrHashTable[h_HASHENTRIES];
+static struct h_UuidHashChain *hostUuidHashTable[h_HASHENTRIES];
#define h_HashIndex(hostip) ((hostip) & (h_HASHENTRIES-1))
#define h_UuidHashIndex(uuidp) (((int)(afs_uuid_hash(uuidp))) & (h_HASHENTRIES-1))
if (!uclient) {
code = hpr_Initialize(&uclient);
- assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
+ if (!code)
+ assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
+ else
+ return code;
}
over = 0;
if (!uclient) {
code = hpr_Initialize(&uclient);
- assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
+ if (!code)
+ assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
+ else
+ return code;
}
for (i = 0; i < names->namelist_len; i++)
if (!uclient) {
code = hpr_Initialize(&uclient);
- assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
+ if (!code)
+ assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
+ else
+ return code;
}
code = ubik_PR_IDToName(uclient, 0, ids, names);
if (!uclient) {
code = hpr_Initialize(&uclient);
- assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
+ if (!code)
+ assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0);
+ else
+ return code;
}
over = 0;
code = hpr_GetHostCPS(ntohl(host->host), &host->hcps);
H_LOCK;
if (code) {
+ char hoststr[16];
/*
* Although ubik_Call (called by pr_GetHostCPS) traverses thru all protection servers
* and reevaluates things if no sync server or quorum is found we could still end up
*/
host->hcpsfailed = 1;
ViceLog(0,
- ("Warning: GetHostCPS failed (%d) for %x; will retry\n",
- code, host->host));
+ ("Warning: GetHostCPS failed (%d) for %x (%s:%d); will retry\n",
+ code, host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
} else {
host->hcpsfailed = 0;
ViceLog(1,
- ("gethost: GetHostCPS failed (%d) for %x; ignored\n",
- code, host->host));
+ ("gethost: GetHostCPS failed (%d) for %x (%s:%d); ignored\n",
+ code, host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
}
if (host->hcps.prlist_val)
free(host->hcps.prlist_val);
host->host = rxr_HostOf(r_con);
host->port = rxr_PortOf(r_con);
- h_AddHostToHashTable_r(host->host, host->port, host);
+ h_AddHostToAddrHashTable_r(host->host, host->port, host);
if (consolePort == 0) { /* find the portal number for console */
#if defined(AFS_OSF_ENV)
h_Lookup_r(afs_uint32 haddr, afs_uint16 hport, int *heldp)
{
afs_int32 now;
- struct host *host = 0;
- struct h_hashChain *chain;
+ struct host *host = NULL;
+ struct h_AddrHashChain *chain;
int index = h_HashIndex(haddr);
extern int hostaclRefresh;
restart:
- for (chain = hostHashTable[index]; chain; chain = chain->next) {
+ for (chain = hostAddrHashTable[index]; chain; chain = chain->next) {
host = chain->hostPtr;
assert(host);
if (!(host->hostFlags & HOSTDELETED) && chain->addr == haddr
h_LookupUuid_r(afsUUID * uuidp)
{
struct host *host = 0;
- struct h_hashChain *chain;
+ struct h_UuidHashChain *chain;
int index = h_UuidHashIndex(uuidp);
for (chain = hostUuidHashTable[index]; chain; chain = chain->next) {
if (h_NBLock_r(host) != 0) {
char hoststr[16];
ViceLog(0,
- ("Warning: h_TossStuff_r failed; Host %s:%d was locked.\n",
- afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
+ ("Warning: h_TossStuff_r failed; Host %x (%s:%d) was locked.\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
return;
} else {
h_Unlock_r(host);
if (code < 0) {
char hoststr[16];
ViceLog(0,
- ("Warning: h_TossStuff_r failed: Host %s:%d client %x was locked.\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("Warning: h_TossStuff_r failed: Host %x (%s:%d) client %x was locked.\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port), client));
return;
}
if (client->refCount) {
char hoststr[16];
ViceLog(0,
- ("Warning: h_TossStuff_r failed: Host %s:%d client %x refcount %d.\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("Warning: h_TossStuff_r failed: Host %x (%s:%d) client %x refcount %d.\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port), client, client->refCount));
/* This is the same thing we do if the host is locked */
ReleaseWriteLock(&client->lock);
host->hostFlags &= ~CLIENTDELETED;
if (host->hostFlags & HOSTDELETED) {
- register struct h_hashChain **hp, *th;
+ register struct h_AddrHashChain **ahp, *ath;
register struct rx_connection *rxconn;
afsUUID *uuidp;
struct AddrPort hostAddrPort;
/* if alternate addresses do not exist */
if (!(host->interface)) {
- for (hp = &hostHashTable[h_HashIndex(host->host)]; (th = *hp);
- hp = &th->next) {
- assert(th->hostPtr);
- if (th->hostPtr == host) {
- *hp = th->next;
- h_DeleteList_r(host);
- FreeHT(host);
- free(th);
+ for (ahp = &hostAddrHashTable[h_HashIndex(host->host)]; (ath = *ahp);
+ ahp = &ath->next) {
+ assert(ath->hostPtr);
+ if (ath->hostPtr == host) {
+ *ahp = ath->next;
+ free(ath);
break;
}
}
} else {
- /* delete all hash entries for the UUID */
+ register struct h_UuidHashChain **uhp, *uth;
+ /* delete the hash entry for the UUID */
uuidp = &host->interface->uuid;
- for (hp = &hostUuidHashTable[h_UuidHashIndex(uuidp)]; (th = *hp);
- hp = &th->next) {
- assert(th->hostPtr);
- if (th->hostPtr == host) {
- *hp = th->next;
- free(th);
+ for (uhp = &hostUuidHashTable[h_UuidHashIndex(uuidp)]; (uth = *uhp);
+ uhp = &uth->next) {
+ assert(uth->hostPtr);
+ if (uth->hostPtr == host) {
+ *uhp = uth->next;
+ free(uth);
break;
}
}
- /* delete all hash entries for alternate addresses */
- assert(host->interface->numberOfInterfaces > 0);
+ /* delete the hash entry for each alternate addresses */
for (i = 0; i < host->interface->numberOfInterfaces; i++) {
hostAddrPort = host->interface->interface[i];
- for (hp = &hostHashTable[h_HashIndex(hostAddrPort.addr)]; (th = *hp);
- hp = &th->next) {
- assert(th->hostPtr);
- if (th->hostPtr == host) {
- *hp = th->next;
- free(th);
+ if (!hostAddrPort.valid)
+ continue;
+
+ for (ahp = &hostAddrHashTable[h_HashIndex(hostAddrPort.addr)]; (ath = *ahp);
+ ahp = &ath->next) {
+ assert(ath->hostPtr);
+ if (ath->hostPtr == host) {
+ *ahp = ath->next;
+ free(ath);
break;
}
}
}
free(host->interface);
host->interface = NULL;
- h_DeleteList_r(host); /* remove host from global host List */
- FreeHT(host);
} /* if alternate address exists */
+
+ h_DeleteList_r(host); /* remove host from global host List */
+ FreeHT(host);
}
} /*h_TossStuff_r */
if (!(held[count] = h_Held_r(host)))
h_Hold_r(host);
}
- assert(count == hostCount);
+ if (count != hostCount) {
+ ViceLog(0, ("h_Enumerate found %d of %d hosts\n", count, hostCount));
+ }
+ assert(count <= hostCount);
H_UNLOCK;
for (i = 0; i < count; i++) {
held[i] = (*proc) (list[i], held[i], param);
} /*h_Enumerate_r */
/* inserts a new HashChain structure corresponding to this UUID */
-static void
+void
h_AddHostToUuidHashTable_r(struct afsUUID *uuid, struct host *host)
{
int index;
- struct h_hashChain *chain;
+ struct h_UuidHashChain *chain;
/* hash into proper bucket */
index = h_UuidHashIndex(uuid);
+ /* don't add the same entry multiple times */
+ for (chain = hostUuidHashTable[index]; chain; chain = chain->next) {
+ if (host->interface && afs_uuid_equal(&host->interface->uuid, uuid))
+ return;
+ }
+
/* insert into beginning of list for this bucket */
- chain = (struct h_hashChain *)malloc(sizeof(struct h_hashChain));
+ chain = (struct h_UuidHashChain *)malloc(sizeof(struct h_UuidHashChain));
if (!chain) {
ViceLog(0, ("Failed malloc in h_AddHostToUuidHashTable_r\n"));
assert(0);
/* inserts a new HashChain structure corresponding to this address */
-static void
-h_AddHostToHashTable_r(afs_uint32 addr, afs_uint16 port, struct host *host)
+void
+h_AddHostToAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host *host)
{
int index;
- struct h_hashChain *chain;
+ struct h_AddrHashChain *chain;
+ int found = 0;
+ char hoststr[16];
/* hash into proper bucket */
index = h_HashIndex(addr);
/* don't add the same entry multiple times */
- for (chain = hostHashTable[index]; chain; chain = chain->next) {
- if (chain->hostPtr == host && chain->addr == addr && chain->port == port)
- return;
+ for (chain = hostAddrHashTable[index]; chain; chain = chain->next) {
+ if (chain->addr == addr && chain->port == port) {
+ if (chain->hostPtr == host)
+ found = 1;
+ else if (!(host->hostFlags & HOSTDELETED))
+ ViceLog(125, ("Addr %s:%d assigned to %x and %x.\n",
+ afs_inet_ntoa_r(addr, hoststr), ntohs(port),
+ host, chain));
+ }
}
+ if (found)
+ return;
+
/* insert into beginning of list for this bucket */
- chain = (struct h_hashChain *)malloc(sizeof(struct h_hashChain));
+ chain = (struct h_AddrHashChain *)malloc(sizeof(struct h_AddrHashChain));
if (!chain) {
- ViceLog(0, ("Failed malloc in h_AddHostToHashTable_r\n"));
+ ViceLog(0, ("Failed malloc in h_AddHostToAddrHashTable_r\n"));
assert(0);
}
chain->hostPtr = host;
- chain->next = hostHashTable[index];
+ chain->next = hostAddrHashTable[index];
chain->addr = addr;
chain->port = port;
- hostHashTable[index] = chain;
+ hostAddrHashTable[index] = chain;
}
/*
* This is called with host locked and held. At this point, the
- * hostHashTable should not be having entries for the alternate
+ * hostAddrHashTable should not have entries for the alternate
* interfaces. This function has to insert these entries in the
- * hostHashTable.
+ * hostAddrHashTable.
*
* All addresses are in network byte order.
*/
assert(host);
assert(host->interface);
- ViceLog(125, ("addInterfaceAddr : host %s:%d addr %s:%d\n",
- afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
- afs_inet_ntoa_r(addr, hoststr2), ntohs(port)));
-
/*
* Make sure this address is on the list of known addresses
* for this host.
number = host->interface->numberOfInterfaces;
for (i = 0, found = 0; i < number && !found; i++) {
if (host->interface->interface[i].addr == addr &&
- host->interface->interface[i].port == port)
+ host->interface->interface[i].port == port) {
found = 1;
+ host->interface->interface[i].valid = 1;
+ }
}
+
+ ViceLog(125, ("addInterfaceAddr : host %s:%d addr %s:%d : found:%d\n",
+ afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
+ afs_inet_ntoa_r(addr, hoststr2), ntohs(port), found));
+
if (!found) {
interface = (struct Interface *)
malloc(sizeof(struct Interface) + (sizeof(struct AddrPort) * number));
interface->interface[i] = host->interface->interface[i];
interface->interface[number].addr = addr;
interface->interface[number].port = port;
+ interface->interface[number].valid = 1;
free(host->interface);
host->interface = interface;
}
- /*
- * Create a hash table entry for this address
- */
- h_AddHostToHashTable_r(addr, port, host);
-
return 0;
}
/*
* This is called with host locked and held. At this point, the
- * hostHashTable should not be having entries for the alternate
+ * hostAddrHashTable should not be having entries for the alternate
* interfaces. This function has to insert these entries in the
- * hostHashTable.
+ * hostAddrHashTable.
*
* All addresses are in network byte order.
*/
*/
interface = host->interface;
number = host->interface->numberOfInterfaces;
- for (i = 0, found = 0; i < number; i++) {
+ for (i = 0, found = 0; i < number && !found; i++) {
if (interface->interface[i].addr == addr &&
interface->interface[i].port == port) {
found = 1;
- break;
+ interface->interface[i].valid = 0;
}
}
if (found) {
number--;
for (; i < number; i++) {
- interface->interface[i].addr = interface->interface[i+1].addr;
- interface->interface[i].port = interface->interface[i+1].port;
+ interface->interface[i] = interface->interface[i+1];
}
interface->numberOfInterfaces = number;
}
/*
* Remove the hash table entry for this address
*/
- h_DeleteHostFromHashTableByAddr_r(addr, port, host);
+ h_DeleteHostFromAddrHashTable_r(addr, port, host);
return 0;
}
+/*
+ * This is called with host locked and held. This function differs
+ * from removeInterfaceAddr_r in that it is called when the address
+ * is being removed from the host regardless of whether or not there
+ * is an interface list for the host. This function will delete the
+ * host if there are no addresses left on it.
+ *
+ * All addresses are in network byte order.
+ */
+int
+removeAddress_r(struct host *host, afs_uint32 addr, afs_uint16 port)
+{
+ int i;
+ char hoststr[16], hoststr2[16];
+
+ if (!host->interface) {
+ if (host->host == addr && host->port == port) {
+ ViceLog(25,
+ ("Removing only address for host %x (%s:%d), deleting host.\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
+ host->hostFlags |= HOSTDELETED;
+ }
+ } else {
+ removeInterfaceAddr_r(host, host->host, host->port);
+ if (host->interface->numberOfInterfaces == 0) {
+ ViceLog(25,
+ ("Removed only address for host %x (%s:%d), no alternate interfaces, deleting host.\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
+ host->hostFlags |= HOSTDELETED;
+ } else {
+ struct rx_connection *rxconn;
+
+ rxconn = host->callback_rxcon;
+ host->callback_rxcon = NULL;
+
+ if (rxconn) {
+ struct client *client;
+ /*
+ * If rx_DestroyConnection calls h_FreeConnection we will
+ * deadlock on the host_glock_mutex. Work around the problem
+ * by unhooking the client from the connection before
+ * destroying the connection.
+ */
+ client = rx_GetSpecific(rxconn, rxcon_client_key);
+ rx_SetSpecific(rxconn, rxcon_client_key, (void *)0);
+ rx_DestroyConnection(rxconn);
+ }
+
+ for (i=0; i < host->interface->numberOfInterfaces; i++) {
+ if (host->interface->interface[i].valid) {
+ ViceLog(25,
+ ("Removed address for host %x (%s:%d), new primary interface %s:%d.\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
+ afs_inet_ntoa_r(host->interface->interface[i].addr, hoststr2),
+ ntohs(host->interface->interface[i].port)));
+ host->host = host->interface->interface[i].addr;
+ host->port = host->interface->interface[i].port;
+ h_AddHostToAddrHashTable_r(host->host, host->port, host);
+ break;
+ }
+ }
+
+ if (i == host->interface->numberOfInterfaces) {
+ ViceLog(25,
+ ("Removed only address for host %x (%s:%d), no valid alternate interfaces, deleting host.\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
+ host->hostFlags |= HOSTDELETED;
+ } else {
+ if (!sc)
+ sc = rxnull_NewClientSecurityObject();
+ host->callback_rxcon =
+ rx_NewConnection(host->host, host->port, 1, sc, 0);
+ rx_SetConnDeadTime(host->callback_rxcon, 50);
+ rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
+ }
+ }
+ }
+
+ return 0;
+}
+int
+h_threadquota(int waiting)
+{
+ if (lwps > 64) {
+ if (waiting > 5)
+ return 1;
+ } else if (lwps > 32) {
+ if (waiting > 4)
+ return 1;
+ } else if (lwps > 16) {
+ if (waiting > 3)
+ return 1;
+ } else {
+ if (waiting > 2)
+ return 1;
+ }
+ return 0;
+}
/* Host is returned held */
struct host *
struct host *host;
struct host *oldHost;
int code;
- int held, oheld;
+ int held;
struct interfaceAddr interf;
int interfValid = 0;
struct Identity *identP = NULL;
* structure for this address. Verify that the identity
* of the caller matches the identity in the host structure.
*/
+ if ((host->hostFlags & HWHO_INPROGRESS) &&
+ h_threadquota(host->lock.num_waiting)) {
+ if (!held)
+ h_Release_r(host);
+ return 0;
+ }
h_Lock_r(host);
if (!(host->hostFlags & ALTADDR)) {
+ host->hostFlags &= ~HWHO_INPROGRESS;
/* Another thread is doing initialization */
h_Unlock_r(host);
if (!held)
h_Release_r(host);
ViceLog(125,
- ("Host %s:%d starting h_Lookup again\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("Host %x (%s:%d) starting h_Lookup again\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port)));
goto retry;
}
rx_PutConnection(cb_conn);
cb_conn=NULL;
H_LOCK;
- if (code == RXGEN_OPCODE) {
+ if ((code == RXGEN_OPCODE) ||
+ ((code == 0) && (afs_uuid_equal(&interf.uuid, &nulluuid)))) {
identP = (struct Identity *)malloc(sizeof(struct Identity));
if (!identP) {
ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
* that we maintain some extra callback state information */
if (host->interface) {
ViceLog(0,
- ("Host %s:%d used to support WhoAreYou, deleting.\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("Host %x (%s:%d) used to support WhoAreYou, deleting.\n",
+ host,
+ afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port)));
host->hostFlags |= HOSTDELETED;
+ host->hostFlags &= ~HWHO_INPROGRESS;
h_Unlock_r(host);
if (!held)
h_Release_r(host);
* then this is not the same host as before. */
if (!host->interface
|| !afs_uuid_equal(&interf.uuid, &host->interface->uuid)) {
- ViceLog(25,
- ("Host %s:%d has changed its identity, deleting.\n",
- afs_inet_ntoa_r(host->host, hoststr), host->port));
- host->hostFlags |= HOSTDELETED;
+ ViceLog(25,
+ ("Uuid doesn't match host %x (%s:%d).\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
+
+ removeAddress_r(host, host->host, host->port);
+ host->hostFlags &= ~HWHO_INPROGRESS;
h_Unlock_r(host);
if (!held)
h_Release_r(host);
goto retry;
}
} else {
- afs_inet_ntoa_r(host->host, hoststr);
ViceLog(0,
- ("CB: WhoAreYou failed for %s:%d, error %d\n", hoststr,
+ ("CB: WhoAreYou failed for host %x (%s:%d), error %d\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port), code));
host->hostFlags |= VENUSDOWN;
}
else
host->hostFlags &= ~(HERRORTRANS);
host->hostFlags |= ALTADDR;
+ host->hostFlags &= ~HWHO_INPROGRESS;
h_Unlock_r(host);
} else if (host) {
if (!(host->hostFlags & ALTADDR)) {
/* another thread is doing the initialisation */
ViceLog(125,
- ("Host %s:%d waiting for host-init to complete\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("Host %x (%s:%d) waiting for host-init to complete\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port)));
h_Lock_r(host);
+ host->hostFlags &= ~HWHO_INPROGRESS;
h_Unlock_r(host);
if (!held)
h_Release_r(host);
ViceLog(125,
- ("Host %s:%d starting h_Lookup again\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("Host %x (%s:%d) starting h_Lookup again\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port)));
goto retry;
}
if (host->interface)
afsUUID_to_string(&host->interface->uuid, uuid2, 127);
ViceLog(0,
- ("CB: new identity for host %s:%d, deleting(%x %x %s %s)\n",
- afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
+ ("CB: new identity for host %x (%s:%d), deleting(%x %x %s %s)\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
identP->valid, host->interface,
- identP->valid ? uuid1 : "",
- host->interface ? uuid2 : ""));
+ identP->valid ? uuid1 : "no_uuid",
+ host->interface ? uuid2 : "no_uuid"));
/* The host in the cache is not the host for this connection */
+ h_Lock_r(host);
host->hostFlags |= HOSTDELETED;
+ host->hostFlags &= ~HWHO_INPROGRESS;
h_Unlock_r(host);
if (!held)
h_Release_r(host);
rx_PutConnection(cb_conn);
cb_conn=NULL;
H_LOCK;
- if (code == RXGEN_OPCODE) {
+ if ((code == RXGEN_OPCODE) ||
+ ((code == 0) && (afs_uuid_equal(&interf.uuid, &nulluuid)))) {
if (!identP)
identP =
(struct Identity *)malloc(sizeof(struct Identity));
if (!pident)
rx_SetSpecific(tcon, rxcon_ident_key, identP);
ViceLog(25,
- ("Host %s:%d does not support WhoAreYou.\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("Host %x (%s:%d) does not support WhoAreYou.\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port)));
code = 0;
} else if (code == 0) {
if (!pident)
rx_SetSpecific(tcon, rxcon_ident_key, identP);
ViceLog(25,
- ("WhoAreYou success on %s:%d\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("WhoAreYou success on host %x (%s:%d)\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port)));
}
if (code == 0 && !identP->valid) {
if (oldHost) {
int probefail = 0;
- if (!(oheld = h_Held_r(oldHost)))
+ if (!h_Held_r(oldHost))
h_Hold_r(oldHost);
h_Lock_r(oldHost);
+ oldHost->hostFlags |= HWHO_INPROGRESS;
if (oldHost->interface) {
int code2;
* MultiProbeAlternateAddress_r() will remove the
* alternate interfaces that do not have the same
* Uuid. */
- ViceLog(0,("CB: ProbeUuid for %s:%d failed %d\n",
- afs_inet_ntoa_r(oldHost->host, hoststr),
+ ViceLog(0,("CB: ProbeUuid for host %x (%s:%d) failed %d\n",
+ oldHost,
+ afs_inet_ntoa_r(oldHost->host, hoststr),
ntohs(oldHost->port),code2));
MultiProbeAlternateAddress_r(oldHost);
probefail = 1;
/* This is a new address for an existing host. Update
* the list of interfaces for the existing host and
* delete the host structure we just allocated. */
+
+ /* prevent warnings while manipulating interface lists */
+ host->hostFlags |= HOSTDELETED;
+
if (oldHost->host != haddr || oldHost->port != hport) {
struct rx_connection *rxconn;
ViceLog(25,
- ("CB: new addr %s:%d for old host %s:%d\n",
- afs_inet_ntoa_r(haddr, hoststr),
- ntohs(hport),
- afs_inet_ntoa_r(oldHost->host, hoststr2),
- ntohs(oldHost->port)));
+ ("CB: Host %x (%s:%d) has new addr %s:%d\n",
+ oldHost,
+ afs_inet_ntoa_r(oldHost->host, hoststr2),
+ ntohs(oldHost->port),
+ afs_inet_ntoa_r(haddr, hoststr),
+ ntohs(hport)));
if (probefail || oldHost->host == haddr) {
/* The probe failed which means that the old address is
* either unreachable or is not the same host we were just
rx_DestroyConnection(rxconn);
}
}
- host->hostFlags |= HOSTDELETED;
+ host->hostFlags &= ~HWHO_INPROGRESS;
h_Unlock_r(host);
/* release host because it was allocated by h_Alloc_r */
h_Release_r(host);
H_LOCK;
if (code == 0) {
ViceLog(25,
- ("InitCallBackState3 success on %s:%d\n",
- afs_inet_ntoa_r(host->host, hoststr),
+ ("InitCallBackState3 success on host %x (%s:%d)\n",
+ host, afs_inet_ntoa_r(host->host, hoststr),
ntohs(host->port)));
assert(interfValid == 1);
initInterfaceAddr_r(host, &interf);
}
}
if (code) {
- afs_inet_ntoa_r(host->host, hoststr);
ViceLog(0,
- ("CB: RCallBackConnectBack failed for %s:%d\n",
- hoststr, ntohs(host->port)));
+ ("CB: RCallBackConnectBack failed for %x (%s:%d)\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
host->hostFlags |= VENUSDOWN;
} else {
ViceLog(125,
- ("CB: RCallBackConnectBack succeeded for %s:%d\n",
- hoststr, ntohs(host->port)));
+ ("CB: RCallBackConnectBack succeeded for %x (%s:%d)\n",
+ host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
host->hostFlags |= RESETDONE;
}
}
else
host->hostFlags &= ~(HERRORTRANS);
host->hostFlags |= ALTADDR; /* host structure initialization complete */
+ host->hostFlags &= ~HWHO_INPROGRESS;
h_Unlock_r(host);
}
if (caps.Capabilities_val)
void
h_InitHostPackage()
{
+ memset(&nulluuid, 0, sizeof(afsUUID));
afsconf_GetLocalCell(confDir, localcellname, PR_MAXNAMELEN);
if (num_lrealms == -1) {
int i;
if (!client) { /* loop */
host = h_GetHost_r(tcon); /* Returns it h_Held */
+ if (!host)
+ return 0;
+
retryfirstclient:
/* First try to find the client structure */
for (client = host->FirstClient; client; client = client->next) {
if (code) {
char hoststr[16];
ViceLog(0,
- ("pr_GetCPS failed(%d) for user %d, host %s:%d\n",
- code, viceid, afs_inet_ntoa_r(client->host->host,
- hoststr),
+ ("pr_GetCPS failed(%d) for user %d, host %x (%s:%d)\n",
+ code, viceid, client->host,
+ afs_inet_ntoa_r(client->host->host,hoststr),
ntohs(client->host->port)));
/* Although ubik_Call (called by pr_GetCPS) traverses thru
GetClient(struct rx_connection *tcon, struct client **cp)
{
register struct client *client;
+ char hoststr[16];
H_LOCK;
*cp = NULL;
client = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
if (client == NULL) {
ViceLog(0,
- ("GetClient: no client in conn %x (host %x:%d), VBUSYING\n",
- tcon, rxr_HostOf(tcon),ntohs(rxr_PortOf(tcon))));
+ ("GetClient: no client in conn %x (host %s:%d), VBUSYING\n",
+ tcon, afs_inet_ntoa_r(rxr_HostOf(tcon), hoststr),
+ ntohs(rxr_PortOf(tcon))));
H_UNLOCK;
return VBUSY;
}
return VBUSY;
}
if (client && client->LastCall > client->expTime && client->expTime) {
- char hoststr[16];
ViceLog(1,
("Token for %s at %s:%d expired %d\n", h_UserName(client),
afs_inet_ntoa_r(client->host->host, hoststr),
static char User[PR_MAXNAMELEN + 1];
namelist lnames;
idlist lids;
- afs_int32 code;
lids.idlist_len = 1;
lids.idlist_val = (afs_int32 *) malloc(1 * sizeof(afs_int32));
free(lids.idlist_val);
free(lnames.namelist_val);
return User;
-
} /*h_UserName */
{
int ret = 0, found = 0;
struct host *host = NULL;
- struct h_hashChain *chain;
+ struct h_AddrHashChain *chain;
int index = h_HashIndex(addr);
char tmp[16];
int chain_len = 0;
- for (chain = hostHashTable[index]; chain; chain = chain->next) {
+ for (chain = hostAddrHashTable[index]; chain; chain = chain->next) {
host = chain->hostPtr;
if (host == NULL) {
afs_inet_ntoa_r(addr, tmp);
{
int ret = 0, found = 0;
struct host *host = NULL;
- struct h_hashChain *chain;
+ struct h_UuidHashChain *chain;
afsUUID * uuidp = &h->interface->uuid;
int index = h_UuidHashIndex(uuidp);
char tmp[40];
if (ifp) {
int i;
for (i = ifp->numberOfInterfaces-1; i >= 0; i--) {
- h_AddHostToHashTable_r(ifp->interface[i].addr,
- ifp->interface[i].port, host);
}
h_AddHostToUuidHashTable_r(&ifp->uuid, host);
- } else {
- h_AddHostToHashTable_r(host->host, host->port, host);
}
+ h_AddHostToAddrHashTable_r(host->host, host->port, host);
h_InsertList_r(host);
/* setup host id map entry */
}
if (host->LastCall < checktime) {
h_Lock_r(host);
+ host->hostFlags |= HWHO_INPROGRESS;
if (!(host->hostFlags & HOSTDELETED)) {
cb_conn = host->callback_rxcon;
rx_GetConnection(cb_conn);
cb_conn=NULL;
H_LOCK;
}
+ host->hostFlags &= ~HWHO_INPROGRESS;
h_Unlock_r(host);
}
H_UNLOCK;
} /*CheckHost */
+int
+CheckHost_r(register struct host *host, int held, char *dummy)
+{
+ register struct client *client;
+ struct rx_connection *cb_conn = NULL;
+ int code;
+
+#ifdef AFS_DEMAND_ATTACH_FS
+ /* kill the checkhost lwp ASAP during shutdown */
+ FS_STATE_RDLOCK;
+ if (fs_state.mode == FS_MODE_SHUTDOWN) {
+ FS_STATE_UNLOCK;
+ return H_ENUMERATE_BAIL(held);
+ }
+ FS_STATE_UNLOCK;
+#endif
+
+ /* Host is held by h_Enumerate_r */
+ for (client = host->FirstClient; client; client = client->next) {
+ if (client->refCount == 0 && client->LastCall < clientdeletetime) {
+ client->deleted = 1;
+ host->hostFlags |= CLIENTDELETED;
+ }
+ }
+ if (host->LastCall < checktime) {
+ h_Lock_r(host);
+ if (!(host->hostFlags & HOSTDELETED)) {
+ cb_conn = host->callback_rxcon;
+ rx_GetConnection(cb_conn);
+ if (host->LastCall < clientdeletetime) {
+ host->hostFlags |= HOSTDELETED;
+ if (!(host->hostFlags & VENUSDOWN)) {
+ host->hostFlags &= ~ALTADDR; /* alternate address invalid */
+ if (host->interface) {
+ H_UNLOCK;
+ code =
+ RXAFSCB_InitCallBackState3(cb_conn,
+ &FS_HostUUID);
+ H_LOCK;
+ } else {
+ H_UNLOCK;
+ code =
+ RXAFSCB_InitCallBackState(cb_conn);
+ H_LOCK;
+ }
+ host->hostFlags |= ALTADDR; /* alternate addresses valid */
+ if (code) {
+ char hoststr[16];
+ (void)afs_inet_ntoa_r(host->host, hoststr);
+ ViceLog(0,
+ ("CB: RCallBackConnectBack (host.c) failed for host %s:%d\n",
+ hoststr, ntohs(host->port)));
+ host->hostFlags |= VENUSDOWN;
+ }
+ /* Note: it's safe to delete hosts even if they have call
+ * back state, because break delayed callbacks (called when a
+ * message is received from the workstation) will always send a
+ * break all call backs to the workstation if there is no
+ *callback.
+ */
+ }
+ } else {
+ if (!(host->hostFlags & VENUSDOWN) && host->cblist) {
+ char hoststr[16];
+ (void)afs_inet_ntoa_r(host->host, hoststr);
+ if (host->interface) {
+ afsUUID uuid = host->interface->uuid;
+ H_UNLOCK;
+ code = RXAFSCB_ProbeUuid(cb_conn, &uuid);
+ H_LOCK;
+ if (code) {
+ if (MultiProbeAlternateAddress_r(host)) {
+ ViceLog(0,("CheckHost_r: Probing all interfaces of host %s:%d failed, code %d\n",
+ hoststr, ntohs(host->port), code));
+ host->hostFlags |= VENUSDOWN;
+ }
+ }
+ } else {
+ H_UNLOCK;
+ code = RXAFSCB_Probe(cb_conn);
+ H_LOCK;
+ if (code) {
+ ViceLog(0,
+ ("CheckHost_r: Probe failed for host %s:%d, code %d\n",
+ hoststr, ntohs(host->port), code));
+ host->hostFlags |= VENUSDOWN;
+ }
+ }
+ }
+ }
+ H_UNLOCK;
+ rx_PutConnection(cb_conn);
+ cb_conn=NULL;
+ H_LOCK;
+ }
+ h_Unlock_r(host);
+ }
+ return held;
+
+} /*CheckHost_r */
+
/*
* Set VenusDown for any hosts that have not had a call in 15 minutes and
*/
checktime = now - 15 * 60;
clientdeletetime = now - 120 * 60; /* 2 hours ago */
- h_Enumerate(CheckHost, NULL);
-
+
+ H_LOCK;
+ h_Enumerate_r(CheckHost_r, hostList, NULL);
+ H_UNLOCK;
} /*h_CheckHosts */
/*
* This is called with host locked and held. At this point, the
- * hostHashTable should not have any entries for the alternate
+ * hostAddrHashTable should not have any entries for the alternate
* interfaces. This function has to insert these entries in the
- * hostHashTable.
+ * hostAddrHashTable.
*
* The addresses in the interfaceAddr list are in host byte order.
*/
int found;
struct Interface *interface;
char hoststr[16];
+ char uuidstr[128];
+ afs_uint16 port7001 = htons(7001);
assert(host);
assert(interf);
}
/*
- * Convert IP addresses to network byte order, and remove for
- * duplicate IP addresses from the interface list.
+ * The client's notion of its own IP addresses is not reliable.
+ *
+ * 1. The client list might contain private address ranges which
+ * are likely to be re-used by many clients allocated addresses
+ * by a NAT.
+ *
+ * 2. The client list will not include any public addresses that
+ * are hidden by a NAT.
+ *
+ * 3. Private address ranges that are exposed to the server will
+ * be obtained from the rx connections that use them.
+ *
+ * 4. Lists provided by the client are not necessarily truthful.
+ * Many existing clients (UNIX) do not refresh the IP address
+ * list as the actual assigned addresses change. The end result
+ * is that they report the initial address list for the lifetime
+ * of the process. In other words, a client can report addresses
+ * that they are in fact not using. Adding these addresses to
+ * the host interface list without verification is not only
+ * pointless, it is downright dangerous.
+ *
+ * We therefore do not add alternate addresses to the addr hash table.
+ * We only use them for multi-rx callback breaks.
+ */
+
+ /*
+ * Convert IP addresses to network byte order, and remove
+ * duplicate IP addresses from the interface list, and
+ * determine whether or not the incoming addr/port is
+ * listed. Note that if the address matches it is not
+ * truly a match because the port number for the entries
+ * in the interface list are port 7001 and the port number
+ * for this connection might not be 7001.
*/
for (i = 0, count = 0, found = 0; i < number; i++) {
interf->addr_in[i] = htonl(interf->addr_in[i]);
}
if (j == count) {
interf->addr_in[count] = interf->addr_in[i];
- if (interf->addr_in[count] == myAddr)
+ if (interf->addr_in[count] == myAddr &&
+ port7001 == myPort)
found = 1;
count++;
}
malloc(sizeof(struct Interface) +
(sizeof(struct AddrPort) * (count - 1)));
if (!interface) {
- ViceLog(0, ("Failed malloc in initInterfaceAddr_r\n"));
+ ViceLog(0, ("Failed malloc in initInterfaceAddr_r 1\n"));
assert(0);
}
interface->numberOfInterfaces = count;
} else {
interface = (struct Interface *)
malloc(sizeof(struct Interface) + (sizeof(struct AddrPort) * count));
- assert(interface);
+ if (!interface) {
+ ViceLog(0, ("Failed malloc in initInterfaceAddr_r 2\n"));
+ assert(0);
+ }
interface->numberOfInterfaces = count + 1;
interface->interface[count].addr = myAddr;
interface->interface[count].port = myPort;
+ interface->interface[count].valid = 1;
}
- interface->uuid = interf->uuid;
+
for (i = 0; i < count; i++) {
- interface->interface[i].addr = interf->addr_in[i];
+
+ interface->interface[i].addr = interf->addr_in[i];
/* We store the port as 7001 because the addresses reported by
* TellMeAboutYourself and WhoAreYou RPCs are only valid if they
* are coming from fully connected hosts (no NAT/PATs)
*/
- interface->interface[i].port = htons(7001);
+ interface->interface[i].port = port7001;
+ interface->interface[i].valid = 1; /* valid until a conflict is found */
}
+ interface->uuid = interf->uuid;
+
assert(!host->interface);
host->interface = interface;
+ afsUUID_to_string(&interface->uuid, uuidstr, 127);
+
+ ViceLog(125, ("--- uuid %s\n", uuidstr));
for (i = 0; i < host->interface->numberOfInterfaces; i++) {
ViceLog(125, ("--- alt address %s:%d\n",
afs_inet_ntoa_r(host->interface->interface[i].addr, hoststr),
/* deleted a HashChain structure for this address and host */
/* returns 1 on success */
-static int
-h_DeleteHostFromHashTableByAddr_r(afs_uint32 addr, afs_uint16 port, struct host *host)
+int
+h_DeleteHostFromAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host *host)
{
int flag;
- register struct h_hashChain **hp, *th;
+ register struct h_AddrHashChain **hp, *th;
- for (hp = &hostHashTable[h_HashIndex(addr)]; (th = *hp);) {
+ for (hp = &hostAddrHashTable[h_HashIndex(addr)]; (th = *hp);) {
assert(th->hostPtr);
if (th->hostPtr == host && th->addr == addr && th->port == port) {
*hp = th->next;
if (host->interface) {
/* check alternate addresses */
number = host->interface->numberOfInterfaces;
- assert(number > 0);
- for (i = 0; i < number; i++)
- ViceLog(level, ("%s:%d ", afs_inet_ntoa_r(host->interface->interface[i].addr, hoststr),
- ntohs(host->interface->interface[i].port)));
+ if (number == 0)
+ ViceLog(level, ("no-addresses "));
+ else {
+ for (i = 0; i < number; i++)
+ ViceLog(level, ("%s:%d ", afs_inet_ntoa_r(host->interface->interface[i].addr, hoststr),
+ ntohs(host->interface->interface[i].port)));
+ }
}
ViceLog(level, ("\n"));
}