VirtualBox

Changeset 59313 in vbox


Ignore:
Timestamp:
Jan 12, 2016 3:00:48 AM (9 years ago)
Author:
vboxsync
Message:

NAT: When host resolver has a DNS mapping for a name, don't bother
actually looking up the name (and failing if the name doesn't resolve).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/hostres.c

    r59220 r59313  
    142142#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
    143143static void alterHostentWithDataFromDNSMap(PNATState pData, struct hostent *h);
     144static PDNSMAPPINGENTRY getDNSMapByName(PNATState pData, const char *name);
    144145#endif
    145146
     
    458459    struct dnsmsg_header *pHdr;
    459460    struct hostent *h;
     461    struct hostent hostent;
     462    char *h_aliases[1];
     463    char *h_addr_list[2];
    460464    size_t oend;
    461465    size_t nanswers;
     
    477481    }
    478482
    479 
    480     h = gethostbyname(name);
     483    h = NULL;
     484#ifdef VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER
     485    {
     486        PDNSMAPPINGENTRY pDNSMapingEntry = getDNSMapByName(pData, name);
     487        if (pDNSMapingEntry != NULL)
     488        {
     489            LogDbg(("NAT: hostres: %s resolved from %s%s\n",
     490                    name,
     491                    pDNSMapingEntry->fPattern ? "pattern " : "mapping",
     492                    pDNSMapingEntry->fPattern ? pDNSMapingEntry->pszName : ""));
     493
     494            if (qtype == Type_CNAME)
     495            {
     496                goto out;
     497            }
     498
     499            hostent.h_name = name;
     500            hostent.h_aliases = h_aliases;
     501            h_aliases[0] = NULL;
     502            hostent.h_addrtype = AF_INET;
     503            hostent.h_length = sizeof(RTNETADDRIPV4);
     504            hostent.h_addr_list = h_addr_list;
     505            h_addr_list[0] = (char *)&pDNSMapingEntry->u32IpAddress;
     506            h_addr_list[1] = NULL;
     507
     508            h = &hostent;
     509        }
     510    }
     511#endif
     512
     513    if (h == NULL)
     514    {
     515        h = gethostbyname(name);
     516    }
     517
    481518    if (h == NULL)
    482519    {
     
    536573    else if (qtype == Type_CNAME)
    537574    {
    538         LogErr(("NAT: hostres: %s is already canonical\n", name));
     575        LogDbg(("NAT: hostres: %s is already canonical\n", name));
    539576        goto out; /* NB: RCode_NoError without an answer, not RCode_NXDomain */
    540577    }
     
    12561293
    12571294
     1295static PDNSMAPPINGENTRY
     1296getDNSMapByName(PNATState pData, const char *pszName)
     1297{
     1298    PDNSMAPPINGENTRY pDNSMapingEntry;
     1299    const char *pszNameLower;
     1300
     1301    pszNameLower = RTStrDup(pszName);
     1302    if (RT_UNLIKELY(pszNameLower == NULL))
     1303        return NULL;
     1304    RTStrToLower(pszNameLower);
     1305
     1306    STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapNames, MapList)
     1307    {
     1308        if (RTStrICmp(pDNSMapingEntry->pszName, pszNameLower) == 0)
     1309            goto done;
     1310    }
     1311
     1312    STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapPatterns, MapList)
     1313    {
     1314        if (RTStrSimplePatternMultiMatch(pDNSMapingEntry->pszName, RTSTR_MAX,
     1315                                         pszNameLower, RTSTR_MAX, NULL))
     1316            goto done;
     1317    }
     1318
     1319  done:
     1320    RTStrFree(pszNameLower);
     1321    return pDNSMapingEntry;
     1322}
     1323
     1324
    12581325static void
    12591326alterHostentWithDataFromDNSMap(PNATState pData, struct hostent *h)
    12601327{
    12611328    PDNSMAPPINGENTRY pDNSMapingEntry = NULL;
    1262     char **pszAlias;
    1263 
    1264     STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapNames, MapList)
    1265     {
    1266         Assert(!pDNSMapingEntry->fPattern);
    1267 
    1268         if (RTStrICmp(pDNSMapingEntry->pszName, h->h_name) == 0)
     1329    char **ppszAlias;
     1330
     1331    if (h->h_name != NULL)
     1332    {
     1333        pDNSMapingEntry = getDNSMapByName(pData, h->h_name);
     1334        if (pDNSMapingEntry != NULL)
    12691335            goto done;
    1270 
    1271         for (pszAlias = h->h_aliases; *pszAlias != NULL; ++pszAlias)
    1272         {
    1273             if (RTStrICmp(pDNSMapingEntry->pszName, *pszAlias) == 0)
    1274                 goto done;
    1275         }
    1276     }
    1277 
    1278 
    1279 #   define MATCH(_pattern, _string) \
    1280         (RTStrSimplePatternMultiMatch((_pattern), RTSTR_MAX, (_string), RTSTR_MAX, NULL))
    1281 
    1282     STAILQ_FOREACH(pDNSMapingEntry, &pData->DNSMapPatterns, MapList)
    1283     {
    1284         RTStrToLower(h->h_name);
    1285         if (MATCH(pDNSMapingEntry->pszName, h->h_name))
     1336    }
     1337
     1338    for (ppszAlias = h->h_aliases; *ppszAlias != NULL; ++ppszAlias)
     1339    {
     1340        pDNSMapingEntry = getDNSMapByName(pData, *ppszAlias);
     1341        if (pDNSMapingEntry != NULL)
    12861342            goto done;
    1287 
    1288         for (pszAlias = h->h_aliases; *pszAlias != NULL; ++pszAlias)
    1289         {
    1290             RTStrToLower(*pszAlias);
    1291             if (MATCH(pDNSMapingEntry->pszName, h->h_name))
    1292                 goto done;
    1293         }
    12941343    }
    12951344
     
    13011350    }
    13021351}
    1303 #endif
     1352#endif /* VBOX_WITH_DNSMAPPING_IN_HOSTRESOLVER */
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