Commit 6b9d28f7 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[1186] Part 3 of review changes

- buffer type changed: char => uint8_t
- removed unnecessary statements in Makefile.am
parent 223b19a3
......@@ -34,8 +34,6 @@ b10_dhcp6_SOURCES = main.cc iface_mgr.cc dhcp6_srv.cc
b10_dhcp6_SOURCES += iface_mgr.h dhcp6_srv.h
b10_dhcp6_LDADD = $(top_builddir)/src/lib/dhcp/libdhcp.la
b10_dhcp6_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la
b10_dhcp6_LDADD += $(top_builddir)/src/lib/cc/libcc.la
b10_dhcp6_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
b10_dhcp6_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
b10_dhcp6_LDADD += $(top_builddir)/src/lib/log/liblog.la
......
......@@ -118,7 +118,7 @@ Dhcpv6Srv::setServerID() {
/// TODO implement this for real once interface detection is done.
/// Use hardcoded server-id for now
boost::shared_array<char> srvid(new char[14]);
boost::shared_array<uint8_t> srvid(new uint8_t[14]);
srvid[0] = 0;
srvid[1] = 1; // DUID type 1 = DUID-LLT (see section 9.2 of RFC3315)
srvid[2] = 0;
......
......@@ -26,8 +26,11 @@
#include <iostream>
#include <exceptions/exceptions.h>
#if 0
// TODO cc is not used yet. It should be eventually
#include <cc/session.h>
#include <config/ccsession.h>
#endif
#include <util/buffer.h>
#include <log/dummylog.h>
......@@ -37,10 +40,6 @@
using namespace std;
using namespace isc::util;
using namespace isc::data;
using namespace isc::cc;
using namespace isc::config;
using namespace isc::util;
using namespace isc;
using namespace isc::dhcp;
......@@ -98,8 +97,6 @@ main(int argc, char* argv[]) {
specfile = string(DHCP6_SPECFILE_LOCATION);
}
// auth_server = new AuthSrv(cache, xfrout_client);
// auth_server->setVerbose(verbose_mode);
cout << "[b10-dhcp6] Initiating DHCPv6 operation." << endl;
Dhcpv6Srv* srv = new Dhcpv6Srv();
......
......@@ -57,8 +57,6 @@ dhcp6_unittests_LDADD = $(GTEST_LDADD)
dhcp6_unittests_LDADD += $(SQLITE_LIBS)
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libdhcp.la
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
dhcp6_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
endif
......
......@@ -74,7 +74,7 @@ TEST_F(Dhcpv6SrvTest, Solicit_basic) {
EXPECT_NO_THROW( srv = new NakedDhcpv6Srv(); );
// a dummy content for client-id
boost::shared_array<char> clntDuid(new char[32]);
boost::shared_array<uint8_t> clntDuid(new uint8_t[32]);
for (int i=0; i<32; i++)
clntDuid[i] = 100+i;
......
......@@ -23,7 +23,7 @@
#include <exceptions/exceptions.h>
#include <asiolink/io_address.h>
#include <asiolink/io_error.h>
#include <boost/static_assert.hpp>
using namespace asio;
using asio::ip::udp;
......@@ -55,17 +55,18 @@ IOAddress::toText() const {
}
IOAddress
IOAddress::from_bytes(short family, const char* data) {
static char addr_str[INET6_ADDRSTRLEN];
IOAddress::from_bytes(short family, const uint8_t* data) {
if (data == NULL) {
isc_throw(BadValue, "NULL pointer received.");
}
} else
if ( (family != AF_INET) && (family != AF_INET6) ) {
isc_throw(BadValue, "Invalid family type. Only AF_INET and AF_INET6"
<< "are supported");
}
inet_ntop(family, data, addr_str,INET6_ADDRSTRLEN);
BOOST_STATIC_ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
char addr_str[INET6_ADDRSTRLEN];
inet_ntop(family, data, addr_str, INET6_ADDRSTRLEN);
return IOAddress(string(addr_str));
}
......
......@@ -95,7 +95,7 @@ public:
///
/// \return Created IOAddress object
static IOAddress
from_bytes(short family, const char* data);
from_bytes(short family, const uint8_t* data);
/// \brief Compare addresses for equality
///
......
......@@ -66,11 +66,11 @@ TEST(IOAddressTest, Family) {
TEST(IOAddressTest, from_bytes) {
// 2001:db8:1::dead:beef
char v6[] = {
uint8_t v6[] = {
0x20, 0x01, 0x0d, 0xb8, 0x00, 0x01, 0, 0,
0, 0, 0, 0, 0xde, 0xad, 0xbe, 0xef };
char v4[] = { 192, 0 , 2, 3 };
uint8_t v4[] = { 192, 0 , 2, 3 };
IOAddress addr("::");
EXPECT_NO_THROW({
......
......@@ -3,6 +3,8 @@ SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CXXFLAGS = $(B10_CXXFLAGS)
CLEANFILES = *.gcno *.gcda
lib_LTLIBRARIES = libdhcp.la
......@@ -18,16 +20,7 @@ libdhcp_la_SOURCES += pkt6.cc pkt6.h
EXTRA_DIST = README
#EXTRA_DIST += log_messages.mes
# Note: the ordering matters: -Wno-... must follow -Wextra (defined in
# B10_CXXFLAGS)
libdhcp_la_CXXFLAGS = $(AM_CXXFLAGS)
if USE_GXX
libdhcp_la_CXXFLAGS += -Wall
endif
if USE_CLANGPP
# Same for clang++, but we need to turn off -Werror completely.
libdhcp_la_CXXFLAGS += -Wall
endif
libdhcp_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
libdhcp_la_LDFLAGS = $(LOG4CPLUS_LDFLAGS)
libdhcp_la_LIBADD = $(top_builddir)/src/lib/util/libutil.la
......@@ -34,7 +34,7 @@ LibDHCP::version() {
}
unsigned int
LibDHCP::unpackOptions6(boost::shared_array<char> buf, unsigned int buf_len,
LibDHCP::unpackOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
unsigned int offset, unsigned int parse_len,
isc::dhcp::Option::Option6Lst& options) {
if (offset + parse_len > buf_len) {
......@@ -45,11 +45,9 @@ LibDHCP::unpackOptions6(boost::shared_array<char> buf, unsigned int buf_len,
unsigned int end = offset + parse_len;
while (offset<end) {
unsigned int opt_type = static_cast<unsigned char>(buf[offset])*256
+ static_cast<unsigned char>(buf[offset+1]);
unsigned int opt_type = buf[offset]*256 + buf[offset+1];
offset += 2;
unsigned int opt_len = static_cast<unsigned char>(buf[offset]*256)
+ static_cast<unsigned char>(buf[offset+1]);
unsigned int opt_len = buf[offset]*256 + buf[offset+1];
offset += 2;
if (offset + opt_len > end ) {
......@@ -91,7 +89,7 @@ LibDHCP::unpackOptions6(boost::shared_array<char> buf, unsigned int buf_len,
}
unsigned int
LibDHCP::packOptions6(boost::shared_array<char> data,
LibDHCP::packOptions6(boost::shared_array<uint8_t> data,
unsigned int data_len,
unsigned int offset,
isc::dhcp::Option::Option6Lst& options) {
......
......@@ -44,7 +44,7 @@ public:
/// used byte)
///
static unsigned int
packOptions6(boost::shared_array<char> buf, unsigned int buf_len,
packOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
unsigned int offset,
isc::dhcp::Option::Option6Lst& options);
......@@ -62,7 +62,7 @@ public:
/// @return offset to first byte after last parsed option
///
static unsigned int
unpackOptions6(boost::shared_array<char> buf, unsigned int buf_len,
unpackOptions6(boost::shared_array<uint8_t> buf, unsigned int buf_len,
unsigned int offset, unsigned int parse_len,
isc::dhcp::Option::Option6Lst& options_);
......
......@@ -32,7 +32,7 @@ Option::Option(Universe u, unsigned short type)
}
Option::Option(Universe u, unsigned short type, boost::shared_array<char> buf,
Option::Option(Universe u, unsigned short type, boost::shared_array<uint8_t> buf,
unsigned int offset, unsigned int len)
:universe_(u), type_(type), data_(buf),
data_len_(len), offset_(offset)
......@@ -43,7 +43,7 @@ Option::Option(Universe u, unsigned short type, boost::shared_array<char> buf,
}
unsigned int
Option::pack(boost::shared_array<char> buf,
Option::pack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset) {
switch (universe_) {
......@@ -58,14 +58,14 @@ Option::pack(boost::shared_array<char> buf,
unsigned int
Option::pack4(boost::shared_array<char> buf,
Option::pack4(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset) {
if ( offset+len() > buf_len ) {
isc_throw(OutOfRange, "Failed to pack v4 option=" <<
type_ << ",len=" << data_len_ << ": too small buffer.");
}
char *ptr = &buf[offset];
uint8_t *ptr = &buf[offset];
ptr[0] = type_;
ptr[1] = data_len_;
ptr += 2;
......@@ -75,7 +75,7 @@ Option::pack4(boost::shared_array<char> buf,
}
unsigned int
Option::pack6(boost::shared_array<char> buf,
Option::pack6(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset) {
if ( offset+len() > buf_len ) {
......@@ -85,7 +85,7 @@ Option::pack6(boost::shared_array<char> buf,
int length = len() - getHeaderLen();
char * ptr = &buf[offset];
uint8_t * ptr = &buf[offset];
*(uint16_t*)ptr = htons(type_);
ptr += 2;
*(uint16_t*)ptr = htons(length);
......@@ -99,7 +99,7 @@ Option::pack6(boost::shared_array<char> buf,
}
unsigned int
Option::unpack(boost::shared_array<char> buf,
Option::unpack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int parse_len) {
......@@ -116,7 +116,7 @@ Option::unpack(boost::shared_array<char> buf,
}
unsigned int
Option::unpack4(boost::shared_array<char>,
Option::unpack4(boost::shared_array<uint8_t>,
unsigned int ,
unsigned int ,
unsigned int ) {
......@@ -125,7 +125,7 @@ Option::unpack4(boost::shared_array<char>,
}
unsigned int
Option::unpack6(boost::shared_array<char> buf,
Option::unpack6(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int parse_len) {
......@@ -209,7 +209,7 @@ std::string Option::toText(int indent /* =0 */ ) {
tmp << ":";
}
tmp << setfill('0') << setw(2) << hex
<< (unsigned short)(unsigned char)data_[offset_+i];
<< (unsigned short)(unsigned uint8_t)data_[offset_+i];
}
// print suboptions
......@@ -226,7 +226,7 @@ Option::getType() {
return type_;
}
char*
uint8_t*
Option::getData() {
if (data_len_) {
return (&data_[offset_]);
......
......@@ -29,7 +29,7 @@ public:
typedef std::multimap<unsigned int, boost::shared_ptr<Option> > Option6Lst;
typedef boost::shared_ptr<Option> Factory(Option::Universe u,
unsigned short type,
boost::shared_array<char> buf,
boost::shared_array<uint8_t> buf,
unsigned int offset,
unsigned int len);
......@@ -42,14 +42,14 @@ public:
// to different elements in shared array. Therefore we need to share
// pointer to the whole array and remember offset where data for
// this option begins
Option(Universe u, unsigned short type, boost::shared_array<char> buf,
Option(Universe u, unsigned short type, boost::shared_array<uint8_t> buf,
unsigned int offset,
unsigned int len);
// writes option in wire-format to buf, returns pointer to first unused
// byte after stored option
virtual unsigned int
pack(boost::shared_array<char> buf,
pack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset);
......@@ -67,7 +67,7 @@ public:
/// @return offset after last parsed option
///
virtual unsigned int
unpack(boost::shared_array<char> buf,
unpack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int parse_len);
......@@ -113,7 +113,7 @@ public:
///
/// @return pointer to actual data (or NULL if there is no data)
///
virtual char*
virtual uint8_t*
getData();
/// Adds a sub-option.
......@@ -160,7 +160,7 @@ protected:
/// @return offset to the next byte after last used byte
///
virtual unsigned int
pack4(boost::shared_array<char> buf,
pack4(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset);
......@@ -175,7 +175,7 @@ protected:
/// @return offset to the next byte after last used byte
///
virtual unsigned int
pack6(boost::shared_array<char> buf,
pack6(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset);
......@@ -189,7 +189,7 @@ protected:
/// @return offset to the next byte after last parsed byte
///
virtual unsigned int
unpack4(boost::shared_array<char> buf,
unpack4(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int parse_len);
......@@ -204,7 +204,7 @@ protected:
/// @return offset to the next byte after last parsed byte
///
virtual unsigned int
unpack6(boost::shared_array<char> buf,
unpack6(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int parse_len);
......@@ -212,7 +212,7 @@ protected:
Universe universe_; // option universe (V4 or V6)
unsigned short type_; // option type (0-255 for DHCPv4, 0-65535 for DHCPv6)
boost::shared_array<char> data_;
boost::shared_array<uint8_t> data_;
unsigned int data_len_; // length of data only. Use len() if you want to
// know proper length with option header overhead
unsigned int offset_; // data is a shared_pointer that points out to the
......
......@@ -41,7 +41,7 @@ Option6AddrLst::Option6AddrLst(unsigned short type,
}
Option6AddrLst::Option6AddrLst(unsigned short type,
boost::shared_array<char> buf,
boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int option_len)
......@@ -61,7 +61,7 @@ Option6AddrLst::setAddresses(std::vector<isc::asiolink::IOAddress>& addrs) {
}
unsigned int
Option6AddrLst::pack(boost::shared_array<char> buf,
Option6AddrLst::pack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset) {
if (len() > buf_len) {
......@@ -88,7 +88,7 @@ Option6AddrLst::pack(boost::shared_array<char> buf,
}
unsigned int
Option6AddrLst::unpack(boost::shared_array<char> buf,
Option6AddrLst::unpack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int option_len) {
......
......@@ -57,7 +57,7 @@ public:
/// @param offset offset to beginning of option data
/// @param len length of option data
///
Option6AddrLst(unsigned short type, boost::shared_array<char> buf,
Option6AddrLst(unsigned short type, boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int len);
......@@ -71,7 +71,7 @@ public:
/// @return offset to the next unused char (just after stored option)
///
unsigned int
pack(boost::shared_array<char> buf, unsigned int buf_len,
pack(boost::shared_array<uint8_t> buf, unsigned int buf_len,
unsigned int offset);
/// @brief Parses received data
......@@ -84,7 +84,7 @@ public:
/// @return offset to the next unparsed char (just after parsed option)
///
virtual unsigned int
unpack(boost::shared_array<char> buf,
unpack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int parse_len);
......
......@@ -31,31 +31,31 @@ Option6IA::Option6IA(Universe u, unsigned short type, unsigned int iaid)
}
Option6IA::Option6IA(Universe u, unsigned short type,
boost::shared_array<char> buf,
Option6IA::Option6IA(Universe u, unsigned short type,
boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int offset,
unsigned int option_len)
:Option(u, type) {
unpack(buf, buf_len, offset, option_len);
}
unsigned int
Option6IA::pack(boost::shared_array<char> buf,
Option6IA::pack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset) {
if (offset + len() > buf_len) {
isc_throw(OutOfRange, "Failed to pack IA option: len=" << len()
isc_throw(OutOfRange, "Failed to pack IA option: len=" << len()
<< ", buffer=" << buf_len << ": too small buffer.");
}
char* ptr = &buf[offset];
uint8_t* ptr = &buf[offset];
*(uint16_t*)ptr = htons(type_);
ptr += 2;
*(uint16_t*)ptr = htons(len() - 4); // len() returns complete option length
// len field contains length without 4-byte option header
ptr += 2;
*(uint32_t*)ptr = htonl(iaid_);
ptr += 4;
......@@ -69,10 +69,10 @@ Option6IA::pack(boost::shared_array<char> buf,
return offset;
}
unsigned int
Option6IA::unpack(boost::shared_array<char> buf,
unsigned int
Option6IA::unpack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int offset,
unsigned int parse_len) {
if (parse_len<12 || offset+12>buf_len) {
isc_throw(OutOfRange, "Option " << type_ << " truncated");
......@@ -83,7 +83,7 @@ Option6IA::unpack(boost::shared_array<char> buf,
offset +=4;
t2_ = ntohl(*(uint32_t*)&buf[offset]);
offset +=4;
offset = LibDHCP::unpackOptions6(buf, buf_len, offset,
offset = LibDHCP::unpackOptions6(buf, buf_len, offset,
parse_len - 12, optionLst_);
return (offset);
......@@ -118,7 +118,7 @@ std::string Option6IA::toText(int indent /* = 0*/) {
}
unsigned short Option6IA::len() {
unsigned short length = 4/*header*/ + 12 /* option content */; // header
// length of all suboptions
......@@ -129,4 +129,3 @@ unsigned short Option6IA::len() {
}
return (length);
}
......@@ -32,7 +32,7 @@ public:
// to different elements in shared array. Therefore we need to share
// pointer to the whole array and remember offset where data for
// this option begins
Option6IA(Universe u, unsigned short type, boost::shared_array<char> buf,
Option6IA(Universe u, unsigned short type, boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int len);
......@@ -40,20 +40,20 @@ public:
// writes option in wire-format to buf, returns pointer to first unused
// byte after stored option
unsigned int
pack(boost::shared_array<char> buf, unsigned int buf_len,
pack(boost::shared_array<uint8_t> buf, unsigned int buf_len,
unsigned int offset);
// parses received buffer, returns offset to the first unused byte after
// parsed option
virtual unsigned int
unpack(boost::shared_array<char> buf,
unpack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int parse_len);
/// Provides human readable text representation
///
/// @param indent number of leading space characterss
/// @param indent number of leading space characters
///
/// @return string with text represenation
///
......
......@@ -36,7 +36,7 @@ Option6IAAddr::Option6IAAddr(unsigned short type,
}
Option6IAAddr::Option6IAAddr(unsigned short type,
boost::shared_array<char> buf,
boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int option_len)
......@@ -45,7 +45,7 @@ Option6IAAddr::Option6IAAddr(unsigned short type,
}
unsigned int
Option6IAAddr::pack(boost::shared_array<char> buf,
Option6IAAddr::pack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset) {
if (len() > buf_len) {
......@@ -73,7 +73,7 @@ Option6IAAddr::pack(boost::shared_array<char> buf,
}
unsigned int
Option6IAAddr::unpack(boost::shared_array<char> buf,
Option6IAAddr::unpack(boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int parse_len) {
......@@ -82,10 +82,7 @@ Option6IAAddr::unpack(boost::shared_array<char> buf,
}
// 16 bytes: IPv6 address
/// TODO Implement fromBytes() method in IOAddress
char addr_str[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &buf[offset], addr_str,INET6_ADDRSTRLEN);
addr_ = IOAddress(string(addr_str));
addr_ = IOAddress::from_bytes(AF_INET6, &buf[offset]);
offset += 16;
preferred_ = ntohl(*(uint32_t*)&buf[offset]);
......
......@@ -22,37 +22,37 @@ namespace isc {
namespace dhcp {
class Option6IAAddr: public Option {
public:
// ctor, used for options constructed, usually during transmission
Option6IAAddr(unsigned short type,
Option6IAAddr(unsigned short type,
isc::asiolink::IOAddress addr,
unsigned int prefered,
unsigned int valid);
unsigned int valid);
// ctor, used for received options
// boost::shared_array allows sharing a buffer, but it requires that
// boost::shared_array allows sharing a buffer, but it requires that
// different instances share pointer to the whole array, not point
// to different elements in shared array. Therefore we need to share
// pointer to the whole array and remember offset where data for
// this option begins
Option6IAAddr(unsigned short type, boost::shared_array<char> buf,
Option6IAAddr(unsigned short type, boost::shared_array<uint8_t> buf,
unsigned int buf_len,
unsigned int offset,
unsigned int offset,
unsigned int len);
// writes option in wire-format to buf, returns pointer to first unused
// writes option in wire-format to buf, returns pointer to first unused
// byte after stored option
unsigned int