Kea  2.1.7-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 
220  static void packOptions4(isc::util::OutputBuffer& buf,
221  const isc::dhcp::OptionCollection& options,
222  bool top = false, bool check = true);
223 
233  static bool splitOptions4(isc::dhcp::OptionCollection& options,
234  ScopedOptionsCopyContainer& scopedOptions,
235  uint32_t used = 0);
236 
251  static void packOptions6(isc::util::OutputBuffer& buf,
252  const isc::dhcp::OptionCollection& options);
253 
283  static size_t unpackOptions6(const OptionBuffer& buf,
284  const std::string& option_space,
286  size_t* relay_msg_offset = 0,
287  size_t* relay_msg_len = 0);
288 
295  static bool fuseOptions4(isc::dhcp::OptionCollection& options);
296 
316  static size_t unpackOptions4(const OptionBuffer& buf,
317  const std::string& option_space,
319  std::list<uint16_t>& deferred,
320  bool flexible_pad_end = false);
321 
330  static void OptionFactoryRegister(Option::Universe u,
331  uint16_t type,
332  Option::Factory * factory);
333 
341  static const OptionDefContainerPtr getVendorOptionDefs(Option::Universe u,
342  const uint32_t vendor_id);
343 
359  static size_t unpackVendorOptions6(const uint32_t vendor_id,
360  const OptionBuffer& buf,
361  isc::dhcp::OptionCollection& options);
362 
377  static size_t unpackVendorOptions4(const uint32_t vendor_id,
378  const OptionBuffer& buf,
379  isc::dhcp::OptionCollection& options);
380 
381 
391  static void setRuntimeOptionDefs(const OptionDefSpaceContainer& defs);
392 
394  static void clearRuntimeOptionDefs();
395 
397  static void revertRuntimeOptionDefs();
398 
400  static void commitRuntimeOptionDefs();
401 
415  static uint32_t optionSpaceToVendorId(const std::string& option_space);
416 
417 private:
418 
426  static bool initOptionDefs();
427 
429  static bool initialized_;
430 
432  static FactoryMap v4factories_;
433 
435  static FactoryMap v6factories_;
436 
438  static OptionDefContainers option_defs_;
439 
441  static util::StagedValue<OptionDefSpaceContainer> runtime_option_defs_;
442 };
443 
444 }
445 }
446 
447 #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:856
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