Kea 3.2.1-git
pkt_transform.h
Go to the documentation of this file.
1// Copyright (C) 2012-2026 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 PKT_TRANSFORM_H
8#define PKT_TRANSFORM_H
9
11
12#include <dhcp/option.h>
13
14namespace isc {
15namespace perfdhcp {
16
32public:
33
60 static bool pack(const dhcp::Option::Universe universe,
61 const dhcp::OptionBuffer& in_buffer,
62 const dhcp::OptionCollection& options,
63 const size_t transid_offset,
64 const uint32_t transid,
65 util::OutputBuffer& out_buffer);
66
82 static bool unpack(const dhcp::Option::Universe universe,
83 const dhcp::OptionBuffer& in_buffer,
84 const dhcp::OptionCollection& options,
85 const size_t transid_offset,
86 uint32_t& transid);
87
97 static void writeAt(dhcp::OptionBuffer& in_buffer, size_t dest_pos,
98 std::vector<uint8_t>::iterator first,
99 std::vector<uint8_t>::iterator last);
100
110 template<typename T>
111 static void writeValueAt(dhcp::OptionBuffer& in_buffer, size_t dest_pos,
112 T val) {
113 if (in_buffer.size() < dest_pos + sizeof(T)) {
114 isc_throw(isc::OutOfRange, "writeValueAt: pos=" << dest_pos
115 << ", length=" << sizeof(T)
116 << ", size=" << in_buffer.size());
117 }
118 // @todo consider replacing the loop with switch statement
119 // checking sizeof(T).
120 for (size_t i = 0; i < sizeof(T); ++i) {
121 in_buffer[dest_pos + i] = (val >> 8 * (sizeof(T) - i - 1)) & 0xFF;
122 }
123 }
124
125private:
138 static void packOptions(const dhcp::OptionBuffer& in_buffer,
139 const dhcp::OptionCollection& options,
140 util::OutputBuffer& out_buffer);
141
162 static void unpackOptions(const dhcp::OptionBuffer& in_buffer,
163 const dhcp::OptionCollection& options);
164
165};
166
167} // namespace perfdhcp
168} // namespace isc
169
170#endif // PKT_TRANSFORM_H
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
Universe
defines option universe DHCPv4 or DHCPv6
Definition option.h:90
Read and write raw data to DHCP packets.
static void writeValueAt(dhcp::OptionBuffer &in_buffer, size_t dest_pos, T val)
Replace contents of one vector with a value of type T.
static bool unpack(const dhcp::Option::Universe universe, const dhcp::OptionBuffer &in_buffer, const dhcp::OptionCollection &options, const size_t transid_offset, uint32_t &transid)
Handles selective binary packet parsing.
static void writeAt(dhcp::OptionBuffer &in_buffer, size_t dest_pos, std::vector< uint8_t >::iterator first, std::vector< uint8_t >::iterator last)
Replace contents of buffer with vector.
static bool pack(const dhcp::Option::Universe universe, const dhcp::OptionBuffer &in_buffer, const dhcp::OptionCollection &options, const size_t transid_offset, const uint32_t transid, util::OutputBuffer &out_buffer)
Prepares on-wire format from raw buffer.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition option.h:40
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
Defines the logger used by the top-level component of kea-lfc.