Kea 2.7.1
libdhcp++.h
Go to the documentation of this file.
1// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef LIBDHCP_H
8#define LIBDHCP_H
9
12#include <dhcp/option_space.h>
13#include <dhcp/pkt4.h>
14#include <dhcp/pkt6.h>
15#include <util/buffer.h>
16#include <util/staged_value.h>
17
18#include <iostream>
19#include <stdint.h>
20#include <string>
21
22namespace isc {
23namespace dhcp {
24
26typedef ScopedPktOptionsCopy<Pkt4> ScopedPkt4OptionsCopy;
28typedef ScopedPktOptionsCopy<Pkt6> ScopedPkt6OptionsCopy;
30typedef std::shared_ptr<ScopedSubOptionsCopy> ScopedOptionsCopyPtr;
32typedef std::vector<ScopedOptionsCopyPtr> ScopedOptionsCopyContainer;
33
38
41 // Destroy the scoped options in same order so that parent options
42 // (stored last) are kept alive longer.
43 for (auto& scoped : scoped_options_) {
44 scoped.reset();
45 }
46 }
47
50};
51
52class LibDHCP {
53
54public:
55
57 typedef std::map<unsigned short, Option::Factory*> FactoryMap;
58
67 static const OptionDefContainerPtr getOptionDefs(const std::string& space);
68
77 static OptionDefinitionPtr getOptionDef(const std::string& space,
78 const uint16_t code);
79
87 static OptionDefinitionPtr getOptionDef(const std::string& space,
88 const std::string& name);
89
98 const uint32_t vendor_id,
99 const uint16_t code);
100
111 const uint32_t vendor_id,
112 const std::string& name);
113
114
122 static OptionDefinitionPtr getRuntimeOptionDef(const std::string& space,
123 const uint16_t code);
124
132 static OptionDefinitionPtr getRuntimeOptionDef(const std::string& space,
133 const std::string& name);
134
141 static OptionDefContainerPtr getRuntimeOptionDefs(const std::string& space);
142
149 static OptionDefinitionPtr getLastResortOptionDef(const std::string& space,
150 const uint16_t code);
151
158 static OptionDefinitionPtr getLastResortOptionDef(const std::string& space,
159 const std::string& name);
160
167 static OptionDefContainerPtr getLastResortOptionDefs(const std::string& space);
168
177 static bool shouldDeferOptionUnpack(const std::string& space,
178 const uint16_t code);
179
195 uint16_t type,
196 const OptionBuffer& buf);
197
223 static void packOptions4(isc::util::OutputBuffer& buf,
224 const isc::dhcp::OptionCollection& options,
225 bool top = false, bool check = true);
226
238 static bool splitOptions4(isc::dhcp::OptionCollection& options,
239 ScopedOptionsCopyContainer& scopedOptions,
240 uint32_t used = 0);
241
256 static void packOptions6(isc::util::OutputBuffer& buf,
257 const isc::dhcp::OptionCollection& options);
258
288 static size_t unpackOptions6(const OptionBuffer& buf,
289 const std::string& option_space,
291 size_t* relay_msg_offset = 0,
292 size_t* relay_msg_len = 0);
293
300
320 static size_t unpackOptions4(const OptionBuffer& buf,
321 const std::string& option_space,
323 std::list<uint16_t>& deferred,
324 bool flexible_pad_end = false);
325
335 uint16_t type,
336 Option::Factory * factory);
337
346 const uint32_t vendor_id);
347
363 static size_t unpackVendorOptions6(const uint32_t vendor_id,
364 const OptionBuffer& buf,
366
381 static size_t unpackVendorOptions4(const uint32_t vendor_id,
382 const OptionBuffer& buf,
384
385
395 static void setRuntimeOptionDefs(const OptionDefSpaceContainer& defs);
396
398 static void clearRuntimeOptionDefs();
399
401 static void revertRuntimeOptionDefs();
402
404 static void commitRuntimeOptionDefs();
405
419 static uint32_t optionSpaceToVendorId(const std::string& option_space);
420
423
426
429
432
435
438
441
443 static const OptionDefinition& D6O_LQ_QUERY_DEF();
444
447
450
453
455 static const OptionDefinition& D6O_RSOO_DEF();
456
457private:
458
466 static bool initOptionDefs();
467
469 static bool initialized_;
470
472 static FactoryMap v4factories_;
473
475 static FactoryMap v6factories_;
476
478 static OptionDefContainers option_defs_;
479
481 static util::StagedValue<OptionDefSpaceContainer> runtime_option_defs_;
482};
483
484}
485}
486
487#endif // LIBDHCP_H
static size_t unpackOptions4(const OptionBuffer &buf, const std::string &option_space, isc::dhcp::OptionCollection &options, std::list< uint16_t > &deferred, bool flexible_pad_end=false)
Parses provided buffer as DHCPv4 options and creates Option objects.
Definition libdhcp++.cc:461
static void OptionFactoryRegister(Option::Universe u, uint16_t type, Option::Factory *factory)
Registers factory method that produces options of specific option types.
static const OptionDefinition & D6O_LQ_RELAY_DATA_DEF()
Get definition of D6O_LQ_RELAY_DATA option.
static const OptionDefinition & D6O_RSOO_DEF()
Get definition of D6O_RSOO option.
static size_t unpackVendorOptions6(const uint32_t vendor_id, const OptionBuffer &buf, isc::dhcp::OptionCollection &options)
Parses provided buffer as DHCPv6 vendor options and creates Option objects.
Definition libdhcp++.cc:808
static const OptionDefContainerPtr getOptionDefs(const std::string &space)
Returns collection of option definitions.
Definition libdhcp++.cc:101
static bool shouldDeferOptionUnpack(const std::string &space, const uint16_t code)
Checks if an option unpacking has to be deferred.
Definition libdhcp++.cc:282
static isc::dhcp::OptionPtr optionFactory(isc::dhcp::Option::Universe u, uint16_t type, const OptionBuffer &buf)
Factory function to create instance of option.
Definition libdhcp++.cc:289
static void setRuntimeOptionDefs(const OptionDefSpaceContainer &defs)
Copies option definitions created at runtime.
Definition libdhcp++.cc:220
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
Definition libdhcp++.cc:128
static OptionDefinitionPtr getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id, const uint16_t code)
Returns vendor option definition for a given vendor-id and code.
Definition libdhcp++.cc:170
std::map< unsigned short, Option::Factory * > FactoryMap
Map of factory functions.
Definition libdhcp++.h:57
static OptionDefContainerPtr getLastResortOptionDefs(const std::string &space)
Returns last resort option definitions for specified option space name.
Definition libdhcp++.cc:273
static const OptionDefinition & D6O_LQ_QUERY_DEF()
Get definition of D6O_LQ_QUERY option.
static OptionDefContainerPtr getRuntimeOptionDefs(const std::string &space)
Returns runtime (non-standard) option definitions for specified option space name.
Definition libdhcp++.cc:215
static void commitRuntimeOptionDefs()
Commits runtime option definitions.
Definition libdhcp++.cc:244
static void clearRuntimeOptionDefs()
Removes runtime option definitions.
Definition libdhcp++.cc:234
static void extendVendorOptions4(isc::dhcp::OptionCollection &options)
Extend vendor options from fused options in multiple OptionVendor or OptionVendorClass options and ad...
Definition libdhcp++.cc:802
static const OptionDefinition & D6O_CLIENT_DATA_DEF()
Get definition of D6O_CLIENT_DATA option.
static void packOptions4(isc::util::OutputBuffer &buf, const isc::dhcp::OptionCollection &options, bool top=false, bool check=true)
Stores DHCPv4 options in a buffer.
static bool splitOptions4(isc::dhcp::OptionCollection &options, ScopedOptionsCopyContainer &scopedOptions, uint32_t used=0)
Split long options in multiple options with the same option code (RFC3396).
static const OptionDefinition & DHO_DHCP_REQUESTED_ADDRESS_DEF()
Get definition of DHO_DHCP_REQUESTED_ADDRESS option.
static const OptionDefinition & D6O_BOOTFILE_URL_DEF()
Get definition of D6O_BOOTFILE_URL option.
static const OptionDefinition & DHO_DHCP_SERVER_IDENTIFIER_DEF()
Get definition of DHO_DHCP_SERVER_IDENTIFIER option.
static const OptionDefinition & DHO_SUBNET_SELECTION_DEF()
Get definition of DHO_SUBNET_SELECTION option.
static void revertRuntimeOptionDefs()
Reverts uncommitted changes to runtime option definitions.
Definition libdhcp++.cc:239
static const OptionDefinition & DHO_DOMAIN_SEARCH_DEF()
Get definition of DHO_DOMAIN_SEARCH option.
static const OptionDefContainerPtr getVendorOptionDefs(Option::Universe u, const uint32_t vendor_id)
Returns option definitions for given universe and vendor.
Definition libdhcp++.cc:111
static const OptionDefinition & D6O_CLIENT_FQDN_DEF()
Get definition of D6O_CLIENT_FQDN option.
static const OptionDefinition & DHO_DHCP_AGENT_OPTIONS_DEF()
Get definition of DHO_DHCP_AGENT_OPTIONS option.
static uint32_t optionSpaceToVendorId(const std::string &option_space)
Converts option space name to vendor id.
static OptionDefinitionPtr getRuntimeOptionDef(const std::string &space, const uint16_t code)
Returns runtime (non-standard) option definition by space and option code.
Definition libdhcp++.cc:191
static size_t unpackOptions6(const OptionBuffer &buf, const std::string &option_space, isc::dhcp::OptionCollection &options, size_t *relay_msg_offset=0, size_t *relay_msg_len=0)
Parses provided buffer as DHCPv6 options and creates Option objects.
Definition libdhcp++.cc:313
static void packOptions6(isc::util::OutputBuffer &buf, const isc::dhcp::OptionCollection &options)
Stores DHCPv6 options in a buffer.
static const OptionDefinition & DHO_STATUS_CODE_DEF()
Get definition of DHO_STATUS_CODE option.
static OptionDefinitionPtr getLastResortOptionDef(const std::string &space, const uint16_t code)
Returns last resort option definition by space and option code.
Definition libdhcp++.cc:249
static size_t unpackVendorOptions4(const uint32_t vendor_id, const OptionBuffer &buf, isc::dhcp::OptionCollection &options)
Parses provided buffer as DHCPv4 vendor options and creates Option objects.
Definition libdhcp++.cc:904
Class of option definition space container.
Base class representing a DHCP option definition.
Universe
defines option universe DHCPv4 or DHCPv6
Definition option.h:83
OptionPtr Factory(Option::Universe u, uint16_t type, const OptionBuffer &buf)
a factory function prototype
Definition option.h:96
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
This class implements set/commit mechanism for a single object.
ScopedPktOptionsCopy< Pkt4 > ScopedPkt4OptionsCopy
A pointer to a ScopedPktOptionsCopy object instantiated using Pkt4.
Definition libdhcp++.h:26
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition option.h:40
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
std::map< std::string, OptionDefContainerPtr > OptionDefContainers
Container that holds option definitions for various option spaces.
std::shared_ptr< ScopedSubOptionsCopy > ScopedOptionsCopyPtr
A pointer to a ScopedSubOptionsCopy object.
Definition libdhcp++.h:30
ScopedPktOptionsCopy< Pkt6 > ScopedPkt6OptionsCopy
A pointer to a ScopedPktOptionsCopy object instantiated using Pkt6.
Definition libdhcp++.h:28
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
std::vector< ScopedOptionsCopyPtr > ScopedOptionsCopyContainer
A container of ScopedOptionsCopyPtr objects.
Definition libdhcp++.h:32
boost::shared_ptr< OptionDefContainer > OptionDefContainerPtr
Pointer to an option definition container.
Defines the logger used by the top-level component of kea-lfc.
ScopedOptionsCopyContainer scoped_options_
The container.
Definition libdhcp++.h:49