2019-07-08 08:28:12 -04:00
|
|
|
// Copyright (C) 2012-2019 Internet Systems Consortium, Inc. ("ISC")
|
2012-09-12 17:09:40 +02:00
|
|
|
//
|
2015-12-15 21:37:34 +01:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2012-09-12 17:09:40 +02:00
|
|
|
|
2016-12-14 16:15:52 +02:00
|
|
|
#include <config.h>
|
|
|
|
|
2012-11-16 14:15:45 +00:00
|
|
|
#include <dhcp/duid.h>
|
2012-09-12 17:09:40 +02:00
|
|
|
#include <exceptions/exceptions.h>
|
2012-09-12 20:39:07 +02:00
|
|
|
#include <util/io_utilities.h>
|
2012-10-30 18:22:50 +01:00
|
|
|
#include <iomanip>
|
2014-10-17 15:49:18 +02:00
|
|
|
#include <cctype>
|
2012-11-16 14:15:45 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2012-09-12 17:09:40 +02:00
|
|
|
|
|
|
|
namespace isc {
|
|
|
|
namespace dhcp {
|
|
|
|
|
2023-03-13 20:00:19 +02:00
|
|
|
IdentifierBaseType::~IdentifierBaseType() {
|
2012-09-12 17:09:40 +02:00
|
|
|
}
|
|
|
|
|
2023-05-10 22:35:25 +03:00
|
|
|
constexpr size_t DUID::MIN_DUID_LEN;
|
|
|
|
constexpr size_t DUID::MAX_DUID_LEN;
|
|
|
|
|
2023-03-13 20:00:19 +02:00
|
|
|
DUID::DUID(const std::vector<uint8_t>& data) : IdentifierType<3, 130>(data) {
|
|
|
|
}
|
2012-09-12 17:09:40 +02:00
|
|
|
|
2023-03-13 20:00:19 +02:00
|
|
|
DUID::DUID(const uint8_t* data, size_t len) : IdentifierType<3, 130>(data, len) {
|
2012-09-12 17:09:40 +02:00
|
|
|
}
|
|
|
|
|
2014-03-24 14:32:10 +01:00
|
|
|
const std::vector<uint8_t>& DUID::getDuid() const {
|
2023-03-13 20:00:19 +02:00
|
|
|
return (data_);
|
2014-03-24 14:32:10 +01:00
|
|
|
}
|
2023-03-13 20:00:19 +02:00
|
|
|
|
2014-03-24 14:32:10 +01:00
|
|
|
DUID::DUIDType DUID::getType() const {
|
2023-03-13 20:00:19 +02:00
|
|
|
if (data_.size() < 2) {
|
2014-03-24 14:32:10 +01:00
|
|
|
return (DUID_UNKNOWN);
|
|
|
|
}
|
2023-03-13 20:00:19 +02:00
|
|
|
uint16_t type = (data_[0] << 8) + data_[1];
|
2014-03-24 14:32:10 +01:00
|
|
|
if (type < DUID_MAX) {
|
|
|
|
return (static_cast<DUID::DUIDType>(type));
|
|
|
|
} else {
|
|
|
|
return (DUID_UNKNOWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DUID
|
|
|
|
DUID::fromText(const std::string& text) {
|
2023-03-13 20:00:19 +02:00
|
|
|
return (DUID(IdentifierType::fromText(text)));
|
2014-03-24 07:44:55 +01:00
|
|
|
}
|
|
|
|
|
2016-11-01 11:00:29 -04:00
|
|
|
const DUID&
|
|
|
|
DUID::EMPTY() {
|
2023-03-13 20:00:19 +02:00
|
|
|
static DUID empty({0, 0, 0});
|
|
|
|
return (empty);
|
2012-09-12 17:09:40 +02:00
|
|
|
}
|
|
|
|
|
2023-05-10 13:47:54 +03:00
|
|
|
constexpr size_t ClientId::MIN_CLIENT_ID_LEN;
|
|
|
|
constexpr size_t ClientId::MAX_CLIENT_ID_LEN;
|
|
|
|
|
2023-03-13 20:00:19 +02:00
|
|
|
ClientId::ClientId(const std::vector<uint8_t>& data) : IdentifierType<2, 255>(data) {
|
2012-09-12 17:09:40 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 20:00:19 +02:00
|
|
|
ClientId::ClientId(const uint8_t *data, size_t len) : IdentifierType<2, 255>(data, len) {
|
2012-09-12 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
2013-11-15 13:45:56 +01:00
|
|
|
const std::vector<uint8_t>& ClientId::getClientId() const {
|
2023-03-13 20:00:19 +02:00
|
|
|
return (data_);
|
2012-09-12 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 20:00:19 +02:00
|
|
|
ClientIdPtr ClientId::fromText(const std::string& text) {
|
|
|
|
return (ClientIdPtr(new ClientId(IdentifierType::fromText(text))));
|
2012-09-12 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 20:00:19 +02:00
|
|
|
} // namespace dhcp
|
|
|
|
} // namespace isc
|