11#include <boost/static_assert.hpp>
15#include <netinet/in_systm.h>
16#include <netinet/ip.h>
30 <<
"packet is invalid, expected at least "
31 << ETHERNET_HEADER_LEN <<
" bytes, received "
50 std::vector<uint8_t> dest_addr;
54 std::vector<uint8_t> src_addr;
67 <<
"received packet is invalid, expected at least "
68 << MIN_IP_HEADER_LEN + UDP_HEADER_LEN
79 BOOST_STATIC_ASSERT(IP_SRC_ADDR_OFFSET < MIN_IP_HEADER_LEN);
90 <<
" lower than 5 words. The length of the received header is "
91 <<
static_cast<unsigned>(ip_len) <<
".");
112 buf.
setPosition(start_pos + ip_len * 4 + UDP_HEADER_LEN);
118 HWAddrPtr remote_addr = pkt->getRemoteHWAddr();
121 out_buf.
writeData(&remote_addr->hwaddr_[0],
125 << remote_addr->hwaddr_.size() <<
" when constructing"
126 <<
" an ethernet frame header; expected size is"
139 HWAddrPtr local_addr = pkt->getLocalHWAddr();
142 out_buf.
writeData(&local_addr->hwaddr_[0],
146 << local_addr->hwaddr_.size() <<
" when constructing"
147 <<
" an ethernet frame header; expected size is"
165 out_buf.
writeUint16(28 + pkt->getBuffer().getLength());
171 out_buf.
writeUint32(pkt->getLocalAddr().toUint32());
172 out_buf.
writeUint32(pkt->getRemoteAddr().toUint32());
177 uint32_t udp_len = 8 + pkt->getBuffer().getLength();
184 uint16_t pseudo_hdr_checksum =
186 8, IPPROTO_UDP + udp_len);
189 uint16_t ip_checksum = ~calcChecksum(
static_cast<const uint8_t*
>(out_buf.
getData())
204 uint16_t udp_checksum =
205 ~calcChecksum(
static_cast<const uint8_t*
>(out_buf.
getData()) + out_buf.
getLength() - 6, 6,
206 calcChecksum(
static_cast<const uint8_t*
>(pkt->getBuffer().getData()),
207 pkt->getBuffer().getLength(),
208 pseudo_hdr_checksum));
214calcChecksum(
const uint8_t* buf,
const uint32_t buf_size, uint32_t sum) {
216 for (i = 0; i < (buf_size & ~1U); i += 2) {
217 uint16_t chunk = buf[i] << 8 | buf[i + 1];
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
void writeUint16At(uint16_t data, size_t pos)
Write an unsigned 16-bit integer in host byte order at the specified position of the buffer in networ...
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order.
size_t getLength() const
Return the length of data written in the buffer.
const void * getData() const
Return a pointer to the head of the data stored in the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
void decodeEthernetHeader(InputBuffer &buf, Pkt4Ptr &pkt)
Decode the Ethernet header.
void writeEthernetHeader(const Pkt4Ptr &pkt, OutputBuffer &out_buf)
Writes ethernet frame header into a buffer.
void decodeIpUdpHeader(InputBuffer &buf, Pkt4Ptr &pkt)
Decode IP and UDP header.
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
uint16_t calcChecksum(const uint8_t *buf, const uint32_t buf_size, uint32_t sum)
Calculates checksum for provided buffer.
void writeIpUdpHeader(const Pkt4Ptr &pkt, util::OutputBuffer &out_buf)
Writes both IP and UDP header into output buffer.
Defines the logger used by the top-level component of kea-lfc.
static const size_t ETHERNET_HWADDR_LEN
Size of an ethernet hardware address.