|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
|
|
|
//
|
|
|
// 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
|
|
@@ -6,8 +6,10 @@
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
+#include <dhcp/dhcp4.h>
|
|
|
#include <dhcp/dhcp6.h>
|
|
|
#include <dhcp/option6_status_code.h>
|
|
|
+#include <dhcp/option_data_types.h>
|
|
|
#include <util/io_utilities.h>
|
|
|
#include <iterator>
|
|
|
#include <sstream>
|
|
@@ -19,6 +21,7 @@ namespace {
|
|
|
|
|
|
/// @brief Minimum length of the option (when status message is empty).
|
|
|
const size_t OPTION6_STATUS_CODE_MIN_LEN = sizeof(uint16_t);
|
|
|
+const size_t OPTION4_SLP_SERVICE_SCOPEMIN_LEN = sizeof(bool);
|
|
|
|
|
|
}; // end of anonymous namespace
|
|
|
|
|
@@ -135,5 +138,81 @@ Option6StatusCode::getStatusCodeName() const {
|
|
|
return ("(unknown status code)");
|
|
|
}
|
|
|
|
|
|
+Option4SlpServiceScope::Option4SlpServiceScope(const bool mandatory_flag,
|
|
|
+ const std::string& scope_list)
|
|
|
+ : Option(Option::V4, DHO_SERVICE_SCOPE),
|
|
|
+ mandatory_flag_(mandatory_flag), scope_list_(scope_list) {
|
|
|
+}
|
|
|
+
|
|
|
+Option4SlpServiceScope::Option4SlpServiceScope(OptionBufferConstIter begin,
|
|
|
+ OptionBufferConstIter end)
|
|
|
+ : Option(Option::V4, DHO_SERVICE_SCOPE),
|
|
|
+ mandatory_flag_(false), scope_list_() {
|
|
|
+
|
|
|
+ // Parse data
|
|
|
+ unpack(begin, end);
|
|
|
+}
|
|
|
+
|
|
|
+OptionPtr
|
|
|
+Option4SlpServiceScope::clone() const {
|
|
|
+ return (cloneInternal<Option4SlpServiceScope>());
|
|
|
+}
|
|
|
+
|
|
|
+void
|
|
|
+Option4SlpServiceScope::pack(isc::util::OutputBuffer& buf) const {
|
|
|
+ // Pack option header.
|
|
|
+ packHeader(buf);
|
|
|
+ // Write mandatory flag.
|
|
|
+ buf.writeUint8(static_cast<uint8_t>(getMandatoryFlag() ? 1 : 0));
|
|
|
+ // If there is any scope list, write it.
|
|
|
+ if (!scope_list_.empty()) {
|
|
|
+ buf.writeData(&scope_list_[0], scope_list_.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ // SLP service scope has no options, so leave here.
|
|
|
+}
|
|
|
+
|
|
|
+void
|
|
|
+Option4SlpServiceScope::unpack(OptionBufferConstIter begin, OptionBufferConstIter end) {
|
|
|
+ // Make sure that the option is not truncated.
|
|
|
+ if (std::distance(begin, end) < OPTION4_SLP_SERVICE_SCOPEMIN_LEN) {
|
|
|
+ isc_throw(OutOfRange, "SLP Service Scope option ("
|
|
|
+ << DHO_SERVICE_SCOPE << ") truncated");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (*begin == 1) {
|
|
|
+ mandatory_flag_ = true;
|
|
|
+ } else if (*begin == 0) {
|
|
|
+ mandatory_flag_ = false;
|
|
|
+ } else {
|
|
|
+ isc_throw(BadDataTypeCast, "unable to read the buffer as boolean"
|
|
|
+ << " value. Invalid value " << static_cast<int>(*begin));
|
|
|
+ }
|
|
|
+ begin += sizeof(bool);
|
|
|
+
|
|
|
+ scope_list_.assign(begin, end);
|
|
|
+}
|
|
|
+
|
|
|
+uint16_t
|
|
|
+Option4SlpServiceScope::len() const {
|
|
|
+ return (getHeaderLen() + sizeof(bool) + scope_list_.size());
|
|
|
+}
|
|
|
+
|
|
|
+std::string
|
|
|
+Option4SlpServiceScope::toText(int indent) const {
|
|
|
+ std::ostringstream output;
|
|
|
+ output << headerToText(indent) << ": " << dataToText();
|
|
|
+
|
|
|
+ return (output.str());
|
|
|
+}
|
|
|
+
|
|
|
+std::string
|
|
|
+Option4SlpServiceScope::dataToText() const {
|
|
|
+ std::ostringstream output;
|
|
|
+ output << "mandatory:" << getMandatoryFlag();
|
|
|
+ output << ", scope-list:\"" << scope_list_ << "\"";
|
|
|
+ return (output.str());
|
|
|
+}
|
|
|
+
|
|
|
} // end of namespace isc::dhcp
|
|
|
} // end of namespace isc
|