} else if (optarg_text == "multi") {
single_thread_mode_ = false;
} else {
- isc_throw(InvalidParameter, "value of thread mode (-g) '" << optarg << "' is wrong - should be '-g single' or '-g multi'");
+ if (optarg) {
+ isc_throw(InvalidParameter, "value of thread mode (-g) '" << optarg << "' is wrong - should be '-g single' or '-g multi'");
+ } else {
+ isc_throw(InvalidParameter, "value of thread mode (-g) is wrong - should be '-g single' or '-g multi'");
+ }
}
break;
}
}
}
// Set IA_NA
- boost::shared_ptr<Option6IA> opt_ia_na_advertise =
- boost::static_pointer_cast<Option6IA>(advertise_pkt6->getOption(D6O_IA_NA));
+ OptionPtr opt_ia_na_advertise = advertise_pkt6->getOption(D6O_IA_NA);
if (!opt_ia_na_advertise) {
isc_throw(Unexpected, "DHCPv6 IA_NA option not found in received "
"packet");
}
size_t addr_offset = getRequestedIpOffset();
boost::shared_ptr<LocalizedOption>
- opt_ia_na(new LocalizedOption(opt_ia_na_advertise, addr_offset));
+ opt_ia_na(new LocalizedOption(Option::V6, D6O_IA_NA, opt_ia_na_advertise->getData(), addr_offset));
if (!opt_ia_na->valid()) {
isc_throw(BadValue, "Option IA_NA in advertise packet is invalid");
}
EXPECT_EQ("map", Element::typeToName(Element::map));
EXPECT_EQ("null", Element::typeToName(Element::null));
EXPECT_EQ("any", Element::typeToName(Element::any));
- EXPECT_EQ("unknown", Element::typeToName((Element::types)123));
+ EXPECT_EQ("unknown", Element::typeToName(static_cast<Element::types>(123)));
}
TEST(Element, from_and_to_json) {
BackendSelector::UNSPEC(),
const ServerSelector& server_selector =
ServerSelector::ALL()) const {
- int property;
+ int property = 0;
// If the selector is specified, this method will pick the appropriate
// backend and will call getProperty method on this backend. If the
BackendSelector::UNSPEC(),
const ServerSelector& server_selector =
ServerSelector::ALL()) const {
- int property;
+ int property = 0;
+
getPropertyPtrConst<int, const std::string&, int>
(&TestConfigBackend::getProperty, backend_selector, server_selector,
property, property_name, property_value);
// addresses between the cursor and the end of the range have been already
// returned by this function. Therefore we focus on the remaining cursor-1
// addresses. Let's get random address from this sub-range.
- std::uniform_int_distribution<uint64_t> dist(0, static_cast<uint64_t>(cursor_ - 1));
+ uint64_t max_limit = std::numeric_limits<uint64_t>::max();
+ if ((cursor_ - 1) < isc::util::int128_t(max_limit)) {
+ max_limit = static_cast<uint64_t>(cursor_ - 1);
+ }
+ std::uniform_int_distribution<uint64_t> dist(0, max_limit);
auto next_loc = dist(generator_);
IOAddress next_loc_address = IOAddress::IPV4_ZERO_ADDRESS();
if (flag == 0 || (flag & ~HEADERFLAG_MASK) != 0) {
isc_throw(InvalidParameter,
"Message::getHeaderFlag:: Invalid flag is specified: " <<
- "0x" << std::hex << flag);
+ "0x" << std::hex << static_cast<int>(flag));
}
if (on) {
impl_->flags_ |= flag;
void
Message::appendSection(const Section section, const Message& source) {
if (static_cast<int>(section) >= MessageImpl::NUM_SECTIONS) {
- isc_throw(OutOfRange, "Invalid message section: " << section);
+ isc_throw(OutOfRange, "Invalid message section: " << static_cast<int>(section));
}
if (section == SECTION_QUESTION) {
const SectionIterator<RRsetPtr>
Message::beginSection(const Section section) const {
if (static_cast<int>(section) >= MessageImpl::NUM_SECTIONS) {
- isc_throw(OutOfRange, "Invalid message section: " << section);
+ isc_throw(OutOfRange, "Invalid message section: " << static_cast<int>(section));
}
if (section == SECTION_QUESTION) {
isc_throw(InvalidMessageSection,
// Unknown field fails
clearStack();
- ASSERT_NO_THROW(t_.reset(new TokenPkt4(TokenPkt4::FieldType(100))));
+ ASSERT_NO_THROW(t_.reset(new TokenPkt4(static_cast<TokenPkt4::FieldType>(100))));
EXPECT_THROW(t_->evaluate(*pkt4_, values_), EvalTypeError);
// Check that the debug output was correct. Add the strings
// Unknown field fails
clearStack();
- ASSERT_NO_THROW(t_.reset(new TokenPkt6(TokenPkt6::FieldType(100))));
+ ASSERT_NO_THROW(t_.reset(new TokenPkt6(static_cast<TokenPkt6::FieldType>(100))));
EXPECT_THROW(t_->evaluate(*pkt6_, values_), EvalTypeError);
// Check that the debug output was correct. Add the strings
}
stringstream tmp;
- tmp << static_cast<int32_t>(*(reinterpret_cast<int8_t*>(const_cast<char*>(op.data()))));
+ tmp << static_cast<int32_t>(*(reinterpret_cast<int8_t*>(op.data())));
op = tmp.str();
values.push(op);
}
stringstream tmp;
- int16_t value = 0;
- memcpy(&value, op.data(), size);
+ int16_t value = static_cast<int16_t>(readUint16(const_cast<const char*>(op.data()), size));
tmp << value;
op = tmp.str();
values.push(op);
}
stringstream tmp;
- int32_t value = 0;
- memcpy(&value, op.data(), size);
+ int32_t value = static_cast<int32_t>(readUint32(const_cast<const char*>(op.data()), size));
tmp << value;
op = tmp.str();
values.push(op);
}
stringstream tmp;
- tmp << static_cast<uint32_t>(*(reinterpret_cast<uint8_t*>(const_cast<char*>(op.data()))));
+ tmp << static_cast<uint32_t>(*(reinterpret_cast<uint8_t*>(op.data())));
op = tmp.str();
values.push(op);
}
stringstream tmp;
- uint16_t value = 0;
- memcpy(&value, op.data(), size);
+ uint16_t value = readUint16(const_cast<const char*>(op.data()), size);
tmp << value;
op = tmp.str();
values.push(op);
}
stringstream tmp;
- uint32_t value = 0;
- memcpy(&value, op.data(), size);
+ uint32_t value = readUint32(const_cast<const char*>(op.data()), size);
tmp << value;
op = tmp.str();
values.push(op);
TokenRelay4Option::TokenRelay4Option(const uint16_t option_code,
const RepresentationType& rep_type)
- :TokenOption(option_code, rep_type) {
+ : TokenOption(option_code, rep_type) {
}
OptionPtr TokenRelay4Option::getOption(Pkt& pkt) {
break;
default:
- isc_throw(EvalTypeError, "Bad meta data specified: "
- << static_cast<int>(type_) );
+ isc_throw(EvalTypeError, "Bad meta data specified: " << static_cast<int>(type_));
}
if (is_binary) {
type_str = "transid";
break;
default:
- isc_throw(EvalTypeError, "Bad field specified: "
- << static_cast<int>(type_) );
+ isc_throw(EvalTypeError, "Bad field specified: " << static_cast<int>(type_));
}
} catch (const std::bad_cast&) {
break;
}
default:
- isc_throw(EvalTypeError, "Bad field specified: "
- << static_cast<int>(type_) );
+ isc_throw(EvalTypeError, "Bad field specified: " << static_cast<int>(type_));
}
} catch (const std::bad_cast&) {
TokenVendor::TokenVendor(Option::Universe u, uint32_t vendor_id, RepresentationType repr,
uint16_t option_code)
- :TokenOption(option_code, repr), universe_(u), vendor_id_(vendor_id),
- field_(option_code ? SUBOPTION : EXISTS) {
+ : TokenOption(option_code, repr), universe_(u), vendor_id_(vendor_id),
+ field_(option_code ? SUBOPTION : EXISTS) {
}
TokenVendor::TokenVendor(Option::Universe u, uint32_t vendor_id, FieldType field)
- :TokenOption(0, TokenOption::HEXADECIMAL), universe_(u), vendor_id_(vendor_id),
- field_(field) {
+ : TokenOption(0, TokenOption::HEXADECIMAL), universe_(u), vendor_id_(vendor_id),
+ field_(field) {
if (field_ == EXISTS) {
representation_type_ = TokenOption::EXISTS;
}
TokenVendorClass::TokenVendorClass(Option::Universe u, uint32_t vendor_id,
RepresentationType repr)
- :TokenVendor(u, vendor_id, repr, 0), index_(0) {
+ : TokenVendor(u, vendor_id, repr, 0), index_(0) {
}
TokenVendorClass::TokenVendorClass(Option::Universe u, uint32_t vendor_id,
FieldType field, uint16_t index)
- :TokenVendor(u, vendor_id, TokenOption::HEXADECIMAL, 0), index_(index) {
+ : TokenVendor(u, vendor_id, TokenOption::HEXADECIMAL, 0), index_(index) {
field_ = field;
}
}
TokenInteger::TokenInteger(const uint32_t value)
- :TokenString(EvalContext::fromUint32(value)), int_value_(value) {
+ : TokenString(EvalContext::fromUint32(value)), int_value_(value) {
}
OptionPtr
///
/// @param str constant string to be represented.
TokenString(const std::string& str)
- :value_(str){
+ : value_(str){
}
/// @brief Token evaluation (puts value of the constant string on the stack)
/// @param rep_type Token representation type.
TokenRelay6Option(const int8_t nest_level, const uint16_t option_code,
const RepresentationType& rep_type)
- :TokenOption(option_code, rep_type), nest_level_(nest_level) {}
+ : TokenOption(option_code, rep_type), nest_level_(nest_level) {}
/// @brief Returns nest-level
///
/// @param nest_level the nesting level for which relay to examine.
/// @param type which field to extract.
TokenRelay6Field(const int8_t nest_level, const FieldType type)
- : nest_level_(nest_level), type_(type) {}
+ : nest_level_(nest_level), type_(type) {}
/// @brief Extracts the specified field from the requested relay
///
///
/// @param client_class client class name
TokenMember(const std::string& client_class)
- :client_class_(client_class){
+ : client_class_(client_class){
}
/// @brief Token evaluation (check if client_class_ was added to
connection_pool_(connection_pool),
acceptor_callback_(acceptor_callback),
connection_filter_(connection_filter),
+ read_max_(read_max),
input_buf_(read_max) {
if (!tls_context) {
tcp_socket_.reset(new asiolink::TCPSocket<SocketCallback>(io_service));
///
/// \return Value of 32-bit unsigned integer
inline uint32_t
-readUint32(const uint8_t* buffer, size_t length) {
+readUint32(const void* buffer, size_t length) {
if (length < sizeof(uint32_t)) {
isc_throw(isc::OutOfRange,
"Length (" << length << ") of buffer is insufficient " <<
return (result);
}
+/// \brief Write Unsigned 32-Bit Integer to Buffer
+///
+/// \param value 32-bit value to convert
+/// \param buffer Data buffer at least four bytes long into which the 32-bit
+/// value is written in network-byte order.
+/// \param length Length of the data buffer.
+///
+/// \return pointer to the next byte after stored value
+inline uint8_t*
+writeUint32(uint32_t value, void* buffer, size_t length) {
+ if (length < sizeof(uint32_t)) {
+ isc_throw(isc::OutOfRange,
+ "Length (" << length << ") of buffer is insufficient " <<
+ "to write a uint32_t");
+ }
+
+ uint8_t* byte_buffer = static_cast<uint8_t*>(buffer);
+
+ byte_buffer[0] = static_cast<uint8_t>((value & 0xff000000U) >> 24);
+ byte_buffer[1] = static_cast<uint8_t>((value & 0x00ff0000U) >> 16);
+ byte_buffer[2] = static_cast<uint8_t>((value & 0x0000ff00U) >> 8);
+ byte_buffer[3] = static_cast<uint8_t>((value & 0x000000ffU));
+
+ return (byte_buffer + sizeof(uint32_t));
+}
+
/// \brief Read Unsigned 64-Bit Integer from Buffer
///
/// \param buffer Data buffer at least four bytes long of which the first four
///
/// \return Value of 64-bit unsigned integer
inline uint64_t
-readUint64(const uint8_t* buffer, size_t length) {
+readUint64(const void* buffer, size_t length) {
if (length < sizeof(uint64_t)) {
isc_throw(isc::OutOfRange,
"Length (" << length << ") of buffer is insufficient " <<
result |= (static_cast<uint64_t>(byte_buffer[6])) << 8;
result |= (static_cast<uint64_t>(byte_buffer[7]));
-
return (result);
}
-/// \brief Write Unsigned 32-Bit Integer to Buffer
+/// \brief Write Unsigned 64-Bit Integer to Buffer
///
-/// \param value 32-bit value to convert
-/// \param buffer Data buffer at least four bytes long into which the 32-bit
+/// \param value 64-bit value to convert
+/// \param buffer Data buffer at least four bytes long into which the 64-bit
/// value is written in network-byte order.
/// \param length Length of the data buffer.
///
/// \return pointer to the next byte after stored value
inline uint8_t*
-writeUint32(uint32_t value, uint8_t* buffer, size_t length) {
- if (length < sizeof(uint32_t)) {
+writeUint64(uint64_t value, void* buffer, size_t length) {
+ if (length < sizeof(uint64_t)) {
isc_throw(isc::OutOfRange,
"Length (" << length << ") of buffer is insufficient " <<
- "to write a uint32_t");
+ "to write a uint64_t");
}
uint8_t* byte_buffer = static_cast<uint8_t*>(buffer);
- byte_buffer[0] = static_cast<uint8_t>((value & 0xff000000U) >> 24);
- byte_buffer[1] = static_cast<uint8_t>((value & 0x00ff0000U) >> 16);
- byte_buffer[2] = static_cast<uint8_t>((value & 0x0000ff00U) >> 8);
- byte_buffer[3] = static_cast<uint8_t>((value & 0x000000ffU));
+ byte_buffer[0] = static_cast<uint8_t>((value & 0xff00000000000000UL) >> 56);
+ byte_buffer[1] = static_cast<uint8_t>((value & 0x00ff000000000000UL) >> 48);
+ byte_buffer[2] = static_cast<uint8_t>((value & 0x0000ff0000000000UL) >> 40);
+ byte_buffer[3] = static_cast<uint8_t>((value & 0x000000ff00000000UL) >> 32);
+ byte_buffer[4] = static_cast<uint8_t>((value & 0x00000000ff000000UL) >> 24);
+ byte_buffer[5] = static_cast<uint8_t>((value & 0x0000000000ff0000UL) >> 16);
+ byte_buffer[6] = static_cast<uint8_t>((value & 0x000000000000ff00UL) >> 8);
+ byte_buffer[7] = static_cast<uint8_t>((value & 0x00000000000000ffUL));
- return (byte_buffer + sizeof(uint32_t));
+ return (byte_buffer + sizeof(uint64_t));
}
} // namespace util
EXPECT_EQ(16, int128_t(65) / int128_t(4));
// Check that dividing by zero throws.
- EXPECT_THROW_MSG(int128_t(1) / 0, std::overflow_error, "Integer Division by zero.");
+ EXPECT_THROW(int128_t(1) / 0, std::overflow_error);
// Check that underflowing results in a negative number for int128_t.
EXPECT_EQ(-1, int128_t(0) - 1);
EXPECT_EQ(16, uint128_t(65) / uint128_t(4));
// Check that dividing by zero throws.
- EXPECT_THROW_MSG(uint128_t(1) / 0, std::overflow_error, "Integer Division by zero.");
+ EXPECT_THROW(uint128_t(1) / 0, std::overflow_error);
// Check that underflowing results in a positive number for uint128_t.
EXPECT_LT(0, uint128_t(0) - 1);