Changeset 79819 in vbox for trunk/src/VBox
- Timestamp:
- Jul 16, 2019 7:57:16 PM (5 years ago)
- Location:
- trunk/src/VBox/NetworkServices/Dhcpd
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp
r79818 r79819 830 830 m_secMaxLeaseTime = 0; 831 831 832 /* Swap min and max if max is smaller: */ 833 if (m_secMaxLeaseTime < m_secMinLeaseTime && m_secMinLeaseTime && m_secMaxLeaseTime) 834 { 835 LogRel(("Swapping min/max lease times: %u <-> %u\n", m_secMinLeaseTime, m_secMaxLeaseTime)); 836 uint32_t uTmp = m_secMaxLeaseTime; 837 m_secMaxLeaseTime = m_secMinLeaseTime; 838 m_secMinLeaseTime = uTmp; 839 } 840 832 841 /* 833 842 * Parse children. … … 852 861 { 853 862 ConfigLevelBase::initFromXml(pElmOptions, fStrict, pConfig); 863 864 /* 865 * Resolve defaults here in the global config so we don't have to do this 866 * in Db::allocate() for every lease request. 867 */ 868 if (m_secMaxLeaseTime == 0 && m_secDefaultLeaseTime == 0 && m_secMinLeaseTime == 0) 869 { 870 m_secMinLeaseTime = 300; /* 5 min */ 871 m_secDefaultLeaseTime = 600; /* 10 min */ 872 m_secMaxLeaseTime = 12 * RT_SEC_1HOUR; /* 12 hours */ 873 } 874 else 875 { 876 if (m_secDefaultLeaseTime == 0) 877 { 878 if (m_secMaxLeaseTime != 0) 879 m_secDefaultLeaseTime = RT_MIN(RT_MAX(m_secMinLeaseTime, 600), m_secMaxLeaseTime); 880 else 881 { 882 m_secDefaultLeaseTime = RT_MAX(m_secMinLeaseTime, 600); 883 m_secMaxLeaseTime = RT_MAX(m_secDefaultLeaseTime, 12 * RT_SEC_1HOUR); 884 } 885 } 886 if (m_secMaxLeaseTime == 0) 887 m_secMaxLeaseTime = RT_MAX(RT_MAX(m_secMinLeaseTime, m_secDefaultLeaseTime), 12 * RT_SEC_1HOUR); 888 if (m_secMinLeaseTime == 0) 889 m_secMinLeaseTime = RT_MIN(300, m_secDefaultLeaseTime); 890 } 891 854 892 } 855 893 -
trunk/src/VBox/NetworkServices/Dhcpd/Config.h
r79818 r79819 46 46 /** DHCP options. */ 47 47 optmap_t m_Options; 48 protected: 48 49 /** Minimum lease time, zero means try next level up. */ 49 50 uint32_t m_secMinLeaseTime; … … 77 78 return a_rItRet != m_Options.end(); 78 79 } 80 81 /** @name Accessors 82 * @{ */ 83 uint32_t getMinLeaseTime() const RT_NOEXCEPT { return m_secMinLeaseTime; } 84 uint32_t getDefaultLeaseTime() const RT_NOEXCEPT { return m_secDefaultLeaseTime; } 85 uint32_t getMaxLeaseTime() const RT_NOEXCEPT { return m_secMaxLeaseTime; } 86 /** @} */ 79 87 80 88 protected: -
trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.cpp
r79818 r79819 245 245 m_pConfig->getConfigsForClient(vecConfigs, req.clientId(), OptVendorClassId(req), OptUserClassId(req)); 246 246 247 Binding *b = m_db.allocateBinding(req );247 Binding *b = m_db.allocateBinding(req, vecConfigs); 248 248 if (b == NULL) 249 249 return NULL; … … 313 313 m_pConfig->getConfigsForClient(vecConfigs, req.clientId(), OptVendorClassId(req), OptUserClassId(req)); 314 314 315 Binding *b = m_db.allocateBinding(req );315 Binding *b = m_db.allocateBinding(req, vecConfigs); 316 316 if (b == NULL) 317 317 { -
trunk/src/VBox/NetworkServices/Dhcpd/Db.cpp
r79818 r79819 649 649 * @returns Pointer to the binding, NULL on failure. 650 650 * @param req The DHCP request being served. 651 */ 652 Binding *Db::allocateBinding(const DhcpClientMessage &req) 651 * @param rConfigVec The configurations that applies to the client. 652 * Used for lease time calculation. 653 */ 654 Binding *Db::allocateBinding(const DhcpClientMessage &req, Config::ConfigVec const &rConfigVec) 653 655 { 654 656 const ClientId &id(req.clientId()); … … 694 696 Assert(b->id() == id); 695 697 696 /** @todo 697 * XXX: handle requests for specific lease time! 698 * XXX: old lease might not have expired yet? 699 * Make lease time configurable. 698 /* 699 * Figure out the lease time. 700 700 */ 701 // OptLeaseTime reqLeaseTime(req); 702 b->setLeaseTime(1200); 701 uint32_t secMin = 0; 702 uint32_t secDfl = 0; 703 uint32_t secMax = 0; 704 for (Config::ConfigVec::const_iterator it = rConfigVec.begin(); it != rConfigVec.end(); ++it) 705 { 706 ConfigLevelBase const *pConfig = *it; 707 if (secMin == 0) 708 secMin = pConfig->getMinLeaseTime(); 709 if (secDfl == 0) 710 secDfl = pConfig->getDefaultLeaseTime(); 711 if (secMax == 0) 712 secMax = pConfig->getMaxLeaseTime(); 713 } 714 Assert(secMin); Assert(secMax); Assert(secDfl); /* global config always have non-defaults set */ 715 if (secMin > secMax) 716 secMin = secMax; 717 718 OptLeaseTime reqLeaseTime(req); 719 if (!reqLeaseTime.present()) 720 { 721 b->setLeaseTime(secDfl); 722 LogRel2(("Lease time %u secs (default)\n", b->leaseTime())); 723 } 724 else if (reqLeaseTime.value() < secMin) 725 { 726 b->setLeaseTime(secMin); 727 LogRel2(("Lease time %u secs (min)\n", b->leaseTime())); 728 } 729 else if (reqLeaseTime.value() > secMax) 730 { 731 b->setLeaseTime(secMax); 732 LogRel2(("Lease time %u secs (max)\n", b->leaseTime())); 733 } 734 else 735 { 736 b->setLeaseTime(reqLeaseTime.value()); 737 LogRel2(("Lease time %u secs (requested)\n", b->leaseTime())); 738 } 703 739 } 704 740 return b; -
trunk/src/VBox/NetworkServices/Dhcpd/Db.h
r79818 r79819 182 182 bool addressBelongs(RTNETADDRIPV4 addr) const RT_NOEXCEPT { return m_pool.contains(addr); } 183 183 184 Binding *allocateBinding(const DhcpClientMessage &req );184 Binding *allocateBinding(const DhcpClientMessage &req, Config::ConfigVec const &rConfigVec); 185 185 bool releaseBinding(const DhcpClientMessage &req) RT_NOEXCEPT; 186 186
Note:
See TracChangeset
for help on using the changeset viewer.