Changeset 49063 in vbox
- Timestamp:
- Oct 12, 2013 7:16:07 AM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 89863
- Location:
- trunk/src/VBox/NetworkServices/DHCP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/DHCP/Config.cpp
r48956 r49063 34 34 #include "Config.h" 35 35 36 /* types */ 37 class Lease::Data 38 { 39 public: 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 */ 36 75 37 76 const NullConfigEntity *g_NullConfig = new NullConfigEntity(); … … 241 280 else 242 281 { 243 AssertReturn(client->m_lease-> m_address.u != 0,NULL);282 AssertReturn(client->m_lease->getAddress().u != 0,NULL); 244 283 return client->m_lease; 245 284 } … … 269 308 { 270 309 please = new Lease(); 271 please->pCfg = pNetCfg; 272 please->m_client = client; 310 please->init(); 311 please->setConfig(pNetCfg); 312 please->setClient(client); 273 313 client->m_lease = please; 274 client->m_lease-> m_address = hintAddress;314 client->m_lease->setAddress(hintAddress); 275 315 m_allocations[please] = hintAddress; 276 316 return please; … … 287 327 { 288 328 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 291 334 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; 294 337 return please; 295 338 } … … 302 345 int ConfigurationManager::commitLease4Client(Client *client) 303 346 { 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 308 352 return VINF_SUCCESS; 309 353 } … … 486 530 487 531 488 RTNETADDRIPV4 address = client->m_lease-> m_address;532 RTNETADDRIPV4 address = client->m_lease->getAddress(); 489 533 BootPReplyMsg.BootPHeader.bp_yiaddr = address; 490 534 … … 509 553 510 554 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()); 512 556 opt.cbRawOpt = sizeof(RTNETADDRIPV4); 513 557 client->rawOptions.push_back(opt); … … 532 576 prepareReplyPacket4Client(client, u32Xid); 533 577 534 address = client->m_lease-> m_address;578 address = client->m_lease->getAddress(); 535 579 BootPReplyMsg.BootPHeader.bp_ciaddr = address; 536 580 … … 540 584 * XXX: Using addressHint is not correct way to initialize [cy]iaddress... 541 585 */ 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; 544 588 545 589 Assert(BootPReplyMsg.BootPHeader.bp_yiaddr.u); … … 563 607 */ 564 608 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()); 566 610 opt.cbRawOpt = sizeof(RTNETADDRIPV4); 567 611 client->rawOptions.push_back(opt); … … 629 673 BootPReplyMsg.BootPHeader.bp_chaddr.Mac = client->m_mac; 630 674 631 BootPReplyMsg.BootPHeader.bp_yiaddr = client->m_lease-> m_address;675 BootPReplyMsg.BootPHeader.bp_yiaddr = client->m_lease->getAddress(); 632 676 BootPReplyMsg.BootPHeader.bp_siaddr.u = 0; 633 677 … … 722 766 uint8_t *pReqList = pu8ReqList; 723 767 724 const NetworkConfigEntity *pNetCfg = client->m_lease-> pCfg;768 const NetworkConfigEntity *pNetCfg = client->m_lease->getConfig(); 725 769 726 770 for (idxParam = 0; idxParam < cReqList; ++idxParam) … … 778 822 return VINF_SUCCESS; 779 823 } 824 825 826 Lease::~Lease() 827 { 828 if (m) 829 delete m; 830 } 831 832 833 void Lease::init() 834 { 835 if (!m) 836 m = new Lease::Data(); 837 } 838 839 840 bool 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 853 void Lease::phaseStart(uint64_t u64Start) 854 { 855 if (m->fBinding) 856 m->u64TimestampBindingStarted = u64Start; 857 else 858 m->u64TimestampLeasingStarted = u64Start; 859 } 860 861 862 void Lease::bindingPhase(bool fOnOff) 863 { 864 m->fBinding = fOnOff; 865 } 866 867 868 bool Lease::isInBindingPhase() const 869 { 870 return m->fBinding; 871 } 872 873 874 void Lease::setExpiration(uint32_t exp) 875 { 876 if (m->fBinding) 877 m->u32BindExpirationPeriod = exp; 878 else 879 m->u32LeaseExpirationPeriod = exp; 880 } 881 882 883 uint32_t Lease::getExpiration() const 884 { 885 if (m->fBinding) 886 return m->u32BindExpirationPeriod; 887 else 888 return m->u32LeaseExpirationPeriod; 889 } 890 891 892 RTNETADDRIPV4 Lease::getAddress() const 893 { 894 return m->m_address; 895 } 896 897 898 void Lease::setAddress(RTNETADDRIPV4 address) 899 { 900 m->m_address = address; 901 } 902 903 904 const NetworkConfigEntity *Lease::getConfig() const 905 { 906 return m->pCfg; 907 } 908 909 910 void Lease::setConfig(NetworkConfigEntity *pCfg) 911 { 912 m->pCfg = pCfg; 913 } 914 915 916 Client *Lease::getClient() const 917 { 918 return m->m_client; 919 } 920 921 void Lease::setClient(Client *client) 922 { 923 m->m_client = client; 924 } -
trunk/src/VBox/NetworkServices/DHCP/Config.h
r49056 r49063 475 475 { 476 476 public: 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; 519 504 }; 520 505 -
trunk/src/VBox/NetworkServices/DHCP/VBoxNetDHCP.cpp
r49062 r49063 736 736 NetworkManager *networkManager = NetworkManager::getNetworkManager(); 737 737 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. */ 741 741 networkManager->offer4Client(client, pDhcpMsg->bp_xid, opt.au8RawOpt, opt.cbRawOpt); 742 742 } /* end of if(!m_DhcpServer.isNull()) */
Note:
See TracChangeset
for help on using the changeset viewer.