Kea 2.7.5
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
265
295 static size_t unpackOptions6(const OptionBuffer& buf,
296 const std::string& option_space,
298 size_t* relay_msg_offset = 0,
299 size_t* relay_msg_len = 0);
300
307
327 static size_t unpackOptions4(const OptionBuffer& buf,
328 const std::string& option_space,
330 std::list<uint16_t>& deferred,
331 bool flexible_pad_end = false);
332
342 uint16_t type,
343 Option::Factory * factory);
344
353 const uint32_t vendor_id);
354
370 static size_t unpackVendorOptions6(const uint32_t vendor_id,
371 const OptionBuffer& buf,
373
388 static size_t unpackVendorOptions4(const uint32_t vendor_id,
389 const OptionBuffer& buf,
391
392
402 static void setRuntimeOptionDefs(const OptionDefSpaceContainer& defs);
403
405 static void clearRuntimeOptionDefs();
406
408 static void revertRuntimeOptionDefs();
409
411 static void commitRuntimeOptionDefs();
412
426 static uint32_t optionSpaceToVendorId(const std::string& option_space);
427
430
433
436
439
442
445
448
450 static const OptionDefinition& D6O_LQ_QUERY_DEF();
451
454
457
459 static const OptionDefinition& D6O_NTP_SERVER_DEF();
460
463
465 static const OptionDefinition& D6O_RSOO_DEF();
466
467private:
468
476 static bool initOptionDefs();
477
479 static bool initialized_;
480
482 static FactoryMap v4factories_;
483
485 static FactoryMap v6factories_;
486
488 static OptionDefContainers option_defs_;
489
491 static util::StagedValue<OptionDefSpaceContainer> runtime_option_defs_;
492};
493
494}
495}
496
497#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:471
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_NTP_SERVER_DEF()
Get definition of D6O_NTP_SERVER 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:823
static const OptionDefContainerPtr getOptionDefs(const std::string &space)
Returns collection of option definitions.
Definition libdhcp++.cc:105
static void splitNtpServerOptions6(isc::dhcp::OptionCollection &options)
Split NTP server option to one suboption per instance.
static bool shouldDeferOptionUnpack(const std::string &space, const uint16_t code)
Checks if an option unpacking has to be deferred.
Definition libdhcp++.cc:286
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:293
static void setRuntimeOptionDefs(const OptionDefSpaceContainer &defs)
Copies option definitions created at runtime.
Definition libdhcp++.cc:224
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
Definition libdhcp++.cc:132
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:174
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:277
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:219
static void commitRuntimeOptionDefs()
Commits runtime option definitions.
Definition libdhcp++.cc:248
static void clearRuntimeOptionDefs()
Removes runtime option definitions.
Definition libdhcp++.cc:238
static void extendVendorOptions4(isc::dhcp::OptionCollection &options)
Extend vendor options from fused options in multiple OptionVendor or OptionVendorClass options and ad...
Definition libdhcp++.cc:817
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:243
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:115
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:195
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:317
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:253
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:919
Class of option definition space container.
Base class representing a DHCP option definition.
Universe
defines option universe DHCPv4 or DHCPv6
Definition option.h:90
OptionPtr Factory(Option::Universe u, uint16_t type, const OptionBuffer &buf)
a factory function prototype
Definition option.h:103
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