Kea: protocol_util.h Source File

| Kea 3.2.0-git

protocol_util.h
Go to the documentation of this file.
1// Copyright (C) 2013-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#ifndef PROTOCOL_UTIL_H
8#define PROTOCOL_UTIL_H
9
10#include <dhcp/pkt4.h>
11#include <util/buffer.h>
12
13#include <stdint.h>
14
15namespace isc {
16namespace dhcp {
17
22 class InvalidPacketHeader : public Exception {
23public:
24 InvalidPacketHeader(const char* file, size_t line, const char* what) :
25 isc::Exception(file, line, what) { }
26};
27
29static const size_t ETHERNET_HEADER_LEN = 14;
32static const size_t ETHERNET_PACKET_TYPE_OFFSET = 12;
40static const uint16_t ETHERNET_TYPE_IP = 0x0800;
41
43static const size_t MIN_IP_HEADER_LEN = 20;
45static const size_t IP_FLAGS_OFFSET = 6;
48static const size_t IP_PROTO_TYPE_OFFSET = 9;
50static const size_t IP_SRC_ADDR_OFFSET = 12;
52static const size_t IP_DEST_ADDR_OFFSET = 16;
53
55static const size_t UDP_HEADER_LEN = 8;
57static const size_t UDP_DEST_PORT = 2;
58
76void decodeEthernetHeader(util::InputBuffer& buf, Pkt4Ptr& pkt);
77
95void decodeIpUdpHeader(util::InputBuffer& buf, Pkt4Ptr& pkt);
96
105void writeEthernetHeader(const Pkt4Ptr& pkt,
106 util::OutputBuffer& out_buf);
107
121void writeIpUdpHeader(const Pkt4Ptr& pkt, util::OutputBuffer& out_buf);
122
142uint16_t calcChecksum(const uint8_t* buf, const uint32_t buf_size,
143 uint32_t sum = 0);
144
145}
146}
147#endif // PROTOCOL_UTIL_H
Pkt4Ptr
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:556
buffer.h
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::dhcp::InvalidPacketHeader::InvalidPacketHeader
InvalidPacketHeader(const char *file, size_t line, const char *what)
Definition protocol_util.h:24
isc::util::InputBuffer
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::decodeEthernetHeader
void decodeEthernetHeader(InputBuffer &buf, Pkt4Ptr &pkt)
Decode the Ethernet header.
Definition protocol_util.cc:24
isc::dhcp::writeEthernetHeader
void writeEthernetHeader(const Pkt4Ptr &pkt, OutputBuffer &out_buf)
Writes ethernet frame header into a buffer.
Definition protocol_util.cc:117
isc::dhcp::decodeIpUdpHeader
void decodeIpUdpHeader(InputBuffer &buf, Pkt4Ptr &pkt)
Decode IP and UDP header.
Definition protocol_util.cc:62
isc::dhcp::calcChecksum
uint16_t calcChecksum(const uint8_t *buf, const uint32_t buf_size, uint32_t sum)
Calculates checksum for provided buffer.
Definition protocol_util.cc:219
isc::dhcp::writeIpUdpHeader
void writeIpUdpHeader(const Pkt4Ptr &pkt, util::OutputBuffer &out_buf)
Writes both IP and UDP header into output buffer.
Definition protocol_util.cc:166
isc::util::file
Definition filesystem.cc:29
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
pkt4.h