duid.h 4.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

Tomek Mrugalski's avatar
Tomek Mrugalski committed
15 16 17 18
#ifndef DUID_H
#define DUID_H

#include <asiolink/io_address.h>
19

Tomek Mrugalski's avatar
Tomek Mrugalski committed
20
#include <vector>
21

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include <stdint.h>
#include <unistd.h>

namespace isc {
namespace dhcp {

/// @brief Holds DUID (DHCPv6 Unique Identifier)
///
/// This class holds DUID, that is used in client-id, server-id and
/// several other options. It is used to identify DHCPv6 entity.
class DUID {
 public:
    /// @brief maximum duid size
    /// As defined in RFC3315, section 9.1
    static const size_t MAX_DUID_LEN = 128;

    /// @brief specifies DUID type
    typedef enum {
        DUID_UNKNOWN = 0, ///< invalid/unknown type
        DUID_LLT = 1,     ///< link-layer + time, see RFC3315, section 9.2
        DUID_EN = 2,      ///< enterprise-id, see RFC3315, section 9.3
        DUID_LL = 3,      ///< link-layer, see RFC3315, section 9.4
        DUID_UUID = 4,    ///< UUID, see RFC6355
        DUID_MAX          ///< not a real type, just maximum defined value + 1
    } DUIDType;

Stephen Morris's avatar
Stephen Morris committed
48
    /// @brief Constructor from vector
49 50
    DUID(const std::vector<uint8_t>& duid);

Stephen Morris's avatar
Stephen Morris committed
51
    /// @brief Constructor from array and array size
52
    DUID(const uint8_t* duid, size_t len);
53

Stephen Morris's avatar
Stephen Morris committed
54
    /// @brief Returns a const reference to the actual DUID value
55
    ///
56 57 58 59 60
    /// Note: For safety reasons, this method returns a copy of data as
    /// otherwise the reference would be only valid as long as the object that
    /// returned it. In any case, this method should be used only sporadically.
    /// If there are frequent uses, we must implement some other method
    /// (e.g. storeSelf()) that will avoid data copying.
61
    std::vector<uint8_t> getDuid() const;
62

Stephen Morris's avatar
Stephen Morris committed
63
    /// @brief Returns the DUID type
64 65
    DUIDType getType() const;

Stephen Morris's avatar
Stephen Morris committed
66
    /// @brief Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
67 68
    std::string toText() const;

Stephen Morris's avatar
Stephen Morris committed
69
    /// @brief Compares two DUIDs for equality
70
    bool operator==(const DUID& other) const;
71

Stephen Morris's avatar
Stephen Morris committed
72
    /// @brief Compares two DUIDs for inequality
73
    bool operator!=(const DUID& other) const;
74 75

 protected:
Stephen Morris's avatar
Stephen Morris committed
76
    /// The actual content of the DUID
77 78 79
    std::vector<uint8_t> duid_;
};

Stephen Morris's avatar
Stephen Morris committed
80
/// @brief Shared pointer to a DUID
Tomek Mrugalski's avatar
Tomek Mrugalski committed
81 82
typedef boost::shared_ptr<DUID> DuidPtr;

Stephen Morris's avatar
Stephen Morris committed
83 84


85 86 87 88
/// @brief Holds Client identifier or client IPv4 address
///
/// This class is intended to be a generic IPv4 client identifier. It can hold
/// a client-id
89
class ClientId : public DUID {
90
public:
Stephen Morris's avatar
Stephen Morris committed
91 92 93
    /// @brief Maximum size of a client ID
    ///
    /// This is the same as the maximum size of the underlying DUID.
94 95 96 97 98
    ///
    /// @note RFC 2131 does not specify an upper length of a client ID, the
    ///       value chosen here just being that of the underlying DUID.  For
    ///       some backend database, there may be a possible (minor)
    ///       performance enhancement if this were smaller.
99
    static const size_t MAX_CLIENT_ID_LEN = DUID::MAX_DUID_LEN;
100

Stephen Morris's avatar
Stephen Morris committed
101
    /// @brief Constructor based on vector<uint8_t>
102 103
    ClientId(const std::vector<uint8_t>& clientid);

Stephen Morris's avatar
Stephen Morris committed
104
    /// @brief Constructor based on array and array size
105
    ClientId(const uint8_t* clientid, size_t len);
106

Stephen Morris's avatar
Stephen Morris committed
107
    /// @brief Returns reference to the client-id data
108
    std::vector<uint8_t> getClientId() const;
109

110 111 112
    /// @brief Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
    std::string toText() const;

Stephen Morris's avatar
Stephen Morris committed
113
    /// @brief Compares two client-ids for equality
114
    bool operator==(const ClientId& other) const;
115

Stephen Morris's avatar
Stephen Morris committed
116
    /// @brief Compares two client-ids for inequality
117
    bool operator!=(const ClientId& other) const;
118 119
};

120 121 122
/// @brief Shared pointer to a Client ID.
typedef boost::shared_ptr<ClientId> ClientIdPtr;

123 124
}; // end of isc::dhcp namespace
}; // end of isc namespace
Tomek Mrugalski's avatar
Tomek Mrugalski committed
125 126

#endif /* DUID_H */