Changeset 79563 in vbox for trunk/src/VBox/NetworkServices/Dhcpd
- Timestamp:
- Jul 6, 2019 1:22:56 AM (6 years ago)
- Location:
- trunk/src/VBox/NetworkServices/Dhcpd
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/Dhcpd/ClientId.cpp
r79524 r79563 34 34 * Registers the ClientId format type callback ("%R[id]"). 35 35 */ 36 void ClientId::registerFormat() 36 void ClientId::registerFormat() RT_NOEXCEPT 37 37 { 38 38 if (!g_fFormatRegistered) … … 82 82 83 83 84 bool operator==(const ClientId &l, const ClientId &r) 84 bool operator==(const ClientId &l, const ClientId &r) RT_NOEXCEPT 85 85 { 86 86 if (l.m_id.present()) … … 99 99 100 100 101 bool operator<(const ClientId &l, const ClientId &r) 101 bool operator<(const ClientId &l, const ClientId &r) RT_NOEXCEPT 102 102 { 103 103 if (l.m_id.present()) -
trunk/src/VBox/NetworkServices/Dhcpd/ClientId.h
r79529 r79563 41 41 : m_mac(), m_id() 42 42 {} 43 /** @throws std::bad_alloc */ 43 44 ClientId(const RTMAC &a_mac, const OptClientId &a_id) 44 45 : m_mac(a_mac), m_id(a_id) 45 46 {} 47 /** @throws std::bad_alloc */ 46 48 ClientId(const ClientId &a_rThat) 47 49 : m_mac(a_rThat.m_mac), m_id(a_rThat.m_id) 48 50 {} 51 /** @throws std::bad_alloc */ 49 52 ClientId &operator=(const ClientId &a_rThat) 50 53 { … … 54 57 } 55 58 56 const RTMAC &mac() const { return m_mac; }57 const OptClientId &id() const { return m_id; }59 const RTMAC &mac() const RT_NOEXCEPT { return m_mac; } 60 const OptClientId &id() const RT_NOEXCEPT { return m_id; } 58 61 59 62 /** @name String formatting of %R[id]. 60 63 * @{ */ 61 static void registerFormat() ;64 static void registerFormat() RT_NOEXCEPT; 62 65 private: 63 66 static DECLCALLBACK(size_t) rtStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, const char *pszType, … … 66 69 /** @} */ 67 70 68 friend bool operator==(const ClientId &l, const ClientId &r) ;69 friend bool operator<(const ClientId &l, const ClientId &r) ;71 friend bool operator==(const ClientId &l, const ClientId &r) RT_NOEXCEPT; 72 friend bool operator<(const ClientId &l, const ClientId &r) RT_NOEXCEPT; 70 73 }; 71 74 72 bool operator==(const ClientId &l, const ClientId &r) ;73 bool operator<(const ClientId &l, const ClientId &r) ;75 bool operator==(const ClientId &l, const ClientId &r) RT_NOEXCEPT; 76 bool operator<(const ClientId &l, const ClientId &r) RT_NOEXCEPT; 74 77 75 inline bool operator!=(const ClientId &l, const ClientId &r) 78 inline bool operator!=(const ClientId &l, const ClientId &r) RT_NOEXCEPT 76 79 { 77 80 return !(l == r); -
trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp
r79553 r79563 88 88 * @returns IPRT status code. 89 89 */ 90 int Config::i_init() 90 int Config::i_init() RT_NOEXCEPT 91 91 { 92 92 return i_homeInit(); … … 100 100 * @todo Too many init functions? 101 101 */ 102 int Config::i_homeInit() 102 int Config::i_homeInit() RT_NOEXCEPT 103 103 { 104 104 char szHome[RTPATH_MAX]; … … 121 121 * @returns Config instance on success, NULL on failure. 122 122 */ 123 /*static*/ Config *Config::i_createInstanceAndCallInit() 123 /*static*/ Config *Config::i_createInstanceAndCallInit() RT_NOEXCEPT 124 124 { 125 125 Config *pConfig; … … 161 161 * Interal worker for i_setNetwork() that sets m_strBaseName to sanitized the 162 162 * version of m_strNetwork suitable for use as a path component. 163 * 164 * @throws std::bad_alloc 163 165 */ 164 166 void Config::i_sanitizeBaseName() … … 196 198 * @todo make the log file directly configurable? 197 199 */ 198 int Config::i_logInit() 200 int Config::i_logInit() RT_NOEXCEPT 199 201 { 200 202 if (m_strHome.isEmpty() || m_strBaseName.isEmpty()) … … 241 243 * Post process and validate the configuration after it has been loaded. 242 244 */ 243 int Config::i_complete() 245 int Config::i_complete() RT_NOEXCEPT 244 246 { 245 247 if (m_strNetwork.isEmpty()) … … 336 338 337 339 338 /*static*/ Config *Config::hardcoded() 340 /*static*/ Config *Config::hardcoded() RT_NOEXCEPT 339 341 { 340 342 std::unique_ptr<Config> config(i_createInstanceAndCallInit()); … … 378 380 379 381 380 382 /** 383 * Old VBoxNetDHCP style command line parsing. 384 * 385 * @throws std::bad_alloc 386 */ 381 387 /*static*/ Config *Config::compat(int argc, char **argv) 382 388 { … … 519 525 520 526 521 Config *Config::create(int argc, char **argv) 522 { 523 #define DHCPD_GETOPT_COMMENT 256 /* No short option for --comment */ 527 Config *Config::create(int argc, char **argv) RT_NOEXCEPT 528 { 524 529 static const RTGETOPTDEF s_aOptions[] = 525 530 { 526 { "--config", 'c', 527 { "--comment", DHCPD_GETOPT_COMMENT, RTGETOPT_REQ_STRING }531 { "--config", 'c', RTGETOPT_REQ_STRING }, 532 { "--comment", '#', RTGETOPT_REQ_STRING } 528 533 }; 529 534 … … 556 561 break; 557 562 558 case DHCPD_GETOPT_COMMENT: /* --comment */563 case '#': /* --comment */ 559 564 /* The sole purpose of this option is to allow identification of DHCP 560 565 * server instances in the process list. We ignore the required string … … 589 594 * @note The release log has is not operational when this method is called. 590 595 */ 591 Config *Config::i_read(const char *pszFileName) 596 Config *Config::i_read(const char *pszFileName) RT_NOEXCEPT 592 597 { 593 598 if (pszFileName == NULL || pszFileName[0] == '\0') … … 635 640 return NULL; 636 641 } 642 catch (std::bad_alloc &) 643 { 644 LogFunc(("std::bad_alloc\n")); 645 RTMsgError("std::bad_alloc reading config\n"); 646 return NULL; 647 } 637 648 catch (...) 638 649 { … … 650 661 * below it. 651 662 * 652 * @throws stuff. 663 * @param pElmRoot The root element. 664 * @throws std::bad_alloc, ConfigFileError 653 665 */ 654 666 void Config::i_parseConfig(const xml::ElementNode *pElmRoot) … … 694 706 * 695 707 * @param pElmServer The DHCPServer element. 696 * @throws ConfigFileError708 * @throws std::bad_alloc, ConfigFileError 697 709 */ 698 710 void Config::i_parseServer(const xml::ElementNode *pElmServer) … … 767 779 * 768 780 * @param pElmServer The <Options> element. 769 * @throws ConfigFileError781 * @throws std::bad_alloc, ConfigFileError 770 782 */ 771 783 void Config::i_parseGlobalOptions(const xml::ElementNode *options) … … 792 804 * 793 805 * @param pElmServer The <Config> element. 794 * @throws ConfigFileError806 * @throws std::bad_alloc, ConfigFileError 795 807 */ 796 808 void Config::i_parseVMConfig(const xml::ElementNode *pElmConfig) … … 841 853 * @param pElmServer The <Option> element. 842 854 * @param optmap The option map to add the option to. 843 * @throws ConfigFileError855 * @throws std::bad_alloc, ConfigFileError 844 856 */ 845 857 void Config::i_parseOption(const xml::ElementNode *pElmOption, optmap_t &optmap) … … 946 958 * @param idVendorClass The vendor class ID. 947 959 * @param idUserClass The user class ID. 960 * 961 * @throws std::bad_alloc 948 962 */ 949 963 optmap_t &Config::getOptions(optmap_t &a_rRetOpts, const OptParameterRequest &reqOpts, const ClientId &id, -
trunk/src/VBox/NetworkServices/Dhcpd/Config.h
r79553 r79563 72 72 Config(); 73 73 74 int i_init() ;75 int i_homeInit() ;76 static Config *i_createInstanceAndCallInit() ;77 int i_logInit() ;78 int i_complete() ;74 int i_init() RT_NOEXCEPT; 75 int i_homeInit() RT_NOEXCEPT; 76 static Config *i_createInstanceAndCallInit() RT_NOEXCEPT; 77 int i_logInit() RT_NOEXCEPT; 78 int i_complete() RT_NOEXCEPT; 79 79 80 80 public: 81 81 /** @name Factory methods 82 82 * @{ */ 83 static Config *hardcoded() ;/**< For testing. */84 static Config *create(int argc, char **argv) ;/**< --config */85 static Config *compat(int argc, char **argv); /**< Old VBoxNetDHCP command line parsing. */83 static Config *hardcoded() RT_NOEXCEPT; /**< For testing. */ 84 static Config *create(int argc, char **argv) RT_NOEXCEPT; /**< --config */ 85 static Config *compat(int argc, char **argv); 86 86 /** @} */ 87 87 88 88 /** @name Accessors 89 89 * @{ */ 90 const RTCString &getHome() const { return m_strHome; }90 const RTCString &getHome() const RT_NOEXCEPT { return m_strHome; } 91 91 92 const RTCString &getNetwork() const { return m_strNetwork; }92 const RTCString &getNetwork() const RT_NOEXCEPT { return m_strNetwork; } 93 93 94 const RTCString &getBaseName() const { return m_strBaseName; }95 const RTCString &getTrunk() const { return m_strTrunk; }96 INTNETTRUNKTYPE getTrunkType() const { return m_enmTrunkType; }94 const RTCString &getBaseName() const RT_NOEXCEPT { return m_strBaseName; } 95 const RTCString &getTrunk() const RT_NOEXCEPT { return m_strTrunk; } 96 INTNETTRUNKTYPE getTrunkType() const RT_NOEXCEPT { return m_enmTrunkType; } 97 97 98 const RTMAC &getMacAddress() const { return m_MacAddress; }98 const RTMAC &getMacAddress() const RT_NOEXCEPT { return m_MacAddress; } 99 99 100 RTNETADDRIPV4 getIPv4Address() const { return m_IPv4Address; }101 RTNETADDRIPV4 getIPv4Netmask() const { return m_IPv4Netmask; }100 RTNETADDRIPV4 getIPv4Address() const RT_NOEXCEPT { return m_IPv4Address; } 101 RTNETADDRIPV4 getIPv4Netmask() const RT_NOEXCEPT { return m_IPv4Netmask; } 102 102 103 RTNETADDRIPV4 getIPv4PoolFirst() const { return m_IPv4PoolFirst; }104 RTNETADDRIPV4 getIPv4PoolLast() const { return m_IPv4PoolLast; }103 RTNETADDRIPV4 getIPv4PoolFirst() const RT_NOEXCEPT { return m_IPv4PoolFirst; } 104 RTNETADDRIPV4 getIPv4PoolLast() const RT_NOEXCEPT { return m_IPv4PoolLast; } 105 105 /** @} */ 106 106 … … 112 112 /** @name Configuration file reading and parsing 113 113 * @{ */ 114 static Config *i_read(const char *pszFileName) ;114 static Config *i_read(const char *pszFileName) RT_NOEXCEPT; 115 115 void i_parseConfig(const xml::ElementNode *root); 116 116 void i_parseServer(const xml::ElementNode *server); -
trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.cpp
r79553 r79563 16 16 */ 17 17 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 18 22 #include "DhcpdInternal.h" 19 23 #include "DHCPD.h" 20 24 #include "DhcpOptions.h" 21 25 22 #include <iprt/path.h> 26 #include <iprt/message.h> 27 #include <iprt/cpp/path.h> 23 28 24 29 … … 29 34 30 35 31 int DHCPD::init(const Config *pConfig) 32 { 33 int rc; 34 35 if (m_pConfig != NULL) 36 return VERR_INVALID_STATE; 36 /** 37 * Initializes the DHCPD with the given config. 38 * 39 * @returns VBox status code. 40 * @param pConfig The configuration to use. 41 */ 42 int DHCPD::init(const Config *pConfig) RT_NOEXCEPT 43 { 44 Assert(pConfig); 45 AssertReturn(!m_pConfig, VERR_INVALID_STATE); 37 46 38 47 /** @todo r=bird: This must be configurable so main can read the database and … … 40 49 * figuring out the IP address of a VM.) */ 41 50 42 /* leases file name */ 43 m_strLeasesFileName = pConfig->getHome(); 44 m_strLeasesFileName += RTPATH_DELIMITER; 45 m_strLeasesFileName += pConfig->getBaseName(); 46 m_strLeasesFileName += "-Dhcpd.leases"; 47 48 rc = m_db.init(pConfig); 49 if (RT_FAILURE(rc)) 50 return rc; 51 52 loadLeases(); 53 54 m_pConfig = pConfig; 55 return VINF_SUCCESS; 56 } 57 58 59 void DHCPD::loadLeases() 60 { 61 m_db.loadLeases(m_strLeasesFileName); 62 } 63 64 65 void DHCPD::saveLeases() 51 /* leases filename */ 52 int rc = m_strLeasesFilename.assignNoThrow(pConfig->getHome()); 53 if (RT_SUCCESS(rc)) 54 rc = RTPathAppendCxx(m_strLeasesFilename, pConfig->getBaseName()); 55 if (RT_SUCCESS(rc)) 56 rc = m_strLeasesFilename.appendNoThrow("-Dhcpd.leases"); 57 if (RT_SUCCESS(rc)) 58 { 59 /* Load the lease database, ignoring most issues except being out of memory: */ 60 rc = m_db.init(pConfig); 61 if (RT_SUCCESS(rc)) 62 { 63 rc = i_loadLeases(); 64 if (rc != VERR_NO_MEMORY) 65 { 66 m_pConfig = pConfig; 67 rc = VINF_SUCCESS; 68 } 69 else 70 { 71 LogRel(("Ran out of memory loading leases from '%s'. Try rename or delete the file.\n", 72 m_strLeasesFilename.c_str())); 73 RTMsgError("Ran out of memory loading leases from '%s'. Try rename or delete the file.\n", 74 m_strLeasesFilename.c_str()); 75 } 76 } 77 } 78 return rc; 79 } 80 81 82 /** 83 * Load leases from m_strLeasesFilename. 84 */ 85 int DHCPD::i_loadLeases() RT_NOEXCEPT 86 { 87 return m_db.loadLeases(m_strLeasesFilename); 88 } 89 90 91 /** 92 * Save the current leases to m_strLeasesFilename, doing expiry first. 93 * 94 * This is called after m_db is updated during a client request, so the on disk 95 * database is always up-to-date. This means it doesn't matter if we're 96 * terminated with extreme prejudice, and it allows Main to look up IP addresses 97 * for VMs. 98 * 99 * @throws nothing 100 */ 101 void DHCPD::i_saveLeases() RT_NOEXCEPT 66 102 { 67 103 m_db.expire(); 68 m_db.writeLeases(m_strLeasesFileName); 69 } 70 71 72 DhcpServerMessage *DHCPD::process(DhcpClientMessage &req) 73 { 74 DhcpServerMessage *reply = NULL; 75 76 req.dump(); 77 104 m_db.writeLeases(m_strLeasesFilename); 105 } 106 107 108 /** 109 * Process a DHCP client message. 110 * 111 * Called by VBoxNetDhcpd::dhcp4Recv(). 112 * 113 * @returns Pointer to DHCP reply (caller deletes this). NULL if no reply 114 * warranted or we're out of memory. 115 * @param req The client message. 116 * @throws nothing 117 */ 118 DhcpServerMessage *DHCPD::process(DhcpClientMessage &req) RT_NOEXCEPT 119 { 120 /* 121 * Dump the package if release log level 3+1 are enable or if debug logging is 122 * enabled. We don't normally want to do this at the default log level, of course. 123 */ 124 if ((LogRelIs3Enabled() && LogRelIsEnabled()) || LogIsEnabled()) 125 req.dump(); 126 127 /* 128 * Fend off requests that are not for us. 129 */ 78 130 OptServerId sid(req); 79 131 if (sid.present() && sid.value().u != m_pConfig->getIPv4Address().u) 80 132 { 81 133 if (req.broadcasted() && req.messageType() == RTNET_DHCP_MT_REQUEST) 134 { 135 LogRel2(("Message is not for us, canceling any pending offer.\n")); 82 136 m_db.cancelOffer(req); 83 84 return NULL; 85 } 137 } 138 else 139 LogRel2(("Message is not for us.\n")); 140 return NULL; 141 } 142 143 /* 144 * Process it. 145 */ 146 DhcpServerMessage *reply = NULL; 86 147 87 148 switch (req.messageType()) … … 91 152 */ 92 153 case RTNET_DHCP_MT_DISCOVER: 93 reply = doDiscover(req); 154 try 155 { 156 reply = i_doDiscover(req); 157 } 158 catch (std::bad_alloc &) 159 { 160 LogRelFunc(("i_doDiscover threw bad_alloc\n")); 161 } 94 162 break; 95 163 96 164 case RTNET_DHCP_MT_REQUEST: 97 reply = doRequest(req); 165 try 166 { 167 reply = i_doRequest(req); 168 } 169 catch (std::bad_alloc &) 170 { 171 LogRelFunc(("i_doRequest threw bad_alloc\n")); 172 } 98 173 break; 99 174 100 175 case RTNET_DHCP_MT_INFORM: 101 reply = doInform(req); 176 try 177 { 178 reply = i_doInform(req); 179 } 180 catch (std::bad_alloc &) 181 { 182 LogRelFunc(("i_doInform threw bad_alloc\n")); 183 } 102 184 break; 103 185 … … 106 188 */ 107 189 case RTNET_DHCP_MT_DECLINE: 108 doDecline(req);190 i_doDecline(req); 109 191 break; 110 192 111 193 case RTNET_DHCP_MT_RELEASE: 112 doRelease(req);194 i_doRelease(req); 113 195 break; 114 196 … … 116 198 * Unexpected or unknown message types. 117 199 */ 118 case RTNET_DHCP_MT_OFFER: /* FALLTHROUGH */ 119 case RTNET_DHCP_MT_ACK: /* FALLTHROUGH */ 120 case RTNET_DHCP_MT_NAC: /* FALLTHROUGH */ 200 case RTNET_DHCP_MT_OFFER: 201 LogRel2(("Ignoring unexpected message of type RTNET_DHCP_MT_OFFER!\n")); 202 break; 203 case RTNET_DHCP_MT_ACK: 204 LogRel2(("Ignoring unexpected message of type RTNET_DHCP_MT_ACK!\n")); 205 break; 206 case RTNET_DHCP_MT_NAC: 207 LogRel2(("Ignoring unexpected message of type RTNET_DHCP_MT_NAC!\n")); 208 break; 121 209 default: 210 LogRel2(("Ignoring unexpected message of unknown type: %d (%#x)!\n", req.messageType(), req.messageType())); 122 211 break; 123 212 } … … 127 216 128 217 129 DhcpServerMessage *DHCPD::createMessage(int type, DhcpClientMessage &req) 218 /** 219 * Internal helper. 220 * 221 * @throws std::bad_alloc 222 */ 223 DhcpServerMessage *DHCPD::i_createMessage(int type, DhcpClientMessage &req) 130 224 { 131 225 return new DhcpServerMessage(req, type, m_pConfig->getIPv4Address()); … … 133 227 134 228 135 DhcpServerMessage *DHCPD::doDiscover(DhcpClientMessage &req) 136 { 137 /* 229 /** 230 * 4.3.1 DHCPDISCOVER message 231 * 232 * When a server receives a DHCPDISCOVER message from a client, the server 233 * chooses a network address for the requesting client. If no address is 234 * available, the server may choose to report the problem to the system 235 * administrator. If an address is available, the new address SHOULD be chosen 236 * as follows: 237 * - The client's current address as recorded in the client's current binding, 238 * ELSE 239 * - The client's previous address as recorded in the client's (now expired or 240 * released) binding, if that address is in the server's pool of available 241 * addresses and not already allocated, ELSE 242 * - The address requested in the 'Requested IP Address' option, if that 243 * address is valid and not already allocated, ELSE 244 * - A new address allocated from the server's pool of available addresses; 245 * the address is selected based on the subnet from which the message was 246 * received (if 'giaddr' is 0) or on the address of the relay agent that 247 * forwarded the message ('giaddr' when not 0). 248 * 249 * ... 250 * 251 * @throws std::bad_alloc 252 */ 253 DhcpServerMessage *DHCPD::i_doDiscover(DhcpClientMessage &req) 254 { 255 /** @todo 138 256 * XXX: TODO: Windows iSCSI initiator sends DHCPDISCOVER first and 139 257 * it has ciaddr filled. Shouldn't let it screw up the normal … … 148 266 return NULL; 149 267 150 151 268 std::unique_ptr<DhcpServerMessage> reply; 152 269 … … 154 271 if (!fRapidCommit) 155 272 { 156 reply.reset( createMessage(RTNET_DHCP_MT_OFFER, req));273 reply.reset(i_createMessage(RTNET_DHCP_MT_OFFER, req)); 157 274 158 275 if (b->state() < Binding::OFFERED) 159 276 b->setState(Binding::OFFERED); 160 277 161 /* use small lease time internally to quickly free unclaimed offers? */278 /** @todo use small lease time internally to quickly free unclaimed offers? */ 162 279 } 163 280 else 164 281 { 165 reply.reset( createMessage(RTNET_DHCP_MT_ACK, req));282 reply.reset(i_createMessage(RTNET_DHCP_MT_ACK, req)); 166 283 reply->addOption(OptRapidCommit(true)); 167 284 168 285 b->setState(Binding::ACKED); 169 saveLeases();286 i_saveLeases(); 170 287 } 171 288 … … 178 295 reply->addOptions(m_pConfig->getOptions(replyOptions, optlist, req.clientId())); 179 296 180 // reply->maybeUnicast(req); /* XXX: we reject ciaddr != 0 above */297 // reply->maybeUnicast(req); /** @todo XXX: we reject ciaddr != 0 above */ 181 298 return reply.release(); 182 299 } 183 300 184 301 185 DhcpServerMessage *DHCPD::doRequest(DhcpClientMessage &req) 302 /** 303 * 4.3.2 DHCPREQUEST message 304 * 305 * A DHCPREQUEST message may come from a client responding to a DHCPOFFER 306 * message from a server, from a client verifying a previously allocated IP 307 * address or from a client extending the lease on a network address. If the 308 * DHCPREQUEST message contains a 'server identifier' option, the message is in 309 * response to a DHCPOFFER message. Otherwise, the message is a request to 310 * verify or extend an existing lease. If the client uses a 'client identifier' 311 * in a DHCPREQUEST message, it MUST use that same 'client identifier' in all 312 * subsequent messages. If the client included a list of requested parameters in 313 * a DHCPDISCOVER message, it MUST include that list in all subsequent messages. 314 * 315 * ... 316 * 317 * @throws std::bad_alloc 318 */ 319 DhcpServerMessage *DHCPD::i_doRequest(DhcpClientMessage &req) 186 320 { 187 321 OptRequestedAddress reqAddr(req); … … 189 323 { 190 324 std::unique_ptr<DhcpServerMessage> nak ( 191 createMessage(RTNET_DHCP_MT_NAC, req)325 i_createMessage(RTNET_DHCP_MT_NAC, req) 192 326 ); 193 327 nak->addOption(OptMessage("Requested address does not match ciaddr")); … … 199 333 if (b == NULL) 200 334 { 201 return createMessage(RTNET_DHCP_MT_NAC, req); 202 } 203 204 205 std::unique_ptr<DhcpServerMessage> ack ( 206 createMessage(RTNET_DHCP_MT_ACK, req) 207 ); 335 return i_createMessage(RTNET_DHCP_MT_NAC, req); 336 } 337 338 339 std::unique_ptr<DhcpServerMessage> ack(i_createMessage(RTNET_DHCP_MT_ACK, req)); 208 340 209 341 b->setState(Binding::ACKED); 210 saveLeases();342 i_saveLeases(); 211 343 212 344 ack->setYiaddr(b->addr()); … … 224 356 225 357 226 /* 358 /** 227 359 * 4.3.5 DHCPINFORM message 228 360 * 229 * The server responds to a DHCPINFORM message by sending a DHCPACK 230 * message directly to the address given in the 'ciaddr' field of the 231 * DHCPINFORM message. The server MUST NOT send a lease expiration time 232 * to the client and SHOULD NOT fill in 'yiaddr'. The server includes 233 * other parameters in the DHCPACK message as defined in section 4.3.1. 234 */ 235 DhcpServerMessage *DHCPD::doInform(DhcpClientMessage &req) 361 * The server responds to a DHCPINFORM message by sending a DHCPACK message 362 * directly to the address given in the 'ciaddr' field of the DHCPINFORM 363 * message. The server MUST NOT send a lease expiration time to the client and 364 * SHOULD NOT fill in 'yiaddr'. The server includes other parameters in the 365 * DHCPACK message as defined in section 4.3.1. 366 * 367 * @throws std::bad_alloc 368 */ 369 DhcpServerMessage *DHCPD::i_doInform(DhcpClientMessage &req) 236 370 { 237 371 if (req.ciaddr().u == 0) … … 247 381 return NULL; 248 382 249 std::unique_ptr<DhcpServerMessage> ack ( 250 createMessage(RTNET_DHCP_MT_ACK, req) 251 ); 252 383 std::unique_ptr<DhcpServerMessage> ack(i_createMessage(RTNET_DHCP_MT_ACK, req)); 253 384 ack->addOptions(info); 254 255 385 ack->maybeUnicast(req); 256 386 return ack.release(); … … 258 388 259 389 260 /* 390 /** 261 391 * 4.3.3 DHCPDECLINE message 262 392 * 263 * If the server receives a DHCPDECLINE message, the client has 264 * discovered through some other means that the suggested network 265 * address is already in use. The server MUST mark the network address 266 * as not available and SHOULD notify the local system administrator of 267 * a possible configuration problem. 268 */ 269 DhcpServerMessage *DHCPD::doDecline(DhcpClientMessage &req) 393 * If the server receives a DHCPDECLINE message, the client has discovered 394 * through some other means that the suggested network address is already in 395 * use. The server MUST mark the network address as not available and SHOULD 396 * notify the local system administrator of a possible configuration problem. 397 * 398 * @throws nothing 399 */ 400 DhcpServerMessage *DHCPD::i_doDecline(const DhcpClientMessage &req) RT_NOEXCEPT 270 401 { 271 402 RT_NOREF(req); … … 274 405 275 406 276 /* 407 /** 277 408 * 4.3.4 DHCPRELEASE message 278 409 * 279 * Upon receipt of a DHCPRELEASE message, the server marks the network 280 * address as not allocated. The server SHOULD retain a record of the 281 * client's initialization parameters for possible reuse in response to 282 * subsequent requests from the client. 283 */ 284 DhcpServerMessage *DHCPD::doRelease(DhcpClientMessage &req) 285 { 286 if (req.ciaddr().u == 0) 287 return NULL; 288 289 bool released = m_db.releaseBinding(req); 290 if (released) 291 saveLeases(); 410 * Upon receipt of a DHCPRELEASE message, the server marks the network address 411 * as not allocated. The server SHOULD retain a record of the client's 412 * initialization parameters for possible reuse in response to subsequent 413 * requests from the client. 414 * 415 * @throws nothing 416 */ 417 DhcpServerMessage *DHCPD::i_doRelease(const DhcpClientMessage &req) RT_NOEXCEPT 418 { 419 if (req.ciaddr().u != 0) 420 { 421 bool fReleased = m_db.releaseBinding(req); 422 if (fReleased) 423 i_saveLeases(); 424 } 292 425 293 426 return NULL; -
trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.h
r79524 r79563 29 29 30 30 31 /** 32 * The core of the DHCP server. 33 * 34 * This class is feed DhcpClientMessages that VBoxNetDhcpd has picked up from 35 * the network. After processing a message it returns the appropriate response 36 * (if any) which VBoxNetDhcpd sends out. 37 */ 31 38 class DHCPD 32 39 { 33 const Config *m_pConfig; 34 RTCString m_strLeasesFileName; 35 Db m_db; 40 /** The DHCP configuration. */ 41 const Config *m_pConfig; 42 /** The lease database filename. */ 43 RTCString m_strLeasesFilename; 44 /** The lease database. */ 45 Db m_db; 36 46 37 47 public: 38 48 DHCPD(); 39 49 40 int init(const Config *) ;50 int init(const Config *) RT_NOEXCEPT; 41 51 42 DhcpServerMessage *process(const std::unique_ptr<DhcpClientMessage> &req) 52 DhcpServerMessage *process(const std::unique_ptr<DhcpClientMessage> &req) RT_NOEXCEPT 43 53 { 44 if (req.get() == NULL) 45 return NULL; 46 47 return process(*req.get()); 54 if (req.get() != NULL) 55 return process(*req.get()); 56 return NULL; 48 57 } 49 58 50 DhcpServerMessage *process(DhcpClientMessage &req) ;59 DhcpServerMessage *process(DhcpClientMessage &req) RT_NOEXCEPT; 51 60 52 61 private: 53 DhcpServerMessage *doDiscover(DhcpClientMessage &req); 54 DhcpServerMessage *doRequest(DhcpClientMessage &req); 55 DhcpServerMessage *doInform(DhcpClientMessage &req); 62 /** @name DHCP message processing methods 63 * @{ */ 64 DhcpServerMessage *i_doDiscover(DhcpClientMessage &req); 65 DhcpServerMessage *i_doRequest(DhcpClientMessage &req); 66 DhcpServerMessage *i_doInform(DhcpClientMessage &req); 67 DhcpServerMessage *i_doDecline(const DhcpClientMessage &req) RT_NOEXCEPT; 68 DhcpServerMessage *i_doRelease(const DhcpClientMessage &req) RT_NOEXCEPT; 56 69 57 DhcpServerMessage * doDecline(DhcpClientMessage &req);58 DhcpServerMessage *doRelease(DhcpClientMessage &req);70 DhcpServerMessage *i_createMessage(int type, DhcpClientMessage &req); 71 /** @} */ 59 72 60 DhcpServerMessage *createMessage(int type, DhcpClientMessage &req); 61 62 void loadLeases(); 63 void saveLeases(); 73 /** @name Lease database handling 74 * @{ */ 75 int i_loadLeases() RT_NOEXCEPT; 76 void i_saveLeases() RT_NOEXCEPT; 77 /** @} */ 64 78 }; 65 79 -
trunk/src/VBox/NetworkServices/Dhcpd/Db.cpp
r79530 r79563 36 36 * Registers the ClientId format type callback ("%R[binding]"). 37 37 */ 38 void Binding::registerFormat() 38 void Binding::registerFormat() RT_NOEXCEPT 39 39 { 40 40 if (!g_fFormatRegistered) … … 87 87 } 88 88 89 const char *Binding::stateName() const 89 const char *Binding::stateName() const RT_NOEXCEPT 90 90 { 91 91 switch (m_state) … … 108 108 109 109 110 Binding &Binding::setState(const char *pszStateName) 110 Binding &Binding::setState(const char *pszStateName) RT_NOEXCEPT 111 111 { 112 112 if (strcmp(pszStateName, "free") == 0) … … 137 137 * @param tsDeadline The expiry deadline to use. 138 138 */ 139 bool Binding::expire(Timestamp tsDeadline) 139 bool Binding::expire(Timestamp tsDeadline) RT_NOEXCEPT 140 140 { 141 141 if (m_state <= Binding::EXPIRED) … … 232 232 /* 233 233 * Decode from "de:ad:be:ef". 234 * XXX: RTStrConvertHexBytes() doesn't grok colons235 234 */ 236 size_t cbBytes = strId.length() / 2; 237 uint8_t *pBytes = new uint8_t[cbBytes]; 238 rc = RTStrConvertHexBytes(strId.c_str(), pBytes, cbBytes, 0); 235 /** @todo RTStrConvertHexBytes() doesn't grok colons */ 236 size_t cbBytes = strId.length() / 2; 237 uint8_t *pbBytes = new uint8_t[cbBytes]; 238 rc = RTStrConvertHexBytes(strId.c_str(), pbBytes, cbBytes, 0); 239 239 if (RT_SUCCESS(rc)) 240 240 { 241 std::vector<uint8_t> rawopt(pBytes, pBytes + cbBytes); 242 id = OptClientId(rawopt); 243 } 244 delete[] pBytes; 241 try 242 { 243 std::vector<uint8_t> rawopt(pbBytes, pbBytes + cbBytes); 244 id = OptClientId(rawopt); 245 } 246 catch (std::bad_alloc &) 247 { 248 delete[] pbBytes; 249 throw; 250 } 251 } 252 delete[] pbBytes; 245 253 } 246 254 … … 305 313 } 306 314 else 307 { /* XXX: old code wrote timestamps instead of absolute time. */315 { /** @todo XXX: old code wrote timestamps instead of absolute time. */ 308 316 /* pretend that lease has just ended */ 309 317 Timestamp fakeIssued = Timestamp::now(); … … 341 349 m_pConfig = pConfig; 342 350 343 m_pool.init(pConfig->getIPv4PoolFirst(), 344 pConfig->getIPv4PoolLast()); 345 346 return VINF_SUCCESS; 351 return m_pool.init(pConfig->getIPv4PoolFirst(), pConfig->getIPv4PoolLast()); 347 352 } 348 353 … … 351 356 * Expire old binding (leases). 352 357 */ 353 void Db::expire() 358 void Db::expire() RT_NOEXCEPT 354 359 { 355 360 const Timestamp now = Timestamp::now(); … … 609 614 * @param pNewBinding The new binding to add. 610 615 */ 611 int Db::i_addBinding(Binding *pNewBinding) 616 int Db::i_addBinding(Binding *pNewBinding) RT_NOEXCEPT 612 617 { 613 618 /* … … 662 667 * @param req The DHCP request. 663 668 */ 664 void Db::cancelOffer(const DhcpClientMessage &req) 669 void Db::cancelOffer(const DhcpClientMessage &req) RT_NOEXCEPT 665 670 { 666 671 const OptRequestedAddress reqAddr(req); … … 697 702 * @param req The DHCP request. 698 703 * @returns true if found and released, otherwise false. 699 */ 700 bool Db::releaseBinding(const DhcpClientMessage &req) 704 * @throws nothing 705 */ 706 bool Db::releaseBinding(const DhcpClientMessage &req) RT_NOEXCEPT 701 707 { 702 708 const RTNETADDRIPV4 addr = req.ciaddr(); … … 726 732 * @param strFilename The file to write it to. 727 733 */ 728 int Db::writeLeases(const RTCString &strFilename) const 734 int Db::writeLeases(const RTCString &strFilename) const RT_NOEXCEPT 729 735 { 730 736 LogDHCP(("writing leases to %s\n", strFilename.c_str())); 737 738 /** @todo This could easily be written directly to the file w/o going thru 739 * a xml::Document, xml::XmlFileWriter, hammering the heap and being 740 * required to catch a lot of different exceptions at various points. 741 * (RTStrmOpen, bunch of RTStrmPrintf using \%RMas and \%RMes., 742 * RTStrmClose closely followed by a couple of renames.) 743 */ 731 744 732 745 /* … … 789 802 * @returns IPRT status code. 790 803 * @param strFilename The file to load it from. 791 */ 792 int Db::loadLeases(const RTCString &strFilename) 804 * @throws nothing 805 */ 806 int Db::loadLeases(const RTCString &strFilename) RT_NOEXCEPT 793 807 { 794 808 LogDHCP(("loading leases from %s\n", strFilename.c_str())); … … 863 877 * @return IPRT status code. 864 878 */ 865 int Db::i_loadLease(const xml::ElementNode *pElmLease) 879 int Db::i_loadLease(const xml::ElementNode *pElmLease) RT_NOEXCEPT 866 880 { 867 881 Binding *pBinding = NULL; … … 878 892 bool fExpired = pBinding->expire(); 879 893 if (!fExpired) 880 LogDHCP(("> LOAD: lease %R[binding]\n", pBinding));894 LogDHCP(("> LOAD: lease %R[binding]\n", pBinding)); 881 895 else 882 896 LogDHCP(("> LOAD: EXPIRED lease %R[binding]\n", pBinding)); -
trunk/src/VBox/NetworkServices/Dhcpd/Db.h
r79531 r79563 38 38 39 39 /** 40 * Address binding in the lease database. 40 * An address binding in the lease database. 41 * 42 * This is how an allocated IPv4 address is mananged. 41 43 */ 42 44 class Binding … … 69 71 /** @name Attribute accessors 70 72 * @{ */ 71 RTNETADDRIPV4 addr() const { return m_addr; }73 RTNETADDRIPV4 addr() const RT_NOEXCEPT { return m_addr; } 72 74 73 const ClientId &id() const { return m_id; }75 const ClientId &id() const RT_NOEXCEPT { return m_id; } 74 76 75 uint32_t leaseTime() const { return m_secLease; }76 Timestamp issued() const { return m_issued; }77 uint32_t leaseTime() const RT_NOEXCEPT { return m_secLease; } 78 Timestamp issued() const RT_NOEXCEPT { return m_issued; } 77 79 78 State state() const { return m_state; }79 const char *stateName() const ;80 Binding &setState(const char *pszStateName) ;81 Binding &setState(State stateParam) 80 State state() const RT_NOEXCEPT { return m_state; } 81 const char *stateName() const RT_NOEXCEPT; 82 Binding &setState(const char *pszStateName) RT_NOEXCEPT; 83 Binding &setState(State stateParam) RT_NOEXCEPT 82 84 { 83 85 m_state = stateParam; … … 87 89 88 90 89 Binding &setLeaseTime(uint32_t secLease) 91 Binding &setLeaseTime(uint32_t secLease) RT_NOEXCEPT 90 92 { 91 93 m_issued = Timestamp::now(); … … 95 97 96 98 /** Reassigns the binding to the given client. */ 97 Binding &giveTo(const ClientId &a_id) 99 Binding &giveTo(const ClientId &a_id) RT_NOEXCEPT 98 100 { 99 101 m_id = a_id; … … 108 110 } 109 111 110 bool expire(Timestamp tsDeadline); 111 bool expire() { return expire(Timestamp::now()); } 112 bool expire(Timestamp tsDeadline) RT_NOEXCEPT; 113 bool expire() RT_NOEXCEPT 114 { 115 return expire(Timestamp::now()); 116 } 112 117 113 118 /** @name Serialization … … 119 124 /** @name String formatting of %R[binding]. 120 125 * @{ */ 121 static void registerFormat() ;126 static void registerFormat() RT_NOEXCEPT; 122 127 private: 123 128 static DECLCALLBACK(size_t) rtStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, const char *pszType, … … 125 130 static bool g_fFormatRegistered; 126 131 /** @} */ 132 133 Binding &operator=(const Binding &); /**< Shuts up warning C4626 (incorrect warning?). */ 127 134 }; 128 135 … … 130 137 /** 131 138 * The lease database. 139 * 140 * There is currently just one instance of this class in a running DHCP server 141 * residing in Dhcpd::m_db. It covers one single range of IPv4 addresses, which 142 * currently unbound addressed are managed by m_pool. The allocated addresses 143 * are kept in the m_bindings list. Once an address has been allocated, it will 144 * stay in the m_bindings list even after released or expired. 132 145 */ 133 146 class Db … … 151 164 152 165 /** Check if @a addr belonges to this lease database. */ 153 bool addressBelongs(RTNETADDRIPV4 addr) const { return m_pool.contains(addr); }166 bool addressBelongs(RTNETADDRIPV4 addr) const RT_NOEXCEPT { return m_pool.contains(addr); } 154 167 155 168 Binding *allocateBinding(const DhcpClientMessage &req); 156 bool releaseBinding(const DhcpClientMessage &req) ;169 bool releaseBinding(const DhcpClientMessage &req) RT_NOEXCEPT; 157 170 158 void cancelOffer(const DhcpClientMessage &req) ;171 void cancelOffer(const DhcpClientMessage &req) RT_NOEXCEPT; 159 172 160 void expire() ;173 void expire() RT_NOEXCEPT; 161 174 162 175 /** @name Database serialization methods 163 176 * @{ */ 164 int loadLeases(const RTCString &strFilename) ;177 int loadLeases(const RTCString &strFilename) RT_NOEXCEPT; 165 178 private: 166 int i_loadLease(const xml::ElementNode *pElmLease) ;179 int i_loadLease(const xml::ElementNode *pElmLease) RT_NOEXCEPT; 167 180 public: 168 int writeLeases(const RTCString &strFilename) const ;181 int writeLeases(const RTCString &strFilename) const RT_NOEXCEPT; 169 182 /** @} */ 170 183 … … 176 189 177 190 /* add binding e.g. from the leases file */ 178 int i_addBinding(Binding *pNewBinding) ;191 int i_addBinding(Binding *pNewBinding) RT_NOEXCEPT; 179 192 }; 180 193 -
trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.cpp
r79524 r79563 289 289 290 290 bool fHeader = true; 291 for (rawopts_t::const_iterator it = m_rawopts.begin(); 292 it != m_rawopts.end(); ++it) 291 for (rawopts_t::const_iterator it = m_rawopts.begin(); it != m_rawopts.end(); ++it) 293 292 { 294 293 const uint8_t optcode = (*it).first; -
trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.h
r79524 r79563 69 69 void setGiaddr(RTNETADDRIPV4 addr) { m_giaddr = addr; } 70 70 71 uint8_t messageType() const 71 uint8_t messageType() const RT_NOEXCEPT 72 72 { 73 73 Assert(m_optMessageType.present()); -
trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.h
r79553 r79563 55 55 56 56 public: 57 uint8_t optcode() const { return m_OptCode; }58 bool present() const{ return m_fPresent; }57 uint8_t optcode() const RT_NOEXCEPT { return m_OptCode; } 58 bool present() const RT_NOEXCEPT { return m_fPresent; } 59 59 60 60 public: -
trunk/src/VBox/NetworkServices/Dhcpd/IPv4Pool.cpp
r79531 r79563 26 26 27 27 28 int IPv4Pool::init(const IPv4Range &aRange) 28 int IPv4Pool::init(const IPv4Range &aRange) RT_NOEXCEPT 29 29 { 30 30 AssertReturn(aRange.isValid(), VERR_INVALID_PARAMETER); 31 31 32 32 m_range = aRange; 33 m_pool.insert(m_range); 33 try 34 { 35 m_pool.insert(m_range); 36 } 37 catch (std::bad_alloc &) 38 { 39 return VERR_NO_MEMORY; 40 } 34 41 return VINF_SUCCESS; 35 42 } 36 43 37 44 38 int IPv4Pool::init(RTNETADDRIPV4 aFirstAddr, RTNETADDRIPV4 aLastAddr) 45 int IPv4Pool::init(RTNETADDRIPV4 aFirstAddr, RTNETADDRIPV4 aLastAddr) RT_NOEXCEPT 39 46 { 40 47 return init(IPv4Range(aFirstAddr, aLastAddr)); … … 48 55 * @param a_Range The range to insert. 49 56 */ 50 int IPv4Pool::i_insert(const IPv4Range &a_Range) 57 int IPv4Pool::i_insert(const IPv4Range &a_Range) RT_NOEXCEPT 51 58 { 52 59 /* … … 86 93 * No overlaps, insert it. 87 94 */ 88 m_pool.insert(itHint, a_Range); 95 try 96 { 97 m_pool.insert(itHint, a_Range); 98 } 99 catch (std::bad_alloc &) 100 { 101 return VERR_NO_MEMORY; 102 } 89 103 return VINF_SUCCESS; 90 104 } … … 114 128 trimmed.FirstAddr += 1; 115 129 m_pool.erase(itBeg); 116 m_pool.insert(trimmed); 130 try 131 { 132 m_pool.insert(trimmed); 133 } 134 catch (std::bad_alloc &) 135 { 136 /** @todo r=bird: Theortically the insert could fail with a bad_alloc and we'd 137 * drop a range of IP address. It would be nice if we could safely modify itBit 138 * without having to re-insert it. The author of this code (not bird) didn't 139 * seem to think this safe? 140 * 141 * If we want to play safe and all that, just use a AVLRU32TREE (or AVLRU64TREE 142 * if lazy) AVL tree from IPRT. Since we know exactly how it's implemented and 143 * works, there will be no uncertanties like this when using it (both here 144 * and in the i_insert validation logic). */ 145 LogRelFunc(("Caught bad_alloc! We're truely buggered now!\n")); 146 } 117 147 } 118 148 } -
trunk/src/VBox/NetworkServices/Dhcpd/IPv4Pool.h
r79531 r79563 40 40 IPV4HADDR LastAddr; /**< Higest address (inclusive). */ 41 41 42 IPv4Range() 42 IPv4Range() RT_NOEXCEPT 43 43 : FirstAddr(0), LastAddr(0) 44 44 {} 45 45 46 explicit IPv4Range(IPV4HADDR aSingleAddr) 46 explicit IPv4Range(IPV4HADDR aSingleAddr) RT_NOEXCEPT 47 47 : FirstAddr(aSingleAddr), LastAddr(aSingleAddr) 48 48 {} 49 49 50 IPv4Range(IPV4HADDR aFirstAddr, IPV4HADDR aLastAddr) 50 IPv4Range(IPV4HADDR aFirstAddr, IPV4HADDR aLastAddr) RT_NOEXCEPT 51 51 : FirstAddr(aFirstAddr), LastAddr(aLastAddr) 52 52 {} 53 53 54 explicit IPv4Range(RTNETADDRIPV4 aSingleAddr) 54 explicit IPv4Range(RTNETADDRIPV4 aSingleAddr) RT_NOEXCEPT 55 55 : FirstAddr(RT_N2H_U32(aSingleAddr.u)), LastAddr(RT_N2H_U32(aSingleAddr.u)) 56 56 {} 57 57 58 IPv4Range(RTNETADDRIPV4 aFirstAddr, RTNETADDRIPV4 aLastAddr) 58 IPv4Range(RTNETADDRIPV4 aFirstAddr, RTNETADDRIPV4 aLastAddr) RT_NOEXCEPT 59 59 : FirstAddr(RT_N2H_U32(aFirstAddr.u)), LastAddr(RT_N2H_U32(aLastAddr.u)) 60 60 {} 61 61 62 bool isValid() const 62 bool isValid() const RT_NOEXCEPT 63 63 { 64 64 return FirstAddr <= LastAddr; 65 65 } 66 66 67 bool contains(IPV4HADDR addr) const 67 bool contains(IPV4HADDR addr) const RT_NOEXCEPT 68 68 { 69 69 return FirstAddr <= addr && addr <= LastAddr; 70 70 } 71 71 72 bool contains(RTNETADDRIPV4 addr) const 72 bool contains(RTNETADDRIPV4 addr) const RT_NOEXCEPT 73 73 { 74 74 return contains(RT_N2H_U32(addr.u)); … … 76 76 77 77 /** Checks if this range includes the @a a_rRange. */ 78 bool contains(const IPv4Range &a_rRange) const 78 bool contains(const IPv4Range &a_rRange) const RT_NOEXCEPT 79 79 { 80 80 return a_rRange.isValid() … … 85 85 86 86 87 inline bool operator==(const IPv4Range &l, const IPv4Range &r) 87 inline bool operator==(const IPv4Range &l, const IPv4Range &r) RT_NOEXCEPT 88 88 { 89 89 return l.FirstAddr == r.FirstAddr && l.LastAddr == r.LastAddr; … … 91 91 92 92 93 inline bool operator<(const IPv4Range &l, const IPv4Range &r) 93 inline bool operator<(const IPv4Range &l, const IPv4Range &r) RT_NOEXCEPT 94 94 { 95 95 return l.LastAddr < r.FirstAddr; … … 118 118 {} 119 119 120 int init(const IPv4Range &aRange) ;121 int init(RTNETADDRIPV4 aFirstAddr, RTNETADDRIPV4 aLastAddr) ;120 int init(const IPv4Range &aRange) RT_NOEXCEPT; 121 int init(RTNETADDRIPV4 aFirstAddr, RTNETADDRIPV4 aLastAddr) RT_NOEXCEPT; 122 122 123 123 RTNETADDRIPV4 allocate(); … … 127 127 * Checks if the pool range includes @a addr (allocation status not considered). 128 128 */ 129 bool contains(RTNETADDRIPV4 addr) const 129 bool contains(RTNETADDRIPV4 addr) const RT_NOEXCEPT 130 130 { 131 131 return m_range.contains(addr); … … 133 133 134 134 private: 135 int i_insert(const IPv4Range &range) ;135 int i_insert(const IPv4Range &range) RT_NOEXCEPT; 136 136 #if 0 137 int i_insert(IPV4HADDR single) 137 int i_insert(IPV4HADDR single) RT_NOEXCEPT { return i_insert(IPv4Range(single)); } 138 138 #endif 139 int i_insert(IPV4HADDR first, IPV4HADDR last) 140 int i_insert(RTNETADDRIPV4 single) 141 int i_insert(RTNETADDRIPV4 first, RTNETADDRIPV4 last) 139 int i_insert(IPV4HADDR first, IPV4HADDR last) RT_NOEXCEPT { return i_insert(IPv4Range(first, last)); } 140 int i_insert(RTNETADDRIPV4 single) RT_NOEXCEPT { return i_insert(IPv4Range(single)); } 141 int i_insert(RTNETADDRIPV4 first, RTNETADDRIPV4 last) RT_NOEXCEPT { return i_insert(IPv4Range(first, last)); } 142 142 }; 143 143 -
trunk/src/VBox/NetworkServices/Dhcpd/Timestamp.cpp
r79526 r79563 24 24 25 25 26 size_t Timestamp::strFormatHelper(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const 26 size_t Timestamp::strFormatHelper(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const RT_NOEXCEPT 27 27 { 28 28 RTTIMESPEC TimeSpec; -
trunk/src/VBox/NetworkServices/Dhcpd/Timestamp.h
r79530 r79563 39 39 40 40 public: 41 Timestamp() 41 Timestamp() RT_NOEXCEPT 42 42 { 43 43 RTTimeSpecSetNano(&m_TimeSpec, 0); 44 44 } 45 45 46 Timestamp(PCRTTIMESPEC a_pTimeSpec) 46 Timestamp(PCRTTIMESPEC a_pTimeSpec) RT_NOEXCEPT 47 47 { 48 48 m_TimeSpec = *a_pTimeSpec; … … 50 50 51 51 /** Get a timestamp initialized to current time. */ 52 static Timestamp now() 52 static Timestamp now() RT_NOEXCEPT 53 53 { 54 54 RTTIMESPEC Tmp; … … 57 57 58 58 /** Get a timestamp with the given value in seconds since unix epoch. */ 59 static Timestamp absSeconds(int64_t secTimestamp) 59 static Timestamp absSeconds(int64_t secTimestamp) RT_NOEXCEPT 60 60 { 61 61 RTTIMESPEC Tmp; … … 63 63 } 64 64 65 Timestamp &addSeconds(int64_t cSecs) 65 Timestamp &addSeconds(int64_t cSecs) RT_NOEXCEPT 66 66 { 67 67 RTTimeSpecAddSeconds(&m_TimeSpec, cSecs); … … 69 69 } 70 70 71 Timestamp &subSeconds(int64_t cSecs) 71 Timestamp &subSeconds(int64_t cSecs) RT_NOEXCEPT 72 72 { 73 73 RTTimeSpecSubSeconds(&m_TimeSpec, cSecs); … … 75 75 } 76 76 77 RTTIMESPEC *getAbsTimeSpec(RTTIMESPEC *pTime) const 77 RTTIMESPEC *getAbsTimeSpec(RTTIMESPEC *pTime) const RT_NOEXCEPT 78 78 { 79 79 *pTime = m_TimeSpec; … … 81 81 } 82 82 83 int64_t getAbsSeconds() const 83 int64_t getAbsSeconds() const RT_NOEXCEPT 84 84 { 85 85 return RTTimeSpecGetSeconds(&m_TimeSpec); … … 87 87 88 88 /** Only for log formatting. */ 89 size_t strFormatHelper(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const ;89 size_t strFormatHelper(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const RT_NOEXCEPT; 90 90 91 int compare(const Timestamp &a_rRight) const 91 int compare(const Timestamp &a_rRight) const RT_NOEXCEPT 92 92 { 93 93 return RTTimeSpecCompare(&m_TimeSpec, &a_rRight.m_TimeSpec); 94 94 } 95 95 96 friend bool operator<( const Timestamp &, const Timestamp &) ;97 friend bool operator>( const Timestamp &, const Timestamp &) ;98 friend bool operator==(const Timestamp &, const Timestamp &) ;99 friend bool operator!=(const Timestamp &, const Timestamp &) ;100 friend bool operator<=(const Timestamp &, const Timestamp &) ;101 friend bool operator>=(const Timestamp &, const Timestamp &) ;96 friend bool operator<( const Timestamp &, const Timestamp &) RT_NOEXCEPT; 97 friend bool operator>( const Timestamp &, const Timestamp &) RT_NOEXCEPT; 98 friend bool operator==(const Timestamp &, const Timestamp &) RT_NOEXCEPT; 99 friend bool operator!=(const Timestamp &, const Timestamp &) RT_NOEXCEPT; 100 friend bool operator<=(const Timestamp &, const Timestamp &) RT_NOEXCEPT; 101 friend bool operator>=(const Timestamp &, const Timestamp &) RT_NOEXCEPT; 102 102 }; 103 103 104 104 105 inline bool operator<( const Timestamp &l, const Timestamp &r) { return l.compare(r) < 0; }106 inline bool operator>( const Timestamp &l, const Timestamp &r) { return l.compare(r) > 0; }107 inline bool operator==(const Timestamp &l, const Timestamp &r) { return l.compare(r) == 0; }108 inline bool operator!=(const Timestamp &l, const Timestamp &r) { return l.compare(r) != 0; }109 inline bool operator<=(const Timestamp &l, const Timestamp &r) { return l.compare(r) <= 0; }110 inline bool operator>=(const Timestamp &l, const Timestamp &r) { return l.compare(r) >= 0; }105 inline bool operator<( const Timestamp &l, const Timestamp &r) RT_NOEXCEPT { return l.compare(r) < 0; } 106 inline bool operator>( const Timestamp &l, const Timestamp &r) RT_NOEXCEPT { return l.compare(r) > 0; } 107 inline bool operator==(const Timestamp &l, const Timestamp &r) RT_NOEXCEPT { return l.compare(r) == 0; } 108 inline bool operator!=(const Timestamp &l, const Timestamp &r) RT_NOEXCEPT { return l.compare(r) != 0; } 109 inline bool operator<=(const Timestamp &l, const Timestamp &r) RT_NOEXCEPT { return l.compare(r) <= 0; } 110 inline bool operator>=(const Timestamp &l, const Timestamp &r) RT_NOEXCEPT { return l.compare(r) >= 0; } 111 111 112 112 #endif /* !VBOX_INCLUDED_SRC_Dhcpd_Timestamp_h */ -
trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.cpp
r79524 r79563 372 372 { 373 373 int rc = ifWait(); 374 375 if (RT_UNLIKELY(rc == VERR_INTERRUPTED)) 376 continue; 377 374 if ( rc != VERR_INTERRUPTED 378 375 #if 0 /* we wait indefinitely */ 379 if (rc == VERR_TIMEOUT) 380 ...; 376 && rc != VERR_TIMEOUT 381 377 #endif 382 383 if (RT_FAILURE(rc)) 378 ) 379 ifProcessInput(); 380 else 381 { 382 LogRel(("ifWait failed: %Rrc\n", rc)); 383 RTMsgError("ifWait failed: %Rrc", rc); 384 384 return; 385 386 ifProcessInput(); 385 } 387 386 } 388 387 } … … 613 612 int VBoxNetDhcpd::main(int argc, char **argv) 614 613 { 615 int rc; 616 614 /* 615 * Register string format types. 616 */ 617 617 ClientId::registerFormat(); 618 619 /* XXX: We no longer need hardcoded and compat methods. We should remove them soon. */ 618 Binding::registerFormat(); 619 620 /* 621 * Parse the command line into a configuration object. 622 */ 623 /** @todo XXX: We no longer need hardcoded and compat methods. We should remove them soon. */ 620 624 if (argc < 2) 621 625 m_Config = Config::hardcoded(); … … 624 628 m_Config = Config::create(argc, argv); 625 629 else 626 m_Config = Config::compat(argc, argv); 627 630 { 631 try 632 { 633 m_Config = Config::compat(argc, argv); 634 } 635 catch (std::bad_alloc &) 636 { 637 m_Config = NULL; 638 RTMsgError("Out of memory"); 639 return VERR_NO_MEMORY; 640 } 641 } 628 642 if (m_Config == NULL) 629 643 return VERR_GENERAL_FAILURE; 630 644 631 rc = m_server.init(m_Config); 632 633 /* connect to the intnet */ 634 rc = ifInit(m_Config->getNetwork(), 635 m_Config->getTrunk(), 636 m_Config->getTrunkType()); 637 if (RT_FAILURE(rc)) 638 return rc; 639 640 /* setup lwip */ 641 rc = vboxLwipCoreInitialize(lwipInitCB, this); 642 if (RT_FAILURE(rc)) 643 return rc; 644 645 ifPump(); 646 return VINF_SUCCESS; 645 /* 646 * Initialize the server. 647 */ 648 int rc = m_server.init(m_Config); 649 if (RT_SUCCESS(rc)) 650 { 651 /* connect to the intnet */ 652 rc = ifInit(m_Config->getNetwork(), m_Config->getTrunk(), m_Config->getTrunkType()); 653 if (RT_SUCCESS(rc)) 654 { 655 /* setup lwip */ 656 rc = vboxLwipCoreInitialize(lwipInitCB, this); 657 if (RT_SUCCESS(rc)) 658 { 659 /* 660 * Pump packets more or less for ever. 661 */ 662 ifPump(); 663 } 664 else 665 RTMsgError("Terminating - vboxLwipCoreInitialize failed: %Rrc", rc); 666 } 667 else 668 RTMsgError("Terminating - ifInit failed: %Rrc", rc); 669 } 670 else 671 RTMsgError("Terminating - Dhcpd::init failed: %Rrc", rc); 672 return rc; 647 673 } 648 674 … … 707 733 ip_addr_t *addr, u16_t port) 708 734 { 709 err_t error;710 int rc;711 712 735 RT_NOREF(pcb, addr, port); 713 736 … … 735 758 736 759 octets_t data; 737 rc = msgOut->encode(data);760 int rc = msgOut->encode(data); 738 761 if (RT_FAILURE(rc)) 739 762 return; … … 743 766 return; 744 767 745 err or = pbuf_take(q.get(), &data.front(), (u16_t)data.size());768 err_t error = pbuf_take(q.get(), &data.front(), (u16_t)data.size()); 746 769 if (error != ERR_OK) 747 770 return;
Note:
See TracChangeset
for help on using the changeset viewer.