]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#939] Addressed review comments
authorPiotrek Zadroga <piotrek@isc.org>
Tue, 21 Mar 2023 15:42:00 +0000 (16:42 +0100)
committerPiotrek Zadroga <piotrek@isc.org>
Thu, 23 Mar 2023 13:51:23 +0000 (14:51 +0100)
12 files changed:
src/lib/dhcp/dhcp4.h
src/lib/dhcp/opaque_data_tuple.h
src/lib/dhcp/option_custom.cc
src/lib/dhcp/option_data_types.cc
src/lib/dhcp/option_data_types.h
src/lib/dhcp/option_definition.cc
src/lib/dhcp/option_definition.h
src/lib/dhcp/option_opaque_data_tuples.cc
src/lib/dhcp/option_opaque_data_tuples.h
src/lib/dhcp/std_option_defs.h
src/lib/dhcp/tests/option_definition_unittest.cc
src/lib/dhcp/tests/option_opaque_data_tuples_unittest.cc

index 6095a53de1054dc573903748c11dbc709f9894dc..5c163d0ba6b7ffe4fe2f7204dcd598c6447c7f8e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004-2023 Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1995-2003 by Internet Software Consortium
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
index 6374fc183fe80d69988bd4b2033191ed71120780..66a53dcc179172074b24abe159299600df88604d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2023 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
index b10aeb17b6b9e23af99a650e88b7e4fdbdf9efb9..1da78fddb00dd128611365b627829d0f29aa2fd2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2023 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
index 31308b00d0da41c751730bad463fde6833331bc7..4ca830cab9aee20d8edfb974d5255e6014e94a63 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2023 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
index 7d506e1e67baac913fb584eceec2c13842e26e65..4a941ed34fae11a04443ef39d1dc6b80781ac524 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2023 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
index 7a37587cc4d17741345dba46aa77d5c256c81fed..361fab04fd3ea6ce36e99c5d9107ccff8fe1b68e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2023 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
index 5d07396476887fd80a1b63f189fcfd5073fc7f80..f31a7538a5598161a2141a93a8c8c64f5a9ec56f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2023 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
index 1145da929a91969c2f9b756f6b433a926c3927a9..f70c4356676025898f214697b77249f36d1f2d73 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2023 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
@@ -15,15 +15,23 @@ namespace isc {
 namespace dhcp {
 
 OptionOpaqueDataTuples::OptionOpaqueDataTuples(Option::Universe u,
-                                               const uint16_t type)
-    : Option(u, type) {
+                                               const uint16_t type,
+                                               OpaqueDataTuple::LengthFieldType length_field_type)
+    : Option(u, type), length_field_type_(length_field_type) {
+    if (length_field_type_ == OpaqueDataTuple::LENGTH_EMPTY) {
+        length_field_type_ = OptionDataTypeUtil::getTupleLenFieldType(u);
+    }
 }
 
 OptionOpaqueDataTuples::OptionOpaqueDataTuples(Option::Universe u,
                                                const uint16_t type,
                                                OptionBufferConstIter begin,
-                                               OptionBufferConstIter end)
-    : Option(u, type) {
+                                               OptionBufferConstIter end,
+                                               OpaqueDataTuple::LengthFieldType length_field_type)
+    : Option(u, type), length_field_type_(length_field_type) {
+    if (length_field_type_ == OpaqueDataTuple::LENGTH_EMPTY) {
+        length_field_type_ = OptionDataTypeUtil::getTupleLenFieldType(u);
+    }
     unpack(begin, end);
 }
 
@@ -56,7 +64,7 @@ OptionOpaqueDataTuples::unpack(OptionBufferConstIter begin,
     size_t offset = 0;
     while (offset < std::distance(begin, end)) {
         // Parse a tuple.
-        OpaqueDataTuple tuple(getLengthFieldType(), begin + offset, end);
+        OpaqueDataTuple tuple(length_field_type_, begin + offset, end);
         addTuple(tuple);
         // The tuple has been parsed correctly which implies that it is safe to
         // advance the offset by its total length.
@@ -66,7 +74,7 @@ OptionOpaqueDataTuples::unpack(OptionBufferConstIter begin,
 
 void
 OptionOpaqueDataTuples::addTuple(const OpaqueDataTuple& tuple) {
-    if (tuple.getLengthFieldType() != getLengthFieldType()) {
+    if (tuple.getLengthFieldType() != length_field_type_) {
         isc_throw(isc::BadValue, "attempted to add opaque data tuple having"
                   " invalid size of the length field "
                   << tuple.getDataFieldSize() << " to opaque data tuple option");
@@ -83,7 +91,7 @@ OptionOpaqueDataTuples::setTuple(const size_t at, const OpaqueDataTuple& tuple)
                   " opaque data tuple option at position " << at << " which"
                   " is out of range");
 
-    } else if (tuple.getLengthFieldType() != getLengthFieldType()) {
+    } else if (tuple.getLengthFieldType() != length_field_type_) {
         isc_throw(isc::BadValue, "attempted to set opaque data tuple having"
                   " invalid size of the length field "
                   << tuple.getDataFieldSize() << " to opaque data tuple option");
index 6bf579f2cbb5bee63906ba114e7b297274f01c2f..99fce83d522784162d7ca26b67bf29d30c4f2f51 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2023 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
@@ -42,12 +42,17 @@ public:
 
     /// @brief Constructor.
     ///
-    /// This constructor creates an instance of an OpaqueDataTuple that can
-    /// be used for an option such as DHCPv6 Bootfile Parameters (60).
+    /// This constructor creates an instance of an OptionOpaqueDataTuples
+    /// that can be used for an option such as DHCPv6 Bootfile Parameters (60).
     ///
     /// @param u universe (v4 or v6).
     /// @param type option type
-    OptionOpaqueDataTuples(Option::Universe u, const uint16_t type);
+    /// @param length_field_type Indicates a length of the field which holds
+    /// the size of the tuple. If not provided explicitly, it is evaluated
+    /// basing on Option's v4/v6 universe.
+    OptionOpaqueDataTuples(Option::Universe u,
+                           const uint16_t type,
+                           OpaqueDataTuple::LengthFieldType length_field_type = OpaqueDataTuple::LENGTH_EMPTY);
 
     /// @brief Constructor.
     ///
@@ -59,30 +64,13 @@ public:
     /// @param begin Iterator pointing to the beginning of the buffer holding an
     /// option.
     /// @param end Iterator pointing to the end of the buffer holding an option.
-    OptionOpaqueDataTuples(Option::Universe u, const uint16_t type,
-                           OptionBufferConstIter begin,
-                           OptionBufferConstIter end);
-
-    /// @brief Constructor.
-    ///
-    /// This constructor creates an instance of an OptionOpaqueDataTuples option
-    /// using a buffer with on-wire data. This constructor allows to explicitly set
-    /// tuple's length field type.
-    /// It may throw an exception if the @c unpack method throws.
-    ///
-    /// @param u universe (v4 or v6)
-    /// @param type option type
-    /// @param begin Iterator pointing to the beginning of the buffer holding an
-    /// option.
-    /// @param end Iterator pointing to the end of the buffer holding an option.
-    /// @param lenFieldType explict tuple's length field type
+    /// @param length_field_type Indicates a length of the field which holds
+    /// the size of the tuple. If not provided explicitly, it is evaluated
+    /// basing on Option's v4/v6 universe.
     OptionOpaqueDataTuples(Option::Universe u, const uint16_t type,
                            OptionBufferConstIter begin,
                            OptionBufferConstIter end,
-                           OpaqueDataTuple::LengthFieldType lenFieldType)
-        : Option(u, type), prefLenFieldType_(lenFieldType) {
-        unpack(begin, end);
-    }
+                           OpaqueDataTuple::LengthFieldType length_field_type = OpaqueDataTuple::LENGTH_EMPTY);
 
     /// @brief Copies this option and returns a pointer to the copy.
     OptionPtr clone() const;
@@ -158,25 +146,8 @@ public:
     virtual std::string toText(int indent = 0) const;
 
 private:
-    /// @brief holds information of explicitly assigned tuple length field.
-    ///
-    /// Normally tuple length is evaluated basing on Option's universe.
-    /// But there may be cases when e.g. for v4 universe tuple length field
-    /// is 2 bytes long (e.g. DHCPv4 SZTP Redirect Option #143 bootstrap-server-list).
-    OpaqueDataTuple::LengthFieldType prefLenFieldType_ = OpaqueDataTuple::LENGTH_EMPTY;
-
-    /// @brief Returns the tuple length field type for the given universe.
-    ///
-    /// This function returns the length field type which should be used
-    /// for the opaque data tuples being added to this option.
-    ///
-    /// @return Tuple length field type for the universe this option belongs to.
-    OpaqueDataTuple::LengthFieldType getLengthFieldType() const {
-        if (prefLenFieldType_ != OpaqueDataTuple::LENGTH_EMPTY) {
-            return (prefLenFieldType_);
-        }
-        return (OptionDataTypeUtil::getTupleLenFieldType(getUniverse()));
-    }
+    /// @brief length of the field which holds he size of the tuple.
+    OpaqueDataTuple::LengthFieldType length_field_type_;
 
     /// @brief Returns minimal length of the option for the given universe.
     /// Currently this class is only used for a DHCPv6 option it may be expanded
index b203458cf1ff525c1f8d14bd95ccf9b4c8bdbf32..08f8ef751fdbbde041cd7f270230b8d320c2fa36 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2023 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
index f303c87a05687719f4d1b2e02bde05baba3dfe38..29f5b61a2aafe7de72501bdaa8779166dfd977d9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2021 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2023 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
index 217c2d67b4fae80ec4a403af27e0c44c7f4e9739..cf2f7bf03645fff575e157ddadde2ad6830ef48f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2023 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