VirtualBox

Changeset 79524 in vbox for trunk/src


Ignore:
Timestamp:
Jul 4, 2019 10:14:02 AM (6 years ago)
Author:
vboxsync
Message:

Dhcpd: s/Defs.h/DhcpdInternal.h/, s/TimeStamp/Timestamp/g, started adding comments and stuff. bugref:9288

Location:
trunk/src/VBox/NetworkServices/Dhcpd
Files:
14 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/Dhcpd/ClientId.cpp

    r76553 r79524  
    1616 */
    1717
     18
     19/*********************************************************************************************************************************
     20*   Header Files                                                                                                                 *
     21*********************************************************************************************************************************/
    1822#include <algorithm>
    19 
    2023#include "ClientId.h"
    2124
    2225
     26/*********************************************************************************************************************************
     27*   Global Variables                                                                                                             *
     28*********************************************************************************************************************************/
     29/** Indiciates wherther ClientId::rtStrFormat was already registered. */
    2330bool ClientId::g_fFormatRegistered = false;
    2431
    2532
     33/**
     34 * Registers the ClientId format type callback ("%R[id]").
     35 */
    2636void ClientId::registerFormat()
    2737{
    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    }
    3544}
    3645
    3746
     47/**
     48 * @callback_method_impl{FNRTSTRFORMATTYPE, Formats ClientId via "%R[id]". }
     49 */
    3850DECLCALLBACK(size_t)
    3951ClientId::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)
    4355{
    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
    4563    size_t cb = 0;
     64    if (pThis->m_id.present())
     65    {
     66        cb += pfnOutput(pvArgOutput, RT_STR_TUPLE("["));
    4667
    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]);
    4971
    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("] ("));
    5773    }
    5874
    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);
    6276
    63         cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
    64                           "[");
     77    if (pThis->m_id.present())
     78        cb += pfnOutput(pvArgOutput, RT_STR_TUPLE(")"));
    6579
    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;
    8681}
    8782
     
    110105        if (r.m_id.present())
    111106            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 */
    114108    }
    115109    else
     
    117111        if (r.m_id.present())
    118112            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;
    121114    }
    122115}
     116
  • trunk/src/VBox/NetworkServices/Dhcpd/ClientId.h

    r76576 r79524  
    2222#endif
    2323
    24 #include "Defs.h"
     24#include "DhcpdInternal.h"
    2525#include <iprt/net.h>
    2626#include "DhcpOptions.h"
    2727
    28 /*
    29  * Client is identified by either the Client ID option it sends or its
    30  * 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.
    3131 */
    3232class ClientId
    3333{
    34     RTMAC m_mac;
     34    /** The mac address of the client. */
     35    RTMAC       m_mac;
     36    /** The client ID. */
    3537    OptClientId m_id;
    3638
    3739public:
    3840    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    }
    4255
    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; }
    4558
    46 public:
     59    /** @name String formatting stuff
     60     * @{ */
    4761    static void registerFormat(); /* %R[id] */
     62private:
     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    /** @} */
    4867
    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:
    5868    friend bool operator==(const ClientId &l, const ClientId &r);
    5969    friend bool operator<(const ClientId &l, const ClientId &r);
  • trunk/src/VBox/NetworkServices/Dhcpd/Config.cpp

    r79514 r79524  
    1616 */
    1717
     18#include "DhcpdInternal.h"
    1819#include "Config.h"
    1920
  • trunk/src/VBox/NetworkServices/Dhcpd/Config.h

    r79514 r79524  
    2222#endif
    2323
     24#include "DhcpdInternal.h"
    2425#include <iprt/types.h>
    2526#include <iprt/net.h>
     
    3031
    3132
    32 #include "Defs.h"
    3333#include "DhcpOptions.h"
    3434#include "ClientId.h"
  • trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.cpp

    r76553 r79524  
    1616 */
    1717
     18#include "DhcpdInternal.h"
    1819#include "DHCPD.h"
    1920#include "DhcpOptions.h"
  • trunk/src/VBox/NetworkServices/Dhcpd/DHCPD.h

    r79514 r79524  
    2222#endif
    2323
     24#include "DhcpdInternal.h"
    2425#include <iprt/cpp/ministring.h>
    25 #include "Defs.h"
    2626#include "Config.h"
    2727#include "DhcpMessage.h"
  • trunk/src/VBox/NetworkServices/Dhcpd/Db.cpp

    r79514 r79524  
    1616 */
    1717
     18#include "DhcpdInternal.h"
    1819#include <iprt/errcore.h>
    1920#include <iprt/stream.h>
     
    9899                          &b->m_id, b->stateName());
    99100
    100         TimeStamp tsIssued = b->issued();
     101        Timestamp tsIssued = b->issued();
    101102        cb += tsIssued.absStrFormat(pfnOutput, pvArgOutput);
    102103
     
    105106                          b->leaseTime());
    106107
    107         TimeStamp tsValid = b->issued();
     108        Timestamp tsValid = b->issued();
    108109        tsValid.addSeconds(b->leaseTime());
    109110        cb += tsValid.absStrFormat(pfnOutput, pvArgOutput);
     
    151152
    152153
    153 bool Binding::expire(TimeStamp deadline)
     154bool Binding::expire(Timestamp deadline)
    154155{
    155156    if (m_state <= Binding::EXPIRED)
    156157        return false;
    157158
    158     TimeStamp t = m_issued;
     159    Timestamp t = m_issued;
    159160    t.addSeconds(m_secLease);
    160161
     
    313314    if (fHasState)
    314315    {
    315         b->m_issued = TimeStamp::absSeconds(issued);
     316        b->m_issued = Timestamp::absSeconds(issued);
    316317        b->m_secLease = duration;
    317318        b->setState(strState.c_str());
     
    320321    {   /* XXX: old code wrote timestamps instead of absolute time. */
    321322        /* pretend that lease has just ended */
    322         TimeStamp fakeIssued = TimeStamp::now();
     323        Timestamp fakeIssued = Timestamp::now();
    323324        fakeIssued.subSeconds(duration);
    324325        b->m_issued = fakeIssued;
     
    333334void Db::expire()
    334335{
    335     const TimeStamp now = TimeStamp::now();
     336    const Timestamp now = Timestamp::now();
    336337
    337338    for (bindings_t::iterator it = m_bindings.begin();
     
    393394     * addresses that can be reused.
    394395     */
    395     const TimeStamp now = TimeStamp::now();
     396    const Timestamp now = Timestamp::now();
    396397    for (bindings_t::iterator it = m_bindings.begin();
    397398         it != m_bindings.end(); ++it)
  • trunk/src/VBox/NetworkServices/Dhcpd/Db.h

    r79514 r79524  
    2222#endif
    2323
     24#include "DhcpdInternal.h"
    2425#include <iprt/net.h>
    2526
     
    2930#include <list>
    3031
    31 #include "Defs.h"
    32 #include "TimeStamp.h"
     32#include "Timestamp.h"
    3333#include "ClientId.h"
    3434#include "IPv4Pool.h"
     
    4848    State m_state;
    4949    ClientId m_id;
    50     TimeStamp m_issued;
     50    Timestamp m_issued;
    5151    uint32_t m_secLease;
    5252
     
    7272
    7373    uint32_t leaseTime() const { return m_secLease; }
    74     TimeStamp issued() const { return m_issued; }
     74    Timestamp issued() const { return m_issued; }
    7575
    7676    Binding &setState(State stateParam)
     
    8484    Binding &setLeaseTime(uint32_t secLease)
    8585    {
    86         m_issued = TimeStamp::now();
     86        m_issued = Timestamp::now();
    8787        m_secLease = secLease;
    8888        return *this;
     
    102102    }
    103103
    104     bool expire(TimeStamp deadline);
    105     bool expire() { return expire(TimeStamp::now()); }
     104    bool expire(Timestamp deadline);
     105    bool expire() { return expire(Timestamp::now()); }
    106106
    107107    static Binding *fromXML(const xml::ElementNode *ndLease);
  • trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.cpp

    r79514 r79524  
    1616 */
    1717
     18#include "DhcpdInternal.h"
    1819#include "DhcpMessage.h"
    1920#include "DhcpOptions.h"
  • trunk/src/VBox/NetworkServices/Dhcpd/DhcpMessage.h

    r79514 r79524  
    2222#endif
    2323
    24 #include "Defs.h"
     24#include "DhcpdInternal.h"
    2525#include <iprt/net.h>
    2626#include <iprt/cpp/ministring.h>
  • trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.cpp

    r76553 r79524  
    1616 */
    1717
     18#include "DhcpdInternal.h"
    1819#include "DhcpOptions.h"
    1920#include "DhcpMessage.h"
  • trunk/src/VBox/NetworkServices/Dhcpd/DhcpOptions.h

    r79514 r79524  
    2222#endif
    2323
    24 #include "Defs.h"
     24#include "DhcpdInternal.h"
    2525
    2626#include <iprt/asm.h>
  • trunk/src/VBox/NetworkServices/Dhcpd/DhcpdInternal.h

    r79523 r79524  
    11/* $Id$ */
    22/** @file
    3  * DHCP server - common definitions
     3 * DHCP server - Internal header.
    44 */
    55
     
    2222#endif
    2323
     24#define LOG_GROUP LOG_GROUP_NET_DHCPD
    2425#include <iprt/stdint.h>
    2526#include <iprt/string.h>
     
    3334using std::shared_ptr;
    3435#else
    35 #include <tr1/memory>
     36# include <tr1/memory>
    3637using std::tr1::shared_ptr;
    3738#endif
    3839
     40
     41/** Byte vector. */
    3942typedef std::vector<uint8_t> octets_t;
    4043
     44/** Raw DHCP option map (keyed by option number, byte vector value). */
    4145typedef std::map<uint8_t, octets_t> rawopts_t;
    4246
    4347class DhcpOption;
     48/** DHCP option map (keyed by option number, DhcpOption value). */
    4449typedef std::map<uint8_t, std::shared_ptr<DhcpOption> > optmap_t;
    4550
    46 inline bool operator==(const RTMAC &l, const RTMAC &r)
     51
     52/** Equal compare operator for mac address. */
     53DECLINLINE(bool) operator==(const RTMAC &l, const RTMAC &r)
    4754{
    4855    return memcmp(&l, &r, sizeof(RTMAC)) == 0;
    4956}
    5057
    51 inline bool operator<(const RTMAC &l, const RTMAC &r)
     58/** Less-than compare operator for mac address. */
     59DECLINLINE(bool) operator<(const RTMAC &l, const RTMAC &r)
    5260{
    5361    return memcmp(&l, &r, sizeof(RTMAC)) < 0;
    5462}
    5563
     64
     65/** @def LogDHCP
     66 * Wrapper around LogRel.  */
    5667#if 1
    57 #define LogDHCP LogRel
     68# define LogDHCP LogRel
    5869#else
    59 #define LogDHCP(args) RTPrintf args
     70# include <iprt/stream.h>
     71# define LogDHCP(args) RTPrintf args
    6072#endif
    6173
  • trunk/src/VBox/NetworkServices/Dhcpd/IPv4Pool.cpp

    r76553 r79524  
    1616 */
    1717
     18#include "DhcpdInternal.h"
    1819#include <iprt/errcore.h>
    1920#include <iprt/stream.h>
  • trunk/src/VBox/NetworkServices/Dhcpd/Timestamp.cpp

    r79523 r79524  
    1616 */
    1717
    18 #include "TimeStamp.h"
     18
     19/*********************************************************************************************************************************
     20*   Header Files                                                                                                                 *
     21*********************************************************************************************************************************/
     22#include "DhcpdInternal.h"
     23#include "Timestamp.h"
    1924
    2025#include <iprt/string.h>
    2126
    2227
    23 size_t TimeStamp::absStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const
     28size_t Timestamp::absStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const
    2429{
    2530    RTTIMESPEC Spec;
     
    2934    RTTimeExplode(&Time, &Spec);
    3035
    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);
    3640}
  • trunk/src/VBox/NetworkServices/Dhcpd/Timestamp.h

    r79523 r79524  
    2222#endif
    2323
    24 #include <iprt/string.h>
    2524#include <iprt/time.h>
    2625
    2726
    28 /*
     27/**
    2928 * Timestamp API uses unsigned time, but we need to be able to refer
    3029 * to events in the past.  Hide the ugly convertions.
     30 *
     31 * @todo r=bird: Unnecessary mixing of RTTimeNanoTS and RTTimeNow.
    3132 */
    32 class TimeStamp
     33class Timestamp
    3334{
    3435    int64_t m_ns;
    3536
    3637public:
    37     TimeStamp()
    38       : m_ns(0) {}
     38    Timestamp()
     39      : m_ns(0)
     40    {}
    3941
    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    {}
    4245
    43     static TimeStamp now()
     46    static Timestamp now()
    4447    {
    45         return TimeStamp(RTTimeNanoTS());
     48        return Timestamp(RTTimeNanoTS());
    4649    }
    4750
    48     static TimeStamp absSeconds(int64_t sec)
     51    static Timestamp absSeconds(int64_t sec)
    4952    {
    5053        RTTIMESPEC delta;
     
    5356
    5457        uint64_t stampNow = RTTimeNanoTS();
    55         return TimeStamp(stampNow - RTTimeSpecGetNano(&delta));
     58        return Timestamp(stampNow - RTTimeSpecGetNano(&delta));
    5659    }
    5760
    58     TimeStamp &addSeconds(int64_t sec)
     61    Timestamp &addSeconds(int64_t cSecs)
    5962    {
    60         m_ns += sec * RT_NS_1SEC;
     63        m_ns += cSecs * RT_NS_1SEC;
    6164        return *this;
    6265    }
    6366
    64     TimeStamp &subSeconds(int64_t sec)
     67    Timestamp &subSeconds(int64_t cSecs)
    6568    {
    66         m_ns -= sec * RT_NS_1SEC;
     69        m_ns -= cSecs * RT_NS_1SEC;
    6770        return *this;
    6871    }
     
    8790    size_t absStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput) const;
    8891
    89     friend bool operator<(const TimeStamp &l, const TimeStamp &r);
    90     friend bool operator>(const TimeStamp &l, const TimeStamp &r);
    91     friend bool operator<=(const TimeStamp &l, const TimeStamp &r);
    92     friend bool operator>=(const TimeStamp &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);
    9396};
    9497
    9598
    96 inline bool operator<(const TimeStamp &l, const TimeStamp &r) { return l.m_ns < r.m_ns; }
    97 inline bool operator>(const TimeStamp &l, const TimeStamp &r) { return l.m_ns > r.m_ns; }
    98 inline bool operator<=(const TimeStamp &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; }
     99inline bool operator<(const Timestamp &l, const Timestamp &r) { return l.m_ns < r.m_ns; }
     100inline bool operator>(const Timestamp &l, const Timestamp &r) { return l.m_ns > r.m_ns; }
     101inline bool operator<=(const Timestamp &l, const Timestamp &r) { return l.m_ns <= r.m_ns; }
     102inline bool operator>=(const Timestamp &l, const Timestamp &r) { return l.m_ns >= r.m_ns; }
    100103
    101104#endif /* !VBOX_INCLUDED_SRC_Dhcpd_TimeStamp_h */
  • trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.cpp

    r79514 r79524  
    2727#endif
    2828
    29 
     29#include "DhcpdInternal.h"
    3030#include <iprt/param.h>
    3131#include <iprt/errcore.h>
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