VirtualBox

Changeset 48093 in vbox


Ignore:
Timestamp:
Aug 27, 2013 4:39:15 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
88468
Message:

NAT/xml: loopback mappings introduces NATNetwork entities:

<Mappings>

<Loopback4 address="127.0.1.1" offset="6"/>
<Loopback4 address="127.0.1.2" offset="7"/>

</Mappings>

to describe mapppings any hostid in 127/8 network to our NAT network, e.g. in this case 127.0.1.1 corresponds to network id + 6 (network id here from CIDR defined on creation), for IPv6 (as soon localhost6 could be only one) attribute "loopback6" is reserved in NATNetwork tag.

operators: NATHostLoopbackOffset::operator == (const Utf8Str&) and NATHostLoopbackOffset::operator==(uint32_t) are introduced got using std::find on adding and modification operations in NATNetworkImpl.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/settings.h

    r48004 r48093  
    192192 typedef std::list<NATRule> NATRuleList;
    193193
     194struct NATHostLoopbackOffset
     195{
     196    /** Note: 128/8 is only acceptable */
     197    com::Utf8Str strLoopbackHostAddress;
     198    uint32_t u32Offset;
     199    bool operator == (const com::Utf8Str& strAddr)
     200    {
     201        return (strLoopbackHostAddress == strAddr);
     202    }
     203   
     204    bool operator == (uint32_t off)
     205    {
     206        return (this->u32Offset == off);
     207    }
     208};
     209typedef std::list<NATHostLoopbackOffset> NATLoopbackOffsetList;
     210
    194211/**
    195212 * Common base class for both MainConfigFile and MachineConfigFile
     
    226243    void readMediaRegistry(const xml::ElementNode &elmMediaRegistry, MediaRegistry &mr);
    227244    void readNATForwardRuleList(const xml::ElementNode  &elmParent, NATRuleList &llRules);
     245    void readNATLoopbacks(const xml::ElementNode &elmParent, NATLoopbackOffsetList &llLoopBacks);
    228246
    229247    void setVersionAttribute(xml::ElementNode &elm);
     
    241259                            const MediaRegistry &mr);
    242260    void buildNATForwardRuleList(xml::ElementNode &elmParent, const NATRuleList &natRuleList);
     261    void buildNATLoopbacks(xml::ElementNode &elmParent, const NATLoopbackOffsetList &natLoopbackList);
    243262    void clearDocument();
    244263
     
    342361    bool         fIPv6;
    343362    com::Utf8Str strIPv6Prefix;
     363    uint32_t     u32HostLoopback6Offset;
     364    NATLoopbackOffsetList llHostLoopbackOffsetList;
    344365    bool         fAdvertiseDefaultIPv6Route;
    345366    bool         fNeedDhcpServer;
  • trunk/src/VBox/Main/xml/Settings.cpp

    r47991 r48093  
    837837}
    838838
     839void ConfigFileBase::readNATLoopbacks(const xml::ElementNode &elmParent, NATLoopbackOffsetList &llLoopbacks)
     840{
     841    xml::ElementNodesList plstLoopbacks;
     842    elmParent.getChildElements(plstLoopbacks, "Loopback4");
     843    for (xml::ElementNodesList::iterator lo = plstLoopbacks.begin();
     844         lo != plstLoopbacks.end(); ++lo)
     845    {
     846        NATHostLoopbackOffset loopback;
     847        (*lo)->getAttributeValue("address", loopback.strLoopbackHostAddress);
     848        (*lo)->getAttributeValue("offset", (uint32_t&)loopback.u32Offset);
     849        llLoopbacks.push_back(loopback);
     850    }
     851}
     852
     853
    839854/**
    840855 * Adds a "version" attribute to the given XML element with the
     
    11921207}
    11931208
     1209
     1210void ConfigFileBase::buildNATLoopbacks(xml::ElementNode &elmParent, const NATLoopbackOffsetList &natLoopbackOffsetList)
     1211{
     1212    for (NATLoopbackOffsetList::const_iterator lo = natLoopbackOffsetList.begin();
     1213         lo != natLoopbackOffsetList.end(); ++lo)
     1214    {
     1215        xml::ElementNode *pelmLo;
     1216        pelmLo = elmParent.createChild("Loopback4");
     1217        pelmLo->setAttribute("address", (*lo).strLoopbackHostAddress);
     1218        pelmLo->setAttribute("offset", (*lo).u32Offset);
     1219    }
     1220}
     1221
    11941222/**
    11951223 * Cleans up memory allocated by the internal XML parser. To be called by
     
    13791407               )
    13801408            {
     1409                pelmNet->getAttributeValue("loopback6", net.u32HostLoopback6Offset);
     1410                const xml::ElementNode *pelmMappings;
     1411                if ((pelmMappings = pelmNet->findChildElement("Mappings")))
     1412                    readNATLoopbacks(*pelmMappings, net.llHostLoopbackOffsetList);
     1413
    13811414                const xml::ElementNode *pelmPortForwardRules4;
    13821415                if ((pelmPortForwardRules4 = pelmNet->findChildElement("PortForwarding4")))
     
    16331666                xml::ElementNode *pelmPf6 = pelmThis->createChild("PortForwarding6");
    16341667                buildNATForwardRuleList(*pelmPf6, n.llPortForwardRules6);
     1668            }
     1669
     1670            if (n.llHostLoopbackOffsetList.size())
     1671            {
     1672                xml::ElementNode *pelmMappings = pelmThis->createChild("Mappings");
     1673                buildNATLoopbacks(*pelmMappings, n.llHostLoopbackOffsetList);
     1674
    16351675            }
    16361676        }
Note: See TracChangeset for help on using the changeset viewer.

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