Kea  2.3.3-git
libdhcp++.h
Go to the documentation of this file.
1 // Copyright (C) 2011-2022 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 
10 #include <dhcp/option_definition.h>
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 
22 namespace isc {
23 namespace dhcp {
24 
30 typedef std::shared_ptr<ScopedSubOptionsCopy> ScopedOptionsCopyPtr;
32 typedef std::vector<ScopedOptionsCopyPtr> ScopedOptionsCopyContainer;
33 
37  }
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 
49  ScopedOptionsCopyContainer scoped_options_;
50 };
51 
52 class LibDHCP {
53 
54 public:
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 
97  static OptionDefinitionPtr getVendorOptionDef(const Option::Universe u,
98  const uint32_t vendor_id,
99  const uint16_t code);
100 
110  static OptionDefinitionPtr getVendorOptionDef(const Option::Universe u,
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 
194  static isc::dhcp::OptionPtr optionFactory(isc::dhcp::Option::Universe u,
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  static bool fuseOptions4(isc::dhcp::OptionCollection& options);
301 
321  static size_t unpackOptions4(const OptionBuffer& buf,
322  const std::string& option_space,
324  std::list<uint16_t>& deferred,
325  bool flexible_pad_end = false);
326 
335  static void OptionFactoryRegister(Option::Universe u,
336  uint16_t type,
337  Option::Factory * factory);
338 
346  static const OptionDefContainerPtr getVendorOptionDefs(Option::Universe u,
347  const uint32_t vendor_id);
348 
364  static size_t unpackVendorOptions6(const uint32_t vendor_id,
365  const OptionBuffer& buf,
366  isc::dhcp::OptionCollection& options);
367 
382  static size_t unpackVendorOptions4(const uint32_t vendor_id,
383  const OptionBuffer& buf,
384  isc::dhcp::OptionCollection& options);
385 
386 
396  static void setRuntimeOptionDefs(const OptionDefSpaceContainer& defs);
397 
399  static void clearRuntimeOptionDefs();
400 
402  static void revertRuntimeOptionDefs();
403 
405  static void commitRuntimeOptionDefs();
406 
420  static uint32_t optionSpaceToVendorId(const std::string& option_space);
421 
422 private:
423 
431  static bool initOptionDefs();
432 
434  static bool initialized_;
435 
437  static FactoryMap v4factories_;
438 
440  static FactoryMap v6factories_;
441 
443  static OptionDefContainers option_defs_;
444 
446  static util::StagedValue<OptionDefSpaceContainer> runtime_option_defs_;
447 };
448 
449 }
450 }
451 
452 #endif // LIBDHCP_H
ScopedPktOptionsCopy< Pkt4 > ScopedPkt4OptionsCopy
A pointer to a ScopedPktOptionsCopy object instantiated using Pkt4.
Definition: libdhcp++.h:26
boost::shared_ptr< Option > OptionPtr
Definition: option.h:36
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:83
ScopedPktOptionsCopy< Pkt6 > ScopedPkt6OptionsCopy
A pointer to a ScopedPktOptionsCopy object instantiated using Pkt6.
Definition: libdhcp++.h:28
std::vector< ScopedOptionsCopyPtr > ScopedOptionsCopyContainer
A container of ScopedOptionsCopyPtr objects.
Definition: libdhcp++.h:32
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition: option.h:24
Class of option definition space container.
std::map< unsigned short, Option::Factory * > FactoryMap
Map of factory functions.
Definition: libdhcp++.h:57
boost::shared_ptr< OptionDefContainer > OptionDefContainerPtr
Pointer to an option definition container.
ScopedOptionsCopyContainer scoped_options_
The container.
Definition: libdhcp++.h:49
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition: option.h:40
RAII object enabling duplication of the stored options and restoring the original options on destruct...
Definition: pkt.h:890
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
std::map< std::string, OptionDefContainerPtr > OptionDefContainers
Container that holds option definitions for various option spaces.
Defines the logger used by the top-level component of kea-lfc.
std::shared_ptr< ScopedSubOptionsCopy > ScopedOptionsCopyPtr
A pointer to a ScopedSubOptionsCopy object.
Definition: libdhcp++.h:30
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
This class implements set/commit mechanism for a single object.
Definition: staged_value.h:32
OptionPtr Factory(Option::Universe u, uint16_t type, const OptionBuffer &buf)
a factory function prototype
Definition: option.h:96