From: Tomek Mrugalski Date: Tue, 11 Oct 2011 16:57:19 +0000 (+0200) Subject: [1186] Part 3 of review changes X-Git-Tag: perftcpdns_before_epoll~86^2~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b9d28f7602143bb85fcfcefbaa35cde95fdbde3;p=thirdparty%2Fkea.git [1186] Part 3 of review changes - buffer type changed: char => uint8_t - removed unnecessary statements in Makefile.am --- diff --git a/src/bin/dhcp6/Makefile.am b/src/bin/dhcp6/Makefile.am index dd5cd42fed..690ba5f17a 100644 --- a/src/bin/dhcp6/Makefile.am +++ b/src/bin/dhcp6/Makefile.am @@ -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 diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index ad77621100..83c20a2b55 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -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 srvid(new char[14]); + boost::shared_array 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; diff --git a/src/bin/dhcp6/main.cc b/src/bin/dhcp6/main.cc index ae3ff06e9e..532381196b 100644 --- a/src/bin/dhcp6/main.cc +++ b/src/bin/dhcp6/main.cc @@ -26,8 +26,11 @@ #include #include +#if 0 +// TODO cc is not used yet. It should be eventually #include #include +#endif #include #include @@ -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(); diff --git a/src/bin/dhcp6/tests/Makefile.am b/src/bin/dhcp6/tests/Makefile.am index 4ed870f2f5..985368ef0b 100644 --- a/src/bin/dhcp6/tests/Makefile.am +++ b/src/bin/dhcp6/tests/Makefile.am @@ -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 diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index 22511683a6..f4f9deccb2 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -74,7 +74,7 @@ TEST_F(Dhcpv6SrvTest, Solicit_basic) { EXPECT_NO_THROW( srv = new NakedDhcpv6Srv(); ); // a dummy content for client-id - boost::shared_array clntDuid(new char[32]); + boost::shared_array clntDuid(new uint8_t[32]); for (int i=0; i<32; i++) clntDuid[i] = 100+i; diff --git a/src/lib/asiolink/io_address.cc b/src/lib/asiolink/io_address.cc index 5b2c888909..51c033282b 100644 --- a/src/lib/asiolink/io_address.cc +++ b/src/lib/asiolink/io_address.cc @@ -23,7 +23,7 @@ #include #include #include - +#include 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)); } diff --git a/src/lib/asiolink/io_address.h b/src/lib/asiolink/io_address.h index 4d090a1c4f..fe20c2765b 100644 --- a/src/lib/asiolink/io_address.h +++ b/src/lib/asiolink/io_address.h @@ -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 /// diff --git a/src/lib/asiolink/tests/io_address_unittest.cc b/src/lib/asiolink/tests/io_address_unittest.cc index c50ec454a7..7943a9acc6 100644 --- a/src/lib/asiolink/tests/io_address_unittest.cc +++ b/src/lib/asiolink/tests/io_address_unittest.cc @@ -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({ diff --git a/src/lib/dhcp/Makefile.am b/src/lib/dhcp/Makefile.am index 788a7e0902..f87e2b57fd 100644 --- a/src/lib/dhcp/Makefile.am +++ b/src/lib/dhcp/Makefile.am @@ -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 diff --git a/src/lib/dhcp/libdhcp.cc b/src/lib/dhcp/libdhcp.cc index ac6bc2e502..62326ba7de 100644 --- a/src/lib/dhcp/libdhcp.cc +++ b/src/lib/dhcp/libdhcp.cc @@ -34,7 +34,7 @@ LibDHCP::version() { } unsigned int -LibDHCP::unpackOptions6(boost::shared_array buf, unsigned int buf_len, +LibDHCP::unpackOptions6(boost::shared_array 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 buf, unsigned int buf_len, unsigned int end = offset + parse_len; while (offset(buf[offset])*256 - + static_cast(buf[offset+1]); + unsigned int opt_type = buf[offset]*256 + buf[offset+1]; offset += 2; - unsigned int opt_len = static_cast(buf[offset]*256) - + static_cast(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 buf, unsigned int buf_len, } unsigned int -LibDHCP::packOptions6(boost::shared_array data, +LibDHCP::packOptions6(boost::shared_array data, unsigned int data_len, unsigned int offset, isc::dhcp::Option::Option6Lst& options) { diff --git a/src/lib/dhcp/libdhcp.h b/src/lib/dhcp/libdhcp.h index f1773dbc0f..e1fc10fd81 100644 --- a/src/lib/dhcp/libdhcp.h +++ b/src/lib/dhcp/libdhcp.h @@ -44,7 +44,7 @@ public: /// used byte) /// static unsigned int - packOptions6(boost::shared_array buf, unsigned int buf_len, + packOptions6(boost::shared_array 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 buf, unsigned int buf_len, + unpackOptions6(boost::shared_array buf, unsigned int buf_len, unsigned int offset, unsigned int parse_len, isc::dhcp::Option::Option6Lst& options_); diff --git a/src/lib/dhcp/option.cc b/src/lib/dhcp/option.cc index 1d7a16a190..fcd2f4a628 100644 --- a/src/lib/dhcp/option.cc +++ b/src/lib/dhcp/option.cc @@ -32,7 +32,7 @@ Option::Option(Universe u, unsigned short type) } -Option::Option(Universe u, unsigned short type, boost::shared_array buf, +Option::Option(Universe u, unsigned short type, boost::shared_array 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 buf, } unsigned int -Option::pack(boost::shared_array buf, +Option::pack(boost::shared_array buf, unsigned int buf_len, unsigned int offset) { switch (universe_) { @@ -58,14 +58,14 @@ Option::pack(boost::shared_array buf, unsigned int -Option::pack4(boost::shared_array buf, +Option::pack4(boost::shared_array 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 buf, } unsigned int -Option::pack6(boost::shared_array buf, +Option::pack6(boost::shared_array buf, unsigned int buf_len, unsigned int offset) { if ( offset+len() > buf_len ) { @@ -85,7 +85,7 @@ Option::pack6(boost::shared_array 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 buf, } unsigned int -Option::unpack(boost::shared_array buf, +Option::unpack(boost::shared_array buf, unsigned int buf_len, unsigned int offset, unsigned int parse_len) { @@ -116,7 +116,7 @@ Option::unpack(boost::shared_array buf, } unsigned int -Option::unpack4(boost::shared_array, +Option::unpack4(boost::shared_array, unsigned int , unsigned int , unsigned int ) { @@ -125,7 +125,7 @@ Option::unpack4(boost::shared_array, } unsigned int -Option::unpack6(boost::shared_array buf, +Option::unpack6(boost::shared_array 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_]); diff --git a/src/lib/dhcp/option.h b/src/lib/dhcp/option.h index 65f1ba8371..f8343b5996 100644 --- a/src/lib/dhcp/option.h +++ b/src/lib/dhcp/option.h @@ -29,7 +29,7 @@ public: typedef std::multimap > Option6Lst; typedef boost::shared_ptr