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();
122 << remote_addr->hwaddr_.size() <<
" when constructing"
123 <<
" an ethernet frame header; expected size is"
125 }
else if (!pkt->isRelayed() &&
130 out_buf.
writeData(&remote_addr->hwaddr_[0],
143 HWAddrPtr local_addr = pkt->getLocalHWAddr();
146 out_buf.
writeData(&local_addr->hwaddr_[0],
150 << local_addr->hwaddr_.size() <<
" when constructing"
151 <<
" an ethernet frame header; expected size is"
169 out_buf.
writeUint16(28 + pkt->getBuffer().getLength());
175 out_buf.
writeUint32(pkt->getLocalAddr().toUint32());
176 out_buf.
writeUint32(pkt->getRemoteAddr().toUint32());
181 uint32_t udp_len = 8 + pkt->getBuffer().getLength();
188 uint16_t pseudo_hdr_checksum =
190 8, IPPROTO_UDP + udp_len);
193 uint16_t ip_checksum = ~calcChecksum(out_buf.
getData()
208 uint16_t udp_checksum =
211 pkt->getBuffer().getLength(),
212 pseudo_hdr_checksum));
218calcChecksum(
const uint8_t* buf,
const uint32_t buf_size, uint32_t sum) {
220 for (i = 0; i < (buf_size & ~1U); i += 2) {
221 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)
static const uint16_t FLAG_BROADCAST_MASK
Mask for the value of flags field in the DHCPv4 message to check whether client requested broadcast r...
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
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 writeUint16At(uint16_t data, size_t position)
Write an unsigned 16-bit integer in host byte order at the specified position of the buffer in networ...
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.
const uint8_t * getData() const
Return a pointer to the head of the data stored in the buffer.
size_t getLength() const
Return the length of data written 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.