summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotrek Zadroga <piotrek@isc.org>2023-03-08 18:01:06 +0100
committerPiotrek Zadroga <piotrek@isc.org>2023-03-23 14:51:23 +0100
commit9e313134edf5670e66fa408b17ac1ee930b3f86a (patch)
treec885cf6d3d9871b9e78eeb0b6334674cb0825378
parent[#939] Adding SZTP DHCP Option codes (diff)
downloadkea-9e313134edf5670e66fa408b17ac1ee930b3f86a.tar.xz
kea-9e313134edf5670e66fa408b17ac1ee930b3f86a.zip
[#939] Implementation of SZTP Option codes
Adding initial implementation for new Options.
-rw-r--r--src/lib/dhcp/dhcp4.h2
-rw-r--r--src/lib/dhcp/dhcp6.h2
-rw-r--r--src/lib/dhcp/opaque_data_tuple.h1
-rw-r--r--src/lib/dhcp/option_definition.cc18
-rw-r--r--src/lib/dhcp/option_definition.h17
-rw-r--r--src/lib/dhcp/option_opaque_data_tuples.cc10
-rw-r--r--src/lib/dhcp/option_opaque_data_tuples.h24
-rw-r--r--src/lib/dhcp/std_option_defs.h4
8 files changed, 76 insertions, 2 deletions
diff --git a/src/lib/dhcp/dhcp4.h b/src/lib/dhcp/dhcp4.h
index 5f8e95f23e..6095a53de1 100644
--- a/src/lib/dhcp/dhcp4.h
+++ b/src/lib/dhcp/dhcp4.h
@@ -197,7 +197,7 @@ enum DHCPOptionType {
// DHO_IPV4_FQDN_MOS = 140, /* RFC5678 */
DHO_SIP_UA_CONF_SERVICE_DOMAINS = 141, /* RFC6011 */
// DHO_IPV4_ADDR_ANDSF = 142, /* RFC6153 */
-// DHO_V4_SZTP_REDIRECT = 143, /* RFC8572 */
+ DHO_V4_SZTP_REDIRECT = 143, /* RFC8572 */
// DHO_GEOLOC = 144, /* RFC6225 */
// DHO_FORCERENEW_NONCE_CAPABLE = 145, /* RFC6704 */
DHO_RDNSS_SELECT = 146, /* RFC6731 */
diff --git a/src/lib/dhcp/dhcp6.h b/src/lib/dhcp/dhcp6.h
index 753773af6d..061a1ddf09 100644
--- a/src/lib/dhcp/dhcp6.h
+++ b/src/lib/dhcp/dhcp6.h
@@ -153,7 +153,7 @@ enum DHCPv6OptionType {
// D6O_F_START_TIME_OF_STATE = 133, /* RFC8156 */
// D6O_F_STATE_EXPIRATION_TIME = 134, /* RFC8156 */
D6O_RELAY_SOURCE_PORT = 135, /* RFC8357 */
-// D60_V6_SZTP_REDIRECT = 136, /* RFC8572 */
+ D60_V6_SZTP_REDIRECT = 136, /* RFC8572 */
// Option codes 137-142 are unassigned.
D6O_IPV6_ADDRESS_ANDSF = 143 /* RFC6153 */
};
diff --git a/src/lib/dhcp/opaque_data_tuple.h b/src/lib/dhcp/opaque_data_tuple.h
index 5993fc9953..6374fc183f 100644
--- a/src/lib/dhcp/opaque_data_tuple.h
+++ b/src/lib/dhcp/opaque_data_tuple.h
@@ -55,6 +55,7 @@ public:
/// in the DHCPv6 options have 2 byte long length fields, the tuples carried
/// in DHCPv4 options have 1 byte long length fields.
enum LengthFieldType {
+ LENGTH_EMPTY = -1,
LENGTH_1_BYTE,
LENGTH_2_BYTES
};
diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc
index ce78e56bf0..8868e062b5 100644
--- a/src/lib/dhcp/option_definition.cc
+++ b/src/lib/dhcp/option_definition.cc
@@ -772,6 +772,19 @@ OptionDefinition::factoryOpaqueDataTuples(Option::Universe u,
}
OptionPtr
+OptionDefinition::factoryOpaqueDataTuples(Option::Universe u,
+ uint16_t type,
+ OptionBufferConstIter begin,
+ OptionBufferConstIter end,
+ OpaqueDataTuple::LengthFieldType lenFieldType
+ ) {
+ boost::shared_ptr<OptionOpaqueDataTuples>
+ option(new OptionOpaqueDataTuples(u, type, begin, end, lenFieldType));
+
+ return (option);
+}
+
+OptionPtr
OptionDefinition::factoryFqdnList(Option::Universe u,
OptionBufferConstIter begin,
OptionBufferConstIter end) const {
@@ -873,6 +886,11 @@ OptionDefinition::factorySpecialFormatOption(Option::Universe u,
// Vendor-Specific Information (option code 125).
return (OptionPtr(new OptionVendor(Option::V4, begin, end)));
+ case DHO_V4_SZTP_REDIRECT:
+ // Array of tuples.
+ // DHCPv4 SZTP Redirect Option (option code 143).
+ return (factoryOpaqueDataTuples(Option::V4, getCode(), begin, end, OpaqueDataTuple::LENGTH_2_BYTES));
+
default:
break;
}
diff --git a/src/lib/dhcp/option_definition.h b/src/lib/dhcp/option_definition.h
index 08a5126313..678e18bb31 100644
--- a/src/lib/dhcp/option_definition.h
+++ b/src/lib/dhcp/option_definition.h
@@ -581,6 +581,23 @@ public:
OptionBufferConstIter begin,
OptionBufferConstIter end);
+ /// @brief Factory to create option with tuple list with explict tuple's length field type.
+ ///
+ /// @param u option universe (V4 or V6).
+ /// @param type option type.
+ /// @param begin iterator pointing to the beginning of the buffer
+ /// with a list of tuples.
+ /// @param end iterator pointing to the end of the buffer with
+ /// a list of tuples.
+ /// @param lenFieldType explict tuple's length field type
+ ///
+ /// @return instance of the DHCP option.
+ static OptionPtr factoryOpaqueDataTuples(Option::Universe u,
+ uint16_t type,
+ OptionBufferConstIter begin,
+ OptionBufferConstIter end,
+ OpaqueDataTuple::LengthFieldType lenFieldType);
+
/// @brief Factory function to create option with integer value.
///
/// @param u universe (V4 or V6).
diff --git a/src/lib/dhcp/option_opaque_data_tuples.cc b/src/lib/dhcp/option_opaque_data_tuples.cc
index 1145da929a..655027b2e2 100644
--- a/src/lib/dhcp/option_opaque_data_tuples.cc
+++ b/src/lib/dhcp/option_opaque_data_tuples.cc
@@ -27,6 +27,16 @@ OptionOpaqueDataTuples::OptionOpaqueDataTuples(Option::Universe u,
unpack(begin, end);
}
+OptionOpaqueDataTuples::OptionOpaqueDataTuples(Option::Universe u,
+ const uint16_t type,
+ OptionBufferConstIter begin,
+ OptionBufferConstIter end,
+ OpaqueDataTuple::LengthFieldType lenFieldType)
+ : Option(u, type) {
+ prefLenFieldType = lenFieldType;
+ unpack(begin, end);
+}
+
OptionPtr
OptionOpaqueDataTuples::clone() const {
return (cloneInternal<OptionOpaqueDataTuples>());
diff --git a/src/lib/dhcp/option_opaque_data_tuples.h b/src/lib/dhcp/option_opaque_data_tuples.h
index aa05d8a58c..f1248f59d9 100644
--- a/src/lib/dhcp/option_opaque_data_tuples.h
+++ b/src/lib/dhcp/option_opaque_data_tuples.h
@@ -62,6 +62,22 @@ public:
OptionBufferConstIter begin,
OptionBufferConstIter end);
+ /// @brief Constructor.
+ ///
+ /// This constructor creates an instance of the option using a buffer with
+ /// on-wire data. 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
+ OptionOpaqueDataTuples(Option::Universe u, const uint16_t type,
+ OptionBufferConstIter begin,
+ OptionBufferConstIter end,
+ OpaqueDataTuple::LengthFieldType lenFieldType);
+
/// @brief Copies this option and returns a pointer to the copy.
OptionPtr clone() const;
@@ -136,6 +152,11 @@ 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.
///
@@ -144,6 +165,9 @@ private:
///
/// @return Tuple length field type for the universe this option belongs to.
OpaqueDataTuple::LengthFieldType getLengthFieldType() const {
+ if (prefLenFieldType != OpaqueDataTuple::LENGTH_EMPTY) {
+ return (prefLenFieldType);
+ }
return (universe_ == Option::V6 ? OpaqueDataTuple::LENGTH_2_BYTES :
OpaqueDataTuple::LENGTH_1_BYTE);
}
diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h
index a28ca774cf..b203458cf1 100644
--- a/src/lib/dhcp/std_option_defs.h
+++ b/src/lib/dhcp/std_option_defs.h
@@ -346,6 +346,8 @@ const OptionDefParams STANDARD_V4_OPTION_DEFINITIONS[] = {
OPT_IPV4_ADDRESS_TYPE, true, NO_RECORD_DEF, "" },
{ "sip-ua-cs-domains", DHO_SIP_UA_CONF_SERVICE_DOMAINS, DHCP4_OPTION_SPACE,
OPT_FQDN_TYPE, true, NO_RECORD_DEF, "" },
+ { "v4-sztp-redirect", DHO_V4_SZTP_REDIRECT, DHCP4_OPTION_SPACE, OPT_TUPLE_TYPE,
+ true, NO_RECORD_DEF, ""},
{ "rdnss-selection", DHO_RDNSS_SELECT, DHCP4_OPTION_SPACE, OPT_RECORD_TYPE,
true, RECORD_DEF(V4_RDNSS_SELECT_RECORDS), "" },
{ "status-code", DHO_STATUS_CODE, DHCP4_OPTION_SPACE,
@@ -638,6 +640,8 @@ const OptionDefParams STANDARD_V6_OPTION_DEFINITIONS[] = {
OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
{ "relay-source-port", D6O_RELAY_SOURCE_PORT, DHCP6_OPTION_SPACE,
OPT_UINT16_TYPE, false, NO_RECORD_DEF, "" },
+ { "v6-sztp-redirect", D60_V6_SZTP_REDIRECT, DHCP6_OPTION_SPACE,
+ OPT_TUPLE_TYPE, true, NO_RECORD_DEF, "" },
{ "ipv6-address-andsf", D6O_IPV6_ADDRESS_ANDSF, DHCP6_OPTION_SPACE,
OPT_IPV6_ADDRESS_TYPE, true, NO_RECORD_DEF, "" },
{ "s46-cont-mape", D6O_S46_CONT_MAPE, DHCP6_OPTION_SPACE, OPT_EMPTY_TYPE,