VirtualBox

Changeset 54314 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Feb 19, 2015 9:32:18 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
98389
Message:

Main/DHCPServerImpl: for DHCP options keep not just the text
representation, but also encoding of that text representation.

When XML settings are read, interpret old format, without explicit
"encoding" attribute, as legacy encoding where we are expected to know
the actual format of the option from the option code itself. When
writing legacy options, write them in old format.

This is in preparation for using "de:ad:be:ef" hex-encoded option
values for non-standard options which format we can't know a priory.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/DHCPServerImpl.h

    r50174 r54314  
    2121#define ____H_H_DHCPSERVERIMPL
    2222
     23#include <VBox/settings.h>
    2324#include "DHCPServerWrap.h"
    2425
     
    2728#endif
    2829
    29 namespace settings
    30 {
    31     struct DHCPServer;
    32     struct VmNameSlotKey;
    33 }
    3430#ifdef RT_OS_WINDOWS
    3531# define DHCP_EXECUTABLE_NAME "VBoxNetDHCP.exe"
     
    6258 */
    6359
    64 typedef std::map<DhcpOpt_T, com::Utf8Str> DhcpOptionMap;
    65 typedef DhcpOptionMap::value_type DhcpOptValuePair;
    66 typedef DhcpOptionMap::const_iterator DhcpOptConstIterator;
    67 typedef DhcpOptionMap::iterator DhcpOptIterator;
     60using settings::DhcpOptValue;
     61using settings::DhcpOptionMap;
     62using settings::DhcpOptValuePair;
     63using settings::DhcpOptConstIterator;
     64using settings::DhcpOptIterator;
    6865
    69 typedef std::map<settings::VmNameSlotKey, DhcpOptionMap> VmSlot2OptionsMap;
    70 typedef VmSlot2OptionsMap::value_type VmSlot2OptionsPair;
    71 typedef VmSlot2OptionsMap::iterator VmSlot2OptionsIterator;
     66using settings::VmSlot2OptionsMap;
     67using settings::VmSlot2OptionsPair;
     68using settings::VmSlot2OptionsIterator;
    7269
    7370
  • trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp

    r54284 r54314  
    108108    unconst(mName) = aName;
    109109    m->IPAddress = "0.0.0.0";
    110     m->GlobalDhcpOptions.insert(DhcpOptValuePair(DhcpOpt_SubnetMask, Bstr("0.0.0.0")));
     110    m->GlobalDhcpOptions[DhcpOpt_SubnetMask] = DhcpOptValue("0.0.0.0");
    111111    m->enabled = FALSE;
    112112
     
    222222    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    223223
    224     aNetworkMask = m->GlobalDhcpOptions[DhcpOpt_SubnetMask];
     224    aNetworkMask = m->GlobalDhcpOptions[DhcpOpt_SubnetMask].text;
    225225    return S_OK;
    226226}
     
    294294    for (it = m->GlobalDhcpOptions.begin(); it != m->GlobalDhcpOptions.end(); ++it, ++i)
    295295    {
    296         aValue[i] = Utf8StrFmt("%d:%s", (*it).first, (*it).second.c_str());
     296        uint32_t OptCode = (*it).first;
     297        const DhcpOptValue &OptValue = (*it).second;
     298
     299        // XXX: TODO: factor out and share with getVmSlotOptions()
     300        if (OptValue.encoding == DhcpOptValue::LEGACY)
     301            aValue[i] = Utf8StrFmt("%d:%s", OptCode, OptValue.text.c_str());
    297302    }
    298303
     
    356361    for (it = map.begin(); it != map.end(); ++it, ++i)
    357362    {
    358         aValues[i] = com::Utf8StrFmt("%d:%s", (*it).first, (*it).second.c_str());
     363        uint32_t OptCode = (*it).first;
     364        const DhcpOptValue &OptValue = (*it).second;
     365
     366        // XXX: TODO: factor out and share with getGlobalOptions()
     367        if (OptValue.encoding == DhcpOptValue::LEGACY)
     368            aValues[i] = com::Utf8StrFmt("%d:%s", OptCode, OptValue.text.c_str());
    359369    }
    360370
     
    436446    m->dhcp.setOption(NetworkServiceRunner::kNsrMacAddress, strMAC);
    437447    m->dhcp.setOption(NetworkServiceRunner::kNsrIpAddress,  Utf8Str(m->IPAddress).c_str());
    438     m->dhcp.setOption(NetworkServiceRunner::kNsrIpNetmask, Utf8Str(m->GlobalDhcpOptions[DhcpOpt_SubnetMask]).c_str());
     448    m->dhcp.setOption(NetworkServiceRunner::kNsrIpNetmask, Utf8Str(m->GlobalDhcpOptions[DhcpOpt_SubnetMask].text).c_str());
    439449    m->dhcp.setOption(DHCPServerRunner::kDsrKeyLowerIp, Utf8Str(m->lowerIP).c_str());
    440450    m->dhcp.setOption(DHCPServerRunner::kDsrKeyUpperIp, Utf8Str(m->upperIP).c_str());
  • trunk/src/VBox/Main/xml/Settings.cpp

    r52959 r54314  
    13461346            if (   pelmServer->getAttributeValue("networkName", srv.strNetworkName)
    13471347                && pelmServer->getAttributeValue("IPAddress", srv.strIPAddress)
    1348                 && pelmServer->getAttributeValue("networkMask", srv.GlobalDhcpOptions[DhcpOpt_SubnetMask])
     1348                && pelmServer->getAttributeValue("networkMask", srv.GlobalDhcpOptions[DhcpOpt_SubnetMask].text)
    13491349                && pelmServer->getAttributeValue("lowerIP", srv.strIPLower)
    13501350                && pelmServer->getAttributeValue("upperIP", srv.strIPUpper)
     
    13851385    {
    13861386        DhcpOpt_T OptName;
    1387         com::Utf8Str OptValue;
     1387        com::Utf8Str OptText;
     1388        int32_t OptEnc = DhcpOptValue::LEGACY;
     1389
    13881390        opt->getAttributeValue("name", (uint32_t&)OptName);
    13891391
     
    13911393            continue;
    13921394
    1393         opt->getAttributeValue("value", OptValue);
    1394 
    1395         map.insert(std::map<DhcpOpt_T, Utf8Str>::value_type(OptName, OptValue));
     1395        opt->getAttributeValue("value", OptText);
     1396        opt->getAttributeValue("encoding", OptEnc);
     1397
     1398        map[OptName] = DhcpOptValue(OptText, (DhcpOptValue::Encoding)OptEnc);
    13961399    } /* end of forall("Option") */
    13971400
     
    15351538#endif
    15361539        srv.strIPAddress = "192.168.56.100";
    1537         srv.GlobalDhcpOptions[DhcpOpt_SubnetMask] = "255.255.255.0";
     1540        srv.GlobalDhcpOptions[DhcpOpt_SubnetMask] = DhcpOptValue("255.255.255.0");
    15381541        srv.strIPLower = "192.168.56.101";
    15391542        srv.strIPUpper = "192.168.56.254";
     
    15971600        pelmThis->setAttribute("IPAddress", d.strIPAddress);
    15981601        if (itOpt != d.GlobalDhcpOptions.end())
    1599             pelmThis->setAttribute("networkMask", itOpt->second);
     1602            pelmThis->setAttribute("networkMask", itOpt->second.text);
    16001603        pelmThis->setAttribute("lowerIP", d.strIPLower);
    16011604        pelmThis->setAttribute("upperIP", d.strIPUpper);
     
    16221625
    16231626                pelmOpt->setAttribute("name", itOpt->first);
    1624                 pelmOpt->setAttribute("value", itOpt->second);
     1627                pelmOpt->setAttribute("value", itOpt->second.text);
     1628                if (itOpt->second.encoding != DhcpOptValue::LEGACY)
     1629                    pelmOpt->setAttribute("encoding", (int)itOpt->second.encoding);
    16251630            }
    16261631        } /* end of if */
     
    16441649                    xml::ElementNode *pelmOpt = pelmCfg->createChild("Option");
    16451650                    pelmOpt->setAttribute("name", itOpt1->first);
    1646                     pelmOpt->setAttribute("value", itOpt1->second);
     1651                    pelmOpt->setAttribute("value", itOpt1->second.text);
     1652                    if (itOpt1->second.encoding != DhcpOptValue::LEGACY)
     1653                        pelmOpt->setAttribute("encoding", (int)itOpt1->second.encoding);
    16471654                }
    16481655            }
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