VirtualBox

Changeset 49063 in vbox


Ignore:
Timestamp:
Oct 12, 2013 7:16:07 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
89863
Message:

VboxNetDHCP: Lease: hides fields to internal data-structure and expose accessor functions.

Lease: wasn't intended to be a base class. drop "virtual" from dtor.

Location:
trunk/src/VBox/NetworkServices/DHCP
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/DHCP/Config.cpp

    r48956 r49063  
    3434#include "Config.h"
    3535
     36/* types */
     37class Lease::Data
     38{
     39public:
     40    Data()
     41    {
     42        m_address.u = 0;
     43        m_client = NULL;
     44        fBinding = true;
     45        u64TimestampBindingStarted = 0;
     46        u64TimestampLeasingStarted = 0;
     47        u32LeaseExpirationPeriod = 0;
     48        u32BindExpirationPeriod = 0;
     49        pCfg = NULL;
     50
     51    }
     52    ~Data(){}
     53   
     54    RTNETADDRIPV4 m_address;
     55
     56    /** lease isn't commited */
     57    bool fBinding;
     58
     59    /** Timestamp when lease commited. */
     60    uint64_t u64TimestampLeasingStarted;
     61    /** Period when lease is expired in secs. */
     62    uint32_t u32LeaseExpirationPeriod;
     63
     64    /** timestamp when lease was bound */
     65    uint64_t u64TimestampBindingStarted;
     66    /* Period when binding is expired in secs. */
     67    uint32_t u32BindExpirationPeriod;
     68
     69    NetworkConfigEntity *pCfg;
     70    Client *m_client;
     71};
     72
     73
     74/* consts */
    3675
    3776const NullConfigEntity *g_NullConfig = new NullConfigEntity();
     
    241280        else
    242281        {
    243             AssertReturn(client->m_lease->m_address.u != 0,NULL);
     282            AssertReturn(client->m_lease->getAddress().u != 0,NULL);
    244283            return client->m_lease;
    245284        }
     
    269308    {
    270309        please = new Lease();
    271         please->pCfg = pNetCfg;
    272         please->m_client = client;
     310        please->init();
     311        please->setConfig(pNetCfg);
     312        please->setClient(client);
    273313        client->m_lease = please;
    274         client->m_lease->m_address = hintAddress;
     314        client->m_lease->setAddress(hintAddress);
    275315        m_allocations[please] = hintAddress;
    276316        return please;
     
    287327        {
    288328            please = new Lease();
    289             please->pCfg = pNetCfg;
    290             please->m_client = client;
     329            please->init();
     330            please->setConfig(pNetCfg);
     331            please->setClient(client);
     332            please->setAddress(address);
     333
    291334            client->m_lease = please;
    292             client->m_lease->m_address = address;
    293             m_allocations[please] = client->m_lease->m_address;
     335
     336            m_allocations[please] = address;
    294337            return please;
    295338        }
     
    302345int ConfigurationManager::commitLease4Client(Client *client)
    303346{
    304     client->m_lease->u64TimestampBindingStarted = 0;
    305     client->m_lease->u32LeaseExpirationPeriod = client->m_lease->pCfg->expirationPeriod();
    306     client->m_lease->u64TimestampLeasingStarted = RTTimeMilliTS();
    307     client->m_lease->fBinding = false;
     347    client->m_lease->bindingPhase(false);
     348
     349    client->m_lease->setExpiration(client->m_lease->getConfig()->expirationPeriod());
     350    client->m_lease->phaseStart(RTTimeMilliTS());
     351
    308352    return VINF_SUCCESS;
    309353}
     
    486530
    487531
    488     RTNETADDRIPV4 address = client->m_lease->m_address;
     532    RTNETADDRIPV4 address = client->m_lease->getAddress();
    489533    BootPReplyMsg.BootPHeader.bp_yiaddr =  address;
    490534
     
    509553
    510554    opt.u8OptId = RTNET_DHCP_OPT_LEASE_TIME;
    511     *(uint32_t *)opt.au8RawOpt = RT_H2N_U32(client->m_lease->pCfg->expirationPeriod());
     555    *(uint32_t *)opt.au8RawOpt = RT_H2N_U32(client->m_lease->getConfig()->expirationPeriod());
    512556    opt.cbRawOpt = sizeof(RTNETADDRIPV4);
    513557    client->rawOptions.push_back(opt);
     
    532576    prepareReplyPacket4Client(client, u32Xid);
    533577
    534     address = client->m_lease->m_address;
     578    address = client->m_lease->getAddress();
    535579    BootPReplyMsg.BootPHeader.bp_ciaddr =  address;
    536580
     
    540584     * XXX: Using addressHint is not correct way to initialize [cy]iaddress...
    541585     */
    542     BootPReplyMsg.BootPHeader.bp_ciaddr = client->m_lease->m_address;
    543     BootPReplyMsg.BootPHeader.bp_yiaddr = client->m_lease->m_address;
     586    BootPReplyMsg.BootPHeader.bp_ciaddr = address;
     587    BootPReplyMsg.BootPHeader.bp_yiaddr = address;
    544588
    545589    Assert(BootPReplyMsg.BootPHeader.bp_yiaddr.u);
     
    563607     */
    564608    opt.u8OptId = RTNET_DHCP_OPT_LEASE_TIME;
    565     *(uint32_t *)opt.au8RawOpt = RT_H2N_U32(client->m_lease->u32LeaseExpirationPeriod);
     609    *(uint32_t *)opt.au8RawOpt = RT_H2N_U32(client->m_lease->getExpiration());
    566610    opt.cbRawOpt = sizeof(RTNETADDRIPV4);
    567611    client->rawOptions.push_back(opt);
     
    629673    BootPReplyMsg.BootPHeader.bp_chaddr.Mac = client->m_mac;
    630674
    631     BootPReplyMsg.BootPHeader.bp_yiaddr = client->m_lease->m_address;
     675    BootPReplyMsg.BootPHeader.bp_yiaddr = client->m_lease->getAddress();
    632676    BootPReplyMsg.BootPHeader.bp_siaddr.u = 0;
    633677
     
    722766    uint8_t *pReqList = pu8ReqList;
    723767
    724     const NetworkConfigEntity *pNetCfg = client->m_lease->pCfg;
     768    const NetworkConfigEntity *pNetCfg = client->m_lease->getConfig();
    725769
    726770    for (idxParam = 0; idxParam < cReqList; ++idxParam)
     
    778822    return VINF_SUCCESS;
    779823}
     824
     825
     826Lease::~Lease()
     827{
     828    if (m)
     829        delete m;
     830}
     831
     832
     833void Lease::init()
     834{
     835    if (!m)
     836        m = new Lease::Data();
     837}
     838
     839
     840bool Lease::isExpired() const
     841{
     842    AssertPtrReturn(m, false);
     843
     844    if (!m->fBinding)
     845        return (ASMDivU64ByU32RetU32(RTTimeMilliTS() - m->u64TimestampLeasingStarted, 1000)
     846                > m->u32LeaseExpirationPeriod);
     847    else
     848        return (ASMDivU64ByU32RetU32(RTTimeMilliTS() - m->u64TimestampBindingStarted, 1000)
     849                > m->u32BindExpirationPeriod);
     850}
     851
     852
     853void Lease::phaseStart(uint64_t u64Start)
     854{
     855    if (m->fBinding)
     856        m->u64TimestampBindingStarted = u64Start;
     857    else
     858        m->u64TimestampLeasingStarted = u64Start;
     859}
     860
     861
     862void Lease::bindingPhase(bool fOnOff)
     863{
     864    m->fBinding = fOnOff;
     865}
     866
     867
     868bool Lease::isInBindingPhase() const
     869{
     870    return m->fBinding;
     871}
     872
     873
     874void Lease::setExpiration(uint32_t exp)
     875{
     876    if (m->fBinding)
     877        m->u32BindExpirationPeriod = exp;
     878    else
     879        m->u32LeaseExpirationPeriod = exp;
     880}
     881
     882
     883uint32_t Lease::getExpiration() const
     884{
     885    if (m->fBinding)
     886        return m->u32BindExpirationPeriod;
     887    else
     888        return m->u32LeaseExpirationPeriod;
     889}
     890
     891
     892RTNETADDRIPV4 Lease::getAddress() const
     893{
     894    return m->m_address;
     895}
     896
     897
     898void Lease::setAddress(RTNETADDRIPV4 address)
     899{
     900    m->m_address = address;
     901}
     902
     903
     904const NetworkConfigEntity *Lease::getConfig() const
     905{
     906    return m->pCfg;
     907}
     908
     909
     910void Lease::setConfig(NetworkConfigEntity *pCfg)
     911{
     912    m->pCfg = pCfg;
     913}
     914
     915
     916Client *Lease::getClient() const
     917{
     918    return m->m_client;
     919}
     920
     921void Lease::setClient(Client *client)
     922{
     923    m->m_client = client;
     924}
  • trunk/src/VBox/NetworkServices/DHCP/Config.h

    r49056 r49063  
    475475{
    476476public:
    477     Lease()
    478     {
    479         m_address.u = 0;
    480         m_client = NULL;
    481         fBinding = false;
    482         u64TimestampBindingStarted = 0;
    483         u64TimestampLeasingStarted = 0;
    484         u32LeaseExpirationPeriod = 0;
    485         u32BindExpirationPeriod = 0;
    486         pCfg = NULL;
    487     }
    488     virtual ~Lease(){}
    489 
    490     bool isExpired()
    491     {
    492         if (!fBinding)
    493             return (ASMDivU64ByU32RetU32(RTTimeMilliTS() - u64TimestampLeasingStarted, 1000)
    494                     > u32LeaseExpirationPeriod);
    495         else
    496             return (ASMDivU64ByU32RetU32(RTTimeMilliTS() - u64TimestampBindingStarted, 1000)
    497                     > u32BindExpirationPeriod);
    498 
    499     }
    500 
    501     /* XXX private: */
    502     RTNETADDRIPV4 m_address;
    503 
    504     /** lease isn't commited */
    505     bool fBinding;
    506 
    507     /** Timestamp when lease commited. */
    508     uint64_t u64TimestampLeasingStarted;
    509     /** Period when lease is expired in secs. */
    510     uint32_t u32LeaseExpirationPeriod;
    511 
    512     /** timestamp when lease was bound */
    513     uint64_t u64TimestampBindingStarted;
    514     /* Period when binding is expired in secs. */
    515     uint32_t u32BindExpirationPeriod;
    516 
    517     NetworkConfigEntity *pCfg;
    518     Client *m_client;
     477    Lease():m(NULL){};
     478    ~Lease();
     479    void init();
     480
     481    bool isExpired() const;
     482
     483    /* Depending on phase *Expiration and phaseStart initialize different values. */
     484    void bindingPhase(bool);
     485    void phaseStart(uint64_t u64Start);
     486    bool isInBindingPhase() const;
     487
     488    void setExpiration(uint32_t);
     489    uint32_t getExpiration() const;
     490
     491    RTNETADDRIPV4 getAddress() const;
     492    void setAddress(RTNETADDRIPV4);
     493
     494    const NetworkConfigEntity *getConfig() const;
     495    void setConfig(NetworkConfigEntity *);
     496   
     497    Client *getClient() const;
     498    void setClient(Client *);
     499
     500    private:
     501    class Data;
     502   
     503    Data *m;
    519504};
    520505
  • trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp

    r49062 r49063  
    736736        NetworkManager *networkManager = NetworkManager::getNetworkManager();
    737737
    738         lease->fBinding = true;
    739         lease->u64TimestampBindingStarted = RTTimeMilliTS();
    740         lease->u32BindExpirationPeriod = 300; /* 3 min. */
     738        lease->bindingPhase(true);
     739        lease->phaseStart(RTTimeMilliTS());
     740        lease->setExpiration(300); /* 3 min. */
    741741        networkManager->offer4Client(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt);
    742742    } /* end of if(!m_DhcpServer.isNull()) */
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