VirtualBox

Changeset 2938 in vbox


Ignore:
Timestamp:
May 30, 2007 4:30:42 PM (18 years ago)
Author:
vboxsync
Message:

NAT: Pass first entry of search list as domain name in DHCP (which DHCP
clients usually use to populate the DNS search list).

Location:
trunk/src/VBox/Devices/Network
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvNAT.cpp

    r2837 r2938  
    303303 * @param   pCfgHandle      The drivers configuration handle.
    304304 */
    305 static int drvNATConstructRedir(PDRVNAT pData, PCFGMNODE pCfgHandle)
     305static int drvNATConstructRedir(unsigned iInstance, PDRVNAT pData, PCFGMNODE pCfgHandle)
    306306{
    307307    /*
     
    326326                fUDP = false;
    327327            else if (VBOX_FAILURE(rc))
    328                 return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"UDP\" boolean returned %Vrc"), rc);
     328                return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"UDP\" boolean returned %Vrc"), iInstance, rc);
    329329        }
    330330        else if (VBOX_SUCCESS(rc))
     
    335335                fUDP = true;
    336336            else
    337                 return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS, N_("NAT#%d: Invalid configuration value for \"Protocol\": \"%s\""), szProtocol);
     337                return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS, N_("NAT#%d: Invalid configuration value for \"Protocol\": \"%s\""), iInstance, szProtocol);
    338338        }
    339339        else
    340             return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"Protocol\" string returned %Vrc"), rc);
     340            return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"Protocol\" string returned %Vrc"), iInstance, rc);
    341341
    342342        /* host port */
     
    344344        rc = CFGMR3QueryS32(pNode, "HostPort", &iHostPort);
    345345        if (VBOX_FAILURE(rc))
    346             return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"HostPort\" integer returned %Vrc"), rc);
     346            return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"HostPort\" integer returned %Vrc"), iInstance, rc);
    347347
    348348        /* guest port */
     
    350350        rc = CFGMR3QueryS32(pNode, "GuestPort", &iGuestPort);
    351351        if (VBOX_FAILURE(rc))
    352             return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"GuestPort\" integer returned %Vrc"), rc);
     352            return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"GuestPort\" integer returned %Vrc"), iInstance, rc);
    353353
    354354        /* guest address */
     
    358358            strcpy(szGuestIP, "10.0.2.15");
    359359        else if (VBOX_FAILURE(rc))
    360             return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"GuestIP\" string returned %Vrc"), rc);
     360            return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"GuestIP\" string returned %Vrc"), iInstance, rc);
    361361        struct in_addr GuestIP;
    362362        if (!inet_aton(szGuestIP, &GuestIP))
    363             return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_NAT_REDIR_GUEST_IP, RT_SRC_POS, N_("NAT#%d: configuration error: invalid \"GuestIP\"=\"%s\", inet_aton failed"), szGuestIP);
     363            return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_NAT_REDIR_GUEST_IP, RT_SRC_POS, N_("NAT#%d: configuration error: invalid \"GuestIP\"=\"%s\", inet_aton failed"), iInstance, szGuestIP);
    364364
    365365        /*
     
    368368        Log(("drvNATConstruct: Redir %d -> %s:%d\n", iHostPort, szGuestIP, iGuestPort));
    369369        if (slirp_redir(pData->pNATState, fUDP, iHostPort, GuestIP, iGuestPort) < 0)
    370             return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_NAT_REDIR_SETUP, RT_SRC_POS, N_("NAT#%d: configuration error: failed to set up redirection of %d to %s:%d. Probably a conflict with existing services or other rules"), iHostPort, szGuestIP, iGuestPort);
     370            return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_NAT_REDIR_SETUP, RT_SRC_POS, N_("NAT#%d: configuration error: failed to set up redirection of %d to %s:%d. Probably a conflict with existing services or other rules"), iInstance, iHostPort, szGuestIP, iGuestPort);
    371371    } /* for each redir rule */
    372372
     
    394394     * Validate the config.
    395395     */
    396     if (!CFGMR3AreValuesValid(pCfgHandle, "\0"))
    397         return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, "");
     396    if (!CFGMR3AreValuesValid(pCfgHandle, "PassDomain\0"))
     397        return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, "Unknown NAT configuration option, only supports PassDomain");
     398
     399    /*
     400     * Get the configuration settings.
     401     */
     402    bool fPassDomain = true;
     403    int rc = CFGMR3QueryBool(pCfgHandle, "PassDomain", &fPassDomain);
     404    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     405        fPassDomain = true;
     406    else if (VBOX_FAILURE(rc))
     407        return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"PassDomain\" boolean returned %Vrc"), pDrvIns->iInstance, rc);
    398408
    399409    /*
     
    424434     * The slirp lock..
    425435     */
    426     int rc = RTCritSectInit(&pData->CritSect);
     436    rc = RTCritSectInit(&pData->CritSect);
    427437    if (VBOX_FAILURE(rc))
    428438        return rc;
     
    442452             * Initialize slirp.
    443453             */
    444             rc = slirp_init(&pData->pNATState, &szNetAddr[0], pData);
     454            rc = slirp_init(&pData->pNATState, &szNetAddr[0], fPassDomain, pData);
    445455            if (VBOX_SUCCESS(rc))
    446456            {
    447                 int rc2 = drvNATConstructRedir(pData, pCfgHandle);
     457                int rc2 = drvNATConstructRedir(pDrvIns->iInstance, pData, pCfgHandle);
    448458                if (VBOX_SUCCESS(rc2))
    449459                {
  • trunk/src/VBox/Devices/Network/slirp/bootp.c

    r1076 r2938  
    263263            q += val;
    264264        }
     265
     266        if (pData->pszDomain && pData->fPassDomain)
     267        {
     268            val = strlen(pData->pszDomain);
     269            *q++ = RFC1533_DOMAINNAME;
     270            *q++ = val;
     271            memcpy(q, pData->pszDomain, val);
     272            q += val;
     273        }
    265274    }
    266275    *q++ = RFC1533_END;
  • trunk/src/VBox/Devices/Network/slirp/libslirp.h

    r1076 r2938  
    2727#endif
    2828
    29 int slirp_init(PNATState *, const char *, void *);
     29int slirp_init(PNATState *, const char *, bool, void *);
    3030void slirp_term(PNATState);
    3131void slirp_link_up(PNATState);
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r2566 r2938  
    1313#ifdef _WIN32
    1414
    15 static int get_dns_addr(PNATState pData, struct in_addr *pdns_addr)
     15static int get_dns_addr_domain(PNATState pData, struct in_addr *pdns_addr,
     16                               const char **ppszDomain)
    1617{
    1718    FIXED_INFO *FixedInfo=NULL;
     
    2021    IP_ADDR_STRING *pIPAddr;
    2122    struct in_addr tmp_addr;
     23
     24    *ppszDomain = NULL;
     25    /** @todo implement search list for Windows host. */
    2226
    2327    FixedInfo = (FIXED_INFO *)GlobalAlloc(GPTR, sizeof(FIXED_INFO));
     
    6165#else
    6266
    63 static int get_dns_addr(PNATState pData, struct in_addr *pdns_addr)
     67static int get_dns_addr_domain(PNATState pData, struct in_addr *pdns_addr,
     68                               const char **ppszDomain)
    6469{
    6570    char buff[512];
     
    9297        return -1;
    9398
     99    *ppszDomain = NULL;
    94100    Log(("nat: IP address of your DNS(s): \n"));
    95101    while (fgets(buff, 512, f) != NULL) {
     
    108114                Log(("nat: %s\n", inet_ntoa(tmp_addr)));
    109115        }
     116        if (!strncmp(buff, "domain", 6) || !strncmp(buff, "search", 6))
     117        {
     118            /* Domain name/search list present. Pick first entry */
     119            if (*ppszDomain == NULL)
     120            {
     121                char *tok;
     122                tok = strtok(&buff[6], " \t\n");
     123                *ppszDomain = RTStrDup(tok);
     124                if (pData->fPassDomain)
     125                    LogRel(("NAT: passing domain name %s\n", tok));
     126                else
     127                    Log(("nat: ignoring domain %s\n", tok));
     128            }
     129        }
    110130    }
    111131    fclose(f);
     
    117137#endif
    118138
    119 int slirp_init(PNATState *ppData, const char *pszNetAddr, void *pvUser)
     139int slirp_init(PNATState *ppData, const char *pszNetAddr, bool fPassDomain, void *pvUser)
    120140{
    121141    int fNATfailed = 0;
     
    125145        return VERR_NO_MEMORY;
    126146    memset(pData, '\0', sizeof(NATState));
     147    pData->fPassDomain = fPassDomain;
    127148    pData->pvUser = pvUser;
    128149#if ARCH_BITS == 64
     
    150171    inet_aton("127.0.0.1", &dns_addr);
    151172
    152     if (get_dns_addr(pData, &dns_addr) < 0)
     173    if (get_dns_addr_domain(pData, &dns_addr, &pData->pszDomain) < 0)
    153174        fNATfailed = 1;
    154175
     
    193214void slirp_term(PNATState pData)
    194215{
     216    if (pData->pszDomain)
     217        RTStrFree((char *)(void *)pData->pszDomain);
     218
    195219#if ARCH_BITS == 64
    196220    LogRel(("NAT: cpvHashUsed=%RU32 cpvHashCollisions=%RU32 cpvHashInserts=%RU64 cpvHashDone=%RU64\n",
  • trunk/src/VBox/Devices/Network/slirp/slirp_state.h

    r1300 r2938  
    9191    struct ex_list *exec_list;
    9292    char slirp_hostname[33];
     93    bool fPassDomain;
     94    const char *pszDomain;
    9395    /* Stuff from tcp_input.c */
    9496    struct socket tcb;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette