Commit 14620323 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[1238] Pkt4 now stores input data (a workaround for limitation of InputBuffer)

parent 660cf410
......@@ -47,7 +47,6 @@ Pkt4::Pkt4(uint8_t msg_type, uint32_t transid)
yiaddr_(DEFAULT_ADDRESS),
siaddr_(DEFAULT_ADDRESS),
giaddr_(DEFAULT_ADDRESS),
bufferIn_(NULL, 0), // not used, this is TX packet
bufferOut_(DHCPV4_PKT_HDR_LEN),
msg_type_(msg_type)
{
......@@ -73,7 +72,6 @@ Pkt4::Pkt4(const uint8_t* data, size_t len)
yiaddr_(DEFAULT_ADDRESS),
siaddr_(DEFAULT_ADDRESS),
giaddr_(DEFAULT_ADDRESS),
bufferIn_(data, len),
bufferOut_(0), // not used, this is RX packet
msg_type_(DHCPDISCOVER)
{
......@@ -82,6 +80,9 @@ Pkt4::Pkt4(const uint8_t* data, size_t len)
<< " received, at least " << DHCPV4_PKT_HDR_LEN
<< "is expected");
}
data_.resize(len);
memcpy(&data_[0], data, len);
}
size_t
......@@ -121,31 +122,35 @@ Pkt4::pack() {
}
bool
Pkt4::unpack() {
if (bufferIn_.getLength()<DHCPV4_PKT_HDR_LEN) {
// input buffer (used during message reception)
isc::util::InputBuffer bufferIn(&data_[0], data_.size());
if (bufferIn.getLength()<DHCPV4_PKT_HDR_LEN) {
isc_throw(OutOfRange, "Received truncated DHCPv4 packet (len="
<< bufferIn_.getLength() << " received, at least "
<< bufferIn.getLength() << " received, at least "
<< DHCPV4_PKT_HDR_LEN << "is expected");
}
op_ = bufferIn_.readUint8();
htype_ = bufferIn_.readUint8();
hlen_ = bufferIn_.readUint8();
hops_ = bufferIn_.readUint8();
transid_ = bufferIn_.readUint32();
secs_ = bufferIn_.readUint16();
flags_ = bufferIn_.readUint16();
ciaddr_ = IOAddress(bufferIn_.readUint32());
yiaddr_ = IOAddress(bufferIn_.readUint32());
siaddr_ = IOAddress(bufferIn_.readUint32());
giaddr_ = IOAddress(bufferIn_.readUint32());
bufferIn_.readData(chaddr_, MAX_CHADDR_LEN);
bufferIn_.readData(sname_, MAX_SNAME_LEN);
bufferIn_.readData(file_, MAX_FILE_LEN);
size_t opts_len = bufferIn_.getLength() - bufferIn_.getPosition();
op_ = bufferIn.readUint8();
htype_ = bufferIn.readUint8();
hlen_ = bufferIn.readUint8();
hops_ = bufferIn.readUint8();
transid_ = bufferIn.readUint32();
secs_ = bufferIn.readUint16();
flags_ = bufferIn.readUint16();
ciaddr_ = IOAddress(bufferIn.readUint32());
yiaddr_ = IOAddress(bufferIn.readUint32());
siaddr_ = IOAddress(bufferIn.readUint32());
giaddr_ = IOAddress(bufferIn.readUint32());
bufferIn.readData(chaddr_, MAX_CHADDR_LEN);
bufferIn.readData(sname_, MAX_SNAME_LEN);
bufferIn.readData(file_, MAX_FILE_LEN);
size_t opts_len = bufferIn.getLength() - bufferIn.getPosition();
vector<uint8_t> optsBuffer;
// fist use of readVector
bufferIn_.readVector(optsBuffer, opts_len);
bufferIn.readVector(optsBuffer, opts_len);
LibDHCP::unpackOptions4(optsBuffer, options_);
return (true);
......
......@@ -396,14 +396,15 @@ protected:
// end of real DHCPv4 fields
/// input buffer (used during message reception)
/// Note that it must be modifiable as hooks can modify incoming buffer),
/// thus OutputBuffer, not InputBuffer
isc::util::InputBuffer bufferIn_;
/// output buffer (used during message
isc::util::OutputBuffer bufferOut_;
// that's the data of input buffer used in RX packet. Note that
// InputBuffer does not store the data itself, but just expects that
// data will be valid for the whole life of InputBuffer. Therefore we
// need to keep the data around.
std::vector<uint8_t> data_;
/// message type (e.g. 1=DHCPDISCOVER)
/// TODO: this will eventually be replaced with DHCP Message Type
/// option (option 53)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment