Kea  2.1.7-git
cfg_4o6.cc
Go to the documentation of this file.
1 // Copyright (C) 2017-2019 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 #include <config.h>
8 
9 #include <dhcp/option.h>
10 #include <dhcpsrv/cfg_4o6.h>
11 #include <string>
12 #include <string.h>
13 #include <sstream>
14 #include <vector>
15 
16 using namespace isc::data;
17 
18 namespace isc {
19 namespace dhcp {
20 
22 Cfg4o6::toElement() const {
23  ElementPtr result = Element::createMap();
24  // Set 4o6-interface
25  result->set("4o6-interface", Element::create(iface4o6_));
26  // Set 4o6-subnet
27  if (!subnet4o6_.get().first.isV6Zero() || (subnet4o6_.get().second != 128u)) {
28  std::ostringstream oss;
29  oss << subnet4o6_.get().first << "/"
30  << static_cast<unsigned>(subnet4o6_.get().second);
31  result->set("4o6-subnet", Element::create(oss.str()));
32  } else {
33  result->set("4o6-subnet", Element::create(std::string()));
34  }
35  // Set 4o6-interface-id
36  if (interface_id_) {
37  std::vector<uint8_t> bin = interface_id_->toBinary();
38  std::string iid;
39  iid.resize(bin.size());
40  if (!bin.empty()) {
41  std::memcpy(&iid[0], &bin[0], bin.size());
42  }
43  result->set("4o6-interface-id", Element::create(iid));
44  } else {
45  result->set("4o6-interface-id", Element::create(std::string()));
46  }
47  return (result);
48 }
49 
50 } // end of isc::dhcp namespace
51 } // end of isc namespace
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:286
Defines the logger used by the top-level component of kea-lfc.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition: data.cc:241