continue;
memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr_list[i],
sizeof(long));
+ vlSockAddr.sin_port = htons(7003);
vlSockAddr.sin_family = AF_INET;
/* sin_port supplied by connection code */
if (procp)
*tp++ = c4;
memcpy(&vlSockAddr.sin_addr.s_addr, &ip_addr,
sizeof(long));
+ vlSockAddr.sin_port = htons(7003);
vlSockAddr.sin_family = AF_INET;
/* sin_port supplied by connection code */
if (procp)
* "Rank" DWORD "0..65535"
* "Clone" DWORD "{0,1}"
* "vlserver" DWORD "7003" <future>
- * "ptserver" DWORD ... <future>
+ * "ptserver" DWORD "7002" <future>
*
* ForceDNS is implied non-zero if there are no [servername]
* keys under the [cellname] key. Otherwise, ForceDNS is zero.
HKEY hkCellServDB = 0, hkCellName = 0, hkServerName = 0;
DWORD dwType, dwSize;
DWORD dwCells, dwServers, dwForceDNS;
- DWORD dwIndex, dwRank;
+ DWORD dwIndex, dwRank, dwPort;
unsigned short ipRank;
+ unsigned short vlPort;
LONG code;
FILETIME ftLastWriteTime;
char szCellName[CELL_MAXNAMELEN];
szAddr[0] = '\0';
}
+ dwSize = sizeof(DWORD);
+ code = RegQueryValueEx(hkServerName, "vlserver", NULL, &dwType,
+ (BYTE *) &dwPort, &dwSize);
+ if (code == ERROR_SUCCESS && dwType == REG_DWORD) {
+ vlPort = htons((unsigned short)dwPort);
+ } else {
+ vlPort = htons(7003);
+ }
+
WSASetLastError(0);
thp = gethostbyname(s);
if (thp) {
memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr, sizeof(long));
+ vlSockAddr.sin_port = htons(7003);
vlSockAddr.sin_family = AF_INET;
/* sin_port supplied by connection code */
if (procp)
*tp++ = c4;
memcpy(&vlSockAddr.sin_addr.s_addr, &ip_addr,
sizeof(long));
+ vlSockAddr.sin_port = vlPort;
vlSockAddr.sin_family = AF_INET;
/* sin_port supplied by connection code */
if (procp)
long cm_EnumerateCellRegistry(afs_uint32 client, cm_enumCellRegistryProc_t *procp, void *rockp)
{
HKEY hkCellServDB = 0;
- DWORD dwType, dwSize;
+ DWORD dwSize;
DWORD dwCells;
DWORD dwIndex;
LONG code;
int cellHostAddrs[AFSMAXCELLHOSTS];
char cellHostNames[AFSMAXCELLHOSTS][MAXHOSTCHARS];
unsigned short ipRanks[AFSMAXCELLHOSTS];
+ unsigned short ports[AFSMAXCELLHOSTS];
int numServers;
int i;
struct sockaddr_in vlSockAddr;
strncasecmp(cellNamep, CM_IOCTL_FILENAME_NOSLASH, strlen(CM_IOCTL_FILENAME_NOSLASH)) == 0)
return -1;
- rc = getAFSServer(cellNamep, cellHostAddrs, cellHostNames, ipRanks, &numServers, ttl);
+ rc = getAFSServer("afs3-vlserver", "udp", cellNamep, 7003,
+ cellHostAddrs, cellHostNames, ports, ipRanks, &numServers, ttl);
if (rc == 0 && numServers > 0) { /* found the cell */
for (i = 0; i < numServers; i++) {
memcpy(&vlSockAddr.sin_addr.s_addr, &cellHostAddrs[i],
sizeof(long));
+ vlSockAddr.sin_port = ports[i];
vlSockAddr.sin_family = AF_INET;
- /* sin_port supplied by connection code */
if (procp)
(*procp)(rockp, &vlSockAddr, cellHostNames[i], ipRanks[i]);
}
};
void processReplyBuffer_AFSDB(SOCKET commSock, PDNS_HDR replyBuff, int *cellHostAddrs, char cellHostNames[][MAXHOSTCHARS],
- unsigned short ipRanks[], int *numServers, int *ttl)
+ unsigned short ports[], unsigned short ipRanks[], int *numServers, int *ttl)
/*PAFS_SRV_LIST (srvList)*/
{
u_char *ptr = (u_char *) replyBuff;
strncpy(cellHostNames[srvCount], hostName, CELL_MAXNAMELEN);
cellHostNames[srvCount][CELL_MAXNAMELEN-1] = '\0';
ipRanks[srvCount] = 0;
+ ports[srvCount] = htons(7003);
srvCount++;
}
else {
}
#endif /* DNSAPI_ENV */
-int getAFSServer(char *cellName, int *cellHostAddrs, char cellHostNames[][MAXHOSTCHARS],
- unsigned short ipRanks[], int *numServers, int *ttl)
+int getAFSServer(const char *service, const char *protocol, const char *cellName,
+ unsigned short afsdbPort,
+ int *cellHostAddrs, char cellHostNames[][MAXHOSTCHARS],
+ unsigned short ports[], unsigned short ipRanks[],
+ int *numServers, int *ttl)
{
#ifndef DNSAPI_ENV
SOCKET commSock;
fprintf(stderr, "getAFSServer: cell %s, cm_dnsEnabled=%d\n", cellName, cm_dnsEnabled);
#endif
+ *numServers = 0;
+ *ttl = 0;
+
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
if (cm_dnsEnabled == -1) { /* not yet initialized, eg when called by klog */
cm_InitDNS(1); /* assume enabled */
#endif
if (cm_dnsEnabled == 0) { /* possibly we failed in cm_InitDNS above */
fprintf(stderr, "DNS initialization failed, disabled\n");
- *numServers = 0;
return -1;
}
+ if (service == NULL || protocol == NULL || cellName == NULL) {
+ fprintf(stderr, "invalid input\n");
+ return -1;
+ }
+
sockAddr = setSockAddr(dns_addr, DNS_PORT);
commSock = socket( AF_INET, SOCK_DGRAM, 0 );
{
/*afsi_log("socket() failed\n");*/
fprintf(stderr, "getAFSServer: socket() failed, errno=%d\n", errno);
- *numServers = 0;
return (-1);
}
if (rc < 0) {
closesocket(commSock);
fprintf(stderr,"getAFSServer: send_DNS_AFSDB_Query failed\n");
- *numServers = 0;
return -1;
}
/*printReplyBuffer_AFSDB(pDNShdr);*/
if (pDNShdr)
- processReplyBuffer_AFSDB(commSock, pDNShdr, cellHostAddrs, cellHostNames, ipRanks, numServers, ttl);
- else
- *numServers = 0;
+ processReplyBuffer_AFSDB(commSock, pDNShdr, cellHostAddrs, cellHostNames, ports, ipRanks, numServers, ttl);
closesocket(commSock);
if (*numServers == 0)
#else /* DNSAPI_ENV */
PDNS_RECORD pDnsCell, pDnsIter, pDnsVol, pDnsVolIter, pDnsCIter;
int i;
- struct sockaddr_in vlSockAddr;
char query[1024];
+ *numServers = 0;
+ *ttl = 0;
+
+ if (service == NULL || protocol == NULL || cellName == NULL)
+ return -1;
+
#ifdef AFS_FREELANCE_CLIENT
if ( cm_stricmp_utf8N(cellName, "Freelance.Local.Root") == 0 )
return -1;
#endif /* AFS_FREELANCE_CLIENT */
- *numServers = 0;
- *ttl = 0;
-
- /* query the AFSDB records of cell */
- StringCbCopyA(query, sizeof(query), cellName);
+ /* query the SRV _afs3-vlserver._udp records of cell */
+ StringCbPrintf(query, sizeof(query), "_%s._%s.%s", service, protocol, cellName);
if (query[strlen(query)-1] != '.') {
StringCbCatA(query, sizeof(query), ".");
}
- if (DnsQuery_A(query, DNS_TYPE_AFSDB, DNS_QUERY_STANDARD, NULL, &pDnsCell, NULL) == ERROR_SUCCESS) {
- memset((void*) &vlSockAddr, 0, sizeof(vlSockAddr));
-
+ if (DnsQuery_A(query, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, &pDnsCell, NULL) == ERROR_SUCCESS) {
/* go through the returned records */
for (pDnsIter = pDnsCell;pDnsIter; pDnsIter = pDnsIter->pNext) {
- /* if we find an AFSDB record with Preference set to 1, we found a afs3-vlserver */
- if (pDnsIter->wType == DNS_TYPE_AFSDB && pDnsIter->Data.Afsdb.wPreference == 1) {
+ /* if we find an SRV record, we found the service */
+ if (pDnsIter->wType == DNS_TYPE_SRV) {
StringCbCopyA(cellHostNames[*numServers], sizeof(cellHostNames[*numServers]),
- pDnsIter->Data.Afsdb.pNameExchange);
- ipRanks[*numServers] = 0;
+ pDnsIter->Data.SRV.pNameTarget);
+ ipRanks[*numServers] = pDnsIter->Data.SRV.wPriority;
+ ports[*numServers] = pDnsIter->Data.SRV.wPort;
(*numServers)++;
-
+
if (!*ttl)
*ttl = pDnsIter->dwTtl;
if (*numServers == AFSMAXCELLHOSTS)
/* now check if there are any A records in the results */
for (pDnsIter = pDnsCell; pDnsIter; pDnsIter = pDnsIter->pNext) {
if(pDnsIter->wType == DNS_TYPE_A)
- /* check if its for one of the afs3-vlservers */
+ /* check if its for one of the service */
for (i=0;i<*numServers;i++)
if(cm_stricmp_utf8(pDnsIter->pName, cellHostNames[i]) == 0)
cellHostAddrs[i] = pDnsIter->Data.A.IpAddress;
/* TODO: if the additional section is missing, then do another lookup for the CNAME */
}
}
- /* we are done with the afs3-vlserver lookup */
+ /* we are done with the service lookup */
DnsRecordListFree(pDnsVol, DnsFreeRecordListDeep);
}
}
DnsRecordListFree(pDnsCell, DnsFreeRecordListDeep);
}
else {
- /* query the SRV _afs3-vlserver._udp records of cell */
- StringCbPrintf(query, sizeof(query), "_afs3-vlserver._udp.%s", cellName);
+ /* query the AFSDB records of cell */
+ StringCbCopyA(query, sizeof(query), cellName);
if (query[strlen(query)-1] != '.') {
StringCbCatA(query, sizeof(query), ".");
}
-
- if (DnsQuery_A(query, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, &pDnsCell, NULL) == ERROR_SUCCESS) {
- memset((void*) &vlSockAddr, 0, sizeof(vlSockAddr));
+ if (DnsQuery_A(query, DNS_TYPE_AFSDB, DNS_QUERY_STANDARD, NULL, &pDnsCell, NULL) == ERROR_SUCCESS) {
/* go through the returned records */
for (pDnsIter = pDnsCell;pDnsIter; pDnsIter = pDnsIter->pNext) {
- /* if we find an SRV record, we found a afs3-vlserver */
- if (pDnsIter->wType == DNS_TYPE_SRV) {
+ /* if we find an AFSDB record with Preference set to 1, we found a service instance */
+ if (pDnsIter->wType == DNS_TYPE_AFSDB && pDnsIter->Data.Afsdb.wPreference == 1) {
StringCbCopyA(cellHostNames[*numServers], sizeof(cellHostNames[*numServers]),
- pDnsIter->Data.SRV.pNameTarget);
- ipRanks[*numServers] = pDnsIter->Data.SRV.wPriority;
+ pDnsIter->Data.Afsdb.pNameExchange);
+ ipRanks[*numServers] = 0;
+ ports[*numServers] = htons(afsdbPort);
(*numServers)++;
if (!*ttl)
/* now check if there are any A records in the results */
for (pDnsIter = pDnsCell; pDnsIter; pDnsIter = pDnsIter->pNext) {
if(pDnsIter->wType == DNS_TYPE_A)
- /* check if its for one of the afs3-vlservers */
+ /* check if its for one of the service */
for (i=0;i<*numServers;i++)
if(cm_stricmp_utf8(pDnsIter->pName, cellHostNames[i]) == 0)
cellHostAddrs[i] = pDnsIter->Data.A.IpAddress;
}
for (i=0;i<*numServers;i++) {
- /* if we don't have an IP yet, then we should try resolving the afs3-vlserver hostname
+ /* if we don't have an IP yet, then we should try resolving the service hostname
in a separate query. */
if (!cellHostAddrs[i]) {
if (DnsQuery_A(cellHostNames[i], DNS_TYPE_A, DNS_QUERY_STANDARD, NULL, &pDnsVol, NULL) == ERROR_SUCCESS) {
/* TODO: if the additional section is missing, then do another lookup for the CNAME */
}
}
- /* we are done with the afs3-vlserver lookup */
+ /* we are done with the service lookup */
DnsRecordListFree(pDnsVol, DnsFreeRecordListDeep);
}
}
#endif /* DNSAPI_ENV */
}
-int getAFSServerW(cm_unichar_t *cellName, int *cellHostAddrs,
+int getAFSServerW(const cm_unichar_t *service, const cm_unichar_t *protocol, const cm_unichar_t *cellName,
+ unsigned short afsdbPort,
+ int *cellHostAddrs,
cm_unichar_t cellHostNames[][MAXHOSTCHARS],
+ unsigned short ports[],
unsigned short ipRanks[],
int *numServers, int *ttl)
{
#ifdef DNSAPI_ENV
PDNS_RECORDW pDnsCell, pDnsIter, pDnsVol,pDnsVolIter, pDnsCIter;
int i;
- struct sockaddr_in vlSockAddr;
cm_unichar_t query[1024];
+ *numServers = 0;
+ *ttl = 0;
+
+ if (service == NULL || protocol == NULL || cellName == NULL)
+ return -1;
+
#ifdef AFS_FREELANCE_CLIENT
if ( cm_stricmp_utf16(cellName, L"Freelance.Local.Root") == 0 )
return -1;
#endif /* AFS_FREELANCE_CLIENT */
- *numServers = 0;
- *ttl = 0;
-
- /* query the AFSDB records of cell */
- StringCbCopyW(query, sizeof(query), cellName);
+ /* query the SRV _afs3-vlserver._udp records of cell */
+ StringCbPrintfW(query, sizeof(query), L"_%S._%S.%S", service, protocol, cellName);
if (query[wcslen(query)-1] != L'.') {
StringCbCatW(query, sizeof(query), L".");
}
- if (DnsQuery_W(query, DNS_TYPE_AFSDB, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD *) &pDnsCell,
+ if (DnsQuery_W(query, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD *) &pDnsCell,
NULL) == ERROR_SUCCESS) {
- memset((void*) &vlSockAddr, 0, sizeof(vlSockAddr));
-
/* go through the returned records */
- for (pDnsIter = pDnsCell;pDnsIter; pDnsIter = pDnsIter->pNext) {
- /* if we find an AFSDB record with Preference set to 1, we found a afs3-vlserver */
- if (pDnsIter->wType == DNS_TYPE_AFSDB && pDnsIter->Data.Afsdb.wPreference == 1) {
+ for (pDnsIter = pDnsCell; pDnsIter; pDnsIter = pDnsIter->pNext) {
+ /* if we find an SRV record, we found a service instance */
+ if (pDnsIter->wType == DNS_TYPE_SRV) {
StringCbCopyW(cellHostNames[*numServers], sizeof(cellHostNames[*numServers]),
- pDnsIter->Data.Afsdb.pNameExchange);
- ipRanks[*numServers] = 0;
+ pDnsIter->Data.SRV.pNameTarget);
+ ipRanks[*numServers] = pDnsIter->Data.SRV.wPriority;
+ ports[*numServers] = pDnsIter->Data.SRV.wPort;
(*numServers)++;
if (!*ttl)
/* now check if there are any A records in the results */
for (pDnsIter = pDnsCell; pDnsIter; pDnsIter = pDnsIter->pNext) {
if(pDnsIter->wType == DNS_TYPE_A)
- /* check if its for one of the afs3-vlservers */
+ /* check if its for one of the service instances */
for (i=0;i<*numServers;i++)
if(cm_stricmp_utf16(pDnsIter->pName, cellHostNames[i]) == 0)
cellHostAddrs[i] = pDnsIter->Data.A.IpAddress;
}
for (i=0;i<*numServers;i++) {
- /* if we don't have an IP yet, then we should try resolving the afs3-vlserver hostname
- in a separate query. */
+ /* if we don't have an IP yet, then we should try resolving the service hostname
+ in a separate query. */
if (!cellHostAddrs[i]) {
if (DnsQuery_W(cellHostNames[i], DNS_TYPE_A, DNS_QUERY_STANDARD, NULL,
(PDNS_RECORD *) &pDnsVol, NULL) == ERROR_SUCCESS) {
/* TODO: if the additional section is missing, then do another lookup for the CNAME */
}
}
- /* we are done with the afs3-vlserver lookup */
+ /* we are done with the service lookup */
DnsRecordListFree((PDNS_RECORD) pDnsVol, DnsFreeRecordListDeep);
}
}
DnsRecordListFree((PDNS_RECORD) pDnsCell, DnsFreeRecordListDeep);
}
else {
- /* query the SRV _afs3-vlserver._udp records of cell */
- StringCbPrintfW(query, sizeof(query), L"_afs3-vlserver._udp.%S", cellName);
+ /* query the AFSDB records of cell */
+ StringCbCopyW(query, sizeof(query), cellName);
if (query[wcslen(query)-1] != L'.') {
StringCbCatW(query, sizeof(query), L".");
}
- if (DnsQuery_W(query, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD *) &pDnsCell,
- NULL) == ERROR_SUCCESS) {
- memset((void*) &vlSockAddr, 0, sizeof(vlSockAddr));
-
+ if (DnsQuery_W(query, DNS_TYPE_AFSDB, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD *) &pDnsCell,
+ NULL) == ERROR_SUCCESS) {
/* go through the returned records */
- for (pDnsIter = pDnsCell; pDnsIter; pDnsIter = pDnsIter->pNext) {
- /* if we find an SRV record, we found a afs3-vlserver */
- if (pDnsIter->wType == DNS_TYPE_SRV) {
+ for (pDnsIter = pDnsCell;pDnsIter; pDnsIter = pDnsIter->pNext) {
+ /* if we find an AFSDB record with Preference set to 1, we found a service instance */
+ if (pDnsIter->wType == DNS_TYPE_AFSDB && pDnsIter->Data.Afsdb.wPreference == 1) {
StringCbCopyW(cellHostNames[*numServers], sizeof(cellHostNames[*numServers]),
- pDnsIter->Data.SRV.pNameTarget);
- ipRanks[*numServers] = pDnsIter->Data.SRV.wPriority;
+ pDnsIter->Data.Afsdb.pNameExchange);
+ ipRanks[*numServers] = 0;
+ ports[*numServers] = htons(afsdbPort);
(*numServers)++;
if (!*ttl)
/* now check if there are any A records in the results */
for (pDnsIter = pDnsCell; pDnsIter; pDnsIter = pDnsIter->pNext) {
if(pDnsIter->wType == DNS_TYPE_A)
- /* check if its for one of the afs3-vlservers */
+ /* check if its for one of the service instances */
for (i=0;i<*numServers;i++)
if(cm_stricmp_utf16(pDnsIter->pName, cellHostNames[i]) == 0)
cellHostAddrs[i] = pDnsIter->Data.A.IpAddress;
}
for (i=0;i<*numServers;i++) {
- /* if we don't have an IP yet, then we should try resolving the afs3-vlserver hostname
+ /* if we don't have an IP yet, then we should try resolving the service hostname
in a separate query. */
if (!cellHostAddrs[i]) {
if (DnsQuery_W(cellHostNames[i], DNS_TYPE_A, DNS_QUERY_STANDARD, NULL,
- (PDNS_RECORD *) &pDnsVol, NULL) == ERROR_SUCCESS) {
+ (PDNS_RECORD *) &pDnsVol, NULL) == ERROR_SUCCESS) {
for (pDnsVolIter = pDnsVol; pDnsVolIter; pDnsVolIter=pDnsVolIter->pNext) {
/* if we get an A record, keep it */
if (pDnsVolIter->wType == DNS_TYPE_A && cm_stricmp_utf16(cellHostNames[i], pDnsVolIter->pName)==0) {
/* TODO: if the additional section is missing, then do another lookup for the CNAME */
}
}
- /* we are done with the afs3-vlserver lookup */
+ /* we are done with the service lookup */
DnsRecordListFree((PDNS_RECORD) pDnsVol, DnsFreeRecordListDeep);
}
}