summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcp/pkt4.cc
diff options
context:
space:
mode:
authorTomek Mrugalski <tomasz@isc.org>2014-10-06 19:36:20 +0200
committerTomek Mrugalski <tomasz@isc.org>2014-10-06 19:36:20 +0200
commiteff16335a8366735fb7b5296b8aed0c529a6faff (patch)
tree931d67a9739542e305f599d230a4314dde5ee2c4 /src/lib/dhcp/pkt4.cc
parent[3546] Corrected a typo. (diff)
downloadkea-eff16335a8366735fb7b5296b8aed0c529a6faff.tar.xz
kea-eff16335a8366735fb7b5296b8aed0c529a6faff.zip
[3546] Another changes after review:
- (offset - 4) explained better - Modified Dhcpv6Srv::unpackOptions() - setHWAddrMember() mac_addr renamed (this time for real) - Commented out unused variables - RelayInfo now uses DEFAULT_ADDRESS6 in ctor - LibDHCP::unpackOptions6 and callback now used uniformly - Clarified that ERO is Echo Request Option (RFC4994) - unpackOptions4 in libdhcp and Dhcp4Srv no longer throw when truncated option is received.
Diffstat (limited to 'src/lib/dhcp/pkt4.cc')
-rw-r--r--src/lib/dhcp/pkt4.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc
index 999eace5f6..1d10d416dc 100644
--- a/src/lib/dhcp/pkt4.cc
+++ b/src/lib/dhcp/pkt4.cc
@@ -210,17 +210,34 @@ Pkt4::unpack() {
// Use readVector because a function which parses option requires
// a vector as an input.
+ size_t offset;
buffer_in.readVector(opts_buffer, opts_len);
if (callback_.empty()) {
- LibDHCP::unpackOptions4(opts_buffer, "dhcp4", options_);
+ offset = LibDHCP::unpackOptions4(opts_buffer, "dhcp4", options_);
} else {
// The last two arguments are set to NULL because they are
// specific to DHCPv6 options parsing. They are unused for
// DHCPv4 case. In DHCPv6 case they hold are the relay message
// offset and length.
- callback_(opts_buffer, "dhcp4", options_, NULL, NULL);
+ offset = callback_(opts_buffer, "dhcp4", options_, NULL, NULL);
}
+ // If offset is not equal to the size, then something is wrong here. We
+ // either parsed past input buffer (bug in our code) or we haven't parsed
+ // everything (received trailing garbage or truncated option).
+ //
+ // Invoking Jon Postel's law here: be conservative in what you send, and be
+ // liberal in what you accept. There's no easy way to log something from
+ // libdhcp++ library, so we just choose to be silent about remaining
+ // bytes. We also need to quell compiler warning about unused offset
+ // variable.
+ //
+ // if (offset != size) {
+ // isc_throw(BadValue, "Received DHCPv6 buffer of size " << size
+ // << ", were able to parse " << offset << " bytes.");
+ // }
+ (void)offset;
+
// @todo check will need to be called separately, so hooks can be called
// after the packet is parsed, but before its content is verified
check();