示例#1
0
文件: socket.c 项目: vmware/lightwave
VOID
VmDnsSockPosixFreeEventQueue(
    PVM_SOCK_EVENT_QUEUE pQueue
    )
{
    if (pQueue->pSignalReader)
    {
        VmDnsSockPosixReleaseSocket(pQueue->pSignalReader);
    }
    if (pQueue->pSignalWriter)
    {
        VmDnsSockPosixReleaseSocket(pQueue->pSignalWriter);
    }
    if (pQueue->pMutex)
    {
        VmDnsFreeMutex(pQueue->pMutex);
    }
    if (pQueue->epollFd >= 0)
    {
        close(pQueue->epollFd);
    }
    if (pQueue->pEventArray)
    {
        VmDnsFreeMemory(pQueue->pEventArray);
        pQueue->pEventArray = NULL;
    }
    VmDnsFreeMemory(pQueue);
}
示例#2
0
DWORD
VmDnsCreateSoaRecord(
    PVMDNS_ZONE_INFO    pZoneInfo,
    PVMDNS_RECORD*      ppRecord
    )
{
    DWORD           dwError = 0;
    PVMDNS_RECORD   pRecord = NULL;
    PSTR            pszName = NULL;
    PSTR            pszPrimaryDnsName = NULL;
    PSTR            pszRName = NULL;

    BAIL_ON_VMDNS_INVALID_POINTER(pZoneInfo, dwError);
    BAIL_ON_VMDNS_INVALID_POINTER(ppRecord, dwError);

    dwError = VmDnsAllocateMemory(sizeof(VMDNS_RECORD), (void**)&pRecord);
    BAIL_ON_VMDNS_ERROR(dwError);

    pRecord->dwType = VMDNS_RR_TYPE_SOA;
    dwError = VmDnsAllocateStringA(VMDNS_SOA_RECORD_NAME, &pszName);
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsAllocateStringA(pZoneInfo->pszPrimaryDnsSrvName,
                                    &pszPrimaryDnsName);
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsAllocateStringA(pZoneInfo->pszRName, &pszRName);
    BAIL_ON_VMDNS_ERROR(dwError);

    pRecord->pszName = pszName;
    pRecord->iClass = VMDNS_CLASS_IN;
    pRecord->Data.SOA.pNameAdministrator = pszRName;
    pRecord->Data.SOA.pNamePrimaryServer = pszPrimaryDnsName;
    pRecord->Data.SOA.dwDefaultTtl = pZoneInfo->minimum;
    pRecord->Data.SOA.dwExpire = pZoneInfo->expire;
    pRecord->Data.SOA.dwRefresh = pZoneInfo->refreshInterval;
    pRecord->Data.SOA.dwRetry = pZoneInfo->retryInterval;
    pRecord->Data.SOA.dwSerialNo = pZoneInfo->serial;
    pszName = NULL;
    pszRName = NULL;

    *ppRecord = pRecord;

cleanup:

    return dwError;

error:
    VmDnsFreeMemory(pszName);
    VmDnsFreeMemory(pszRName);
    VMDNS_FREE_RECORD(pRecord);
    goto cleanup;
}
示例#3
0
VOID
VmDnsCliFreeContext(
    PVM_DNS_CLI_CONTEXT pContext
    )
{
    if (pContext->pszZone)
    {
        VmDnsFreeStringA(pContext->pszZone);
    }
    if (pContext->pszNSHost)
    {
        VmDnsFreeStringA(pContext->pszNSHost);
    }
    if (pContext->pszNSIp)
    {
        VmDnsFreeStringA(pContext->pszNSIp);
    }
    if (pContext->pszMboxDomain)
    {
        VmDnsFreeStringA(pContext->pszMboxDomain);
    }
    if (pContext->pszForwarder)
    {
        VmDnsFreeStringA(pContext->pszForwarder);
    }
    if (pContext->pServerContext)
    {
        VmDnsCloseServer(pContext->pServerContext);
    }

    VmDnsClearRecord(&pContext->record);
    VmDnsFreeMemory(pContext);
}
示例#4
0
static
void
VmDnsFreeLockCount(
    void* pkeyData
    )
{
    VmDnsFreeMemory(pkeyData);
}
示例#5
0
VOID
VmDnsFreeRWLock(
    PVMDNS_RWLOCK pLock
    )
{
    pthread_key_delete(pLock->readKey);
    pthread_key_delete(pLock->writeKey);
    VmDnsFreeMemory(pLock);
}
示例#6
0
文件: client.c 项目: vmware/lightwave
VMDNS_API
VOID
VmDnsFreeRecordArray(
    PVMDNS_RECORD_ARRAY     pRecordArray
    )
{
    if (pRecordArray)
    {
        DWORD idx = 0;
        if (pRecordArray->Records)
        {
            for (; idx < pRecordArray->dwCount; ++idx)
            {
                VmDnsClearRecord(&pRecordArray->Records[idx]);
            }

            VmDnsFreeMemory(pRecordArray->Records);
        }
        VmDnsFreeMemory(pRecordArray);
    }
}
示例#7
0
VOID
VmDnsRpcFreeZoneInfoArray(
    PVMDNS_ZONE_INFO_ARRAY pZoneInfoArray
    )
{
    DWORD idx = 0;
    if (pZoneInfoArray)
    {
        for (; idx < pZoneInfoArray->dwCount; ++idx)
        {
            VmDnsRpcFreeZoneInfo(&pZoneInfoArray->ZoneInfos[idx]);
        }
        VmDnsFreeMemory(pZoneInfoArray);
    }
}
示例#8
0
文件: client.c 项目: vmware/lightwave
VMDNS_API
VOID
VmDnsFreeForwarders(
    PVMDNS_FORWARDERS       pForwarder
    )
{
    DWORD idx = 0;
    if (pForwarder)
    {
        for (; idx < pForwarder->dwCount; ++idx)
        {
            VmDnsFreeStringA(pForwarder->ppszName[idx]);
        }
        VmDnsFreeMemory(pForwarder);
    }
}
示例#9
0
static
VOID
VmDnsSockPosixFreeSocket(
    PVM_SOCKET pSocket
    )
{
    if (pSocket->fd >= 0)
    {
        close(pSocket->fd);
    }
    if (pSocket->pMutex)
    {
        VmDnsFreeMutex(pSocket->pMutex);
    }
    VmDnsFreeMemory(pSocket);
}
示例#10
0
文件: cache.c 项目: vmware/lightwave
static
DWORD
VmDnsCacheInitRefreshThread(
    PVMDNS_CACHE_CONTEXT    pContext
    )
{
    DWORD dwError = 0;
    PVMDNS_THREAD pRefreshThread = NULL;
    PVMDNS_COND pRefreshEvent = NULL;
    PVMDNS_MUTEX pThreadMutex = NULL;

    dwError = VmDnsAllocateCondition(&pRefreshEvent);
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsAllocateMutex(&pThreadMutex);
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsAllocateMemory(sizeof(*pRefreshThread), (PVOID *)&pRefreshThread);
    BAIL_ON_VMDNS_ERROR(dwError);

    pContext->pRefreshEvent = pRefreshEvent;
    pContext->pThreadLock = pThreadMutex;
    pContext->pRefreshThread = pRefreshThread;

cleanup:

    return dwError;

error:

    VmDnsFreeMutex(pThreadMutex);
    VmDnsFreeCondition(pRefreshEvent);
    VmDnsFreeMemory(pRefreshThread);

    goto cleanup;
}
示例#11
0
DWORD
VmDnsForwardResponse(
    BOOL        bUseUDP,
    PVM_SOCKET  pSocket,
    PBYTE*      ppResponse,
    PDWORD      pdwResponseSize,
    PDWORD      pdwRCode
    )
{
    DWORD dwError = 0;
    PBYTE pResponse = NULL;
    DWORD dwResponseCode = 0;
    UINT16 usExpectedSize = 0;
    PVM_SOCK_IO_BUFFER pIoSizeResponse = NULL;
    PVM_SOCK_IO_BUFFER pIoDataResponse = NULL;

    if (!pSocket ||
        !ppResponse ||
        !pdwResponseSize ||
        !pdwRCode
       )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDNS_ERROR(dwError);
    }

    if (bUseUDP)
    {
        dwError = VmDnsSockAllocateIoBuffer(
                        VM_SOCK_EVENT_TYPE_UNKNOWN,
                        NULL,
                        VMDNS_UDP_PACKET_SIZE,
                        &pIoDataResponse);
        BAIL_ON_VMDNS_ERROR(dwError);

        dwError = VmDnsSockRead(
                        pSocket,
                        pIoDataResponse);
       BAIL_ON_VMDNS_ERROR(dwError);
    }
    else
    {
        dwError = VmDnsSockAllocateIoBuffer(
                        VM_SOCK_EVENT_TYPE_UNKNOWN,
                        NULL,
                        sizeof(UINT16),
                        &pIoSizeResponse);
        BAIL_ON_VMDNS_ERROR(dwError);

        dwError = VmDnsSockRead(
                        pSocket,
                        pIoSizeResponse);
        BAIL_ON_VMDNS_ERROR(dwError);

        usExpectedSize = htons(*((UINT*)pIoSizeResponse->pData));

        dwError = VmDnsSockAllocateIoBuffer(
                        VM_SOCK_EVENT_TYPE_UNKNOWN,
                        NULL,
                        usExpectedSize,
                        &pIoDataResponse);
        BAIL_ON_VMDNS_ERROR(dwError);

        dwError = VmDnsSockRead(
                        pSocket,
                        pIoDataResponse);
        BAIL_ON_VMDNS_ERROR(dwError);
    }

    dwError = VmDnsAllocateMemory(
                        pIoDataResponse->dwCurrentSize,
                        (PVOID*)&pResponse);
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsCopyMemory(
                      pResponse,
                      pIoDataResponse->dwCurrentSize,
                      pIoDataResponse->pData,
                      pIoDataResponse->dwCurrentSize);
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsPeekResponseCode(
                      pIoDataResponse->dwCurrentSize,
                      pResponse,
                      &dwResponseCode
                      );
    BAIL_ON_VMDNS_ERROR(dwError);

    dwError = VmDnsSockEventQueueRemove(
                                gpSrvContext->pSockContext->pEventQueue,
                                pSocket
                                );
    dwError = 0;

    *ppResponse = pResponse;
    *pdwResponseSize = pIoDataResponse->dwCurrentSize;
    *pdwRCode = dwResponseCode;
    //VmDnsOPStatisticUpdate(FORWARDER_QUERY_COUNT);

cleanup:

    if (pIoSizeResponse)
    {
      
        VMDNS_LOG_IO_RELEASE(pIoSizeResponse);
        VmDnsSockReleaseIoBuffer(pIoSizeResponse);
    }
    if (pIoDataResponse)
    {
        VMDNS_LOG_IO_RELEASE(pIoDataResponse);
        VmDnsSockReleaseIoBuffer(pIoDataResponse);
    }

    return dwError;

error:

    if (pdwResponseSize)
    {
        *pdwResponseSize = 0;
    }

    if (ppResponse)
    {
        *ppResponse = NULL;
    }

    if (pdwRCode)
    {
        *pdwRCode = 0;
    }

    if (pResponse)
    {
        VmDnsFreeMemory(pResponse);
    }

    goto cleanup;
}