From: Piotrek Zadroga Date: Tue, 21 Mar 2023 15:42:00 +0000 (+0100) Subject: [#939] Addressed review comments X-Git-Tag: Kea-2.3.6~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2292c88781ba6ed7ddb99b5a93c874e134edf278;p=thirdparty%2Fkea.git [#939] Addressed review comments --- diff --git a/src/lib/dhcp/dhcp4.h b/src/lib/dhcp/dhcp4.h index 6095a53de1..5c163d0ba6 100644 --- a/src/lib/dhcp/dhcp4.h +++ b/src/lib/dhcp/dhcp4.h @@ -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 diff --git a/src/lib/dhcp/opaque_data_tuple.h b/src/lib/dhcp/opaque_data_tuple.h index 6374fc183f..66a53dcc17 100644 --- a/src/lib/dhcp/opaque_data_tuple.h +++ b/src/lib/dhcp/opaque_data_tuple.h @@ -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 diff --git a/src/lib/dhcp/option_custom.cc b/src/lib/dhcp/option_custom.cc index b10aeb17b6..1da78fddb0 100644 --- a/src/lib/dhcp/option_custom.cc +++ b/src/lib/dhcp/option_custom.cc @@ -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 diff --git a/src/lib/dhcp/option_data_types.cc b/src/lib/dhcp/option_data_types.cc index 31308b00d0..4ca830cab9 100644 --- a/src/lib/dhcp/option_data_types.cc +++ b/src/lib/dhcp/option_data_types.cc @@ -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 diff --git a/src/lib/dhcp/option_data_types.h b/src/lib/dhcp/option_data_types.h index 7d506e1e67..4a941ed34f 100644 --- a/src/lib/dhcp/option_data_types.h +++ b/src/lib/dhcp/option_data_types.h @@ -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 diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc index 7a37587cc4..361fab04fd 100644 --- a/src/lib/dhcp/option_definition.cc +++ b/src/lib/dhcp/option_definition.cc @@ -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 diff --git a/src/lib/dhcp/option_definition.h b/src/lib/dhcp/option_definition.h index 5d07396476..f31a7538a5 100644 --- a/src/lib/dhcp/option_definition.h +++ b/src/lib/dhcp/option_definition.h @@ -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 diff --git a/src/lib/dhcp/option_opaque_data_tuples.cc b/src/lib/dhcp/option_opaque_data_tuples.cc index 1145da929a..f70c435667 100644 --- a/src/lib/dhcp/option_opaque_data_tuples.cc +++ b/src/lib/dhcp/option_opaque_data_tuples.cc @@ -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"); diff --git a/src/lib/dhcp/option_opaque_data_tuples.h b/src/lib/dhcp/option_opaque_data_tuples.h index 6bf579f2cb..99fce83d52 100644 --- a/src/lib/dhcp/option_opaque_data_tuples.h +++ b/src/lib/dhcp/option_opaque_data_tuples.h @@ -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 diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h index b203458cf1..08f8ef751f 100644 --- a/src/lib/dhcp/std_option_defs.h +++ b/src/lib/dhcp/std_option_defs.h @@ -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 diff --git a/src/lib/dhcp/tests/option_definition_unittest.cc b/src/lib/dhcp/tests/option_definition_unittest.cc index f303c87a05..29f5b61a2a 100644 --- a/src/lib/dhcp/tests/option_definition_unittest.cc +++ b/src/lib/dhcp/tests/option_definition_unittest.cc @@ -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 diff --git a/src/lib/dhcp/tests/option_opaque_data_tuples_unittest.cc b/src/lib/dhcp/tests/option_opaque_data_tuples_unittest.cc index 217c2d67b4..cf2f7bf036 100644 --- a/src/lib/dhcp/tests/option_opaque_data_tuples_unittest.cc +++ b/src/lib/dhcp/tests/option_opaque_data_tuples_unittest.cc @@ -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