Kea 2.7.6
option6_ia.cc
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#include <config.h>
8#include <dhcp/dhcp6.h>
9#include <dhcp/libdhcp++.h>
10#include <dhcp/option6_ia.h>
11#include <dhcp/option_space.h>
13#include <util/io.h>
14
15#include <arpa/inet.h>
16#include <sstream>
17#include <stdint.h>
18
19using namespace std;
20using namespace isc::util;
21
22namespace isc {
23namespace dhcp {
24
25Option6IA::Option6IA(uint16_t type, uint32_t iaid)
26 :Option(Option::V6, type), iaid_(iaid), t1_(0), t2_(0) {
27
28 // IA_TA has different layout than IA_NA and IA_PD. We can't use this class
29 if (type == D6O_IA_TA) {
30 isc_throw(BadValue, "Can't use Option6IA for IA_TA as it has "
31 "a different layout");
32 }
33
35}
36
39 :Option(Option::V6, type) {
40
41 // IA_TA has different layout than IA_NA and IA_PD. We can't use this class
42 if (type == D6O_IA_TA) {
43 isc_throw(BadValue, "Can't use Option6IA for IA_TA as it has "
44 "a different layout");
45 }
46
48
49 unpack(begin, end);
50}
51
54 return (cloneInternal<Option6IA>());
55}
56
58 buf.writeUint16(type_);
60 buf.writeUint32(iaid_);
61 buf.writeUint32(t1_);
62 buf.writeUint32(t2_);
63
64 packOptions(buf);
65}
66
69 // IA_NA and IA_PD have 12 bytes content (iaid, t1, t2 fields)
70 // followed by 0 or more sub-options.
71 if (distance(begin, end) < OPTION6_IA_LEN) {
72 isc_throw(OutOfRange, "Option " << type_ << " truncated");
73 }
74 iaid_ = readUint32(&(*begin), distance(begin, end));
75 begin += sizeof(uint32_t);
76 t1_ = readUint32(&(*begin), distance(begin, end));
77 begin += sizeof(uint32_t);
78
79 t2_ = readUint32(&(*begin), distance(begin, end));
80 begin += sizeof(uint32_t);
81
82 unpackOptions(OptionBuffer(begin, end));
83}
84
85std::string Option6IA::toText(int indent) const {
86 stringstream output;
87
88 switch(getType()) {
89 case D6O_IA_NA:
90 output << headerToText(indent, "IA_NA");
91 break;
92 case D6O_IA_PD:
93 output << headerToText(indent, "IA_PD");
94 break;
95 default:
96 output << headerToText(indent);
97 }
98
99 output << ": iaid=" << iaid_ << ", t1=" << t1_ << ", t2=" << t2_
100 << suboptionsToText(indent + 2);
101
102 return (output.str());
103}
104
105uint16_t Option6IA::len() const {
106
107 uint16_t length = OPTION6_HDR_LEN /*header (4)*/ +
108 OPTION6_IA_LEN /* option content (12) */;
109
110 // length of all suboptions
111 for (auto const& it : options_) {
112 length += it.second->len();
113 }
114 return (length);
115}
116
117} // end of isc::dhcp namespace
118} // end of isc namespace
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
uint32_t iaid_
keeps IA identifier
Definition option6_ia.h:109
static const size_t OPTION6_IA_LEN
Length of IA_NA and IA_PD content.
Definition option6_ia.h:26
uint32_t t1_
keeps T1 timer value
Definition option6_ia.h:112
virtual uint16_t len() const
returns complete length of option
Option6IA(uint16_t type, uint32_t iaid)
Ctor, used for constructed options, usually during transmission.
Definition option6_ia.cc:25
virtual OptionPtr clone() const
Copies this option and returns a pointer to the copy.
Definition option6_ia.cc:53
void pack(isc::util::OutputBuffer &buf, bool check=true) const
Writes option in wire-format to buf, returns pointer to first unused byte after stored option.
Definition option6_ia.cc:57
virtual std::string toText(int indent=0) const
Provides human readable text representation.
Definition option6_ia.cc:85
uint32_t t2_
keeps T2 timer value
Definition option6_ia.h:115
virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end)
Parses received buffer.
Definition option6_ia.cc:67
uint16_t type_
option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
Definition option.h:597
std::string headerToText(const int indent=0, const std::string &type_name="") const
Returns option header in the textual format.
Definition option.cc:294
std::string suboptionsToText(const int indent=0) const
Returns collection of suboptions in the textual format.
Definition option.cc:313
void setEncapsulatedSpace(const std::string &encapsulated_space)
Sets the name of the option space encapsulated by this option.
Definition option.h:442
uint16_t getType() const
Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
Definition option.h:300
void unpackOptions(const OptionBuffer &buf)
Builds a collection of sub options from the buffer.
Definition option.cc:155
void packOptions(isc::util::OutputBuffer &buf, bool check=true) const
Store sub options in a buffer.
Definition option.cc:136
static const size_t OPTION6_HDR_LEN
length of any DHCPv6 option header
Definition option.h:87
OptionCollection options_
collection for storing suboptions
Definition option.h:603
OptionPtr cloneInternal() const
Copies this option and returns a pointer to the copy.
Definition option.h:504
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
Definition buffer.h:498
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order.
Definition buffer.h:528
@ D6O_IA_TA
Definition dhcp6.h:24
@ D6O_IA_NA
Definition dhcp6.h:23
@ D6O_IA_PD
Definition dhcp6.h:45
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
OptionBuffer::const_iterator OptionBufferConstIter
const_iterator for walking over OptionBuffer
Definition option.h:30
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
uint32_t readUint32(void const *const buffer, size_t const length)
uint32_t wrapper over readUint.
Definition io.h:82
Defines the logger used by the top-level component of kea-lfc.
#define DHCP6_OPTION_SPACE