| Kea 3.0.2-git

pkt_transform.h
Go to the documentation of this file.
1// Copyright (C) 2012-2025 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
10#include <perfdhcp/localized_option.h>
11
12#include <dhcp/option.h>
13
14 namespace isc {
15 namespace perfdhcp {
16
31 class PktTransform {
32 public:
33
59 static bool pack(const dhcp::Option::Universe universe,
60 const dhcp::OptionBuffer& in_buffer,
61 const dhcp::OptionCollection& options,
62 const size_t transid_offset,
63 const uint32_t transid,
64 util::OutputBuffer& out_buffer);
65
81 static bool unpack(const dhcp::Option::Universe universe,
82 const dhcp::OptionBuffer& in_buffer,
83 const dhcp::OptionCollection& options,
84 const size_t transid_offset,
85 uint32_t& transid);
86
95 static void writeAt(dhcp::OptionBuffer& in_buffer, size_t dest_pos,
96 std::vector<uint8_t>::iterator first,
97 std::vector<uint8_t>::iterator last);
98
106 template<typename T>
107 static void writeValueAt(dhcp::OptionBuffer& in_buffer, size_t dest_pos,
108 T val) {
109 // @todo consider replacing the loop with switch statement
110 // checking sizeof(T).
111 for (size_t i = 0; i < sizeof(T); ++i) {
112 in_buffer[dest_pos + i] = (val >> 8 * (sizeof(T) - i - 1)) & 0xFF;
113 }
114 }
115
116 private:
129 static void packOptions(const dhcp::OptionBuffer& in_buffer,
130 const dhcp::OptionCollection& options,
131 util::OutputBuffer& out_buffer);
132
153 static void unpackOptions(const dhcp::OptionBuffer& in_buffer,
154 const dhcp::OptionCollection& options);
155
156};
157
158} // namespace perfdhcp
159} // namespace isc
160
161#endif // PKT_TRANSFORM_H
isc::dhcp::Option::Universe
Universe
defines option universe DHCPv4 or DHCPv6
Definition option.h:90
isc::perfdhcp::PktTransform
Read and write raw data to DHCP packets.
Definition pkt_transform.h:31
isc::perfdhcp::PktTransform::writeValueAt
static void writeValueAt(dhcp::OptionBuffer &in_buffer, size_t dest_pos, T val)
Replace contents of one vector with uint16 value.
Definition pkt_transform.h:107
isc::perfdhcp::PktTransform::unpack
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.
Definition pkt_transform.cc:72
isc::perfdhcp::PktTransform::writeAt
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.
Definition pkt_transform.cc:212
isc::perfdhcp::PktTransform::pack
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.
Definition pkt_transform.cc:29
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
localized_option.h
isc::dhcp::OptionCollection
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
Definition option.h:40
isc::dhcp::OptionBuffer
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
isc::perfdhcp
Definition abstract_scen.h:15
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
option.h