Changeset 79524 in vbox for trunk/src/VBox
- Timestamp:
- Jul 4, 2019 10:14:02 AM (6 years ago)
- Location:
- trunk/src/VBox/NetworkServices/Dhcpd
- Files:
-
- 14 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/Dhcpd/ClientId.cpp
r76553 r79524 16 16 */ 17 17 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 18 22 #include <algorithm> 19 20 23 #include "ClientId.h" 21 24 22 25 26 /********************************************************************************************************************************* 27 * Global Variables * 28 *********************************************************************************************************************************/ 29 /** Indiciates wherther ClientId::rtStrFormat was already registered. */ 23 30 bool ClientId::g_fFormatRegistered = false; 24 31 25 32 33 /** 34 * Registers the ClientId format type callback ("%R[id]"). 35 */ 26 36 void ClientId::registerFormat() 27 37 { 28 if (g_fFormatRegistered) 29 return; 30 31 int rc = RTStrFormatTypeRegister("id", rtStrFormat, NULL); 32 AssertRC(rc); 33 34 g_fFormatRegistered = true; 38 if (!g_fFormatRegistered) 39 { 40 int rc = RTStrFormatTypeRegister("id", rtStrFormat, NULL); 41 AssertRC(rc); 42 g_fFormatRegistered = RT_SUCCESS(rc); 43 } 35 44 } 36 45 37 46 47 /** 48 * @callback_method_impl{FNRTSTRFORMATTYPE, Formats ClientId via "%R[id]". } 49 */ 38 50 DECLCALLBACK(size_t) 39 51 ClientId::rtStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, 40 const char *pszType, void const *pvValue,41 int cchWidth, int cchPrecision, unsigned fFlags,42 void *pvUser)52 const char *pszType, void const *pvValue, 53 int cchWidth, int cchPrecision, unsigned fFlags, 54 void *pvUser) 43 55 { 44 const ClientId *id = static_cast<const ClientId *>(pvValue); 56 RT_NOREF(pszType, cchWidth, cchPrecision, fFlags, pvUser); 57 Assert(strcmp(pszType, "id") == 0); 58 59 const ClientId *pThis = static_cast<const ClientId *>(pvValue); 60 if (pThis == NULL) 61 return pfnOutput(pvArgOutput, RT_STR_TUPLE("<NULL>")); 62 45 63 size_t cb = 0; 64 if (pThis->m_id.present()) 65 { 66 cb += pfnOutput(pvArgOutput, RT_STR_TUPLE("[")); 46 67 47 AssertReturn(strcmp(pszType, "id") == 0, 0); 48 RT_NOREF(pszType); 68 const OptClientId::value_t &idopt = pThis->m_id.value(); 69 for (size_t i = 0; i < idopt.size(); ++i) 70 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%s%02x", (i == 0 ? "" : ":"), idopt[i]); 49 71 50 RT_NOREF(cchWidth, cchPrecision, fFlags); 51 RT_NOREF(pvUser); 52 53 if (id == NULL) 54 { 55 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 56 "<NULL>"); 72 cb += pfnOutput(pvArgOutput, RT_STR_TUPLE("] (")); 57 73 } 58 74 59 if (id->m_id.present()) 60 { 61 const OptClientId::value_t &idopt = id->m_id.value(); 75 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%RTmac", &pThis->m_mac); 62 76 63 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,64 "[");77 if (pThis->m_id.present()) 78 cb += pfnOutput(pvArgOutput, RT_STR_TUPLE(")")); 65 79 66 for (size_t i = 0; i < idopt.size(); ++i) 67 { 68 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 69 "%s%02x", (i == 0 ? "" : ":"), idopt[i]); 70 } 71 72 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 73 "] ("); 74 } 75 76 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 77 "%RTmac", &id->m_mac); 78 79 if (id->m_id.present()) 80 { 81 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 82 ")"); 83 } 84 85 return 0; 80 return cb; 86 81 } 87 82 … … 110 105 if (r.m_id.present()) 111 106 return l.m_id.value() < r.m_id.value(); 112 else 113 return false; /* the one with id comes last */ 107 return false; /* the one with id comes last */ 114 108 } 115 109 else … … 117 111 if (r.m_id.present()) 118 112 return true; /* the one with id comes last */ 119 else 120 return l.m_mac < r.m_mac; 113 return l.m_mac < r.m_mac; 121 114 } 122 115 } 116 -
trunk/src/VBox/NetworkServices/Dhcpd/ClientId.h
r76576 r79524 22 22 #endif 23 23 24 #include "D efs.h"24 #include "DhcpdInternal.h" 25 25 #include <iprt/net.h> 26 26 #include "DhcpOptions.h" 27 27 28 /* 29 * Client is identified by either the Client ID option it sends or its30 * chaddr,i.e. MAC address.28 /** 29 * A client is identified by either the Client ID option it sends or its chaddr, 30 * i.e. MAC address. 31 31 */ 32 32 class ClientId 33 33 { 34 RTMAC m_mac; 34 /** The mac address of the client. */ 35 RTMAC m_mac; 36 /** The client ID. */ 35 37 OptClientId m_id; 36 38 37 39 public: 38 40 ClientId() 39 : m_mac(), m_id() {} 40 ClientId(const RTMAC &macParam, const OptClientId &idParam) 41 : m_mac(macParam), m_id(idParam) {} 41 : m_mac(), m_id() 42 {} 43 ClientId(const RTMAC &a_mac, const OptClientId &a_id) 44 : m_mac(a_mac), m_id(a_id) 45 {} 46 ClientId(const ClientId &a_rThat) 47 : m_mac(a_rThat.m_mac), m_id(a_rThat.m_id) 48 {} 49 ClientId &operator=(const ClientId &a_rThat) 50 { 51 m_mac = a_rThat.m_mac; 52 m_id = a_rThat.m_id; 53 return *this; 54 } 42 55 43 const RTMAC &mac() const{ return m_mac; }44 const OptClientId &id() const { return m_id; }56 const RTMAC &mac() const { return m_mac; } 57 const OptClientId &id() const { return m_id; } 45 58 46 public: 59 /** @name String formatting stuff 60 * @{ */ 47 61 static void registerFormat(); /* %R[id] */ 62 private: 63 static DECLCALLBACK(size_t) rtStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, const char *pszType, 64 void const *pvValue, int cchWidth, int cchPrecision, unsigned fFlags, void *pvUser); 65 static bool g_fFormatRegistered; 66 /** @} */ 48 67 49 private:50 static bool g_fFormatRegistered;51 static DECLCALLBACK(size_t) rtStrFormat(52 PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,53 const char *pszType, void const *pvValue,54 int cchWidth, int cchPrecision, unsigned fFlags,55 void *pvUser);56 57 private:58 68 friend bool operator==(const ClientId &l, const ClientId &r); 59 69 friend bool operator<(const ClientId &l, const ClientId &r); -
trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp
r79514 r79524 16 16 */ 17 17 18 #include "DhcpdInternal.h" 18 19 #include "Config.h" 19 20 -
trunk/src/VBox/NetworkServices/Dhcpd/Config.h
r79514 r79524 22 22 #endif 23 23 24 #include "DhcpdInternal.h" 24 25 #include <iprt/types.h> 25 26 #include <iprt/net.h> … … 30 31 31 32 32 #include "Defs.h"33 33 #include "DhcpOptions.h" 34 34 #include "ClientId.h" -
trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.cpp
r76553 r79524 16 16 */ 17 17 18 #include "DhcpdInternal.h" 18 19 #include "DHCPD.h" 19 20 #include "DhcpOptions.h" -
trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.h
r79514 r79524 22 22 #endif 23 23 24 #include "DhcpdInternal.h" 24 25 #include <iprt/cpp/ministring.h> 25 #include "Defs.h"26 26 #include "Config.h" 27 27 #include "DhcpMessage.h" -
trunk/src/VBox/NetworkServices/Dhcpd/Db.cpp
r79514 r79524 16 16 */ 17 17 18 #include "DhcpdInternal.h" 18 19 #include <iprt/errcore.h> 19 20 #include <iprt/stream.h> … … 98 99 &b->m_id, b->stateName()); 99 100 100 Time Stamp tsIssued = b->issued();101 Timestamp tsIssued = b->issued(); 101 102 cb += tsIssued.absStrFormat(pfnOutput, pvArgOutput); 102 103 … … 105 106 b->leaseTime()); 106 107 107 Time Stamp tsValid = b->issued();108 Timestamp tsValid = b->issued(); 108 109 tsValid.addSeconds(b->leaseTime()); 109 110 cb += tsValid.absStrFormat(pfnOutput, pvArgOutput); … … 151 152 152 153 153 bool Binding::expire(Time Stamp deadline)154 bool Binding::expire(Timestamp deadline) 154 155 { 155 156 if (m_state <= Binding::EXPIRED) 156 157 return false; 157 158 158 Time Stamp t = m_issued;159 Timestamp t = m_issued; 159 160 t.addSeconds(m_secLease); 160 161 … … 313 314 if (fHasState) 314 315 { 315 b->m_issued = Time Stamp::absSeconds(issued);316 b->m_issued = Timestamp::absSeconds(issued); 316 317 b->m_secLease = duration; 317 318 b->setState(strState.c_str()); … … 320 321 { /* XXX: old code wrote timestamps instead of absolute time. */ 321 322 /* pretend that lease has just ended */ 322 Time Stamp fakeIssued = TimeStamp::now();323 Timestamp fakeIssued = Timestamp::now(); 323 324 fakeIssued.subSeconds(duration); 324 325 b->m_issued = fakeIssued; … … 333 334 void Db::expire() 334 335 { 335 const Time Stamp now = TimeStamp::now();336 const Timestamp now = Timestamp::now(); 336 337 337 338 for (bindings_t::iterator it = m_bindings.begin(); … … 393 394 * addresses that can be reused. 394 395 */ 395 const Time Stamp now = TimeStamp::now();396 const Timestamp now = Timestamp::now(); 396 397 for (bindings_t::iterator it = m_bindings.begin(); 397 398 it != m_bindings.end(); ++it) -
trunk/src/VBox/NetworkServices/Dhcpd/Db.h
r79514 r79524 22 22 #endif 23 23 24 #include "DhcpdInternal.h" 24 25 #include <iprt/net.h> 25 26 … … 29 30 #include <list> 30 31 31 #include "Defs.h" 32 #include "TimeStamp.h" 32 #include "Timestamp.h" 33 33 #include "ClientId.h" 34 34 #include "IPv4Pool.h" … … 48 48 State m_state; 49 49 ClientId m_id; 50 Time Stamp m_issued;50 Timestamp m_issued; 51 51 uint32_t m_secLease; 52 52 … … 72 72 73 73 uint32_t leaseTime() const { return m_secLease; } 74 Time Stamp issued() const { return m_issued; }74 Timestamp issued() const { return m_issued; } 75 75 76 76 Binding &setState(State stateParam) … … 84 84 Binding &setLeaseTime(uint32_t secLease) 85 85 { 86 m_issued = Time Stamp::now();86 m_issued = Timestamp::now(); 87 87 m_secLease = secLease; 88 88 return *this; … … 102 102 } 103 103 104 bool expire(Time Stamp deadline);105 bool expire() { return expire(Time Stamp::now()); }104 bool expire(Timestamp deadline); 105 bool expire() { return expire(Timestamp::now()); } 106 106 107 107 static Binding *fromXML(const xml::ElementNode *ndLease); -
trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.cpp
r79514 r79524 16 16 */ 17 17 18 #include "DhcpdInternal.h" 18 19 #include "DhcpMessage.h" 19 20 #include "DhcpOptions.h" -
trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.h
r79514 r79524 22 22 #endif 23 23 24 #include "D efs.h"24 #include "DhcpdInternal.h" 25 25 #include <iprt/net.h> 26 26 #include <iprt/cpp/ministring.h> -
trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.cpp
r76553 r79524 16 16 */ 17 17 18 #include "DhcpdInternal.h" 18 19 #include "DhcpOptions.h" 19 20 #include "DhcpMessage.h" -
trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.h
r79514 r79524 22 22 #endif 23 23 24 #include "D efs.h"24 #include "DhcpdInternal.h" 25 25 26 26 #include <iprt/asm.h> -
trunk/src/VBox/NetworkServices/Dhcpd/DhcpdInternal.h
r79523 r79524 1 1 /* $Id$ */ 2 2 /** @file 3 * DHCP server - common definitions3 * DHCP server - Internal header. 4 4 */ 5 5 … … 22 22 #endif 23 23 24 #define LOG_GROUP LOG_GROUP_NET_DHCPD 24 25 #include <iprt/stdint.h> 25 26 #include <iprt/string.h> … … 33 34 using std::shared_ptr; 34 35 #else 35 # include <tr1/memory>36 # include <tr1/memory> 36 37 using std::tr1::shared_ptr; 37 38 #endif 38 39 40 41 /** Byte vector. */ 39 42 typedef std::vector<uint8_t> octets_t; 40 43 44 /** Raw DHCP option map (keyed by option number, byte vector value). */ 41 45 typedef std::map<uint8_t, octets_t> rawopts_t; 42 46 43 47 class DhcpOption; 48 /** DHCP option map (keyed by option number, DhcpOption value). */ 44 49 typedef std::map<uint8_t, std::shared_ptr<DhcpOption> > optmap_t; 45 50 46 inline bool operator==(const RTMAC &l, const RTMAC &r) 51 52 /** Equal compare operator for mac address. */ 53 DECLINLINE(bool) operator==(const RTMAC &l, const RTMAC &r) 47 54 { 48 55 return memcmp(&l, &r, sizeof(RTMAC)) == 0; 49 56 } 50 57 51 inline bool operator<(const RTMAC &l, const RTMAC &r) 58 /** Less-than compare operator for mac address. */ 59 DECLINLINE(bool) operator<(const RTMAC &l, const RTMAC &r) 52 60 { 53 61 return memcmp(&l, &r, sizeof(RTMAC)) < 0; 54 62 } 55 63 64 65 /** @def LogDHCP 66 * Wrapper around LogRel. */ 56 67 #if 1 57 # define LogDHCP LogRel68 # define LogDHCP LogRel 58 69 #else 59 #define LogDHCP(args) RTPrintf args 70 # include <iprt/stream.h> 71 # define LogDHCP(args) RTPrintf args 60 72 #endif 61 73 -
trunk/src/VBox/NetworkServices/Dhcpd/IPv4Pool.cpp
r76553 r79524 16 16 */ 17 17 18 #include "DhcpdInternal.h" 18 19 #include <iprt/errcore.h> 19 20 #include <iprt/stream.h> -
trunk/src/VBox/NetworkServices/Dhcpd/Timestamp.cpp
r79523 r79524 16 16 */ 17 17 18 #include "TimeStamp.h" 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 22 #include "DhcpdInternal.h" 23 #include "Timestamp.h" 19 24 20 25 #include <iprt/string.h> 21 26 22 27 23 size_t Time Stamp::absStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const28 size_t Timestamp::absStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const 24 29 { 25 30 RTTIMESPEC Spec; … … 29 34 RTTimeExplode(&Time, &Spec); 30 35 31 size_t cb = RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 32 "%RI32-%02u-%02uT%02u:%02u:%02uZ", 33 Time.i32Year, Time.u8Month, Time.u8MonthDay, 34 Time.u8Hour, Time.u8Minute, Time.u8Second); 35 return cb; 36 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 37 "%RI32-%02u-%02uT%02u:%02u:%02uZ", 38 Time.i32Year, Time.u8Month, Time.u8MonthDay, 39 Time.u8Hour, Time.u8Minute, Time.u8Second); 36 40 } -
trunk/src/VBox/NetworkServices/Dhcpd/Timestamp.h
r79523 r79524 22 22 #endif 23 23 24 #include <iprt/string.h>25 24 #include <iprt/time.h> 26 25 27 26 28 /* 27 /** 29 28 * Timestamp API uses unsigned time, but we need to be able to refer 30 29 * to events in the past. Hide the ugly convertions. 30 * 31 * @todo r=bird: Unnecessary mixing of RTTimeNanoTS and RTTimeNow. 31 32 */ 32 class Time Stamp33 class Timestamp 33 34 { 34 35 int64_t m_ns; 35 36 36 37 public: 37 TimeStamp() 38 : m_ns(0) {} 38 Timestamp() 39 : m_ns(0) 40 {} 39 41 40 TimeStamp(uint64_t ns) 41 : m_ns(static_cast<int64_t>(ns)) {} 42 Timestamp(uint64_t ns) 43 : m_ns(static_cast<int64_t>(ns)) 44 {} 42 45 43 static Time Stamp now()46 static Timestamp now() 44 47 { 45 return Time Stamp(RTTimeNanoTS());48 return Timestamp(RTTimeNanoTS()); 46 49 } 47 50 48 static Time Stamp absSeconds(int64_t sec)51 static Timestamp absSeconds(int64_t sec) 49 52 { 50 53 RTTIMESPEC delta; … … 53 56 54 57 uint64_t stampNow = RTTimeNanoTS(); 55 return Time Stamp(stampNow - RTTimeSpecGetNano(&delta));58 return Timestamp(stampNow - RTTimeSpecGetNano(&delta)); 56 59 } 57 60 58 Time Stamp &addSeconds(int64_t sec)61 Timestamp &addSeconds(int64_t cSecs) 59 62 { 60 m_ns += sec* RT_NS_1SEC;63 m_ns += cSecs * RT_NS_1SEC; 61 64 return *this; 62 65 } 63 66 64 Time Stamp &subSeconds(int64_t sec)67 Timestamp &subSeconds(int64_t cSecs) 65 68 { 66 m_ns -= sec* RT_NS_1SEC;69 m_ns -= cSecs * RT_NS_1SEC; 67 70 return *this; 68 71 } … … 87 90 size_t absStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const; 88 91 89 friend bool operator<(const Time Stamp &l, const TimeStamp &r);90 friend bool operator>(const Time Stamp &l, const TimeStamp &r);91 friend bool operator<=(const Time Stamp &l, const TimeStamp &r);92 friend bool operator>=(const Time Stamp &l, const TimeStamp &r);92 friend bool operator<(const Timestamp &l, const Timestamp &r); 93 friend bool operator>(const Timestamp &l, const Timestamp &r); 94 friend bool operator<=(const Timestamp &l, const Timestamp &r); 95 friend bool operator>=(const Timestamp &l, const Timestamp &r); 93 96 }; 94 97 95 98 96 inline bool operator<(const Time Stamp &l, const TimeStamp &r) { return l.m_ns < r.m_ns; }97 inline bool operator>(const Time Stamp &l, const TimeStamp &r) { return l.m_ns > r.m_ns; }98 inline bool operator<=(const Time Stamp &l, const TimeStamp &r) { return l.m_ns <= r.m_ns; }99 inline bool operator>=(const Time Stamp &l, const TimeStamp &r) { return l.m_ns >= r.m_ns; }99 inline bool operator<(const Timestamp &l, const Timestamp &r) { return l.m_ns < r.m_ns; } 100 inline bool operator>(const Timestamp &l, const Timestamp &r) { return l.m_ns > r.m_ns; } 101 inline bool operator<=(const Timestamp &l, const Timestamp &r) { return l.m_ns <= r.m_ns; } 102 inline bool operator>=(const Timestamp &l, const Timestamp &r) { return l.m_ns >= r.m_ns; } 100 103 101 104 #endif /* !VBOX_INCLUDED_SRC_Dhcpd_TimeStamp_h */ -
trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.cpp
r79514 r79524 27 27 #endif 28 28 29 29 #include "DhcpdInternal.h" 30 30 #include <iprt/param.h> 31 31 #include <iprt/errcore.h>
Note:
See TracChangeset
for help on using the changeset viewer.