size_t offset = 0;
size_t last_offset = 0;
+ // Special case when option_space is dhcp4.
+ bool space_is_dhcp4 = (option_space == DHCP4_OPTION_SPACE);
+
// Get the list of standard option definitions.
const OptionDefContainerPtr& option_defs = LibDHCP::getOptionDefs(option_space);
// Runtime option definitions for non standard option space and if
uint8_t opt_type = buf[offset++];
// DHO_END is a special, one octet long option
- if (opt_type == DHO_END) {
+ if (space_is_dhcp4 && (opt_type == DHO_END)) {
// just return. Don't need to add DHO_END option
// Don't return offset because it makes this condition
// and partial parsing impossible to recognize.
// DHO_PAD is just a padding after DHO_END. Let's continue parsing
// in case we receive a message without DHO_END.
- if (opt_type == DHO_PAD)
+ if (space_is_dhcp4 && (opt_type == DHO_PAD)) {
continue;
+ }
if (offset + 1 > buf.size()) {
// We peeked at the option header of the next option, but
// rather than the dropping the whole packet. We do not have a
// way to log this from here but meh... a PCAP will show it arriving,
// and we know we drop it.
- if (opt_len == 0 && opt_type == DHO_HOST_NAME) {
+ if (space_is_dhcp4 && opt_len == 0 && opt_type == DHO_HOST_NAME) {
continue;
}
-// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Option::Option(Universe u, uint16_t type)
:universe_(u), type_(type) {
-
- // END option (type 255 is forbidden as well)
- if ((u == V4) && ((type == 0) || (type > 254))) {
- isc_throw(BadValue, "Can't create V4 option of type "
- << type << ", V4 options are in range 1..254");
- }
+ check();
}
Option::Option(Universe u, uint16_t type, const OptionBuffer& data)
EXPECT_NO_THROW(opt.reset());
// V4 options have type 0...255
- EXPECT_THROW(opt.reset(new Option(Option::V4, 256)), BadValue);
-
- // 0 is a special PAD option
- EXPECT_THROW(opt.reset(new Option(Option::V4, 0)), BadValue);
-
- // 255 is a special END option
- EXPECT_THROW(opt.reset(new Option(Option::V4, 255)), BadValue);
+ EXPECT_THROW(opt.reset(new Option(Option::V4, 256)), OutOfRange);
}
const uint8_t dummyPayload[] =
return (Optional<uint32_t>());
}
- if (code == 0) {
- isc_throw(DhcpConfigError, "option code must not be zero "
- "(" << getPosition("code", parent) << ")");
-
- } else if (address_family_ == AF_INET &&
- code > std::numeric_limits<uint8_t>::max()) {
+ if (address_family_ == AF_INET &&
+ code > std::numeric_limits<uint8_t>::max()) {
isc_throw(DhcpConfigError, "invalid option code '" << code
- << "', it must not be greater than '"
+ << "', it must not be greater than '"
<< static_cast<int>(std::numeric_limits<uint8_t>::max())
<< "' (" << getPosition("code", parent)
<< ")");
} else if (address_family_ == AF_INET6 &&
code > std::numeric_limits<uint16_t>::max()) {
isc_throw(DhcpConfigError, "invalid option code '" << code
- << "', it must not exceed '"
+ << "', it must not exceed '"
<< std::numeric_limits<uint16_t>::max()
<< "' (" << getPosition("code", parent)
<< ")");